2 * Unit test suite for time functions
4 * Copyright 2004 Uwe Bonnes
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/test.h"
25 #define SECSPERDAY 86400
26 /* 1601 to 1970 is 369 years plus 89 leap days */
27 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
28 #define TICKSPERSEC 10000000
29 #define TICKSPERMSEC 10000
30 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
33 void test_GetTimeZoneInformation()
35 TIME_ZONE_INFORMATION tzinfo
, tzinfo1
;
36 DWORD res
= GetTimeZoneInformation(&tzinfo
);
37 ok(res
!= 0, "GetTimeZoneInformation failed\n");
38 ok(SetEnvironmentVariableA("TZ","GMT0") != 0,
39 "SetEnvironmentVariableA failed\n");
40 res
= GetTimeZoneInformation(&tzinfo1
);
41 ok(res
!= 0, "GetTimeZoneInformation failed\n");
43 ok(((tzinfo
.Bias
== tzinfo1
.Bias
) &&
44 (tzinfo
.StandardBias
== tzinfo1
.StandardBias
) &&
45 (tzinfo
.DaylightBias
== tzinfo1
.DaylightBias
)),
46 "Bias influenced by TZ variable\n");
47 ok(SetEnvironmentVariableA("TZ",NULL
) != 0,
48 "SetEnvironmentVariableA failed\n");
52 void test_FileTimeToSystemTime()
56 ULONGLONG time
= (ULONGLONG
)TICKSPERSEC
+ TICKS_1601_TO_1970
;
58 ft
.dwHighDateTime
= 0;
60 ok(FileTimeToSystemTime(&ft
, &st
),
61 "FileTimeToSystemTime() failed with Error 0x%08lx\n",GetLastError());
62 ok(((st
.wYear
== 1601) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
63 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 0) &&
64 (st
.wMilliseconds
== 0)),
65 "Got Year %4d Month %2d Day %2d\n", st
.wYear
, st
.wMonth
, st
.wDay
);
67 ft
.dwHighDateTime
= (UINT
)(time
>> 32);
68 ft
.dwLowDateTime
= (UINT
)time
;
69 ok(FileTimeToSystemTime(&ft
, &st
),
70 "FileTimeToSystemTime() failed with Error 0x%08lx\n",GetLastError());
71 ok(((st
.wYear
== 1970) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
72 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 1) &&
73 (st
.wMilliseconds
== 0)),
74 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
75 st
.wYear
, st
.wMonth
, st
.wDay
, st
.wHour
, st
.wMinute
, st
.wSecond
,
79 void test_FileTimeToLocalFileTime()
83 TIME_ZONE_INFORMATION tzinfo
;
84 DWORD res
= GetTimeZoneInformation(&tzinfo
);
85 ULONGLONG time
= (ULONGLONG
)TICKSPERSEC
+ TICKS_1601_TO_1970
86 + (ULONGLONG
)tzinfo
.Bias
*SECSPERMIN
*TICKSPERSEC
;
88 ok( res
!= 0, "GetTimeZoneInformation failed\n");
89 ft
.dwHighDateTime
= (UINT
)(time
>> 32);
90 ft
.dwLowDateTime
= (UINT
)time
;
91 ok(FileTimeToLocalFileTime(&ft
, &lft
) !=0 ,
92 "FileTimeToLocalFileTime() failed with Error 0x%08lx\n",GetLastError());
93 FileTimeToSystemTime(&lft
, &st
);
94 ok(((st
.wYear
== 1970) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
95 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 1) &&
96 (st
.wMilliseconds
== 0)),
97 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
98 st
.wYear
, st
.wMonth
, st
.wDay
, st
.wHour
, st
.wMinute
, st
.wSecond
,
101 ok(SetEnvironmentVariableA("TZ","GMT") != 0,
102 "SetEnvironmentVariableA failed\n");
103 ok(res
!= 0, "GetTimeZoneInformation failed\n");
104 ok(FileTimeToLocalFileTime(&ft
, &lft
) !=0 ,
105 "FileTimeToLocalFileTime() failed with Error 0x%08lx\n",GetLastError());
106 FileTimeToSystemTime(&lft
, &st
);
107 ok(((st
.wYear
== 1970) && (st
.wMonth
== 1) && (st
.wDay
== 1) &&
108 (st
.wHour
== 0) && (st
.wMinute
== 0) && (st
.wSecond
== 1) &&
109 (st
.wMilliseconds
== 0)),
110 "Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
111 st
.wYear
, st
.wMonth
, st
.wDay
, st
.wHour
, st
.wMinute
, st
.wSecond
,
113 ok(SetEnvironmentVariableA("TZ",NULL
) != 0,
114 "SetEnvironmentVariableA failed\n");
119 test_GetTimeZoneInformation();
120 test_FileTimeToSystemTime();
121 test_FileTimeToLocalFileTime();