blob: a08e6d7cb7dee6b9a33cbc9a0b27933216d3b28b [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <limits.h>
2#include <stdio.h>
3#include <time.h>
4
5
6static const struct
7{
8 const char *fmt;
9 long int gmtoff;
10} tests[] =
11 {
12 { "1113472456 +1000", 36000 },
13 { "1113472456 -1000", -36000 },
14 { "1113472456 +10", 36000 },
15 { "1113472456 -10", -36000 },
16 { "1113472456 +1030", 37800 },
17 { "1113472456 -1030", -37800 },
18 { "1113472456 +0030", 1800 },
19 { "1113472456 -0030", -1800 },
20 { "1113472456 -1330", LONG_MAX },
21 { "1113472456 +1330", LONG_MAX },
22 { "1113472456 -1060", LONG_MAX },
23 { "1113472456 +1060", LONG_MAX },
24 { "1113472456 1030", LONG_MAX },
25 };
26#define ntests (sizeof (tests) / sizeof (tests[0]))
27
28
29static int
30do_test (void)
31{
32 int result = 0;
33
34 for (int i = 0; i < ntests; ++i)
35 {
36 struct tm tm;
37
38 if (strptime (tests[i].fmt, "%s %z", &tm) == NULL)
39 {
40 if (tests[i].gmtoff != LONG_MAX)
41 {
42 printf ("round %d: strptime unexpectedly failed\n", i);
43 result = 1;
44 }
45 continue;
46 }
47
48 if (tm.tm_gmtoff != tests[i].gmtoff)
49 {
50 printf ("round %d: tm_gmtoff is %ld\n", i, (long int) tm.tm_gmtoff);
51 result = 1;
52 }
53 }
54
55 return result;
56}
57
58#define TEST_FUNCTION do_test ()
59#include "../test-skeleton.c"