Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74624 - in trunk/libs/chrono/test: . stopwatch
From: vicente.botet_at_[hidden]
Date: 2011-10-01 12:53:15


Author: viboes
Date: 2011-10-01 12:53:14 EDT (Sat, 01 Oct 2011)
New Revision: 74624
URL: http://svn.boost.org/trac/boost/changeset/74624

Log:
Chrono: Added test for basic and suspendable stopwatches and make stopwatch use an emulated clock so no time is spent during the regression tests
Added:
   trunk/libs/chrono/test/cycle_count.hpp (contents, props changed)
   trunk/libs/chrono/test/stopwatch/basic_stopwatch_laps_accumulator_set_pass.cpp (contents, props changed)
   trunk/libs/chrono/test/stopwatch/basic_stopwatch_last_lap_pass.cpp (contents, props changed)
   trunk/libs/chrono/test/stopwatch/basic_stopwatch_pass.cpp (contents, props changed)
   trunk/libs/chrono/test/stopwatch/suspendable_stopwatch_pass.cpp (contents, props changed)
Text files modified:
   trunk/libs/chrono/test/Jamfile.v2 | 6 +
   trunk/libs/chrono/test/stopwatch/simple_lightweight_stopwatch_reporter_pass.cpp | 119 +++++++++++----------------------------
   trunk/libs/chrono/test/stopwatch/simple_stopwatch_pass.cpp | 73 +++++-------------------
   trunk/libs/chrono/test/stopwatch/simple_stopwatch_reporter_pass.cpp | 80 ++++++++++++--------------
   4 files changed, 94 insertions(+), 184 deletions(-)

Modified: trunk/libs/chrono/test/Jamfile.v2
==============================================================================
--- trunk/libs/chrono/test/Jamfile.v2 (original)
+++ trunk/libs/chrono/test/Jamfile.v2 2011-10-01 12:53:14 EDT (Sat, 01 Oct 2011)
@@ -243,7 +243,11 @@
 
     test-suite "stopwatch"
         :
- [ chrono-run2-mt stopwatch/simple_stopwatch_pass.cpp : simple_stopwatch_pass ]
+ [ chrono-run2 stopwatch/simple_stopwatch_pass.cpp : simple_stopwatch_pass ]
+ [ chrono-run2 stopwatch/basic_stopwatch_pass.cpp : basic_stopwatch_pass ]
+ [ chrono-run2 stopwatch/basic_stopwatch_last_lap_pass.cpp : basic_stopwatch_last_lap_pass ]
+ [ chrono-run2 stopwatch/basic_stopwatch_laps_accumulator_set_pass.cpp : basic_stopwatch_laps_accumulator_set_pass ]
+ [ chrono-run2 stopwatch/suspendable_stopwatch_pass.cpp : suspendable_stopwatch_pass ]
         ;
 
     test-suite "stopwatch_ex"

Added: trunk/libs/chrono/test/cycle_count.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/test/cycle_count.hpp 2011-10-01 12:53:14 EDT (Sat, 01 Oct 2011)
@@ -0,0 +1,82 @@
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#ifndef BOOST_CHRONO_TEST_CYCLE_COUNT_HPP
+#define BOOST_CHRONO_TEST_CYCLE_COUNT_HPP
+
+#include <boost/chrono/ceil.hpp>
+#include <boost/chrono/duration.hpp>
+#include <boost/chrono/time_point.hpp>
+#include <boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp>
+#include <boost/chrono/stopwatches/formatters/elapsed_formatter.hpp>
+#include <boost/chrono/stopwatches/simple_stopwatch.hpp>
+
+namespace ex
+{
+ template <long long speed>
+ struct cycle_count
+ {
+ typedef typename boost::ratio_multiply<boost::ratio<speed>, boost::mega>::type frequency; // Mhz
+ typedef typename boost::ratio_divide<boost::ratio<1>, frequency>::type period;
+ typedef long long rep;
+ typedef boost::chrono::duration<rep, period> duration;
+ typedef boost::chrono::time_point<cycle_count> time_point;
+ BOOST_CHRONO_STATIC_CONSTEXPR bool is_steady = true;
+ static long long ticks_;
+
+ static time_point now()
+ {
+ // return exact cycle count
+ return time_point(duration(ticks_));
+ }
+ static time_point now(boost::system::error_code & )
+ {
+ // return exact cycle count
+ return time_point(duration(ticks_));
+ }
+ static void advance(std::size_t ticks)
+ {
+ ticks_ += ticks;
+ }
+ template <typename D>
+ static void advance(D const& d)
+ {
+ ticks_ += boost::chrono::ceil<duration>(d).count();
+ }
+ };
+ template <long long speed>
+ long long cycle_count<speed>::ticks_ = 0;
+
+
+ template<class Clock, class Rep, class Period>
+ void sleep_for(const boost::chrono::duration<Rep, Period>& d)
+ {
+ Clock::advance(d);
+ }
+
+}
+
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ template <long long speed>
+ struct stopwatch_reporter_default_formatter<simple_stopwatch<ex::cycle_count<speed> > >
+ {
+ typedef elapsed_formatter type;
+ };
+
+ template <long long speed>
+ struct wstopwatch_reporter_default_formatter<simple_stopwatch<ex::cycle_count<speed> > >
+ {
+ typedef welapsed_formatter type;
+ };
+
+ } // namespace chrono
+} // namespace boost
+
+
+#endif

