t_strptime.c revision 1.15 1 1.15 maya /* $NetBSD: t_strptime.c,v 1.15 2018/06/03 08:48:37 maya 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.15 maya __RCSID("$NetBSD: t_strptime.c,v 1.15 2018/06/03 08:48:37 maya Exp $");
36 1.1 pgoyette
37 1.1 pgoyette #include <time.h>
38 1.10 christos #include <stdlib.h>
39 1.11 christos #include <stdio.h>
40 1.1 pgoyette
41 1.1 pgoyette #include <atf-c.h>
42 1.1 pgoyette
43 1.1 pgoyette static void
44 1.1 pgoyette h_pass(const char *buf, const char *fmt, int len,
45 1.1 pgoyette int tm_sec, int tm_min, int tm_hour, int tm_mday,
46 1.1 pgoyette int tm_mon, int tm_year, int tm_wday, int tm_yday)
47 1.1 pgoyette {
48 1.1 pgoyette struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL };
49 1.1 pgoyette const char *ret, *exp;
50 1.1 pgoyette
51 1.1 pgoyette exp = buf + len;
52 1.1 pgoyette ret = strptime(buf, fmt, &tm);
53 1.1 pgoyette
54 1.15 maya ATF_CHECK_MSG(ret == exp,
55 1.1 pgoyette "strptime(\"%s\", \"%s\", tm): incorrect return code: "
56 1.1 pgoyette "expected: %p, got: %p", buf, fmt, exp, ret);
57 1.1 pgoyette
58 1.1 pgoyette #define H_REQUIRE_FIELD(field) \
59 1.15 maya ATF_CHECK_MSG(tm.field == field, \
60 1.1 pgoyette "strptime(\"%s\", \"%s\", tm): incorrect %s: " \
61 1.1 pgoyette "expected: %d, but got: %d", buf, fmt, \
62 1.1 pgoyette ___STRING(field), field, tm.field)
63 1.1 pgoyette
64 1.1 pgoyette H_REQUIRE_FIELD(tm_sec);
65 1.1 pgoyette H_REQUIRE_FIELD(tm_min);
66 1.1 pgoyette H_REQUIRE_FIELD(tm_hour);
67 1.1 pgoyette H_REQUIRE_FIELD(tm_mday);
68 1.1 pgoyette H_REQUIRE_FIELD(tm_mon);
69 1.1 pgoyette H_REQUIRE_FIELD(tm_year);
70 1.1 pgoyette H_REQUIRE_FIELD(tm_wday);
71 1.1 pgoyette H_REQUIRE_FIELD(tm_yday);
72 1.1 pgoyette
73 1.1 pgoyette #undef H_REQUIRE_FIELD
74 1.1 pgoyette }
75 1.1 pgoyette
76 1.1 pgoyette static void
77 1.1 pgoyette h_fail(const char *buf, const char *fmt)
78 1.1 pgoyette {
79 1.1 pgoyette struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL };
80 1.1 pgoyette
81 1.15 maya ATF_CHECK_MSG(strptime(buf, fmt, &tm) == NULL, "strptime(\"%s\", "
82 1.1 pgoyette "\"%s\", &tm) should fail, but it didn't", buf, fmt);
83 1.1 pgoyette }
84 1.1 pgoyette
85 1.10 christos static struct {
86 1.10 christos const char *name;
87 1.10 christos long offs;
88 1.10 christos } zt[] = {
89 1.10 christos { "Z", 0 },
90 1.10 christos { "UT", 0 },
91 1.10 christos { "UTC", 0 },
92 1.10 christos { "GMT", 0 },
93 1.10 christos { "EST", -18000 },
94 1.10 christos { "EDT", -14400 },
95 1.10 christos { "CST", -21600 },
96 1.10 christos { "CDT", -18000 },
97 1.10 christos { "MST", -25200 },
98 1.10 christos { "MDT", -21600 },
99 1.10 christos { "PST", -28800 },
100 1.10 christos { "PDT", -25200 },
101 1.10 christos
102 1.10 christos { "VST", -1 },
103 1.10 christos { "VDT", -1 },
104 1.10 christos
105 1.10 christos { "+03", 10800 },
106 1.10 christos { "-03", -10800 },
107 1.10 christos { "+0403", 14580 },
108 1.10 christos { "-0403", -14580 },
109 1.10 christos { "+04:03", 14580 },
110 1.10 christos { "-04:03", -14580 },
111 1.10 christos { "+14:00", 50400 },
112 1.10 christos { "-14:00", -50400 },
113 1.10 christos { "+23:59", 86340 },
114 1.10 christos { "-23:59", -86340 },
115 1.10 christos
116 1.10 christos { "1", -1 },
117 1.10 christos { "03", -1 },
118 1.10 christos { "0304", -1 },
119 1.10 christos { "+1", -1 },
120 1.10 christos { "-203", -1 },
121 1.10 christos { "+12345", -1 },
122 1.10 christos { "+12:345", -1 },
123 1.10 christos { "+123:45", -1 },
124 1.10 christos { "+2400", -1 },
125 1.10 christos { "-2400", -1 },
126 1.10 christos { "+1060", -1 },
127 1.10 christos { "-1060", -1 },
128 1.10 christos
129 1.13 ginsbach { "A", 3600 },
130 1.13 ginsbach { "B", 7200 },
131 1.13 ginsbach { "C", 10800 },
132 1.13 ginsbach { "D", 14400 },
133 1.13 ginsbach { "E", 18000 },
134 1.13 ginsbach { "F", 21600 },
135 1.13 ginsbach { "G", 25200 },
136 1.13 ginsbach { "H", 28800 },
137 1.13 ginsbach { "I", 32400 },
138 1.13 ginsbach { "L", 39600 },
139 1.13 ginsbach { "M", 43200 },
140 1.13 ginsbach { "N", -3600 },
141 1.13 ginsbach { "O", -7200 },
142 1.13 ginsbach { "P", -10800 },
143 1.13 ginsbach { "Q", -14400 },
144 1.13 ginsbach { "R", -18000 },
145 1.13 ginsbach { "T", -25200 },
146 1.13 ginsbach { "U", -28800 },
147 1.13 ginsbach { "V", -32400 },
148 1.13 ginsbach { "W", -36000 },
149 1.13 ginsbach { "X", -39600 },
150 1.13 ginsbach { "Y", -43200 },
151 1.10 christos
152 1.11 christos { "J", -2 },
153 1.10 christos
154 1.10 christos { "America/Los_Angeles", -28800 },
155 1.10 christos { "America/New_York", -18000 },
156 1.10 christos { "EST4EDT", -14400 },
157 1.10 christos
158 1.10 christos { "Bogus", -1 },
159 1.10 christos };
160 1.10 christos
161 1.10 christos static void
162 1.12 christos ztest1(const char *name, const char *fmt, long value)
163 1.10 christos {
164 1.10 christos struct tm tm;
165 1.11 christos char *rv;
166 1.10 christos
167 1.10 christos memset(&tm, 0, sizeof(tm));
168 1.11 christos if ((rv = strptime(name, fmt, &tm)) == NULL)
169 1.10 christos tm.tm_gmtoff = -1;
170 1.11 christos else if (rv == name && fmt[1] == 'Z')
171 1.11 christos value = 0;
172 1.11 christos
173 1.11 christos switch (value) {
174 1.11 christos case -2:
175 1.11 christos value = -timezone;
176 1.11 christos break;
177 1.11 christos case -1:
178 1.11 christos if (fmt[1] == 'Z')
179 1.11 christos value = 0;
180 1.11 christos break;
181 1.11 christos default:
182 1.11 christos break;
183 1.11 christos }
184 1.11 christos
185 1.15 maya ATF_CHECK_MSG(tm.tm_gmtoff == value,
186 1.10 christos "strptime(\"%s\", \"%s\", &tm): "
187 1.10 christos "expected: tm.tm_gmtoff=%ld, got: tm.tm_gmtoff=%ld",
188 1.10 christos name, fmt, value, tm.tm_gmtoff);
189 1.11 christos printf("%s %s %ld\n", name, fmt, tm.tm_gmtoff);
190 1.10 christos }
191 1.10 christos
192 1.12 christos static void
193 1.12 christos ztest(const char *fmt)
194 1.12 christos {
195 1.12 christos setenv("TZ", "US/Eastern", 1);
196 1.12 christos ztest1("GMT", fmt, 0);
197 1.12 christos ztest1("UTC", fmt, 0);
198 1.12 christos ztest1("US/Eastern", fmt, -18000);
199 1.12 christos for (size_t i = 0; i < __arraycount(zt); i++)
200 1.12 christos ztest1(zt[i].name, fmt, zt[i].offs);
201 1.12 christos }
202 1.12 christos
203 1.1 pgoyette ATF_TC(common);
204 1.1 pgoyette
205 1.1 pgoyette ATF_TC_HEAD(common, tc)
206 1.1 pgoyette {
207 1.1 pgoyette
208 1.1 pgoyette atf_tc_set_md_var(tc, "descr", "Checks strptime(3): various checks");
209 1.1 pgoyette }
210 1.1 pgoyette
211 1.1 pgoyette ATF_TC_BODY(common, tc)
212 1.1 pgoyette {
213 1.1 pgoyette
214 1.1 pgoyette h_pass("Tue Jan 20 23:27:46 1998", "%a %b %d %T %Y",
215 1.6 christos 24, 46, 27, 23, 20, 0, 98, 2, 19);
216 1.1 pgoyette h_pass("Tue Jan 20 23:27:46 1998", "%a %b %d %H:%M:%S %Y",
217 1.6 christos 24, 46, 27, 23, 20, 0, 98, 2, 19);
218 1.1 pgoyette h_pass("Tue Jan 20 23:27:46 1998", "%c",
219 1.6 christos 24, 46, 27, 23, 20, 0, 98, 2, 19);
220 1.1 pgoyette h_pass("Fri Mar 4 20:05:34 2005", "%a %b %e %H:%M:%S %Y",
221 1.6 christos 24, 34, 5, 20, 4, 2, 105, 5, 62);
222 1.1 pgoyette h_pass("5\t3 4 8pm:05:34 2005", "%w%n%m%t%d%n%k%p:%M:%S %Y",
223 1.6 christos 21, 34, 5, 20, 4, 2, 105, 5, 62);
224 1.1 pgoyette h_pass("Fri Mar 4 20:05:34 2005", "%c",
225 1.6 christos 24, 34, 5, 20, 4, 2, 105, 5, 62);
226 1.1 pgoyette }
227 1.1 pgoyette
228 1.1 pgoyette ATF_TC(day);
229 1.1 pgoyette
230 1.1 pgoyette ATF_TC_HEAD(day, tc)
231 1.1 pgoyette {
232 1.1 pgoyette
233 1.2 ginsbach atf_tc_set_md_var(tc, "descr",
234 1.2 ginsbach "Checks strptime(3) day name conversions [aA]");
235 1.1 pgoyette }
236 1.1 pgoyette
237 1.1 pgoyette ATF_TC_BODY(day, tc)
238 1.1 pgoyette {
239 1.1 pgoyette
240 1.1 pgoyette h_pass("Sun", "%a", 3, -1, -1, -1, -1, -1, -1, 0, -1);
241 1.1 pgoyette h_pass("Sunday", "%a", 6, -1, -1, -1, -1, -1, -1, 0, -1);
242 1.1 pgoyette h_pass("Mon", "%a", 3, -1, -1, -1, -1, -1, -1, 1, -1);
243 1.1 pgoyette h_pass("Monday", "%a", 6, -1, -1, -1, -1, -1, -1, 1, -1);
244 1.1 pgoyette h_pass("Tue", "%a", 3, -1, -1, -1, -1, -1, -1, 2, -1);
245 1.1 pgoyette h_pass("Tuesday", "%a", 7, -1, -1, -1, -1, -1, -1, 2, -1);
246 1.1 pgoyette h_pass("Wed", "%a", 3, -1, -1, -1, -1, -1, -1, 3, -1);
247 1.1 pgoyette h_pass("Wednesday", "%a", 9, -1, -1, -1, -1, -1, -1, 3, -1);
248 1.1 pgoyette h_pass("Thu", "%a", 3, -1, -1, -1, -1, -1, -1, 4, -1);
249 1.1 pgoyette h_pass("Thursday", "%a", 8, -1, -1, -1, -1, -1, -1, 4, -1);
250 1.1 pgoyette h_pass("Fri", "%a", 3, -1, -1, -1, -1, -1, -1, 5, -1);
251 1.1 pgoyette h_pass("Friday", "%a", 6, -1, -1, -1, -1, -1, -1, 5, -1);
252 1.1 pgoyette h_pass("Sat", "%a", 3, -1, -1, -1, -1, -1, -1, 6, -1);
253 1.1 pgoyette h_pass("Saturday", "%a", 8, -1, -1, -1, -1, -1, -1, 6, -1);
254 1.1 pgoyette h_pass("Saturn", "%a", 3, -1, -1, -1, -1, -1, -1, 6, -1);
255 1.1 pgoyette h_fail("Moon", "%a");
256 1.1 pgoyette h_pass("Sun", "%A", 3, -1, -1, -1, -1, -1, -1, 0, -1);
257 1.1 pgoyette h_pass("Sunday", "%A", 6, -1, -1, -1, -1, -1, -1, 0, -1);
258 1.1 pgoyette h_pass("Mon", "%A", 3, -1, -1, -1, -1, -1, -1, 1, -1);
259 1.1 pgoyette h_pass("Monday", "%A", 6, -1, -1, -1, -1, -1, -1, 1, -1);
260 1.1 pgoyette h_pass("Tue", "%A", 3, -1, -1, -1, -1, -1, -1, 2, -1);
261 1.1 pgoyette h_pass("Tuesday", "%A", 7, -1, -1, -1, -1, -1, -1, 2, -1);
262 1.1 pgoyette h_pass("Wed", "%A", 3, -1, -1, -1, -1, -1, -1, 3, -1);
263 1.1 pgoyette h_pass("Wednesday", "%A", 9, -1, -1, -1, -1, -1, -1, 3, -1);
264 1.1 pgoyette h_pass("Thu", "%A", 3, -1, -1, -1, -1, -1, -1, 4, -1);
265 1.1 pgoyette h_pass("Thursday", "%A", 8, -1, -1, -1, -1, -1, -1, 4, -1);
266 1.1 pgoyette h_pass("Fri", "%A", 3, -1, -1, -1, -1, -1, -1, 5, -1);
267 1.1 pgoyette h_pass("Friday", "%A", 6, -1, -1, -1, -1, -1, -1, 5, -1);
268 1.1 pgoyette h_pass("Sat", "%A", 3, -1, -1, -1, -1, -1, -1, 6, -1);
269 1.1 pgoyette h_pass("Saturday", "%A", 8, -1, -1, -1, -1, -1, -1, 6, -1);
270 1.1 pgoyette h_pass("Saturn", "%A", 3, -1, -1, -1, -1, -1, -1, 6, -1);
271 1.1 pgoyette h_fail("Moon", "%A");
272 1.1 pgoyette
273 1.1 pgoyette h_pass("mon", "%a", 3, -1, -1, -1, -1, -1, -1, 1, -1);
274 1.1 pgoyette h_pass("tueSDay", "%A", 7, -1, -1, -1, -1, -1, -1, 2, -1);
275 1.1 pgoyette h_pass("sunday", "%A", 6, -1, -1, -1, -1, -1, -1, 0, -1);
276 1.1 pgoyette h_fail("sunday", "%EA");
277 1.1 pgoyette h_pass("SaturDay", "%A", 8, -1, -1, -1, -1, -1, -1, 6, -1);
278 1.1 pgoyette h_fail("SaturDay", "%OA");
279 1.1 pgoyette }
280 1.1 pgoyette
281 1.5 ginsbach ATF_TC(hour);
282 1.5 ginsbach
283 1.5 ginsbach ATF_TC_HEAD(hour, tc)
284 1.5 ginsbach {
285 1.5 ginsbach
286 1.5 ginsbach atf_tc_set_md_var(tc, "descr",
287 1.5 ginsbach "Checks strptime(3) hour conversions [IH]");
288 1.5 ginsbach }
289 1.5 ginsbach
290 1.5 ginsbach ATF_TC_BODY(hour, tc)
291 1.5 ginsbach {
292 1.5 ginsbach
293 1.5 ginsbach h_fail("00", "%I");
294 1.5 ginsbach h_fail("13", "%I");
295 1.5 ginsbach
296 1.5 ginsbach h_pass("00", "%H", 2, -1, -1, 0, -1, -1, -1, -1, -1);
297 1.5 ginsbach h_pass("12", "%H", 2, -1, -1, 12, -1, -1, -1, -1, -1);
298 1.5 ginsbach h_pass("23", "%H", 2, -1, -1, 23, -1, -1, -1, -1, -1);
299 1.5 ginsbach h_fail("24", "%H");
300 1.5 ginsbach }
301 1.5 ginsbach
302 1.5 ginsbach
303 1.1 pgoyette ATF_TC(month);
304 1.1 pgoyette
305 1.1 pgoyette ATF_TC_HEAD(month, tc)
306 1.1 pgoyette {
307 1.1 pgoyette
308 1.2 ginsbach atf_tc_set_md_var(tc, "descr",
309 1.2 ginsbach "Checks strptime(3) month name conversions [bB]");
310 1.1 pgoyette }
311 1.1 pgoyette
312 1.1 pgoyette ATF_TC_BODY(month, tc)
313 1.1 pgoyette {
314 1.1 pgoyette
315 1.1 pgoyette h_pass("Jan", "%b", 3, -1, -1, -1, -1, 0, -1, -1, -1);
316 1.1 pgoyette h_pass("January", "%b", 7, -1, -1, -1, -1, 0, -1, -1, -1);
317 1.1 pgoyette h_pass("Feb", "%b", 3, -1, -1, -1, -1, 1, -1, -1, -1);
318 1.1 pgoyette h_pass("February", "%b", 8, -1, -1, -1, -1, 1, -1, -1, -1);
319 1.1 pgoyette h_pass("Mar", "%b", 3, -1, -1, -1, -1, 2, -1, -1, -1);
320 1.1 pgoyette h_pass("March", "%b", 5, -1, -1, -1, -1, 2, -1, -1, -1);
321 1.1 pgoyette h_pass("Apr", "%b", 3, -1, -1, -1, -1, 3, -1, -1, -1);
322 1.1 pgoyette h_pass("April", "%b", 5, -1, -1, -1, -1, 3, -1, -1, -1);
323 1.1 pgoyette h_pass("May", "%b", 3, -1, -1, -1, -1, 4, -1, -1, -1);
324 1.1 pgoyette h_pass("Jun", "%b", 3, -1, -1, -1, -1, 5, -1, -1, -1);
325 1.1 pgoyette h_pass("June", "%b", 4, -1, -1, -1, -1, 5, -1, -1, -1);
326 1.1 pgoyette h_pass("Jul", "%b", 3, -1, -1, -1, -1, 6, -1, -1, -1);
327 1.1 pgoyette h_pass("July", "%b", 4, -1, -1, -1, -1, 6, -1, -1, -1);
328 1.1 pgoyette h_pass("Aug", "%b", 3, -1, -1, -1, -1, 7, -1, -1, -1);
329 1.1 pgoyette h_pass("August", "%b", 6, -1, -1, -1, -1, 7, -1, -1, -1);
330 1.1 pgoyette h_pass("Sep", "%b", 3, -1, -1, -1, -1, 8, -1, -1, -1);
331 1.1 pgoyette h_pass("September", "%b", 9, -1, -1, -1, -1, 8, -1, -1, -1);
332 1.1 pgoyette h_pass("Oct", "%b", 3, -1, -1, -1, -1, 9, -1, -1, -1);
333 1.1 pgoyette h_pass("October", "%b", 7, -1, -1, -1, -1, 9, -1, -1, -1);
334 1.1 pgoyette h_pass("Nov", "%b", 3, -1, -1, -1, -1, 10, -1, -1, -1);
335 1.1 pgoyette h_pass("November", "%b", 8, -1, -1, -1, -1, 10, -1, -1, -1);
336 1.1 pgoyette h_pass("Dec", "%b", 3, -1, -1, -1, -1, 11, -1, -1, -1);
337 1.1 pgoyette h_pass("December", "%b", 8, -1, -1, -1, -1, 11, -1, -1, -1);
338 1.1 pgoyette h_pass("Mayor", "%b", 3, -1, -1, -1, -1, 4, -1, -1, -1);
339 1.1 pgoyette h_pass("Mars", "%b", 3, -1, -1, -1, -1, 2, -1, -1, -1);
340 1.1 pgoyette h_fail("Rover", "%b");
341 1.1 pgoyette h_pass("Jan", "%B", 3, -1, -1, -1, -1, 0, -1, -1, -1);
342 1.1 pgoyette h_pass("January", "%B", 7, -1, -1, -1, -1, 0, -1, -1, -1);
343 1.1 pgoyette h_pass("Feb", "%B", 3, -1, -1, -1, -1, 1, -1, -1, -1);
344 1.1 pgoyette h_pass("February", "%B", 8, -1, -1, -1, -1, 1, -1, -1, -1);
345 1.1 pgoyette h_pass("Mar", "%B", 3, -1, -1, -1, -1, 2, -1, -1, -1);
346 1.1 pgoyette h_pass("March", "%B", 5, -1, -1, -1, -1, 2, -1, -1, -1);
347 1.1 pgoyette h_pass("Apr", "%B", 3, -1, -1, -1, -1, 3, -1, -1, -1);
348 1.1 pgoyette h_pass("April", "%B", 5, -1, -1, -1, -1, 3, -1, -1, -1);
349 1.1 pgoyette h_pass("May", "%B", 3, -1, -1, -1, -1, 4, -1, -1, -1);
350 1.1 pgoyette h_pass("Jun", "%B", 3, -1, -1, -1, -1, 5, -1, -1, -1);
351 1.1 pgoyette h_pass("June", "%B", 4, -1, -1, -1, -1, 5, -1, -1, -1);
352 1.1 pgoyette h_pass("Jul", "%B", 3, -1, -1, -1, -1, 6, -1, -1, -1);
353 1.1 pgoyette h_pass("July", "%B", 4, -1, -1, -1, -1, 6, -1, -1, -1);
354 1.1 pgoyette h_pass("Aug", "%B", 3, -1, -1, -1, -1, 7, -1, -1, -1);
355 1.1 pgoyette h_pass("August", "%B", 6, -1, -1, -1, -1, 7, -1, -1, -1);
356 1.1 pgoyette h_pass("Sep", "%B", 3, -1, -1, -1, -1, 8, -1, -1, -1);
357 1.1 pgoyette h_pass("September", "%B", 9, -1, -1, -1, -1, 8, -1, -1, -1);
358 1.1 pgoyette h_pass("Oct", "%B", 3, -1, -1, -1, -1, 9, -1, -1, -1);
359 1.1 pgoyette h_pass("October", "%B", 7, -1, -1, -1, -1, 9, -1, -1, -1);
360 1.1 pgoyette h_pass("Nov", "%B", 3, -1, -1, -1, -1, 10, -1, -1, -1);
361 1.1 pgoyette h_pass("November", "%B", 8, -1, -1, -1, -1, 10, -1, -1, -1);
362 1.1 pgoyette h_pass("Dec", "%B", 3, -1, -1, -1, -1, 11, -1, -1, -1);
363 1.1 pgoyette h_pass("December", "%B", 8, -1, -1, -1, -1, 11, -1, -1, -1);
364 1.1 pgoyette h_pass("Mayor", "%B", 3, -1, -1, -1, -1, 4, -1, -1, -1);
365 1.1 pgoyette h_pass("Mars", "%B", 3, -1, -1, -1, -1, 2, -1, -1, -1);
366 1.1 pgoyette h_fail("Rover", "%B");
367 1.1 pgoyette
368 1.1 pgoyette h_pass("september", "%b", 9, -1, -1, -1, -1, 8, -1, -1, -1);
369 1.1 pgoyette h_pass("septembe", "%B", 3, -1, -1, -1, -1, 8, -1, -1, -1);
370 1.1 pgoyette }
371 1.1 pgoyette
372 1.3 ginsbach ATF_TC(seconds);
373 1.3 ginsbach
374 1.3 ginsbach ATF_TC_HEAD(seconds, tc)
375 1.3 ginsbach {
376 1.3 ginsbach
377 1.3 ginsbach atf_tc_set_md_var(tc, "descr",
378 1.3 ginsbach "Checks strptime(3) seconds conversions [S]");
379 1.3 ginsbach }
380 1.3 ginsbach
381 1.3 ginsbach ATF_TC_BODY(seconds, tc)
382 1.3 ginsbach {
383 1.3 ginsbach
384 1.3 ginsbach h_pass("0", "%S", 1, 0, -1, -1, -1, -1, -1, -1, -1);
385 1.3 ginsbach h_pass("59", "%S", 2, 59, -1, -1, -1, -1, -1, -1, -1);
386 1.3 ginsbach h_pass("60", "%S", 2, 60, -1, -1, -1, -1, -1, -1, -1);
387 1.3 ginsbach h_pass("61", "%S", 2, 61, -1, -1, -1, -1, -1, -1, -1);
388 1.3 ginsbach h_fail("62", "%S");
389 1.3 ginsbach }
390 1.3 ginsbach
391 1.4 ginsbach ATF_TC(year);
392 1.4 ginsbach
393 1.4 ginsbach ATF_TC_HEAD(year, tc)
394 1.4 ginsbach {
395 1.4 ginsbach
396 1.4 ginsbach atf_tc_set_md_var(tc, "descr",
397 1.4 ginsbach "Checks strptime(3) century/year conversions [CyY]");
398 1.4 ginsbach }
399 1.4 ginsbach
400 1.4 ginsbach ATF_TC_BODY(year, tc)
401 1.4 ginsbach {
402 1.4 ginsbach
403 1.4 ginsbach h_pass("x20y", "x%Cy", 4, -1, -1, -1, -1, -1, 100, -1, -1);
404 1.4 ginsbach h_pass("x84y", "x%yy", 4, -1, -1, -1, -1, -1, 84, -1, -1);
405 1.4 ginsbach h_pass("x2084y", "x%C%yy", 6, -1, -1, -1, -1, -1, 184, -1, -1);
406 1.4 ginsbach h_pass("x8420y", "x%y%Cy", 6, -1, -1, -1, -1, -1, 184, -1, -1);
407 1.4 ginsbach h_pass("%20845", "%%%C%y5", 6, -1, -1, -1, -1, -1, 184, -1, -1);
408 1.4 ginsbach h_fail("%", "%E%");
409 1.4 ginsbach
410 1.4 ginsbach h_pass("1980", "%Y", 4, -1, -1, -1, -1, -1, 80, -1, -1);
411 1.4 ginsbach h_pass("1980", "%EY", 4, -1, -1, -1, -1, -1, 80, -1, -1);
412 1.4 ginsbach }
413 1.4 ginsbach
414 1.7 christos ATF_TC(zone);
415 1.7 christos
416 1.7 christos ATF_TC_HEAD(zone, tc)
417 1.7 christos {
418 1.7 christos
419 1.7 christos atf_tc_set_md_var(tc, "descr",
420 1.7 christos "Checks strptime(3) timezone conversion [z]");
421 1.7 christos }
422 1.7 christos
423 1.7 christos
424 1.10 christos ATF_TC_BODY(zone, tc)
425 1.10 christos {
426 1.12 christos ztest("%z");
427 1.10 christos }
428 1.7 christos
429 1.10 christos ATF_TC(Zone);
430 1.7 christos
431 1.10 christos ATF_TC_HEAD(Zone, tc)
432 1.10 christos {
433 1.7 christos
434 1.10 christos atf_tc_set_md_var(tc, "descr",
435 1.10 christos "Checks strptime(3) timezone conversion [Z]");
436 1.10 christos }
437 1.7 christos
438 1.7 christos
439 1.10 christos ATF_TC_BODY(Zone, tc)
440 1.7 christos {
441 1.14 kre ztest("%Z");
442 1.7 christos }
443 1.7 christos
444 1.1 pgoyette ATF_TP_ADD_TCS(tp)
445 1.1 pgoyette {
446 1.1 pgoyette
447 1.1 pgoyette ATF_TP_ADD_TC(tp, common);
448 1.1 pgoyette ATF_TP_ADD_TC(tp, day);
449 1.5 ginsbach ATF_TP_ADD_TC(tp, hour);
450 1.1 pgoyette ATF_TP_ADD_TC(tp, month);
451 1.3 ginsbach ATF_TP_ADD_TC(tp, seconds);
452 1.4 ginsbach ATF_TP_ADD_TC(tp, year);
453 1.7 christos ATF_TP_ADD_TC(tp, zone);
454 1.10 christos ATF_TP_ADD_TC(tp, Zone);
455 1.1 pgoyette
456 1.1 pgoyette return atf_no_error();
457 1.1 pgoyette }
458