t_strptime.c revision 1.7 1 1.7 christos /* $NetBSD: t_strptime.c,v 1.7 2015/10/29 17:48:20 christos Exp $ */
2 1.1 pgoyette
3 1.1 pgoyette /*-
4 1.1 pgoyette * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
5 1.1 pgoyette * All rights reserved.
6 1.1 pgoyette *
7 1.1 pgoyette * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pgoyette * by David Laight.
9 1.1 pgoyette *
10 1.1 pgoyette * Redistribution and use in source and binary forms, with or without
11 1.1 pgoyette * modification, are permitted provided that the following conditions
12 1.1 pgoyette * are met:
13 1.1 pgoyette * 1. Redistributions of source code must retain the above copyright
14 1.1 pgoyette * notice, this list of conditions and the following disclaimer.
15 1.1 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pgoyette * notice, this list of conditions and the following disclaimer in the
17 1.1 pgoyette * documentation and/or other materials provided with the distribution.
18 1.1 pgoyette *
19 1.1 pgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 pgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 pgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 pgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 pgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 pgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 pgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 pgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 pgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 pgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 pgoyette * POSSIBILITY OF SUCH DAMAGE.
30 1.1 pgoyette */
31 1.1 pgoyette
32 1.1 pgoyette #include <sys/cdefs.h>
33 1.1 pgoyette __COPYRIGHT("@(#) Copyright (c) 2008\
34 1.1 pgoyette The NetBSD Foundation, inc. All rights reserved.");
35 1.7 christos __RCSID("$NetBSD: t_strptime.c,v 1.7 2015/10/29 17:48:20 christos Exp $");
36 1.1 pgoyette
37 1.1 pgoyette #include <time.h>
38 1.1 pgoyette
39 1.1 pgoyette #include <atf-c.h>
40 1.1 pgoyette
41 1.1 pgoyette static void
42 1.1 pgoyette h_pass(const char *buf, const char *fmt, int len,
43 1.1 pgoyette int tm_sec, int tm_min, int tm_hour, int tm_mday,
44 1.1 pgoyette int tm_mon, int tm_year, int tm_wday, int tm_yday)
45 1.1 pgoyette {
46 1.1 pgoyette struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL };
47 1.1 pgoyette const char *ret, *exp;
48 1.1 pgoyette
49 1.1 pgoyette exp = buf + len;
50 1.1 pgoyette ret = strptime(buf, fmt, &tm);
51 1.1 pgoyette
52 1.1 pgoyette ATF_REQUIRE_MSG(ret == exp,
53 1.1 pgoyette "strptime(\"%s\", \"%s\", tm): incorrect return code: "
54 1.1 pgoyette "expected: %p, got: %p", buf, fmt, exp, ret);
55 1.1 pgoyette
56 1.1 pgoyette #define H_REQUIRE_FIELD(field) \
57 1.1 pgoyette ATF_REQUIRE_MSG(tm.field == field, \
58 1.1 pgoyette "strptime(\"%s\", \"%s\", tm): incorrect %s: " \
59 1.1 pgoyette "expected: %d, but got: %d", buf, fmt, \
60 1.1 pgoyette ___STRING(field), field, tm.field)
61 1.1 pgoyette
62 1.1 pgoyette H_REQUIRE_FIELD(tm_sec);
63 1.1 pgoyette H_REQUIRE_FIELD(tm_min);
64 1.1 pgoyette H_REQUIRE_FIELD(tm_hour);
65 1.1 pgoyette H_REQUIRE_FIELD(tm_mday);
66 1.1 pgoyette H_REQUIRE_FIELD(tm_mon);
67 1.1 pgoyette H_REQUIRE_FIELD(tm_year);
68 1.1 pgoyette H_REQUIRE_FIELD(tm_wday);
69 1.1 pgoyette H_REQUIRE_FIELD(tm_yday);
70 1.1 pgoyette
71 1.1 pgoyette #undef H_REQUIRE_FIELD
72 1.1 pgoyette }
73 1.1 pgoyette
74 1.1 pgoyette static void
75 1.1 pgoyette h_fail(const char *buf, const char *fmt)
76 1.1 pgoyette {
77 1.1 pgoyette struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL };
78 1.1 pgoyette
79 1.1 pgoyette ATF_REQUIRE_MSG(strptime(buf, fmt, &tm) == NULL, "strptime(\"%s\", "
80 1.1 pgoyette "\"%s\", &tm) should fail, but it didn't", buf, fmt);
81 1.1 pgoyette }
82 1.1 pgoyette
83 1.1 pgoyette ATF_TC(common);
84 1.1 pgoyette
85 1.1 pgoyette ATF_TC_HEAD(common, tc)
86 1.1 pgoyette {
87 1.1 pgoyette
88 1.1 pgoyette atf_tc_set_md_var(tc, "descr", "Checks strptime(3): various checks");
89 1.1 pgoyette }
90 1.1 pgoyette
91 1.1 pgoyette ATF_TC_BODY(common, tc)
92 1.1 pgoyette {
93 1.1 pgoyette
94 1.1 pgoyette h_pass("Tue Jan 20 23:27:46 1998", "%a %b %d %T %Y",
95 1.6 christos 24, 46, 27, 23, 20, 0, 98, 2, 19);
96 1.1 pgoyette h_pass("Tue Jan 20 23:27:46 1998", "%a %b %d %H:%M:%S %Y",
97 1.6 christos 24, 46, 27, 23, 20, 0, 98, 2, 19);
98 1.1 pgoyette h_pass("Tue Jan 20 23:27:46 1998", "%c",
99 1.6 christos 24, 46, 27, 23, 20, 0, 98, 2, 19);
100 1.1 pgoyette h_pass("Fri Mar 4 20:05:34 2005", "%a %b %e %H:%M:%S %Y",
101 1.6 christos 24, 34, 5, 20, 4, 2, 105, 5, 62);
102 1.1 pgoyette h_pass("5\t3 4 8pm:05:34 2005", "%w%n%m%t%d%n%k%p:%M:%S %Y",
103 1.6 christos 21, 34, 5, 20, 4, 2, 105, 5, 62);
104 1.1 pgoyette h_pass("Fri Mar 4 20:05:34 2005", "%c",
105 1.6 christos 24, 34, 5, 20, 4, 2, 105, 5, 62);
106 1.1 pgoyette }
107 1.1 pgoyette
108 1.1 pgoyette ATF_TC(day);
109 1.1 pgoyette
110 1.1 pgoyette ATF_TC_HEAD(day, tc)
111 1.1 pgoyette {
112 1.1 pgoyette
113 1.2 ginsbach atf_tc_set_md_var(tc, "descr",
114 1.2 ginsbach "Checks strptime(3) day name conversions [aA]");
115 1.1 pgoyette }
116 1.1 pgoyette
117 1.1 pgoyette ATF_TC_BODY(day, tc)
118 1.1 pgoyette {
119 1.1 pgoyette
120 1.1 pgoyette h_pass("Sun", "%a", 3, -1, -1, -1, -1, -1, -1, 0, -1);
121 1.1 pgoyette h_pass("Sunday", "%a", 6, -1, -1, -1, -1, -1, -1, 0, -1);
122 1.1 pgoyette h_pass("Mon", "%a", 3, -1, -1, -1, -1, -1, -1, 1, -1);
123 1.1 pgoyette h_pass("Monday", "%a", 6, -1, -1, -1, -1, -1, -1, 1, -1);
124 1.1 pgoyette h_pass("Tue", "%a", 3, -1, -1, -1, -1, -1, -1, 2, -1);
125 1.1 pgoyette h_pass("Tuesday", "%a", 7, -1, -1, -1, -1, -1, -1, 2, -1);
126 1.1 pgoyette h_pass("Wed", "%a", 3, -1, -1, -1, -1, -1, -1, 3, -1);
127 1.1 pgoyette h_pass("Wednesday", "%a", 9, -1, -1, -1, -1, -1, -1, 3, -1);
128 1.1 pgoyette h_pass("Thu", "%a", 3, -1, -1, -1, -1, -1, -1, 4, -1);
129 1.1 pgoyette h_pass("Thursday", "%a", 8, -1, -1, -1, -1, -1, -1, 4, -1);
130 1.1 pgoyette h_pass("Fri", "%a", 3, -1, -1, -1, -1, -1, -1, 5, -1);
131 1.1 pgoyette h_pass("Friday", "%a", 6, -1, -1, -1, -1, -1, -1, 5, -1);
132 1.1 pgoyette h_pass("Sat", "%a", 3, -1, -1, -1, -1, -1, -1, 6, -1);
133 1.1 pgoyette h_pass("Saturday", "%a", 8, -1, -1, -1, -1, -1, -1, 6, -1);
134 1.1 pgoyette h_pass("Saturn", "%a", 3, -1, -1, -1, -1, -1, -1, 6, -1);
135 1.1 pgoyette h_fail("Moon", "%a");
136 1.1 pgoyette h_pass("Sun", "%A", 3, -1, -1, -1, -1, -1, -1, 0, -1);
137 1.1 pgoyette h_pass("Sunday", "%A", 6, -1, -1, -1, -1, -1, -1, 0, -1);
138 1.1 pgoyette h_pass("Mon", "%A", 3, -1, -1, -1, -1, -1, -1, 1, -1);
139 1.1 pgoyette h_pass("Monday", "%A", 6, -1, -1, -1, -1, -1, -1, 1, -1);
140 1.1 pgoyette h_pass("Tue", "%A", 3, -1, -1, -1, -1, -1, -1, 2, -1);
141 1.1 pgoyette h_pass("Tuesday", "%A", 7, -1, -1, -1, -1, -1, -1, 2, -1);
142 1.1 pgoyette h_pass("Wed", "%A", 3, -1, -1, -1, -1, -1, -1, 3, -1);
143 1.1 pgoyette h_pass("Wednesday", "%A", 9, -1, -1, -1, -1, -1, -1, 3, -1);
144 1.1 pgoyette h_pass("Thu", "%A", 3, -1, -1, -1, -1, -1, -1, 4, -1);
145 1.1 pgoyette h_pass("Thursday", "%A", 8, -1, -1, -1, -1, -1, -1, 4, -1);
146 1.1 pgoyette h_pass("Fri", "%A", 3, -1, -1, -1, -1, -1, -1, 5, -1);
147 1.1 pgoyette h_pass("Friday", "%A", 6, -1, -1, -1, -1, -1, -1, 5, -1);
148 1.1 pgoyette h_pass("Sat", "%A", 3, -1, -1, -1, -1, -1, -1, 6, -1);
149 1.1 pgoyette h_pass("Saturday", "%A", 8, -1, -1, -1, -1, -1, -1, 6, -1);
150 1.1 pgoyette h_pass("Saturn", "%A", 3, -1, -1, -1, -1, -1, -1, 6, -1);
151 1.1 pgoyette h_fail("Moon", "%A");
152 1.1 pgoyette
153 1.1 pgoyette h_pass("mon", "%a", 3, -1, -1, -1, -1, -1, -1, 1, -1);
154 1.1 pgoyette h_pass("tueSDay", "%A", 7, -1, -1, -1, -1, -1, -1, 2, -1);
155 1.1 pgoyette h_pass("sunday", "%A", 6, -1, -1, -1, -1, -1, -1, 0, -1);
156 1.1 pgoyette h_fail("sunday", "%EA");
157 1.1 pgoyette h_pass("SaturDay", "%A", 8, -1, -1, -1, -1, -1, -1, 6, -1);
158 1.1 pgoyette h_fail("SaturDay", "%OA");
159 1.1 pgoyette }
160 1.1 pgoyette
161 1.5 ginsbach ATF_TC(hour);
162 1.5 ginsbach
163 1.5 ginsbach ATF_TC_HEAD(hour, tc)
164 1.5 ginsbach {
165 1.5 ginsbach
166 1.5 ginsbach atf_tc_set_md_var(tc, "descr",
167 1.5 ginsbach "Checks strptime(3) hour conversions [IH]");
168 1.5 ginsbach }
169 1.5 ginsbach
170 1.5 ginsbach ATF_TC_BODY(hour, tc)
171 1.5 ginsbach {
172 1.5 ginsbach
173 1.5 ginsbach h_fail("00", "%I");
174 1.5 ginsbach h_fail("13", "%I");
175 1.5 ginsbach
176 1.5 ginsbach h_pass("00", "%H", 2, -1, -1, 0, -1, -1, -1, -1, -1);
177 1.5 ginsbach h_pass("12", "%H", 2, -1, -1, 12, -1, -1, -1, -1, -1);
178 1.5 ginsbach h_pass("23", "%H", 2, -1, -1, 23, -1, -1, -1, -1, -1);
179 1.5 ginsbach h_fail("24", "%H");
180 1.5 ginsbach }
181 1.5 ginsbach
182 1.5 ginsbach
183 1.1 pgoyette ATF_TC(month);
184 1.1 pgoyette
185 1.1 pgoyette ATF_TC_HEAD(month, tc)
186 1.1 pgoyette {
187 1.1 pgoyette
188 1.2 ginsbach atf_tc_set_md_var(tc, "descr",
189 1.2 ginsbach "Checks strptime(3) month name conversions [bB]");
190 1.1 pgoyette }
191 1.1 pgoyette
192 1.1 pgoyette ATF_TC_BODY(month, tc)
193 1.1 pgoyette {
194 1.1 pgoyette
195 1.1 pgoyette h_pass("Jan", "%b", 3, -1, -1, -1, -1, 0, -1, -1, -1);
196 1.1 pgoyette h_pass("January", "%b", 7, -1, -1, -1, -1, 0, -1, -1, -1);
197 1.1 pgoyette h_pass("Feb", "%b", 3, -1, -1, -1, -1, 1, -1, -1, -1);
198 1.1 pgoyette h_pass("February", "%b", 8, -1, -1, -1, -1, 1, -1, -1, -1);
199 1.1 pgoyette h_pass("Mar", "%b", 3, -1, -1, -1, -1, 2, -1, -1, -1);
200 1.1 pgoyette h_pass("March", "%b", 5, -1, -1, -1, -1, 2, -1, -1, -1);
201 1.1 pgoyette h_pass("Apr", "%b", 3, -1, -1, -1, -1, 3, -1, -1, -1);
202 1.1 pgoyette h_pass("April", "%b", 5, -1, -1, -1, -1, 3, -1, -1, -1);
203 1.1 pgoyette h_pass("May", "%b", 3, -1, -1, -1, -1, 4, -1, -1, -1);
204 1.1 pgoyette h_pass("Jun", "%b", 3, -1, -1, -1, -1, 5, -1, -1, -1);
205 1.1 pgoyette h_pass("June", "%b", 4, -1, -1, -1, -1, 5, -1, -1, -1);
206 1.1 pgoyette h_pass("Jul", "%b", 3, -1, -1, -1, -1, 6, -1, -1, -1);
207 1.1 pgoyette h_pass("July", "%b", 4, -1, -1, -1, -1, 6, -1, -1, -1);
208 1.1 pgoyette h_pass("Aug", "%b", 3, -1, -1, -1, -1, 7, -1, -1, -1);
209 1.1 pgoyette h_pass("August", "%b", 6, -1, -1, -1, -1, 7, -1, -1, -1);
210 1.1 pgoyette h_pass("Sep", "%b", 3, -1, -1, -1, -1, 8, -1, -1, -1);
211 1.1 pgoyette h_pass("September", "%b", 9, -1, -1, -1, -1, 8, -1, -1, -1);
212 1.1 pgoyette h_pass("Oct", "%b", 3, -1, -1, -1, -1, 9, -1, -1, -1);
213 1.1 pgoyette h_pass("October", "%b", 7, -1, -1, -1, -1, 9, -1, -1, -1);
214 1.1 pgoyette h_pass("Nov", "%b", 3, -1, -1, -1, -1, 10, -1, -1, -1);
215 1.1 pgoyette h_pass("November", "%b", 8, -1, -1, -1, -1, 10, -1, -1, -1);
216 1.1 pgoyette h_pass("Dec", "%b", 3, -1, -1, -1, -1, 11, -1, -1, -1);
217 1.1 pgoyette h_pass("December", "%b", 8, -1, -1, -1, -1, 11, -1, -1, -1);
218 1.1 pgoyette h_pass("Mayor", "%b", 3, -1, -1, -1, -1, 4, -1, -1, -1);
219 1.1 pgoyette h_pass("Mars", "%b", 3, -1, -1, -1, -1, 2, -1, -1, -1);
220 1.1 pgoyette h_fail("Rover", "%b");
221 1.1 pgoyette h_pass("Jan", "%B", 3, -1, -1, -1, -1, 0, -1, -1, -1);
222 1.1 pgoyette h_pass("January", "%B", 7, -1, -1, -1, -1, 0, -1, -1, -1);
223 1.1 pgoyette h_pass("Feb", "%B", 3, -1, -1, -1, -1, 1, -1, -1, -1);
224 1.1 pgoyette h_pass("February", "%B", 8, -1, -1, -1, -1, 1, -1, -1, -1);
225 1.1 pgoyette h_pass("Mar", "%B", 3, -1, -1, -1, -1, 2, -1, -1, -1);
226 1.1 pgoyette h_pass("March", "%B", 5, -1, -1, -1, -1, 2, -1, -1, -1);
227 1.1 pgoyette h_pass("Apr", "%B", 3, -1, -1, -1, -1, 3, -1, -1, -1);
228 1.1 pgoyette h_pass("April", "%B", 5, -1, -1, -1, -1, 3, -1, -1, -1);
229 1.1 pgoyette h_pass("May", "%B", 3, -1, -1, -1, -1, 4, -1, -1, -1);
230 1.1 pgoyette h_pass("Jun", "%B", 3, -1, -1, -1, -1, 5, -1, -1, -1);
231 1.1 pgoyette h_pass("June", "%B", 4, -1, -1, -1, -1, 5, -1, -1, -1);
232 1.1 pgoyette h_pass("Jul", "%B", 3, -1, -1, -1, -1, 6, -1, -1, -1);
233 1.1 pgoyette h_pass("July", "%B", 4, -1, -1, -1, -1, 6, -1, -1, -1);
234 1.1 pgoyette h_pass("Aug", "%B", 3, -1, -1, -1, -1, 7, -1, -1, -1);
235 1.1 pgoyette h_pass("August", "%B", 6, -1, -1, -1, -1, 7, -1, -1, -1);
236 1.1 pgoyette h_pass("Sep", "%B", 3, -1, -1, -1, -1, 8, -1, -1, -1);
237 1.1 pgoyette h_pass("September", "%B", 9, -1, -1, -1, -1, 8, -1, -1, -1);
238 1.1 pgoyette h_pass("Oct", "%B", 3, -1, -1, -1, -1, 9, -1, -1, -1);
239 1.1 pgoyette h_pass("October", "%B", 7, -1, -1, -1, -1, 9, -1, -1, -1);
240 1.1 pgoyette h_pass("Nov", "%B", 3, -1, -1, -1, -1, 10, -1, -1, -1);
241 1.1 pgoyette h_pass("November", "%B", 8, -1, -1, -1, -1, 10, -1, -1, -1);
242 1.1 pgoyette h_pass("Dec", "%B", 3, -1, -1, -1, -1, 11, -1, -1, -1);
243 1.1 pgoyette h_pass("December", "%B", 8, -1, -1, -1, -1, 11, -1, -1, -1);
244 1.1 pgoyette h_pass("Mayor", "%B", 3, -1, -1, -1, -1, 4, -1, -1, -1);
245 1.1 pgoyette h_pass("Mars", "%B", 3, -1, -1, -1, -1, 2, -1, -1, -1);
246 1.1 pgoyette h_fail("Rover", "%B");
247 1.1 pgoyette
248 1.1 pgoyette h_pass("september", "%b", 9, -1, -1, -1, -1, 8, -1, -1, -1);
249 1.1 pgoyette h_pass("septembe", "%B", 3, -1, -1, -1, -1, 8, -1, -1, -1);
250 1.1 pgoyette }
251 1.1 pgoyette
252 1.3 ginsbach ATF_TC(seconds);
253 1.3 ginsbach
254 1.3 ginsbach ATF_TC_HEAD(seconds, tc)
255 1.3 ginsbach {
256 1.3 ginsbach
257 1.3 ginsbach atf_tc_set_md_var(tc, "descr",
258 1.3 ginsbach "Checks strptime(3) seconds conversions [S]");
259 1.3 ginsbach }
260 1.3 ginsbach
261 1.3 ginsbach ATF_TC_BODY(seconds, tc)
262 1.3 ginsbach {
263 1.3 ginsbach
264 1.3 ginsbach h_pass("0", "%S", 1, 0, -1, -1, -1, -1, -1, -1, -1);
265 1.3 ginsbach h_pass("59", "%S", 2, 59, -1, -1, -1, -1, -1, -1, -1);
266 1.3 ginsbach h_pass("60", "%S", 2, 60, -1, -1, -1, -1, -1, -1, -1);
267 1.3 ginsbach h_pass("61", "%S", 2, 61, -1, -1, -1, -1, -1, -1, -1);
268 1.3 ginsbach h_fail("62", "%S");
269 1.3 ginsbach }
270 1.3 ginsbach
271 1.4 ginsbach ATF_TC(year);
272 1.4 ginsbach
273 1.4 ginsbach ATF_TC_HEAD(year, tc)
274 1.4 ginsbach {
275 1.4 ginsbach
276 1.4 ginsbach atf_tc_set_md_var(tc, "descr",
277 1.4 ginsbach "Checks strptime(3) century/year conversions [CyY]");
278 1.4 ginsbach }
279 1.4 ginsbach
280 1.4 ginsbach ATF_TC_BODY(year, tc)
281 1.4 ginsbach {
282 1.4 ginsbach
283 1.4 ginsbach h_pass("x20y", "x%Cy", 4, -1, -1, -1, -1, -1, 100, -1, -1);
284 1.4 ginsbach h_pass("x84y", "x%yy", 4, -1, -1, -1, -1, -1, 84, -1, -1);
285 1.4 ginsbach h_pass("x2084y", "x%C%yy", 6, -1, -1, -1, -1, -1, 184, -1, -1);
286 1.4 ginsbach h_pass("x8420y", "x%y%Cy", 6, -1, -1, -1, -1, -1, 184, -1, -1);
287 1.4 ginsbach h_pass("%20845", "%%%C%y5", 6, -1, -1, -1, -1, -1, 184, -1, -1);
288 1.4 ginsbach h_fail("%", "%E%");
289 1.4 ginsbach
290 1.4 ginsbach h_pass("1980", "%Y", 4, -1, -1, -1, -1, -1, 80, -1, -1);
291 1.4 ginsbach h_pass("1980", "%EY", 4, -1, -1, -1, -1, -1, 80, -1, -1);
292 1.4 ginsbach }
293 1.4 ginsbach
294 1.7 christos ATF_TC(zone);
295 1.7 christos
296 1.7 christos ATF_TC_HEAD(zone, tc)
297 1.7 christos {
298 1.7 christos
299 1.7 christos atf_tc_set_md_var(tc, "descr",
300 1.7 christos "Checks strptime(3) timezone conversion [z]");
301 1.7 christos }
302 1.7 christos
303 1.7 christos static struct {
304 1.7 christos const char *name;
305 1.7 christos long offs;
306 1.7 christos } zt[] = {
307 1.7 christos { "Z", 0 },
308 1.7 christos { "UT", 0 },
309 1.7 christos { "UTC", 0 },
310 1.7 christos { "GMT", 0 },
311 1.7 christos { "EST", -18000 },
312 1.7 christos { "EDT", -14400 },
313 1.7 christos { "CST", -21600 },
314 1.7 christos { "CDT", -18000 },
315 1.7 christos { "MST", -25200 },
316 1.7 christos { "MDT", -21600 },
317 1.7 christos { "PST", -28800 },
318 1.7 christos { "PDT", -25200 },
319 1.7 christos
320 1.7 christos { "VST", -1 },
321 1.7 christos { "VDT", -1 },
322 1.7 christos
323 1.7 christos { "+03", 10800 },
324 1.7 christos { "-03", -10800 },
325 1.7 christos { "+0403", 14580 },
326 1.7 christos { "-0403", -14580 },
327 1.7 christos { "+04:03", 14580 },
328 1.7 christos { "-04:03", -14580 },
329 1.7 christos
330 1.7 christos { "1", -1 },
331 1.7 christos { "03", -1 },
332 1.7 christos { "0304", -1 },
333 1.7 christos { "+1", -1 },
334 1.7 christos { "-203", -1 },
335 1.7 christos { "+12345", -1 },
336 1.7 christos { "+12:345", -1 },
337 1.7 christos { "+123:45", -1 },
338 1.7 christos
339 1.7 christos { "A", -3600 },
340 1.7 christos { "B", -7200 },
341 1.7 christos { "C", -10800 },
342 1.7 christos { "D", -14400 },
343 1.7 christos { "E", -18000 },
344 1.7 christos { "F", -21600 },
345 1.7 christos { "G", -25200 },
346 1.7 christos { "H", -28800 },
347 1.7 christos { "I", -32400 },
348 1.7 christos { "L", -39600 },
349 1.7 christos { "M", -43200 },
350 1.7 christos { "N", 3600 },
351 1.7 christos { "O", 7200 },
352 1.7 christos { "P", 10800 },
353 1.7 christos { "Q", 14400 },
354 1.7 christos { "R", 18000 },
355 1.7 christos { "T", 25200 },
356 1.7 christos { "U", 28800 },
357 1.7 christos { "V", 32400 },
358 1.7 christos { "W", 36000 },
359 1.7 christos { "X", 39600 },
360 1.7 christos { "Y", 43200 },
361 1.7 christos
362 1.7 christos { "J", -1 },
363 1.7 christos
364 1.7 christos { "America/Los_Angeles", -28800 },
365 1.7 christos { "America/New_York", -18000 },
366 1.7 christos { "EST4EDT", -14400 },
367 1.7 christos
368 1.7 christos { "Bogus", -1 },
369 1.7 christos };
370 1.7 christos
371 1.7 christos ATF_TC_BODY(zone, tc)
372 1.7 christos {
373 1.7 christos struct tm tm;
374 1.7 christos
375 1.7 christos for (size_t i = 0; i < __arraycount(zt); i++) {
376 1.7 christos if (strptime(zt[i].name, "%z", &tm) == NULL)
377 1.7 christos tm.tm_gmtoff = -1;
378 1.7 christos ATF_REQUIRE_MSG(tm.tm_gmtoff == zt[i].offs,
379 1.7 christos "strptime(\"%s\", \"%%z\", &tm): "
380 1.7 christos "expected: tm.tm_gmtoff=%ld, got: tm.tm_gmtoff=%ld",
381 1.7 christos zt[i].name, zt[i].offs, tm.tm_gmtoff);
382 1.7 christos }
383 1.7 christos }
384 1.7 christos
385 1.1 pgoyette ATF_TP_ADD_TCS(tp)
386 1.1 pgoyette {
387 1.1 pgoyette
388 1.1 pgoyette ATF_TP_ADD_TC(tp, common);
389 1.1 pgoyette ATF_TP_ADD_TC(tp, day);
390 1.5 ginsbach ATF_TP_ADD_TC(tp, hour);
391 1.1 pgoyette ATF_TP_ADD_TC(tp, month);
392 1.3 ginsbach ATF_TP_ADD_TC(tp, seconds);
393 1.4 ginsbach ATF_TP_ADD_TC(tp, year);
394 1.7 christos ATF_TP_ADD_TC(tp, zone);
395 1.1 pgoyette
396 1.1 pgoyette return atf_no_error();
397 1.1 pgoyette }
398