Set the WINEPRELOADRESERVE variable when starting a new process.
[wine] / dlls / kernel / tests / time.c
1 /*
2  * Unit test suite for time functions
3  *
4  * Copyright 2004 Uwe Bonnes
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "wine/test.h"
22 #include "winbase.h"
23
24 #define SECSPERMIN         60
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)
31
32
33 void test_GetTimeZoneInformation()
34 {
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");
42
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");
49         
50 }
51
52 void test_FileTimeToSystemTime()
53 {
54     FILETIME ft;
55     SYSTEMTIME st;
56     ULONGLONG time = (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
57
58     ft.dwHighDateTime = 0;
59     ft.dwLowDateTime  = 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);
66
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,
76        st.wMilliseconds);
77 }
78
79 void test_FileTimeToLocalFileTime()
80 {
81     FILETIME ft, lft;
82     SYSTEMTIME st;
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;
87
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,
99        st.wMilliseconds);
100
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,
112        st.wMilliseconds);
113     ok(SetEnvironmentVariableA("TZ",NULL) != 0,
114        "SetEnvironmentVariableA failed\n");
115 }
116
117 START_TEST(time)
118 {
119     test_GetTimeZoneInformation();
120     test_FileTimeToSystemTime();
121     test_FileTimeToLocalFileTime();
122     
123 }