winex11.drv: Map coordinates before calling send_mouse_input.
[wine/zf.git] / dlls / kernel32 / tests / time.c
blob28312bac3ce5210c0621887424fff4c1b4fb02a5
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"
25 #include "winternl.h"
27 static BOOL (WINAPI *pTzSpecificLocalTimeToSystemTime)(LPTIME_ZONE_INFORMATION, LPSYSTEMTIME, LPSYSTEMTIME);
28 static BOOL (WINAPI *pSystemTimeToTzSpecificLocalTime)(LPTIME_ZONE_INFORMATION, LPSYSTEMTIME, LPSYSTEMTIME);
29 static BOOL (WINAPI *pGetSystemTimes)(LPFILETIME, LPFILETIME, LPFILETIME);
30 static int (WINAPI *pGetCalendarInfoA)(LCID,CALID,CALTYPE,LPSTR,int,LPDWORD);
31 static int (WINAPI *pGetCalendarInfoW)(LCID,CALID,CALTYPE,LPWSTR,int,LPDWORD);
32 static DWORD (WINAPI *pGetDynamicTimeZoneInformation)(DYNAMIC_TIME_ZONE_INFORMATION*);
33 static void (WINAPI *pGetSystemTimePreciseAsFileTime)(LPFILETIME);
34 static BOOL (WINAPI *pGetTimeZoneInformationForYear)(USHORT, PDYNAMIC_TIME_ZONE_INFORMATION, LPTIME_ZONE_INFORMATION);
35 static ULONG (WINAPI *pNtGetTickCount)(void);
37 #define SECSPERMIN 60
38 #define SECSPERDAY 86400
39 /* 1601 to 1970 is 369 years plus 89 leap days */
40 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
41 #define TICKSPERSEC 10000000
42 #define TICKSPERMSEC 10000
43 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
46 #define NEWYEAR_1980_HI 0x01a8e79f
47 #define NEWYEAR_1980_LO 0xe1d58000
49 #define MAYDAY_2002_HI 0x01c1f107
50 #define MAYDAY_2002_LO 0xb82b6000
52 #define ATIME_HI 0x1c2349b
53 #define ATIME_LOW 0x580716b0
55 #define LOCAL_ATIME_HI 0x01c23471
56 #define LOCAL_ATIME_LOW 0x6f310eb0
58 #define DOS_DATE(y,m,d) ( (((y)-1980)<<9) | ((m)<<5) | (d) )
59 #define DOS_TIME(h,m,s) ( ((h)<<11) | ((m)<<5) | ((s)>>1) )
62 #define SETUP_1980(st) \
63 (st).wYear = 1980; \
64 (st).wMonth = 1; \
65 (st).wDay = 1; \
66 (st).wHour = 0; \
67 (st).wMinute = 0; \
68 (st).wSecond = 0; \
69 (st).wMilliseconds = 0;
71 #define SETUP_2002(st) \
72 (st).wYear = 2002; \
73 (st).wMonth = 5; \
74 (st).wDay = 1; \
75 (st).wHour = 12; \
76 (st).wMinute = 0; \
77 (st).wSecond = 0; \
78 (st).wMilliseconds = 0;
80 #define SETUP_ATIME(st) \
81 (st).wYear = 2002; \
82 (st).wMonth = 7; \
83 (st).wDay = 26; \
84 (st).wHour = 11; \
85 (st).wMinute = 55; \
86 (st).wSecond = 32; \
87 (st).wMilliseconds = 123;
89 #define SETUP_ZEROTIME(st) \
90 (st).wYear = 1601; \
91 (st).wMonth = 1; \
92 (st).wDay = 1; \
93 (st).wHour = 0; \
94 (st).wMinute = 0; \
95 (st).wSecond = 0; \
96 (st).wMilliseconds = 0;
98 #define SETUP_EARLY(st) \
99 (st).wYear = 1600; \
100 (st).wMonth = 12; \
101 (st).wDay = 31; \
102 (st).wHour = 23; \
103 (st).wMinute = 59; \
104 (st).wSecond = 59; \
105 (st).wMilliseconds = 999;
108 static void test_conversions(void)
110 FILETIME ft;
111 SYSTEMTIME st;
113 memset(&ft,0,sizeof ft);
115 SetLastError(0xdeadbeef);
116 SETUP_EARLY(st)
117 ok (!SystemTimeToFileTime(&st, &ft), "Conversion succeeded EARLY\n");
118 ok (GetLastError() == ERROR_INVALID_PARAMETER ||
119 GetLastError() == 0xdeadbeef, /* win9x */
120 "EARLY should be INVALID\n");
122 SETUP_ZEROTIME(st)
123 ok (SystemTimeToFileTime(&st, &ft), "Conversion failed ZERO_TIME\n");
124 ok( (!((ft.dwHighDateTime != 0) || (ft.dwLowDateTime != 0))),
125 "Wrong time for ATIME: %08x %08x (correct %08x %08x)\n",
126 ft.dwLowDateTime, ft.dwHighDateTime, 0, 0);
129 SETUP_ATIME(st)
130 ok (SystemTimeToFileTime(&st,&ft), "Conversion Failed ATIME\n");
131 ok( (!((ft.dwHighDateTime != ATIME_HI) || (ft.dwLowDateTime!=ATIME_LOW))),
132 "Wrong time for ATIME: %08x %08x (correct %08x %08x)\n",
133 ft.dwLowDateTime, ft.dwHighDateTime, ATIME_LOW, ATIME_HI);
136 SETUP_2002(st)
137 ok (SystemTimeToFileTime(&st, &ft), "Conversion failed 2002\n");
139 ok( (!((ft.dwHighDateTime != MAYDAY_2002_HI) ||
140 (ft.dwLowDateTime!=MAYDAY_2002_LO))),
141 "Wrong time for 2002 %08x %08x (correct %08x %08x)\n", ft.dwLowDateTime,
142 ft.dwHighDateTime, MAYDAY_2002_LO, MAYDAY_2002_HI);
145 SETUP_1980(st)
146 ok((SystemTimeToFileTime(&st, &ft)), "Conversion failed 1980\n");
148 ok( (!((ft.dwHighDateTime!=NEWYEAR_1980_HI) ||
149 (ft.dwLowDateTime!=NEWYEAR_1980_LO))) ,
150 "Wrong time for 1980 %08x %08x (correct %08x %08x)\n", ft.dwLowDateTime,
151 ft.dwHighDateTime, NEWYEAR_1980_LO,NEWYEAR_1980_HI );
153 ok(DosDateTimeToFileTime(DOS_DATE(1980,1,1),DOS_TIME(0,0,0),&ft),
154 "DosDateTimeToFileTime() failed\n");
156 ok( (!((ft.dwHighDateTime!=NEWYEAR_1980_HI) ||
157 (ft.dwLowDateTime!=NEWYEAR_1980_LO))),
158 "Wrong time DosDateTimeToFileTime %08x %08x (correct %08x %08x)\n",
159 ft.dwHighDateTime, ft.dwLowDateTime, NEWYEAR_1980_HI, NEWYEAR_1980_LO);
163 static void test_invalid_arg(void)
165 FILETIME ft;
166 SYSTEMTIME st;
169 /* Invalid argument checks */
171 memset(&ft,0,sizeof ft);
172 ok( DosDateTimeToFileTime(DOS_DATE(1980,1,1),DOS_TIME(0,0,0),&ft), /* this is 1 Jan 1980 00:00:00 */
173 "DosDateTimeToFileTime() failed\n");
175 ok( (ft.dwHighDateTime==NEWYEAR_1980_HI) && (ft.dwLowDateTime==NEWYEAR_1980_LO),
176 "filetime for 1/1/80 00:00:00 was %08x %08x\n", ft.dwHighDateTime, ft.dwLowDateTime);
178 /* now check SystemTimeToFileTime */
179 memset(&ft,0,sizeof ft);
182 /* try with a bad month */
183 SETUP_1980(st)
184 st.wMonth = 0;
186 ok( !SystemTimeToFileTime(&st, &ft), "bad month\n");
188 /* with a bad hour */
189 SETUP_1980(st)
190 st.wHour = 24;
192 ok( !SystemTimeToFileTime(&st, &ft), "bad hour\n");
194 /* with a bad minute */
195 SETUP_1980(st)
196 st.wMinute = 60;
198 ok( !SystemTimeToFileTime(&st, &ft), "bad minute\n");
201 static LONGLONG system_time_to_minutes(const SYSTEMTIME *st)
203 BOOL ret;
204 FILETIME ft;
205 LONGLONG minutes;
207 SetLastError(0xdeadbeef);
208 ret = SystemTimeToFileTime(st, &ft);
209 ok(ret, "SystemTimeToFileTime error %u\n", GetLastError());
211 minutes = ((LONGLONG)ft.dwHighDateTime << 32) + ft.dwLowDateTime;
212 minutes /= (LONGLONG)600000000; /* convert to minutes */
213 return minutes;
216 static LONG get_tz_bias(const TIME_ZONE_INFORMATION *tzinfo, DWORD tz_id)
218 switch (tz_id)
220 case TIME_ZONE_ID_DAYLIGHT:
221 if (memcmp(&tzinfo->StandardDate, &tzinfo->DaylightDate, sizeof(tzinfo->DaylightDate)) != 0)
222 return tzinfo->DaylightBias;
223 /* fall through */
225 case TIME_ZONE_ID_STANDARD:
226 return tzinfo->StandardBias;
228 default:
229 trace("unknown time zone id %d\n", tz_id);
230 /* fall through */
231 case TIME_ZONE_ID_UNKNOWN:
232 return 0;
236 static void test_GetTimeZoneInformation(void)
238 char std_name[32], dlt_name[32];
239 TIME_ZONE_INFORMATION tzinfo, tzinfo1;
240 BOOL res;
241 DWORD tz_id;
242 SYSTEMTIME st, current, utc, local;
243 FILETIME l_ft, s_ft;
244 LONGLONG l_time, s_time;
245 LONG diff;
247 GetSystemTime(&st);
248 s_time = system_time_to_minutes(&st);
250 SetLastError(0xdeadbeef);
251 res = SystemTimeToFileTime(&st, &s_ft);
252 ok(res, "SystemTimeToFileTime error %u\n", GetLastError());
253 SetLastError(0xdeadbeef);
254 res = FileTimeToLocalFileTime(&s_ft, &l_ft);
255 ok(res, "FileTimeToLocalFileTime error %u\n", GetLastError());
256 SetLastError(0xdeadbeef);
257 res = FileTimeToSystemTime(&l_ft, &local);
258 ok(res, "FileTimeToSystemTime error %u\n", GetLastError());
259 l_time = system_time_to_minutes(&local);
261 tz_id = GetTimeZoneInformation(&tzinfo);
262 ok(tz_id != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
264 trace("tz_id %u (%s)\n", tz_id,
265 tz_id == TIME_ZONE_ID_DAYLIGHT ? "TIME_ZONE_ID_DAYLIGHT" :
266 (tz_id == TIME_ZONE_ID_STANDARD ? "TIME_ZONE_ID_STANDARD" :
267 (tz_id == TIME_ZONE_ID_UNKNOWN ? "TIME_ZONE_ID_UNKNOWN" :
268 "TIME_ZONE_ID_INVALID")));
270 WideCharToMultiByte(CP_ACP, 0, tzinfo.StandardName, -1, std_name, sizeof(std_name), NULL, NULL);
271 WideCharToMultiByte(CP_ACP, 0, tzinfo.DaylightName, -1, dlt_name, sizeof(dlt_name), NULL, NULL);
272 trace("bias %d, %s - %s\n", tzinfo.Bias, std_name, dlt_name);
273 trace("standard (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n",
274 tzinfo.StandardDate.wDay, tzinfo.StandardDate.wMonth,
275 tzinfo.StandardDate.wYear, tzinfo.StandardDate.wDayOfWeek,
276 tzinfo.StandardDate.wHour, tzinfo.StandardDate.wMinute,
277 tzinfo.StandardDate.wSecond, tzinfo.StandardDate.wMilliseconds,
278 tzinfo.StandardBias);
279 trace("daylight (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n",
280 tzinfo.DaylightDate.wDay, tzinfo.DaylightDate.wMonth,
281 tzinfo.DaylightDate.wYear, tzinfo.DaylightDate.wDayOfWeek,
282 tzinfo.DaylightDate.wHour, tzinfo.DaylightDate.wMinute,
283 tzinfo.DaylightDate.wSecond, tzinfo.DaylightDate.wMilliseconds,
284 tzinfo.DaylightBias);
286 diff = (LONG)(s_time - l_time);
287 ok(diff == tzinfo.Bias + get_tz_bias(&tzinfo, tz_id),
288 "system/local diff %d != tz bias %d\n",
289 diff, tzinfo.Bias + get_tz_bias(&tzinfo, tz_id));
291 ok(SetEnvironmentVariableA("TZ","GMT0") != 0,
292 "SetEnvironmentVariableA failed\n");
293 res = GetTimeZoneInformation(&tzinfo1);
294 ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
296 ok(((tzinfo.Bias == tzinfo1.Bias) &&
297 (tzinfo.StandardBias == tzinfo1.StandardBias) &&
298 (tzinfo.DaylightBias == tzinfo1.DaylightBias)),
299 "Bias influenced by TZ variable\n");
300 ok(SetEnvironmentVariableA("TZ",NULL) != 0,
301 "SetEnvironmentVariableA failed\n");
303 if (!pSystemTimeToTzSpecificLocalTime)
305 win_skip("SystemTimeToTzSpecificLocalTime not available\n");
306 return;
309 diff = get_tz_bias(&tzinfo, tz_id);
311 utc = st;
312 SetLastError(0xdeadbeef);
313 res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &current);
314 if (!res && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
316 win_skip("SystemTimeToTzSpecificLocalTime is not implemented\n");
317 return;
320 ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
321 s_time = system_time_to_minutes(&current);
323 tzinfo.StandardBias -= 123;
324 tzinfo.DaylightBias += 456;
326 res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
327 ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
328 l_time = system_time_to_minutes(&local);
329 ok(l_time - s_time == diff - get_tz_bias(&tzinfo, tz_id), "got %d, expected %d\n",
330 (LONG)(l_time - s_time), diff - get_tz_bias(&tzinfo, tz_id));
332 /* pretend that there is no transition dates */
333 tzinfo.DaylightDate.wDay = 0;
334 tzinfo.DaylightDate.wMonth = 0;
335 tzinfo.DaylightDate.wYear = 0;
336 tzinfo.StandardDate.wDay = 0;
337 tzinfo.StandardDate.wMonth = 0;
338 tzinfo.StandardDate.wYear = 0;
340 res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
341 ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
342 l_time = system_time_to_minutes(&local);
343 ok(l_time - s_time == diff, "got %d, expected %d\n",
344 (LONG)(l_time - s_time), diff);
346 /* test 23:01, 31st of December date */
347 memset(&tzinfo, 0, sizeof(tzinfo));
348 tzinfo.StandardDate.wMonth = 10;
349 tzinfo.StandardDate.wDay = 5;
350 tzinfo.StandardDate.wHour = 2;
351 tzinfo.StandardDate.wMinute = 0;
352 tzinfo.DaylightDate.wMonth = 4;
353 tzinfo.DaylightDate.wDay = 1;
354 tzinfo.DaylightDate.wHour = 2;
355 tzinfo.Bias = 0;
356 tzinfo.StandardBias = 0;
357 tzinfo.DaylightBias = -60;
358 utc.wYear = 2012;
359 utc.wMonth = 12;
360 utc.wDay = 31;
361 utc.wHour = 23;
362 utc.wMinute = 1;
363 res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
364 ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
365 ok(local.wYear==2012 && local.wMonth==12 && local.wDay==31 && local.wHour==23 && local.wMinute==1,
366 "got (%d-%d-%d %02d:%02d), expected (2012-12-31 23:01)\n",
367 local.wYear, local.wMonth, local.wDay, local.wHour, local.wMinute);
370 static void test_FileTimeToSystemTime(void)
372 FILETIME ft;
373 SYSTEMTIME st;
374 ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
375 BOOL ret;
377 ft.dwHighDateTime = 0;
378 ft.dwLowDateTime = 0;
379 ret = FileTimeToSystemTime(&ft, &st);
380 ok( ret,
381 "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
382 ok(((st.wYear == 1601) && (st.wMonth == 1) && (st.wDay == 1) &&
383 (st.wHour == 0) && (st.wMinute == 0) && (st.wSecond == 0) &&
384 (st.wMilliseconds == 0)),
385 "Got Year %4d Month %2d Day %2d\n", st.wYear, st.wMonth, st.wDay);
387 ft.dwHighDateTime = (UINT)(time >> 32);
388 ft.dwLowDateTime = (UINT)time;
389 ret = FileTimeToSystemTime(&ft, &st);
390 ok( ret,
391 "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
392 ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
393 (st.wHour == 0) && (st.wMinute == 0) && (st.wSecond == 1) &&
394 (st.wMilliseconds == 0)),
395 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
396 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
397 st.wMilliseconds);
400 static void test_FileTimeToLocalFileTime(void)
402 FILETIME ft, lft;
403 SYSTEMTIME st;
404 TIME_ZONE_INFORMATION tzinfo;
405 DWORD res = GetTimeZoneInformation(&tzinfo);
406 ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970 +
407 (LONGLONG)(tzinfo.Bias +
408 ( res == TIME_ZONE_ID_STANDARD ? tzinfo.StandardBias :
409 ( res == TIME_ZONE_ID_DAYLIGHT ? tzinfo.DaylightBias : 0 ))) *
410 SECSPERMIN *TICKSPERSEC;
411 BOOL ret;
413 ok( res != TIME_ZONE_ID_INVALID , "GetTimeZoneInformation failed\n");
414 ft.dwHighDateTime = (UINT)(time >> 32);
415 ft.dwLowDateTime = (UINT)time;
416 ret = FileTimeToLocalFileTime(&ft, &lft);
417 ok( ret,
418 "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
419 FileTimeToSystemTime(&lft, &st);
420 ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
421 (st.wHour == 0) && (st.wMinute == 0) && (st.wSecond == 1) &&
422 (st.wMilliseconds == 0)),
423 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
424 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
425 st.wMilliseconds);
427 ok(SetEnvironmentVariableA("TZ","GMT") != 0,
428 "SetEnvironmentVariableA failed\n");
429 ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
430 ret = FileTimeToLocalFileTime(&ft, &lft);
431 ok( ret,
432 "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
433 FileTimeToSystemTime(&lft, &st);
434 ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
435 (st.wHour == 0) && (st.wMinute == 0) && (st.wSecond == 1) &&
436 (st.wMilliseconds == 0)),
437 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
438 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
439 st.wMilliseconds);
440 ok(SetEnvironmentVariableA("TZ",NULL) != 0,
441 "SetEnvironmentVariableA failed\n");
444 typedef struct {
445 int nr; /* test case number for easier lookup */
446 TIME_ZONE_INFORMATION *ptz; /* ptr to timezone */
447 SYSTEMTIME slt; /* system/local time to convert */
448 WORD ehour; /* expected hour */
449 } TZLT2ST_case;
451 static void test_TzSpecificLocalTimeToSystemTime(void)
453 TIME_ZONE_INFORMATION tzE, tzW, tzS;
454 SYSTEMTIME result;
455 int i, j, year;
457 if (!pTzSpecificLocalTimeToSystemTime || !pSystemTimeToTzSpecificLocalTime)
459 win_skip("TzSpecificLocalTimeToSystemTime or SystemTimeToTzSpecificLocalTime not available\n");
460 return;
463 ZeroMemory( &tzE, sizeof(tzE));
464 ZeroMemory( &tzW, sizeof(tzW));
465 ZeroMemory( &tzS, sizeof(tzS));
466 /* timezone Eastern hemisphere */
467 tzE.Bias=-600;
468 tzE.StandardBias=0;
469 tzE.DaylightBias=-60;
470 tzE.StandardDate.wMonth=10;
471 tzE.StandardDate.wDayOfWeek=0; /* Sunday */
472 tzE.StandardDate.wDay=5; /* last (Sunday) of the month */
473 tzE.StandardDate.wHour=3;
474 tzE.DaylightDate.wMonth=3;
475 tzE.DaylightDate.wDay=5;
476 tzE.DaylightDate.wHour=2;
477 /* timezone Western hemisphere */
478 tzW.Bias=240;
479 tzW.StandardBias=0;
480 tzW.DaylightBias=-60;
481 tzW.StandardDate.wMonth=10;
482 tzW.StandardDate.wDayOfWeek=0; /* Sunday */
483 tzW.StandardDate.wDay=4; /* 4th (Sunday) of the month */
484 tzW.StandardDate.wHour=2;
485 tzW.DaylightDate.wMonth=4;
486 tzW.DaylightDate.wDay=1;
487 tzW.DaylightDate.wHour=2;
488 /* timezone Southern hemisphere */
489 tzS.Bias=240;
490 tzS.StandardBias=0;
491 tzS.DaylightBias=-60;
492 tzS.StandardDate.wMonth=4;
493 tzS.StandardDate.wDayOfWeek=0; /*Sunday */
494 tzS.StandardDate.wDay=1; /* 1st (Sunday) of the month */
495 tzS.StandardDate.wHour=2;
496 tzS.DaylightDate.wMonth=10;
497 tzS.DaylightDate.wDay=4;
498 tzS.DaylightDate.wHour=2;
499 /*tests*/
500 /* TzSpecificLocalTimeToSystemTime */
501 { TZLT2ST_case cases[] = {
502 /* standard->daylight transition */
503 { 1, &tzE, {2004,3,-1,28,1,0,0,0}, 15 },
504 { 2, &tzE, {2004,3,-1,28,1,59,59,999}, 15},
505 { 3, &tzE, {2004,3,-1,28,2,0,0,0}, 15},
506 /* daylight->standard transition */
507 { 4, &tzE, {2004,10,-1,31,2,0,0,0} , 15 },
508 { 5, &tzE, {2004,10,-1,31,2,59,59,999}, 15 },
509 { 6, &tzE, {2004,10,-1,31,3,0,0,0}, 17 },
510 /* West and with fixed weekday of the month */
511 { 7, &tzW, {2004,4,-1,4,1,0,0,0}, 5},
512 { 8, &tzW, {2004,4,-1,4,1,59,59,999}, 5},
513 { 9, &tzW, {2004,4,-1,4,2,0,0,0}, 5},
514 { 10, &tzW, {2004,10,-1,24,1,0,0,0}, 4},
515 { 11, &tzW, {2004,10,-1,24,1,59,59,999}, 4},
516 { 12, &tzW, {2004,10,-1,24,2,0,0,0 }, 6},
517 /* and now South */
518 { 13, &tzS, {2004,4,-1,4,1,0,0,0}, 4},
519 { 14, &tzS, {2004,4,-1,4,1,59,59,999}, 4},
520 { 15, &tzS, {2004,4,-1,4,2,0,0,0}, 6},
521 { 16, &tzS, {2004,10,-1,24,1,0,0,0}, 5},
522 { 17, &tzS, {2004,10,-1,24,1,59,59,999}, 5},
523 { 18, &tzS, {2004,10,-1,24,2,0,0,0}, 5},
526 /* days of transitions to put into the cases array */
527 int yeardays[][6]=
529 {28,31,4,24,4,24} /* 1999 */
530 , {26,29,2,22,2,22} /* 2000 */
531 , {25,28,1,28,1,28} /* 2001 */
532 , {31,27,7,27,7,27} /* 2002 */
533 , {30,26,6,26,6,26} /* 2003 */
534 , {28,31,4,24,4,24} /* 2004 */
535 , {27,30,3,23,3,23} /* 2005 */
536 , {26,29,2,22,2,22} /* 2006 */
537 , {25,28,1,28,1,28} /* 2007 */
538 , {30,26,6,26,6,26} /* 2008 */
539 , {29,25,5,25,5,25} /* 2009 */
540 , {28,31,4,24,4,24} /* 2010 */
541 , {27,30,3,23,3,23} /* 2011 */
542 , {25,28,1,28,1,28} /* 2012 */
543 , {31,27,7,27,7,27} /* 2013 */
544 , {30,26,6,26,6,26} /* 2014 */
545 , {29,25,5,25,5,25} /* 2015 */
546 , {27,30,3,23,3,23} /* 2016 */
547 , {26,29,2,22,2,22} /* 2017 */
548 , {25,28,1,28,1,28} /* 2018 */
549 , {31,27,7,27,7,27} /* 2019 */
550 ,{0}
552 for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
553 for (i=0; cases[i].nr; i++) {
554 if(i) cases[i].nr += 18;
555 cases[i].slt.wYear = year;
556 cases[i].slt.wDay = yeardays[j][i/3];
557 pTzSpecificLocalTimeToSystemTime( cases[i].ptz, &(cases[i].slt), &result);
558 ok( result.wHour == cases[i].ehour,
559 "Test TzSpecificLocalTimeToSystemTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n",
560 cases[i].nr, result.wYear, result.wMonth, result.wDay,
561 result.wHour, result.wMinute, cases[i].ehour);
565 /* SystemTimeToTzSpecificLocalTime */
566 { TZLT2ST_case cases[] = {
567 /* standard->daylight transition */
568 { 1, &tzE, {2004,3,-1,27,15,0,0,0}, 1 },
569 { 2, &tzE, {2004,3,-1,27,15,59,59,999}, 1},
570 { 3, &tzE, {2004,3,-1,27,16,0,0,0}, 3},
571 /* daylight->standard transition */
572 { 4, &tzE, {2004,10,-1,30,15,0,0,0}, 2 },
573 { 5, &tzE, {2004,10,-1,30,15,59,59,999}, 2 },
574 { 6, &tzE, {2004,10,-1,30,16,0,0,0}, 2 },
575 /* West and with fixed weekday of the month */
576 { 7, &tzW, {2004,4,-1,4,5,0,0,0}, 1},
577 { 8, &tzW, {2004,4,-1,4,5,59,59,999}, 1},
578 { 9, &tzW, {2004,4,-1,4,6,0,0,0}, 3},
579 { 10, &tzW, {2004,10,-1,24,4,0,0,0}, 1},
580 { 11, &tzW, {2004,10,-1,24,4,59,59,999}, 1},
581 { 12, &tzW, {2004,10,-1,24,5,0,0,0 }, 1},
582 /* and now South */
583 { 13, &tzS, {2004,4,-1,4,4,0,0,0}, 1},
584 { 14, &tzS, {2004,4,-1,4,4,59,59,999}, 1},
585 { 15, &tzS, {2004,4,-1,4,5,0,0,0}, 1},
586 { 16, &tzS, {2004,10,-1,24,5,0,0,0}, 1},
587 { 17, &tzS, {2004,10,-1,24,5,59,59,999}, 1},
588 { 18, &tzS, {2004,10,-1,24,6,0,0,0}, 3},
592 /* days of transitions to put into the cases array */
593 int yeardays[][6]=
595 {27,30,4,24,4,24} /* 1999 */
596 , {25,28,2,22,2,22} /* 2000 */
597 , {24,27,1,28,1,28} /* 2001 */
598 , {30,26,7,27,7,27} /* 2002 */
599 , {29,25,6,26,6,26} /* 2003 */
600 , {27,30,4,24,4,24} /* 2004 */
601 , {26,29,3,23,3,23} /* 2005 */
602 , {25,28,2,22,2,22} /* 2006 */
603 , {24,27,1,28,1,28} /* 2007 */
604 , {29,25,6,26,6,26} /* 2008 */
605 , {28,24,5,25,5,25} /* 2009 */
606 , {27,30,4,24,4,24} /* 2010 */
607 , {26,29,3,23,3,23} /* 2011 */
608 , {24,27,1,28,1,28} /* 2012 */
609 , {30,26,7,27,7,27} /* 2013 */
610 , {29,25,6,26,6,26} /* 2014 */
611 , {28,24,5,25,5,25} /* 2015 */
612 , {26,29,3,23,3,23} /* 2016 */
613 , {25,28,2,22,2,22} /* 2017 */
614 , {24,27,1,28,1,28} /* 2018 */
615 , {30,26,7,27,7,27} /* 2019 */
616 , {0}
618 for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
619 for (i=0; cases[i].nr; i++) {
620 if(i) cases[i].nr += 18;
621 cases[i].slt.wYear = year;
622 cases[i].slt.wDay = yeardays[j][i/3];
623 pSystemTimeToTzSpecificLocalTime( cases[i].ptz, &(cases[i].slt), &result);
624 ok( result.wHour == cases[i].ehour,
625 "Test SystemTimeToTzSpecificLocalTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n",
626 cases[i].nr, result.wYear, result.wMonth, result.wDay,
627 result.wHour, result.wMinute, cases[i].ehour);
634 static void test_FileTimeToDosDateTime(void)
636 FILETIME ft = { 0 };
637 WORD fatdate, fattime;
638 BOOL ret;
640 if (0)
642 /* Crashes */
643 FileTimeToDosDateTime(NULL, NULL, NULL);
645 /* Parameter checking */
646 SetLastError(0xdeadbeef);
647 ret = FileTimeToDosDateTime(&ft, NULL, NULL);
648 ok(!ret, "expected failure\n");
649 ok(GetLastError() == ERROR_INVALID_PARAMETER,
650 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
652 SetLastError(0xdeadbeef);
653 ret = FileTimeToDosDateTime(&ft, &fatdate, NULL);
654 ok(!ret, "expected failure\n");
655 ok(GetLastError() == ERROR_INVALID_PARAMETER,
656 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
658 SetLastError(0xdeadbeef);
659 ret = FileTimeToDosDateTime(&ft, NULL, &fattime);
660 ok(!ret, "expected failure\n");
661 ok(GetLastError() == ERROR_INVALID_PARAMETER,
662 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
664 SetLastError(0xdeadbeef);
665 ret = FileTimeToDosDateTime(&ft, &fatdate, &fattime);
666 ok(!ret, "expected failure\n");
667 ok(GetLastError() == ERROR_INVALID_PARAMETER,
668 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
671 static void test_GetCalendarInfo(void)
673 char bufferA[20];
674 WCHAR bufferW[20];
675 DWORD val1, val2;
676 int ret, ret2;
678 if (!pGetCalendarInfoA || !pGetCalendarInfoW)
680 trace( "GetCalendarInfo missing\n" );
681 return;
684 ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER,
685 NULL, 0, &val1 );
686 ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() );
687 ok( ret == sizeof(val1), "wrong size %u\n", ret );
688 ok( val1 >= 2000 && val1 < 2100, "wrong value %u\n", val1 );
690 ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER,
691 NULL, 0, &val2 );
692 ok( ret, "GetCalendarInfoW failed err %u\n", GetLastError() );
693 ok( ret == sizeof(val2)/sizeof(WCHAR), "wrong size %u\n", ret );
694 ok( val1 == val2, "A/W mismatch %u/%u\n", val1, val2 );
696 ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, bufferA, sizeof(bufferA), NULL );
697 ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() );
698 ok( ret == 5, "wrong size %u\n", ret );
699 ok( atoi( bufferA ) == val1, "wrong value %s/%u\n", bufferA, val1 );
701 ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, bufferW, ARRAY_SIZE(bufferW), NULL );
702 ok( ret, "GetCalendarInfoW failed err %u\n", GetLastError() );
703 ok( ret == 5, "wrong size %u\n", ret );
704 memset( bufferA, 0x55, sizeof(bufferA) );
705 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, bufferA, sizeof(bufferA), NULL, NULL );
706 ok( atoi( bufferA ) == val1, "wrong value %s/%u\n", bufferA, val1 );
708 ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER,
709 NULL, 0, NULL );
710 ok( !ret, "GetCalendarInfoA succeeded\n" );
711 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
713 ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, NULL, 0, NULL );
714 ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() );
715 ok( ret == 5, "wrong size %u\n", ret );
717 ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER,
718 NULL, 0, NULL );
719 ok( !ret, "GetCalendarInfoW succeeded\n" );
720 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
722 ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, NULL, 0, NULL );
723 ok( ret, "GetCalendarInfoW failed err %u\n", GetLastError() );
724 ok( ret == 5, "wrong size %u\n", ret );
726 ret = pGetCalendarInfoA( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1,
727 bufferA, sizeof(bufferA), NULL);
728 ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() );
729 ret2 = pGetCalendarInfoA( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1,
730 bufferA, 0, NULL);
731 ok( ret2, "GetCalendarInfoA failed err %u\n", GetLastError() );
732 ok( ret == ret2, "got %d, expected %d\n", ret2, ret );
734 ret2 = pGetCalendarInfoW( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1,
735 bufferW, ARRAY_SIZE(bufferW), NULL);
736 ok( ret2, "GetCalendarInfoW failed err %u\n", GetLastError() );
737 ret2 = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
738 ok( ret == ret2, "got %d, expected %d\n", ret, ret2 );
741 static void test_GetDynamicTimeZoneInformation(void)
743 DYNAMIC_TIME_ZONE_INFORMATION dyninfo;
744 TIME_ZONE_INFORMATION tzinfo;
745 DWORD ret, ret2;
747 if (!pGetDynamicTimeZoneInformation)
749 win_skip("GetDynamicTimeZoneInformation() is not supported.\n");
750 return;
753 ret = pGetDynamicTimeZoneInformation(&dyninfo);
754 ret2 = GetTimeZoneInformation(&tzinfo);
755 ok(ret == ret2, "got %d, %d\n", ret, ret2);
757 ok(dyninfo.Bias == tzinfo.Bias, "got %d, %d\n", dyninfo.Bias, tzinfo.Bias);
758 ok(!lstrcmpW(dyninfo.StandardName, tzinfo.StandardName), "got std name %s, %s\n",
759 wine_dbgstr_w(dyninfo.StandardName), wine_dbgstr_w(tzinfo.StandardName));
760 ok(!memcmp(&dyninfo.StandardDate, &tzinfo.StandardDate, sizeof(dyninfo.StandardDate)), "got different StandardDate\n");
761 ok(dyninfo.StandardBias == tzinfo.StandardBias, "got %d, %d\n", dyninfo.StandardBias, tzinfo.StandardBias);
762 ok(!lstrcmpW(dyninfo.DaylightName, tzinfo.DaylightName), "got daylight name %s, %s\n",
763 wine_dbgstr_w(dyninfo.DaylightName), wine_dbgstr_w(tzinfo.DaylightName));
764 ok(!memcmp(&dyninfo.DaylightDate, &tzinfo.DaylightDate, sizeof(dyninfo.DaylightDate)), "got different DaylightDate\n");
765 ok(dyninfo.TimeZoneKeyName[0] != 0, "got empty tz keyname\n");
766 trace("Dyn TimeZoneKeyName %s\n", wine_dbgstr_w(dyninfo.TimeZoneKeyName));
769 static ULONGLONG get_longlong_time(FILETIME *time)
771 ULARGE_INTEGER uli;
772 uli.u.LowPart = time->dwLowDateTime;
773 uli.u.HighPart = time->dwHighDateTime;
774 return uli.QuadPart;
777 static void test_GetSystemTimeAsFileTime(void)
779 LARGE_INTEGER t1, t2, t3;
780 FILETIME ft;
782 NtQuerySystemTime( &t1 );
783 GetSystemTimeAsFileTime( &ft );
784 NtQuerySystemTime( &t3 );
785 t2.QuadPart = get_longlong_time( &ft );
787 ok(t1.QuadPart <= t2.QuadPart, "out of order %s %s\n", wine_dbgstr_longlong(t1.QuadPart), wine_dbgstr_longlong(t2.QuadPart));
788 ok(t2.QuadPart <= t3.QuadPart, "out of order %s %s\n", wine_dbgstr_longlong(t2.QuadPart), wine_dbgstr_longlong(t3.QuadPart));
791 static void test_GetSystemTimePreciseAsFileTime(void)
793 FILETIME ft;
794 ULONGLONG time1, time2;
795 LONGLONG diff;
797 if (!pGetSystemTimePreciseAsFileTime)
799 win_skip("GetSystemTimePreciseAsFileTime() is not supported.\n");
800 return;
803 GetSystemTimeAsFileTime(&ft);
804 time1 = get_longlong_time(&ft);
805 pGetSystemTimePreciseAsFileTime(&ft);
806 time2 = get_longlong_time(&ft);
807 diff = time2 - time1;
808 if (diff < 0)
809 diff = -diff;
810 ok(diff < 1000000, "Difference between GetSystemTimeAsFileTime and GetSystemTimePreciseAsFileTime more than 100 ms\n");
812 pGetSystemTimePreciseAsFileTime(&ft);
813 time1 = get_longlong_time(&ft);
814 do {
815 pGetSystemTimePreciseAsFileTime(&ft);
816 time2 = get_longlong_time(&ft);
817 } while (time2 == time1);
818 diff = time2 - time1;
819 ok(diff < 10000 && diff > 0, "GetSystemTimePreciseAsFileTime incremented by more than 1 ms\n");
822 static void test_GetSystemTimes(void)
825 FILETIME idletime, kerneltime, usertime;
826 int i;
827 ULARGE_INTEGER ul1, ul2, ul3;
828 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi;
829 SYSTEM_BASIC_INFORMATION sbi;
830 ULONG ReturnLength;
831 ULARGE_INTEGER total_usertime, total_kerneltime, total_idletime;
833 if (!pGetSystemTimes)
835 win_skip("GetSystemTimes not available\n");
836 return;
839 ok( pGetSystemTimes(NULL, NULL, NULL), "GetSystemTimes failed unexpectedly\n" );
841 total_usertime.QuadPart = 0;
842 total_kerneltime.QuadPart = 0;
843 total_idletime.QuadPart = 0;
844 memset( &idletime, 0x11, sizeof(idletime) );
845 memset( &kerneltime, 0x11, sizeof(kerneltime) );
846 memset( &usertime, 0x11, sizeof(usertime) );
847 ok( pGetSystemTimes(&idletime, &kerneltime , &usertime),
848 "GetSystemTimes failed unexpectedly\n" );
850 ul1.LowPart = idletime.dwLowDateTime;
851 ul1.HighPart = idletime.dwHighDateTime;
852 ul2.LowPart = kerneltime.dwLowDateTime;
853 ul2.HighPart = kerneltime.dwHighDateTime;
854 ul3.LowPart = usertime.dwLowDateTime;
855 ul3.HighPart = usertime.dwHighDateTime;
857 ok( !NtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength),
858 "NtQuerySystemInformation failed\n" );
859 ok( sizeof(sbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength );
861 /* Check if we have some return values */
862 trace( "Number of Processors : %d\n", sbi.NumberOfProcessors );
863 ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n",
864 sbi.NumberOfProcessors );
866 sppi = HeapAlloc( GetProcessHeap(), 0,
867 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * sbi.NumberOfProcessors);
869 ok( !NtQuerySystemInformation( SystemProcessorPerformanceInformation, sppi,
870 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * sbi.NumberOfProcessors,
871 &ReturnLength),
872 "NtQuerySystemInformation failed\n" );
874 for (i = 0; i < sbi.NumberOfProcessors; i++)
876 total_usertime.QuadPart += sppi[i].UserTime.QuadPart;
877 total_kerneltime.QuadPart += sppi[i].KernelTime.QuadPart;
878 total_idletime.QuadPart += sppi[i].IdleTime.QuadPart;
881 ok( total_idletime.QuadPart - ul1.QuadPart < 10000000, "test idletime failed\n" );
882 ok( total_kerneltime.QuadPart - ul2.QuadPart < 10000000, "test kerneltime failed\n" );
883 ok( total_usertime.QuadPart - ul3.QuadPart < 10000000, "test usertime failed\n" );
885 HeapFree(GetProcessHeap(), 0, sppi);
888 static WORD day_of_month(const SYSTEMTIME* systemtime, WORD year)
890 SYSTEMTIME first_of_month = {0};
891 FILETIME filetime;
892 WORD result;
894 if (systemtime->wYear != 0)
895 return systemtime->wDay;
897 first_of_month.wYear = year;
898 first_of_month.wMonth = systemtime->wMonth;
899 first_of_month.wDay = 1;
901 /* round-trip conversion sets day of week field */
902 SystemTimeToFileTime(&first_of_month, &filetime);
903 FileTimeToSystemTime(&filetime, &first_of_month);
905 result = 1 + ((systemtime->wDayOfWeek - first_of_month.wDayOfWeek + 7) % 7) +
906 (7 * (systemtime->wDay - 1));
908 if (systemtime->wDay == 5)
910 /* make sure this isn't in the next month */
911 SYSTEMTIME result_date;
913 result_date = first_of_month;
914 result_date.wDay = result;
916 SystemTimeToFileTime(&result_date, &filetime);
917 FileTimeToSystemTime(&filetime, &result_date);
919 if (result_date.wDay != result)
920 result = 1 + ((systemtime->wDayOfWeek - first_of_month.wDayOfWeek + 7) % 7) +
921 (7 * (4 - 1));
924 return result;
927 static void test_GetTimeZoneInformationForYear(void)
929 BOOL ret;
930 SYSTEMTIME systemtime;
931 TIME_ZONE_INFORMATION local_tzinfo, tzinfo, tzinfo2;
932 DYNAMIC_TIME_ZONE_INFORMATION dyn_tzinfo;
933 static const WCHAR std_tzname[] = {'G','r','e','e','n','l','a','n','d',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',0};
934 static const WCHAR dlt_tzname[] = {'G','r','e','e','n','l','a','n','d',' ','D','a','y','l','i','g','h','t',' ','T','i','m','e',0};
935 WORD std_day, dlt_day;
937 if (!pGetTimeZoneInformationForYear || !pGetDynamicTimeZoneInformation)
939 win_skip("GetTimeZoneInformationForYear not available\n");
940 return;
943 GetLocalTime(&systemtime);
945 GetTimeZoneInformation(&local_tzinfo);
947 ret = pGetTimeZoneInformationForYear(systemtime.wYear, NULL, &tzinfo);
948 ok(ret == TRUE, "GetTimeZoneInformationForYear failed, err %u\n", GetLastError());
949 ok(tzinfo.Bias == local_tzinfo.Bias, "Expected Bias %d, got %d\n", local_tzinfo.Bias, tzinfo.Bias);
950 ok(!lstrcmpW(tzinfo.StandardName, local_tzinfo.StandardName),
951 "Expected StandardName %s, got %s\n", wine_dbgstr_w(local_tzinfo.StandardName), wine_dbgstr_w(tzinfo.StandardName));
952 ok(!memcmp(&tzinfo.StandardDate, &local_tzinfo.StandardDate, sizeof(SYSTEMTIME)), "StandardDate does not match\n");
953 ok(tzinfo.StandardBias == local_tzinfo.StandardBias, "Expected StandardBias %d, got %d\n", local_tzinfo.StandardBias, tzinfo.StandardBias);
954 ok(!lstrcmpW(tzinfo.DaylightName, local_tzinfo.DaylightName),
955 "Expected DaylightName %s, got %s\n", wine_dbgstr_w(local_tzinfo.DaylightName), wine_dbgstr_w(tzinfo.DaylightName));
956 ok(!memcmp(&tzinfo.DaylightDate, &local_tzinfo.DaylightDate, sizeof(SYSTEMTIME)), "DaylightDate does not match\n");
957 ok(tzinfo.DaylightBias == local_tzinfo.DaylightBias, "Expected DaylightBias %d, got %d\n", local_tzinfo.DaylightBias, tzinfo.DaylightBias);
959 pGetDynamicTimeZoneInformation(&dyn_tzinfo);
961 ret = pGetTimeZoneInformationForYear(systemtime.wYear, &dyn_tzinfo, &tzinfo);
962 ok(ret == TRUE, "GetTimeZoneInformationForYear failed, err %u\n", GetLastError());
963 ok(tzinfo.Bias == local_tzinfo.Bias, "Expected Bias %d, got %d\n", local_tzinfo.Bias, tzinfo.Bias);
964 ok(!lstrcmpW(tzinfo.StandardName, local_tzinfo.StandardName),
965 "Expected StandardName %s, got %s\n", wine_dbgstr_w(local_tzinfo.StandardName), wine_dbgstr_w(tzinfo.StandardName));
966 ok(!memcmp(&tzinfo.StandardDate, &local_tzinfo.StandardDate, sizeof(SYSTEMTIME)), "StandardDate does not match\n");
967 ok(tzinfo.StandardBias == local_tzinfo.StandardBias, "Expected StandardBias %d, got %d\n", local_tzinfo.StandardBias, tzinfo.StandardBias);
968 ok(!lstrcmpW(tzinfo.DaylightName, local_tzinfo.DaylightName),
969 "Expected DaylightName %s, got %s\n", wine_dbgstr_w(local_tzinfo.DaylightName), wine_dbgstr_w(tzinfo.DaylightName));
970 ok(!memcmp(&tzinfo.DaylightDate, &local_tzinfo.DaylightDate, sizeof(SYSTEMTIME)), "DaylightDate does not match\n");
971 ok(tzinfo.DaylightBias == local_tzinfo.DaylightBias, "Expected DaylightBias %d, got %d\n", local_tzinfo.DaylightBias, tzinfo.DaylightBias);
973 memset(&dyn_tzinfo, 0xaa, sizeof(dyn_tzinfo));
974 lstrcpyW(dyn_tzinfo.TimeZoneKeyName, std_tzname);
975 dyn_tzinfo.DynamicDaylightTimeDisabled = FALSE;
977 ret = pGetTimeZoneInformationForYear(2015, &dyn_tzinfo, &tzinfo);
978 ok(ret == TRUE, "GetTimeZoneInformationForYear failed, err %u\n", GetLastError());
979 ok(tzinfo.Bias == 180, "Expected Bias 180, got %d\n", tzinfo.Bias);
980 ok(tzinfo.StandardDate.wMonth == 10, "Expected standard month 10, got %d\n", tzinfo.StandardDate.wMonth);
981 std_day = day_of_month(&tzinfo.StandardDate, 2015);
982 ok(std_day == 24, "Expected standard day 24, got %d\n", std_day);
983 ok(tzinfo.StandardBias == 0, "Expected StandardBias 0, got %d\n", tzinfo.StandardBias);
984 ok(tzinfo.DaylightDate.wMonth == 3, "Expected daylight month 3, got %d\n", tzinfo.DaylightDate.wMonth);
985 dlt_day = day_of_month(&tzinfo.DaylightDate, 2015);
986 ok(dlt_day == 28, "Expected daylight day 28, got %d\n", dlt_day);
987 ok(tzinfo.DaylightBias == -60, "Expected DaylightBias -60, got %d\n", tzinfo.DaylightBias);
989 ret = pGetTimeZoneInformationForYear(2016, &dyn_tzinfo, &tzinfo2);
990 ok(ret == TRUE, "GetTimeZoneInformationForYear failed, err %u\n", GetLastError());
991 ok(!lstrcmpW(tzinfo.StandardName, tzinfo2.StandardName),
992 "Got differing StandardName values %s and %s\n",
993 wine_dbgstr_w(tzinfo.StandardName), wine_dbgstr_w(tzinfo2.StandardName));
994 ok(!lstrcmpW(tzinfo.DaylightName, tzinfo2.DaylightName),
995 "Got differing DaylightName values %s and %s\n",
996 wine_dbgstr_w(tzinfo.DaylightName), wine_dbgstr_w(tzinfo2.DaylightName));
998 memset(&dyn_tzinfo, 0xaa, sizeof(dyn_tzinfo));
999 lstrcpyW(dyn_tzinfo.TimeZoneKeyName, dlt_tzname);
1001 SetLastError(0xdeadbeef);
1002 ret = pGetTimeZoneInformationForYear(2015, &dyn_tzinfo, &tzinfo);
1003 ok((ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND) ||
1004 broken(ret == TRUE) /* vista,7 */,
1005 "GetTimeZoneInformationForYear err %u\n", GetLastError());
1008 static void test_GetTickCount(void)
1010 DWORD t1, t2, t3;
1011 int i = 0;
1013 if (!pNtGetTickCount)
1015 win_skip("NtGetTickCount not implemented\n");
1016 return;
1021 t1 = pNtGetTickCount();
1022 t2 = GetTickCount();
1023 t3 = pNtGetTickCount();
1024 } while(t3 < t1 && i++ < 1); /* allow for wrap, but only once */
1026 ok(t1 <= t2, "out of order %d %d\n", t1, t2);
1027 ok(t2 <= t3, "out of order %d %d\n", t2, t3);
1030 BOOL (WINAPI *pQueryUnbiasedInterruptTime)(ULONGLONG *time);
1031 BOOL (WINAPI *pRtlQueryUnbiasedInterruptTime)(ULONGLONG *time);
1033 static void test_QueryUnbiasedInterruptTime(void)
1035 ULONGLONG time;
1036 BOOL ret;
1038 if (pQueryUnbiasedInterruptTime)
1040 SetLastError( 0xdeadbeef );
1041 ret = pQueryUnbiasedInterruptTime( &time );
1042 ok( ret, "QueryUnbiasedInterruptTime failed err %u\n", GetLastError() );
1043 SetLastError( 0xdeadbeef );
1044 ret = pQueryUnbiasedInterruptTime( NULL );
1045 ok( !ret, "QueryUnbiasedInterruptTime succeeded\n" );
1046 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
1048 else win_skip( "QueryUnbiasedInterruptTime not supported\n" );
1049 if (pRtlQueryUnbiasedInterruptTime)
1051 SetLastError( 0xdeadbeef );
1052 ret = pRtlQueryUnbiasedInterruptTime( &time );
1053 ok( ret, "RtlQueryUnbiasedInterruptTime failed err %u\n", GetLastError() );
1054 SetLastError( 0xdeadbeef );
1055 ret = pRtlQueryUnbiasedInterruptTime( NULL );
1056 ok( !ret, "RtlQueryUnbiasedInterruptTime succeeded\n" );
1057 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
1059 else win_skip( "RtlQueryUnbiasedInterruptTime not supported\n" );
1062 START_TEST(time)
1064 HMODULE hKernel = GetModuleHandleA("kernel32");
1065 HMODULE hntdll = GetModuleHandleA("ntdll");
1066 pTzSpecificLocalTimeToSystemTime = (void *)GetProcAddress(hKernel, "TzSpecificLocalTimeToSystemTime");
1067 pSystemTimeToTzSpecificLocalTime = (void *)GetProcAddress( hKernel, "SystemTimeToTzSpecificLocalTime");
1068 pGetSystemTimes = (void *)GetProcAddress( hKernel, "GetSystemTimes");
1069 pGetCalendarInfoA = (void *)GetProcAddress(hKernel, "GetCalendarInfoA");
1070 pGetCalendarInfoW = (void *)GetProcAddress(hKernel, "GetCalendarInfoW");
1071 pGetDynamicTimeZoneInformation = (void *)GetProcAddress(hKernel, "GetDynamicTimeZoneInformation");
1072 pGetSystemTimePreciseAsFileTime = (void *)GetProcAddress(hKernel, "GetSystemTimePreciseAsFileTime");
1073 pGetTimeZoneInformationForYear = (void *)GetProcAddress(hKernel, "GetTimeZoneInformationForYear");
1074 pQueryUnbiasedInterruptTime = (void *)GetProcAddress(hKernel, "QueryUnbiasedInterruptTime");
1075 pNtGetTickCount = (void *)GetProcAddress(hntdll, "NtGetTickCount");
1076 pRtlQueryUnbiasedInterruptTime = (void *)GetProcAddress(hntdll, "RtlQueryUnbiasedInterruptTime");
1078 test_conversions();
1079 test_invalid_arg();
1080 test_GetTimeZoneInformation();
1081 test_FileTimeToSystemTime();
1082 test_FileTimeToLocalFileTime();
1083 test_TzSpecificLocalTimeToSystemTime();
1084 test_GetSystemTimes();
1085 test_FileTimeToDosDateTime();
1086 test_GetCalendarInfo();
1087 test_GetDynamicTimeZoneInformation();
1088 test_GetSystemTimeAsFileTime();
1089 test_GetSystemTimePreciseAsFileTime();
1090 test_GetTimeZoneInformationForYear();
1091 test_GetTickCount();
1092 test_QueryUnbiasedInterruptTime();