Added: trunk/libs/chrono/test/stopwatch/basic_stopwatch_laps_accumulator_set_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/test/stopwatch/basic_stopwatch_laps_accumulator_set_pass.cpp 2011-10-01 12:53:14 EDT (Sat, 01 Oct 2011)
@@ -0,0 +1,220 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Adaptation to Boost of the libcxx
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#include <iostream>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/chrono/stopwatches/basic_stopwatch.hpp>
+#include <boost/chrono/stopwatches/memories/laps_accumulator_set.hpp>
+#include <libs/chrono/test/cycle_count.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#if !defined(BOOST_NO_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+
+template <typename Stopwatch>
+void check_invariants()
+{
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
+}
+
+template <typename Stopwatch>
+void check_default_constructor()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==0);
+}
+
+template <typename Stopwatch>
+void check_dont_start_constructor()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(d == Stopwatch::duration::zero());
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==0);
+}
+
+template <typename Stopwatch>
+void check_constructor_ec()
+{
+ boost::system::error_code ec;
+ Stopwatch sw(ec);
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(ec.value()==0);
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==0);
+}
+
+template <typename Stopwatch>
+void check_constructor_throws()
+{
+ Stopwatch sw(boost::throws());
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==0);
+}
+
+template <typename Stopwatch>
+void check_elapsed()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==0);
+}
+
+template <typename Stopwatch>
+void check_start_start()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==0);
+}
+
+template <typename Stopwatch>
+void check_dont_start_start()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==0);
+}
+
+template <typename Stopwatch>
+void check_dont_start_start_stop()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ BOOST_TEST(sw.get_laps_memory().last()==boost::chrono::milliseconds(100));
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==1);
+}
+
+template <typename Stopwatch>
+void check_dont_start_scoped_run()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ {
+ typename Stopwatch::scoped_run _(sw);
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ }
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==1);
+}
+
+template <typename Stopwatch>
+void check_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ BOOST_TEST(sw.get_laps_memory().last()==boost::chrono::milliseconds(100));
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==1);
+}
+
+template <typename Stopwatch>
+void check_stop_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ BOOST_TEST(sw.get_laps_memory().last()==boost::chrono::milliseconds(100));
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ BOOST_TEST(sw.get_laps_memory().last()==boost::chrono::milliseconds(100));
+ BOOST_TEST(boost::accumulators::count(sw.get_laps_memory().accumulator_set())==1);
+}
+
+
+template <typename Stopwatch>
+void check_all()
+{
+ check_invariants<Stopwatch>();
+ check_default_constructor<Stopwatch>();
+ check_constructor_ec<Stopwatch>();
+ check_constructor_throws<Stopwatch>();
+ check_elapsed<Stopwatch>();
+
+ check_start_start<Stopwatch>();
+ check_dont_start_constructor<Stopwatch>();
+ check_dont_start_start<Stopwatch>();
+ check_dont_start_start_stop<Stopwatch>();
+ check_dont_start_scoped_run<Stopwatch>();
+ check_stop<Stopwatch>();
+ check_stop_stop<Stopwatch>();
+
+}
+
+
+int main()
+{
+ std::cout << "cycle_count=";
+ check_all<boost::chrono::basic_stopwatch< ex::cycle_count<1500>, boost::chrono::laps_accumulator_set<ex::cycle_count<1500>::duration> > >();
+ return boost::report_errors();
+}

