Update.
[platform/upstream/glibc.git] / time / tst-posixtz.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <time.h>
5
6 struct
7 {
8   time_t when;
9   const char *tz;
10   const char *result;
11 } tests[] =
12 {
13   { 909312849L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
14     "1998/10/25 21:54:09 dst=1 zone=AEDST" },
15   { 924864849L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
16     "1999/04/23 20:54:09 dst=0 zone=AEST" },
17 };
18
19 int
20 main (void)
21 {
22   int result = 0;
23   int cnt;
24
25   for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
26     {
27       char buf[100];
28       struct tm *tmp;
29
30       printf ("TZ = \"%s\", time = %ld => ", tests[cnt].tz, tests[cnt].when);
31       fflush (stdout);
32
33       setenv ("TZ", tests[cnt].tz, 1);
34
35       tmp = localtime (&tests[cnt].when);
36
37       snprintf (buf, sizeof (buf),
38                 "%04d/%02d/%02d %02d:%02d:%02d dst=%d zone=%s",
39                 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
40                 tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tmp->tm_isdst,
41                 tzname[tmp->tm_isdst ? 1 : 0]);
42
43       fputs (buf, stdout);
44
45       if (strcmp (buf, tests[cnt].result) == 0)
46         puts (", OK");
47       else
48         {
49           result = 1;
50           puts (", FAIL");
51         }
52     }
53
54   return result;
55 }