]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/stopwatches/test/stopwatch/simple_stopclock_pass.cpp
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / libs / chrono / stopwatches / test / stopwatch / simple_stopclock_pass.cpp
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
4
5 #define BOOST_CHRONO_VERSION 2
6
7 #include <iostream>
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>
12
13 #include <boost/chrono/chrono_io.hpp>
14 #include <boost/system/system_error.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16
17 #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
18 #define NOTHING ""
19 #endif
20
21 using namespace boost::chrono;
22
23
24 template <typename Stopwatch>
25 void check_invariants()
26 {
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, ());
31 }
32
33 template <typename Stopwatch>
34 void check_default_constructor()
35 {
36 Stopwatch sw;
37 BOOST_TEST(sw.is_running());
38 }
39
40
41 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
42 template <typename Stopwatch>
43 void check_constructor_ec()
44 {
45 boost::system::error_code ec;
46 Stopwatch sw(ec);
47 BOOST_TEST(sw.is_running());
48 BOOST_TEST(ec.value()==0);
49 }
50
51 template <typename Stopwatch>
52 void check_constructor_throws()
53 {
54 Stopwatch sw(boost::throws());
55 BOOST_TEST(sw.is_running());
56 }
57 #endif
58
59 template <typename Stopwatch>
60 void check_elapsed()
61 {
62 Stopwatch sw;
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));
68 }
69
70
71
72
73 struct file_line {
74 file_line(const char* file, std::size_t line)
75 : fmt("%1%[%2%] Elapsed time:")
76 {
77 fmt % file % line;
78 }
79 ~file_line()
80 {
81 std::cout << fmt;
82 }
83 boost::format fmt;
84
85 };
86
87 template <typename Reporter>
88 void check_file_line2()
89 {
90 Reporter _("%1%\n");
91 file_line fl(__FILE__, __LINE__);
92 ex::sleep_for<typename Reporter::clock>(milliseconds(100));
93
94 }
95 template <typename Reporter>
96 void check_file_line()
97 {
98 Reporter rp("%1%[%2%] Elapsed time: %3%\n");
99 rp.format() % __FILE__ % __LINE__;
100
101 ex::sleep_for<typename Reporter::clock>(milliseconds(100));
102
103 }
104
105 template <typename Reporter>
106 void check_report()
107 {
108 Reporter sw;
109 ex::sleep_for<typename Reporter::clock>(milliseconds(100));
110 sw.report();
111 }
112
113
114
115
116 template <typename Clock>
117 void check_all()
118 {
119 typedef strict_stopclock<Clock> Reporter;
120 typedef strict_stopclock<Clock, elapsed_formatter > ReporterE;
121
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>();
127 #endif
128 check_elapsed<Reporter>();
129
130 check_report<Reporter>();
131 check_file_line<ReporterE>();
132
133
134 }
135
136 int main()
137 {
138 typedef strict_stopclock<high_resolution_clock > Reporter;
139
140 static Reporter::formatter_type fmtr;
141
142 //Reporter _(fmtr);
143 Reporter _;
144
145 check_all<ex::cycle_count<1500> >();
146
147 return boost::report_errors();
148 }