Added: trunk/libs/chrono/test/stopwatch/basic_stopwatch_last_lap_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/test/stopwatch/basic_stopwatch_last_lap_pass.cpp 2011-10-01 12:53:14 EDT (Sat, 01 Oct 2011)
@@ -0,0 +1,222 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Adaptation to Boost of the libcxx
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#include <iostream>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/chrono/stopwatches/basic_stopwatch.hpp>
+#include <boost/chrono/stopwatches/memories/last_lap.hpp>
+#include <libs/chrono/test/cycle_count.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#if !defined(BOOST_NO_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+
+template <typename Stopwatch>
+void check_invariants()
+{
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
+}
+
+template <typename Stopwatch>
+void check_default_constructor()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_dont_start_constructor()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(d == Stopwatch::duration::zero());
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_constructor_ec()
+{
+ boost::system::error_code ec;
+ Stopwatch sw(ec);
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(ec.value()==0);
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_constructor_throws()
+{
+ Stopwatch sw(boost::throws());
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_elapsed()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_start_start()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_dont_start_start()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+ BOOST_TEST(sw.get_laps_memory().last()==Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_dont_start_start_stop()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+ BOOST_TEST(sw.get_laps_memory().last()==boost::chrono::milliseconds(100));
+}
+
+template <typename Stopwatch>
+void check_dont_start_scoped_run()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ {
+ typename Stopwatch::scoped_run _(sw);
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ }
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+ BOOST_TEST(sw.get_laps_memory().last()==boost::chrono::milliseconds(100));
+
+ BOOST_TEST(!sw.is_running());
+ {
+ typename Stopwatch::scoped_run _(sw);
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(200));
+ }
+ BOOST_TEST(!sw.is_running());
+ d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+ BOOST_TEST(sw.get_laps_memory().last()==boost::chrono::milliseconds(200));
+}
+
+template <typename Stopwatch>
+void check_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ BOOST_TEST(sw.get_laps_memory().last()==boost::chrono::milliseconds(100));
+}
+
+template <typename Stopwatch>
+void check_stop_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ BOOST_TEST(sw.get_laps_memory().last()==boost::chrono::milliseconds(100));
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ BOOST_TEST(sw.get_laps_memory().last()==boost::chrono::milliseconds(100));
+}
+
+
+template <typename Stopwatch>
+void check_all()
+{
+ check_invariants<Stopwatch>();
+ check_default_constructor<Stopwatch>();
+ check_constructor_ec<Stopwatch>();
+ check_constructor_throws<Stopwatch>();
+ check_elapsed<Stopwatch>();
+
+ check_start_start<Stopwatch>();
+ check_dont_start_constructor<Stopwatch>();
+ check_dont_start_start<Stopwatch>();
+ check_dont_start_start_stop<Stopwatch>();
+ check_dont_start_scoped_run<Stopwatch>();
+ check_stop<Stopwatch>();
+ check_stop_stop<Stopwatch>();
+
+}
+
+
+int main()
+{
+ std::cout << "cycle_count=";
+ check_all<boost::chrono::basic_stopwatch< ex::cycle_count<1500>, boost::chrono::last_lap<ex::cycle_count<1500>::duration> > >();
+ return boost::report_errors();
+}

Added: trunk/libs/chrono/test/stopwatch/basic_stopwatch_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/test/stopwatch/basic_stopwatch_pass.cpp 2011-10-01 12:53:14 EDT (Sat, 01 Oct 2011)
@@ -0,0 +1,199 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Adaptation to Boost of the libcxx
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#include <iostream>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/chrono/stopwatches/basic_stopwatch.hpp>
+#include <boost/chrono/stopwatches/memories/last_lap.hpp>
+#include <libs/chrono/test/cycle_count.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#if !defined(BOOST_NO_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+
+template <typename Stopwatch>
+void check_invariants()
+{
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
+}
+
+template <typename Stopwatch>
+void check_default_constructor()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+}
+
+template <typename Stopwatch>
+void check_dont_start_constructor()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(d == Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_constructor_ec()
+{
+ boost::system::error_code ec;
+ Stopwatch sw(ec);
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(ec.value()==0);
+}
+
+template <typename Stopwatch>
+void check_constructor_throws()
+{
+ Stopwatch sw(boost::throws());
+ BOOST_TEST(sw.is_running());
+}
+
+template <typename Stopwatch>
+void check_elapsed()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+}
+
+template <typename Stopwatch>
+void check_start_start()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+}
+
+template <typename Stopwatch>
+void check_dont_start_start()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+}
+
+template <typename Stopwatch>
+void check_dont_start_start_stop()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_dont_start_scoped_run()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ {
+ typename Stopwatch::scoped_run _(sw);
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ }
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_stop_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+}
+
+
+template <typename Stopwatch>
+void check_all()
+{
+ check_invariants<Stopwatch>();
+ check_default_constructor<Stopwatch>();
+ check_constructor_ec<Stopwatch>();
+ check_constructor_throws<Stopwatch>();
+ check_elapsed<Stopwatch>();
+
+ check_start_start<Stopwatch>();
+ check_dont_start_constructor<Stopwatch>();
+ check_dont_start_start<Stopwatch>();
+ check_dont_start_start_stop<Stopwatch>();
+ check_dont_start_scoped_run<Stopwatch>();
+ check_stop<Stopwatch>();
+ check_stop_stop<Stopwatch>();
+
+}
+
+
+int main()
+{
+ std::cout << "cycle_count=";
+ check_all<boost::chrono::basic_stopwatch< ex::cycle_count<1500> > >();
+
+
+ return boost::report_errors();
+}

