xref: /freebsd/contrib/kyua/utils/datetime_test.cpp (revision 6b13d60bf49ee40626d7e3a5d5a80519f0067307)
1b0d29bc4SBrooks Davis // Copyright 2010 The Kyua Authors.
2b0d29bc4SBrooks Davis // All rights reserved.
3b0d29bc4SBrooks Davis //
4b0d29bc4SBrooks Davis // Redistribution and use in source and binary forms, with or without
5b0d29bc4SBrooks Davis // modification, are permitted provided that the following conditions are
6b0d29bc4SBrooks Davis // met:
7b0d29bc4SBrooks Davis //
8b0d29bc4SBrooks Davis // * Redistributions of source code must retain the above copyright
9b0d29bc4SBrooks Davis //   notice, this list of conditions and the following disclaimer.
10b0d29bc4SBrooks Davis // * Redistributions in binary form must reproduce the above copyright
11b0d29bc4SBrooks Davis //   notice, this list of conditions and the following disclaimer in the
12b0d29bc4SBrooks Davis //   documentation and/or other materials provided with the distribution.
13b0d29bc4SBrooks Davis // * Neither the name of Google Inc. nor the names of its contributors
14b0d29bc4SBrooks Davis //   may be used to endorse or promote products derived from this software
15b0d29bc4SBrooks Davis //   without specific prior written permission.
16b0d29bc4SBrooks Davis //
17b0d29bc4SBrooks Davis // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18b0d29bc4SBrooks Davis // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19b0d29bc4SBrooks Davis // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20b0d29bc4SBrooks Davis // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21b0d29bc4SBrooks Davis // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22b0d29bc4SBrooks Davis // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23b0d29bc4SBrooks Davis // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24b0d29bc4SBrooks Davis // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25b0d29bc4SBrooks Davis // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26b0d29bc4SBrooks Davis // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27b0d29bc4SBrooks Davis // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28b0d29bc4SBrooks Davis 
29b0d29bc4SBrooks Davis #include "utils/datetime.hpp"
30b0d29bc4SBrooks Davis 
31b0d29bc4SBrooks Davis extern "C" {
32b0d29bc4SBrooks Davis #include <time.h>
33b0d29bc4SBrooks Davis #include <unistd.h>
34b0d29bc4SBrooks Davis }
35b0d29bc4SBrooks Davis 
36b0d29bc4SBrooks Davis #include <sstream>
37b0d29bc4SBrooks Davis #include <stdexcept>
38b0d29bc4SBrooks Davis 
39b0d29bc4SBrooks Davis #include <atf-c++.hpp>
40b0d29bc4SBrooks Davis 
41b0d29bc4SBrooks Davis namespace datetime = utils::datetime;
42b0d29bc4SBrooks Davis 
43b0d29bc4SBrooks Davis 
44b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__defaults);
ATF_TEST_CASE_BODY(delta__defaults)45b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__defaults)
46b0d29bc4SBrooks Davis {
47b0d29bc4SBrooks Davis     const datetime::delta delta;
48b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(0, delta.seconds);
49b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(0, delta.useconds);
50b0d29bc4SBrooks Davis }
51b0d29bc4SBrooks Davis 
52b0d29bc4SBrooks Davis 
53b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__overrides);
ATF_TEST_CASE_BODY(delta__overrides)54b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__overrides)
55b0d29bc4SBrooks Davis {
56b0d29bc4SBrooks Davis     const datetime::delta delta(1, 2);
57b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(1, delta.seconds);
58b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(2, delta.useconds);
59b0d29bc4SBrooks Davis 
60b0d29bc4SBrooks Davis     ATF_REQUIRE_THROW_RE(
61b0d29bc4SBrooks Davis         std::runtime_error, "Negative.*not supported.*-4999997us",
62b0d29bc4SBrooks Davis         datetime::delta(-5, 3));
63b0d29bc4SBrooks Davis }
64b0d29bc4SBrooks Davis 
65b0d29bc4SBrooks Davis 
66b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__from_microseconds);
ATF_TEST_CASE_BODY(delta__from_microseconds)67b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__from_microseconds)
68b0d29bc4SBrooks Davis {
69b0d29bc4SBrooks Davis     {
70b0d29bc4SBrooks Davis         const datetime::delta delta = datetime::delta::from_microseconds(0);
71b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(0, delta.seconds);
72b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(0, delta.useconds);
73b0d29bc4SBrooks Davis     }
74b0d29bc4SBrooks Davis     {
75b0d29bc4SBrooks Davis         const datetime::delta delta = datetime::delta::from_microseconds(
76b0d29bc4SBrooks Davis             999999);
77b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(0, delta.seconds);
78b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(999999, delta.useconds);
79b0d29bc4SBrooks Davis     }
80b0d29bc4SBrooks Davis     {
81b0d29bc4SBrooks Davis         const datetime::delta delta = datetime::delta::from_microseconds(
82b0d29bc4SBrooks Davis             1000000);
83b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(1, delta.seconds);
84b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(0, delta.useconds);
85b0d29bc4SBrooks Davis     }
86b0d29bc4SBrooks Davis     {
87b0d29bc4SBrooks Davis         const datetime::delta delta = datetime::delta::from_microseconds(
88b0d29bc4SBrooks Davis             10576293);
89b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(10, delta.seconds);
90b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(576293, delta.useconds);
91b0d29bc4SBrooks Davis     }
92b0d29bc4SBrooks Davis     {
93b0d29bc4SBrooks Davis         const datetime::delta delta = datetime::delta::from_microseconds(
94b0d29bc4SBrooks Davis             123456789123456LL);
95b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(123456789, delta.seconds);
96b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(123456, delta.useconds);
97b0d29bc4SBrooks Davis     }
98b0d29bc4SBrooks Davis 
99b0d29bc4SBrooks Davis     ATF_REQUIRE_THROW_RE(
100b0d29bc4SBrooks Davis         std::runtime_error, "Negative.*not supported.*-12345us",
101b0d29bc4SBrooks Davis         datetime::delta::from_microseconds(-12345));
102b0d29bc4SBrooks Davis }
103b0d29bc4SBrooks Davis 
104b0d29bc4SBrooks Davis 
105b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__to_microseconds);
ATF_TEST_CASE_BODY(delta__to_microseconds)106b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__to_microseconds)
107b0d29bc4SBrooks Davis {
108b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(0, datetime::delta(0, 0).to_microseconds());
109b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(999999, datetime::delta(0, 999999).to_microseconds());
110b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(1000000, datetime::delta(1, 0).to_microseconds());
111b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(10576293, datetime::delta(10, 576293).to_microseconds());
112b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(11576293, datetime::delta(10, 1576293).to_microseconds());
113b0d29bc4SBrooks Davis }
114b0d29bc4SBrooks Davis 
115b0d29bc4SBrooks Davis 
116b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__equals);
ATF_TEST_CASE_BODY(delta__equals)117b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__equals)
118b0d29bc4SBrooks Davis {
119b0d29bc4SBrooks Davis     ATF_REQUIRE(datetime::delta() == datetime::delta());
120b0d29bc4SBrooks Davis     ATF_REQUIRE(datetime::delta() == datetime::delta(0, 0));
121b0d29bc4SBrooks Davis     ATF_REQUIRE(datetime::delta(1, 2) == datetime::delta(1, 2));
122b0d29bc4SBrooks Davis 
123b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta() == datetime::delta(0, 1)));
124b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta() == datetime::delta(1, 0)));
125b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(1, 2) == datetime::delta(2, 1)));
126b0d29bc4SBrooks Davis }
127b0d29bc4SBrooks Davis 
128b0d29bc4SBrooks Davis 
129b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__differs);
ATF_TEST_CASE_BODY(delta__differs)130b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__differs)
131b0d29bc4SBrooks Davis {
132b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta() != datetime::delta()));
133b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta() != datetime::delta(0, 0)));
134b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(1, 2) != datetime::delta(1, 2)));
135b0d29bc4SBrooks Davis 
136b0d29bc4SBrooks Davis     ATF_REQUIRE(datetime::delta() != datetime::delta(0, 1));
137b0d29bc4SBrooks Davis     ATF_REQUIRE(datetime::delta() != datetime::delta(1, 0));
138b0d29bc4SBrooks Davis     ATF_REQUIRE(datetime::delta(1, 2) != datetime::delta(2, 1));
139b0d29bc4SBrooks Davis }
140b0d29bc4SBrooks Davis 
141b0d29bc4SBrooks Davis 
142b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__sorting);
ATF_TEST_CASE_BODY(delta__sorting)143b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__sorting)
144b0d29bc4SBrooks Davis {
145b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta() <  datetime::delta()));
146b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta() <= datetime::delta());
147b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta() >  datetime::delta()));
148b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta() >= datetime::delta());
149b0d29bc4SBrooks Davis 
150b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(9, 8) <  datetime::delta(9, 8)));
151b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta(9, 8) <= datetime::delta(9, 8));
152b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(9, 8) >  datetime::delta(9, 8)));
153b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta(9, 8) >= datetime::delta(9, 8));
154b0d29bc4SBrooks Davis 
155b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta(2, 5) <  datetime::delta(4, 8));
156b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta(2, 5) <= datetime::delta(4, 8));
157b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(2, 5) >  datetime::delta(4, 8)));
158b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(2, 5) >= datetime::delta(4, 8)));
159b0d29bc4SBrooks Davis 
160b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta(2, 5) <  datetime::delta(2, 8));
161b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta(2, 5) <= datetime::delta(2, 8));
162b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(2, 5) >  datetime::delta(2, 8)));
163b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(2, 5) >= datetime::delta(2, 8)));
164b0d29bc4SBrooks Davis 
165b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(4, 8) <  datetime::delta(2, 5)));
166b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(4, 8) <= datetime::delta(2, 5)));
167b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta(4, 8) >  datetime::delta(2, 5));
168b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta(4, 8) >= datetime::delta(2, 5));
169b0d29bc4SBrooks Davis 
170b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(2, 8) <  datetime::delta(2, 5)));
171b0d29bc4SBrooks Davis     ATF_REQUIRE(!(datetime::delta(2, 8) <= datetime::delta(2, 5)));
172b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta(2, 8) >  datetime::delta(2, 5));
173b0d29bc4SBrooks Davis     ATF_REQUIRE(  datetime::delta(2, 8) >= datetime::delta(2, 5));
174b0d29bc4SBrooks Davis }
175b0d29bc4SBrooks Davis 
176b0d29bc4SBrooks Davis 
177b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__addition);
ATF_TEST_CASE_BODY(delta__addition)178b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__addition)
179b0d29bc4SBrooks Davis {
180b0d29bc4SBrooks Davis     using datetime::delta;
181b0d29bc4SBrooks Davis 
182b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(delta(), delta() + delta());
183b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(delta(0, 10), delta() + delta(0, 10));
184b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(delta(10, 0), delta(10, 0) + delta());
185b0d29bc4SBrooks Davis 
186b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(delta(1, 234567), delta(0, 1234567) + delta());
187b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(delta(12, 34), delta(10, 20) + delta(2, 14));
188b0d29bc4SBrooks Davis }
189b0d29bc4SBrooks Davis 
190b0d29bc4SBrooks Davis 
191b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__addition_and_set);
ATF_TEST_CASE_BODY(delta__addition_and_set)192b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__addition_and_set)
193b0d29bc4SBrooks Davis {
194b0d29bc4SBrooks Davis     using datetime::delta;
195b0d29bc4SBrooks Davis 
196b0d29bc4SBrooks Davis     {
197b0d29bc4SBrooks Davis         delta d;
198b0d29bc4SBrooks Davis         d += delta(3, 5);
199b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(delta(3, 5), d);
200b0d29bc4SBrooks Davis     }
201b0d29bc4SBrooks Davis     {
202b0d29bc4SBrooks Davis         delta d(1, 2);
203b0d29bc4SBrooks Davis         d += delta(3, 5);
204b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(delta(4, 7), d);
205b0d29bc4SBrooks Davis     }
206b0d29bc4SBrooks Davis     {
207b0d29bc4SBrooks Davis         delta d(1, 2);
208b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(delta(4, 7), (d += delta(3, 5)));
209b0d29bc4SBrooks Davis     }
210b0d29bc4SBrooks Davis }
211b0d29bc4SBrooks Davis 
212b0d29bc4SBrooks Davis 
213b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__scale);
ATF_TEST_CASE_BODY(delta__scale)214b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__scale)
215b0d29bc4SBrooks Davis {
216b0d29bc4SBrooks Davis     using datetime::delta;
217b0d29bc4SBrooks Davis 
218b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(delta(), delta() * 0);
219b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(delta(), delta() * 5);
220b0d29bc4SBrooks Davis 
221b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(delta(0, 30), delta(0, 10) * 3);
222b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(delta(17, 500000), delta(3, 500000) * 5);
223b0d29bc4SBrooks Davis }
224b0d29bc4SBrooks Davis 
225b0d29bc4SBrooks Davis 
226b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__scale_and_set);
ATF_TEST_CASE_BODY(delta__scale_and_set)227b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__scale_and_set)
228b0d29bc4SBrooks Davis {
229b0d29bc4SBrooks Davis     using datetime::delta;
230b0d29bc4SBrooks Davis 
231b0d29bc4SBrooks Davis     {
232b0d29bc4SBrooks Davis         delta d(3, 5);
233b0d29bc4SBrooks Davis         d *= 2;
234b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(delta(6, 10), d);
235b0d29bc4SBrooks Davis     }
236b0d29bc4SBrooks Davis     {
237b0d29bc4SBrooks Davis         delta d(8, 0);
238b0d29bc4SBrooks Davis         d *= 8;
239b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(delta(64, 0), d);
240b0d29bc4SBrooks Davis     }
241b0d29bc4SBrooks Davis     {
242b0d29bc4SBrooks Davis         delta d(3, 5);
243b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(delta(9, 15), (d *= 3));
244b0d29bc4SBrooks Davis     }
245b0d29bc4SBrooks Davis }
246b0d29bc4SBrooks Davis 
247b0d29bc4SBrooks Davis 
248b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(delta__output);
ATF_TEST_CASE_BODY(delta__output)249b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(delta__output)
250b0d29bc4SBrooks Davis {
251b0d29bc4SBrooks Davis     {
252b0d29bc4SBrooks Davis         std::ostringstream str;
253b0d29bc4SBrooks Davis         str << datetime::delta(15, 8791);
254b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ("15008791us", str.str());
255b0d29bc4SBrooks Davis     }
256b0d29bc4SBrooks Davis     {
257b0d29bc4SBrooks Davis         std::ostringstream str;
258b0d29bc4SBrooks Davis         str << datetime::delta(12345678, 0);
259b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ("12345678000000us", str.str());
260b0d29bc4SBrooks Davis     }
261b0d29bc4SBrooks Davis }
262b0d29bc4SBrooks Davis 
263b0d29bc4SBrooks Davis 
264b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__copy);
ATF_TEST_CASE_BODY(timestamp__copy)265b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__copy)
266b0d29bc4SBrooks Davis {
267b0d29bc4SBrooks Davis     const datetime::timestamp ts1 = datetime::timestamp::from_values(
268b0d29bc4SBrooks Davis         2011, 2, 16, 19, 15, 30, 0);
269b0d29bc4SBrooks Davis     {
270b0d29bc4SBrooks Davis         const datetime::timestamp ts2 = ts1;
271b0d29bc4SBrooks Davis         const datetime::timestamp ts3 = datetime::timestamp::from_values(
272b0d29bc4SBrooks Davis             2012, 2, 16, 19, 15, 30, 0);
273b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ("2011", ts1.strftime("%Y"));
274b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ("2011", ts2.strftime("%Y"));
275b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ("2012", ts3.strftime("%Y"));
276b0d29bc4SBrooks Davis     }
277b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("2011", ts1.strftime("%Y"));
278b0d29bc4SBrooks Davis }
279b0d29bc4SBrooks Davis 
280b0d29bc4SBrooks Davis 
281b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__from_microseconds);
ATF_TEST_CASE_BODY(timestamp__from_microseconds)282b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__from_microseconds)
283b0d29bc4SBrooks Davis {
284b0d29bc4SBrooks Davis     const datetime::timestamp ts = datetime::timestamp::from_microseconds(
285b0d29bc4SBrooks Davis         1328829351987654LL);
286b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("2012-02-09 23:15:51", ts.strftime("%Y-%m-%d %H:%M:%S"));
287b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(1328829351987654LL, ts.to_microseconds());
288b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(1328829351, ts.to_seconds());
289b0d29bc4SBrooks Davis }
290b0d29bc4SBrooks Davis 
291b0d29bc4SBrooks Davis 
292b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__now__mock);
ATF_TEST_CASE_BODY(timestamp__now__mock)293b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__now__mock)
294b0d29bc4SBrooks Davis {
295b0d29bc4SBrooks Davis     datetime::set_mock_now(2011, 2, 21, 18, 5, 10, 0);
296b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("2011-02-21 18:05:10",
297b0d29bc4SBrooks Davis                    datetime::timestamp::now().strftime("%Y-%m-%d %H:%M:%S"));
298b0d29bc4SBrooks Davis 
299b0d29bc4SBrooks Davis     datetime::set_mock_now(datetime::timestamp::from_values(
300b0d29bc4SBrooks Davis                                2012, 3, 22, 19, 6, 11, 54321));
301b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("2012-03-22 19:06:11",
302b0d29bc4SBrooks Davis                    datetime::timestamp::now().strftime("%Y-%m-%d %H:%M:%S"));
303b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("2012-03-22 19:06:11",
304b0d29bc4SBrooks Davis                    datetime::timestamp::now().strftime("%Y-%m-%d %H:%M:%S"));
305b0d29bc4SBrooks Davis }
306b0d29bc4SBrooks Davis 
307b0d29bc4SBrooks Davis 
308b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__now__real);
ATF_TEST_CASE_BODY(timestamp__now__real)309b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__now__real)
310b0d29bc4SBrooks Davis {
311b0d29bc4SBrooks Davis     // This test is might fail if we happen to run at the crossing of one
312b0d29bc4SBrooks Davis     // day to the other and the two measures we pick of the current time
313b0d29bc4SBrooks Davis     // differ.  This is so unlikely that I haven't bothered to do this in any
314b0d29bc4SBrooks Davis     // other way.
315b0d29bc4SBrooks Davis 
316b0d29bc4SBrooks Davis     const time_t just_before = ::time(NULL);
317b0d29bc4SBrooks Davis     const datetime::timestamp now = datetime::timestamp::now();
318b0d29bc4SBrooks Davis 
319b0d29bc4SBrooks Davis     ::tm data;
320b0d29bc4SBrooks Davis     char buf[1024];
321b0d29bc4SBrooks Davis     ATF_REQUIRE(::gmtime_r(&just_before, &data) != 0);
322b0d29bc4SBrooks Davis     ATF_REQUIRE(::strftime(buf, sizeof(buf), "%Y-%m-%d", &data) != 0);
323b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(buf, now.strftime("%Y-%m-%d"));
324b0d29bc4SBrooks Davis 
325b0d29bc4SBrooks Davis     ATF_REQUIRE(now.strftime("%Z") == "GMT" || now.strftime("%Z") == "UTC");
326b0d29bc4SBrooks Davis }
327b0d29bc4SBrooks Davis 
328b0d29bc4SBrooks Davis 
329b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__now__granularity);
ATF_TEST_CASE_BODY(timestamp__now__granularity)330b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__now__granularity)
331b0d29bc4SBrooks Davis {
332b0d29bc4SBrooks Davis     const datetime::timestamp first = datetime::timestamp::now();
333b0d29bc4SBrooks Davis     ::usleep(1);
334b0d29bc4SBrooks Davis     const datetime::timestamp second = datetime::timestamp::now();
335b0d29bc4SBrooks Davis     ATF_REQUIRE(first.to_microseconds() != second.to_microseconds());
336b0d29bc4SBrooks Davis }
337b0d29bc4SBrooks Davis 
338b0d29bc4SBrooks Davis 
339b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__strftime);
ATF_TEST_CASE_BODY(timestamp__strftime)340b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__strftime)
341b0d29bc4SBrooks Davis {
342b0d29bc4SBrooks Davis     const datetime::timestamp ts1 = datetime::timestamp::from_values(
343b0d29bc4SBrooks Davis         2010, 12, 10, 8, 45, 50, 0);
344b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("2010-12-10", ts1.strftime("%Y-%m-%d"));
345b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("08:45:50", ts1.strftime("%H:%M:%S"));
346b0d29bc4SBrooks Davis 
347b0d29bc4SBrooks Davis     const datetime::timestamp ts2 = datetime::timestamp::from_values(
348b0d29bc4SBrooks Davis         2011, 2, 16, 19, 15, 30, 0);
349b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("2011-02-16T19:15:30", ts2.strftime("%Y-%m-%dT%H:%M:%S"));
350b0d29bc4SBrooks Davis }
351b0d29bc4SBrooks Davis 
352b0d29bc4SBrooks Davis 
353b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__to_iso8601_in_utc);
ATF_TEST_CASE_BODY(timestamp__to_iso8601_in_utc)354b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__to_iso8601_in_utc)
355b0d29bc4SBrooks Davis {
356b0d29bc4SBrooks Davis     const datetime::timestamp ts1 = datetime::timestamp::from_values(
357b0d29bc4SBrooks Davis         2010, 12, 10, 8, 45, 50, 0);
358b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("2010-12-10T08:45:50.000000Z", ts1.to_iso8601_in_utc());
359b0d29bc4SBrooks Davis 
360b0d29bc4SBrooks Davis     const datetime::timestamp ts2= datetime::timestamp::from_values(
361b0d29bc4SBrooks Davis         2016, 7, 11, 17, 51, 28, 123456);
362b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("2016-07-11T17:51:28.123456Z", ts2.to_iso8601_in_utc());
363b0d29bc4SBrooks Davis }
364b0d29bc4SBrooks Davis 
365b0d29bc4SBrooks Davis 
366b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__to_microseconds);
ATF_TEST_CASE_BODY(timestamp__to_microseconds)367b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__to_microseconds)
368b0d29bc4SBrooks Davis {
369b0d29bc4SBrooks Davis     const datetime::timestamp ts1 = datetime::timestamp::from_values(
370b0d29bc4SBrooks Davis         2010, 12, 10, 8, 45, 50, 123456);
371b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(1291970750123456LL, ts1.to_microseconds());
372b0d29bc4SBrooks Davis }
373b0d29bc4SBrooks Davis 
374b0d29bc4SBrooks Davis 
375b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__to_seconds);
ATF_TEST_CASE_BODY(timestamp__to_seconds)376b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__to_seconds)
377b0d29bc4SBrooks Davis {
378b0d29bc4SBrooks Davis     const datetime::timestamp ts1 = datetime::timestamp::from_values(
379b0d29bc4SBrooks Davis         2010, 12, 10, 8, 45, 50, 123456);
380b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(1291970750, ts1.to_seconds());
381b0d29bc4SBrooks Davis }
382b0d29bc4SBrooks Davis 
383b0d29bc4SBrooks Davis 
384b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__leap_second);
ATF_TEST_CASE_BODY(timestamp__leap_second)385b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__leap_second)
386b0d29bc4SBrooks Davis {
387b0d29bc4SBrooks Davis     // This is actually a test for from_values(), which is the function that
388b0d29bc4SBrooks Davis     // includes assertions to validate the input parameters.
389b0d29bc4SBrooks Davis     const datetime::timestamp ts1 = datetime::timestamp::from_values(
390b0d29bc4SBrooks Davis         2012, 6, 30, 23, 59, 60, 543);
391b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(1341100800, ts1.to_seconds());
392b0d29bc4SBrooks Davis }
393b0d29bc4SBrooks Davis 
394b0d29bc4SBrooks Davis 
395b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__equals);
ATF_TEST_CASE_BODY(timestamp__equals)396b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__equals)
397b0d29bc4SBrooks Davis {
398b0d29bc4SBrooks Davis     ATF_REQUIRE(datetime::timestamp::from_microseconds(1291970750123456LL) ==
399b0d29bc4SBrooks Davis                 datetime::timestamp::from_microseconds(1291970750123456LL));
400b0d29bc4SBrooks Davis }
401b0d29bc4SBrooks Davis 
402b0d29bc4SBrooks Davis 
403b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__differs);
ATF_TEST_CASE_BODY(timestamp__differs)404b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__differs)
405b0d29bc4SBrooks Davis {
406b0d29bc4SBrooks Davis     ATF_REQUIRE(datetime::timestamp::from_microseconds(1291970750123456LL) !=
407b0d29bc4SBrooks Davis                 datetime::timestamp::from_microseconds(1291970750123455LL));
408b0d29bc4SBrooks Davis }
409b0d29bc4SBrooks Davis 
410b0d29bc4SBrooks Davis 
411b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__sorting);
ATF_TEST_CASE_BODY(timestamp__sorting)412b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__sorting)
413b0d29bc4SBrooks Davis {
414b0d29bc4SBrooks Davis     {
415b0d29bc4SBrooks Davis         const datetime::timestamp ts1 = datetime::timestamp::from_microseconds(
416b0d29bc4SBrooks Davis             1291970750123455LL);
417b0d29bc4SBrooks Davis         const datetime::timestamp ts2 = datetime::timestamp::from_microseconds(
418b0d29bc4SBrooks Davis             1291970750123455LL);
419b0d29bc4SBrooks Davis 
420b0d29bc4SBrooks Davis         ATF_REQUIRE(!(ts1 < ts2));
421b0d29bc4SBrooks Davis         ATF_REQUIRE(  ts1 <= ts2);
422b0d29bc4SBrooks Davis         ATF_REQUIRE(!(ts1 > ts2));
423b0d29bc4SBrooks Davis         ATF_REQUIRE(  ts1 >= ts2);
424b0d29bc4SBrooks Davis     }
425b0d29bc4SBrooks Davis     {
426b0d29bc4SBrooks Davis         const datetime::timestamp ts1 = datetime::timestamp::from_microseconds(
427b0d29bc4SBrooks Davis             1291970750123455LL);
428b0d29bc4SBrooks Davis         const datetime::timestamp ts2 = datetime::timestamp::from_microseconds(
429b0d29bc4SBrooks Davis             1291970759123455LL);
430b0d29bc4SBrooks Davis 
431b0d29bc4SBrooks Davis         ATF_REQUIRE( ts1 < ts2);
432b0d29bc4SBrooks Davis         ATF_REQUIRE( ts1 <= ts2);
433b0d29bc4SBrooks Davis         ATF_REQUIRE(!(ts1 > ts2));
434b0d29bc4SBrooks Davis         ATF_REQUIRE(!(ts1 >= ts2));
435b0d29bc4SBrooks Davis     }
436b0d29bc4SBrooks Davis     {
437b0d29bc4SBrooks Davis         const datetime::timestamp ts1 = datetime::timestamp::from_microseconds(
438b0d29bc4SBrooks Davis             1291970759123455LL);
439b0d29bc4SBrooks Davis         const datetime::timestamp ts2 = datetime::timestamp::from_microseconds(
440b0d29bc4SBrooks Davis             1291970750123455LL);
441b0d29bc4SBrooks Davis 
442b0d29bc4SBrooks Davis         ATF_REQUIRE(!(ts1 < ts2));
443b0d29bc4SBrooks Davis         ATF_REQUIRE(!(ts1 <= ts2));
444b0d29bc4SBrooks Davis         ATF_REQUIRE(  ts1 > ts2);
445b0d29bc4SBrooks Davis         ATF_REQUIRE(  ts1 >= ts2);
446b0d29bc4SBrooks Davis     }
447b0d29bc4SBrooks Davis }
448b0d29bc4SBrooks Davis 
449b0d29bc4SBrooks Davis 
450b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__add_delta);
ATF_TEST_CASE_BODY(timestamp__add_delta)451b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__add_delta)
452b0d29bc4SBrooks Davis {
453b0d29bc4SBrooks Davis     using datetime::delta;
454b0d29bc4SBrooks Davis     using datetime::timestamp;
455b0d29bc4SBrooks Davis 
456b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(timestamp::from_values(2014, 12, 11, 21, 43, 30, 1234),
457b0d29bc4SBrooks Davis                    timestamp::from_values(2014, 12, 11, 21, 43, 0, 0) +
458b0d29bc4SBrooks Davis                    delta(30, 1234));
459b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(timestamp::from_values(2014, 12, 11, 22, 43, 7, 100),
460b0d29bc4SBrooks Davis                    timestamp::from_values(2014, 12, 11, 21, 43, 0, 0) +
461b0d29bc4SBrooks Davis                    delta(3602, 5000100));
462b0d29bc4SBrooks Davis }
463b0d29bc4SBrooks Davis 
464b0d29bc4SBrooks Davis 
465b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__add_delta_and_set);
ATF_TEST_CASE_BODY(timestamp__add_delta_and_set)466b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__add_delta_and_set)
467b0d29bc4SBrooks Davis {
468b0d29bc4SBrooks Davis     using datetime::delta;
469b0d29bc4SBrooks Davis     using datetime::timestamp;
470b0d29bc4SBrooks Davis 
471b0d29bc4SBrooks Davis     {
472b0d29bc4SBrooks Davis         timestamp ts = timestamp::from_values(2014, 12, 11, 21, 43, 0, 0);
473b0d29bc4SBrooks Davis         ts += delta(30, 1234);
474b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(timestamp::from_values(2014, 12, 11, 21, 43, 30, 1234),
475b0d29bc4SBrooks Davis                        ts);
476b0d29bc4SBrooks Davis     }
477b0d29bc4SBrooks Davis     {
478b0d29bc4SBrooks Davis         timestamp ts = timestamp::from_values(2014, 12, 11, 21, 43, 0, 0);
479b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(timestamp::from_values(2014, 12, 11, 22, 43, 7, 100),
480b0d29bc4SBrooks Davis                        ts += delta(3602, 5000100));
481b0d29bc4SBrooks Davis     }
482b0d29bc4SBrooks Davis }
483b0d29bc4SBrooks Davis 
484b0d29bc4SBrooks Davis 
485b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__subtract_delta);
ATF_TEST_CASE_BODY(timestamp__subtract_delta)486b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__subtract_delta)
487b0d29bc4SBrooks Davis {
488b0d29bc4SBrooks Davis     using datetime::delta;
489b0d29bc4SBrooks Davis     using datetime::timestamp;
490b0d29bc4SBrooks Davis 
491b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(timestamp::from_values(2014, 12, 11, 21, 43, 10, 4321),
492b0d29bc4SBrooks Davis                    timestamp::from_values(2014, 12, 11, 21, 43, 40, 5555) -
493b0d29bc4SBrooks Davis                    delta(30, 1234));
494b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(timestamp::from_values(2014, 12, 11, 20, 43, 1, 300),
495b0d29bc4SBrooks Davis                    timestamp::from_values(2014, 12, 11, 21, 43, 8, 400) -
496b0d29bc4SBrooks Davis                    delta(3602, 5000100));
497b0d29bc4SBrooks Davis }
498b0d29bc4SBrooks Davis 
499b0d29bc4SBrooks Davis 
500b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__subtract_delta_and_set);
ATF_TEST_CASE_BODY(timestamp__subtract_delta_and_set)501b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__subtract_delta_and_set)
502b0d29bc4SBrooks Davis {
503b0d29bc4SBrooks Davis     using datetime::delta;
504b0d29bc4SBrooks Davis     using datetime::timestamp;
505b0d29bc4SBrooks Davis 
506b0d29bc4SBrooks Davis     {
507b0d29bc4SBrooks Davis         timestamp ts = timestamp::from_values(2014, 12, 11, 21, 43, 40, 5555);
508b0d29bc4SBrooks Davis         ts -= delta(30, 1234);
509b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(timestamp::from_values(2014, 12, 11, 21, 43, 10, 4321),
510b0d29bc4SBrooks Davis                        ts);
511b0d29bc4SBrooks Davis     }
512b0d29bc4SBrooks Davis     {
513b0d29bc4SBrooks Davis         timestamp ts = timestamp::from_values(2014, 12, 11, 21, 43, 8, 400);
514b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ(timestamp::from_values(2014, 12, 11, 20, 43, 1, 300),
515b0d29bc4SBrooks Davis                        ts -= delta(3602, 5000100));
516b0d29bc4SBrooks Davis     }
517b0d29bc4SBrooks Davis }
518b0d29bc4SBrooks Davis 
519b0d29bc4SBrooks Davis 
520b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__subtraction);
ATF_TEST_CASE_BODY(timestamp__subtraction)521b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__subtraction)
522b0d29bc4SBrooks Davis {
523b0d29bc4SBrooks Davis     const datetime::timestamp ts1 = datetime::timestamp::from_microseconds(
524b0d29bc4SBrooks Davis         1291970750123456LL);
525b0d29bc4SBrooks Davis     const datetime::timestamp ts2 = datetime::timestamp::from_microseconds(
526b0d29bc4SBrooks Davis         1291970750123468LL);
527b0d29bc4SBrooks Davis     const datetime::timestamp ts3 = datetime::timestamp::from_microseconds(
528b0d29bc4SBrooks Davis         1291970850123456LL);
529b0d29bc4SBrooks Davis 
530b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(datetime::delta(0, 0), ts1 - ts1);
531b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(datetime::delta(0, 12), ts2 - ts1);
532b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(datetime::delta(100, 0), ts3 - ts1);
533b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(datetime::delta(99, 999988), ts3 - ts2);
534b0d29bc4SBrooks Davis 
535*6b13d60bSMuhammad Moinur Rahman     /*
536*6b13d60bSMuhammad Moinur Rahman      * NOTE (ngie): behavior change for
537*6b13d60bSMuhammad Moinur Rahman      * https://github.com/jmmv/kyua/issues/155 .
538*6b13d60bSMuhammad Moinur Rahman      */
539*6b13d60bSMuhammad Moinur Rahman     ATF_REQUIRE_EQ(datetime::delta::from_microseconds(1), ts2 - ts3);
540b0d29bc4SBrooks Davis }
541b0d29bc4SBrooks Davis 
542b0d29bc4SBrooks Davis 
543b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(timestamp__output);
ATF_TEST_CASE_BODY(timestamp__output)544b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(timestamp__output)
545b0d29bc4SBrooks Davis {
546b0d29bc4SBrooks Davis     {
547b0d29bc4SBrooks Davis         std::ostringstream str;
548b0d29bc4SBrooks Davis         str << datetime::timestamp::from_microseconds(1291970750123456LL);
549b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ("1291970750123456us", str.str());
550b0d29bc4SBrooks Davis     }
551b0d29bc4SBrooks Davis     {
552b0d29bc4SBrooks Davis         std::ostringstream str;
553b0d29bc4SBrooks Davis         str << datetime::timestamp::from_microseconds(1028309798759812LL);
554b0d29bc4SBrooks Davis         ATF_REQUIRE_EQ("1028309798759812us", str.str());
555b0d29bc4SBrooks Davis     }
556b0d29bc4SBrooks Davis }
557b0d29bc4SBrooks Davis 
558b0d29bc4SBrooks Davis 
ATF_INIT_TEST_CASES(tcs)559b0d29bc4SBrooks Davis ATF_INIT_TEST_CASES(tcs)
560b0d29bc4SBrooks Davis {
561b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__defaults);
562b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__overrides);
563b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__from_microseconds);
564b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__to_microseconds);
565b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__equals);
566b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__differs);
567b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__sorting);
568b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__addition);
569b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__addition_and_set);
570b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__scale);
571b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__scale_and_set);
572b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, delta__output);
573b0d29bc4SBrooks Davis 
574b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__copy);
575b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__from_microseconds);
576b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__now__mock);
577b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__now__real);
578b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__now__granularity);
579b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__strftime);
580b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__to_iso8601_in_utc);
581b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__to_microseconds);
582b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__to_seconds);
583b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__leap_second);
584b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__equals);
585b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__differs);
586b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__sorting);
587b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__add_delta);
588b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__add_delta_and_set);
589b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__subtract_delta);
590b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__subtract_delta_and_set);
591b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__subtraction);
592b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, timestamp__output);
593b0d29bc4SBrooks Davis }
594