]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/stopwatches/test/stopwatch/simple_stopwatch_pass.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / chrono / stopwatches / test / stopwatch / simple_stopwatch_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/strict_stopwatch.hpp>
10 #include "../cycle_count.hpp"
11 #include <boost/detail/lightweight_test.hpp>
12
13 #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
14 #define NOTHING ""
15 #endif
16
17
18 template <typename Stopwatch>
19 void check_invariants()
20 {
21 BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
22 BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
23 BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
24 BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
25 }
26
27 template <typename Stopwatch>
28 void check_default_constructor()
29 {
30 Stopwatch _;
31 }
32
33 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
34 template <typename Stopwatch>
35 void check_constructor_ec()
36 {
37 boost::system::error_code ec;
38 Stopwatch _(ec);
39 BOOST_TEST(ec.value()==0);
40 }
41
42 template <typename Stopwatch>
43 void check_constructor_throws()
44 {
45 Stopwatch _(boost::throws());
46 }
47 #endif
48
49 template <typename Stopwatch>
50 void check_elapsed(bool check=true)
51 {
52 Stopwatch sw;
53 ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
54 typename Stopwatch::duration d=sw.elapsed();
55 if (check)
56 BOOST_TEST(d >= boost::chrono::milliseconds(100));
57 }
58
59 template <typename Clock>
60 void check_all(bool check=true)
61 {
62 typedef boost::chrono::strict_stopwatch<Clock> Stopwatch;
63 check_invariants<Stopwatch>();
64 check_default_constructor<Stopwatch>();
65 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
66 check_constructor_ec<Stopwatch>();
67 check_constructor_throws<Stopwatch>();
68 #endif
69 check_elapsed<Stopwatch>(check);
70 }
71
72
73 int main()
74 {
75 std::cout << "cycle_count=";
76 check_all<ex::cycle_count<1500> >(true);
77
78 return boost::report_errors();
79 }