Modified: trunk/libs/chrono/test/stopwatch/simple_lightweight_stopwatch_reporter_pass.cpp
==============================================================================
--- trunk/libs/chrono/test/stopwatch/simple_lightweight_stopwatch_reporter_pass.cpp (original)
+++ trunk/libs/chrono/test/stopwatch/simple_lightweight_stopwatch_reporter_pass.cpp 2011-10-01 12:53:14 EDT (Sat, 01 Oct 2011)
@@ -14,12 +14,11 @@
 #include <iostream>
 #include <boost/type_traits/is_same.hpp>
 #include <boost/chrono/stopwatches/simple_stopwatch.hpp>
+#include <libs/chrono/test/cycle_count.hpp>
 #include <boost/chrono/stopwatches/reporters/lightweight_stopwatch_reporter.hpp>
-#include <boost/chrono/stopwatches/reporters/system_default_formatter.hpp>
-#include <boost/chrono/stopwatches/reporters/process_default_formatter.hpp>
-#include <boost/chrono/stopwatches/reporters/thread_default_formatter.hpp>
 #include <boost/chrono/chrono_io.hpp>
 #include <boost/system/system_error.hpp>
+#include <boost/chrono/stopwatches/reporters/system_default_formatter.hpp>
 #include <boost/detail/lightweight_test.hpp>
 
 #if !defined(BOOST_NO_STATIC_ASSERT)
@@ -28,155 +27,107 @@
 
 using namespace boost::chrono;
 
-namespace ex
-{
- template<class Rep, class Period>
- void sleep_for(const duration<Rep, Period>& d)
- {
- typedef high_resolution_clock Clock;
- typename Clock::time_point go =
- Clock::now() + d;
- while (Clock::now() < go)
- {
- }
- }
-}
 
-template <typename Clock>
+template <typename Reporter>
 void check_invariants()
 {
- typedef lightweight_stopwatch_reporter<simple_stopwatch<Clock> > Reporter;
   typedef Reporter Stopwatch;
     BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
     BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
     BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
     BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
- BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::stopwatch, simple_stopwatch<Clock> >::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::stopwatch, simple_stopwatch<typename Stopwatch::clock> >::value), NOTHING, ());
 }
 
-template <typename Clock>
+template <typename Reporter>
 void check_constructor()
 {
- typedef simple_stopwatch<Clock> Stopwatch;
- typedef typename stopwatch_reporter_default_formatter<Stopwatch>::type Formatter;
- typedef lightweight_stopwatch_reporter<Stopwatch> Reporter;
- static Formatter fmtr;
+ static typename Reporter::formatter_type fmtr;
 
   Reporter _(fmtr);
 }
 
-template <typename Clock>
+template <typename Reporter>
 void check_constructor_ec()
 {
- typedef simple_stopwatch<Clock> Stopwatch;
- typedef typename stopwatch_reporter_default_formatter<Stopwatch>::type Formatter;
- typedef lightweight_stopwatch_reporter<Stopwatch> Reporter;
- static Formatter fmtr;
+ static typename Reporter::formatter_type fmtr;
 
   boost::system::error_code ec;
   Reporter _(fmtr, ec);
   BOOST_TEST(ec.value()==0);
 }
 
