VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTTimeSpec.cpp@ 53427

Last change on this file since 53427 was 48935, checked in by vboxsync, 11 years ago

Runtime: Whitespace and svn:keyword cleanups by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 17.4 KB
Line 
1/* $Id: tstRTTimeSpec.cpp 48935 2013-10-07 21:19:37Z vboxsync $ */
2/** @file
3 * IPRT - RTTimeSpec and PRTTIME tests.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#if !defined(RT_OS_WINDOWS)
31# define RTTIME_INCL_TIMEVAL
32# define RTTIME_INCL_TIMESPEC
33# include <time.h>
34# include <sys/time.h>
35#endif
36#include <iprt/time.h>
37
38#include <iprt/test.h>
39#include <iprt/string.h>
40
41
42/**
43 * Format the time into a string using a static buffer.
44 */
45char *ToString(PRTTIME pTime)
46{
47 static char szBuf[128];
48 RTStrPrintf(szBuf, sizeof(szBuf), "%04d-%02d-%02dT%02u:%02u:%02u.%09u [YD%u WD%u UO%d F%#x]",
49 pTime->i32Year,
50 pTime->u8Month,
51 pTime->u8MonthDay,
52 pTime->u8Hour,
53 pTime->u8Minute,
54 pTime->u8Second,
55 pTime->u32Nanosecond,
56 pTime->u16YearDay,
57 pTime->u8WeekDay,
58 pTime->offUTC,
59 pTime->fFlags);
60 return szBuf;
61}
62
63#define CHECK_NZ(expr) do { if (!(expr)) { RTTestIFailed("at line %d: %#x\n", __LINE__, #expr); return RTTestSummaryAndDestroy(hTest); } } while (0)
64
65#define TEST_NS(ns) do {\
66 CHECK_NZ(RTTimeExplode(&T1, RTTimeSpecSetNano(&Ts1, ns))); \
67 RTTestIPrintf(RTTESTLVL_ALWAYS, "%RI64 ns - %s\n", ns, ToString(&T1)); \
68 CHECK_NZ(RTTimeImplode(&Ts2, &T1)); \
69 if (!RTTimeSpecIsEqual(&Ts2, &Ts1)) \
70 RTTestIFailed("FAILURE - %RI64 != %RI64, line no. %d\n", \
71 RTTimeSpecGetNano(&Ts2), RTTimeSpecGetNano(&Ts1), __LINE__); \
72 } while (0)
73
74#define TEST_SEC(sec) do {\
75 CHECK_NZ(RTTimeExplode(&T1, RTTimeSpecSetSeconds(&Ts1, sec))); \
76 RTTestIPrintf(RTTESTLVL_ALWAYS, "%RI64 sec - %s\n", sec, ToString(&T1)); \
77 CHECK_NZ(RTTimeImplode(&Ts2, &T1)); \
78 if (!RTTimeSpecIsEqual(&Ts2, &Ts1)) \
79 RTTestIFailed("FAILURE - %RI64 != %RI64, line no. %d\n", \
80 RTTimeSpecGetNano(&Ts2), RTTimeSpecGetNano(&Ts1), __LINE__); \
81 } while (0)
82
83#define CHECK_TIME(pTime, _i32Year, _u8Month, _u8MonthDay, _u8Hour, _u8Minute, _u8Second, _u32Nanosecond, _u16YearDay, _u8WeekDay, _offUTC, _fFlags)\
84 do { \
85 if ( (pTime)->i32Year != (_i32Year) \
86 || (pTime)->u8Month != (_u8Month) \
87 || (pTime)->u8WeekDay != (_u8WeekDay) \
88 || (pTime)->u16YearDay != (_u16YearDay) \
89 || (pTime)->u8MonthDay != (_u8MonthDay) \
90 || (pTime)->u8Hour != (_u8Hour) \
91 || (pTime)->u8Minute != (_u8Minute) \
92 || (pTime)->u8Second != (_u8Second) \
93 || (pTime)->u32Nanosecond != (_u32Nanosecond) \
94 || (pTime)->offUTC != (_offUTC) \
95 || (pTime)->fFlags != (_fFlags) \
96 ) \
97 { \
98 RTTestIFailed(" %s ; line no %d\n" \
99 "!= %04d-%02d-%02dT%02u-%02u-%02u.%09u [YD%u WD%u UO%d F%#x]\n", \
100 ToString(pTime), __LINE__, (_i32Year), (_u8Month), (_u8MonthDay), (_u8Hour), (_u8Minute), \
101 (_u8Second), (_u32Nanosecond), (_u16YearDay), (_u8WeekDay), (_offUTC), (_fFlags)); \
102 } \
103 else \
104 RTTestIPrintf(RTTESTLVL_ALWAYS, "=> %s\n", ToString(pTime)); \
105 } while (0)
106
107#define SET_TIME(pTime, _i32Year, _u8Month, _u8MonthDay, _u8Hour, _u8Minute, _u8Second, _u32Nanosecond, _u16YearDay, _u8WeekDay, _offUTC, _fFlags)\
108 do { \
109 (pTime)->i32Year = (_i32Year); \
110 (pTime)->u8Month = (_u8Month); \
111 (pTime)->u8WeekDay = (_u8WeekDay); \
112 (pTime)->u16YearDay = (_u16YearDay); \
113 (pTime)->u8MonthDay = (_u8MonthDay); \
114 (pTime)->u8Hour = (_u8Hour); \
115 (pTime)->u8Minute = (_u8Minute); \
116 (pTime)->u8Second = (_u8Second); \
117 (pTime)->u32Nanosecond = (_u32Nanosecond); \
118 (pTime)->offUTC = (_offUTC); \
119 (pTime)->fFlags = (_fFlags); \
120 RTTestIPrintf(RTTESTLVL_ALWAYS, " %s\n", ToString(pTime)); \
121 } while (0)
122
123
124int main()
125{
126 RTTIMESPEC Now;
127 RTTIMESPEC Ts1;
128 RTTIMESPEC Ts2;
129 RTTIME T1;
130 RTTIME T2;
131#ifdef RTTIME_INCL_TIMEVAL
132 struct timeval Tv1;
133 struct timeval Tv2;
134 struct timespec Tsp1;
135 struct timespec Tsp2;
136#endif
137 RTTEST hTest;
138
139 int rc = RTTestInitAndCreate("tstRTTimeSpec", &hTest);
140 if (rc)
141 return rc;
142
143 /*
144 * Simple test with current time.
145 */
146 RTTestSub(hTest, "Current time (UTC)");
147 CHECK_NZ(RTTimeNow(&Now));
148 CHECK_NZ(RTTimeExplode(&T1, &Now));
149 RTTestIPrintf(RTTESTLVL_ALWAYS, " %RI64 ns - %s\n", RTTimeSpecGetNano(&Now), ToString(&T1));
150 CHECK_NZ(RTTimeImplode(&Ts1, &T1));
151 if (!RTTimeSpecIsEqual(&Ts1, &Now))
152 RTTestIFailed("%RI64 != %RI64\n", RTTimeSpecGetNano(&Ts1), RTTimeSpecGetNano(&Now));
153
154 /*
155 * Simple test with current local time.
156 */
157 RTTestSub(hTest, "Current time (local)");
158 CHECK_NZ(RTTimeLocalNow(&Now));
159 CHECK_NZ(RTTimeExplode(&T1, &Now));
160 RTTestIPrintf(RTTESTLVL_ALWAYS, " %RI64 ns - %s\n", RTTimeSpecGetNano(&Now), ToString(&T1));
161 CHECK_NZ(RTTimeImplode(&Ts1, &T1));
162 if (!RTTimeSpecIsEqual(&Ts1, &Now))
163 RTTestIFailed("%RI64 != %RI64\n", RTTimeSpecGetNano(&Ts1), RTTimeSpecGetNano(&Now));
164
165 /*
166 * Some simple tests with fixed dates (just checking for smoke).
167 */
168 RTTestSub(hTest, "Smoke");
169 TEST_NS(INT64_C(0));
170 CHECK_TIME(&T1, 1970,01,01, 00,00,00, 0, 1, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
171 TEST_NS(INT64_C(86400000000000));
172 CHECK_TIME(&T1, 1970,01,02, 00,00,00, 0, 2, 4, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
173
174 TEST_NS(INT64_C(1));
175 CHECK_TIME(&T1, 1970,01,01, 00,00,00, 1, 1, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
176 TEST_NS(INT64_C(-1));
177 CHECK_TIME(&T1, 1969,12,31, 23,59,59,999999999, 365, 2, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
178
179 /*
180 * Test the limits.
181 */
182 RTTestSub(hTest, "Extremes");
183 TEST_NS(INT64_MAX);
184 TEST_NS(INT64_MIN);
185 TEST_SEC(1095379198);
186 CHECK_TIME(&T1, 2004, 9,16, 23,59,58, 0, 260, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_LEAP_YEAR);
187 TEST_SEC(1095379199);
188 CHECK_TIME(&T1, 2004, 9,16, 23,59,59, 0, 260, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_LEAP_YEAR);
189 TEST_SEC(1095379200);
190 CHECK_TIME(&T1, 2004, 9,17, 00,00,00, 0, 261, 4, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_LEAP_YEAR);
191 TEST_SEC(1095379201);
192 CHECK_TIME(&T1, 2004, 9,17, 00,00,01, 0, 261, 4, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_LEAP_YEAR);
193
194
195 /*
196 * Test normalization (UTC).
197 */
198 RTTestSub(hTest, "Normalization (UTC)");
199 /* simple */
200 CHECK_NZ(RTTimeNow(&Now));
201 CHECK_NZ(RTTimeExplode(&T1, &Now));
202 T2 = T1;
203 CHECK_NZ(RTTimeNormalize(&T1));
204 if (memcmp(&T1, &T2, sizeof(T1)))
205 RTTestIFailed("simple normalization failed\n");
206 CHECK_NZ(RTTimeImplode(&Ts1, &T1));
207 CHECK_NZ(RTTimeSpecIsEqual(&Ts1, &Now));
208
209 /* a few partial dates. */
210 memset(&T1, 0, sizeof(T1));
211 SET_TIME( &T1, 1970,01,01, 00,00,00, 0, 0, 0, 0, 0);
212 CHECK_NZ(RTTimeNormalize(&T1));
213 CHECK_TIME(&T1, 1970,01,01, 00,00,00, 0, 1, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
214
215 SET_TIME( &T1, 1970,00,00, 00,00,00, 1, 1, 0, 0, 0);
216 CHECK_NZ(RTTimeNormalize(&T1));
217 CHECK_TIME(&T1, 1970,01,01, 00,00,00, 1, 1, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
218
219 SET_TIME( &T1, 2007,12,06, 02,15,23, 1, 0, 0, 0, 0);
220 CHECK_NZ(RTTimeNormalize(&T1));
221 CHECK_TIME(&T1, 2007,12,06, 02,15,23, 1, 340, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
222
223 SET_TIME( &T1, 1968,01,30, 00,19,24, 5, 0, 0, 0, 0);
224 CHECK_NZ(RTTimeNormalize(&T1));
225 CHECK_TIME(&T1, 1968,01,30, 00,19,24, 5, 30, 1, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_LEAP_YEAR);
226
227 SET_TIME( &T1, 1969,01,31, 00, 9, 2, 7, 0, 0, 0, 0);
228 CHECK_NZ(RTTimeNormalize(&T1));
229 CHECK_TIME(&T1, 1969,01,31, 00, 9, 2, 7, 31, 4, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
230
231 SET_TIME( &T1, 1969,03,31, 00, 9, 2, 7, 0, 0, 0, 0);
232 CHECK_NZ(RTTimeNormalize(&T1));
233 CHECK_TIME(&T1, 1969,03,31, 00, 9, 2, 7, 90, 0, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
234
235 SET_TIME( &T1, 1969,12,31, 00,00,00, 9, 0, 0, 0, 0);
236 CHECK_NZ(RTTimeNormalize(&T1));
237 CHECK_TIME(&T1, 1969,12,31, 00,00,00, 9, 365, 2, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
238
239 SET_TIME( &T1, 1969,12,30, 00,00,00, 30, 0, 0, 0, 0);
240 CHECK_NZ(RTTimeNormalize(&T1));
241 CHECK_TIME(&T1, 1969,12,30, 00,00,00, 30, 364, 1, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
242
243 SET_TIME( &T1, 1969,00,00, 00,00,00, 30, 363, 0, 0, 0);
244 CHECK_NZ(RTTimeNormalize(&T1));
245 CHECK_TIME(&T1, 1969,12,29, 00,00,00, 30, 363, 0, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
246
247 SET_TIME( &T1, 1969,00,00, 00,00,00, 30, 362, 6, 0, 0);
248 CHECK_NZ(RTTimeNormalize(&T1));
249 CHECK_TIME(&T1, 1969,12,28, 00,00,00, 30, 362, 6, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
250
251 SET_TIME( &T1, 1969,12,27, 00,00,00, 30, 0, 5, 0, 0);
252 CHECK_NZ(RTTimeNormalize(&T1));
253 CHECK_TIME(&T1, 1969,12,27, 00,00,00, 30, 361, 5, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
254
255 SET_TIME( &T1, 1969,00,00, 00,00,00, 30, 360, 0, 0, 0);
256 CHECK_NZ(RTTimeNormalize(&T1));
257 CHECK_TIME(&T1, 1969,12,26, 00,00,00, 30, 360, 4, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
258
259 SET_TIME( &T1, 1969,12,25, 00,00,00, 12, 0, 0, 0, 0);
260 CHECK_NZ(RTTimeNormalize(&T1));
261 CHECK_TIME(&T1, 1969,12,25, 00,00,00, 12, 359, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
262
263 SET_TIME( &T1, 1969,12,24, 00,00,00, 16, 0, 0, 0, 0);
264 CHECK_NZ(RTTimeNormalize(&T1));
265 CHECK_TIME(&T1, 1969,12,24, 00,00,00, 16, 358, 2, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
266
267 /* outside the year table range */
268 SET_TIME( &T1, 1200,01,30, 00,00,00, 2, 0, 0, 0, 0);
269 CHECK_NZ(RTTimeNormalize(&T1));
270 CHECK_TIME(&T1, 1200,01,30, 00,00,00, 2, 30, 6, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_LEAP_YEAR);
271
272 SET_TIME( &T1, 2555,11,29, 00,00,00, 2, 0, 0, 0, 0);
273 CHECK_NZ(RTTimeNormalize(&T1));
274 CHECK_TIME(&T1, 2555,11,29, 00,00,00, 2, 333, 5, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
275
276 SET_TIME( &T1, 2555,00,00, 00,00,00, 3, 333, 0, 0, 0);
277 CHECK_NZ(RTTimeNormalize(&T1));
278 CHECK_TIME(&T1, 2555,11,29, 00,00,00, 3, 333, 5, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
279
280 /* time overflow */
281 SET_TIME( &T1, 1969,12,30, 255,255,255, UINT32_MAX, 364, 0, 0, 0);
282 CHECK_NZ(RTTimeNormalize(&T1));
283 CHECK_TIME(&T1, 1970,01, 9, 19,19,19,294967295, 9, 4, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
284
285 /* date overflow */
286 SET_TIME( &T1, 2007,11,36, 02,15,23, 1, 0, 0, 0, 0);
287 CHECK_NZ(RTTimeNormalize(&T1));
288 CHECK_TIME(&T1, 2007,12,06, 02,15,23, 1, 340, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
289
290 SET_TIME( &T1, 2007,10,67, 02,15,23, 1, 0, 0, 0, 0);
291 CHECK_NZ(RTTimeNormalize(&T1));
292 CHECK_TIME(&T1, 2007,12,06, 02,15,23, 1, 340, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
293
294 SET_TIME( &T1, 2007,10,98, 02,15,23, 1, 0, 0, 0, 0);
295 CHECK_NZ(RTTimeNormalize(&T1));
296 CHECK_TIME(&T1, 2008,01,06, 02,15,23, 1, 6, 6, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_LEAP_YEAR);
297
298 SET_TIME( &T1, 2006,24,06, 02,15,23, 1, 0, 0, 0, 0);
299 CHECK_NZ(RTTimeNormalize(&T1));
300 CHECK_TIME(&T1, 2007,12,06, 02,15,23, 1, 340, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
301
302 SET_TIME( &T1, 2003,60,37, 02,15,23, 1, 0, 0, 0, 0);
303 CHECK_NZ(RTTimeNormalize(&T1));
304 CHECK_TIME(&T1, 2008,01,06, 02,15,23, 1, 6, 6, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_LEAP_YEAR);
305
306 SET_TIME( &T1, 2003,00,00, 02,15,23, 1,1801, 0, 0, 0);
307 CHECK_NZ(RTTimeNormalize(&T1));
308 CHECK_TIME(&T1, 2007,12,06, 02,15,23, 1, 340, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
309
310 /*
311 * Conversions.
312 */
313#define CHECK_NSEC(Ts1, T2) \
314 do { \
315 RTTIMESPEC TsTmp; \
316 RTTESTI_CHECK_MSG( RTTimeSpecGetNano(&(Ts1)) == RTTimeSpecGetNano(RTTimeImplode(&TsTmp, &(T2))), \
317 ("line %d: %RI64, %RI64\n", __LINE__, \
318 RTTimeSpecGetNano(&(Ts1)), RTTimeSpecGetNano(RTTimeImplode(&TsTmp, &(T2)))) ); \
319 } while (0)
320 RTTestSub(hTest, "Conversions, positive");
321 SET_TIME(&T1, 1980,01,01, 00,00,00, 0, 1, 1, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_LEAP_YEAR);
322 RTTESTI_CHECK(RTTimeSpecSetDosSeconds(&Ts2, 0) == &Ts2);
323 RTTESTI_CHECK(RTTimeSpecGetDosSeconds(&Ts2) == 0);
324 CHECK_NSEC(Ts2, T1);
325
326 SET_TIME(&T1, 1980,01,01, 00,00,00, 0, 1, 1, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_LEAP_YEAR);
327 RTTESTI_CHECK(RTTimeSpecSetNtTime(&Ts2, INT64_C(119600064000000000)) == &Ts2);
328 RTTESTI_CHECK(RTTimeSpecGetNtTime(&Ts2) == INT64_C(119600064000000000));
329 CHECK_NSEC(Ts2, T1);
330
331 SET_TIME(&T1, 1970,01,01, 00,00,01, 0, 1, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
332 RTTESTI_CHECK(RTTimeSpecSetSeconds(&Ts2, 1) == &Ts2);
333 RTTESTI_CHECK(RTTimeSpecGetSeconds(&Ts2) == 1);
334 CHECK_NSEC(Ts2, T1);
335
336 SET_TIME(&T1, 1970,01,01, 00,00,01, 0, 1, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
337 RTTESTI_CHECK(RTTimeSpecSetMilli(&Ts2, 1000) == &Ts2);
338 RTTESTI_CHECK(RTTimeSpecGetMilli(&Ts2) == 1000);
339 CHECK_NSEC(Ts2, T1);
340
341 SET_TIME(&T1, 1970,01,01, 00,00,01, 0, 1, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
342 RTTESTI_CHECK(RTTimeSpecSetMicro(&Ts2, 1000000) == &Ts2);
343 RTTESTI_CHECK(RTTimeSpecGetMicro(&Ts2) == 1000000);
344 CHECK_NSEC(Ts2, T1);
345
346 SET_TIME(&T1, 1970,01,01, 00,00,01, 0, 1, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
347 RTTESTI_CHECK(RTTimeSpecSetNano(&Ts2, 1000000000) == &Ts2);
348 RTTESTI_CHECK(RTTimeSpecGetNano(&Ts2) == 1000000000);
349 CHECK_NSEC(Ts2, T1);
350
351#ifdef RTTIME_INCL_TIMEVAL
352 SET_TIME(&T1, 1970,01,01, 00,00,01, 5000, 1, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
353 Tv1.tv_sec = 1;
354 Tv1.tv_usec = 5;
355 RTTESTI_CHECK(RTTimeSpecSetTimeval(&Ts2, &Tv1) == &Ts2);
356 RTTESTI_CHECK(RTTimeSpecGetMicro(&Ts2) == 1000005);
357 CHECK_NSEC(Ts2, T1);
358 RTTESTI_CHECK(RTTimeSpecGetTimeval(&Ts2, &Tv2) == &Tv2);
359 RTTESTI_CHECK(Tv1.tv_sec == Tv2.tv_sec); RTTESTI_CHECK(Tv1.tv_usec == Tv2.tv_usec);
360#endif
361
362#ifdef RTTIME_INCL_TIMESPEC
363 SET_TIME(&T1, 1970,01,01, 00,00,01, 5, 1, 3, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
364 Tsp1.tv_sec = 1;
365 Tsp1.tv_nsec = 5;
366 RTTESTI_CHECK(RTTimeSpecSetTimespec(&Ts2, &Tsp1) == &Ts2);
367 RTTESTI_CHECK(RTTimeSpecGetNano(&Ts2) == 1000000005);
368 CHECK_NSEC(Ts2, T1);
369 RTTESTI_CHECK(RTTimeSpecGetTimespec(&Ts2, &Tsp2) == &Tsp2);
370 RTTESTI_CHECK(Tsp1.tv_sec == Tsp2.tv_sec); RTTESTI_CHECK(Tsp1.tv_nsec == Tsp2.tv_nsec);
371#endif
372
373
374 RTTestSub(hTest, "Conversions, negative");
375
376#ifdef RTTIME_INCL_TIMEVAL
377 SET_TIME(&T1, 1969,12,31, 23,59,58,999995000, 365, 2, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
378 Tv1.tv_sec = -2;
379 Tv1.tv_usec = 999995;
380 RTTESTI_CHECK(RTTimeSpecSetTimeval(&Ts2, &Tv1) == &Ts2);
381 RTTESTI_CHECK_MSG(RTTimeSpecGetMicro(&Ts2) == -1000005, ("%RI64\n", RTTimeSpecGetMicro(&Ts2)));
382 CHECK_NSEC(Ts2, T1);
383 RTTESTI_CHECK(RTTimeSpecGetTimeval(&Ts2, &Tv2) == &Tv2);
384 RTTESTI_CHECK(Tv1.tv_sec == Tv2.tv_sec); RTTESTI_CHECK(Tv1.tv_usec == Tv2.tv_usec);
385#endif
386
387#ifdef RTTIME_INCL_TIMESPEC
388 SET_TIME(&T1, 1969,12,31, 23,59,58,999999995, 365, 2, 0, RTTIME_FLAGS_TYPE_UTC | RTTIME_FLAGS_COMMON_YEAR);
389 Tsp1.tv_sec = -2;
390 Tsp1.tv_nsec = 999999995;
391 RTTESTI_CHECK(RTTimeSpecSetTimespec(&Ts2, &Tsp1) == &Ts2);
392 RTTESTI_CHECK_MSG(RTTimeSpecGetNano(&Ts2) == -1000000005, ("%RI64\n", RTTimeSpecGetMicro(&Ts2)));
393 CHECK_NSEC(Ts2, T1);
394 RTTESTI_CHECK(RTTimeSpecGetTimespec(&Ts2, &Tsp2) == &Tsp2);
395 RTTESTI_CHECK(Tsp1.tv_sec == Tsp2.tv_sec); RTTESTI_CHECK(Tsp1.tv_nsec == Tsp2.tv_nsec);
396#endif
397
398 /*
399 * Summary
400 */
401 return RTTestSummaryAndDestroy(hTest);
402}
403
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette