kernel32: FindExSearchLimitToDirectories has no effect on FindFirstFileEx.
[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     ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
302     s_time = system_time_to_minutes(&current);
303
304     tzinfo.StandardBias -= 123;
305     tzinfo.DaylightBias += 456;
306
307     res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
308     ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
309     l_time = system_time_to_minutes(&local);
310     ok(l_time - s_time == diff - get_tz_bias(&tzinfo, tz_id), "got %d, expected %d\n",
311        (LONG)(l_time - s_time), diff - get_tz_bias(&tzinfo, tz_id));
312
313     /* pretend that there is no transition dates */
314     tzinfo.DaylightDate.wDay = 0;
315     tzinfo.DaylightDate.wMonth = 0;
316     tzinfo.DaylightDate.wYear = 0;
317     tzinfo.StandardDate.wDay = 0;
318     tzinfo.StandardDate.wMonth = 0;
319     tzinfo.StandardDate.wYear = 0;
320
321     res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
322     ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
323     l_time = system_time_to_minutes(&local);
324     ok(l_time - s_time == diff, "got %d, expected %d\n",
325        (LONG)(l_time - s_time), diff);
326 }
327
328 static void test_FileTimeToSystemTime(void)
329 {
330     FILETIME ft;
331     SYSTEMTIME st;
332     ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
333     BOOL ret;
334
335     ft.dwHighDateTime = 0;
336     ft.dwLowDateTime  = 0;
337     ret = FileTimeToSystemTime(&ft, &st);
338     ok( ret,
339        "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
340     ok(((st.wYear == 1601) && (st.wMonth  == 1) && (st.wDay    == 1) &&
341         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 0) &&
342         (st.wMilliseconds == 0)),
343         "Got Year %4d Month %2d Day %2d\n",  st.wYear, st.wMonth, st.wDay);
344
345     ft.dwHighDateTime = (UINT)(time >> 32);
346     ft.dwLowDateTime  = (UINT)time;
347     ret = FileTimeToSystemTime(&ft, &st);
348     ok( ret,
349        "FileTimeToSystemTime() failed with Error %d\n",GetLastError());
350     ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
351         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 1) &&
352         (st.wMilliseconds == 0)),
353        "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
354        st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
355        st.wMilliseconds);
356 }
357
358 static void test_FileTimeToLocalFileTime(void)
359 {
360     FILETIME ft, lft;
361     SYSTEMTIME st;
362     TIME_ZONE_INFORMATION tzinfo;
363     DWORD res =  GetTimeZoneInformation(&tzinfo);
364     ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970 +
365         (LONGLONG)(tzinfo.Bias + 
366             ( res == TIME_ZONE_ID_STANDARD ? tzinfo.StandardBias :
367             ( res == TIME_ZONE_ID_DAYLIGHT ? tzinfo.DaylightBias : 0 ))) *
368              SECSPERMIN *TICKSPERSEC;
369     BOOL ret;
370
371     ok( res != TIME_ZONE_ID_INVALID , "GetTimeZoneInformation failed\n");
372     ft.dwHighDateTime = (UINT)(time >> 32);
373     ft.dwLowDateTime  = (UINT)time;
374     ret = FileTimeToLocalFileTime(&ft, &lft);
375     ok( ret,
376        "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
377     FileTimeToSystemTime(&lft, &st);
378     ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
379         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 1) &&
380         (st.wMilliseconds == 0)),
381        "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
382        st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
383        st.wMilliseconds);
384
385     ok(SetEnvironmentVariableA("TZ","GMT") != 0,
386        "SetEnvironmentVariableA failed\n");
387     ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
388     ret = FileTimeToLocalFileTime(&ft, &lft);
389     ok( ret,
390        "FileTimeToLocalFileTime() failed with Error %d\n",GetLastError());
391     FileTimeToSystemTime(&lft, &st);
392     ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
393         (st.wHour ==    0) && (st.wMinute == 0) && (st.wSecond == 1) &&
394         (st.wMilliseconds == 0)),
395        "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
396        st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
397        st.wMilliseconds);
398     ok(SetEnvironmentVariableA("TZ",NULL) != 0,
399        "SetEnvironmentVariableA failed\n");
400 }
401
402 typedef struct {
403     int nr;             /* test case number for easier lookup */
404     TIME_ZONE_INFORMATION *ptz; /* ptr to timezone */
405     SYSTEMTIME slt;     /* system/local time to convert */
406     WORD ehour;        /* expected hour */
407 } TZLT2ST_case;
408
409 static void test_TzSpecificLocalTimeToSystemTime(void)
410 {    
411     TIME_ZONE_INFORMATION tzE, tzW, tzS;
412     SYSTEMTIME result;
413     int i, j, year;
414
415     if (!pTzSpecificLocalTimeToSystemTime || !pSystemTimeToTzSpecificLocalTime)
416     {
417         skip("TzSpecificLocalTimeToSystemTime or SystemTimeToTzSpecificLocalTime not present\n");
418         return;
419     }
420
421     ZeroMemory( &tzE, sizeof(tzE));
422     ZeroMemory( &tzW, sizeof(tzW));
423     ZeroMemory( &tzS, sizeof(tzS));
424     /* timezone Eastern hemisphere */
425     tzE.Bias=-600;
426     tzE.StandardBias=0;
427     tzE.DaylightBias=-60;
428     tzE.StandardDate.wMonth=10;
429     tzE.StandardDate.wDayOfWeek=0; /*sunday */
430     tzE.StandardDate.wDay=5;       /* last (sunday) of the month */
431     tzE.StandardDate.wHour=3;
432     tzE.DaylightDate.wMonth=3;
433     tzE.DaylightDate.wDay=5;
434     tzE.DaylightDate.wHour=2;
435     /* timezone Western hemisphere */
436     tzW.Bias=240;
437     tzW.StandardBias=0;
438     tzW.DaylightBias=-60;
439     tzW.StandardDate.wMonth=10;
440     tzW.StandardDate.wDayOfWeek=0; /*sunday */
441     tzW.StandardDate.wDay=4;       /* 4th (sunday) of the month */
442     tzW.StandardDate.wHour=2;
443     tzW.DaylightDate.wMonth=4;
444     tzW.DaylightDate.wDay=1;
445     tzW.DaylightDate.wHour=2;
446     /* timezone Eastern hemisphere */
447     tzS.Bias=240;
448     tzS.StandardBias=0;
449     tzS.DaylightBias=-60;
450     tzS.StandardDate.wMonth=4;
451     tzS.StandardDate.wDayOfWeek=0; /*sunday */
452     tzS.StandardDate.wDay=1;       /* 1st  (sunday) of the month */
453     tzS.StandardDate.wHour=2;
454     tzS.DaylightDate.wMonth=10;
455     tzS.DaylightDate.wDay=4;
456     tzS.DaylightDate.wHour=2;
457     /*tests*/
458         /* TzSpecificLocalTimeToSystemTime */
459     {   TZLT2ST_case cases[] = {
460             /* standard->daylight transition */
461             { 1, &tzE, {2004,3,-1,28,1,0,0,0}, 15 },
462             { 2, &tzE, {2004,3,-1,28,1,59,59,999}, 15},
463             { 3, &tzE, {2004,3,-1,28,2,0,0,0}, 15},
464             /* daylight->standard transition */
465             { 4, &tzE, {2004,10,-1,31,2,0,0,0} , 15 },
466             { 5, &tzE, {2004,10,-1,31,2,59,59,999}, 15 },
467             { 6, &tzE, {2004,10,-1,31,3,0,0,0}, 17 },
468             /* West and with fixed weekday of the month */
469             { 7, &tzW, {2004,4,-1,4,1,0,0,0}, 5},
470             { 8, &tzW, {2004,4,-1,4,1,59,59,999}, 5},
471             { 9, &tzW, {2004,4,-1,4,2,0,0,0}, 5},
472             { 10, &tzW, {2004,10,-1,24,1,0,0,0}, 4},
473             { 11, &tzW, {2004,10,-1,24,1,59,59,999}, 4},
474             { 12, &tzW, {2004,10,-1,24,2,0,0,0 }, 6},
475             /* and now south */
476             { 13, &tzS, {2004,4,-1,4,1,0,0,0}, 4},
477             { 14, &tzS, {2004,4,-1,4,1,59,59,999}, 4},
478             { 15, &tzS, {2004,4,-1,4,2,0,0,0}, 6},
479             { 16, &tzS, {2004,10,-1,24,1,0,0,0}, 5},
480             { 17, &tzS, {2004,10,-1,24,1,59,59,999}, 5},
481             { 18, &tzS, {2004,10,-1,24,2,0,0,0}, 5},
482             {0}
483         };
484     /*  days of transitions to put into the cases array */
485         int yeardays[][6]=
486         {
487               {28,31,4,24,4,24}  /* 1999 */
488             , {26,29,2,22,2,22}  /* 2000 */
489             , {25,28,1,28,1,28}  /* 2001 */
490             , {31,27,7,27,7,27}  /* 2002 */
491             , {30,26,6,26,6,26}  /* 2003 */
492             , {28,31,4,24,4,24}  /* 2004 */
493             , {27,30,3,23,3,23}  /* 2005 */
494             , {26,29,2,22,2,22}  /* 2006 */
495             , {25,28,1,28,1,28}  /* 2007 */
496             , {30,26,6,26,6,26}  /* 2008 */
497             , {29,25,5,25,5,25}  /* 2009 */
498             , {28,31,4,24,4,24}  /* 2010 */
499             , {27,30,3,23,3,23}  /* 2011 */
500             , {25,28,1,28,1,28}  /* 2012 */
501             , {31,27,7,27,7,27}  /* 2013 */
502             , {30,26,6,26,6,26}  /* 2014 */
503             , {29,25,5,25,5,25}  /* 2015 */
504             , {27,30,3,23,3,23}  /* 2016 */
505             , {26,29,2,22,2,22}  /* 2017 */
506             , {25,28,1,28,1,28}  /* 2018 */
507             , {31,27,7,27,7,27}  /* 2019 */
508             ,{0}
509         };
510         for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
511             for (i=0; cases[i].nr; i++) {
512                 if(i) cases[i].nr += 18;
513                 cases[i].slt.wYear = year;
514                 cases[i].slt.wDay = yeardays[j][i/3];
515                 pTzSpecificLocalTimeToSystemTime( cases[i].ptz, &(cases[i].slt), &result);
516                 ok( result.wHour == cases[i].ehour,
517                         "Test TzSpecificLocalTimeToSystemTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour =  %02d\n", 
518                         cases[i].nr, result.wYear, result.wMonth, result.wDay,
519                         result.wHour, result.wMinute, cases[i].ehour);
520             }
521         }
522     }
523         /* SystemTimeToTzSpecificLocalTime */
524     {   TZLT2ST_case cases[] = {
525             /* standard->daylight transition */
526             { 1, &tzE, {2004,3,-1,27,15,0,0,0}, 1 },
527             { 2, &tzE, {2004,3,-1,27,15,59,59,999}, 1},
528             { 3, &tzE, {2004,3,-1,27,16,0,0,0}, 3},
529             /* daylight->standard transition */
530             { 4,  &tzE, {2004,10,-1,30,15,0,0,0}, 2 },
531             { 5, &tzE, {2004,10,-1,30,15,59,59,999}, 2 },
532             { 6, &tzE, {2004,10,-1,30,16,0,0,0}, 2 },
533             /* West and with fixed weekday of the month */
534             { 7, &tzW, {2004,4,-1,4,5,0,0,0}, 1},
535             { 8, &tzW, {2004,4,-1,4,5,59,59,999}, 1},
536             { 9, &tzW, {2004,4,-1,4,6,0,0,0}, 3},
537             { 10, &tzW, {2004,10,-1,24,4,0,0,0}, 1},
538             { 11, &tzW, {2004,10,-1,24,4,59,59,999}, 1},
539             { 12, &tzW, {2004,10,-1,24,5,0,0,0 }, 1},
540             /* and now south */
541             { 13, &tzS, {2004,4,-1,4,4,0,0,0}, 1},
542             { 14, &tzS, {2004,4,-1,4,4,59,59,999}, 1},
543             { 15, &tzS, {2004,4,-1,4,5,0,0,0}, 1},
544             { 16, &tzS, {2004,10,-1,24,5,0,0,0}, 1},
545             { 17, &tzS, {2004,10,-1,24,5,59,59,999}, 1},
546             { 18, &tzS, {2004,10,-1,24,6,0,0,0}, 3},
547
548             {0}
549         }; 
550     /*  days of transitions to put into the cases array */
551         int yeardays[][6]=
552         {
553               {27,30,4,24,4,24}  /* 1999 */
554             , {25,28,2,22,2,22}  /* 2000 */
555             , {24,27,1,28,1,28}  /* 2001 */
556             , {30,26,7,27,7,27}  /* 2002 */
557             , {29,25,6,26,6,26}  /* 2003 */
558             , {27,30,4,24,4,24}  /* 2004 */
559             , {26,29,3,23,3,23}  /* 2005 */
560             , {25,28,2,22,2,22}  /* 2006 */
561             , {24,27,1,28,1,28}  /* 2007 */
562             , {29,25,6,26,6,26}  /* 2008 */
563             , {28,24,5,25,5,25}  /* 2009 */
564             , {27,30,4,24,4,24}  /* 2010 */
565             , {26,29,3,23,3,23}  /* 2011 */
566             , {24,27,1,28,1,28}  /* 2012 */
567             , {30,26,7,27,7,27}  /* 2013 */
568             , {29,25,6,26,6,26}  /* 2014 */
569             , {28,24,5,25,5,25}  /* 2015 */
570             , {26,29,3,23,3,23}  /* 2016 */
571             , {25,28,2,22,2,22}  /* 2017 */
572             , {24,27,1,28,1,28}  /* 2018 */
573             , {30,26,7,27,7,27}  /* 2019 */
574         };
575         for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
576             for (i=0; cases[i].nr; i++) {
577                 if(i) cases[i].nr += 18;
578                 cases[i].slt.wYear = year;
579                 cases[i].slt.wDay = yeardays[j][i/3];
580                 pSystemTimeToTzSpecificLocalTime( cases[i].ptz, &(cases[i].slt), &result);
581                 ok( result.wHour == cases[i].ehour,
582                         "Test SystemTimeToTzSpecificLocalTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n", 
583                         cases[i].nr, result.wYear, result.wMonth, result.wDay,
584                         result.wHour, result.wMinute, cases[i].ehour);
585             }
586         }
587
588     }        
589 }
590
591 START_TEST(time)
592 {
593     HMODULE hKernel = GetModuleHandle("kernel32");
594     pTzSpecificLocalTimeToSystemTime = (void *)GetProcAddress(hKernel, "TzSpecificLocalTimeToSystemTime");
595     pSystemTimeToTzSpecificLocalTime = (void *)GetProcAddress( hKernel, "SystemTimeToTzSpecificLocalTime");
596
597     test_conversions();
598     test_invalid_arg();
599     test_GetTimeZoneInformation();
600     test_FileTimeToSystemTime();
601     test_FileTimeToLocalFileTime();
602     test_TzSpecificLocalTimeToSystemTime();
603 }