• 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  * Modified by the E or O indicate that an alternative format or
10  * specification should be used rather than the one normally used by the
11  * unmodified conversion specifier (1-1.c).
12  */
13 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <locale.h>
17 #include <langinfo.h>
18 #include <time.h>
19 #include "posixtest.h"
20 
main(void)21 int main(void)
22 {
23 
24 	/* current time */
25 	time_t t = time(NULL);
26 	struct tm *local_t = localtime(&t);
27 	char text[256];
28 	int result;
29 
30 	setlocale(LC_TIME, "");
31 	strftime(text, sizeof(text), nl_langinfo(D_T_FMT), local_t);
32 	printf("STRING IS:   %s\n\n", text);
33 
34 /* use format controls to print the various date/time components. */
35 
36 /*  This section has been commented for known bug in gcc:
37  *  result = strftime(text, sizeof(text), "%Ec", local_t);
38  *  printf("Ec   Bytes %i           %s	", result, text);
39  *  if (result != 31) {
40  *    puts("Test Failed: \%Ec doesn't equal at least 31 bytes");
41  *    return PTS_FAIL;
42  *   } else {
43  *    puts("PASS");
44  *   }
45  */
46 
47 	result = strftime(text, sizeof(text), "%EC", local_t);
48 	printf("EC   Bytes %i           %s	", result, text);
49 	if (result != 2) {
50 		puts("Test Failed: \%EC doesn't equal to 2 bytes");
51 		return PTS_FAIL;
52 	} else {
53 		puts("PASS");
54 	}
55 
56 /*  This section has been commented for known bug in gcc:
57  *  result = strftime(text, sizeof(text) , "%Ex", local_t);
58  *  printf("Ex   Bytes %i           %s	", result, text);
59  *  if (result != 10) {
60  *    puts("Test Failed: \%Ex doesn't equal to 10 bytes");
61  *    return PTS_FAIL;
62  *   } else {
63  *    puts ("PASS");
64  *   }
65  */
66 
67 	result = strftime(text, sizeof(text), "%EX", local_t);
68 	printf("EX   Bytes %i           %s	", result, text);
69 	if (result <= 3) {
70 		puts("Test Failed: \%EX doesn't equal to 3 bytes");
71 		return PTS_FAIL;
72 	} else {
73 		puts("PASS");
74 	}
75 
76 /*  This section has been commented for known bug in gcc:
77  *  result = strftime(text, sizeof(text), "%Ey", local_t);
78  *  printf("Ey   Bytes %i           %s	", result, text);
79  *  if (result != 2) {
80  *    puts("Test Failed: \%Ey doesn't equal at least 2 bytes");
81  *    return PTS_FAIL;
82  *   } else {
83  *    puts ("PASS");
84  *   }
85  */
86 
87 	result = strftime(text, sizeof(text), "%EY", local_t);
88 	printf("EY   Bytes %i           %s	", result, text);
89 	if (result != 4) {
90 		puts("Test Failed: \%EY doesn't equal at least 4 bytes");
91 		return PTS_FAIL;
92 	} else {
93 		puts("PASS");
94 	}
95 
96 	result = strftime(text, sizeof(text), "%Od", local_t);
97 	printf("Od   Bytes %i           %s	", result, text);
98 	if (result != 2) {
99 		puts("Test Failed: \%Od doesn't equal at least 2 bytes");
100 		return PTS_FAIL;
101 	} else {
102 		puts("PASS");
103 	}
104 
105 	result = strftime(text, sizeof(text), "%Oe", local_t);
106 	printf("Oe   Bytes %i           %s	", result, text);
107 	if (result != 2) {
108 		puts("Test Failed: \%Oe doesn't equal at least 2 bytes");
109 		return PTS_FAIL;
110 	} else {
111 		puts("PASS");
112 	}
113 
114 	result = strftime(text, sizeof(text), "%OH", local_t);
115 	printf("OH   Bytes %i           %s	", result, text);
116 	if (result != 2) {
117 		puts("Test Failed: \%OH doesn't equal at least 2 bytes");
118 		return PTS_FAIL;
119 	} else {
120 		puts("PASS");
121 	}
122 
123 	result = strftime(text, sizeof(text), "%OI", local_t);
124 	printf("OI   Bytes %i           %s	", result, text);
125 	if (result != 2) {
126 		puts("Test Failed: \%OI doesn't equal at least 2 bytes");
127 		return PTS_FAIL;
128 	} else {
129 		puts("PASS");
130 	}
131 
132 	result = strftime(text, sizeof(text), "%Om", local_t);
133 	printf("Om   Bytes %i           %s	", result, text);
134 	if (result != 2) {
135 		puts("Test Failed: \%Om doesn't equal at least 2 bytes");
136 		return PTS_FAIL;
137 	} else {
138 		puts("PASS");
139 	}
140 
141 	result = strftime(text, sizeof(text), "%OM", local_t);
142 	printf("OM   Bytes %i           %s	", result, text);
143 	if (result != 2) {
144 		puts("Test Failed: \%OM doesn't equal at least 2 bytes");
145 		return PTS_FAIL;
146 	} else {
147 		puts("PASS");
148 	}
149 
150 	result = strftime(text, sizeof(text), "%OS", local_t);
151 	printf("OS   Bytes %i           %s	", result, text);
152 	if (result != 2) {
153 		puts("Test Failed: \%OS doesn't equal at least 2 bytes");
154 		return PTS_FAIL;
155 	} else {
156 		puts("PASS");
157 	}
158 
159 	result = strftime(text, sizeof(text), "%Ou", local_t);
160 	printf("Ou   Bytes %i           %s	", result, text);
161 	if (result != 1) {
162 		puts("Test Failed: \%Ou doesn't equal at least 1 bytes");
163 		return PTS_FAIL;
164 	} else {
165 		puts("PASS");
166 	}
167 
168 	result = strftime(text, sizeof(text), "%OU", local_t);
169 	printf("OU   Bytes %i           %s	", result, text);
170 	if (result != 2) {
171 		puts("Test Failed: \%OU doesn't equal at least 2 bytes");
172 		return PTS_FAIL;
173 	} else {
174 		puts("PASS");
175 	}
176 
177 	result = strftime(text, sizeof(text), "%OV", local_t);
178 	printf("OV   Bytes %i           %s	", result, text);
179 	if (result != 2) {
180 		puts("Test Failed: \%OV doesn't equal at least 2 bytes");
181 		return PTS_FAIL;
182 	} else {
183 		puts("PASS");
184 	}
185 
186 	result = strftime(text, sizeof(text), "%Ow", local_t);
187 	printf("Ow   Bytes %i           %s	", result, text);
188 	if (result != 1) {
189 		puts("Test Failed: \%Ow doesn't equal at least 1 bytes");
190 		return PTS_FAIL;
191 	} else {
192 		puts("PASS");
193 	}
194 
195 	result = strftime(text, sizeof(text), "%OW", local_t);
196 	printf("OW   Bytes %i           %s	", result, text);
197 	if (result != 2) {
198 		puts("Test Failed: \%OW doesn't equal at least 2 bytes");
199 		return PTS_FAIL;
200 	} else {
201 		puts("PASS");
202 	}
203 
204 /*  This section has been commented for known bug in gcc:
205  *  result = strftime(text, sizeof(text), "%Oy", local_t);
206  *  printf("Oy   Bytes %i           %s	", result, text);
207  *  if (result != 2) {
208  *    puts("Test Failed: \%Oy doesn't equal at least 2 bytes");
209  *    return PTS_FAIL;
210  *   } else {
211  *    puts ("PASS");
212  *   }
213  */
214 
215 	printf("\n");
216 
217 	return PTS_PASS;
218 }
219