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"
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
);
32 #define SECSPERDAY 86400
33 /* 1601 to 1970 is 369 years plus 89 leap days */
34 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
35 #define TICKSPERSEC 10000000
36 #define TICKSPERMSEC 10000
37 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
40 #define NEWYEAR_1980_HI 0x01a8e79f
41 #define NEWYEAR_1980_LO 0xe1d58000
43 #define MAYDAY_2002_HI 0x01c1f107
44 #define MAYDAY_2002_LO 0xb82b6000
46 #define ATIME_HI 0x1c2349b
47 #define ATIME_LOW 0x580716b0
49 #define LOCAL_ATIME_HI 0x01c23471
50 #define LOCAL_ATIME_LOW 0x6f310eb0
52 #define DOS_DATE(y,m,d) ( (((y)-1980)<<9) | ((m)<<5) | (d) )
53 #define DOS_TIME(h,m,s) ( ((h)<<11) | ((m)<<5) | ((s)>>1) )
56 #define SETUP_1980(st) \
63 (st).wMilliseconds = 0;
65 #define SETUP_2002(st) \
72 (st).wMilliseconds = 0;
74 #define SETUP_ATIME(st) \
81 (st).wMilliseconds = 123;
83 #define SETUP_ZEROTIME(st) \
90 (st).wMilliseconds = 0;
92 #define SETUP_EARLY(st) \
99 (st).wMilliseconds = 999;
102 static void test_conversions(void)
107 memset(&ft
,0,sizeof ft
);
109 SetLastError(0xdeadbeef);
111 ok (!SystemTimeToFileTime(&st
, &ft
), "Conversion succeeded EARLY\n");
112 ok (GetLastError() == ERROR_INVALID_PARAMETER
||
113 GetLastError() == 0xdeadbeef, /* win9x */
114 "EARLY should be INVALID\n");
117 ok (SystemTimeToFileTime(&st
, &ft
), "Conversion failed ZERO_TIME\n");
118 ok( (!((ft
.dwHighDateTime
!= 0) || (ft
.dwLowDateTime
!= 0))),
119 "Wrong time for ATIME: %08x %08x (correct %08x %08x)\n",
120 ft
.dwLowDateTime
, ft
.dwHighDateTime
, 0, 0);
124 ok (SystemTimeToFileTime(&st
,&ft
), "Conversion Failed ATIME\n");
125 ok( (!((ft
.dwHighDateTime
!= ATIME_HI
) || (ft
.dwLowDateTime
!=ATIME_LOW
))),
126 "Wrong time for ATIME: %08x %08x (correct %08x %08x)\n",
127 ft
.dwLowDateTime
, ft
.dwHighDateTime
, ATIME_LOW
, ATIME_HI
);
131 ok (SystemTimeToFileTime(&st
, &ft
), "Conversion failed 2002\n");
133 ok( (!((ft
.dwHighDateTime
!= MAYDAY_2002_HI
) ||
134 (ft
.dwLowDateTime
!=MAYDAY_2002_LO
))),
135 "Wrong time for 2002 %08x %08x (correct %08x %08x)\n", ft
.dwLowDateTime
,
136 ft
.dwHighDateTime
, MAYDAY_2002_LO
, MAYDAY_2002_HI
);
140 ok((SystemTimeToFileTime(&st
, &ft
)), "Conversion failed 1980\n");
142 ok( (!((ft
.dwHighDateTime
!=NEWYEAR_1980_HI
) ||
143 (ft
.dwLowDateTime
!=NEWYEAR_1980_LO
))) ,
144 "Wrong time for 1980 %08x %08x (correct %08x %08x)\n", ft
.dwLowDateTime
,
145 ft
.dwHighDateTime
, NEWYEAR_1980_LO
,NEWYEAR_1980_HI
);
147 ok(DosDateTimeToFileTime(DOS_DATE(1980,1,1),DOS_TIME(0,0,0),&ft
),
148 "DosDateTimeToFileTime() failed\n");
150 ok( (!((ft
.dwHighDateTime
!=NEWYEAR_1980_HI
) ||
151 (ft
.dwLowDateTime
!=NEWYEAR_1980_LO
))),
152 "Wrong time DosDateTimeToFileTime %08x %08x (correct %08x %08x)\n",
153 ft
.dwHighDateTime
, ft
.dwLowDateTime
, NEWYEAR_1980_HI
, NEWYEAR_1980_LO
);
157 static void test_invalid_arg(void)
163 /* Invalid argument checks */
165 memset(&ft
,0,sizeof ft
);
166 ok( DosDateTimeToFileTime(DOS_DATE(1980,1,1),DOS_TIME(0,0,0),&ft
), /* this is 1 Jan 1980 00:00:00 */
167 "DosDateTimeToFileTime() failed\n");
169 ok( (ft
.dwHighDateTime
==NEWYEAR_1980_HI
) && (ft
.dwLowDateTime
==NEWYEAR_1980_LO
),
170 "filetime for 1/1/80 00:00:00 was %08x %08x\n", ft
.dwHighDateTime
, ft
.dwLowDateTime
);
172 /* now check SystemTimeToFileTime */
173 memset(&ft
,0,sizeof ft
);
176 /* try with a bad month */
180 ok( !SystemTimeToFileTime(&st
, &ft
), "bad month\n");
182 /* with a bad hour */
186 ok( !SystemTimeToFileTime(&st
, &ft
), "bad hour\n");
188 /* with a bad minute */
192 ok( !SystemTimeToFileTime(&st
, &ft
), "bad minute\n");
195 static LONGLONG
system_time_to_minutes(const SYSTEMTIME
*st
)
201 SetLastError(0xdeadbeef);
202 ret
= SystemTimeToFileTime(st
, &ft
);
203 ok(ret
, "SystemTimeToFileTime error %u\n", GetLastError());
205 minutes
= ((LONGLONG
)ft
.dwHighDateTime
<< 32) + ft
.dwLowDateTime
;
206 minutes
/= (LONGLONG
)600000000; /* convert to minutes */
210 static LONG
get_tz_bias(const TIME_ZONE_INFORMATION
*tzinfo
, DWORD tz_id
)
214 case TIME_ZONE_ID_DAYLIGHT
:
215 if (memcmp(&tzinfo
->StandardDate
, &tzinfo
->DaylightDate
, sizeof(tzinfo
->DaylightDate
)) != 0)
216 return tzinfo
->DaylightBias
;
219 case TIME_ZONE_ID_STANDARD
:
220 return tzinfo
->StandardBias
;
223 trace("unknown time zone id %d\n", tz_id
);
225 case TIME_ZONE_ID_UNKNOWN
:
230 static void test_GetTimeZoneInformation(void)
232 char std_name
[32], dlt_name
[32];
233 TIME_ZONE_INFORMATION tzinfo
, tzinfo1
;
236 SYSTEMTIME st
, current
, utc
, local
;
238 LONGLONG l_time
, s_time
;
242 s_time
= system_time_to_minutes(&st
);
244 SetLastError(0xdeadbeef);
245 res
= SystemTimeToFileTime(&st
, &s_ft
);
246 ok(res
, "SystemTimeToFileTime error %u\n", GetLastError());
247 SetLastError(0xdeadbeef);
248 res
= FileTimeToLocalFileTime(&s_ft
, &l_ft
);
249 ok(res
, "FileTimeToLocalFileTime error %u\n", GetLastError());
250 SetLastError(0xdeadbeef);
251 res
= FileTimeToSystemTime(&l_ft
, &local
);
252 ok(res
, "FileTimeToSystemTime error %u\n", GetLastError());
253 l_time
= system_time_to_minutes(&local
);
255 tz_id
= GetTimeZoneInformation(&tzinfo
);
256 ok(tz_id
!= TIME_ZONE_ID_INVALID
, "GetTimeZoneInformation failed\n");
258 trace("tz_id %u (%s)\n", tz_id
,
259 tz_id
== TIME_ZONE_ID_DAYLIGHT
? "TIME_ZONE_ID_DAYLIGHT" :
260 (tz_id
== TIME_ZONE_ID_STANDARD
? "TIME_ZONE_ID_STANDARD" :
261 (tz_id
== TIME_ZONE_ID_UNKNOWN
? "TIME_ZONE_ID_UNKNOWN" :
262 "TIME_ZONE_ID_INVALID")));
264 WideCharToMultiByte(CP_ACP
, 0, tzinfo
.StandardName
, -1, std_name
, sizeof(std_name
), NULL
, NULL
);
265 WideCharToMultiByte(CP_ACP
, 0, tzinfo
.DaylightName
, -1, dlt_name
, sizeof(dlt_name
), NULL
, NULL
);
266 trace("bias %d, %s - %s\n", tzinfo
.Bias
, std_name
, dlt_name
);
267 trace("standard (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n",
268 tzinfo
.StandardDate
.wDay
, tzinfo
.StandardDate
.wMonth
,
269 tzinfo
.StandardDate
.wYear
, tzinfo
.StandardDate
.wDayOfWeek
,
270 tzinfo
.StandardDate
.wHour
, tzinfo
.StandardDate
.wMinute
,
271 tzinfo
.StandardDate
.wSecond
, tzinfo
.StandardDate
.wMilliseconds
,
272 tzinfo
.StandardBias
);
273 trace("daylight (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n",
274 tzinfo
.DaylightDate
.wDay
, tzinfo
.DaylightDate
.wMonth
,
275 tzinfo
.DaylightDate
.wYear
, tzinfo
.DaylightDate
.wDayOfWeek
,
276 tzinfo
.DaylightDate
.wHour
, tzinfo
.DaylightDate
.wMinute
,
277 tzinfo
.DaylightDate
.wSecond
, tzinfo
.DaylightDate
.wMilliseconds
,
278 tzinfo
.DaylightBias
);
280 diff
= (LONG
)(s_time
- l_time
);
281 ok(diff
== tzinfo
.Bias
+ get_tz_bias(&tzinfo
, tz_id
),
282 "system/local diff %d != tz bias %d\n",
283 diff
, tzinfo
.Bias
+ get_tz_bias(&tzinfo
, tz_id
));
285 ok(SetEnvironmentVariableA("TZ","GMT0") != 0,
286 "SetEnvironmentVariableA failed\n");
287 res
= GetTimeZoneInformation(&tzinfo1
);
288 ok(res
!= TIME_ZONE_ID_INVALID
, "GetTimeZoneInformation failed\n");
290 ok(((tzinfo
.Bias
== tzinfo1
.Bias
) &&
291 (tzinfo
.StandardBias
== tzinfo1
.StandardBias
) &&
292 (tzinfo
.DaylightBias
== tzinfo1
.DaylightBias
)),
293 "Bias influenced by TZ variable\n");
294 ok(SetEnvironmentVariableA("TZ",NULL
) != 0,
295 "SetEnvironmentVariableA failed\n");
297 if (!pSystemTimeToTzSpecificLocalTime
)
299 win_skip("SystemTimeToTzSpecificLocalTime not available\n");
303 diff
= get_tz_bias(&tzinfo
, tz_id
);
306 SetLastError(0xdeadbeef);
307 res
= pSystemTimeToTzSpecificLocalTime(&tzinfo
, &utc
, ¤t
);
308 if (!res
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
310 win_skip("SystemTimeToTzSpecificLocalTime is not implemented\n");
314 ok(res
, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
315 s_time
= system_time_to_minutes(¤t
);
317 tzinfo
.StandardBias
-= 123;
318 tzinfo
.DaylightBias
+= 456;
320 res
= pSystemTimeToTzSpecificLocalTime(&tzinfo
, &utc
, &local
);
321 ok(res
, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
322 l_time
= system_time_to_minutes(&local
);
323 ok(l_time
- s_time
== diff
- get_tz_bias(&tzinfo
, tz_id
), "got %d, expected %d\n",
324 (LONG
)(l_time
- s_time
), diff
- get_tz_bias(&tzinfo
, tz_id
));
326 /* pretend that there is no transition dates */
327 tzinfo
.DaylightDate
.wDay
= 0;
328 tzinfo
.DaylightDate
.wMonth
= 0;
329 tzinfo
.DaylightDate
.wYear
= 0;
330 tzinfo
.StandardDate
.wDay
= 0;
331 tzinfo
.StandardDate
.wMonth
= 0;
332 tzinfo
.StandardDate
.wYear
= 0;
334 res
= pSystemTimeToTzSpecificLocalTime(&tzinfo
, &utc
, &local
);
335 ok(res
, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
336 l_time
= system_time_to_minutes(&local
);
337 ok(l_time
- s_time
== diff
, "got %d, expected %d\n",
338 (LONG
)(l_time
- s_time
), diff
);
341 static void test_FileTimeToSystemTime(void)
345 ULONGLONG time
= (ULONGLONG
)TICKSPERSEC
+ TICKS_1601_TO_1970
;
348 ft
.dwHighDateTime
= 0;
349 ft
.dwLowDateTime
= 0;
350 ret
= FileTimeToSystemTime(&ft
, &st
);
352 "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
353 ok(((st
.wYear
== 1601) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
354 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 0) &&
355 (st
.wMilliseconds
== 0)),
356 "Got Year %4d Month %2d Day %2d\n", st
.wYear
, st
.wMonth
, st
.wDay
);
358 ft
.dwHighDateTime
= (UINT
)(time
>> 32);
359 ft
.dwLowDateTime
= (UINT
)time
;
360 ret
= FileTimeToSystemTime(&ft
, &st
);
362 "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
363 ok(((st
.wYear
== 1970) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
364 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 1) &&
365 (st
.wMilliseconds
== 0)),
366 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
367 st
.wYear
, st
.wMonth
, st
.wDay
, st
.wHour
, st
.wMinute
, st
.wSecond
,
371 static void test_FileTimeToLocalFileTime(void)
375 TIME_ZONE_INFORMATION tzinfo
;
376 DWORD res
= GetTimeZoneInformation(&tzinfo
);
377 ULONGLONG time
= (ULONGLONG
)TICKSPERSEC
+ TICKS_1601_TO_1970
+
378 (LONGLONG
)(tzinfo
.Bias
+
379 ( res
== TIME_ZONE_ID_STANDARD
? tzinfo
.StandardBias
:
380 ( res
== TIME_ZONE_ID_DAYLIGHT
? tzinfo
.DaylightBias
: 0 ))) *
381 SECSPERMIN
*TICKSPERSEC
;
384 ok( res
!= TIME_ZONE_ID_INVALID
, "GetTimeZoneInformation failed\n");
385 ft
.dwHighDateTime
= (UINT
)(time
>> 32);
386 ft
.dwLowDateTime
= (UINT
)time
;
387 ret
= FileTimeToLocalFileTime(&ft
, &lft
);
389 "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
390 FileTimeToSystemTime(&lft
, &st
);
391 ok(((st
.wYear
== 1970) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
392 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 1) &&
393 (st
.wMilliseconds
== 0)),
394 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
395 st
.wYear
, st
.wMonth
, st
.wDay
, st
.wHour
, st
.wMinute
, st
.wSecond
,
398 ok(SetEnvironmentVariableA("TZ","GMT") != 0,
399 "SetEnvironmentVariableA failed\n");
400 ok(res
!= TIME_ZONE_ID_INVALID
, "GetTimeZoneInformation failed\n");
401 ret
= FileTimeToLocalFileTime(&ft
, &lft
);
403 "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
404 FileTimeToSystemTime(&lft
, &st
);
405 ok(((st
.wYear
== 1970) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
406 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 1) &&
407 (st
.wMilliseconds
== 0)),
408 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
409 st
.wYear
, st
.wMonth
, st
.wDay
, st
.wHour
, st
.wMinute
, st
.wSecond
,
411 ok(SetEnvironmentVariableA("TZ",NULL
) != 0,
412 "SetEnvironmentVariableA failed\n");
416 int nr
; /* test case number for easier lookup */
417 TIME_ZONE_INFORMATION
*ptz
; /* ptr to timezone */
418 SYSTEMTIME slt
; /* system/local time to convert */
419 WORD ehour
; /* expected hour */
422 static void test_TzSpecificLocalTimeToSystemTime(void)
424 TIME_ZONE_INFORMATION tzE
, tzW
, tzS
;
428 if (!pTzSpecificLocalTimeToSystemTime
|| !pSystemTimeToTzSpecificLocalTime
)
430 win_skip("TzSpecificLocalTimeToSystemTime or SystemTimeToTzSpecificLocalTime not available\n");
434 ZeroMemory( &tzE
, sizeof(tzE
));
435 ZeroMemory( &tzW
, sizeof(tzW
));
436 ZeroMemory( &tzS
, sizeof(tzS
));
437 /* timezone Eastern hemisphere */
440 tzE
.DaylightBias
=-60;
441 tzE
.StandardDate
.wMonth
=10;
442 tzE
.StandardDate
.wDayOfWeek
=0; /* Sunday */
443 tzE
.StandardDate
.wDay
=5; /* last (Sunday) of the month */
444 tzE
.StandardDate
.wHour
=3;
445 tzE
.DaylightDate
.wMonth
=3;
446 tzE
.DaylightDate
.wDay
=5;
447 tzE
.DaylightDate
.wHour
=2;
448 /* timezone Western hemisphere */
451 tzW
.DaylightBias
=-60;
452 tzW
.StandardDate
.wMonth
=10;
453 tzW
.StandardDate
.wDayOfWeek
=0; /* Sunday */
454 tzW
.StandardDate
.wDay
=4; /* 4th (Sunday) of the month */
455 tzW
.StandardDate
.wHour
=2;
456 tzW
.DaylightDate
.wMonth
=4;
457 tzW
.DaylightDate
.wDay
=1;
458 tzW
.DaylightDate
.wHour
=2;
459 /* timezone Southern hemisphere */
462 tzS
.DaylightBias
=-60;
463 tzS
.StandardDate
.wMonth
=4;
464 tzS
.StandardDate
.wDayOfWeek
=0; /*Sunday */
465 tzS
.StandardDate
.wDay
=1; /* 1st (Sunday) of the month */
466 tzS
.StandardDate
.wHour
=2;
467 tzS
.DaylightDate
.wMonth
=10;
468 tzS
.DaylightDate
.wDay
=4;
469 tzS
.DaylightDate
.wHour
=2;
471 /* TzSpecificLocalTimeToSystemTime */
472 { TZLT2ST_case cases
[] = {
473 /* standard->daylight transition */
474 { 1, &tzE
, {2004,3,-1,28,1,0,0,0}, 15 },
475 { 2, &tzE
, {2004,3,-1,28,1,59,59,999}, 15},
476 { 3, &tzE
, {2004,3,-1,28,2,0,0,0}, 15},
477 /* daylight->standard transition */
478 { 4, &tzE
, {2004,10,-1,31,2,0,0,0} , 15 },
479 { 5, &tzE
, {2004,10,-1,31,2,59,59,999}, 15 },
480 { 6, &tzE
, {2004,10,-1,31,3,0,0,0}, 17 },
481 /* West and with fixed weekday of the month */
482 { 7, &tzW
, {2004,4,-1,4,1,0,0,0}, 5},
483 { 8, &tzW
, {2004,4,-1,4,1,59,59,999}, 5},
484 { 9, &tzW
, {2004,4,-1,4,2,0,0,0}, 5},
485 { 10, &tzW
, {2004,10,-1,24,1,0,0,0}, 4},
486 { 11, &tzW
, {2004,10,-1,24,1,59,59,999}, 4},
487 { 12, &tzW
, {2004,10,-1,24,2,0,0,0 }, 6},
489 { 13, &tzS
, {2004,4,-1,4,1,0,0,0}, 4},
490 { 14, &tzS
, {2004,4,-1,4,1,59,59,999}, 4},
491 { 15, &tzS
, {2004,4,-1,4,2,0,0,0}, 6},
492 { 16, &tzS
, {2004,10,-1,24,1,0,0,0}, 5},
493 { 17, &tzS
, {2004,10,-1,24,1,59,59,999}, 5},
494 { 18, &tzS
, {2004,10,-1,24,2,0,0,0}, 5},
497 /* days of transitions to put into the cases array */
500 {28,31,4,24,4,24} /* 1999 */
501 , {26,29,2,22,2,22} /* 2000 */
502 , {25,28,1,28,1,28} /* 2001 */
503 , {31,27,7,27,7,27} /* 2002 */
504 , {30,26,6,26,6,26} /* 2003 */
505 , {28,31,4,24,4,24} /* 2004 */
506 , {27,30,3,23,3,23} /* 2005 */
507 , {26,29,2,22,2,22} /* 2006 */
508 , {25,28,1,28,1,28} /* 2007 */
509 , {30,26,6,26,6,26} /* 2008 */
510 , {29,25,5,25,5,25} /* 2009 */
511 , {28,31,4,24,4,24} /* 2010 */
512 , {27,30,3,23,3,23} /* 2011 */
513 , {25,28,1,28,1,28} /* 2012 */
514 , {31,27,7,27,7,27} /* 2013 */
515 , {30,26,6,26,6,26} /* 2014 */
516 , {29,25,5,25,5,25} /* 2015 */
517 , {27,30,3,23,3,23} /* 2016 */
518 , {26,29,2,22,2,22} /* 2017 */
519 , {25,28,1,28,1,28} /* 2018 */
520 , {31,27,7,27,7,27} /* 2019 */
523 for( j
=0 , year
= 1999; yeardays
[j
][0] ; j
++, year
++) {
524 for (i
=0; cases
[i
].nr
; i
++) {
525 if(i
) cases
[i
].nr
+= 18;
526 cases
[i
].slt
.wYear
= year
;
527 cases
[i
].slt
.wDay
= yeardays
[j
][i
/3];
528 pTzSpecificLocalTimeToSystemTime( cases
[i
].ptz
, &(cases
[i
].slt
), &result
);
529 ok( result
.wHour
== cases
[i
].ehour
,
530 "Test TzSpecificLocalTimeToSystemTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n",
531 cases
[i
].nr
, result
.wYear
, result
.wMonth
, result
.wDay
,
532 result
.wHour
, result
.wMinute
, cases
[i
].ehour
);
536 /* SystemTimeToTzSpecificLocalTime */
537 { TZLT2ST_case cases
[] = {
538 /* standard->daylight transition */
539 { 1, &tzE
, {2004,3,-1,27,15,0,0,0}, 1 },
540 { 2, &tzE
, {2004,3,-1,27,15,59,59,999}, 1},
541 { 3, &tzE
, {2004,3,-1,27,16,0,0,0}, 3},
542 /* daylight->standard transition */
543 { 4, &tzE
, {2004,10,-1,30,15,0,0,0}, 2 },
544 { 5, &tzE
, {2004,10,-1,30,15,59,59,999}, 2 },
545 { 6, &tzE
, {2004,10,-1,30,16,0,0,0}, 2 },
546 /* West and with fixed weekday of the month */
547 { 7, &tzW
, {2004,4,-1,4,5,0,0,0}, 1},
548 { 8, &tzW
, {2004,4,-1,4,5,59,59,999}, 1},
549 { 9, &tzW
, {2004,4,-1,4,6,0,0,0}, 3},
550 { 10, &tzW
, {2004,10,-1,24,4,0,0,0}, 1},
551 { 11, &tzW
, {2004,10,-1,24,4,59,59,999}, 1},
552 { 12, &tzW
, {2004,10,-1,24,5,0,0,0 }, 1},
554 { 13, &tzS
, {2004,4,-1,4,4,0,0,0}, 1},
555 { 14, &tzS
, {2004,4,-1,4,4,59,59,999}, 1},
556 { 15, &tzS
, {2004,4,-1,4,5,0,0,0}, 1},
557 { 16, &tzS
, {2004,10,-1,24,5,0,0,0}, 1},
558 { 17, &tzS
, {2004,10,-1,24,5,59,59,999}, 1},
559 { 18, &tzS
, {2004,10,-1,24,6,0,0,0}, 3},
563 /* days of transitions to put into the cases array */
566 {27,30,4,24,4,24} /* 1999 */
567 , {25,28,2,22,2,22} /* 2000 */
568 , {24,27,1,28,1,28} /* 2001 */
569 , {30,26,7,27,7,27} /* 2002 */
570 , {29,25,6,26,6,26} /* 2003 */
571 , {27,30,4,24,4,24} /* 2004 */
572 , {26,29,3,23,3,23} /* 2005 */
573 , {25,28,2,22,2,22} /* 2006 */
574 , {24,27,1,28,1,28} /* 2007 */
575 , {29,25,6,26,6,26} /* 2008 */
576 , {28,24,5,25,5,25} /* 2009 */
577 , {27,30,4,24,4,24} /* 2010 */
578 , {26,29,3,23,3,23} /* 2011 */
579 , {24,27,1,28,1,28} /* 2012 */
580 , {30,26,7,27,7,27} /* 2013 */
581 , {29,25,6,26,6,26} /* 2014 */
582 , {28,24,5,25,5,25} /* 2015 */
583 , {26,29,3,23,3,23} /* 2016 */
584 , {25,28,2,22,2,22} /* 2017 */
585 , {24,27,1,28,1,28} /* 2018 */
586 , {30,26,7,27,7,27} /* 2019 */
589 for( j
=0 , year
= 1999; yeardays
[j
][0] ; j
++, year
++) {
590 for (i
=0; cases
[i
].nr
; i
++) {
591 if(i
) cases
[i
].nr
+= 18;
592 cases
[i
].slt
.wYear
= year
;
593 cases
[i
].slt
.wDay
= yeardays
[j
][i
/3];
594 pSystemTimeToTzSpecificLocalTime( cases
[i
].ptz
, &(cases
[i
].slt
), &result
);
595 ok( result
.wHour
== cases
[i
].ehour
,
596 "Test SystemTimeToTzSpecificLocalTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n",
597 cases
[i
].nr
, result
.wYear
, result
.wMonth
, result
.wDay
,
598 result
.wHour
, result
.wMinute
, cases
[i
].ehour
);
605 static void test_FileTimeToDosDateTime(void)
608 WORD fatdate
, fattime
;
614 FileTimeToDosDateTime(NULL
, NULL
, NULL
);
616 /* Parameter checking */
617 SetLastError(0xdeadbeef);
618 ret
= FileTimeToDosDateTime(&ft
, NULL
, NULL
);
619 ok(!ret
, "expected failure\n");
620 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
621 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
623 SetLastError(0xdeadbeef);
624 ret
= FileTimeToDosDateTime(&ft
, &fatdate
, NULL
);
625 ok(!ret
, "expected failure\n");
626 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
627 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
629 SetLastError(0xdeadbeef);
630 ret
= FileTimeToDosDateTime(&ft
, NULL
, &fattime
);
631 ok(!ret
, "expected failure\n");
632 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
633 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
635 SetLastError(0xdeadbeef);
636 ret
= FileTimeToDosDateTime(&ft
, &fatdate
, &fattime
);
637 ok(!ret
, "expected failure\n");
638 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
639 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
642 static void test_GetCalendarInfo(void)
649 if (!pGetCalendarInfoA
|| !pGetCalendarInfoW
)
651 trace( "GetCalendarInfo missing\n" );
655 ret
= pGetCalendarInfoA( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
| CAL_RETURN_NUMBER
,
657 ok( ret
, "GetCalendarInfoA failed err %u\n", GetLastError() );
658 ok( ret
== sizeof(val1
), "wrong size %u\n", ret
);
659 ok( val1
>= 2000 && val1
< 2100, "wrong value %u\n", val1
);
661 ret
= pGetCalendarInfoW( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
| CAL_RETURN_NUMBER
,
663 ok( ret
, "GetCalendarInfoW failed err %u\n", GetLastError() );
664 ok( ret
== sizeof(val2
)/sizeof(WCHAR
), "wrong size %u\n", ret
);
665 ok( val1
== val2
, "A/W mismatch %u/%u\n", val1
, val2
);
667 ret
= pGetCalendarInfoA( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
, bufferA
, sizeof(bufferA
), NULL
);
668 ok( ret
, "GetCalendarInfoA failed err %u\n", GetLastError() );
669 ok( ret
== 5, "wrong size %u\n", ret
);
670 ok( atoi( bufferA
) == val1
, "wrong value %s/%u\n", bufferA
, val1
);
672 ret
= pGetCalendarInfoW( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
, bufferW
, sizeof(bufferW
), NULL
);
673 ok( ret
, "GetCalendarInfoW failed err %u\n", GetLastError() );
674 ok( ret
== 5, "wrong size %u\n", ret
);
675 memset( bufferA
, 0x55, sizeof(bufferA
) );
676 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, bufferA
, sizeof(bufferA
), NULL
, NULL
);
677 ok( atoi( bufferA
) == val1
, "wrong value %s/%u\n", bufferA
, val1
);
679 ret
= pGetCalendarInfoA( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
| CAL_RETURN_NUMBER
,
681 ok( !ret
, "GetCalendarInfoA succeeded\n" );
682 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
684 ret
= pGetCalendarInfoA( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
, NULL
, 0, NULL
);
685 ok( ret
, "GetCalendarInfoA failed err %u\n", GetLastError() );
686 ok( ret
== 5, "wrong size %u\n", ret
);
688 ret
= pGetCalendarInfoW( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
| CAL_RETURN_NUMBER
,
690 ok( !ret
, "GetCalendarInfoW succeeded\n" );
691 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
693 ret
= pGetCalendarInfoW( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
, NULL
, 0, NULL
);
694 ok( ret
, "GetCalendarInfoW failed err %u\n", GetLastError() );
695 ok( ret
== 5, "wrong size %u\n", ret
);
700 HMODULE hKernel
= GetModuleHandle("kernel32");
701 pTzSpecificLocalTimeToSystemTime
= (void *)GetProcAddress(hKernel
, "TzSpecificLocalTimeToSystemTime");
702 pSystemTimeToTzSpecificLocalTime
= (void *)GetProcAddress( hKernel
, "SystemTimeToTzSpecificLocalTime");
703 pGetCalendarInfoA
= (void *)GetProcAddress(hKernel
, "GetCalendarInfoA");
704 pGetCalendarInfoW
= (void *)GetProcAddress(hKernel
, "GetCalendarInfoW");
708 test_GetTimeZoneInformation();
709 test_FileTimeToSystemTime();
710 test_FileTimeToLocalFileTime();
711 test_TzSpecificLocalTimeToSystemTime();
712 test_FileTimeToDosDateTime();
713 test_GetCalendarInfo();