]> git.ipfire.org Git - thirdparty/glibc.git/blob - timezone/tst-timezone.c
Update.
[thirdparty/glibc.git] / timezone / tst-timezone.c
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.
4
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.
9
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.
14
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. */
19
20 #include <time.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24
25 int failed = 0;
26
27 struct test_times
28 {
29 const char *name;
30 int daylight;
31 int timezone;
32 };
33
34 static const struct test_times tests[] =
35 {
36 { "Europe/Berlin", 1, -3600 },
37 { "Universal", 0, 0 },
38 { "Australia/Melbourne", 1, -36000 },
39 { "America/Sao_Paulo", 1, 10800 },
40 { NULL, 0, 0 }
41 };
42
43
44 void
45 print_tzvars (void)
46 {
47 printf ("tzname[0]: %s\n", tzname[0]);
48 printf ("tzname[1]: %s\n", tzname[1]);
49 printf ("daylight: %d\n", daylight);
50 printf ("timezone: %ld\n", timezone);
51 }
52
53
54 void
55 check_tzvars (const char *name, int dayl, int timez)
56 {
57 if (daylight != dayl)
58 {
59 printf ("Timezone: %s, daylight is: %d but should be: %d\n",
60 name, daylight, dayl);
61 ++failed;
62 }
63 if (timezone != timez)
64 {
65 printf ("Timezone: %s, timezone is: %ld but should be: %d\n",
66 name, timezone, timez);
67 ++failed;
68 }
69 }
70
71
72 int
73 main (int argc, char ** argv)
74 {
75 time_t t;
76 const struct test_times *pt;
77 char buf[BUFSIZ];
78
79 /* This should be: Thu May 14 18:02:16 1998. */
80 t = 895194136;
81 printf ("We use this date: %s\n", ctime (&t));
82
83 for (pt = tests; pt->name != NULL; ++pt)
84 {
85 /* Start with a known state */
86 printf ("Checking timezone %s\n", pt->name);
87 sprintf (buf, "TZ=%s", pt->name);
88 if (putenv (buf))
89 {
90 puts ("putenv failed.");
91 failed = 1;
92 }
93 tzset ();
94 print_tzvars ();
95 check_tzvars (pt->name, pt->daylight, pt->timezone);
96
97 /* calling localtime shouldn't make a difference */
98 localtime (&t);
99 print_tzvars ();
100 check_tzvars (pt->name, pt->daylight, pt->timezone);
101 }
102
103 return failed ? EXIT_FAILURE : EXIT_SUCCESS;
104 }