Updated to fedora-glibc-20090424T1908
[glibc/history.git] / time / tst-mktime3.c
blob60d0e0b32ceac34295ea573a991c13eee53e29d1
1 /* Test program for mktime bugs with out-of-range tm_sec values. */
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <time.h>
7 struct tm tests[] =
9 { .tm_sec = -1, .tm_mday = 1, .tm_year = 104 },
10 { .tm_sec = 65, .tm_min = 59, .tm_hour = 23, .tm_mday = 31,
11 .tm_mon = 11, .tm_year = 101 }
13 struct tm expected[] =
15 { .tm_sec = 59, .tm_min = 59, .tm_hour = 23, .tm_mday = 31,
16 .tm_mon = 11, .tm_year = 103, .tm_wday = 3, .tm_yday = 364 },
17 { .tm_sec = 5, .tm_mday = 1, .tm_year = 102, .tm_wday = 2 }
20 int
21 main (void)
23 setenv ("TZ", "UTC", 1);
24 int i;
25 for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
27 if (mktime (&tests[i]) < 0)
29 printf ("mktime %d failed\n", i);
30 return 1;
32 #define CHECK(name) \
33 if (tests[i].name != expected[i].name) \
34 { \
35 printf ("test %d " #name " got %d expected %d\n", \
36 i, tests[i].name, expected[i].name); \
37 return 1; \
39 CHECK (tm_sec)
40 CHECK (tm_min)
41 CHECK (tm_hour)
42 CHECK (tm_mday)
43 CHECK (tm_mon)
44 CHECK (tm_year)
45 CHECK (tm_wday)
46 CHECK (tm_yday)
47 CHECK (tm_isdst)
49 return 0;