~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/kernel32/tests/time.c

Version: ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.