9 /* Flag to #ifdef the tests out that crash the old implementation */
10 /*#define NOCRASH 1 */
14 /*****************************************************************************/
16 /*****************************************************************************/
20 /* Struct used to test the 'n' conversion specifier. It is machine dependent /
23 typedef union WriteCount WriteCount;
30 /* Count the number of tests and the number of failures */
31 static unsigned Tests = 0;
32 static unsigned Failures = 0;
36 /*****************************************************************************/
38 /*****************************************************************************/
42 static void OneTest (int Line, const char* RString, int RCount, const char* Format, ...)
43 /* Test one conversion. Line is the line number (to make the life of the
44 ** tester easier), RString the expected result and RCount the expected return
45 ** count. The other parameters are used for formatting.
52 /* Count the number of tests */
55 /* Format the string using the given arguments */
56 va_start (ap, Format);
57 Count = vsprintf (Buf, Format, ap);
60 /* Check the result */
61 if (Count != RCount || strcmp (Buf, RString) != 0) {
63 printf ("%3d: \"%s\" (%d)\n"
65 Line, Buf, Count, RString, RCount);
71 static void WriteTest (int Line, const char* Format, WriteCount* W, long Count)
72 /* Test one write conversion. Line is the line number (to make the life of the
73 ** tester easier), Format is the format specification. W is a WriteCount
74 ** variable and Count is the expected result.
77 /* Clear the counter in full length */
80 /* Format the string using the given arguments */
81 OneTest (Line, "4200", 4, Format, 4200, W);
83 /* Check the counter */
86 printf ("%3d: n = 0x%08lX\n"
99 /* The one and only starter to begin with ... */
100 OneTest (__LINE__, "hello, world", 12, "hello, world");
102 /* Duplicate percent signs are used to output single ones */
103 OneTest (__LINE__, "hello % %", 9, "hello %% %%");
105 /* Simple conversions */
106 OneTest (__LINE__, "u", 1, "%c", 'u');
107 OneTest (__LINE__, "4200", 4, "%d", 4200);
108 OneTest (__LINE__, "-4200", 5, "%d", -4200);
109 OneTest (__LINE__, "4200", 4, "%i", 4200);
110 OneTest (__LINE__, "-4200", 5, "%i", -4200);
111 OneTest (__LINE__, "10150", 5, "%o", 4200U);
112 OneTest (__LINE__, "167630", 6, "%o", -4200U);
113 OneTest (__LINE__, "hello, world", 12, "hello, %s", "world");
114 OneTest (__LINE__, "4200", 4, "%u", 4200U);
115 OneTest (__LINE__, "61336", 5, "%u", -4200U);
116 OneTest (__LINE__, "1068", 4, "%x", 4200U);
117 OneTest (__LINE__, "ef98", 4, "%x", -4200U);
118 OneTest (__LINE__, "1068", 4, "%X", 4200U);
119 OneTest (__LINE__, "EF98", 4, "%X", -4200U);
121 /* Simple conversions with special values */
122 OneTest (__LINE__, "\0", 1, "%c", '\0');
123 OneTest (__LINE__, "0", 1, "%d", 0);
124 OneTest (__LINE__, "0", 1, "%o", 0U);
125 OneTest (__LINE__, "hello, ", 7, "hello, %s", "");
126 OneTest (__LINE__, "0", 1, "%u", 0U);
127 OneTest (__LINE__, "0", 1, "%x", 0U);
130 OneTest (__LINE__, "4200", 4, "%hd", 4200);
131 OneTest (__LINE__, "-4200", 5, "%hd", -4200);
132 OneTest (__LINE__, "4200", 4, "%hi", 4200);
133 OneTest (__LINE__, "-4200", 5, "%hi", -4200);
134 OneTest (__LINE__, "10150", 5, "%ho", 4200U);
135 OneTest (__LINE__, "167630", 6, "%ho", -4200U);
136 OneTest (__LINE__, "4200", 4, "%hu", 4200U);
137 OneTest (__LINE__, "61336", 5, "%hu", -4200U);
138 OneTest (__LINE__, "1068", 4, "%hx", 4200U);
139 OneTest (__LINE__, "ef98", 4, "%hx", -4200U);
140 OneTest (__LINE__, "1068", 4, "%hX", 4200U);
141 OneTest (__LINE__, "EF98", 4, "%hX", -4200U);
144 OneTest (__LINE__, "104", 3, "%hhd", 4200);
145 OneTest (__LINE__, "-104", 4, "%hhd", -4200);
146 OneTest (__LINE__, "104", 3, "%hhi", 4200);
147 OneTest (__LINE__, "-104", 4, "%hhi", -4200);
148 OneTest (__LINE__, "150", 3, "%hho", 4200U);
149 OneTest (__LINE__, "230", 3, "%hho", -4200U);
150 OneTest (__LINE__, "104", 3, "%hhu", 4200U);
151 OneTest (__LINE__, "152", 3, "%hhu", -4200U);
152 OneTest (__LINE__, "68", 2, "%hhx", 4200U);
153 OneTest (__LINE__, "98", 2, "%hhx", -4200U);
154 OneTest (__LINE__, "68", 2, "%hhX", 4200U);
155 OneTest (__LINE__, "98", 2, "%hhX", -4200U);
158 OneTest (__LINE__, "4200123", 7, "%jd", 4200123L);
159 OneTest (__LINE__, "-4200123", 8, "%jd", -4200123L);
160 OneTest (__LINE__, "4200123", 7, "%ji", 4200123L);
161 OneTest (__LINE__, "-4200123", 8, "%ji", -4200123L);
162 OneTest (__LINE__, "20013273", 8, "%jo", 4200123UL);
163 OneTest (__LINE__, "37757764505", 11, "%jo", -4200123UL);
164 OneTest (__LINE__, "4200123", 7, "%ju", 4200123UL);
165 OneTest (__LINE__, "4290767173", 10, "%ju", -4200123UL);
166 OneTest (__LINE__, "4016bb", 6, "%jx", 4200123UL);
167 OneTest (__LINE__, "ffbfe945", 8, "%jx", -4200123UL);
168 OneTest (__LINE__, "4016BB", 6, "%jX", 4200123UL);
169 OneTest (__LINE__, "FFBFE945", 8, "%jX", -4200123UL);
172 OneTest (__LINE__, "4200123", 7, "%ld", 4200123L);
173 OneTest (__LINE__, "-4200123", 8, "%ld", -4200123L);
174 OneTest (__LINE__, "4200123", 7, "%li", 4200123L);
175 OneTest (__LINE__, "-4200123", 8, "%li", -4200123L);
176 OneTest (__LINE__, "20013273", 8, "%lo", 4200123UL);
177 OneTest (__LINE__, "37757764505", 11, "%lo", -4200123UL);
178 OneTest (__LINE__, "4200123", 7, "%lu", 4200123UL);
179 OneTest (__LINE__, "4290767173", 10, "%lu", -4200123UL);
180 OneTest (__LINE__, "4016bb", 6, "%lx", 4200123UL);
181 OneTest (__LINE__, "ffbfe945", 8, "%lx", -4200123UL);
182 OneTest (__LINE__, "4016BB", 6, "%lX", 4200123UL);
183 OneTest (__LINE__, "FFBFE945", 8, "%lX", -4200123UL);
186 OneTest (__LINE__, "4200", 4, "%td", 4200);
187 OneTest (__LINE__, "-4200", 5, "%td", -4200);
188 OneTest (__LINE__, "4200", 4, "%ti", 4200);
189 OneTest (__LINE__, "-4200", 5, "%ti", -4200);
190 OneTest (__LINE__, "10150", 5, "%to", 4200U);
191 OneTest (__LINE__, "167630", 6, "%to", -4200U);
192 OneTest (__LINE__, "4200", 4, "%tu", 4200U);
193 OneTest (__LINE__, "61336", 5, "%tu", -4200U);
194 OneTest (__LINE__, "1068", 4, "%tx", 4200U);
195 OneTest (__LINE__, "ef98", 4, "%tx", -4200U);
196 OneTest (__LINE__, "1068", 4, "%tX", 4200U);
197 OneTest (__LINE__, "EF98", 4, "%tX", -4200U);
200 OneTest (__LINE__, "4200", 4, "%zd", 4200);
201 OneTest (__LINE__, "-4200", 5, "%zd", -4200);
202 OneTest (__LINE__, "4200", 4, "%zi", 4200);
203 OneTest (__LINE__, "-4200", 5, "%zi", -4200);
204 OneTest (__LINE__, "10150", 5, "%zo", 4200U);
205 OneTest (__LINE__, "167630", 6, "%zo", -4200U);
206 OneTest (__LINE__, "4200", 4, "%zu", 4200U);
207 OneTest (__LINE__, "61336", 5, "%zu", -4200U);
208 OneTest (__LINE__, "1068", 4, "%zx", 4200U);
209 OneTest (__LINE__, "ef98", 4, "%zx", -4200U);
210 OneTest (__LINE__, "1068", 4, "%zX", 4200U);
211 OneTest (__LINE__, "EF98", 4, "%zX", -4200U);
213 /* '+' forces a sign for signed conversions */
214 OneTest (__LINE__, "u", 1, "%+c", 'u');
215 OneTest (__LINE__, "+4200", 5, "%+d", 4200);
216 OneTest (__LINE__, "-4200", 5, "%+d", -4200);
217 OneTest (__LINE__, "+4200", 5, "%+i", 4200);
218 OneTest (__LINE__, "-4200", 5, "%+i", -4200);
219 OneTest (__LINE__, "10150", 5, "%+o", 4200U);
220 OneTest (__LINE__, "167630", 6, "%+o", -4200U);
221 OneTest (__LINE__, "hello, world", 12, "%+s", "hello, world");
222 OneTest (__LINE__, "4200", 4, "%+u", 4200U);
223 OneTest (__LINE__, "61336", 5, "%+u", -4200U);
224 OneTest (__LINE__, "1068", 4, "%+x", 4200U);
225 OneTest (__LINE__, "ef98", 4, "%+x", -4200U);
226 OneTest (__LINE__, "1068", 4, "%+X", 4200U);
227 OneTest (__LINE__, "EF98", 4, "%+X", -4200U);
229 /* ' ': If the first character of a signed conversion is not a sign, or if
230 ** a signed conversion results in no characters, a space is prefixed
233 OneTest (__LINE__, "u", 1, "% c", 'u');
234 OneTest (__LINE__, " 4200", 5, "% d", 4200);
235 OneTest (__LINE__, "-4200", 5, "% d", -4200);
236 OneTest (__LINE__, " 4200", 5, "% i", 4200);
237 OneTest (__LINE__, "-4200", 5, "% i", -4200);
238 OneTest (__LINE__, "10150", 5, "% o", 4200U);
239 OneTest (__LINE__, "167630", 6, "% o", -4200U);
240 OneTest (__LINE__, "hello, world", 12, "% s", "hello, world");
241 OneTest (__LINE__, "4200", 4, "% u", 4200U);
242 OneTest (__LINE__, "61336", 5, "% u", -4200U);
243 OneTest (__LINE__, "1068", 4, "% x", 4200U);
244 OneTest (__LINE__, "ef98", 4, "% x", -4200U);
245 OneTest (__LINE__, "1068", 4, "% X", 4200U);
246 OneTest (__LINE__, "EF98", 4, "% X", -4200U);
248 /* If the ' ' and '+' flags both appear, the ' ' flag is ignored */
249 OneTest (__LINE__, "u", 1, "% +c", 'u');
250 OneTest (__LINE__, "+4200", 5, "% +d", 4200);
251 OneTest (__LINE__, "-4200", 5, "% +d", -4200);
252 OneTest (__LINE__, "+4200", 5, "% +i", 4200);
253 OneTest (__LINE__, "-4200", 5, "% +i", -4200);
254 OneTest (__LINE__, "10150", 5, "% +o", 4200U);
255 OneTest (__LINE__, "167630", 6, "% +o", -4200U);
256 OneTest (__LINE__, "hello, world", 12, "% +s", "hello, world");
257 OneTest (__LINE__, "4200", 4, "% +u", 4200U);
258 OneTest (__LINE__, "61336", 5, "% +u", -4200U);
259 OneTest (__LINE__, "1068", 4, "% +x", 4200U);
260 OneTest (__LINE__, "ef98", 4, "% +x", -4200U);
261 OneTest (__LINE__, "1068", 4, "% +X", 4200U);
262 OneTest (__LINE__, "EF98", 4, "% +X", -4200U);
264 /* Field width given */
265 OneTest (__LINE__, " u", 15, "%15c", 'u');
266 OneTest (__LINE__, " 4200", 15, "%15d", 4200);
267 OneTest (__LINE__, " -4200", 15, "%15d", -4200);
268 OneTest (__LINE__, " 4200", 15, "%15i", 4200);
269 OneTest (__LINE__, " -4200", 15, "%15i", -4200);
270 OneTest (__LINE__, " 10150", 15, "%15o", 4200U);
271 OneTest (__LINE__, " 167630", 15, "%15o", -4200U);
272 OneTest (__LINE__, " hello, world", 15, "%15s", "hello, world");
273 OneTest (__LINE__, " 4200", 15, "%15u", 4200U);
274 OneTest (__LINE__, " 61336", 15, "%15u", -4200U);
275 OneTest (__LINE__, " 1068", 15, "%15x", 4200U);
276 OneTest (__LINE__, " ef98", 15, "%15x", -4200U);
277 OneTest (__LINE__, " 1068", 15, "%15X", 4200U);
278 OneTest (__LINE__, " EF98", 15, "%15X", -4200U);
280 /* Field width given as separate argument */
281 OneTest (__LINE__, " u", 15, "%*c", 15, 'u');
282 OneTest (__LINE__, " 4200", 15, "%*d", 15, 4200);
283 OneTest (__LINE__, " -4200", 15, "%*d", 15, -4200);
284 OneTest (__LINE__, " 4200", 15, "%*i", 15, 4200);
285 OneTest (__LINE__, " -4200", 15, "%*i", 15, -4200);
286 OneTest (__LINE__, " 10150", 15, "%*o", 15, 4200U);
287 OneTest (__LINE__, " 167630", 15, "%*o", 15, -4200U);
288 OneTest (__LINE__, " hello, world", 15, "%*s", 15, "hello, world");
289 OneTest (__LINE__, " 4200", 15, "%*u", 15, 4200U);
290 OneTest (__LINE__, " 61336", 15, "%*u", 15, -4200U);
291 OneTest (__LINE__, " 1068", 15, "%*x", 15, 4200U);
292 OneTest (__LINE__, " ef98", 15, "%*x", 15, -4200U);
293 OneTest (__LINE__, " 1068", 15, "%*X", 15, 4200U);
294 OneTest (__LINE__, " EF98", 15, "%*X", 15, -4200U);
296 /* Field width and '-' flag given */
297 OneTest (__LINE__, "u ", 15, "%-15c", 'u');
298 OneTest (__LINE__, "4200 ", 15, "%-15d", 4200);
299 OneTest (__LINE__, "-4200 ", 15, "%-15d", -4200);
300 OneTest (__LINE__, "4200 ", 15, "%-15i", 4200);
301 OneTest (__LINE__, "-4200 ", 15, "%-15i", -4200);
302 OneTest (__LINE__, "10150 ", 15, "%-15o", 4200U);
303 OneTest (__LINE__, "167630 ", 15, "%-15o", -4200U);
304 OneTest (__LINE__, "hello, world ", 15, "%-15s", "hello, world");
305 OneTest (__LINE__, "4200 ", 15, "%-15u", 4200U);
306 OneTest (__LINE__, "61336 ", 15, "%-15u", -4200U);
307 OneTest (__LINE__, "1068 ", 15, "%-15x", 4200U);
308 OneTest (__LINE__, "ef98 ", 15, "%-15x", -4200U);
309 OneTest (__LINE__, "1068 ", 15, "%-15X", 4200U);
310 OneTest (__LINE__, "EF98 ", 15, "%-15X", -4200U);
312 /* A negative field width specified via an argument is treated as if the
313 ** '-' flag and a positive field width were given.
315 ** Beware: These tests will crash the old printf routine!
318 OneTest (__LINE__, "u ", 15, "%*c", -15, 'u');
319 OneTest (__LINE__, "4200 ", 15, "%*d", -15, 4200);
320 OneTest (__LINE__, "-4200 ", 15, "%*d", -15, -4200);
321 OneTest (__LINE__, "4200 ", 15, "%*i", -15, 4200);
322 OneTest (__LINE__, "-4200 ", 15, "%*i", -15, -4200);
323 OneTest (__LINE__, "10150 ", 15, "%*o", -15, 4200U);
324 OneTest (__LINE__, "167630 ", 15, "%*o", -15, -4200U);
325 OneTest (__LINE__, "hello, world ", 15, "%*s", -15, "hello, world");
326 OneTest (__LINE__, "4200 ", 15, "%*u", -15, 4200U);
327 OneTest (__LINE__, "61336 ", 15, "%*u", -15, -4200U);
328 OneTest (__LINE__, "1068 ", 15, "%*x", -15, 4200U);
329 OneTest (__LINE__, "ef98 ", 15, "%*x", -15, -4200U);
330 OneTest (__LINE__, "1068 ", 15, "%*X", -15, 4200U);
331 OneTest (__LINE__, "EF98 ", 15, "%*X", -15, -4200U);
334 /* Field width smaller than converted value */
335 OneTest (__LINE__, "u", 1, "%1c", 'u');
336 OneTest (__LINE__, "4200", 4, "%1d", 4200);
337 OneTest (__LINE__, "-4200", 5, "%1d", -4200);
338 OneTest (__LINE__, "4200", 4, "%1i", 4200);
339 OneTest (__LINE__, "-4200", 5, "%1i", -4200);
340 OneTest (__LINE__, "10150", 5, "%1o", 4200U);
341 OneTest (__LINE__, "167630", 6, "%1o", -4200U);
342 OneTest (__LINE__, "hello, world", 12, "%1s", "hello, world");
343 OneTest (__LINE__, "4200", 4, "%1u", 4200U);
344 OneTest (__LINE__, "61336", 5, "%1u", -4200U);
345 OneTest (__LINE__, "1068", 4, "%1x", 4200U);
346 OneTest (__LINE__, "ef98", 4, "%1x", -4200U);
347 OneTest (__LINE__, "1068", 4, "%1X", 4200U);
348 OneTest (__LINE__, "EF98", 4, "%1X", -4200U);
350 /* Field width specified and '0' flag given */
351 OneTest (__LINE__, "000000000004200", 15, "%015d", 4200);
352 OneTest (__LINE__, "-00000000004200", 15, "%015d", -4200);
353 OneTest (__LINE__, "000000000004200", 15, "%015i", 4200);
354 OneTest (__LINE__, "-00000000004200", 15, "%015i", -4200);
355 OneTest (__LINE__, "000000000010150", 15, "%015o", 4200U);
356 OneTest (__LINE__, "000000000167630", 15, "%015o", -4200U);
357 OneTest (__LINE__, "000000000004200", 15, "%015u", 4200U);
358 OneTest (__LINE__, "000000000061336", 15, "%015u", -4200U);
359 OneTest (__LINE__, "000000000001068", 15, "%015x", 4200U);
360 OneTest (__LINE__, "00000000000ef98", 15, "%015x", -4200U);
361 OneTest (__LINE__, "000000000001068", 15, "%015X", 4200U);
362 OneTest (__LINE__, "00000000000EF98", 15, "%015X", -4200U);
364 /* If the '-' and '0' flags are both specified, '0' is ignored */
365 OneTest (__LINE__, "4200 ", 15, "%-015d", 4200);
366 OneTest (__LINE__, "-4200 ", 15, "%-015d", -4200);
367 OneTest (__LINE__, "4200 ", 15, "%-015i", 4200);
368 OneTest (__LINE__, "-4200 ", 15, "%-015i", -4200);
369 OneTest (__LINE__, "10150 ", 15, "%-015o", 4200U);
370 OneTest (__LINE__, "167630 ", 15, "%-015o", -4200U);
371 OneTest (__LINE__, "4200 ", 15, "%-015u", 4200U);
372 OneTest (__LINE__, "61336 ", 15, "%-015u", -4200U);
373 OneTest (__LINE__, "1068 ", 15, "%-015x", 4200U);
374 OneTest (__LINE__, "ef98 ", 15, "%-015x", -4200U);
375 OneTest (__LINE__, "1068 ", 15, "%-015X", 4200U);
376 OneTest (__LINE__, "EF98 ", 15, "%-015X", -4200U);
378 /* Precision given */
379 OneTest (__LINE__, "u", 1, "%.15c", 'u');
380 OneTest (__LINE__, "000000000004200", 15, "%.15d", 4200);
381 OneTest (__LINE__, "-000000000004200", 16, "%.15d", -4200);
382 OneTest (__LINE__, "000000000004200", 15, "%.15i", 4200);
383 OneTest (__LINE__, "-000000000004200", 16, "%.15i", -4200);
384 OneTest (__LINE__, "000000000010150", 15, "%.15o", 4200U);
385 OneTest (__LINE__, "000000000167630", 15, "%.15o", -4200U);
386 OneTest (__LINE__, "hello, world", 12, "%.15s", "hello, world");
387 OneTest (__LINE__, "000000000004200", 15, "%.15u", 4200U);
388 OneTest (__LINE__, "000000000061336", 15, "%.15u", -4200U);
389 OneTest (__LINE__, "000000000001068", 15, "%.15x", 4200U);
390 OneTest (__LINE__, "00000000000ef98", 15, "%.15x", -4200U);
391 OneTest (__LINE__, "000000000001068", 15, "%.15X", 4200U);
392 OneTest (__LINE__, "00000000000EF98", 15, "%.15X", -4200U);
394 /* Precision given via argument */
395 OneTest (__LINE__, "u", 1, "%.*c", 15, 'u');
396 OneTest (__LINE__, "000000000004200", 15, "%.*d", 15, 4200);
397 OneTest (__LINE__, "-000000000004200", 16, "%.*d", 15, -4200);
398 OneTest (__LINE__, "000000000004200", 15, "%.*i", 15, 4200);
399 OneTest (__LINE__, "-000000000004200", 16, "%.*i", 15, -4200);
400 OneTest (__LINE__, "000000000010150", 15, "%.*o", 15, 4200U);
401 OneTest (__LINE__, "000000000167630", 15, "%.*o", 15, -4200U);
402 OneTest (__LINE__, "hello, world", 12, "%.*s", 15, "hello, world");
403 OneTest (__LINE__, "000000000004200", 15, "%.*u", 15, 4200U);
404 OneTest (__LINE__, "000000000061336", 15, "%.*u", 15, -4200U);
405 OneTest (__LINE__, "000000000001068", 15, "%.*x", 15, 4200U);
406 OneTest (__LINE__, "00000000000ef98", 15, "%.*x", 15, -4200U);
407 OneTest (__LINE__, "000000000001068", 15, "%.*X", 15, 4200U);
408 OneTest (__LINE__, "00000000000EF98", 15, "%.*X", 15, -4200U);
410 /* Negative precision is treated as if the precision were omitted */
412 OneTest (__LINE__, "u", 1, "%.*c", -15, 'u');
413 OneTest (__LINE__, "4200", 4, "%.*d", -15, 4200);
414 OneTest (__LINE__, "-4200", 5, "%.*d", -15, -4200);
415 OneTest (__LINE__, "4200", 4, "%.*i", -15, 4200);
416 OneTest (__LINE__, "-4200", 5, "%.*i", -15, -4200);
417 OneTest (__LINE__, "10150", 5, "%.*o", -15, 4200U);
418 OneTest (__LINE__, "167630", 6, "%.*o", -15, -4200U);
419 OneTest (__LINE__, "hello, world", 12, "%.*s", -15, "hello, world");
420 OneTest (__LINE__, "4200", 4, "%.*u", -15, 4200U);
421 OneTest (__LINE__, "61336", 5, "%.*u", -15, -4200U);
422 OneTest (__LINE__, "1068", 4, "%.*x", -15, 4200U);
423 OneTest (__LINE__, "ef98", 4, "%.*x", -15, -4200U);
424 OneTest (__LINE__, "1068", 4, "%.*X", -15, 4200U);
425 OneTest (__LINE__, "EF98", 4, "%.*X", -15, -4200U);
428 /* Field width and precision given */
429 OneTest (__LINE__, " u", 15, "%15.10c", 'u');
430 OneTest (__LINE__, " 0000004200", 15, "%15.10d", 4200);
431 OneTest (__LINE__, " -0000004200", 15, "%15.10d", -4200);
432 OneTest (__LINE__, " 0000004200", 15, "%15.10i", 4200);
433 OneTest (__LINE__, " -0000004200", 15, "%15.10i", -4200);
434 OneTest (__LINE__, " 0000010150", 15, "%15.10o", 4200U);
435 OneTest (__LINE__, " 0000167630", 15, "%15.10o", -4200U);
436 OneTest (__LINE__, " hello, wor", 15, "%15.10s", "hello, world");
437 OneTest (__LINE__, " 0000004200", 15, "%15.10u", 4200U);
438 OneTest (__LINE__, " 0000061336", 15, "%15.10u", -4200U);
439 OneTest (__LINE__, " 0000001068", 15, "%15.10x", 4200U);
440 OneTest (__LINE__, " 000000ef98", 15, "%15.10x", -4200U);
441 OneTest (__LINE__, " 0000001068", 15, "%15.10X", 4200U);
442 OneTest (__LINE__, " 000000EF98", 15, "%15.10X", -4200U);
444 /* For d, i, o, u, x and X conversions, if a precision is specified, the
445 ** '0' flag is ignored.
447 OneTest (__LINE__, " 0000004200", 15, "%015.10d", 4200);
448 OneTest (__LINE__, " -0000004200", 15, "%015.10d", -4200);
449 OneTest (__LINE__, " 0000004200", 15, "%015.10i", 4200);
450 OneTest (__LINE__, " -0000004200", 15, "%015.10i", -4200);
451 OneTest (__LINE__, " 0000010150", 15, "%015.10o", 4200U);
452 OneTest (__LINE__, " 0000167630", 15, "%015.10o", -4200U);
453 OneTest (__LINE__, " 0000004200", 15, "%015.10u", 4200U);
454 OneTest (__LINE__, " 0000061336", 15, "%015.10u", -4200U);
455 OneTest (__LINE__, " 0000001068", 15, "%015.10x", 4200U);
456 OneTest (__LINE__, " 000000ef98", 15, "%015.10x", -4200U);
457 OneTest (__LINE__, " 0000001068", 15, "%015.10X", 4200U);
458 OneTest (__LINE__, " 000000EF98", 15, "%015.10X", -4200U);
460 /* Zero precision, explicitly specified */
461 OneTest (__LINE__, "u", 1, "%.0c", 'u');
462 OneTest (__LINE__, "4200", 4, "%.0d", 4200);
463 OneTest (__LINE__, "-4200", 5, "%.0d", -4200);
464 OneTest (__LINE__, "4200", 4, "%.0i", 4200);
465 OneTest (__LINE__, "-4200", 5, "%.0i", -4200);
466 OneTest (__LINE__, "10150", 5, "%.0o", 4200U);
467 OneTest (__LINE__, "167630", 6, "%.0o", -4200U);
468 OneTest (__LINE__, "", 0, "%.0s", "hello, world");
469 OneTest (__LINE__, "4200", 4, "%.0u", 4200U);
470 OneTest (__LINE__, "61336", 5, "%.0u", -4200U);
471 OneTest (__LINE__, "1068", 4, "%.0x", 4200U);
472 OneTest (__LINE__, "ef98", 4, "%.0x", -4200U);
473 OneTest (__LINE__, "1068", 4, "%.0X", 4200U);
474 OneTest (__LINE__, "EF98", 4, "%.0X", -4200U);
476 /* Zero precision, dot only */
477 OneTest (__LINE__, "u", 1, "%.c", 'u');
478 OneTest (__LINE__, "4200", 4, "%.d", 4200);
479 OneTest (__LINE__, "-4200", 5, "%.d", -4200);
480 OneTest (__LINE__, "4200", 4, "%.i", 4200);
481 OneTest (__LINE__, "-4200", 5, "%.i", -4200);
482 OneTest (__LINE__, "10150", 5, "%.o", 4200U);
483 OneTest (__LINE__, "167630", 6, "%.o", -4200U);
484 OneTest (__LINE__, "", 0, "%.s", "hello, world");
485 OneTest (__LINE__, "4200", 4, "%.u", 4200U);
486 OneTest (__LINE__, "61336", 5, "%.u", -4200U);
487 OneTest (__LINE__, "1068", 4, "%.x", 4200U);
488 OneTest (__LINE__, "ef98", 4, "%.x", -4200U);
489 OneTest (__LINE__, "1068", 4, "%.X", 4200U);
490 OneTest (__LINE__, "EF98", 4, "%.X", -4200U);
492 /* Zero precision, zero value */
493 OneTest (__LINE__, "", 0, "%.0d", 0);
494 OneTest (__LINE__, "", 0, "%.0i", 0);
495 OneTest (__LINE__, "", 0, "%.0o", 0U);
496 OneTest (__LINE__, "", 0, "%.0u", 0U);
497 OneTest (__LINE__, "", 0, "%.0x", 0U);
498 OneTest (__LINE__, "", 0, "%.0X", 0U);
500 /* Field width and zero precision given */
501 OneTest (__LINE__, " u", 15, "%15.0c", 'u');
502 OneTest (__LINE__, " 4200", 15, "%15.0d", 4200);
503 OneTest (__LINE__, " -4200", 15, "%15.0d", -4200);
504 OneTest (__LINE__, " 4200", 15, "%15.0i", 4200);
505 OneTest (__LINE__, " -4200", 15, "%15.0i", -4200);
506 OneTest (__LINE__, " 10150", 15, "%15.0o", 4200U);
507 OneTest (__LINE__, " 167630", 15, "%15.0o", -4200U);
508 OneTest (__LINE__, " ", 15, "%15.0s", "hello, world");
509 OneTest (__LINE__, " 4200", 15, "%15.0u", 4200U);
510 OneTest (__LINE__, " 61336", 15, "%15.0u", -4200U);
511 OneTest (__LINE__, " 1068", 15, "%15.0x", 4200U);
512 OneTest (__LINE__, " ef98", 15, "%15.0x", -4200U);
513 OneTest (__LINE__, " 1068", 15, "%15.0X", 4200U);
514 OneTest (__LINE__, " EF98", 15, "%15.0X", -4200U);
516 /* Field width, zero precision and zero value */
517 OneTest (__LINE__, " ", 15, "%15.0d", 0);
518 OneTest (__LINE__, " ", 15, "%15.0i", 0);
519 OneTest (__LINE__, " ", 15, "%15.0o", 0U);
520 OneTest (__LINE__, " ", 15, "%15.0u", 0U);
521 OneTest (__LINE__, " ", 15, "%15.0x", 0U);
522 OneTest (__LINE__, " ", 15, "%15.0X", 0U);
524 /* Alternative form */
525 OneTest (__LINE__, "010150", 6, "%#o", 4200U);
526 OneTest (__LINE__, "0167630", 7, "%#o", -4200U);
527 OneTest (__LINE__, "0x1068", 6, "%#x", 4200U);
528 OneTest (__LINE__, "0xef98", 6, "%#x", -4200U);
529 OneTest (__LINE__, "0X1068", 6, "%#X", 4200U);
530 OneTest (__LINE__, "0XEF98", 6, "%#X", -4200U);
532 /* Alternative form with zero value */
534 OneTest (__LINE__, "0", 1, "%#o", 0U);
535 OneTest (__LINE__, "0", 1, "%#x", 0U);
536 OneTest (__LINE__, "0", 1, "%#X", 0U);
539 /* Alternative form with zero value and precision 1 */
540 OneTest (__LINE__, "0", 1, "%#.1o", 0U);
541 OneTest (__LINE__, "0", 1, "%#.1x", 0U);
542 OneTest (__LINE__, "0", 1, "%#.1X", 0U);
544 /* Alternative form with non zero value and precision 1 */
545 OneTest (__LINE__, "01", 2, "%#.1o", 1U);
546 OneTest (__LINE__, "0x1", 3, "%#.1x", 1U);
547 OneTest (__LINE__, "0X1", 3, "%#.1X", 1U);
549 /* Alternative form and width given */
550 OneTest (__LINE__, " 010150", 15, "%#15o", 4200U);
551 OneTest (__LINE__, " 0x1068", 15, "%#15x", 4200U);
552 OneTest (__LINE__, " 0X1068", 15, "%#15X", 4200U);
554 /* Alternative form, width and zero padding */
555 OneTest (__LINE__, "000000000010150", 15, "%#015o", 4200U);
556 OneTest (__LINE__, "0x0000000001068", 15, "%#015x", 4200U);
557 OneTest (__LINE__, "0X0000000001068", 15, "%#015X", 4200U);
559 /* n conversion specifier */
560 WriteTest (__LINE__, "%d%n", &W, 0x5A5A0004L);
561 WriteTest (__LINE__, "%d%hn", &W, 0x5A5A0004L);
562 WriteTest (__LINE__, "%d%hhn", &W, 0x5A5A5A04L);
563 WriteTest (__LINE__, "%d%ln", &W, 0x00000004L);
565 /* Output the result */
567 printf ("%u tests, %u failures\n", Tests, Failures);
569 printf ("%u tests: Ok\n", Tests);
572 /* Wait for a key so we can read the result */
573 #if defined(__CC65__)