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
);
340 /* test 23:01, 31st of December date */
341 memset(&tzinfo
, 0, sizeof(tzinfo
));
342 tzinfo
.StandardDate
.wMonth
= 10;
343 tzinfo
.StandardDate
.wDay
= 5;
344 tzinfo
.StandardDate
.wHour
= 2;
345 tzinfo
.StandardDate
.wMinute
= 0;
346 tzinfo
.DaylightDate
.wMonth
= 4;
347 tzinfo
.DaylightDate
.wDay
= 1;
348 tzinfo
.DaylightDate
.wHour
= 2;
350 tzinfo
.StandardBias
= 0;
351 tzinfo
.DaylightBias
= -60;
357 res
= pSystemTimeToTzSpecificLocalTime(&tzinfo
, &utc
, &local
);
358 ok(res
, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
359 ok(local
.wYear
==2012 && local
.wMonth
==12 && local
.wDay
==31 && local
.wHour
==23 && local
.wMinute
==1,
360 "got (%d-%d-%d %02d:%02d), expected (2012-12-31 23:01)\n",
361 local
.wYear
, local
.wMonth
, local
.wDay
, local
.wHour
, local
.wMinute
);
364 static void test_FileTimeToSystemTime(void)
368 ULONGLONG time
= (ULONGLONG
)TICKSPERSEC
+ TICKS_1601_TO_1970
;
371 ft
.dwHighDateTime
= 0;
372 ft
.dwLowDateTime
= 0;
373 ret
= FileTimeToSystemTime(&ft
, &st
);
375 "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
376 ok(((st
.wYear
== 1601) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
377 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 0) &&
378 (st
.wMilliseconds
== 0)),
379 "Got Year %4d Month %2d Day %2d\n", st
.wYear
, st
.wMonth
, st
.wDay
);
381 ft
.dwHighDateTime
= (UINT
)(time
>> 32);
382 ft
.dwLowDateTime
= (UINT
)time
;
383 ret
= FileTimeToSystemTime(&ft
, &st
);
385 "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
386 ok(((st
.wYear
== 1970) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
387 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 1) &&
388 (st
.wMilliseconds
== 0)),
389 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
390 st
.wYear
, st
.wMonth
, st
.wDay
, st
.wHour
, st
.wMinute
, st
.wSecond
,
394 static void test_FileTimeToLocalFileTime(void)
398 TIME_ZONE_INFORMATION tzinfo
;
399 DWORD res
= GetTimeZoneInformation(&tzinfo
);
400 ULONGLONG time
= (ULONGLONG
)TICKSPERSEC
+ TICKS_1601_TO_1970
+
401 (LONGLONG
)(tzinfo
.Bias
+
402 ( res
== TIME_ZONE_ID_STANDARD
? tzinfo
.StandardBias
:
403 ( res
== TIME_ZONE_ID_DAYLIGHT
? tzinfo
.DaylightBias
: 0 ))) *
404 SECSPERMIN
*TICKSPERSEC
;
407 ok( res
!= TIME_ZONE_ID_INVALID
, "GetTimeZoneInformation failed\n");
408 ft
.dwHighDateTime
= (UINT
)(time
>> 32);
409 ft
.dwLowDateTime
= (UINT
)time
;
410 ret
= FileTimeToLocalFileTime(&ft
, &lft
);
412 "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
413 FileTimeToSystemTime(&lft
, &st
);
414 ok(((st
.wYear
== 1970) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
415 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 1) &&
416 (st
.wMilliseconds
== 0)),
417 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
418 st
.wYear
, st
.wMonth
, st
.wDay
, st
.wHour
, st
.wMinute
, st
.wSecond
,
421 ok(SetEnvironmentVariableA("TZ","GMT") != 0,
422 "SetEnvironmentVariableA failed\n");
423 ok(res
!= TIME_ZONE_ID_INVALID
, "GetTimeZoneInformation failed\n");
424 ret
= FileTimeToLocalFileTime(&ft
, &lft
);
426 "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
427 FileTimeToSystemTime(&lft
, &st
);
428 ok(((st
.wYear
== 1970) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
429 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 1) &&
430 (st
.wMilliseconds
== 0)),
431 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
432 st
.wYear
, st
.wMonth
, st
.wDay
, st
.wHour
, st
.wMinute
, st
.wSecond
,
434 ok(SetEnvironmentVariableA("TZ",NULL
) != 0,
435 "SetEnvironmentVariableA failed\n");
439 int nr
; /* test case number for easier lookup */
440 TIME_ZONE_INFORMATION
*ptz
; /* ptr to timezone */
441 SYSTEMTIME slt
; /* system/local time to convert */
442 WORD ehour
; /* expected hour */
445 static void test_TzSpecificLocalTimeToSystemTime(void)
447 TIME_ZONE_INFORMATION tzE
, tzW
, tzS
;
451 if (!pTzSpecificLocalTimeToSystemTime
|| !pSystemTimeToTzSpecificLocalTime
)
453 win_skip("TzSpecificLocalTimeToSystemTime or SystemTimeToTzSpecificLocalTime not available\n");
457 ZeroMemory( &tzE
, sizeof(tzE
));
458 ZeroMemory( &tzW
, sizeof(tzW
));
459 ZeroMemory( &tzS
, sizeof(tzS
));
460 /* timezone Eastern hemisphere */
463 tzE
.DaylightBias
=-60;
464 tzE
.StandardDate
.wMonth
=10;
465 tzE
.StandardDate
.wDayOfWeek
=0; /* Sunday */
466 tzE
.StandardDate
.wDay
=5; /* last (Sunday) of the month */
467 tzE
.StandardDate
.wHour
=3;
468 tzE
.DaylightDate
.wMonth
=3;
469 tzE
.DaylightDate
.wDay
=5;
470 tzE
.DaylightDate
.wHour
=2;
471 /* timezone Western hemisphere */
474 tzW
.DaylightBias
=-60;
475 tzW
.StandardDate
.wMonth
=10;
476 tzW
.StandardDate
.wDayOfWeek
=0; /* Sunday */
477 tzW
.StandardDate
.wDay
=4; /* 4th (Sunday) of the month */
478 tzW
.StandardDate
.wHour
=2;
479 tzW
.DaylightDate
.wMonth
=4;
480 tzW
.DaylightDate
.wDay
=1;
481 tzW
.DaylightDate
.wHour
=2;
482 /* timezone Southern hemisphere */
485 tzS
.DaylightBias
=-60;
486 tzS
.StandardDate
.wMonth
=4;
487 tzS
.StandardDate
.wDayOfWeek
=0; /*Sunday */
488 tzS
.StandardDate
.wDay
=1; /* 1st (Sunday) of the month */
489 tzS
.StandardDate
.wHour
=2;
490 tzS
.DaylightDate
.wMonth
=10;
491 tzS
.DaylightDate
.wDay
=4;
492 tzS
.DaylightDate
.wHour
=2;
494 /* TzSpecificLocalTimeToSystemTime */
495 { TZLT2ST_case cases
[] = {
496 /* standard->daylight transition */
497 { 1, &tzE
, {2004,3,-1,28,1,0,0,0}, 15 },
498 { 2, &tzE
, {2004,3,-1,28,1,59,59,999}, 15},
499 { 3, &tzE
, {2004,3,-1,28,2,0,0,0}, 15},
500 /* daylight->standard transition */
501 { 4, &tzE
, {2004,10,-1,31,2,0,0,0} , 15 },
502 { 5, &tzE
, {2004,10,-1,31,2,59,59,999}, 15 },
503 { 6, &tzE
, {2004,10,-1,31,3,0,0,0}, 17 },
504 /* West and with fixed weekday of the month */
505 { 7, &tzW
, {2004,4,-1,4,1,0,0,0}, 5},
506 { 8, &tzW
, {2004,4,-1,4,1,59,59,999}, 5},
507 { 9, &tzW
, {2004,4,-1,4,2,0,0,0}, 5},
508 { 10, &tzW
, {2004,10,-1,24,1,0,0,0}, 4},
509 { 11, &tzW
, {2004,10,-1,24,1,59,59,999}, 4},
510 { 12, &tzW
, {2004,10,-1,24,2,0,0,0 }, 6},
512 { 13, &tzS
, {2004,4,-1,4,1,0,0,0}, 4},
513 { 14, &tzS
, {2004,4,-1,4,1,59,59,999}, 4},
514 { 15, &tzS
, {2004,4,-1,4,2,0,0,0}, 6},
515 { 16, &tzS
, {2004,10,-1,24,1,0,0,0}, 5},
516 { 17, &tzS
, {2004,10,-1,24,1,59,59,999}, 5},
517 { 18, &tzS
, {2004,10,-1,24,2,0,0,0}, 5},
520 /* days of transitions to put into the cases array */
523 {28,31,4,24,4,24} /* 1999 */
524 , {26,29,2,22,2,22} /* 2000 */
525 , {25,28,1,28,1,28} /* 2001 */
526 , {31,27,7,27,7,27} /* 2002 */
527 , {30,26,6,26,6,26} /* 2003 */
528 , {28,31,4,24,4,24} /* 2004 */
529 , {27,30,3,23,3,23} /* 2005 */
530 , {26,29,2,22,2,22} /* 2006 */
531 , {25,28,1,28,1,28} /* 2007 */
532 , {30,26,6,26,6,26} /* 2008 */
533 , {29,25,5,25,5,25} /* 2009 */
534 , {28,31,4,24,4,24} /* 2010 */
535 , {27,30,3,23,3,23} /* 2011 */
536 , {25,28,1,28,1,28} /* 2012 */
537 , {31,27,7,27,7,27} /* 2013 */
538 , {30,26,6,26,6,26} /* 2014 */
539 , {29,25,5,25,5,25} /* 2015 */
540 , {27,30,3,23,3,23} /* 2016 */
541 , {26,29,2,22,2,22} /* 2017 */
542 , {25,28,1,28,1,28} /* 2018 */
543 , {31,27,7,27,7,27} /* 2019 */
546 for( j
=0 , year
= 1999; yeardays
[j
][0] ; j
++, year
++) {
547 for (i
=0; cases
[i
].nr
; i
++) {
548 if(i
) cases
[i
].nr
+= 18;
549 cases
[i
].slt
.wYear
= year
;
550 cases
[i
].slt
.wDay
= yeardays
[j
][i
/3];
551 pTzSpecificLocalTimeToSystemTime( cases
[i
].ptz
, &(cases
[i
].slt
), &result
);
552 ok( result
.wHour
== cases
[i
].ehour
,
553 "Test TzSpecificLocalTimeToSystemTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n",
554 cases
[i
].nr
, result
.wYear
, result
.wMonth
, result
.wDay
,
555 result
.wHour
, result
.wMinute
, cases
[i
].ehour
);
559 /* SystemTimeToTzSpecificLocalTime */
560 { TZLT2ST_case cases
[] = {
561 /* standard->daylight transition */
562 { 1, &tzE
, {2004,3,-1,27,15,0,0,0}, 1 },
563 { 2, &tzE
, {2004,3,-1,27,15,59,59,999}, 1},
564 { 3, &tzE
, {2004,3,-1,27,16,0,0,0}, 3},
565 /* daylight->standard transition */
566 { 4, &tzE
, {2004,10,-1,30,15,0,0,0}, 2 },
567 { 5, &tzE
, {2004,10,-1,30,15,59,59,999}, 2 },
568 { 6, &tzE
, {2004,10,-1,30,16,0,0,0}, 2 },
569 /* West and with fixed weekday of the month */
570 { 7, &tzW
, {2004,4,-1,4,5,0,0,0}, 1},
571 { 8, &tzW
, {2004,4,-1,4,5,59,59,999}, 1},
572 { 9, &tzW
, {2004,4,-1,4,6,0,0,0}, 3},
573 { 10, &tzW
, {2004,10,-1,24,4,0,0,0}, 1},
574 { 11, &tzW
, {2004,10,-1,24,4,59,59,999}, 1},
575 { 12, &tzW
, {2004,10,-1,24,5,0,0,0 }, 1},
577 { 13, &tzS
, {2004,4,-1,4,4,0,0,0}, 1},
578 { 14, &tzS
, {2004,4,-1,4,4,59,59,999}, 1},
579 { 15, &tzS
, {2004,4,-1,4,5,0,0,0}, 1},
580 { 16, &tzS
, {2004,10,-1,24,5,0,0,0}, 1},
581 { 17, &tzS
, {2004,10,-1,24,5,59,59,999}, 1},
582 { 18, &tzS
, {2004,10,-1,24,6,0,0,0}, 3},
586 /* days of transitions to put into the cases array */
589 {27,30,4,24,4,24} /* 1999 */
590 , {25,28,2,22,2,22} /* 2000 */
591 , {24,27,1,28,1,28} /* 2001 */
592 , {30,26,7,27,7,27} /* 2002 */
593 , {29,25,6,26,6,26} /* 2003 */
594 , {27,30,4,24,4,24} /* 2004 */
595 , {26,29,3,23,3,23} /* 2005 */
596 , {25,28,2,22,2,22} /* 2006 */
597 , {24,27,1,28,1,28} /* 2007 */
598 , {29,25,6,26,6,26} /* 2008 */
599 , {28,24,5,25,5,25} /* 2009 */
600 , {27,30,4,24,4,24} /* 2010 */
601 , {26,29,3,23,3,23} /* 2011 */
602 , {24,27,1,28,1,28} /* 2012 */
603 , {30,26,7,27,7,27} /* 2013 */
604 , {29,25,6,26,6,26} /* 2014 */
605 , {28,24,5,25,5,25} /* 2015 */
606 , {26,29,3,23,3,23} /* 2016 */
607 , {25,28,2,22,2,22} /* 2017 */
608 , {24,27,1,28,1,28} /* 2018 */
609 , {30,26,7,27,7,27} /* 2019 */
612 for( j
=0 , year
= 1999; yeardays
[j
][0] ; j
++, year
++) {
613 for (i
=0; cases
[i
].nr
; i
++) {
614 if(i
) cases
[i
].nr
+= 18;
615 cases
[i
].slt
.wYear
= year
;
616 cases
[i
].slt
.wDay
= yeardays
[j
][i
/3];
617 pSystemTimeToTzSpecificLocalTime( cases
[i
].ptz
, &(cases
[i
].slt
), &result
);
618 ok( result
.wHour
== cases
[i
].ehour
,
619 "Test SystemTimeToTzSpecificLocalTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n",
620 cases
[i
].nr
, result
.wYear
, result
.wMonth
, result
.wDay
,
621 result
.wHour
, result
.wMinute
, cases
[i
].ehour
);
628 static void test_FileTimeToDosDateTime(void)
631 WORD fatdate
, fattime
;
637 FileTimeToDosDateTime(NULL
, NULL
, NULL
);
639 /* Parameter checking */
640 SetLastError(0xdeadbeef);
641 ret
= FileTimeToDosDateTime(&ft
, NULL
, NULL
);
642 ok(!ret
, "expected failure\n");
643 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
644 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
646 SetLastError(0xdeadbeef);
647 ret
= FileTimeToDosDateTime(&ft
, &fatdate
, 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
, NULL
, &fattime
);
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
, &fatdate
, &fattime
);
660 ok(!ret
, "expected failure\n");
661 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
662 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
665 static void test_GetCalendarInfo(void)
672 if (!pGetCalendarInfoA
|| !pGetCalendarInfoW
)
674 trace( "GetCalendarInfo missing\n" );
678 ret
= pGetCalendarInfoA( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
| CAL_RETURN_NUMBER
,
680 ok( ret
, "GetCalendarInfoA failed err %u\n", GetLastError() );
681 ok( ret
== sizeof(val1
), "wrong size %u\n", ret
);
682 ok( val1
>= 2000 && val1
< 2100, "wrong value %u\n", val1
);
684 ret
= pGetCalendarInfoW( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
| CAL_RETURN_NUMBER
,
686 ok( ret
, "GetCalendarInfoW failed err %u\n", GetLastError() );
687 ok( ret
== sizeof(val2
)/sizeof(WCHAR
), "wrong size %u\n", ret
);
688 ok( val1
== val2
, "A/W mismatch %u/%u\n", val1
, val2
);
690 ret
= pGetCalendarInfoA( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
, bufferA
, sizeof(bufferA
), NULL
);
691 ok( ret
, "GetCalendarInfoA failed err %u\n", GetLastError() );
692 ok( ret
== 5, "wrong size %u\n", ret
);
693 ok( atoi( bufferA
) == val1
, "wrong value %s/%u\n", bufferA
, val1
);
695 ret
= pGetCalendarInfoW( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
, bufferW
, sizeof(bufferW
), NULL
);
696 ok( ret
, "GetCalendarInfoW failed err %u\n", GetLastError() );
697 ok( ret
== 5, "wrong size %u\n", ret
);
698 memset( bufferA
, 0x55, sizeof(bufferA
) );
699 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, bufferA
, sizeof(bufferA
), NULL
, NULL
);
700 ok( atoi( bufferA
) == val1
, "wrong value %s/%u\n", bufferA
, val1
);
702 ret
= pGetCalendarInfoA( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
| CAL_RETURN_NUMBER
,
704 ok( !ret
, "GetCalendarInfoA succeeded\n" );
705 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
707 ret
= pGetCalendarInfoA( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
, NULL
, 0, NULL
);
708 ok( ret
, "GetCalendarInfoA failed err %u\n", GetLastError() );
709 ok( ret
== 5, "wrong size %u\n", ret
);
711 ret
= pGetCalendarInfoW( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
| CAL_RETURN_NUMBER
,
713 ok( !ret
, "GetCalendarInfoW succeeded\n" );
714 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
716 ret
= pGetCalendarInfoW( 0x0409, CAL_GREGORIAN
, CAL_ITWODIGITYEARMAX
, NULL
, 0, NULL
);
717 ok( ret
, "GetCalendarInfoW failed err %u\n", GetLastError() );
718 ok( ret
== 5, "wrong size %u\n", ret
);
720 ret
= pGetCalendarInfoA( LANG_SYSTEM_DEFAULT
, CAL_GREGORIAN
, CAL_SDAYNAME1
,
721 bufferA
, sizeof(bufferA
), NULL
);
722 ok( ret
, "GetCalendarInfoA failed err %u\n", GetLastError() );
723 ret2
= pGetCalendarInfoA( LANG_SYSTEM_DEFAULT
, CAL_GREGORIAN
, CAL_SDAYNAME1
,
725 ok( ret2
, "GetCalendarInfoA failed err %u\n", GetLastError() );
726 ok( ret
== ret2
, "got %d, expected %d\n", ret2
, ret
);
728 ret2
= pGetCalendarInfoW( LANG_SYSTEM_DEFAULT
, CAL_GREGORIAN
, CAL_SDAYNAME1
,
729 bufferW
, sizeof(bufferW
), NULL
);
730 ok( ret2
, "GetCalendarInfoW failed err %u\n", GetLastError() );
731 ret2
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
732 ok( ret
== ret2
, "got %d, expected %d\n", ret
, ret2
);
738 HMODULE hKernel
= GetModuleHandleA("kernel32");
739 pTzSpecificLocalTimeToSystemTime
= (void *)GetProcAddress(hKernel
, "TzSpecificLocalTimeToSystemTime");
740 pSystemTimeToTzSpecificLocalTime
= (void *)GetProcAddress( hKernel
, "SystemTimeToTzSpecificLocalTime");
741 pGetCalendarInfoA
= (void *)GetProcAddress(hKernel
, "GetCalendarInfoA");
742 pGetCalendarInfoW
= (void *)GetProcAddress(hKernel
, "GetCalendarInfoW");
746 test_GetTimeZoneInformation();
747 test_FileTimeToSystemTime();
748 test_FileTimeToLocalFileTime();
749 test_TzSpecificLocalTimeToSystemTime();
750 test_FileTimeToDosDateTime();
751 test_GetCalendarInfo();