• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //  Adaptation to Boost of the libcxx
10 //  Copyright 2010 Vicente J. Botet Escriba
11 //  Distributed under the Boost Software License, Version 1.0.
12 //  See http://www.boost.org/LICENSE_1_0.txt
13 
14 #include <boost/chrono/chrono.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16 #ifdef BOOST_NO_CXX11_CONSTEXPR
17 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C)
18 #else
19 #include <boost/static_assert.hpp>
20 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C)
21 #endif
22 
main()23 int main()
24 {
25   {
26     typedef boost::chrono::system_clock Clock;
27     typedef boost::chrono::milliseconds Duration;
28     boost::chrono::time_point<Clock, Duration> t(Duration(3));
29     t += Duration(2);
30     BOOST_TEST(t.time_since_epoch() == Duration(5));
31   }
32   {
33     typedef boost::chrono::system_clock Clock;
34     typedef boost::chrono::milliseconds Duration;
35     boost::chrono::time_point<Clock, Duration> t(Duration(3));
36     t -= Duration(2);
37     BOOST_TEST(t.time_since_epoch() == Duration(1));
38   }
39   {
40     typedef boost::chrono::system_clock Clock;
41     typedef boost::chrono::milliseconds Duration1;
42     typedef boost::chrono::microseconds Duration2;
43     boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
44     boost::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
45     BOOST_TEST(t2.time_since_epoch() == Duration2(2995));
46   }
47   {
48     typedef boost::chrono::system_clock Clock;
49     typedef boost::chrono::milliseconds Duration1;
50     typedef boost::chrono::microseconds Duration2;
51     BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
52     BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
53     BOOST_CONSTEXPR_ASSERT(t2.time_since_epoch() == Duration2(2995));
54   }
55   {
56     typedef boost::chrono::system_clock Clock;
57     typedef boost::chrono::milliseconds Duration1;
58     typedef boost::chrono::microseconds Duration2;
59     boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
60     boost::chrono::time_point<Clock, Duration2> t2(Duration2(5));
61     BOOST_TEST( (t1 - t2) == Duration2(2995));
62   }
63   {
64     typedef boost::chrono::system_clock Clock;
65     typedef boost::chrono::milliseconds Duration1;
66     typedef boost::chrono::microseconds Duration2;
67     BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
68     BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration2> t2(Duration2(5));
69     BOOST_CONSTEXPR_ASSERT( (t1 - t2) == Duration2(2995));
70   }
71   {
72     typedef boost::chrono::system_clock Clock;
73     typedef boost::chrono::milliseconds Duration1;
74     typedef boost::chrono::microseconds Duration2;
75     boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
76     boost::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5);
77     BOOST_TEST(t2.time_since_epoch() == Duration2(3005));
78     t2 = Duration2(6) + t1;
79     BOOST_TEST(t2.time_since_epoch() == Duration2(3006));
80   }
81   {
82     typedef boost::chrono::system_clock Clock;
83     typedef boost::chrono::milliseconds Duration1;
84     typedef boost::chrono::microseconds Duration2;
85     BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
86     BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5);
87     BOOST_CONSTEXPR_ASSERT(t2.time_since_epoch() == Duration2(3005));
88     BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration2> t3 = Duration2(6) + t1;
89     BOOST_CONSTEXPR_ASSERT(t3.time_since_epoch() == Duration2(3006));
90   }
91 #ifdef BOOST_CHRONO_EXTENSIONS
92   {
93     typedef boost::chrono::system_clock Clock;
94     typedef boost::chrono::milliseconds Duration;
95     boost::chrono::time_point<Clock, Duration> t(Duration(3));
96     t += 2;
97     BOOST_TEST(t.time_since_epoch() == Duration(5));
98   }
99   {
100     typedef boost::chrono::system_clock Clock;
101     typedef boost::chrono::milliseconds Duration;
102     boost::chrono::time_point<Clock, Duration> t(Duration(3));
103     t++;
104     BOOST_TEST(t.time_since_epoch() == Duration(4));
105   }
106   {
107     typedef boost::chrono::system_clock Clock;
108     typedef boost::chrono::milliseconds Duration;
109     boost::chrono::time_point<Clock, Duration> t(Duration(3));
110     ++t;
111     BOOST_TEST(t.time_since_epoch() == Duration(4));
112   }
113   {
114     typedef boost::chrono::system_clock Clock;
115     typedef boost::chrono::milliseconds Duration;
116     boost::chrono::time_point<Clock, Duration> t(Duration(3));
117     t -= 2;
118     BOOST_TEST(t.time_since_epoch() == Duration(1));
119   }
120 #if 0
121   {
122     typedef boost::chrono::system_clock Clock;
123     typedef boost::chrono::milliseconds Duration1;
124     typedef boost::chrono::microseconds Duration2;
125     boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
126     boost::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
127     BOOST_TEST(t2.time_since_epoch() == Duration2(2995));
128   }
129   {
130     typedef boost::chrono::system_clock Clock;
131     typedef boost::chrono::milliseconds Duration1;
132     typedef boost::chrono::microseconds Duration2;
133     boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
134     boost::chrono::time_point<Clock, Duration2> t2(Duration2(5));
135     BOOST_TEST((t1 - t2) == Duration2(2995));
136   }
137   {
138     typedef boost::chrono::system_clock Clock;
139     typedef boost::chrono::milliseconds Duration1;
140     typedef boost::chrono::microseconds Duration2;
141     boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
142     boost::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5);
143     BOOST_TEST(t2.time_since_epoch() == Duration2(3005));
144     t2 = Duration2(6) + t1;
145     BOOST_TEST(t2.time_since_epoch() == Duration2(3006));
146   }
147 #endif
148 #endif
149 
150   return boost::report_errors();
151 }
152