Update.
[glibc.git] / timezone / tst-timezone.c
blob3585a9c60bfb6c87071bf1df12a0f2e410b6283b
1 /* Copyright (C) 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1998.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <time.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
26 int failed = 0;
28 struct test_times
30 const char *name;
31 int daylight;
32 int timezone;
33 const char *tzname[2];
36 static const struct test_times tests[] =
38 { "Europe/Berlin", 1, -3600, { "CET", "CEST" }},
39 { "Universal", 0, 0, {"UTC", "UTC" }},
40 { "Australia/Melbourne", 1, -36000, { "EST", "EST" }},
41 { "America/Sao_Paulo", 1, 10800, {"EST", "EDT" }},
42 { "America/Los_Angeles", 1, 28800, {"PST", "PDT" }},
43 { "Asia/Tokyo", 0, -32400, {"JST", "JST" }},
44 { NULL, 0, 0 }
48 void
49 print_tzvars (void)
51 printf ("tzname[0]: %s\n", tzname[0]);
52 printf ("tzname[1]: %s\n", tzname[1]);
53 printf ("daylight: %d\n", daylight);
54 printf ("timezone: %ld\n", timezone);
58 void
59 check_tzvars (const char *name, int dayl, int timez, const char *const tznam[])
61 int i;
63 if (daylight != dayl)
65 printf ("Timezone: %s, daylight is: %d but should be: %d\n",
66 name, daylight, dayl);
67 ++failed;
69 if (timezone != timez)
71 printf ("Timezone: %s, timezone is: %ld but should be: %d\n",
72 name, timezone, timez);
73 ++failed;
75 for (i = 0; i <= 1; ++i)
76 if (strcmp (tzname[i], tznam[i]) != 0)
78 printf ("Timezone: %s, tzname[%d] is: %s but should be: %s\n",
79 name, i, tzname[i], tznam[i]);
80 ++failed;
85 int
86 main (int argc, char ** argv)
88 time_t t;
89 const struct test_times *pt;
90 char buf[BUFSIZ];
92 /* This should be: Thu May 14 18:02:16 1998. */
93 t = 895194136;
94 printf ("We use this date: %s\n", ctime (&t));
96 for (pt = tests; pt->name != NULL; ++pt)
98 /* Start with a known state */
99 printf ("Checking timezone %s\n", pt->name);
100 sprintf (buf, "TZ=%s", pt->name);
101 if (putenv (buf))
103 puts ("putenv failed.");
104 failed = 1;
106 tzset ();
107 print_tzvars ();
108 check_tzvars (pt->name, pt->daylight, pt->timezone, pt->tzname);
110 /* calling localtime shouldn't make a difference */
111 localtime (&t);
112 print_tzvars ();
113 check_tzvars (pt->name, pt->daylight, pt->timezone, pt->tzname);
116 return failed ? EXIT_FAILURE : EXIT_SUCCESS;