1 | /* Test program for mktime bugs with out-of-range tm_sec values. */ |
---|---|
2 | |
3 | #include <stdlib.h> |
4 | #include <stdio.h> |
5 | #include <time.h> |
6 | |
7 | struct tm tests[] = |
8 | { |
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 } |
12 | }; |
13 | struct tm expected[] = |
14 | { |
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 } |
18 | }; |
19 | |
20 | static int |
21 | do_test (void) |
22 | { |
23 | setenv (name: "TZ", value: "UTC", replace: 1); |
24 | int i; |
25 | for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i) |
26 | { |
27 | if (mktime (&tests[i]) < 0) |
28 | { |
29 | printf (format: "mktime %d failed\n", i); |
30 | return 1; |
31 | } |
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; \ |
38 | } |
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) |
48 | } |
49 | return 0; |
50 | } |
51 | |
52 | #define TEST_FUNCTION do_test () |
53 | #include "../test-skeleton.c" |
54 |