kernel32/tests: Skip not implemented functions.
[wine] / dlls / kernel32 / tests / time.c
1 /*
2  * Unit test suite for time functions
3  *
4  * Copyright 2004 Uwe Bonnes
5  * Copyright 2007 Dmitry Timoshkov
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "wine/test.h"
23 #include "winbase.h"
24 #include "winnls.h"
25
26 static BOOL (WINAPI *pTzSpecificLocalTimeToSystemTime)(LPTIME_ZONE_INFORMATION, LPSYSTEMTIME, LPSYSTEMTIME);
27 static BOOL (WINAPI *pSystemTimeToTzSpecificLocalTime)(LPTIME_ZONE_INFORMATION, LPSYSTEMTIME, LPSYSTEMTIME);
28
29 #define SECSPERMIN         60
30 #define SECSPERDAY        86400
31 /* 1601 to 1970 is 369 years plus 89 leap days */
32 #define SECS_1601_TO_1970  ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
33 #define TICKSPERSEC       10000000
34 #define TICKSPERMSEC      10000
35 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
36
37
38 #define NEWYEAR_1980_HI 0x01a8e79f
39 #define NEWYEAR_1980_LO 0xe1d58000
40
41 #define MAYDAY_2002_HI 0x01c1f107
42 #define MAYDAY_2002_LO 0xb82b6000
43
44 #define ATIME_HI  0x1c2349b
45 #define ATIME_LOW 0x580716b0
46
47 #define LOCAL_ATIME_HI  0x01c23471
48 #define LOCAL_ATIME_LOW 0x6f310eb0
49
50 #define DOS_DATE(y,m,d) ( (((y)-1980)<<9) | ((m)<<5) | (d) )
51 #define DOS_TIME(h,m,s) ( ((h)<<11) | ((m)<<5) | ((s)>>1) )
52
53
54 #define SETUP_1980(st) \
55     (st).wYear = 1980; \
56     (st).wMonth = 1; \
57     (st).wDay = 1; \
58     (st).wHour = 0; \
59     (st).wMinute = 0; \
60     (st).wSecond = 0; \
61     (st).wMilliseconds = 0;
62
63 #define SETUP_2002(st) \
64     (st).wYear = 2002; \
65     (st).wMonth = 5; \
66     (st).wDay = 1; \
67     (st).wHour = 12; \
68     (st).wMinute = 0; \
69     (st).wSecond = 0; \
70     (st).wMilliseconds = 0;
71
72 #define SETUP_ATIME(st) \
73     (st).wYear = 2002; \
74     (st).wMonth = 7; \
75     (st).wDay = 26; \
76     (st).wHour = 11; \
77     (st).wMinute = 55; \
78     (st).wSecond = 32; \
79     (st).wMilliseconds = 123;
80
81 #define SETUP_ZEROTIME(st) \
82     (st).wYear = 1601; \
83     (st).wMonth = 1; \
84     (st).wDay = 1; \
85     (st).wHour = 0; \
86     (st).wMinute = 0; \
87     (st).wSecond = 0; \
88     (st).wMilliseconds = 0;
89
90 #define SETUP_EARLY(st) \
91     (st).wYear = 1600; \
92     (st).wMonth = 12; \
93     (st).wDay = 31; \
94     (st).wHour = 23; \
95     (st).wMinute = 59; \
96     (st).wSecond = 59; \
97     (st).wMilliseconds = 999;
98
99
100 static void test_conversions(void)
101 {
102     FILETIME ft;
103     SYSTEMTIME st;
104
105     memset(&ft,0,sizeof ft);
106
107     SETUP_EARLY(st)
108     ok (!SystemTimeToFileTime(&st, &ft), "Conversion succeeded EARLY\n");
109     ok (GetLastError() == ERROR_INVALID_PARAMETER, "EARLY should be INVALID\n");
110
111     SETUP_ZEROTIME(st)
112     ok (SystemTimeToFileTime(&st, &ft), "Conversion failed ZERO_TIME\n");
113     ok( (!((ft.dwHighDateTime != 0) || (ft.dwLowDateTime != 0))),
114         "Wrong time for ATIME: %08x %08x (correct %08x %08x)\n",
115         ft.dwLowDateTime, ft.dwHighDateTime, 0, 0);
116
117
118     SETUP_ATIME(st)
119     ok (SystemTimeToFileTime(&st,&ft), "Conversion Failed ATIME\n");
120     ok( (!((ft.dwHighDateTime != ATIME_HI) || (ft.dwLowDateTime!=ATIME_LOW))),
121         "Wrong time for ATIME: %08x %08x (correct %08x %08x)\n",
122         ft.dwLowDateTime, ft.dwHighDateTime, ATIME_LOW, ATIME_HI);
123
124
125     SETUP_2002(st)
126     ok (SystemTimeToFileTime(&st, &ft), "Conversion failed 2002\n");
127
128     ok( (!((ft.dwHighDateTime != MAYDAY_2002_HI) ||
129          (ft.dwLowDateTime!=MAYDAY_2002_LO))),
130         "Wrong time for 2002 %08x %08x (correct %08x %08x)\n", ft.dwLowDateTime,
131         ft.dwHighDateTime, MAYDAY_2002_LO, MAYDAY_2002_HI);
132
133
134     SETUP_1980(st)
135     ok((SystemTimeToFileTime(&st, &ft)), "Conversion failed 1980\n");
136
137     ok( (!((ft.dwHighDateTime!=NEWYEAR_1980_HI) ||
138         (ft.dwLowDateTime!=NEWYEAR_1980_LO))) ,
139         "Wrong time for 1980 %08x %08x (correct %08x %08x)\n", ft.dwLowDateTime,
140          ft.dwHighDateTime, NEWYEAR_1980_LO,NEWYEAR_1980_HI  );
141
142     ok(DosDateTimeToFileTime(DOS_DATE(1980,1,1),DOS_TIME(0,0,0),&ft),
143         "DosDateTimeToFileTime() failed\n");
144
145     ok( (!((ft.dwHighDateTime!=NEWYEAR_1980_HI) ||
146          (ft.dwLowDateTime!=NEWYEAR_1980_LO))),
147         "Wrong time DosDateTimeToFileTime %08x %08x (correct %08x %08x)\n",
148         ft.dwHighDateTime, ft.dwLowDateTime, NEWYEAR_1980_HI, NEWYEAR_1980_LO);
149
150 }
151
152 static void test_invalid_arg(void)
153 {
154     FILETIME ft;
155     SYSTEMTIME st;
156
157
158     /* Invalid argument checks */
159
160     memset(&ft,0,sizeof ft);
161     ok( DosDateTimeToFileTime(DOS_DATE(1980,1,1),DOS_TIME(0,0,0),&ft), /* this is 1 Jan 1980 00:00:00 */
162         "DosDateTimeToFileTime() failed\n");
163
164     ok( (ft.dwHighDateTime==NEWYEAR_1980_HI) && (ft.dwLowDateTime==NEWYEAR_1980_LO),
165         "filetime for 1/1/80 00:00:00 was %08x %08x\n", ft.dwHighDateTime, ft.dwLowDateTime);
166
167     /* now check SystemTimeToFileTime */
168     memset(&ft,0,sizeof ft);
169
170
171     /* try with a bad month */
172     SETUP_1980(st)
173     st.wMonth = 0;
174
175     ok( !SystemTimeToFileTime(&st, &ft), "bad month\n");
176
177     /* with a bad hour */
178     SETUP_1980(st)
179     st.wHour = 24;
180
181     ok( !SystemTimeToFileTime(&st, &ft), "bad hour\n");
182
183     /* with a bad minute */
184     SETUP_1980(st)
185     st.wMinute = 60;
186
187     ok( !SystemTimeToFileTime(&st, &ft), "bad minute\n");
188 }
189
190 static LONGLONG system_time_to_minutes(const SYSTEMTIME *st)
191 {
192     BOOL ret;
193     FILETIME ft;
194     LONGLONG minutes;
195
196     SetLastError(0xdeadbeef);
197     ret = SystemTimeToFileTime(st, &ft);
198     ok(ret, "SystemTimeToFileTime error %u\n", GetLastError());
199
200     minutes = ((LONGLONG)ft.dwHighDateTime << 32) + ft.dwLowDateTime;
201     minutes /= (LONGLONG)600000000; /* convert to minutes */
202     return minutes;
203 }
204
205 static LONG get_tz_bias(const TIME_ZONE_INFORMATION *tzinfo, DWORD tz_id)
206 {
207     switch (tz_id)
208     {
209     case TIME_ZONE_ID_DAYLIGHT:
210         return tzinfo->DaylightBias;
211
212     case TIME_ZONE_ID_STANDARD:
213         return tzinfo->StandardBias;
214
215     default:
216         trace("unknown time zone id %d\n", tz_id);
217         /* fall through */
218     case TIME_ZONE_ID_UNKNOWN:
219         return 0;
220     }
221 }
222  
223 static void test_GetTimeZoneInformation(void)
224 {
225     char std_name[32], dlt_name[32];
226     TIME_ZONE_INFORMATION tzinfo, tzinfo1;
227     BOOL res;
228     DWORD tz_id;
229     SYSTEMTIME st, current, utc, local;
230     FILETIME l_ft, s_ft;
231     LONGLONG l_time, s_time;
232     LONG diff;
233
234     GetSystemTime(&st);
235     s_time = system_time_to_minutes(&st);
236
237     SetLastError(0xdeadbeef);
238     res = SystemTimeToFileTime(&st, &s_ft);
239     ok(res, "SystemTimeToFileTime error %u\n", GetLastError());
240     SetLastError(0xdeadbeef);
241     res = FileTimeToLocalFileTime(&s_ft, &l_ft);
242     ok(res, "FileTimeToLocalFileTime error %u\n", GetLastError());
243     SetLastError(0xdeadbeef);
244     res = FileTimeToSystemTime(&l_ft, &local);
245     ok(res, "FileTimeToSystemTime error %u\n", GetLastError());
246     l_time = system_time_to_minutes(&local);
247
248     tz_id = GetTimeZoneInformation(&tzinfo);
249     ok(tz_id != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
250
251     trace("tz_id %u (%s)\n", tz_id,
252           tz_id == TIME_ZONE_ID_DAYLIGHT ? "TIME_ZONE_ID_DAYLIGHT" :
253           (tz_id == TIME_ZONE_ID_STANDARD ? "TIME_ZONE_ID_STANDARD" :
254           (tz_id == TIME_ZONE_ID_UNKNOWN ? "TIME_ZONE_ID_UNKNOWN" :
255           "TIME_ZONE_ID_INVALID")));
256
257     WideCharToMultiByte(CP_ACP, 0, tzinfo.StandardName, -1, std_name, sizeof(std_name), NULL, NULL);
258     WideCharToMultiByte(CP_ACP, 0, tzinfo.DaylightName, -1, dlt_name, sizeof(dlt_name), NULL, NULL);
259     trace("bias %d, %s - %s\n", tzinfo.Bias, std_name, dlt_name);
260     trace("standard (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n",
261         tzinfo.StandardDate.wDay, tzinfo.StandardDate.wMonth,
262         tzinfo.StandardDate.wYear, tzinfo.StandardDate.wDayOfWeek,
263         tzinfo.StandardDate.wHour, tzinfo.StandardDate.wMinute,
264         tzinfo.StandardDate.wSecond, tzinfo.StandardDate.wMilliseconds,
265         tzinfo.StandardBias);
266     trace("daylight (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n",
267         tzinfo.DaylightDate.wDay, tzinfo.DaylightDate.wMonth,
268         tzinfo.DaylightDate.wYear, tzinfo.DaylightDate.wDayOfWeek,
269         tzinfo.DaylightDate.wHour, tzinfo.DaylightDate.wMinute,
270         tzinfo.DaylightDate.wSecond, tzinfo.DaylightDate.wMilliseconds,
271         tzinfo.DaylightBias);
272
273     diff = (LONG)(s_time - l_time);
274     ok(diff == tzinfo.Bias + get_tz_bias(&tzinfo, tz_id),
275        "system/local diff %d != tz bias %d\n",
276        diff, tzinfo.Bias + get_tz_bias(&tzinfo, tz_id));
277
278     ok(SetEnvironmentVariableA("TZ","GMT0") != 0,
279        "SetEnvironmentVariableA failed\n");
280     res =  GetTimeZoneInformation(&tzinfo1);
281     ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
282
283     ok(((tzinfo.Bias == tzinfo1.Bias) && 
284         (tzinfo.StandardBias == tzinfo1.StandardBias) &&
285         (tzinfo.DaylightBias == tzinfo1.DaylightBias)),
286        "Bias influenced by TZ variable\n"); 
287     ok(SetEnvironmentVariableA("TZ",NULL) != 0,
288        "SetEnvironmentVariableA failed\n");
289
290     if (!pSystemTimeToTzSpecificLocalTime)
291     {
292         skip("SystemTimeToTzSpecificLocalTime not present\n");
293         return;
294     }
295
296     diff = get_tz_bias(&tzinfo, tz_id);
297
298     utc = st;
299     SetLastError(0xdeadbeef);
300     res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &current);
301     if (!res && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
302     {
303         skip("SystemTimeToTzSpecificLocalTime is not implemented\n");
304         return;
305     }
306
307     ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
308     s_time = system_time_to_minutes(&current);
309
310     tzinfo.StandardBias -= 123;
311     tzinfo.DaylightBias += 456;
312
313     res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
314     ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
315     l_time = system_time_to_minutes(&local);
316     ok(l_time - s_time == diff - get_tz_bias(&tzinfo, tz_id), "got %d, expected %d\n",
317        (LONG)(l_time - s_time), diff - get_tz_bias(&tzinfo, tz_id));
318
319     /* pretend that there is no transition dates */
320     tzinfo.DaylightDate.wDay = 0;
321     tzinfo.DaylightDate.wMonth = 0;
322     tzinfo.DaylightDate.wYear = 0;
323     tzinfo.StandardDate.wDay = 0;
324     tzinfo.StandardDate.wMonth = 0;
325     tzinfo.StandardDate.wYear = 0;
326
327     res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
328     ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
329     l_time = system_time_to_minutes(&local);
330     ok(l_time - s_time == diff, "got %d, expected %d\n",
331        (LONG)(l_time - s_time), diff);
332 }
333
334 static void test_FileTimeToSystemTime(void)
335 {
336     FILETIME ft;
337     SYSTEMTIME st;
338     ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
339     BOOL ret;
340
341     ft.dwHighDateTime = 0;
342     ft.dwLowDateTime  = 0;
343     ret = FileTimeToSystemTime(&ft, &st);
344     ok( ret,
345        "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
346     ok(((st.wYear == 1601) && (st.wMonth  == 1) && (st.wDay    == 1) &&
347         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 0) &&
348         (st.wMilliseconds == 0)),
349         "Got Year %4d Month %2d Day %2d\n",  st.wYear, st.wMonth, st.wDay);
350
351     ft.dwHighDateTime = (UINT)(time >> 32);
352     ft.dwLowDateTime  = (UINT)time;
353     ret = FileTimeToSystemTime(&ft, &st);
354     ok( ret,
355        "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
356     ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
357         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 1) &&
358         (st.wMilliseconds == 0)),
359        "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
360        st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
361        st.wMilliseconds);
362 }
363
364 static void test_FileTimeToLocalFileTime(void)
365 {
366     FILETIME ft, lft;
367     SYSTEMTIME st;
368     TIME_ZONE_INFORMATION tzinfo;
369     DWORD res =  GetTimeZoneInformation(&tzinfo);
370     ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970 +
371         (LONGLONG)(tzinfo.Bias + 
372             ( res == TIME_ZONE_ID_STANDARD ? tzinfo.StandardBias :
373             ( res == TIME_ZONE_ID_DAYLIGHT ? tzinfo.DaylightBias : 0 ))) *
374              SECSPERMIN *TICKSPERSEC;
375     BOOL ret;
376
377     ok( res != TIME_ZONE_ID_INVALID , "GetTimeZoneInformation failed\n");
378     ft.dwHighDateTime = (UINT)(time >> 32);
379     ft.dwLowDateTime  = (UINT)time;
380     ret = FileTimeToLocalFileTime(&ft, &lft);
381     ok( ret,
382        "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
383     FileTimeToSystemTime(&lft, &st);
384     ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
385         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 1) &&
386         (st.wMilliseconds == 0)),
387        "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
388        st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
389        st.wMilliseconds);
390
391     ok(SetEnvironmentVariableA("TZ","GMT") != 0,
392        "SetEnvironmentVariableA failed\n");
393     ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
394     ret = FileTimeToLocalFileTime(&ft, &lft);
395     ok( ret,
396        "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
397     FileTimeToSystemTime(&lft, &st);
398     ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
399         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 1) &&
400         (st.wMilliseconds == 0)),
401        "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
402        st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
403        st.wMilliseconds);
404     ok(SetEnvironmentVariableA("TZ",NULL) != 0,
405        "SetEnvironmentVariableA failed\n");
406 }
407
408 typedef struct {
409     int nr;             /* test case number for easier lookup */
410     TIME_ZONE_INFORMATION *ptz; /* ptr to timezone */
411     SYSTEMTIME slt;     /* system/local time to convert */
412     WORD ehour;        /* expected hour */
413 } TZLT2ST_case;
414
415 static void test_TzSpecificLocalTimeToSystemTime(void)
416 {    
417     TIME_ZONE_INFORMATION tzE, tzW, tzS;
418     SYSTEMTIME result;
419     int i, j, year;
420
421     if (!pTzSpecificLocalTimeToSystemTime || !pSystemTimeToTzSpecificLocalTime)
422     {
423         skip("TzSpecificLocalTimeToSystemTime or SystemTimeToTzSpecificLocalTime not present\n");
424         return;
425     }
426
427     ZeroMemory( &tzE, sizeof(tzE));
428     ZeroMemory( &tzW, sizeof(tzW));
429     ZeroMemory( &tzS, sizeof(tzS));
430     /* timezone Eastern hemisphere */
431     tzE.Bias=-600;
432     tzE.StandardBias=0;
433     tzE.DaylightBias=-60;
434     tzE.StandardDate.wMonth=10;
435     tzE.StandardDate.wDayOfWeek=0; /*sunday */
436     tzE.StandardDate.wDay=5;       /* last (sunday) of the month */
437     tzE.StandardDate.wHour=3;
438     tzE.DaylightDate.wMonth=3;
439     tzE.DaylightDate.wDay=5;
440     tzE.DaylightDate.wHour=2;
441     /* timezone Western hemisphere */
442     tzW.Bias=240;
443     tzW.StandardBias=0;
444     tzW.DaylightBias=-60;
445     tzW.StandardDate.wMonth=10;
446     tzW.StandardDate.wDayOfWeek=0; /*sunday */
447     tzW.StandardDate.wDay=4;       /* 4th (sunday) of the month */
448     tzW.StandardDate.wHour=2;
449     tzW.DaylightDate.wMonth=4;
450     tzW.DaylightDate.wDay=1;
451     tzW.DaylightDate.wHour=2;
452     /* timezone Eastern hemisphere */
453     tzS.Bias=240;
454     tzS.StandardBias=0;
455     tzS.DaylightBias=-60;
456     tzS.StandardDate.wMonth=4;
457     tzS.StandardDate.wDayOfWeek=0; /*sunday */
458     tzS.StandardDate.wDay=1;       /* 1st  (sunday) of the month */
459     tzS.StandardDate.wHour=2;
460     tzS.DaylightDate.wMonth=10;
461     tzS.DaylightDate.wDay=4;
462     tzS.DaylightDate.wHour=2;
463     /*tests*/
464         /* TzSpecificLocalTimeToSystemTime */
465     {   TZLT2ST_case cases[] = {
466             /* standard->daylight transition */
467             { 1, &tzE, {2004,3,-1,28,1,0,0,0}, 15 },
468             { 2, &tzE, {2004,3,-1,28,1,59,59,999}, 15},
469             { 3, &tzE, {2004,3,-1,28,2,0,0,0}, 15},
470             /* daylight->standard transition */
471             { 4, &tzE, {2004,10,-1,31,2,0,0,0} , 15 },
472             { 5, &tzE, {2004,10,-1,31,2,59,59,999}, 15 },
473             { 6, &tzE, {2004,10,-1,31,3,0,0,0}, 17 },
474             /* West and with fixed weekday of the month */
475             { 7, &tzW, {2004,4,-1,4,1,0,0,0}, 5},
476             { 8, &tzW, {2004,4,-1,4,1,59,59,999}, 5},
477             { 9, &tzW, {2004,4,-1,4,2,0,0,0}, 5},
478             { 10, &tzW, {2004,10,-1,24,1,0,0,0}, 4},
479             { 11, &tzW, {2004,10,-1,24,1,59,59,999}, 4},
480             { 12, &tzW, {2004,10,-1,24,2,0,0,0 }, 6},
481             /* and now south */
482             { 13, &tzS, {2004,4,-1,4,1,0,0,0}, 4},
483             { 14, &tzS, {2004,4,-1,4,1,59,59,999}, 4},
484             { 15, &tzS, {2004,4,-1,4,2,0,0,0}, 6},
485             { 16, &tzS, {2004,10,-1,24,1,0,0,0}, 5},
486             { 17, &tzS, {2004,10,-1,24,1,59,59,999}, 5},
487             { 18, &tzS, {2004,10,-1,24,2,0,0,0}, 5},
488             {0}
489         };
490     /*  days of transitions to put into the cases array */
491         int yeardays[][6]=
492         {
493               {28,31,4,24,4,24}  /* 1999 */
494             , {26,29,2,22,2,22}  /* 2000 */
495             , {25,28,1,28,1,28}  /* 2001 */
496             , {31,27,7,27,7,27}  /* 2002 */
497             , {30,26,6,26,6,26}  /* 2003 */
498             , {28,31,4,24,4,24}  /* 2004 */
499             , {27,30,3,23,3,23}  /* 2005 */
500             , {26,29,2,22,2,22}  /* 2006 */
501             , {25,28,1,28,1,28}  /* 2007 */
502             , {30,26,6,26,6,26}  /* 2008 */
503             , {29,25,5,25,5,25}  /* 2009 */
504             , {28,31,4,24,4,24}  /* 2010 */
505             , {27,30,3,23,3,23}  /* 2011 */
506             , {25,28,1,28,1,28}  /* 2012 */
507             , {31,27,7,27,7,27}  /* 2013 */
508             , {30,26,6,26,6,26}  /* 2014 */
509             , {29,25,5,25,5,25}  /* 2015 */
510             , {27,30,3,23,3,23}  /* 2016 */
511             , {26,29,2,22,2,22}  /* 2017 */
512             , {25,28,1,28,1,28}  /* 2018 */
513             , {31,27,7,27,7,27}  /* 2019 */
514             ,{0}
515         };
516         for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
517             for (i=0; cases[i].nr; i++) {
518                 if(i) cases[i].nr += 18;
519                 cases[i].slt.wYear = year;
520                 cases[i].slt.wDay = yeardays[j][i/3];
521                 pTzSpecificLocalTimeToSystemTime( cases[i].ptz, &(cases[i].slt), &result);
522                 ok( result.wHour == cases[i].ehour,
523                         "Test TzSpecificLocalTimeToSystemTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour =  %02d\n", 
524                         cases[i].nr, result.wYear, result.wMonth, result.wDay,
525                         result.wHour, result.wMinute, cases[i].ehour);
526             }
527         }
528     }
529         /* SystemTimeToTzSpecificLocalTime */
530     {   TZLT2ST_case cases[] = {
531             /* standard->daylight transition */
532             { 1, &tzE, {2004,3,-1,27,15,0,0,0}, 1 },
533             { 2, &tzE, {2004,3,-1,27,15,59,59,999}, 1},
534             { 3, &tzE, {2004,3,-1,27,16,0,0,0}, 3},
535             /* daylight->standard transition */
536             { 4,  &tzE, {2004,10,-1,30,15,0,0,0}, 2 },
537             { 5, &tzE, {2004,10,-1,30,15,59,59,999}, 2 },
538             { 6, &tzE, {2004,10,-1,30,16,0,0,0}, 2 },
539             /* West and with fixed weekday of the month */
540             { 7, &tzW, {2004,4,-1,4,5,0,0,0}, 1},
541             { 8, &tzW, {2004,4,-1,4,5,59,59,999}, 1},
542             { 9, &tzW, {2004,4,-1,4,6,0,0,0}, 3},
543             { 10, &tzW, {2004,10,-1,24,4,0,0,0}, 1},
544             { 11, &tzW, {2004,10,-1,24,4,59,59,999}, 1},
545             { 12, &tzW, {2004,10,-1,24,5,0,0,0 }, 1},
546             /* and now south */
547             { 13, &tzS, {2004,4,-1,4,4,0,0,0}, 1},
548             { 14, &tzS, {2004,4,-1,4,4,59,59,999}, 1},
549             { 15, &tzS, {2004,4,-1,4,5,0,0,0}, 1},
550             { 16, &tzS, {2004,10,-1,24,5,0,0,0}, 1},
551             { 17, &tzS, {2004,10,-1,24,5,59,59,999}, 1},
552             { 18, &tzS, {2004,10,-1,24,6,0,0,0}, 3},
553
554             {0}
555         }; 
556     /*  days of transitions to put into the cases array */
557         int yeardays[][6]=
558         {
559               {27,30,4,24,4,24}  /* 1999 */
560             , {25,28,2,22,2,22}  /* 2000 */
561             , {24,27,1,28,1,28}  /* 2001 */
562             , {30,26,7,27,7,27}  /* 2002 */
563             , {29,25,6,26,6,26}  /* 2003 */
564             , {27,30,4,24,4,24}  /* 2004 */
565             , {26,29,3,23,3,23}  /* 2005 */
566             , {25,28,2,22,2,22}  /* 2006 */
567             , {24,27,1,28,1,28}  /* 2007 */
568             , {29,25,6,26,6,26}  /* 2008 */
569             , {28,24,5,25,5,25}  /* 2009 */
570             , {27,30,4,24,4,24}  /* 2010 */
571             , {26,29,3,23,3,23}  /* 2011 */
572             , {24,27,1,28,1,28}  /* 2012 */
573             , {30,26,7,27,7,27}  /* 2013 */
574             , {29,25,6,26,6,26}  /* 2014 */
575             , {28,24,5,25,5,25}  /* 2015 */
576             , {26,29,3,23,3,23}  /* 2016 */
577             , {25,28,2,22,2,22}  /* 2017 */
578             , {24,27,1,28,1,28}  /* 2018 */
579             , {30,26,7,27,7,27}  /* 2019 */
580         };
581         for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
582             for (i=0; cases[i].nr; i++) {
583                 if(i) cases[i].nr += 18;
584                 cases[i].slt.wYear = year;
585                 cases[i].slt.wDay = yeardays[j][i/3];
586                 pSystemTimeToTzSpecificLocalTime( cases[i].ptz, &(cases[i].slt), &result);
587                 ok( result.wHour == cases[i].ehour,
588                         "Test SystemTimeToTzSpecificLocalTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n", 
589                         cases[i].nr, result.wYear, result.wMonth, result.wDay,
590                         result.wHour, result.wMinute, cases[i].ehour);
591             }
592         }
593
594     }        
595 }
596
597 START_TEST(time)
598 {
599     HMODULE hKernel = GetModuleHandle("kernel32");
600     pTzSpecificLocalTimeToSystemTime = (void *)GetProcAddress(hKernel, "TzSpecificLocalTimeToSystemTime");
601     pSystemTimeToTzSpecificLocalTime = (void *)GetProcAddress( hKernel, "SystemTimeToTzSpecificLocalTime");
602
603     test_conversions();
604     test_invalid_arg();
605     test_GetTimeZoneInformation();
606     test_FileTimeToSystemTime();
607     test_FileTimeToLocalFileTime();
608     test_TzSpecificLocalTimeToSystemTime();
609 }