-template <typename Clock>
+template <typename Reporter>
 void check_constructor_throws()
 {
- typedef simple_stopwatch<Clock> Stopwatch;
- typedef typename stopwatch_reporter_default_formatter<Stopwatch>::type Formatter;
- typedef lightweight_stopwatch_reporter<Stopwatch> Reporter;
- static Formatter fmtr;
+ static typename Reporter::formatter_type fmtr;
 
   Reporter _(fmtr, boost::throws());
 }
 
-template <typename Clock>
+template <typename Reporter>
 void check_elapsed(bool check=true)
 {
- typedef simple_stopwatch<Clock> Stopwatch;
- typedef typename stopwatch_reporter_default_formatter<Stopwatch>::type Formatter;
- typedef lightweight_stopwatch_reporter<Stopwatch> Reporter;
- static Formatter fmtr;
+ static typename Reporter::formatter_type fmtr;
 
   Reporter sw(fmtr);
- ex::sleep_for(milliseconds(100));
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
   typename Reporter::duration d=sw.elapsed();
   std::cout << d << std::endl;
   if (check)
     BOOST_TEST(d >= milliseconds(100));
 }
 
-template <typename Clock>
+template <typename Reporter>
 void check_report()
 {
- typedef simple_stopwatch<Clock> Stopwatch;
- typedef typename stopwatch_reporter_default_formatter<Stopwatch>::type Formatter;
- typedef lightweight_stopwatch_reporter<Stopwatch> Reporter;
- static Formatter fmtr;
+ static typename Reporter::formatter_type fmtr;
 
   Reporter sw(fmtr);
- ex::sleep_for(milliseconds(100));
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
   sw.report();
 }
 
-template <typename Clock>
+template <typename Reporter>
 void check_file_line()
 {
- typedef simple_stopwatch<Clock> Stopwatch;
- typedef elapsed_formatter Formatter;
- typedef lightweight_stopwatch_reporter<Stopwatch,Formatter> Reporter;
- static Formatter fmtr("%1%[%2%] Elapsed time: %3%\n");
+ static typename Reporter::formatter_type fmtr("%1%[%2%] Elapsed time: %3%\n");
+
   fmtr % __FILE__ % __LINE__;
 
   Reporter _(fmtr);
- ex::sleep_for(milliseconds(100));
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
 }
 
 template <typename Clock>
 void check_all(bool check=true)
 {
- check_invariants<Clock>();
- check_constructor<Clock>();
- check_constructor_ec<Clock>();
- check_constructor_throws<Clock>();
- check_elapsed<Clock>(check);
- check_report<Clock>();
- check_file_line<Clock>();
+ typedef simple_stopwatch<Clock> Stopwatch;
+ typedef typename stopwatch_reporter_default_formatter<Stopwatch>::type Formatter;
+ typedef lightweight_stopwatch_reporter<Stopwatch> Reporter;
+ typedef elapsed_formatter FormatterE;
+ typedef lightweight_stopwatch_reporter<Stopwatch,FormatterE> ReporterE;
+
+ check_invariants<Reporter>();
+ check_constructor<Reporter>();
+ check_constructor_ec<Reporter>();
+ check_constructor_throws<Reporter>();
+ check_elapsed<Reporter>(check);
+ check_report<Reporter>();
+ check_file_line<ReporterE>();
 }
 
 int main()
 {
 
- typedef simple_stopwatch<high_resolution_clock> Stopwatch;
+ typedef simple_stopwatch<high_resolution_clock > Stopwatch;
   typedef stopwatch_reporter_default_formatter<Stopwatch>::type Formatter;
   typedef lightweight_stopwatch_reporter<Stopwatch> Reporter;
   static Formatter fmtr;
 
   Reporter _(fmtr);
 
- std::cout << "high_resolution_clock=\n";
- check_all<high_resolution_clock>(false);
-#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
- std::cout << "steady_clock=\n";
- check_all<steady_clock>(false);
-#endif
- std::cout << "system_clock=\n";
- check_all<system_clock>(false);
-
-#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
- std::cout << "thread_clock=\n";
- check_all<thread_clock>(false);
-#endif
-
-#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
- std::cout << "process_real_cpu_clock=\n";
- check_all<process_real_cpu_clock>(false);
- std::cout << "process_user_cpu_clock=\n";
- check_all<process_user_cpu_clock>(false);
- std::cout << "process_system_cpu_clock=\n";
- check_all<process_system_cpu_clock>(false);
- std::cout << "process_cpu_clock=\n";
- check_all<process_cpu_clock>(false);
-#endif
+ check_all<ex::cycle_count<1500> >(true);
 
   return boost::report_errors();
 }

