• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2003, Intel Corporation. All rights reserved.
3  * Created by:  majid.awad REMOVE-THIS AT intel DOT com
4  * This file is licensed under the GPL license.  For the full content
5  * of this license, see the COPYING file at the top level of this
6  * source tree.
7  *
8  *
9  * This test case will cover all the conversion specifiers that are supported
10  * in strftime().
11  */
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <locale.h>
16 #include <langinfo.h>
17 #include <time.h>
18 #include "posixtest.h"
19 
main(void)20 int main(void)
21 {
22 
23 	/* current time */
24 	time_t t = time(NULL);
25 	struct tm *local_t = localtime(&t);
26 	char text[256];
27 	int result;
28 
29 	setlocale(LC_TIME, "C");
30 	strftime(text, sizeof(text), nl_langinfo(D_T_FMT), local_t);
31 	printf("STRING IS:   %s\n\n", text);
32 
33 	/* use format controls to print the various date/time components. */
34 
35 	result = strftime(text, sizeof(text), "%a", local_t);
36 	printf("a   Bytes %i           %s	", result, text);
37 	if (result != 3) {
38 		puts("Test Failed: \%a doesn't equal at least 3 bytes");
39 		return PTS_FAIL;
40 	} else {
41 		puts("PASS");
42 	}
43 
44 	result = strftime(text, sizeof(text), "%A", local_t);
45 	printf("A   Bytes %i           %s	", result, text);
46 	if (result <= 5) {
47 		puts("Test Failed: \%A doesn't equal to 6 bytes");
48 		return PTS_FAIL;
49 	} else {
50 		puts("PASS");
51 	}
52 
53 	result = strftime(text, sizeof(text), "%b", local_t);
54 	printf("b   Bytes %i           %s	", result, text);
55 	if (result != 3) {
56 		puts("Test Failed: \%b doesn't equal to 3 bytes");
57 		return PTS_FAIL;
58 	} else {
59 		puts("PASS");
60 	}
61 
62 	result = strftime(text, sizeof(text), "%B", local_t);
63 	printf("B   Bytes %i           %s	", result, text);
64 	if (result < 3) {
65 		puts("Test Failed: \%B is less than3 bytes");
66 		return PTS_FAIL;
67 	} else {
68 		puts("PASS");
69 	}
70 
71 /*  This section has been commented for known bug in gcc:
72  *
73  *  result = strftime(text, sizeof(text), "%c", local_t);
74  *  printf("c   Bytes %i          %s	", result, text);
75  *  if (result <= 30) {
76  *    puts("Test Failed: \%c doesn't equal at least 30 bytes");
77  *   } else {
78  *    puts ("PASS");
79  *   }
80  */
81 
82 	result = strftime(text, sizeof(text), "%C", local_t);
83 	printf("C   Bytes %i           %s	", result, text);
84 	if (result != 2) {
85 		puts("Test Failed: \%C doesn't equal at least 2 bytes");
86 		return PTS_FAIL;
87 	} else {
88 		puts("PASS");
89 	}
90 
91 	result = strftime(text, sizeof(text), "%d", local_t);
92 	printf("d   Bytes %i           %s	", result, text);
93 	if (result != 2) {
94 		puts("Test Failed: \%d doesn't equal at least 2 bytes");
95 		return PTS_FAIL;
96 	} else {
97 		puts("PASS");
98 	}
99 
100 /*  This section has been commented for known bug in gcc:
101  *
102  *  result = strftime(text, sizeof(text), "%D", local_t);
103  *  printf("D   Bytes %i           %s	", result, text);
104  *  if (result != 8) {
105  *    puts("Test Failed: \%D doesn't equal at least 2 bytes");
106  *    return PTS_FAIL;
107  *   } else {
108  *    puts ("PASS");
109  *   }
110  */
111 
112 	result = strftime(text, sizeof(text), "%e", local_t);
113 	printf("e   Bytes %i           %s	", result, text);
114 	if (result != 2) {
115 		puts("Test Failed: \%e doesn't equal at least 2 bytes");
116 		return PTS_FAIL;
117 	} else {
118 		puts("PASS");
119 	}
120 
121 	result = strftime(text, sizeof(text), "%F", local_t);
122 	printf("F   Bytes %i           %s	", result, text);
123 	if (result != 10) {
124 		puts("Test Failed: \%F doesn't equal at least 10 bytes");
125 		return PTS_FAIL;
126 	} else {
127 		puts("PASS");
128 	}
129 
130 	result = strftime(text, sizeof(text), "%H", local_t);
131 	printf("H   Bytes %i           %s	", result, text);
132 	if (result != 2) {
133 		puts("Test Failed: \%H doesn't equal at least 2 bytes");
134 		return PTS_FAIL;
135 	} else {
136 		puts("PASS");
137 	}
138 
139 /*  This section has been commented for known bug in gcc:
140  *
141  *   result = strftime(text, sizeof(text), "%g", local_t);
142  *   printf("g   Bytes %i           %s		", result, text);
143  *   if (result != 2) {
144 *	    puts("Test Failed: \%g doesn't equal at least 2 bytes");
145 *	    return PTS_FAIL;
146 *    } else {
147 *	    puts ("PASS");
148 *    }
149 */
150 
151 	result = strftime(text, sizeof(text), "%G", local_t);
152 	printf("G   Bytes %i           %s	", result, text);
153 	if (result != 4) {
154 		puts("Test Failed: \%G doesn't equal at least 4 bytes");
155 		return PTS_FAIL;
156 	} else {
157 		puts("PASS");
158 	}
159 
160 	result = strftime(text, sizeof(text), "%h", local_t);
161 	printf("h   Bytes %i           %s	", result, text);
162 	if (result != 3) {
163 		puts("Test Failed: \%h doesn't equal at least 3 bytes");
164 		return PTS_FAIL;
165 	} else {
166 		puts("PASS");
167 	}
168 
169 	result = strftime(text, sizeof(text), "%I", local_t);
170 	printf("I   Bytes %i           %s	", result, text);
171 	if (result != 2) {
172 		puts("Test Failed: \%I doesn't equal at least 2 bytes");
173 		return PTS_FAIL;
174 	} else {
175 		puts("PASS");
176 	}
177 
178 	result = strftime(text, sizeof(text), "%j", local_t);
179 	printf("j   Bytes %i           %s	", result, text);
180 	if (result != 3) {
181 		puts("Test Failed: \%j doesn't equal at least 3 bytes");
182 		return PTS_FAIL;
183 	} else {
184 		puts("PASS");
185 	}
186 
187 	result = strftime(text, sizeof(text), "%m", local_t);
188 	printf("m   Bytes %i           %s	", result, text);
189 	if (result != 2) {
190 		puts("Test Failed: \%m doesn't equal at least 2 bytes");
191 		return PTS_FAIL;
192 	} else {
193 		puts("PASS");
194 	}
195 
196 	result = strftime(text, sizeof(text), "%M", local_t);
197 	printf("M   Bytes %i           %s	", result, text);
198 	if (result != 2) {
199 		puts("Test Failed: \%M doesn't equal at least 2 bytes");
200 		return PTS_FAIL;
201 	} else {
202 		puts("PASS");
203 	}
204 
205 	result = strftime(text, sizeof(text), "%n", local_t);
206 	printf("n   Bytes %i           %s	", result, text);
207 	if (result != 1) {
208 		puts("Test Failed: \%n doesn't equal at least 1 bytes");
209 		return PTS_FAIL;
210 	} else {
211 		puts("PASS");
212 	}
213 
214 	result = strftime(text, sizeof(text), "%p", local_t);
215 	printf("p   Bytes %i           %s	", result, text);
216 	if (result != 2) {
217 		puts("Test Failed: \%p doesn't equal at least 2 bytes");
218 		return PTS_FAIL;
219 	} else {
220 		puts("PASS");
221 	}
222 
223 	result = strftime(text, sizeof(text), "%r", local_t);
224 	printf("r   Bytes %i           %s	", result, text);
225 	if (result != 11) {
226 		puts("Test Failed: \%r doesn't equal at least 11 bytes");
227 		return PTS_FAIL;
228 	} else {
229 		puts("PASS");
230 	}
231 
232 	result = strftime(text, sizeof(text), "%R", local_t);
233 	printf("R   Bytes %i           %s	", result, text);
234 	if (result != 5) {
235 		puts("Test Failed: \%R doesn't equal at least 5 bytes");
236 		return PTS_FAIL;
237 	} else {
238 		puts("PASS");
239 	}
240 
241 	result = strftime(text, sizeof(text), "%S", local_t);
242 	printf("S   Bytes %i           %s	", result, text);
243 	if (result != 2) {
244 		puts("Test Failed: \%S doesn't equal at least 2 bytes");
245 		return PTS_FAIL;
246 	} else {
247 		puts("PASS");
248 	}
249 
250 	result = strftime(text, sizeof(text), "%t", local_t);
251 	printf("t   Bytes %i           %s	", result, text);
252 	if (result != 1) {
253 		puts("Test Failed: \%t doesn't equal at least 1 bytes");
254 		return PTS_FAIL;
255 	} else {
256 		puts("PASS");
257 	}
258 
259 	result = strftime(text, sizeof(text), "%T", local_t);
260 	printf("T   Bytes %i           %s	", result, text);
261 	if (result != 8) {
262 		puts("Test Failed: \%T doesn't equal at least 8 bytes");
263 		return PTS_FAIL;
264 	} else {
265 		puts("PASS");
266 	}
267 
268 	result = strftime(text, sizeof(text), "%u", local_t);
269 	printf("u   Bytes %i           %s	", result, text);
270 	if (result != 1) {
271 		puts("Test Failed: \%u doesn't equal at least 1 bytes");
272 		return PTS_FAIL;
273 	} else {
274 		puts("PASS");
275 	}
276 
277 	result = strftime(text, sizeof(text), "%U", local_t);
278 	printf("U   Bytes %i           %s	", result, text);
279 	if (result != 2) {
280 		puts("Test Failed: \%U doesn't equal at least 2 bytes");
281 		return PTS_FAIL;
282 	} else {
283 		puts("PASS");
284 	}
285 
286 	result = strftime(text, sizeof(text), "%V", local_t);
287 	printf("V   Bytes %i           %s	", result, text);
288 	if (result != 2) {
289 		puts("Test Failed: \%V doesn't equal at least 2 bytes");
290 		return PTS_FAIL;
291 	} else {
292 		puts("PASS");
293 	}
294 
295 	result = strftime(text, sizeof(text), "%w", local_t);
296 	printf("w   Bytes %i           %s	", result, text);
297 	if (result != 1) {
298 		puts("Test Failed: \%w doesn't equal at least 1 bytes");
299 		return PTS_FAIL;
300 	} else {
301 		puts("PASS");
302 	}
303 
304 	result = strftime(text, sizeof(text), "%W", local_t);
305 	printf("W   Bytes %i           %s	", result, text);
306 	if (result != 2) {
307 		puts("Test Failed: \%W doesn't equal at least 2 bytes");
308 		return PTS_FAIL;
309 	} else {
310 		puts("PASS");
311 	}
312 
313 /*  This section has been commented for known bug in gcc:
314  *
315  *  result = strftime(text, sizeof(text), "%x", local_t);
316  *  printf("x   Bytes %i           %s	", result, text);
317  *  if (result != 10) {
318  *    puts("Test Failed: \%x doesn't equal at least 10 bytes");
319  *    return PTS_FAIL;
320  *   } else {
321  *    puts ("PASS");
322  *   }
323  */
324 
325 	result = strftime(text, sizeof(text), "%X", local_t);
326 	printf("X   Bytes %i           %s	", result, text);
327 	if (result < 8) {
328 		puts("Test Failed: \%X doesn't equal at least 8 bytes");
329 		return PTS_FAIL;
330 	} else {
331 		puts("PASS");
332 	}
333 
334 /*  This section has been commented for known bug in gcc:
335  *
336  *  result = strftime(text, sizeof(text), "%y", local_t);
337  *  printf("y   Bytes %i           %s	", result, text);
338  *  if (result != 2) {
339  *    puts("Test Failed: \%y doesn't equal at least 2 bytes");
340  *    return PTS_FAIL;
341  *   } else {
342  *    puts ("PASS");
343  *   }
344  */
345 
346 	result = strftime(text, sizeof(text), "%Y", local_t);
347 	printf("Y   Bytes %i           %s	", result, text);
348 	if (result != 4) {
349 		puts("Test Failed: \%Y doesn't equal at least 4 bytes");
350 		return PTS_FAIL;
351 	} else {
352 		puts("PASS");
353 	}
354 
355 	result = strftime(text, sizeof(text), "%z", local_t);
356 	printf("z   Bytes %i           %s	", result, text);
357 	if (result != 5) {
358 		puts("Test Failed: \%z doesn't equal at least 5 bytes");
359 		return PTS_FAIL;
360 	} else {
361 		puts("PASS");
362 	}
363 
364 	//result = strftime(text, sizeof(text), "%Z", local_t);
365 	//printf("Z   Bytes %i           %s   ", result, text);
366 	//if (result != 3) {
367 //          puts("Test Failed: \%Z doesn't equal at least 3 bytes");
368 	//             return PTS_FAIL;
369 	//   } else {
370 //                  puts ("PASS");
371 	//    }
372 	printf("\n");
373 
374 	return PTS_PASS;
375 }
376