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