1 // Copyright 2010-2011 Vicente J. Botet Escriba
2 // Distributed under the Boost Software License, Version 1.0.
3 // See http://www.boost.org/LICENSE_1_0.txt
5 #define BOOST_CHRONO_VERSION 2
8 #include <boost/type_traits/is_same.hpp>
9 #include <boost/chrono/stopwatches/reporters/strict_stopclock.hpp>
10 #include "../cycle_count.hpp"
11 #include <boost/chrono/stopwatches/reporters/system_default_formatter.hpp>
13 #include <boost/chrono/chrono_io.hpp>
14 #include <boost/system/system_error.hpp>
15 #include <boost/detail/lightweight_test.hpp>
17 #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
21 using namespace boost::chrono
;
24 template <typename Stopwatch
>
25 void check_invariants()
27 BOOST_CHRONO_STATIC_ASSERT((boost::is_same
<typename
Stopwatch::rep
, typename
Stopwatch::clock::duration::rep
>::value
), NOTHING
, ());
28 BOOST_CHRONO_STATIC_ASSERT((boost::is_same
<typename
Stopwatch::period
, typename
Stopwatch::clock::duration::period
>::value
), NOTHING
, ());
29 BOOST_CHRONO_STATIC_ASSERT((boost::is_same
<typename
Stopwatch::duration
, typename
Stopwatch::clock::time_point::duration
>::value
), NOTHING
, ());
30 BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady
== Stopwatch::clock::is_steady
, NOTHING
, ());
33 template <typename Stopwatch
>
34 void check_default_constructor()
37 BOOST_TEST(sw
.is_running());
41 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
42 template <typename Stopwatch
>
43 void check_constructor_ec()
45 boost::system::error_code ec
;
47 BOOST_TEST(sw
.is_running());
48 BOOST_TEST(ec
.value()==0);
51 template <typename Stopwatch
>
52 void check_constructor_throws()
54 Stopwatch
sw(boost::throws());
55 BOOST_TEST(sw
.is_running());
59 template <typename Stopwatch
>
63 BOOST_TEST(sw
.is_running());
64 ex::sleep_for
<typename
Stopwatch::clock
>(boost::chrono::milliseconds(100));
65 typename
Stopwatch::duration d
=sw
.elapsed();
66 BOOST_TEST(sw
.is_running());
67 BOOST_TEST(d
>= boost::chrono::milliseconds(100));
74 file_line(const char* file
, std::size_t line
)
75 : fmt("%1%[%2%] Elapsed time:")
87 template <typename Reporter
>
88 void check_file_line2()
91 file_line
fl(__FILE__
, __LINE__
);
92 ex::sleep_for
<typename
Reporter::clock
>(milliseconds(100));
95 template <typename Reporter
>
96 void check_file_line()
98 Reporter
rp("%1%[%2%] Elapsed time: %3%\n");
99 rp
.format() % __FILE__
% __LINE__
;
101 ex::sleep_for
<typename
Reporter::clock
>(milliseconds(100));
105 template <typename Reporter
>
109 ex::sleep_for
<typename
Reporter::clock
>(milliseconds(100));
116 template <typename Clock
>
119 typedef strict_stopclock
<Clock
> Reporter
;
120 typedef strict_stopclock
<Clock
, elapsed_formatter
> ReporterE
;
122 check_invariants
<Reporter
>();
123 check_default_constructor
<Reporter
>();
124 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
125 check_constructor_ec
<Reporter
>();
126 check_constructor_throws
<Reporter
>();
128 check_elapsed
<Reporter
>();
130 check_report
<Reporter
>();
131 check_file_line
<ReporterE
>();
138 typedef strict_stopclock
<high_resolution_clock
> Reporter
;
140 static Reporter::formatter_type fmtr
;
145 check_all
<ex::cycle_count
<1500> >();
147 return boost::report_errors();