winex11: add owned windows to taskbar if owner is not mapped
[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         if (memcmp(&tzinfo->StandardDate, &tzinfo->DaylightDate, sizeof(tzinfo->DaylightDate)) != 0)
211             return tzinfo->DaylightBias;
212         /* fall through */
213
214     case TIME_ZONE_ID_STANDARD:
215         return tzinfo->StandardBias;
216
217     default:
218         trace("unknown time zone id %d\n", tz_id);
219         /* fall through */
220     case TIME_ZONE_ID_UNKNOWN:
221         return 0;
222     }
223 }
224  
225 static void test_GetTimeZoneInformation(void)
226 {
227     char std_name[32], dlt_name[32];
228     TIME_ZONE_INFORMATION tzinfo, tzinfo1;
229     BOOL res;
230     DWORD tz_id;
231     SYSTEMTIME st, current, utc, local;
232     FILETIME l_ft, s_ft;
233     LONGLONG l_time, s_time;
234     LONG diff;
235
236     GetSystemTime(&st);
237     s_time = system_time_to_minutes(&st);
238
239     SetLastError(0xdeadbeef);
240     res = SystemTimeToFileTime(&st, &s_ft);
241     ok(res, "SystemTimeToFileTime error %u\n", GetLastError());
242     SetLastError(0xdeadbeef);
243     res = FileTimeToLocalFileTime(&s_ft, &l_ft);
244     ok(res, "FileTimeToLocalFileTime error %u\n", GetLastError());
245     SetLastError(0xdeadbeef);
246     res = FileTimeToSystemTime(&l_ft, &local);
247     ok(res, "FileTimeToSystemTime error %u\n", GetLastError());
248     l_time = system_time_to_minutes(&local);
249
250     tz_id = GetTimeZoneInformation(&tzinfo);
251     ok(tz_id != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
252
253     trace("tz_id %u (%s)\n", tz_id,
254           tz_id == TIME_ZONE_ID_DAYLIGHT ? "TIME_ZONE_ID_DAYLIGHT" :
255           (tz_id == TIME_ZONE_ID_STANDARD ? "TIME_ZONE_ID_STANDARD" :
256           (tz_id == TIME_ZONE_ID_UNKNOWN ? "TIME_ZONE_ID_UNKNOWN" :
257           "TIME_ZONE_ID_INVALID")));
258
259     WideCharToMultiByte(CP_ACP, 0, tzinfo.StandardName, -1, std_name, sizeof(std_name), NULL, NULL);
260     WideCharToMultiByte(CP_ACP, 0, tzinfo.DaylightName, -1, dlt_name, sizeof(dlt_name), NULL, NULL);
261     trace("bias %d, %s - %s\n", tzinfo.Bias, std_name, dlt_name);
262     trace("standard (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n",
263         tzinfo.StandardDate.wDay, tzinfo.StandardDate.wMonth,
264         tzinfo.StandardDate.wYear, tzinfo.StandardDate.wDayOfWeek,
265         tzinfo.StandardDate.wHour, tzinfo.StandardDate.wMinute,
266         tzinfo.StandardDate.wSecond, tzinfo.StandardDate.wMilliseconds,
267         tzinfo.StandardBias);
268     trace("daylight (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n",
269         tzinfo.DaylightDate.wDay, tzinfo.DaylightDate.wMonth,
270         tzinfo.DaylightDate.wYear, tzinfo.DaylightDate.wDayOfWeek,
271         tzinfo.DaylightDate.wHour, tzinfo.DaylightDate.wMinute,
272         tzinfo.DaylightDate.wSecond, tzinfo.DaylightDate.wMilliseconds,
273         tzinfo.DaylightBias);
274
275     diff = (LONG)(s_time - l_time);
276     ok(diff == tzinfo.Bias + get_tz_bias(&tzinfo, tz_id),
277        "system/local diff %d != tz bias %d\n",
278        diff, tzinfo.Bias + get_tz_bias(&tzinfo, tz_id));
279
280     ok(SetEnvironmentVariableA("TZ","GMT0") != 0,
281        "SetEnvironmentVariableA failed\n");
282     res =  GetTimeZoneInformation(&tzinfo1);
283     ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
284
285     ok(((tzinfo.Bias == tzinfo1.Bias) && 
286         (tzinfo.StandardBias == tzinfo1.StandardBias) &&
287         (tzinfo.DaylightBias == tzinfo1.DaylightBias)),
288        "Bias influenced by TZ variable\n"); 
289     ok(SetEnvironmentVariableA("TZ",NULL) != 0,
290        "SetEnvironmentVariableA failed\n");
291
292     if (!pSystemTimeToTzSpecificLocalTime)
293     {
294         skip("SystemTimeToTzSpecificLocalTime not present\n");
295         return;
296     }
297
298     diff = get_tz_bias(&tzinfo, tz_id);
299
300     utc = st;
301     SetLastError(0xdeadbeef);
302     res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &current);
303     if (!res && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
304     {
305         skip("SystemTimeToTzSpecificLocalTime is not implemented\n");
306         return;
307     }
308
309     ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
310     s_time = system_time_to_minutes(&current);
311
312     tzinfo.StandardBias -= 123;
313     tzinfo.DaylightBias += 456;
314
315     res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
316     ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
317     l_time = system_time_to_minutes(&local);
318     ok(l_time - s_time == diff - get_tz_bias(&tzinfo, tz_id), "got %d, expected %d\n",
319        (LONG)(l_time - s_time), diff - get_tz_bias(&tzinfo, tz_id));
320
321     /* pretend that there is no transition dates */
322     tzinfo.DaylightDate.wDay = 0;
323     tzinfo.DaylightDate.wMonth = 0;
324     tzinfo.DaylightDate.wYear = 0;
325     tzinfo.StandardDate.wDay = 0;
326     tzinfo.StandardDate.wMonth = 0;
327     tzinfo.StandardDate.wYear = 0;
328
329     res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
330     ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
331     l_time = system_time_to_minutes(&local);
332     ok(l_time - s_time == diff, "got %d, expected %d\n",
333        (LONG)(l_time - s_time), diff);
334 }
335
336 static void test_FileTimeToSystemTime(void)
337 {
338     FILETIME ft;
339     SYSTEMTIME st;
340     ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
341     BOOL ret;
342
343     ft.dwHighDateTime = 0;
344     ft.dwLowDateTime  = 0;
345     ret = FileTimeToSystemTime(&ft, &st);
346     ok( ret,
347        "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
348     ok(((st.wYear == 1601) && (st.wMonth  == 1) && (st.wDay    == 1) &&
349         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 0) &&
350         (st.wMilliseconds == 0)),
351         "Got Year %4d Month %2d Day %2d\n",  st.wYear, st.wMonth, st.wDay);
352
353     ft.dwHighDateTime = (UINT)(time >> 32);
354     ft.dwLowDateTime  = (UINT)time;
355     ret = FileTimeToSystemTime(&ft, &st);
356     ok( ret,
357        "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
358     ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
359         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 1) &&
360         (st.wMilliseconds == 0)),
361        "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
362        st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
363        st.wMilliseconds);
364 }
365
366 static void test_FileTimeToLocalFileTime(void)
367 {
368     FILETIME ft, lft;
369     SYSTEMTIME st;
370     TIME_ZONE_INFORMATION tzinfo;
371     DWORD res =  GetTimeZoneInformation(&tzinfo);
372     ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970 +
373         (LONGLONG)(tzinfo.Bias + 
374             ( res == TIME_ZONE_ID_STANDARD ? tzinfo.StandardBias :
375             ( res == TIME_ZONE_ID_DAYLIGHT ? tzinfo.DaylightBias : 0 ))) *
376              SECSPERMIN *TICKSPERSEC;
377     BOOL ret;
378
379     ok( res != TIME_ZONE_ID_INVALID , "GetTimeZoneInformation failed\n");
380     ft.dwHighDateTime = (UINT)(time >> 32);
381     ft.dwLowDateTime  = (UINT)time;
382     ret = FileTimeToLocalFileTime(&ft, &lft);
383     ok( ret,
384        "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
385     FileTimeToSystemTime(&lft, &st);
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,
391        st.wMilliseconds);
392
393     ok(SetEnvironmentVariableA("TZ","GMT") != 0,
394        "SetEnvironmentVariableA failed\n");
395     ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
396     ret = FileTimeToLocalFileTime(&ft, &lft);
397     ok( ret,
398        "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
399     FileTimeToSystemTime(&lft, &st);
400     ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
401         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 1) &&
402         (st.wMilliseconds == 0)),
403        "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
404        st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
405        st.wMilliseconds);
406     ok(SetEnvironmentVariableA("TZ",NULL) != 0,
407        "SetEnvironmentVariableA failed\n");
408 }
409
410 typedef struct {
411     int nr;             /* test case number for easier lookup */
412     TIME_ZONE_INFORMATION *ptz; /* ptr to timezone */
413     SYSTEMTIME slt;     /* system/local time to convert */
414     WORD ehour;        /* expected hour */
415 } TZLT2ST_case;
416
417 static void test_TzSpecificLocalTimeToSystemTime(void)
418 {    
419     TIME_ZONE_INFORMATION tzE, tzW, tzS;
420     SYSTEMTIME result;
421     int i, j, year;
422
423     if (!pTzSpecificLocalTimeToSystemTime || !pSystemTimeToTzSpecificLocalTime)
424     {
425         skip("TzSpecificLocalTimeToSystemTime or SystemTimeToTzSpecificLocalTime not present\n");
426         return;
427     }
428
429     ZeroMemory( &tzE, sizeof(tzE));
430     ZeroMemory( &tzW, sizeof(tzW));
431     ZeroMemory( &tzS, sizeof(tzS));
432     /* timezone Eastern hemisphere */
433     tzE.Bias=-600;
434     tzE.StandardBias=0;
435     tzE.DaylightBias=-60;
436     tzE.StandardDate.wMonth=10;
437     tzE.StandardDate.wDayOfWeek=0; /*sunday */
438     tzE.StandardDate.wDay=5;       /* last (sunday) of the month */
439     tzE.StandardDate.wHour=3;
440     tzE.DaylightDate.wMonth=3;
441     tzE.DaylightDate.wDay=5;
442     tzE.DaylightDate.wHour=2;
443     /* timezone Western hemisphere */
444     tzW.Bias=240;
445     tzW.StandardBias=0;
446     tzW.DaylightBias=-60;
447     tzW.StandardDate.wMonth=10;
448     tzW.StandardDate.wDayOfWeek=0; /*sunday */
449     tzW.StandardDate.wDay=4;       /* 4th (sunday) of the month */
450     tzW.StandardDate.wHour=2;
451     tzW.DaylightDate.wMonth=4;
452     tzW.DaylightDate.wDay=1;
453     tzW.DaylightDate.wHour=2;
454     /* timezone Eastern hemisphere */
455     tzS.Bias=240;
456     tzS.StandardBias=0;
457     tzS.DaylightBias=-60;
458     tzS.StandardDate.wMonth=4;
459     tzS.StandardDate.wDayOfWeek=0; /*sunday */
460     tzS.StandardDate.wDay=1;       /* 1st  (sunday) of the month */
461     tzS.StandardDate.wHour=2;
462     tzS.DaylightDate.wMonth=10;
463     tzS.DaylightDate.wDay=4;
464     tzS.DaylightDate.wHour=2;
465     /*tests*/
466         /* TzSpecificLocalTimeToSystemTime */
467     {   TZLT2ST_case cases[] = {
468             /* standard->daylight transition */
469             { 1, &tzE, {2004,3,-1,28,1,0,0,0}, 15 },
470             { 2, &tzE, {2004,3,-1,28,1,59,59,999}, 15},
471             { 3, &tzE, {2004,3,-1,28,2,0,0,0}, 15},
472             /* daylight->standard transition */
473             { 4, &tzE, {2004,10,-1,31,2,0,0,0} , 15 },
474             { 5, &tzE, {2004,10,-1,31,2,59,59,999}, 15 },
475             { 6, &tzE, {2004,10,-1,31,3,0,0,0}, 17 },
476             /* West and with fixed weekday of the month */
477             { 7, &tzW, {2004,4,-1,4,1,0,0,0}, 5},
478             { 8, &tzW, {2004,4,-1,4,1,59,59,999}, 5},
479             { 9, &tzW, {2004,4,-1,4,2,0,0,0}, 5},
480             { 10, &tzW, {2004,10,-1,24,1,0,0,0}, 4},
481             { 11, &tzW, {2004,10,-1,24,1,59,59,999}, 4},
482             { 12, &tzW, {2004,10,-1,24,2,0,0,0 }, 6},
483             /* and now south */
484             { 13, &tzS, {2004,4,-1,4,1,0,0,0}, 4},
485             { 14, &tzS, {2004,4,-1,4,1,59,59,999}, 4},
486             { 15, &tzS, {2004,4,-1,4,2,0,0,0}, 6},
487             { 16, &tzS, {2004,10,-1,24,1,0,0,0}, 5},
488             { 17, &tzS, {2004,10,-1,24,1,59,59,999}, 5},
489             { 18, &tzS, {2004,10,-1,24,2,0,0,0}, 5},
490             {0}
491         };
492     /*  days of transitions to put into the cases array */
493         int yeardays[][6]=
494         {
495               {28,31,4,24,4,24}  /* 1999 */
496             , {26,29,2,22,2,22}  /* 2000 */
497             , {25,28,1,28,1,28}  /* 2001 */
498             , {31,27,7,27,7,27}  /* 2002 */
499             , {30,26,6,26,6,26}  /* 2003 */
500             , {28,31,4,24,4,24}  /* 2004 */
501             , {27,30,3,23,3,23}  /* 2005 */
502             , {26,29,2,22,2,22}  /* 2006 */
503             , {25,28,1,28,1,28}  /* 2007 */
504             , {30,26,6,26,6,26}  /* 2008 */
505             , {29,25,5,25,5,25}  /* 2009 */
506             , {28,31,4,24,4,24}  /* 2010 */
507             , {27,30,3,23,3,23}  /* 2011 */
508             , {25,28,1,28,1,28}  /* 2012 */
509             , {31,27,7,27,7,27}  /* 2013 */
510             , {30,26,6,26,6,26}  /* 2014 */
511             , {29,25,5,25,5,25}  /* 2015 */
512             , {27,30,3,23,3,23}  /* 2016 */
513             , {26,29,2,22,2,22}  /* 2017 */
514             , {25,28,1,28,1,28}  /* 2018 */
515             , {31,27,7,27,7,27}  /* 2019 */
516             ,{0}
517         };
518         for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
519             for (i=0; cases[i].nr; i++) {
520                 if(i) cases[i].nr += 18;
521                 cases[i].slt.wYear = year;
522                 cases[i].slt.wDay = yeardays[j][i/3];
523                 pTzSpecificLocalTimeToSystemTime( cases[i].ptz, &(cases[i].slt), &result);
524                 ok( result.wHour == cases[i].ehour,
525                         "Test TzSpecificLocalTimeToSystemTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour =  %02d\n", 
526                         cases[i].nr, result.wYear, result.wMonth, result.wDay,
527                         result.wHour, result.wMinute, cases[i].ehour);
528             }
529         }
530     }
531         /* SystemTimeToTzSpecificLocalTime */
532     {   TZLT2ST_case cases[] = {
533             /* standard->daylight transition */
534             { 1, &tzE, {2004,3,-1,27,15,0,0,0}, 1 },
535             { 2, &tzE, {2004,3,-1,27,15,59,59,999}, 1},
536             { 3, &tzE, {2004,3,-1,27,16,0,0,0}, 3},
537             /* daylight->standard transition */
538             { 4,  &tzE, {2004,10,-1,30,15,0,0,0}, 2 },
539             { 5, &tzE, {2004,10,-1,30,15,59,59,999}, 2 },
540             { 6, &tzE, {2004,10,-1,30,16,0,0,0}, 2 },
541             /* West and with fixed weekday of the month */
542             { 7, &tzW, {2004,4,-1,4,5,0,0,0}, 1},
543             { 8, &tzW, {2004,4,-1,4,5,59,59,999}, 1},
544             { 9, &tzW, {2004,4,-1,4,6,0,0,0}, 3},
545             { 10, &tzW, {2004,10,-1,24,4,0,0,0}, 1},
546             { 11, &tzW, {2004,10,-1,24,4,59,59,999}, 1},
547             { 12, &tzW, {2004,10,-1,24,5,0,0,0 }, 1},
548             /* and now south */
549             { 13, &tzS, {2004,4,-1,4,4,0,0,0}, 1},
550             { 14, &tzS, {2004,4,-1,4,4,59,59,999}, 1},
551             { 15, &tzS, {2004,4,-1,4,5,0,0,0}, 1},
552             { 16, &tzS, {2004,10,-1,24,5,0,0,0}, 1},
553             { 17, &tzS, {2004,10,-1,24,5,59,59,999}, 1},
554             { 18, &tzS, {2004,10,-1,24,6,0,0,0}, 3},
555
556             {0}
557         }; 
558     /*  days of transitions to put into the cases array */
559         int yeardays[][6]=
560         {
561               {27,30,4,24,4,24}  /* 1999 */
562             , {25,28,2,22,2,22}  /* 2000 */
563             , {24,27,1,28,1,28}  /* 2001 */
564             , {30,26,7,27,7,27}  /* 2002 */
565             , {29,25,6,26,6,26}  /* 2003 */
566             , {27,30,4,24,4,24}  /* 2004 */
567             , {26,29,3,23,3,23}  /* 2005 */
568             , {25,28,2,22,2,22}  /* 2006 */
569             , {24,27,1,28,1,28}  /* 2007 */
570             , {29,25,6,26,6,26}  /* 2008 */
571             , {28,24,5,25,5,25}  /* 2009 */
572             , {27,30,4,24,4,24}  /* 2010 */
573             , {26,29,3,23,3,23}  /* 2011 */
574             , {24,27,1,28,1,28}  /* 2012 */
575             , {30,26,7,27,7,27}  /* 2013 */
576             , {29,25,6,26,6,26}  /* 2014 */
577             , {28,24,5,25,5,25}  /* 2015 */
578             , {26,29,3,23,3,23}  /* 2016 */
579             , {25,28,2,22,2,22}  /* 2017 */
580             , {24,27,1,28,1,28}  /* 2018 */
581             , {30,26,7,27,7,27}  /* 2019 */
582         };
583         for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
584             for (i=0; cases[i].nr; i++) {
585                 if(i) cases[i].nr += 18;
586                 cases[i].slt.wYear = year;
587                 cases[i].slt.wDay = yeardays[j][i/3];
588                 pSystemTimeToTzSpecificLocalTime( cases[i].ptz, &(cases[i].slt), &result);
589                 ok( result.wHour == cases[i].ehour,
590                         "Test SystemTimeToTzSpecificLocalTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n", 
591                         cases[i].nr, result.wYear, result.wMonth, result.wDay,
592                         result.wHour, result.wMinute, cases[i].ehour);
593             }
594         }
595
596     }        
597 }
598
599 START_TEST(time)
600 {
601     HMODULE hKernel = GetModuleHandle("kernel32");
602     pTzSpecificLocalTimeToSystemTime = (void *)GetProcAddress(hKernel, "TzSpecificLocalTimeToSystemTime");
603     pSystemTimeToTzSpecificLocalTime = (void *)GetProcAddress( hKernel, "SystemTimeToTzSpecificLocalTime");
604
605     test_conversions();
606     test_invalid_arg();
607     test_GetTimeZoneInformation();
608     test_FileTimeToSystemTime();
609     test_FileTimeToLocalFileTime();
610     test_TzSpecificLocalTimeToSystemTime();
611 }