Modified: trunk/libs/chrono/test/stopwatch/simple_stopwatch_pass.cpp
==============================================================================
--- trunk/libs/chrono/test/stopwatch/simple_stopwatch_pass.cpp (original)
+++ trunk/libs/chrono/test/stopwatch/simple_stopwatch_pass.cpp 2011-10-01 12:53:14 EDT (Sat, 01 Oct 2011)
@@ -14,70 +14,49 @@
 #include <iostream>
 #include <boost/type_traits/is_same.hpp>
 #include <boost/chrono/stopwatches/simple_stopwatch.hpp>
-#include <boost/chrono/process_cpu_clocks.hpp>
-#include <boost/chrono/thread_clock.hpp>
-#include <boost/system/system_error.hpp>
+#include <libs/chrono/test/cycle_count.hpp>
 #include <boost/detail/lightweight_test.hpp>
 
 #if !defined(BOOST_NO_STATIC_ASSERT)
 #define NOTHING ""
 #endif
 
-namespace ex
-{
- template<class Rep, class Period>
- void sleep_for(const boost::chrono::duration<Rep, Period>& d)
- {
- typedef boost::chrono::high_resolution_clock Clock;
- typename Clock::time_point go =
- Clock::now() + d;
- while (Clock::now() < go)
- {
- }
- }
-}
 
-template <typename Clock>
+template <typename Stopwatch>
 void check_invariants()
 {
- typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
     BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
     BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
     BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
     BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
- // to be replaced by has static member bool is_steady
 }
 
-template <typename Clock>
+template <typename Stopwatch>
 void check_default_constructor()
 {
- typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
   Stopwatch _;
 }
 
-template <typename Clock>
+template <typename Stopwatch>
 void check_constructor_ec()
 {
- typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
   boost::system::error_code ec;
   Stopwatch _(ec);
   BOOST_TEST(ec.value()==0);
 }
 
-template <typename Clock>
+template <typename Stopwatch>
 void check_constructor_throws()
 {
- typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
   Stopwatch _(boost::throws());
 }
 
 
-template <typename Clock>
+template <typename Stopwatch>
 void check_elapsed(bool check=true)
 {
- typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
   Stopwatch sw;
- ex::sleep_for(boost::chrono::milliseconds(100));
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
   typename Stopwatch::duration d=sw.elapsed();
   if (check)
     BOOST_TEST(d >= boost::chrono::milliseconds(100));
@@ -86,39 +65,19 @@
 template <typename Clock>
 void check_all(bool check=true)
 {
- check_invariants<Clock>();
- check_default_constructor<Clock>();
- check_constructor_ec<Clock>();
- check_constructor_throws<Clock>();
- check_elapsed<Clock>(check);
+ typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
+ check_invariants<Stopwatch>();
+ check_default_constructor<Stopwatch>();
+ check_constructor_ec<Stopwatch>();
+ check_constructor_throws<Stopwatch>();
+ check_elapsed<Stopwatch>(check);
 }
 
+
 int main()
 {
- std::cout << "high_resolution_clock=";
- check_all<boost::chrono::high_resolution_clock>(false);
-#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
- std::cout << "steady_clock=";
- check_all<boost::chrono::steady_clock>(false);
-#endif
- std::cout << "system_clock=";
- check_all<boost::chrono::system_clock>(false);
+ std::cout << "cycle_count=";
+ check_all<ex::cycle_count<1500> >(true);
 
-#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
- std::cout << "thread_clock=";
- check_all<boost::chrono::thread_clock>(false);
-#endif
-
-#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
- std::cout << "process_real_cpu_clock=";
- check_all<boost::chrono::process_real_cpu_clock>(false);
- std::cout << "process_user_cpu_clock=";
- check_all<boost::chrono::process_user_cpu_clock>(false);
- std::cout << "process_system_cpu_clock=";
- check_all<boost::chrono::process_system_cpu_clock>(false);
- std::cout << "process_cpu_clock=";
- check_all<boost::chrono::process_cpu_clock>(false);
-#endif
-
   return boost::report_errors();
 }

Modified: trunk/libs/chrono/test/stopwatch/simple_stopwatch_reporter_pass.cpp
==============================================================================
--- trunk/libs/chrono/test/stopwatch/simple_stopwatch_reporter_pass.cpp (original)
+++ trunk/libs/chrono/test/stopwatch/simple_stopwatch_reporter_pass.cpp 2011-10-01 12:53:14 EDT (Sat, 01 Oct 2011)
@@ -14,10 +14,10 @@
 #include <iostream>
 #include <boost/type_traits/is_same.hpp>
 #include <boost/chrono/stopwatches/simple_stopwatch.hpp>
+#include <libs/chrono/test/cycle_count.hpp>
 #include <boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp>
 #include <boost/chrono/stopwatches/reporters/system_default_formatter.hpp>
-#include <boost/chrono/stopwatches/reporters/process_default_formatter.hpp>
-#include <boost/chrono/stopwatches/reporters/thread_default_formatter.hpp>
+
 #include <boost/chrono/chrono_io.hpp>
 #include <boost/system/system_error.hpp>
 #include <boost/detail/lightweight_test.hpp>
@@ -28,36 +28,21 @@
 
 using namespace boost::chrono;
 
-namespace ex
-{
- template<class Rep, class Period>
- void sleep_for(const duration<Rep, Period>& d)
- {
- typedef high_resolution_clock Clock;
- typename Clock::time_point go =
- Clock::now() + d;
- while (Clock::now() < go)
- {
- }
- }
-}
 
-template <typename Clock>
+template <typename Reporter>
 void check_invariants()
 {
- typedef stopwatch_reporter<simple_stopwatch<Clock> > Reporter;
   typedef Reporter Stopwatch;
     BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
     BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
     BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
     BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
- BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::stopwatch, simple_stopwatch<Clock> >::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::stopwatch, simple_stopwatch<typename Stopwatch::clock> >::value), NOTHING, ());
 }
 
