]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/test/time/tst-strptime2.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / test / time / tst-strptime2.c
1 #include <limits.h>
2 #include <stdio.h>
3 #include <time.h>
4
5
6 static 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
29 int
30 main (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   if (result == 0)
56     puts ("all OK");
57
58   return 0;
59 }