Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / msvcrt / tests / time.c
bloba56f53c196fcf5d4f0242e8f8bfba205823fda85
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
22 #include "winbase.h"
23 #include "winnls.h"
24 #include "time.h"
26 #include <stdlib.h> /*setenv*/
27 #include <stdio.h> /*printf*/
28 #include <errno.h>
30 #define _MAX__TIME64_T (((__time64_t)0x00000007 << 32) | 0x93406FFF)
32 #define SECSPERDAY 86400
33 #define SECSPERHOUR 3600
34 #define SECSPERMIN 60
35 #define MINSPERHOUR 60
36 #define HOURSPERDAY 24
38 static __time32_t (__cdecl *p_mkgmtime32)(struct tm*);
39 static struct tm* (__cdecl *p_gmtime32)(__time32_t*);
40 static errno_t (__cdecl *p_gmtime32_s)(struct tm*, __time32_t*);
41 static errno_t (__cdecl *p_strtime_s)(char*,size_t);
42 static errno_t (__cdecl *p_strdate_s)(char*,size_t);
43 static errno_t (__cdecl *p_localtime32_s)(struct tm*, __time32_t*);
44 static errno_t (__cdecl *p_localtime64_s)(struct tm*, __time64_t*);
46 static void init(void)
48 HMODULE hmod = GetModuleHandleA("msvcrt.dll");
50 p_gmtime32 = (void*)GetProcAddress(hmod, "_gmtime32");
51 p_gmtime32_s = (void*)GetProcAddress(hmod, "_gmtime32_s");
52 p_mkgmtime32 = (void*)GetProcAddress(hmod, "_mkgmtime32");
53 p_strtime_s = (void*)GetProcAddress(hmod, "_strtime_s");
54 p_strdate_s = (void*)GetProcAddress(hmod, "_strdate_s");
55 p_localtime32_s = (void*)GetProcAddress(hmod, "_localtime32_s");
56 p_localtime64_s = (void*)GetProcAddress(hmod, "_localtime64_s");
59 static int get_test_year(time_t *start)
61 time_t now = time(NULL);
62 struct tm *tm = localtime(&now);
64 /* compute start of year in seconds */
65 *start = SECSPERDAY * ((tm->tm_year - 70) * 365 +
66 (tm->tm_year - 69) / 4 -
67 (tm->tm_year - 1) / 100 +
68 (tm->tm_year + 299) / 400);
69 return tm->tm_year;
72 static void test_ctime(void)
74 time_t badtime = -1;
75 char* ret;
76 ret = ctime(&badtime);
77 ok(ret == NULL, "expected ctime to return NULL, got %s\n", ret);
79 static void test_gmtime(void)
81 __time32_t valid, gmt;
82 struct tm* gmt_tm, gmt_tm_s;
83 errno_t err;
85 if(!p_gmtime32) {
86 win_skip("Skipping _gmtime32 tests\n");
87 return;
90 gmt_tm = p_gmtime32(NULL);
91 ok(gmt_tm == NULL, "gmt_tm != NULL\n");
93 gmt = -1;
94 gmt_tm = p_gmtime32(&gmt);
95 ok(gmt_tm == NULL, "gmt_tm != NULL\n");
97 gmt = valid = 0;
98 gmt_tm = p_gmtime32(&gmt);
99 if(!gmt_tm) {
100 ok(0, "_gmtime32() failed\n");
101 return;
104 ok(((gmt_tm->tm_year == 70) && (gmt_tm->tm_mon == 0) && (gmt_tm->tm_yday == 0) &&
105 (gmt_tm->tm_mday == 1) && (gmt_tm->tm_wday == 4) && (gmt_tm->tm_hour == 0) &&
106 (gmt_tm->tm_min == 0) && (gmt_tm->tm_sec == 0) && (gmt_tm->tm_isdst == 0)),
107 "Wrong date:Year %4d mon %2d yday %3d mday %2d wday %1d hour%2d min %2d sec %2d dst %2d\n",
108 gmt_tm->tm_year, gmt_tm->tm_mon, gmt_tm->tm_yday, gmt_tm->tm_mday, gmt_tm->tm_wday,
109 gmt_tm->tm_hour, gmt_tm->tm_min, gmt_tm->tm_sec, gmt_tm->tm_isdst);
111 if(!p_mkgmtime32) {
112 win_skip("Skipping _mkgmtime32 tests\n");
113 return;
116 gmt_tm->tm_wday = gmt_tm->tm_yday = 0;
117 gmt = p_mkgmtime32(gmt_tm);
118 ok(gmt == valid, "gmt = %u\n", gmt);
119 ok(gmt_tm->tm_wday == 4, "gmt_tm->tm_wday = %d\n", gmt_tm->tm_wday);
120 ok(gmt_tm->tm_yday == 0, "gmt_tm->tm_yday = %d\n", gmt_tm->tm_yday);
122 gmt_tm->tm_wday = gmt_tm->tm_yday = 0;
123 gmt_tm->tm_isdst = -1;
124 gmt = p_mkgmtime32(gmt_tm);
125 ok(gmt == valid, "gmt = %u\n", gmt);
126 ok(gmt_tm->tm_wday == 4, "gmt_tm->tm_wday = %d\n", gmt_tm->tm_wday);
127 ok(gmt_tm->tm_yday == 0, "gmt_tm->tm_yday = %d\n", gmt_tm->tm_yday);
129 gmt_tm->tm_wday = gmt_tm->tm_yday = 0;
130 gmt_tm->tm_isdst = 1;
131 gmt = p_mkgmtime32(gmt_tm);
132 ok(gmt == valid, "gmt = %u\n", gmt);
133 ok(gmt_tm->tm_wday == 4, "gmt_tm->tm_wday = %d\n", gmt_tm->tm_wday);
134 ok(gmt_tm->tm_yday == 0, "gmt_tm->tm_yday = %d\n", gmt_tm->tm_yday);
136 gmt = valid = 173921;
137 gmt_tm = p_gmtime32(&gmt);
138 if(!gmt_tm) {
139 ok(0, "_gmtime32() failed\n");
140 return;
143 gmt_tm->tm_isdst = -1;
144 gmt = p_mkgmtime32(gmt_tm);
145 ok(gmt == valid, "gmt = %u\n", gmt);
146 ok(gmt_tm->tm_wday == 6, "gmt_tm->tm_wday = %d\n", gmt_tm->tm_wday);
147 ok(gmt_tm->tm_yday == 2, "gmt_tm->tm_yday = %d\n", gmt_tm->tm_yday);
149 gmt_tm->tm_isdst = 1;
150 gmt = p_mkgmtime32(gmt_tm);
151 ok(gmt == valid, "gmt = %u\n", gmt);
153 if(!p_gmtime32_s) {
154 win_skip("Skipping _gmtime32_s tests\n");
155 return;
158 errno = 0;
159 gmt = 0;
160 err = p_gmtime32_s(NULL, &gmt);
161 ok(err == EINVAL, "err = %d\n", err);
162 ok(errno == EINVAL, "errno = %d\n", errno);
164 errno = 0;
165 gmt = -1;
166 err = p_gmtime32_s(&gmt_tm_s, &gmt);
167 ok(err == EINVAL, "err = %d\n", err);
168 ok(errno == EINVAL, "errno = %d\n", errno);
169 ok(gmt_tm_s.tm_year == -1, "tm_year = %d\n", gmt_tm_s.tm_year);
172 static void test_mktime(void)
174 TIME_ZONE_INFORMATION tzinfo;
175 DWORD res = GetTimeZoneInformation(&tzinfo);
176 struct tm my_tm, sav_tm;
177 time_t nulltime, local_time;
178 char TZ_env[256];
179 char buffer[64];
180 int year;
181 time_t ref, secs;
183 year = get_test_year( &ref );
184 ref += SECSPERDAY;
186 ok (res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
187 WideCharToMultiByte( CP_ACP, 0, tzinfo.StandardName, -1, buffer, sizeof(buffer), NULL, NULL );
188 trace( "bias %d std %d dst %d zone %s\n",
189 tzinfo.Bias, tzinfo.StandardBias, tzinfo.DaylightBias, buffer );
190 /* Bias may be positive or negative, to use offset of one day */
191 my_tm = *localtime(&ref); /* retrieve current dst flag */
192 secs = SECSPERDAY - tzinfo.Bias * SECSPERMIN;
193 secs -= (my_tm.tm_isdst ? tzinfo.DaylightBias : tzinfo.StandardBias) * SECSPERMIN;
194 my_tm.tm_mday = 1 + secs/SECSPERDAY;
195 secs = secs % SECSPERDAY;
196 my_tm.tm_hour = secs / SECSPERHOUR;
197 secs = secs % SECSPERHOUR;
198 my_tm.tm_min = secs / SECSPERMIN;
199 secs = secs % SECSPERMIN;
200 my_tm.tm_sec = secs;
202 my_tm.tm_year = year;
203 my_tm.tm_mon = 0;
205 sav_tm = my_tm;
207 local_time = mktime(&my_tm);
208 ok(local_time == ref, "mktime returned %u, expected %u\n",
209 (DWORD)local_time, (DWORD)ref);
210 /* now test some unnormalized struct tm's */
211 my_tm = sav_tm;
212 my_tm.tm_sec += 60;
213 my_tm.tm_min -= 1;
214 local_time = mktime(&my_tm);
215 ok(local_time == ref, "Unnormalized mktime returned %u, expected %u\n",
216 (DWORD)local_time, (DWORD)ref);
217 ok( my_tm.tm_year == sav_tm.tm_year && my_tm.tm_mon == sav_tm.tm_mon &&
218 my_tm.tm_mday == sav_tm.tm_mday && my_tm.tm_hour == sav_tm.tm_hour &&
219 my_tm.tm_sec == sav_tm.tm_sec,
220 "mktime returned %2d-%02d-%02d %02d:%02d expected %2d-%02d-%02d %02d:%02d\n",
221 my_tm.tm_year,my_tm.tm_mon,my_tm.tm_mday,
222 my_tm.tm_hour,my_tm.tm_sec,
223 sav_tm.tm_year,sav_tm.tm_mon,sav_tm.tm_mday,
224 sav_tm.tm_hour,sav_tm.tm_sec);
225 my_tm = sav_tm;
226 my_tm.tm_min -= 60;
227 my_tm.tm_hour += 1;
228 local_time = mktime(&my_tm);
229 ok(local_time == ref, "Unnormalized mktime returned %u, expected %u\n",
230 (DWORD)local_time, (DWORD)ref);
231 ok( my_tm.tm_year == sav_tm.tm_year && my_tm.tm_mon == sav_tm.tm_mon &&
232 my_tm.tm_mday == sav_tm.tm_mday && my_tm.tm_hour == sav_tm.tm_hour &&
233 my_tm.tm_sec == sav_tm.tm_sec,
234 "mktime returned %2d-%02d-%02d %02d:%02d expected %2d-%02d-%02d %02d:%02d\n",
235 my_tm.tm_year,my_tm.tm_mon,my_tm.tm_mday,
236 my_tm.tm_hour,my_tm.tm_sec,
237 sav_tm.tm_year,sav_tm.tm_mon,sav_tm.tm_mday,
238 sav_tm.tm_hour,sav_tm.tm_sec);
239 my_tm = sav_tm;
240 my_tm.tm_mon -= 12;
241 my_tm.tm_year += 1;
242 local_time = mktime(&my_tm);
243 ok(local_time == ref, "Unnormalized mktime returned %u, expected %u\n",
244 (DWORD)local_time, (DWORD)ref);
245 ok( my_tm.tm_year == sav_tm.tm_year && my_tm.tm_mon == sav_tm.tm_mon &&
246 my_tm.tm_mday == sav_tm.tm_mday && my_tm.tm_hour == sav_tm.tm_hour &&
247 my_tm.tm_sec == sav_tm.tm_sec,
248 "mktime returned %2d-%02d-%02d %02d:%02d expected %2d-%02d-%02d %02d:%02d\n",
249 my_tm.tm_year,my_tm.tm_mon,my_tm.tm_mday,
250 my_tm.tm_hour,my_tm.tm_sec,
251 sav_tm.tm_year,sav_tm.tm_mon,sav_tm.tm_mday,
252 sav_tm.tm_hour,sav_tm.tm_sec);
253 my_tm = sav_tm;
254 my_tm.tm_mon += 12;
255 my_tm.tm_year -= 1;
256 local_time = mktime(&my_tm);
257 ok(local_time == ref, "Unnormalized mktime returned %u, expected %u\n",
258 (DWORD)local_time, (DWORD)ref);
259 ok( my_tm.tm_year == sav_tm.tm_year && my_tm.tm_mon == sav_tm.tm_mon &&
260 my_tm.tm_mday == sav_tm.tm_mday && my_tm.tm_hour == sav_tm.tm_hour &&
261 my_tm.tm_sec == sav_tm.tm_sec,
262 "mktime returned %2d-%02d-%02d %02d:%02d expected %2d-%02d-%02d %02d:%02d\n",
263 my_tm.tm_year,my_tm.tm_mon,my_tm.tm_mday,
264 my_tm.tm_hour,my_tm.tm_sec,
265 sav_tm.tm_year,sav_tm.tm_mon,sav_tm.tm_mday,
266 sav_tm.tm_hour,sav_tm.tm_sec);
267 /* now a bad time example */
268 my_tm = sav_tm;
269 my_tm.tm_year = 69;
270 local_time = mktime(&my_tm);
271 ok((local_time == -1), "(bad time) mktime returned %d, expected -1\n", (int)local_time);
273 my_tm = sav_tm;
274 /* TEST that we are independent from the TZ variable */
275 /*Argh, msvcrt doesn't have setenv() */
276 _snprintf(TZ_env,255,"TZ=%s",(getenv("TZ")?getenv("TZ"):""));
277 putenv("TZ=GMT");
278 nulltime = mktime(&my_tm);
279 ok(nulltime == ref,"mktime returned 0x%08x\n",(DWORD)nulltime);
280 putenv(TZ_env);
283 static void test_localtime(void)
285 TIME_ZONE_INFORMATION tzinfo;
286 DWORD res = GetTimeZoneInformation(&tzinfo);
287 time_t gmt, ref;
289 char TZ_env[256];
290 struct tm* lt;
291 int year = get_test_year( &ref );
292 int is_leap = !(year % 4) && ((year % 100) || !((year + 300) % 400));
294 gmt = ref + SECSPERDAY + tzinfo.Bias * SECSPERMIN;
295 ok (res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
296 lt = localtime(&gmt);
297 gmt += (lt->tm_isdst ? tzinfo.DaylightBias : tzinfo.StandardBias) * SECSPERMIN;
298 lt = localtime(&gmt);
299 ok(((lt->tm_year == year) && (lt->tm_mon == 0) && (lt->tm_yday == 1) &&
300 (lt->tm_mday == 2) && (lt->tm_hour == 0) &&
301 (lt->tm_min == 0) && (lt->tm_sec == 0)),
302 "Wrong date:Year %d mon %d yday %d mday %d wday %d hour %d min %d sec %d dst %d\n",
303 lt->tm_year, lt->tm_mon, lt->tm_yday, lt->tm_mday, lt->tm_wday, lt->tm_hour,
304 lt->tm_min, lt->tm_sec, lt->tm_isdst);
306 _snprintf(TZ_env,255,"TZ=%s",(getenv("TZ")?getenv("TZ"):""));
307 putenv("TZ=GMT");
308 lt = localtime(&gmt);
309 ok(((lt->tm_year == year) && (lt->tm_mon == 0) && (lt->tm_yday == 1) &&
310 (lt->tm_mday == 2) && (lt->tm_hour == 0) &&
311 (lt->tm_min == 0) && (lt->tm_sec == 0)),
312 "Wrong date:Year %d mon %d yday %d mday %d wday %d hour %d min %d sec %d dst %d\n",
313 lt->tm_year, lt->tm_mon, lt->tm_yday, lt->tm_mday, lt->tm_wday, lt->tm_hour,
314 lt->tm_min, lt->tm_sec, lt->tm_isdst);
315 putenv(TZ_env);
317 /* June 22 */
318 gmt = ref + 202 * SECSPERDAY + tzinfo.Bias * SECSPERMIN;
319 lt = localtime(&gmt);
320 gmt += (lt->tm_isdst ? tzinfo.DaylightBias : tzinfo.StandardBias) * SECSPERMIN;
321 lt = localtime(&gmt);
322 ok(((lt->tm_year == year) && (lt->tm_mon == 6) && (lt->tm_yday == 202) &&
323 (lt->tm_mday == 22 - is_leap) && (lt->tm_hour == 0) &&
324 (lt->tm_min == 0) && (lt->tm_sec == 0)),
325 "Wrong date:Year %d mon %d yday %d mday %d wday %d hour %d min %d sec %d dst %d\n",
326 lt->tm_year, lt->tm_mon, lt->tm_yday, lt->tm_mday, lt->tm_wday, lt->tm_hour,
327 lt->tm_min, lt->tm_sec, lt->tm_isdst);
330 static void test_strdate(void)
332 char date[16], * result;
333 int month, day, year, count, len;
334 errno_t err;
336 result = _strdate(date);
337 ok(result == date, "Wrong return value\n");
338 len = strlen(date);
339 ok(len == 8, "Wrong length: returned %d, should be 8\n", len);
340 count = sscanf(date, "%02d/%02d/%02d", &month, &day, &year);
341 ok(count == 3, "Wrong format: count = %d, should be 3\n", count);
343 if(!p_strdate_s) {
344 win_skip("Skipping _strdate_s tests\n");
345 return;
348 errno = 0;
349 err = p_strdate_s(NULL, 1);
350 ok(err == EINVAL, "err = %d\n", err);
351 ok(errno == EINVAL, "errno = %d\n", errno);
353 date[0] = 'x';
354 date[1] = 'x';
355 err = p_strdate_s(date, 8);
356 ok(err == ERANGE, "err = %d\n", err);
357 ok(errno == ERANGE, "errno = %d\n", errno);
358 ok(date[0] == '\0', "date[0] != '\\0'\n");
359 ok(date[1] == 'x', "date[1] != 'x'\n");
361 err = p_strdate_s(date, 9);
362 ok(err == 0, "err = %x\n", err);
365 static void test_strtime(void)
367 char time[16], * result;
368 int hour, minute, second, count, len;
369 errno_t err;
371 result = _strtime(time);
372 ok(result == time, "Wrong return value\n");
373 len = strlen(time);
374 ok(len == 8, "Wrong length: returned %d, should be 8\n", len);
375 count = sscanf(time, "%02d:%02d:%02d", &hour, &minute, &second);
376 ok(count == 3, "Wrong format: count = %d, should be 3\n", count);
378 if(!p_strtime_s) {
379 win_skip("Skipping _strtime_s tests\n");
380 return;
383 errno = 0;
384 err = p_strtime_s(NULL, 0);
385 ok(err == EINVAL, "err = %d\n", err);
386 ok(errno == EINVAL, "errno = %d\n", errno);
388 err = p_strtime_s(NULL, 1);
389 ok(err == EINVAL, "err = %d\n", err);
390 ok(errno == EINVAL, "errno = %d\n", errno);
392 time[0] = 'x';
393 err = p_strtime_s(time, 8);
394 ok(err == ERANGE, "err = %d\n", err);
395 ok(errno == ERANGE, "errno = %d\n", errno);
396 ok(time[0] == '\0', "time[0] != '\\0'\n");
398 err = p_strtime_s(time, 9);
399 ok(err == 0, "err = %x\n", err);
402 static void test_wstrdate(void)
404 wchar_t date[16], * result;
405 int month, day, year, count, len;
406 wchar_t format[] = { '%','0','2','d','/','%','0','2','d','/','%','0','2','d',0 };
408 result = _wstrdate(date);
409 ok(result == date, "Wrong return value\n");
410 len = wcslen(date);
411 ok(len == 8, "Wrong length: returned %d, should be 8\n", len);
412 count = swscanf(date, format, &month, &day, &year);
413 ok(count == 3, "Wrong format: count = %d, should be 3\n", count);
416 static void test_wstrtime(void)
418 wchar_t time[16], * result;
419 int hour, minute, second, count, len;
420 wchar_t format[] = { '%','0','2','d',':','%','0','2','d',':','%','0','2','d',0 };
422 result = _wstrtime(time);
423 ok(result == time, "Wrong return value\n");
424 len = wcslen(time);
425 ok(len == 8, "Wrong length: returned %d, should be 8\n", len);
426 count = swscanf(time, format, &hour, &minute, &second);
427 ok(count == 3, "Wrong format: count = %d, should be 3\n", count);
430 static void test_localtime32_s(void)
432 struct tm tm;
433 __time32_t time;
434 errno_t err;
436 if (!p_localtime32_s)
438 win_skip("Skipping _localtime32_s tests\n");
439 return;
442 errno = EBADF;
443 err = p_localtime32_s(NULL, NULL);
444 ok(err == EINVAL, "Expected _localtime32_s to return EINVAL, got %d\n", err);
445 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
447 errno = EBADF;
448 time = 0x12345678;
449 err = p_localtime32_s(NULL, &time);
450 ok(err == EINVAL, "Expected _localtime32_s to return EINVAL, got %d\n", err);
451 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
453 memset(&tm, 0, sizeof(tm));
454 errno = EBADF;
455 err = p_localtime32_s(&tm, NULL);
456 ok(err == EINVAL, "Expected _localtime32_s to return EINVAL, got %d\n", err);
457 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
458 ok(tm.tm_sec == -1 && tm.tm_min == -1 && tm.tm_hour == -1 &&
459 tm.tm_mday == -1 && tm.tm_mon == -1 && tm.tm_year == -1 &&
460 tm.tm_wday == -1 && tm.tm_yday == -1 && tm.tm_isdst == -1,
461 "Expected tm structure members to be initialized to -1, got "
462 "(%d, %d, %d, %d, %d, %d, %d, %d, %d)\n", tm.tm_sec, tm.tm_min,
463 tm.tm_hour, tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday,
464 tm.tm_isdst);
466 memset(&tm, 0, sizeof(tm));
467 time = -1;
468 errno = EBADF;
469 err = p_localtime32_s(&tm, &time);
470 ok(err == EINVAL, "Expected _localtime32_s to return EINVAL, got %d\n", err);
471 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
472 ok(tm.tm_sec == -1 && tm.tm_min == -1 && tm.tm_hour == -1 &&
473 tm.tm_mday == -1 && tm.tm_mon == -1 && tm.tm_year == -1 &&
474 tm.tm_wday == -1 && tm.tm_yday == -1 && tm.tm_isdst == -1,
475 "Expected tm structure members to be initialized to -1, got "
476 "(%d, %d, %d, %d, %d, %d, %d, %d, %d)\n", tm.tm_sec, tm.tm_min,
477 tm.tm_hour, tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday,
478 tm.tm_isdst);
481 static void test_localtime64_s(void)
483 struct tm tm;
484 __time64_t time;
485 errno_t err;
487 if (!p_localtime64_s)
489 win_skip("Skipping _localtime64_s tests\n");
490 return;
493 errno = EBADF;
494 err = p_localtime64_s(NULL, NULL);
495 ok(err == EINVAL, "Expected _localtime64_s to return EINVAL, got %d\n", err);
496 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
498 errno = EBADF;
499 time = 0xdeadbeef;
500 err = p_localtime64_s(NULL, &time);
501 ok(err == EINVAL, "Expected _localtime64_s to return EINVAL, got %d\n", err);
502 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
504 memset(&tm, 0, sizeof(tm));
505 errno = EBADF;
506 err = p_localtime64_s(&tm, NULL);
507 ok(err == EINVAL, "Expected _localtime64_s to return EINVAL, got %d\n", err);
508 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
509 ok(tm.tm_sec == -1 && tm.tm_min == -1 && tm.tm_hour == -1 &&
510 tm.tm_mday == -1 && tm.tm_mon == -1 && tm.tm_year == -1 &&
511 tm.tm_wday == -1 && tm.tm_yday == -1 && tm.tm_isdst == -1,
512 "Expected tm structure members to be initialized to -1, got "
513 "(%d, %d, %d, %d, %d, %d, %d, %d, %d)\n", tm.tm_sec, tm.tm_min,
514 tm.tm_hour, tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday,
515 tm.tm_isdst);
517 memset(&tm, 0, sizeof(tm));
518 time = -1;
519 errno = EBADF;
520 err = p_localtime64_s(&tm, &time);
521 ok(err == EINVAL, "Expected _localtime64_s to return EINVAL, got %d\n", err);
522 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
523 ok(tm.tm_sec == -1 && tm.tm_min == -1 && tm.tm_hour == -1 &&
524 tm.tm_mday == -1 && tm.tm_mon == -1 && tm.tm_year == -1 &&
525 tm.tm_wday == -1 && tm.tm_yday == -1 && tm.tm_isdst == -1,
526 "Expected tm structure members to be initialized to -1, got "
527 "(%d, %d, %d, %d, %d, %d, %d, %d, %d)\n", tm.tm_sec, tm.tm_min,
528 tm.tm_hour, tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday,
529 tm.tm_isdst);
531 memset(&tm, 0, sizeof(tm));
532 time = _MAX__TIME64_T + 1;
533 errno = EBADF;
534 err = p_localtime64_s(&tm, &time);
535 ok(err == EINVAL, "Expected _localtime64_s to return EINVAL, got %d\n", err);
536 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
537 ok(tm.tm_sec == -1 && tm.tm_min == -1 && tm.tm_hour == -1 &&
538 tm.tm_mday == -1 && tm.tm_mon == -1 && tm.tm_year == -1 &&
539 tm.tm_wday == -1 && tm.tm_yday == -1 && tm.tm_isdst == -1,
540 "Expected tm structure members to be initialized to -1, got "
541 "(%d, %d, %d, %d, %d, %d, %d, %d, %d)\n", tm.tm_sec, tm.tm_min,
542 tm.tm_hour, tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday,
543 tm.tm_isdst);
546 START_TEST(time)
548 init();
550 test_ctime();
551 test_gmtime();
552 test_mktime();
553 test_localtime();
554 test_strdate();
555 test_strtime();
556 test_wstrdate();
557 test_wstrtime();
558 test_localtime32_s();
559 test_localtime64_s();