-template <typename Clock>
+template <typename Reporter>
 void check_default_constructor()
 {
- typedef stopwatch_reporter<simple_stopwatch<Clock> > Reporter;
   Reporter _;
 }
 
@@ -75,75 +60,85 @@
 
 };
 
-template <typename Clock>
-void check_file_line()
+template <typename Reporter>
+void check_file_line2()
 {
- typedef stopwatch_reporter<simple_stopwatch<Clock>, elapsed_formatter > Reporter;
   Reporter _("%1%\n");
   file_line fl(__FILE__, __LINE__);
- ex::sleep_for(milliseconds(100));
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
 
 }
+template <typename Reporter>
+void check_file_line()
+{
+ Reporter rp("%1%[%2%] Elapsed time: %3%\n");
+ rp.format() % __FILE__ % __LINE__;
 
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
 
-template <typename Clock>
+}
+
+
+template <typename Reporter>
 void check_constructor_ec()
 {
- typedef stopwatch_reporter<simple_stopwatch<Clock> > Reporter;
   boost::system::error_code ec;
   Reporter _(ec);
   BOOST_TEST(ec.value()==0);
 }
 
-template <typename Clock>
+template <typename Reporter>
 void check_constructor_throws()
 {
- typedef stopwatch_reporter<simple_stopwatch<Clock> > Reporter;
   Reporter _(boost::throws());
 }
 
-template <typename Clock>
+template <typename Reporter>
 void check_elapsed(bool check=true)
 {
- typedef stopwatch_reporter<simple_stopwatch<Clock> > Reporter;
   Reporter sw;
- ex::sleep_for(milliseconds(100));
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
   typename Reporter::duration d=sw.elapsed();
   std::cout << d << std::endl;
   if (check)
     BOOST_TEST(d >= milliseconds(100));
 }
 
