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 #include <stdlib.h> /*setenv*/
26 #include <stdio.h> /*printf*/
28 #define SECSPERDAY 86400
29 #define SECSPERHOUR 3600
31 #define MINSPERHOUR 60
32 #define HOURSPERDAY 24
34 static void test_gmtime()
36 time_t gmt = (time_t)NULL;
37 struct tm* gmt_tm = gmtime(&gmt);
40 ok(0,"gmtime() error\n");
43 ok(((gmt_tm->tm_year == 70) && (gmt_tm->tm_mon == 0) && (gmt_tm->tm_yday == 0) &&
44 (gmt_tm->tm_mday == 1) && (gmt_tm->tm_wday == 4) && (gmt_tm->tm_hour == 0) &&
45 (gmt_tm->tm_min == 0) && (gmt_tm->tm_sec == 0) && (gmt_tm->tm_isdst == 0)),
46 "Wrong date:Year %4d mon %2d yday %3d mday %2d wday %1d hour%2d min %2d sec %2d dst %2d\n",
47 gmt_tm->tm_year, gmt_tm->tm_mon, gmt_tm->tm_yday, gmt_tm->tm_mday, gmt_tm->tm_wday,
48 gmt_tm->tm_hour, gmt_tm->tm_min, gmt_tm->tm_sec, gmt_tm->tm_isdst);
51 static void test_mktime()
53 TIME_ZONE_INFORMATION tzinfo;
54 DWORD res = GetTimeZoneInformation(&tzinfo);
56 time_t nulltime, local_time;
60 ok (res != 0, "GetTimeZoneInformation faile\n");
61 /* Bias may be positive or negative, to use offset of one day */
62 secs= SECSPERDAY - tzinfo.Bias*SECSPERMIN;
63 my_tm.tm_mday = 1 + secs/SECSPERDAY;
64 secs = secs % SECSPERDAY;
65 my_tm.tm_hour = secs / SECSPERHOUR;
66 secs = secs % SECSPERHOUR;
67 my_tm.tm_min = secs / SECSPERMIN;
68 secs = secs % SECSPERMIN;
75 local_time = mktime(&my_tm);
76 ok(((DWORD)local_time == SECSPERDAY), "mktime returned 0x%08lx\n",(DWORD)local_time);
78 /* TEST that we are indepentant from the TZ variable */
79 /*Argh, msvcrt doesn't have setenv() */
80 _snprintf(TZ_env,255,"TZ=%s",(getenv("TZ")?getenv("TZ"):""));
82 nulltime = mktime(&my_tm);
83 ok(((DWORD)nulltime == SECSPERDAY),"mktime returned 0x%08lx\n",(DWORD)nulltime);
86 static void test_localtime()
88 TIME_ZONE_INFORMATION tzinfo;
89 DWORD res = GetTimeZoneInformation(&tzinfo);
90 time_t gmt = (time_t)(SECSPERDAY + tzinfo.Bias*SECSPERMIN);
94 ok (res != 0, "GetTimeZoneInformation faile\n");
96 ok(((lt->tm_year == 70) && (lt->tm_mon == 0) && (lt->tm_yday == 1) &&
97 (lt->tm_mday == 2) && (lt->tm_wday == 5) && (lt->tm_hour == 0) &&
98 (lt->tm_min == 0) && (lt->tm_sec == 0) && (lt->tm_isdst == 0)),
99 "Wrong date:Year %4d mon %2d yday %3d mday %2d wday %1d hour%2d min %2d sec %2d dst %2d\n",
100 lt->tm_year, lt->tm_mon, lt->tm_yday, lt->tm_mday, lt->tm_wday, lt->tm_hour,
101 lt->tm_min, lt->tm_sec, lt->tm_isdst);
103 _snprintf(TZ_env,255,"TZ=%s",(getenv("TZ")?getenv("TZ"):""));
105 lt = localtime(&gmt);
106 ok(((lt->tm_year == 70) && (lt->tm_mon == 0) && (lt->tm_yday == 1) &&
107 (lt->tm_mday == 2) && (lt->tm_wday == 5) && (lt->tm_hour == 0) &&
108 (lt->tm_min == 0) && (lt->tm_sec == 0) && (lt->tm_isdst == 0)),
109 "Wrong date:Year %4d mon %2d yday %3d mday %2d wday %1d hour%2d min %2d sec %2d dst %2d\n",
110 lt->tm_year, lt->tm_mon, lt->tm_yday, lt->tm_mday, lt->tm_wday, lt->tm_hour,
111 lt->tm_min, lt->tm_sec, lt->tm_isdst);