VirtualBox

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

Last change on this file since 59983 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

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