Pre-2.0 release, MFC firewire disk changes to properly detach SIMs.
[dragonfly.git] / crypto / heimdal-0.6.3 / lib / roken / strpftime-test.c
blob7eb8fb85eb2a63fc8db9193cbbe2270dcf7d7b86
1 /*
2 * Copyright (c) 1999 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of KTH nor the names of its contributors may be
18 * used to endorse or promote products derived from this software without
19 * specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
36 #include "roken.h"
38 RCSID("$Id: strpftime-test.c,v 1.2 1999/11/12 15:29:55 assar Exp $");
40 enum { MAXSIZE = 26 };
42 static struct testcase {
43 time_t t;
44 struct {
45 const char *format;
46 const char *result;
47 } vals[MAXSIZE];
48 } tests[] = {
49 {0,
51 {"%A", "Thursday"},
52 {"%a", "Thu"},
53 {"%B", "January"},
54 {"%b", "Jan"},
55 {"%C", "19"},
56 {"%d", "01"},
57 {"%e", " 1"},
58 {"%H", "00"},
59 {"%I", "12"},
60 {"%j", "001"},
61 {"%k", " 0"},
62 {"%l", "12"},
63 {"%M", "00"},
64 {"%m", "01"},
65 {"%n", "\n"},
66 {"%p", "AM"},
67 {"%S", "00"},
68 {"%t", "\t"},
69 {"%w", "4"},
70 {"%Y", "1970"},
71 {"%y", "70"},
72 {"%U", "00"},
73 {"%W", "00"},
74 {"%V", "01"},
75 {"%%", "%"},
76 {NULL, NULL}}
78 {90000,
80 {"%A", "Friday"},
81 {"%a", "Fri"},
82 {"%B", "January"},
83 {"%b", "Jan"},
84 {"%C", "19"},
85 {"%d", "02"},
86 {"%e", " 2"},
87 {"%H", "01"},
88 {"%I", "01"},
89 {"%j", "002"},
90 {"%k", " 1"},
91 {"%l", " 1"},
92 {"%M", "00"},
93 {"%m", "01"},
94 {"%n", "\n"},
95 {"%p", "AM"},
96 {"%S", "00"},
97 {"%t", "\t"},
98 {"%w", "5"},
99 {"%Y", "1970"},
100 {"%y", "70"},
101 {"%U", "00"},
102 {"%W", "00"},
103 {"%V", "01"},
104 {"%%", "%"},
105 {NULL, NULL}
108 {216306,
110 {"%A", "Saturday"},
111 {"%a", "Sat"},
112 {"%B", "January"},
113 {"%b", "Jan"},
114 {"%C", "19"},
115 {"%d", "03"},
116 {"%e", " 3"},
117 {"%H", "12"},
118 {"%I", "12"},
119 {"%j", "003"},
120 {"%k", "12"},
121 {"%l", "12"},
122 {"%M", "05"},
123 {"%m", "01"},
124 {"%n", "\n"},
125 {"%p", "PM"},
126 {"%S", "06"},
127 {"%t", "\t"},
128 {"%w", "6"},
129 {"%Y", "1970"},
130 {"%y", "70"},
131 {"%U", "00"},
132 {"%W", "00"},
133 {"%V", "01"},
134 {"%%", "%"},
135 {NULL, NULL}
138 {259200,
140 {"%A", "Sunday"},
141 {"%a", "Sun"},
142 {"%B", "January"},
143 {"%b", "Jan"},
144 {"%C", "19"},
145 {"%d", "04"},
146 {"%e", " 4"},
147 {"%H", "00"},
148 {"%I", "12"},
149 {"%j", "004"},
150 {"%k", " 0"},
151 {"%l", "12"},
152 {"%M", "00"},
153 {"%m", "01"},
154 {"%n", "\n"},
155 {"%p", "AM"},
156 {"%S", "00"},
157 {"%t", "\t"},
158 {"%w", "0"},
159 {"%Y", "1970"},
160 {"%y", "70"},
161 {"%U", "01"},
162 {"%W", "00"},
163 {"%V", "01"},
164 {"%%", "%"},
165 {NULL, NULL}
168 {915148800,
170 {"%A", "Friday"},
171 {"%a", "Fri"},
172 {"%B", "January"},
173 {"%b", "Jan"},
174 {"%C", "19"},
175 {"%d", "01"},
176 {"%e", " 1"},
177 {"%H", "00"},
178 {"%I", "12"},
179 {"%j", "001"},
180 {"%k", " 0"},
181 {"%l", "12"},
182 {"%M", "00"},
183 {"%m", "01"},
184 {"%n", "\n"},
185 {"%p", "AM"},
186 {"%S", "00"},
187 {"%t", "\t"},
188 {"%w", "5"},
189 {"%Y", "1999"},
190 {"%y", "99"},
191 {"%U", "00"},
192 {"%W", "00"},
193 {"%V", "53"},
194 {"%%", "%"},
195 {NULL, NULL}}
197 {942161105,
200 {"%A", "Tuesday"},
201 {"%a", "Tue"},
202 {"%B", "November"},
203 {"%b", "Nov"},
204 {"%C", "19"},
205 {"%d", "09"},
206 {"%e", " 9"},
207 {"%H", "15"},
208 {"%I", "03"},
209 {"%j", "313"},
210 {"%k", "15"},
211 {"%l", " 3"},
212 {"%M", "25"},
213 {"%m", "11"},
214 {"%n", "\n"},
215 {"%p", "PM"},
216 {"%S", "05"},
217 {"%t", "\t"},
218 {"%w", "2"},
219 {"%Y", "1999"},
220 {"%y", "99"},
221 {"%U", "45"},
222 {"%W", "45"},
223 {"%V", "45"},
224 {"%%", "%"},
225 {NULL, NULL}
231 main(int argc, char **argv)
233 int i, j;
234 int ret = 0;
236 for (i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) {
237 struct tm *tm;
239 tm = gmtime (&tests[i].t);
241 for (j = 0; tests[i].vals[j].format != NULL; ++j) {
242 char buf[128];
243 size_t len;
244 struct tm tm2;
245 char *ptr;
247 len = strftime (buf, sizeof(buf), tests[i].vals[j].format, tm);
248 if (len != strlen (buf)) {
249 printf ("length of strftime(\"%s\") = %d (\"%s\")\n",
250 tests[i].vals[j].format, len,
251 buf);
252 ++ret;
253 continue;
255 if (strcmp (buf, tests[i].vals[j].result) != 0) {
256 printf ("result of strftime(\"%s\") = \"%s\" != \"%s\"\n",
257 tests[i].vals[j].format, buf,
258 tests[i].vals[j].result);
259 ++ret;
260 continue;
262 memset (&tm2, 0, sizeof(tm2));
263 ptr = strptime (tests[i].vals[j].result,
264 tests[i].vals[j].format,
265 &tm2);
266 if (ptr == NULL || *ptr != '\0') {
267 printf ("bad return value from strptime("
268 "\"%s\", \"%s\")\n",
269 tests[i].vals[j].result,
270 tests[i].vals[j].format);
271 ++ret;
273 strftime (buf, sizeof(buf), tests[i].vals[j].format, &tm2);
274 if (strcmp (buf, tests[i].vals[j].result) != 0) {
275 printf ("reverse of \"%s\" failed: \"%s\" vs \"%s\"\n",
276 tests[i].vals[j].format,
277 buf, tests[i].vals[j].result);
278 ++ret;
282 if (ret) {
283 printf ("%d errors\n", ret);
284 return 1;
285 } else
286 return 0;