cleanup specfile for packaging
[profile/ivi/gpsd.git] / test_mkgmtime.c
1 /*
2  * This file is Copyright (c) 2010 by the GPSD project
3  * BSD terms apply: see the file COPYING in the distribution root for details.
4  */
5 #include <time.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <stdbool.h>
9
10 #include "gps.h"
11
12 /*@-type@*/
13 static struct
14 {
15     struct tm t;
16     time_t result;
17 } tests[] = {
18         /* *INDENT-OFF* */
19         /* sec, min,  h, md, mon, year, wd,  yd, isdst, gmtoff, zone    timestamp        what   */
20         {{   0,   0,  0,  1,   0,   70,  0,   0,     0,      0,    0, }, 0 },
21         {{   0,   0,  0,  1,   0,   70,  0,   0,     0,      0,    0, }, 0            }, /* lower limit */
22         {{   7,  14,  3, 19,   0,  138,  0,   0,     0,      0,    0, }, 0x7fffffff }, /* upper limit */
23         {{   0,   0, 12,  1,   0,   99,  0,   0,     0,      0,    0, }, 915192000  }, /* leap year */
24         {{   0,   0, 12,  1,   1,   99,  0,   0,     0,      0,    0, }, 917870400  }, /* leap year */
25         {{   0,   0, 12,  1,   2,   99,  0,   0,     0,      0,    0, }, 920289600  }, /* leap year */
26         {{   0,   0, 12,  1,   8,   99,  0,   0,     0,      0,    0, }, 936187200  }, /* leap year */
27         {{   0,   0, 12,  1,   0,  100,  0,   0,     0,      0,    0, }, 946728000  }, /* leap year */
28         {{   0,   0, 12,  1,   1,  100,  0,   0,     0,      0,    0, }, 949406400  }, /* leap year */
29         {{   0,   0, 12,  1,   2,  100,  0,   0,     0,      0,    0, }, 951912000  }, /* leap year */
30         {{   0,   0, 12,  1,   8,  100,  0,   0,     0,      0,    0, }, 967809600  }, /* leap year */
31         {{   0,   0, 12,  1,   0,  101,  0,   0,     0,      0,    0, }, 978350400  }, /* leap year */
32         {{   0,   0, 12,  1,   1,  101,  0,   0,     0,      0,    0, }, 981028800  }, /* leap year */
33         {{   0,   0, 12,  1,   2,  101,  0,   0,     0,      0,    0, }, 983448000  }, /* leap year */
34         {{   0,   0, 12,  1,   8,  101,  0,   0,     0,      0,    0, }, 999345600  }, /* leap year */
35         {{   0,   0, 12,  1,   0,  102,  0,   0,     0,      0,    0, }, 1009886400 }, /* leap year */
36         {{   0,   0, 12,  1,   1,  102,  0,   0,     0,      0,    0, }, 1012564800 }, /* leap year */
37         {{   0,   0, 12,  1,   2,  102,  0,   0,     0,      0,    0, }, 1014984000 }, /* leap year */
38         {{   0,   0, 12,  1,   8,  102,  0,   0,     0,      0,    0, }, 1030881600 }, /* leap year */
39         {{   0,   0, 12,  1,   0,  103,  0,   0,     0,      0,    0, }, 1041422400 }, /* leap year */
40         {{   0,   0, 12,  1,   1,  103,  0,   0,     0,      0,    0, }, 1044100800 }, /* leap year */
41         {{   0,   0, 12,  1,   2,  103,  0,   0,     0,      0,    0, }, 1046520000 }, /* leap year */
42         {{   0,   0, 12,  1,   8,  103,  0,   0,     0,      0,    0, }, 1062417600 }, /* leap year */
43         {{   0,   0, 12,  1,   0,  104,  0,   0,     0,      0,    0, }, 1072958400 }, /* leap year */
44         {{   0,   0, 12,  1,   1,  104,  0,   0,     0,      0,    0, }, 1075636800 }, /* leap year */
45         {{   0,   0, 12,  1,   2,  104,  0,   0,     0,      0,    0, }, 1078142400 }, /* leap year */
46         {{   0,   0, 12,  1,   8,  104,  0,   0,     0,      0,    0, }, 1094040000 }, /* leap year */
47         {{   0,   0, 12,  1,   0,  108,  0,   0,     0,      0,    0, }, 1199188800 }, /* leap year */
48         {{   0,   0, 12,  1,   1,  108,  0,   0,     0,      0,    0, }, 1201867200 }, /* leap year */
49         {{   0,   0, 12,  1,   2,  108,  0,   0,     0,      0,    0, }, 1204372800 }, /* leap year */
50         {{   0,   0, 12,  1,   8,  108,  0,   0,     0,      0,    0, }, 1220270400 }, /* leap year */
51         {{  59,  59, 23, 31,  12,  110,  0,   0,     0,      0,    0, }, 1296518399 }, /* year wrap */
52         {{   0,   0,  0,  1,   0,  111,  0,   0,     0,      0,    0, }, 1293840000 }, /* year wrap */
53         {{  59,  59, 23, 31,  12,  111,  0,   0,     0,      0,    0, }, 1328054399 }, /* year wrap */
54         {{   0,   0,  0,  1,   0,  112,  0,   0,     0,      0,    0, }, 1325376000 }, /* year wrap */
55         {{  59,  59, 23, 31,  12,  112,  0,   0,     0,      0,    0, }, 1359676799 }, /* year wrap */
56         {{   0,   0,  0,  1,   0,  113,  0,   0,     0,      0,    0, }, 1356998400 }, /* year wrap */
57         {{  59,  59, 23, 31,   0,  115,  0,   0,     0,      0,    0, }, 1422748799 }, /* month wrap */
58         {{   0,   0,  0,  1,   1,  115,  0,   0,     0,      0,    0, }, 1422748800 }, /* month wrap */
59         {{  59,  59, 23, 28,   1,  115,  0,   0,     0,      0,    0, }, 1425167999 }, /* month wrap */
60         {{   0,   0,  0,  1,   2,  115,  0,   0,     0,      0,    0, }, 1425168000 }, /* month wrap */
61         {{  59,  59, 23, 31,   2,  115,  0,   0,     0,      0,    0, }, 1427846399 }, /* month wrap */
62         {{   0,   0,  0,  1,   3,  115,  0,   0,     0,      0,    0, }, 1427846400 }, /* month wrap */
63         {{  59,  59, 23, 30,   3,  115,  0,   0,     0,      0,    0, }, 1430438399 }, /* month wrap */
64         {{   0,   0,  0,  1,   4,  115,  0,   0,     0,      0,    0, }, 1430438400 }, /* month wrap */
65         {{  59,  59, 23, 31,   4,  115,  0,   0,     0,      0,    0, }, 1433116799 }, /* month wrap */
66         {{   0,   0,  0,  1,   5,  115,  0,   0,     0,      0,    0, }, 1433116800 }, /* month wrap */
67         {{  59,  59, 23, 30,   5,  115,  0,   0,     0,      0,    0, }, 1435708799 }, /* month wrap */
68         {{   0,   0,  0,  1,   6,  115,  0,   0,     0,      0,    0, }, 1435708800 }, /* month wrap */
69         {{  59,  59, 23, 31,   6,  115,  0,   0,     0,      0,    0, }, 1438387199 }, /* month wrap */
70         {{   0,   0,  0,  1,   7,  115,  0,   0,     0,      0,    0, }, 1438387200 }, /* month wrap */
71         {{  59,  59, 23, 31,   7,  115,  0,   0,     0,      0,    0, }, 1441065599 }, /* month wrap */
72         {{   0,   0,  0,  1,   8,  115,  0,   0,     0,      0,    0, }, 1441065600 }, /* month wrap */
73         {{  59,  59, 23, 30,   8,  115,  0,   0,     0,      0,    0, }, 1443657599 }, /* month wrap */
74         {{   0,   0,  0,  1,   9,  115,  0,   0,     0,      0,    0, }, 1443657600 }, /* month wrap */
75         {{  59,  59, 23, 31,   9,  115,  0,   0,     0,      0,    0, }, 1446335999 }, /* month wrap */
76         {{   0,   0,  0,  1,  10,  115,  0,   0,     0,      0,    0, }, 1446336000 }, /* month wrap */
77         {{  59,  59, 23, 30,  10,  115,  0,   0,     0,      0,    0, }, 1448927999 }, /* month wrap */
78         {{   0,   0,  0,  1,  11,  115,  0,   0,     0,      0,    0, }, 1448928000 }, /* month wrap */
79         {{  59,  59, 23, 31,  11,  115,  0,   0,     0,      0,    0, }, 1451606399 }, /* month wrap */
80         {{   0,   0,  0,  1,   0,  116,  0,   0,     0,      0,    0, }, 1451606400 }, /* month wrap */
81         /* *INDENT-ON* */
82 };
83
84 /*@-type@*/
85
86 /*@+longunsignedintegral*/
87 int main(int argc, char *argv[])
88 {
89     int i;
90     char tbuf[128];
91     time_t ts;
92     bool failed = false;
93
94     (void)setenv("TZ", "GMT", 1);
95
96     for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
97 #if 0                           /* use this to calculate with glibc */
98         ts = mktime(&tests[i].t);
99 #else
100         ts = mkgmtime(&tests[i].t);
101 #endif
102         if (ts != tests[i].result) {
103             failed = true;
104             (void)strftime(tbuf, sizeof(tbuf), "%F %T", &tests[i].t);
105             (void)printf("test %2d failed. "
106                          "Time returned from: %s should be %lu (but was: %lu)\n",
107                          i, tbuf, (unsigned long)tests[i].result,
108                          (unsigned long)ts);
109         }
110     }
111     return (int)failed;
112 }
113
114 /*@-longunsignedintegral*/