kernel32: Implement GetSystemTimePreciseAsFileTime.
[wine.git] / dlls / kernel32 / tests / time.c
blobd205174859ddbe44083a7268318496c0af39e94e
1 /*
2 * Unit test suite for time functions
4 * Copyright 2004 Uwe Bonnes
5 * Copyright 2007 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
23 #include "winbase.h"
24 #include "winnls.h"
26 static BOOL (WINAPI *pTzSpecificLocalTimeToSystemTime)(LPTIME_ZONE_INFORMATION, LPSYSTEMTIME, LPSYSTEMTIME);
27 static BOOL (WINAPI *pSystemTimeToTzSpecificLocalTime)(LPTIME_ZONE_INFORMATION, LPSYSTEMTIME, LPSYSTEMTIME);
28 static int (WINAPI *pGetCalendarInfoA)(LCID,CALID,CALTYPE,LPSTR,int,LPDWORD);
29 static int (WINAPI *pGetCalendarInfoW)(LCID,CALID,CALTYPE,LPWSTR,int,LPDWORD);
30 static DWORD (WINAPI *pGetDynamicTimeZoneInformation)(DYNAMIC_TIME_ZONE_INFORMATION*);
31 static void (WINAPI *pGetSystemTimePreciseAsFileTime)(LPFILETIME);
33 #define SECSPERMIN 60
34 #define SECSPERDAY 86400
35 /* 1601 to 1970 is 369 years plus 89 leap days */
36 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
37 #define TICKSPERSEC 10000000
38 #define TICKSPERMSEC 10000
39 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
42 #define NEWYEAR_1980_HI 0x01a8e79f
43 #define NEWYEAR_1980_LO 0xe1d58000
45 #define MAYDAY_2002_HI 0x01c1f107
46 #define MAYDAY_2002_LO 0xb82b6000
48 #define ATIME_HI 0x1c2349b
49 #define ATIME_LOW 0x580716b0
51 #define LOCAL_ATIME_HI 0x01c23471
52 #define LOCAL_ATIME_LOW 0x6f310eb0
54 #define DOS_DATE(y,m,d) ( (((y)-1980)<<9) | ((m)<<5) | (d) )
55 #define DOS_TIME(h,m,s) ( ((h)<<11) | ((m)<<5) | ((s)>>1) )
58 #define SETUP_1980(st) \
59 (st).wYear = 1980; \
60 (st).wMonth = 1; \
61 (st).wDay = 1; \
62 (st).wHour = 0; \
63 (st).wMinute = 0; \
64 (st).wSecond = 0; \
65 (st).wMilliseconds = 0;
67 #define SETUP_2002(st) \
68 (st).wYear = 2002; \
69 (st).wMonth = 5; \
70 (st).wDay = 1; \
71 (st).wHour = 12; \
72 (st).wMinute = 0; \
73 (st).wSecond = 0; \
74 (st).wMilliseconds = 0;
76 #define SETUP_ATIME(st) \
77 (st).wYear = 2002; \
78 (st).wMonth = 7; \
79 (st).wDay = 26; \
80 (st).wHour = 11; \
81 (st).wMinute = 55; \
82 (st).wSecond = 32; \
83 (st).wMilliseconds = 123;
85 #define SETUP_ZEROTIME(st) \
86 (st).wYear = 1601; \
87 (st).wMonth = 1; \
88 (st).wDay = 1; \
89 (st).wHour = 0; \
90 (st).wMinute = 0; \
91 (st).wSecond = 0; \
92 (st).wMilliseconds = 0;
94 #define SETUP_EARLY(st) \
95 (st).wYear = 1600; \
96 (st).wMonth = 12; \
97 (st).wDay = 31; \
98 (st).wHour = 23; \
99 (st).wMinute = 59; \
100 (st).wSecond = 59; \
101 (st).wMilliseconds = 999;
104 static void test_conversions(void)
106 FILETIME ft;
107 SYSTEMTIME st;
109 memset(&ft,0,sizeof ft);
111 SetLastError(0xdeadbeef);
112 SETUP_EARLY(st)
113 ok (!SystemTimeToFileTime(&st, &ft), "Conversion succeeded EARLY\n");
114 ok (GetLastError() == ERROR_INVALID_PARAMETER ||
115 GetLastError() == 0xdeadbeef, /* win9x */
116 "EARLY should be INVALID\n");
118 SETUP_ZEROTIME(st)
119 ok (SystemTimeToFileTime(&st, &ft), "Conversion failed ZERO_TIME\n");
120 ok( (!((ft.dwHighDateTime != 0) || (ft.dwLowDateTime != 0))),
121 "Wrong time for ATIME: %08x %08x (correct %08x %08x)\n",
122 ft.dwLowDateTime, ft.dwHighDateTime, 0, 0);
125 SETUP_ATIME(st)
126 ok (SystemTimeToFileTime(&st,&ft), "Conversion Failed ATIME\n");
127 ok( (!((ft.dwHighDateTime != ATIME_HI) || (ft.dwLowDateTime!=ATIME_LOW))),
128 "Wrong time for ATIME: %08x %08x (correct %08x %08x)\n",
129 ft.dwLowDateTime, ft.dwHighDateTime, ATIME_LOW, ATIME_HI);
132 SETUP_2002(st)
133 ok (SystemTimeToFileTime(&st, &ft), "Conversion failed 2002\n");
135 ok( (!((ft.dwHighDateTime != MAYDAY_2002_HI) ||
136 (ft.dwLowDateTime!=MAYDAY_2002_LO))),
137 "Wrong time for 2002 %08x %08x (correct %08x %08x)\n", ft.dwLowDateTime,
138 ft.dwHighDateTime, MAYDAY_2002_LO, MAYDAY_2002_HI);
141 SETUP_1980(st)
142 ok((SystemTimeToFileTime(&st, &ft)), "Conversion failed 1980\n");
144 ok( (!((ft.dwHighDateTime!=NEWYEAR_1980_HI) ||
145 (ft.dwLowDateTime!=NEWYEAR_1980_LO))) ,
146 "Wrong time for 1980 %08x %08x (correct %08x %08x)\n", ft.dwLowDateTime,
147 ft.dwHighDateTime, NEWYEAR_1980_LO,NEWYEAR_1980_HI );
149 ok(DosDateTimeToFileTime(DOS_DATE(1980,1,1),DOS_TIME(0,0,0),&ft),
150 "DosDateTimeToFileTime() failed\n");
152 ok( (!((ft.dwHighDateTime!=NEWYEAR_1980_HI) ||
153 (ft.dwLowDateTime!=NEWYEAR_1980_LO))),
154 "Wrong time DosDateTimeToFileTime %08x %08x (correct %08x %08x)\n",
155 ft.dwHighDateTime, ft.dwLowDateTime, NEWYEAR_1980_HI, NEWYEAR_1980_LO);
159 static void test_invalid_arg(void)
161 FILETIME ft;
162 SYSTEMTIME st;
165 /* Invalid argument checks */
167 memset(&ft,0,sizeof ft);
168 ok( DosDateTimeToFileTime(DOS_DATE(1980,1,1),DOS_TIME(0,0,0),&ft), /* this is 1 Jan 1980 00:00:00 */
169 "DosDateTimeToFileTime() failed\n");
171 ok( (ft.dwHighDateTime==NEWYEAR_1980_HI) && (ft.dwLowDateTime==NEWYEAR_1980_LO),
172 "filetime for 1/1/80 00:00:00 was %08x %08x\n", ft.dwHighDateTime, ft.dwLowDateTime);
174 /* now check SystemTimeToFileTime */
175 memset(&ft,0,sizeof ft);
178 /* try with a bad month */
179 SETUP_1980(st)
180 st.wMonth = 0;
182 ok( !SystemTimeToFileTime(&st, &ft), "bad month\n");
184 /* with a bad hour */
185 SETUP_1980(st)
186 st.wHour = 24;
188 ok( !SystemTimeToFileTime(&st, &ft), "bad hour\n");
190 /* with a bad minute */
191 SETUP_1980(st)
192 st.wMinute = 60;
194 ok( !SystemTimeToFileTime(&st, &ft), "bad minute\n");
197 static LONGLONG system_time_to_minutes(const SYSTEMTIME *st)
199 BOOL ret;
200 FILETIME ft;
201 LONGLONG minutes;
203 SetLastError(0xdeadbeef);
204 ret = SystemTimeToFileTime(st, &ft);
205 ok(ret, "SystemTimeToFileTime error %u\n", GetLastError());
207 minutes = ((LONGLONG)ft.dwHighDateTime << 32) + ft.dwLowDateTime;
208 minutes /= (LONGLONG)600000000; /* convert to minutes */
209 return minutes;
212 static LONG get_tz_bias(const TIME_ZONE_INFORMATION *tzinfo, DWORD tz_id)
214 switch (tz_id)
216 case TIME_ZONE_ID_DAYLIGHT:
217 if (memcmp(&tzinfo->StandardDate, &tzinfo->DaylightDate, sizeof(tzinfo->DaylightDate)) != 0)
218 return tzinfo->DaylightBias;
219 /* fall through */
221 case TIME_ZONE_ID_STANDARD:
222 return tzinfo->StandardBias;
224 default:
225 trace("unknown time zone id %d\n", tz_id);
226 /* fall through */
227 case TIME_ZONE_ID_UNKNOWN:
228 return 0;
232 static void test_GetTimeZoneInformation(void)
234 char std_name[32], dlt_name[32];
235 TIME_ZONE_INFORMATION tzinfo, tzinfo1;
236 BOOL res;
237 DWORD tz_id;
238 SYSTEMTIME st, current, utc, local;
239 FILETIME l_ft, s_ft;
240 LONGLONG l_time, s_time;
241 LONG diff;
243 GetSystemTime(&st);
244 s_time = system_time_to_minutes(&st);
246 SetLastError(0xdeadbeef);
247 res = SystemTimeToFileTime(&st, &s_ft);
248 ok(res, "SystemTimeToFileTime error %u\n", GetLastError());
249 SetLastError(0xdeadbeef);
250 res = FileTimeToLocalFileTime(&s_ft, &l_ft);
251 ok(res, "FileTimeToLocalFileTime error %u\n", GetLastError());
252 SetLastError(0xdeadbeef);
253 res = FileTimeToSystemTime(&l_ft, &local);
254 ok(res, "FileTimeToSystemTime error %u\n", GetLastError());
255 l_time = system_time_to_minutes(&local);
257 tz_id = GetTimeZoneInformation(&tzinfo);
258 ok(tz_id != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
260 trace("tz_id %u (%s)\n", tz_id,
261 tz_id == TIME_ZONE_ID_DAYLIGHT ? "TIME_ZONE_ID_DAYLIGHT" :
262 (tz_id == TIME_ZONE_ID_STANDARD ? "TIME_ZONE_ID_STANDARD" :
263 (tz_id == TIME_ZONE_ID_UNKNOWN ? "TIME_ZONE_ID_UNKNOWN" :
264 "TIME_ZONE_ID_INVALID")));
266 WideCharToMultiByte(CP_ACP, 0, tzinfo.StandardName, -1, std_name, sizeof(std_name), NULL, NULL);
267 WideCharToMultiByte(CP_ACP, 0, tzinfo.DaylightName, -1, dlt_name, sizeof(dlt_name), NULL, NULL);
268 trace("bias %d, %s - %s\n", tzinfo.Bias, std_name, dlt_name);
269 trace("standard (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n",
270 tzinfo.StandardDate.wDay, tzinfo.StandardDate.wMonth,
271 tzinfo.StandardDate.wYear, tzinfo.StandardDate.wDayOfWeek,
272 tzinfo.StandardDate.wHour, tzinfo.StandardDate.wMinute,
273 tzinfo.StandardDate.wSecond, tzinfo.StandardDate.wMilliseconds,
274 tzinfo.StandardBias);
275 trace("daylight (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n",
276 tzinfo.DaylightDate.wDay, tzinfo.DaylightDate.wMonth,
277 tzinfo.DaylightDate.wYear, tzinfo.DaylightDate.wDayOfWeek,
278 tzinfo.DaylightDate.wHour, tzinfo.DaylightDate.wMinute,
279 tzinfo.DaylightDate.wSecond, tzinfo.DaylightDate.wMilliseconds,
280 tzinfo.DaylightBias);
282 diff = (LONG)(s_time - l_time);
283 ok(diff == tzinfo.Bias + get_tz_bias(&tzinfo, tz_id),
284 "system/local diff %d != tz bias %d\n",
285 diff, tzinfo.Bias + get_tz_bias(&tzinfo, tz_id));
287 ok(SetEnvironmentVariableA("TZ","GMT0") != 0,
288 "SetEnvironmentVariableA failed\n");
289 res = GetTimeZoneInformation(&tzinfo1);
290 ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
292 ok(((tzinfo.Bias == tzinfo1.Bias) &&
293 (tzinfo.StandardBias == tzinfo1.StandardBias) &&
294 (tzinfo.DaylightBias == tzinfo1.DaylightBias)),
295 "Bias influenced by TZ variable\n");
296 ok(SetEnvironmentVariableA("TZ",NULL) != 0,
297 "SetEnvironmentVariableA failed\n");
299 if (!pSystemTimeToTzSpecificLocalTime)
301 win_skip("SystemTimeToTzSpecificLocalTime not available\n");
302 return;
305 diff = get_tz_bias(&tzinfo, tz_id);
307 utc = st;
308 SetLastError(0xdeadbeef);
309 res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &current);
310 if (!res && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
312 win_skip("SystemTimeToTzSpecificLocalTime is not implemented\n");
313 return;
316 ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
317 s_time = system_time_to_minutes(&current);
319 tzinfo.StandardBias -= 123;
320 tzinfo.DaylightBias += 456;
322 res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
323 ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
324 l_time = system_time_to_minutes(&local);
325 ok(l_time - s_time == diff - get_tz_bias(&tzinfo, tz_id), "got %d, expected %d\n",
326 (LONG)(l_time - s_time), diff - get_tz_bias(&tzinfo, tz_id));
328 /* pretend that there is no transition dates */
329 tzinfo.DaylightDate.wDay = 0;
330 tzinfo.DaylightDate.wMonth = 0;
331 tzinfo.DaylightDate.wYear = 0;
332 tzinfo.StandardDate.wDay = 0;
333 tzinfo.StandardDate.wMonth = 0;
334 tzinfo.StandardDate.wYear = 0;
336 res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
337 ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
338 l_time = system_time_to_minutes(&local);
339 ok(l_time - s_time == diff, "got %d, expected %d\n",
340 (LONG)(l_time - s_time), diff);
342 /* test 23:01, 31st of December date */
343 memset(&tzinfo, 0, sizeof(tzinfo));
344 tzinfo.StandardDate.wMonth = 10;
345 tzinfo.StandardDate.wDay = 5;
346 tzinfo.StandardDate.wHour = 2;
347 tzinfo.StandardDate.wMinute = 0;
348 tzinfo.DaylightDate.wMonth = 4;
349 tzinfo.DaylightDate.wDay = 1;
350 tzinfo.DaylightDate.wHour = 2;
351 tzinfo.Bias = 0;
352 tzinfo.StandardBias = 0;
353 tzinfo.DaylightBias = -60;
354 utc.wYear = 2012;
355 utc.wMonth = 12;
356 utc.wDay = 31;
357 utc.wHour = 23;
358 utc.wMinute = 1;
359 res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
360 ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
361 ok(local.wYear==2012 && local.wMonth==12 && local.wDay==31 && local.wHour==23 && local.wMinute==1,
362 "got (%d-%d-%d %02d:%02d), expected (2012-12-31 23:01)\n",
363 local.wYear, local.wMonth, local.wDay, local.wHour, local.wMinute);
366 static void test_FileTimeToSystemTime(void)
368 FILETIME ft;
369 SYSTEMTIME st;
370 ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
371 BOOL ret;
373 ft.dwHighDateTime = 0;
374 ft.dwLowDateTime = 0;
375 ret = FileTimeToSystemTime(&ft, &st);
376 ok( ret,
377 "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
378 ok(((st.wYear == 1601) && (st.wMonth == 1) && (st.wDay == 1) &&
379 (st.wHour == 0) && (st.wMinute == 0) && (st.wSecond == 0) &&
380 (st.wMilliseconds == 0)),
381 "Got Year %4d Month %2d Day %2d\n", st.wYear, st.wMonth, st.wDay);
383 ft.dwHighDateTime = (UINT)(time >> 32);
384 ft.dwLowDateTime = (UINT)time;
385 ret = FileTimeToSystemTime(&ft, &st);
386 ok( ret,
387 "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
388 ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
389 (st.wHour == 0) && (st.wMinute == 0) && (st.wSecond == 1) &&
390 (st.wMilliseconds == 0)),
391 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
392 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
393 st.wMilliseconds);
396 static void test_FileTimeToLocalFileTime(void)
398 FILETIME ft, lft;
399 SYSTEMTIME st;
400 TIME_ZONE_INFORMATION tzinfo;
401 DWORD res = GetTimeZoneInformation(&tzinfo);
402 ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970 +
403 (LONGLONG)(tzinfo.Bias +
404 ( res == TIME_ZONE_ID_STANDARD ? tzinfo.StandardBias :
405 ( res == TIME_ZONE_ID_DAYLIGHT ? tzinfo.DaylightBias : 0 ))) *
406 SECSPERMIN *TICKSPERSEC;
407 BOOL ret;
409 ok( res != TIME_ZONE_ID_INVALID , "GetTimeZoneInformation failed\n");
410 ft.dwHighDateTime = (UINT)(time >> 32);
411 ft.dwLowDateTime = (UINT)time;
412 ret = FileTimeToLocalFileTime(&ft, &lft);
413 ok( ret,
414 "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
415 FileTimeToSystemTime(&lft, &st);
416 ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
417 (st.wHour == 0) && (st.wMinute == 0) && (st.wSecond == 1) &&
418 (st.wMilliseconds == 0)),
419 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
420 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
421 st.wMilliseconds);
423 ok(SetEnvironmentVariableA("TZ","GMT") != 0,
424 "SetEnvironmentVariableA failed\n");
425 ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
426 ret = FileTimeToLocalFileTime(&ft, &lft);
427 ok( ret,
428 "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
429 FileTimeToSystemTime(&lft, &st);
430 ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
431 (st.wHour == 0) && (st.wMinute == 0) && (st.wSecond == 1) &&
432 (st.wMilliseconds == 0)),
433 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
434 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
435 st.wMilliseconds);
436 ok(SetEnvironmentVariableA("TZ",NULL) != 0,
437 "SetEnvironmentVariableA failed\n");
440 typedef struct {
441 int nr; /* test case number for easier lookup */
442 TIME_ZONE_INFORMATION *ptz; /* ptr to timezone */
443 SYSTEMTIME slt; /* system/local time to convert */
444 WORD ehour; /* expected hour */
445 } TZLT2ST_case;
447 static void test_TzSpecificLocalTimeToSystemTime(void)
449 TIME_ZONE_INFORMATION tzE, tzW, tzS;
450 SYSTEMTIME result;
451 int i, j, year;
453 if (!pTzSpecificLocalTimeToSystemTime || !pSystemTimeToTzSpecificLocalTime)
455 win_skip("TzSpecificLocalTimeToSystemTime or SystemTimeToTzSpecificLocalTime not available\n");
456 return;
459 ZeroMemory( &tzE, sizeof(tzE));
460 ZeroMemory( &tzW, sizeof(tzW));
461 ZeroMemory( &tzS, sizeof(tzS));
462 /* timezone Eastern hemisphere */
463 tzE.Bias=-600;
464 tzE.StandardBias=0;
465 tzE.DaylightBias=-60;
466 tzE.StandardDate.wMonth=10;
467 tzE.StandardDate.wDayOfWeek=0; /* Sunday */
468 tzE.StandardDate.wDay=5; /* last (Sunday) of the month */
469 tzE.StandardDate.wHour=3;
470 tzE.DaylightDate.wMonth=3;
471 tzE.DaylightDate.wDay=5;
472 tzE.DaylightDate.wHour=2;
473 /* timezone Western hemisphere */
474 tzW.Bias=240;
475 tzW.StandardBias=0;
476 tzW.DaylightBias=-60;
477 tzW.StandardDate.wMonth=10;
478 tzW.StandardDate.wDayOfWeek=0; /* Sunday */
479 tzW.StandardDate.wDay=4; /* 4th (Sunday) of the month */
480 tzW.StandardDate.wHour=2;
481 tzW.DaylightDate.wMonth=4;
482 tzW.DaylightDate.wDay=1;
483 tzW.DaylightDate.wHour=2;
484 /* timezone Southern hemisphere */
485 tzS.Bias=240;
486 tzS.StandardBias=0;
487 tzS.DaylightBias=-60;
488 tzS.StandardDate.wMonth=4;
489 tzS.StandardDate.wDayOfWeek=0; /*Sunday */
490 tzS.StandardDate.wDay=1; /* 1st (Sunday) of the month */
491 tzS.StandardDate.wHour=2;
492 tzS.DaylightDate.wMonth=10;
493 tzS.DaylightDate.wDay=4;
494 tzS.DaylightDate.wHour=2;
495 /*tests*/
496 /* TzSpecificLocalTimeToSystemTime */
497 { TZLT2ST_case cases[] = {
498 /* standard->daylight transition */
499 { 1, &tzE, {2004,3,-1,28,1,0,0,0}, 15 },
500 { 2, &tzE, {2004,3,-1,28,1,59,59,999}, 15},
501 { 3, &tzE, {2004,3,-1,28,2,0,0,0}, 15},
502 /* daylight->standard transition */
503 { 4, &tzE, {2004,10,-1,31,2,0,0,0} , 15 },
504 { 5, &tzE, {2004,10,-1,31,2,59,59,999}, 15 },
505 { 6, &tzE, {2004,10,-1,31,3,0,0,0}, 17 },
506 /* West and with fixed weekday of the month */
507 { 7, &tzW, {2004,4,-1,4,1,0,0,0}, 5},
508 { 8, &tzW, {2004,4,-1,4,1,59,59,999}, 5},
509 { 9, &tzW, {2004,4,-1,4,2,0,0,0}, 5},
510 { 10, &tzW, {2004,10,-1,24,1,0,0,0}, 4},
511 { 11, &tzW, {2004,10,-1,24,1,59,59,999}, 4},
512 { 12, &tzW, {2004,10,-1,24,2,0,0,0 }, 6},
513 /* and now South */
514 { 13, &tzS, {2004,4,-1,4,1,0,0,0}, 4},
515 { 14, &tzS, {2004,4,-1,4,1,59,59,999}, 4},
516 { 15, &tzS, {2004,4,-1,4,2,0,0,0}, 6},
517 { 16, &tzS, {2004,10,-1,24,1,0,0,0}, 5},
518 { 17, &tzS, {2004,10,-1,24,1,59,59,999}, 5},
519 { 18, &tzS, {2004,10,-1,24,2,0,0,0}, 5},
522 /* days of transitions to put into the cases array */
523 int yeardays[][6]=
525 {28,31,4,24,4,24} /* 1999 */
526 , {26,29,2,22,2,22} /* 2000 */
527 , {25,28,1,28,1,28} /* 2001 */
528 , {31,27,7,27,7,27} /* 2002 */
529 , {30,26,6,26,6,26} /* 2003 */
530 , {28,31,4,24,4,24} /* 2004 */
531 , {27,30,3,23,3,23} /* 2005 */
532 , {26,29,2,22,2,22} /* 2006 */
533 , {25,28,1,28,1,28} /* 2007 */
534 , {30,26,6,26,6,26} /* 2008 */
535 , {29,25,5,25,5,25} /* 2009 */
536 , {28,31,4,24,4,24} /* 2010 */
537 , {27,30,3,23,3,23} /* 2011 */
538 , {25,28,1,28,1,28} /* 2012 */
539 , {31,27,7,27,7,27} /* 2013 */
540 , {30,26,6,26,6,26} /* 2014 */
541 , {29,25,5,25,5,25} /* 2015 */
542 , {27,30,3,23,3,23} /* 2016 */
543 , {26,29,2,22,2,22} /* 2017 */
544 , {25,28,1,28,1,28} /* 2018 */
545 , {31,27,7,27,7,27} /* 2019 */
546 ,{0}
548 for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
549 for (i=0; cases[i].nr; i++) {
550 if(i) cases[i].nr += 18;
551 cases[i].slt.wYear = year;
552 cases[i].slt.wDay = yeardays[j][i/3];
553 pTzSpecificLocalTimeToSystemTime( cases[i].ptz, &(cases[i].slt), &result);
554 ok( result.wHour == cases[i].ehour,
555 "Test TzSpecificLocalTimeToSystemTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n",
556 cases[i].nr, result.wYear, result.wMonth, result.wDay,
557 result.wHour, result.wMinute, cases[i].ehour);
561 /* SystemTimeToTzSpecificLocalTime */
562 { TZLT2ST_case cases[] = {
563 /* standard->daylight transition */
564 { 1, &tzE, {2004,3,-1,27,15,0,0,0}, 1 },
565 { 2, &tzE, {2004,3,-1,27,15,59,59,999}, 1},
566 { 3, &tzE, {2004,3,-1,27,16,0,0,0}, 3},
567 /* daylight->standard transition */
568 { 4, &tzE, {2004,10,-1,30,15,0,0,0}, 2 },
569 { 5, &tzE, {2004,10,-1,30,15,59,59,999}, 2 },
570 { 6, &tzE, {2004,10,-1,30,16,0,0,0}, 2 },
571 /* West and with fixed weekday of the month */
572 { 7, &tzW, {2004,4,-1,4,5,0,0,0}, 1},
573 { 8, &tzW, {2004,4,-1,4,5,59,59,999}, 1},
574 { 9, &tzW, {2004,4,-1,4,6,0,0,0}, 3},
575 { 10, &tzW, {2004,10,-1,24,4,0,0,0}, 1},
576 { 11, &tzW, {2004,10,-1,24,4,59,59,999}, 1},
577 { 12, &tzW, {2004,10,-1,24,5,0,0,0 }, 1},
578 /* and now South */
579 { 13, &tzS, {2004,4,-1,4,4,0,0,0}, 1},
580 { 14, &tzS, {2004,4,-1,4,4,59,59,999}, 1},
581 { 15, &tzS, {2004,4,-1,4,5,0,0,0}, 1},
582 { 16, &tzS, {2004,10,-1,24,5,0,0,0}, 1},
583 { 17, &tzS, {2004,10,-1,24,5,59,59,999}, 1},
584 { 18, &tzS, {2004,10,-1,24,6,0,0,0}, 3},
588 /* days of transitions to put into the cases array */
589 int yeardays[][6]=
591 {27,30,4,24,4,24} /* 1999 */
592 , {25,28,2,22,2,22} /* 2000 */
593 , {24,27,1,28,1,28} /* 2001 */
594 , {30,26,7,27,7,27} /* 2002 */
595 , {29,25,6,26,6,26} /* 2003 */
596 , {27,30,4,24,4,24} /* 2004 */
597 , {26,29,3,23,3,23} /* 2005 */
598 , {25,28,2,22,2,22} /* 2006 */
599 , {24,27,1,28,1,28} /* 2007 */
600 , {29,25,6,26,6,26} /* 2008 */
601 , {28,24,5,25,5,25} /* 2009 */
602 , {27,30,4,24,4,24} /* 2010 */
603 , {26,29,3,23,3,23} /* 2011 */
604 , {24,27,1,28,1,28} /* 2012 */
605 , {30,26,7,27,7,27} /* 2013 */
606 , {29,25,6,26,6,26} /* 2014 */
607 , {28,24,5,25,5,25} /* 2015 */
608 , {26,29,3,23,3,23} /* 2016 */
609 , {25,28,2,22,2,22} /* 2017 */
610 , {24,27,1,28,1,28} /* 2018 */
611 , {30,26,7,27,7,27} /* 2019 */
612 , {0}
614 for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
615 for (i=0; cases[i].nr; i++) {
616 if(i) cases[i].nr += 18;
617 cases[i].slt.wYear = year;
618 cases[i].slt.wDay = yeardays[j][i/3];
619 pSystemTimeToTzSpecificLocalTime( cases[i].ptz, &(cases[i].slt), &result);
620 ok( result.wHour == cases[i].ehour,
621 "Test SystemTimeToTzSpecificLocalTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n",
622 cases[i].nr, result.wYear, result.wMonth, result.wDay,
623 result.wHour, result.wMinute, cases[i].ehour);
630 static void test_FileTimeToDosDateTime(void)
632 FILETIME ft = { 0 };
633 WORD fatdate, fattime;
634 BOOL ret;
636 if (0)
638 /* Crashes */
639 FileTimeToDosDateTime(NULL, NULL, NULL);
641 /* Parameter checking */
642 SetLastError(0xdeadbeef);
643 ret = FileTimeToDosDateTime(&ft, NULL, NULL);
644 ok(!ret, "expected failure\n");
645 ok(GetLastError() == ERROR_INVALID_PARAMETER,
646 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
648 SetLastError(0xdeadbeef);
649 ret = FileTimeToDosDateTime(&ft, &fatdate, NULL);
650 ok(!ret, "expected failure\n");
651 ok(GetLastError() == ERROR_INVALID_PARAMETER,
652 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
654 SetLastError(0xdeadbeef);
655 ret = FileTimeToDosDateTime(&ft, NULL, &fattime);
656 ok(!ret, "expected failure\n");
657 ok(GetLastError() == ERROR_INVALID_PARAMETER,
658 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
660 SetLastError(0xdeadbeef);
661 ret = FileTimeToDosDateTime(&ft, &fatdate, &fattime);
662 ok(!ret, "expected failure\n");
663 ok(GetLastError() == ERROR_INVALID_PARAMETER,
664 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
667 static void test_GetCalendarInfo(void)
669 char bufferA[20];
670 WCHAR bufferW[20];
671 DWORD val1, val2;
672 int ret, ret2;
674 if (!pGetCalendarInfoA || !pGetCalendarInfoW)
676 trace( "GetCalendarInfo missing\n" );
677 return;
680 ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER,
681 NULL, 0, &val1 );
682 ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() );
683 ok( ret == sizeof(val1), "wrong size %u\n", ret );
684 ok( val1 >= 2000 && val1 < 2100, "wrong value %u\n", val1 );
686 ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER,
687 NULL, 0, &val2 );
688 ok( ret, "GetCalendarInfoW failed err %u\n", GetLastError() );
689 ok( ret == sizeof(val2)/sizeof(WCHAR), "wrong size %u\n", ret );
690 ok( val1 == val2, "A/W mismatch %u/%u\n", val1, val2 );
692 ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, bufferA, sizeof(bufferA), NULL );
693 ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() );
694 ok( ret == 5, "wrong size %u\n", ret );
695 ok( atoi( bufferA ) == val1, "wrong value %s/%u\n", bufferA, val1 );
697 ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, bufferW, sizeof(bufferW), NULL );
698 ok( ret, "GetCalendarInfoW failed err %u\n", GetLastError() );
699 ok( ret == 5, "wrong size %u\n", ret );
700 memset( bufferA, 0x55, sizeof(bufferA) );
701 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, bufferA, sizeof(bufferA), NULL, NULL );
702 ok( atoi( bufferA ) == val1, "wrong value %s/%u\n", bufferA, val1 );
704 ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER,
705 NULL, 0, NULL );
706 ok( !ret, "GetCalendarInfoA succeeded\n" );
707 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
709 ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, NULL, 0, NULL );
710 ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() );
711 ok( ret == 5, "wrong size %u\n", ret );
713 ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER,
714 NULL, 0, NULL );
715 ok( !ret, "GetCalendarInfoW succeeded\n" );
716 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
718 ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, NULL, 0, NULL );
719 ok( ret, "GetCalendarInfoW failed err %u\n", GetLastError() );
720 ok( ret == 5, "wrong size %u\n", ret );
722 ret = pGetCalendarInfoA( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1,
723 bufferA, sizeof(bufferA), NULL);
724 ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() );
725 ret2 = pGetCalendarInfoA( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1,
726 bufferA, 0, NULL);
727 ok( ret2, "GetCalendarInfoA failed err %u\n", GetLastError() );
728 ok( ret == ret2, "got %d, expected %d\n", ret2, ret );
730 ret2 = pGetCalendarInfoW( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1,
731 bufferW, sizeof(bufferW), NULL);
732 ok( ret2, "GetCalendarInfoW failed err %u\n", GetLastError() );
733 ret2 = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
734 ok( ret == ret2, "got %d, expected %d\n", ret, ret2 );
737 static void test_GetDynamicTimeZoneInformation(void)
739 DYNAMIC_TIME_ZONE_INFORMATION dyninfo;
740 TIME_ZONE_INFORMATION tzinfo;
741 DWORD ret, ret2;
743 if (!pGetDynamicTimeZoneInformation)
745 win_skip("GetDynamicTimeZoneInformation() is not supported.\n");
746 return;
749 ret = pGetDynamicTimeZoneInformation(&dyninfo);
750 ret2 = GetTimeZoneInformation(&tzinfo);
751 ok(ret == ret2, "got %d, %d\n", ret, ret2);
753 ok(dyninfo.Bias == tzinfo.Bias, "got %d, %d\n", dyninfo.Bias, tzinfo.Bias);
754 ok(!lstrcmpW(dyninfo.StandardName, tzinfo.StandardName), "got std name %s, %s\n",
755 wine_dbgstr_w(dyninfo.StandardName), wine_dbgstr_w(tzinfo.StandardName));
756 ok(!memcmp(&dyninfo.StandardDate, &tzinfo.StandardDate, sizeof(dyninfo.StandardDate)), "got different StandardDate\n");
757 ok(dyninfo.StandardBias == tzinfo.StandardBias, "got %d, %d\n", dyninfo.StandardBias, tzinfo.StandardBias);
758 ok(!lstrcmpW(dyninfo.DaylightName, tzinfo.DaylightName), "got daylight name %s, %s\n",
759 wine_dbgstr_w(dyninfo.DaylightName), wine_dbgstr_w(tzinfo.DaylightName));
760 ok(!memcmp(&dyninfo.DaylightDate, &tzinfo.DaylightDate, sizeof(dyninfo.DaylightDate)), "got different DaylightDate\n");
761 ok(dyninfo.TimeZoneKeyName[0] != 0, "got empty tz keyname\n");
762 trace("Dyn TimeZoneKeyName %s\n", wine_dbgstr_w(dyninfo.TimeZoneKeyName));
765 static ULONGLONG get_longlong_time(FILETIME *time)
767 ULARGE_INTEGER uli;
768 uli.LowPart = time->dwLowDateTime;
769 uli.HighPart = time->dwHighDateTime;
770 return uli.QuadPart;
773 static void test_GetSystemTimePreciseAsFileTime(void)
775 FILETIME ft;
776 ULONGLONG time1, time2;
777 LONGLONG diff;
779 if (!pGetSystemTimePreciseAsFileTime)
781 win_skip("GetSystemTimePreciseAsFileTime() is not supported.\n");
782 return;
785 GetSystemTimeAsFileTime(&ft);
786 time1 = get_longlong_time(&ft);
787 pGetSystemTimePreciseAsFileTime(&ft);
788 time2 = get_longlong_time(&ft);
789 diff = time2 - time1;
790 if (diff < 0)
791 diff = -diff;
792 ok(diff < 1000000, "Difference between GetSystemTimeAsFileTime and GetSystemTimePreciseAsFileTime more than 100 ms\n");
794 pGetSystemTimePreciseAsFileTime(&ft);
795 time1 = get_longlong_time(&ft);
796 do {
797 pGetSystemTimePreciseAsFileTime(&ft);
798 time2 = get_longlong_time(&ft);
799 } while (time2 == time1);
800 diff = time2 - time1;
801 ok(diff < 10000 && diff > 0, "GetSystemTimePreciseAsFileTime incremented by more than 1 ms\n");
804 START_TEST(time)
806 HMODULE hKernel = GetModuleHandleA("kernel32");
807 pTzSpecificLocalTimeToSystemTime = (void *)GetProcAddress(hKernel, "TzSpecificLocalTimeToSystemTime");
808 pSystemTimeToTzSpecificLocalTime = (void *)GetProcAddress( hKernel, "SystemTimeToTzSpecificLocalTime");
809 pGetCalendarInfoA = (void *)GetProcAddress(hKernel, "GetCalendarInfoA");
810 pGetCalendarInfoW = (void *)GetProcAddress(hKernel, "GetCalendarInfoW");
811 pGetDynamicTimeZoneInformation = (void *)GetProcAddress(hKernel, "GetDynamicTimeZoneInformation");
812 pGetSystemTimePreciseAsFileTime = (void *)GetProcAddress(hKernel, "GetSystemTimePreciseAsFileTime");
814 test_conversions();
815 test_invalid_arg();
816 test_GetTimeZoneInformation();
817 test_FileTimeToSystemTime();
818 test_FileTimeToLocalFileTime();
819 test_TzSpecificLocalTimeToSystemTime();
820 test_FileTimeToDosDateTime();
821 test_GetCalendarInfo();
822 test_GetDynamicTimeZoneInformation();
823 test_GetSystemTimePreciseAsFileTime();