-template <typename Clock>
+template <typename Reporter>
 void check_report()
 {
- typedef stopwatch_reporter<simple_stopwatch<Clock> > Reporter;
   Reporter sw;
- ex::sleep_for(milliseconds(100));
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
   sw.report();
 }
 
 template <typename Clock>
 void check_all(bool check=true)
 {
- check_invariants<Clock>();
- check_default_constructor<Clock>();
- check_constructor_ec<Clock>();
- check_constructor_throws<Clock>();
- check_elapsed<Clock>(check);
- check_report<Clock>();
- check_file_line<Clock>();
+ typedef stopwatch_reporter<simple_stopwatch<Clock> > Reporter;
+ typedef stopwatch_reporter<simple_stopwatch<Clock>, elapsed_formatter > ReporterE;
+
+ check_invariants<Reporter>();
+ check_default_constructor<Reporter>();
+ check_constructor_ec<Reporter>();
+ check_constructor_throws<Reporter>();
+ check_elapsed<Reporter>(check);
+ check_report<Reporter>();
+ check_file_line<ReporterE>();
 }
 
 int main()
 {
- typedef simple_stopwatch<high_resolution_clock> Stopwatch;
+ typedef simple_stopwatch<high_resolution_clock > Stopwatch;
   typedef stopwatch_reporter_default_formatter<Stopwatch>::type Formatter;
   typedef stopwatch_reporter<Stopwatch> Reporter;
   static Formatter fmtr;
 
   Reporter _(fmtr);
 
+ check_all<ex::cycle_count<1500> >(true);
+
+#if 0
   std::cout << "high_resolution_clock=\n";
 
   check_all<high_resolution_clock>();
@@ -169,6 +164,7 @@
   std::cout << "process_cpu_clock=\n";
   check_all<process_cpu_clock>(false);
 #endif
+#endif
 
   return boost::report_errors();
 }

Added: trunk/libs/chrono/test/stopwatch/suspendable_stopwatch_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/test/stopwatch/suspendable_stopwatch_pass.cpp 2011-10-01 12:53:14 EDT (Sat, 01 Oct 2011)
@@ -0,0 +1,282 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Adaptation to Boost of the libcxx
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#include <iostream>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/chrono/stopwatches/suspendable_stopwatch.hpp>
+#include <libs/chrono/test/cycle_count.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#if !defined(BOOST_NO_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+
+template <typename Stopwatch>
+void check_invariants()
+{
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
+}
+
+template <typename Stopwatch>
+void check_default_constructor()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+}
+
+template <typename Stopwatch>
+void check_dont_start_constructor()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(d == Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_constructor_ec()
+{
+ boost::system::error_code ec;
+ Stopwatch sw(ec);
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(ec.value()==0);
+}
+
+template <typename Stopwatch>
+void check_constructor_throws()
+{
+ Stopwatch sw(boost::throws());
+ BOOST_TEST(sw.is_running());
+}
+
+template <typename Stopwatch>
+void check_elapsed()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+}
+
+template <typename Stopwatch>
+void check_start_start()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+}
+
+template <typename Stopwatch>
+void check_dont_start_start()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+}
+
+template <typename Stopwatch>
+void check_dont_start_start_stop()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_dont_start_scoped_run()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ {
+ typename Stopwatch::scoped_run _(sw);
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ }
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_stop_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+}
+
+
+template <typename Stopwatch>
+void check_start_suspend()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.suspend();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(sw.is_suspended());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(sw.is_suspended());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+}
+
+template <typename Stopwatch>
+void check_start_suspend_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.suspend();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(sw.is_suspended());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(sw.is_suspended());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+ sw.stop();
+ d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(!sw.is_suspended());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_start_suspend_resume()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.suspend();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(sw.is_suspended());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.resume();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(!sw.is_suspended());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ d=sw.elapsed();
+ BOOST_TEST(d >= boost::chrono::milliseconds(200));
+ BOOST_TEST(d < boost::chrono::milliseconds(300));
+}
+
+template <typename Stopwatch>
+void check_start_scoped_suspend()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ {
+ typename Stopwatch::scoped_suspend _(sw);
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(sw.is_suspended());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ }
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(!sw.is_suspended());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+}
+template <typename Clock>
+void check_all()
+{
+ typedef boost::chrono::suspendable_stopwatch<Clock> Stopwatch;
+ check_invariants<Stopwatch>();
+ check_default_constructor<Stopwatch>();
+ check_constructor_ec<Stopwatch>();
+ check_constructor_throws<Stopwatch>();
+ check_elapsed<Stopwatch>();
+
+ check_start_start<Stopwatch>();
+ check_dont_start_constructor<Stopwatch>();
+ check_dont_start_start<Stopwatch>();
+ check_dont_start_start_stop<Stopwatch>();
+ check_dont_start_scoped_run<Stopwatch>();
+ check_stop<Stopwatch>();
+ check_stop_stop<Stopwatch>();
+
+ check_start_suspend<Stopwatch>();
+ check_start_suspend_resume<Stopwatch>();
+ check_start_suspend_stop<Stopwatch>();
+ check_start_scoped_suspend<Stopwatch>();
+
+}
+
+
+int main()
+{
+ std::cout << "cycle_count=";
+ check_all<ex::cycle_count<1500> >();
+
+ return boost::report_errors();
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk