]>
Commit | Line | Data |
---|---|---|
ff152e3f UD |
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> | |
ba9234d9 | 23 | #include <string.h> |
ff152e3f UD |
24 | #include <unistd.h> |
25 | ||
26 | int failed = 0; | |
27 | ||
28 | struct test_times | |
29 | { | |
30 | const char *name; | |
31 | int daylight; | |
32 | int timezone; | |
ba9234d9 | 33 | const char *tzname[2]; |
ff152e3f UD |
34 | }; |
35 | ||
36 | static const struct test_times tests[] = | |
37 | { | |
ba9234d9 UD |
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" }}, | |
ff152e3f UD |
43 | { NULL, 0, 0 } |
44 | }; | |
45 | ||
46 | ||
47 | void | |
48 | print_tzvars (void) | |
49 | { | |
50 | printf ("tzname[0]: %s\n", tzname[0]); | |
51 | printf ("tzname[1]: %s\n", tzname[1]); | |
52 | printf ("daylight: %d\n", daylight); | |
53 | printf ("timezone: %ld\n", timezone); | |
54 | } | |
55 | ||
56 | ||
57 | void | |
ba9234d9 | 58 | check_tzvars (const char *name, int dayl, int timez, const char *const tznam[]) |
ff152e3f | 59 | { |
ba9234d9 UD |
60 | int i; |
61 | ||
ff152e3f UD |
62 | if (daylight != dayl) |
63 | { | |
64 | printf ("Timezone: %s, daylight is: %d but should be: %d\n", | |
65 | name, daylight, dayl); | |
66 | ++failed; | |
67 | } | |
68 | if (timezone != timez) | |
69 | { | |
70 | printf ("Timezone: %s, timezone is: %ld but should be: %d\n", | |
71 | name, timezone, timez); | |
72 | ++failed; | |
73 | } | |
ba9234d9 UD |
74 | for (i = 0; i <= 1; ++i) |
75 | if (strcmp (tzname[i], tznam[i]) != 0) | |
76 | { | |
77 | printf ("Timezone: %s, tzname[%d] is: %s but should be: %s\n", | |
78 | name, i, tzname[i], tznam[i]); | |
79 | ++failed; | |
80 | } | |
ff152e3f UD |
81 | } |
82 | ||
83 | ||
84 | int | |
85 | main (int argc, char ** argv) | |
86 | { | |
87 | time_t t; | |
88 | const struct test_times *pt; | |
89 | char buf[BUFSIZ]; | |
90 | ||
91 | /* This should be: Thu May 14 18:02:16 1998. */ | |
92 | t = 895194136; | |
93 | printf ("We use this date: %s\n", ctime (&t)); | |
94 | ||
95 | for (pt = tests; pt->name != NULL; ++pt) | |
96 | { | |
97 | /* Start with a known state */ | |
98 | printf ("Checking timezone %s\n", pt->name); | |
99 | sprintf (buf, "TZ=%s", pt->name); | |
100 | if (putenv (buf)) | |
101 | { | |
102 | puts ("putenv failed."); | |
103 | failed = 1; | |
104 | } | |
105 | tzset (); | |
106 | print_tzvars (); | |
ba9234d9 | 107 | check_tzvars (pt->name, pt->daylight, pt->timezone, pt->tzname); |
ff152e3f UD |
108 | |
109 | /* calling localtime shouldn't make a difference */ | |
110 | localtime (&t); | |
111 | print_tzvars (); | |
ba9234d9 | 112 | check_tzvars (pt->name, pt->daylight, pt->timezone, pt->tzname); |
ff152e3f UD |
113 | } |
114 | ||
115 | return failed ? EXIT_FAILURE : EXIT_SUCCESS; | |
116 | } |