1 /* Test of u16_v[a]s[n]printf() function.
2 Copyright (C) 2007 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
21 test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...))
23 /* Test support of size specifiers as in C99. */
27 my_xasprintf ("%ju %d", (uintmax_t) 12345671, 33, 44, 55);
28 static const uint16_t expected[] =
29 { '1', '2', '3', '4', '5', '6', '7', '1', ' ', '3', '3', 0 };
30 ASSERT (result != NULL);
31 ASSERT (u16_strcmp (result, expected) == 0);
37 my_xasprintf ("%zu %d", (size_t) 12345672, 33, 44, 55);
38 static const uint16_t expected[] =
39 { '1', '2', '3', '4', '5', '6', '7', '2', ' ', '3', '3', 0 };
40 ASSERT (result != NULL);
41 ASSERT (u16_strcmp (result, expected) == 0);
47 my_xasprintf ("%tu %d", (ptrdiff_t) 12345673, 33, 44, 55);
48 static const uint16_t expected[] =
49 { '1', '2', '3', '4', '5', '6', '7', '3', ' ', '3', '3', 0 };
50 ASSERT (result != NULL);
51 ASSERT (u16_strcmp (result, expected) == 0);
57 my_xasprintf ("%Lg %d", (long double) 1.5, 33, 44, 55);
58 static const uint16_t expected[] =
59 { '1', '.', '5', ' ', '3', '3', 0 };
60 ASSERT (result != NULL);
61 ASSERT (u16_strcmp (result, expected) == 0);
65 /* Test the support of the 'U' conversion specifier for Unicode strings. */
68 static const uint8_t unicode_string[] = "Hello";
71 my_xasprintf ("%U %d", unicode_string, 33, 44, 55);
72 static const uint16_t expected[] =
73 { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
74 ASSERT (result != NULL);
75 ASSERT (u16_strcmp (result, expected) == 0);
80 my_xasprintf ("%10U %d", unicode_string, 33, 44, 55);
81 static const uint16_t expected[] =
82 { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
83 ASSERT (result != NULL);
84 ASSERT (u16_strcmp (result, expected) == 0);
89 my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55);
90 static const uint16_t expected[] =
91 { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
92 ASSERT (result != NULL);
93 ASSERT (u16_strcmp (result, expected) == 0);
96 { /* FLAG_ZERO: no effect. */
98 my_xasprintf ("%010U %d", unicode_string, 33, 44, 55);
99 static const uint16_t expected[] =
100 { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
101 ASSERT (result != NULL);
102 ASSERT (u16_strcmp (result, expected) == 0);
108 static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 };
111 my_xasprintf ("%lU %d", unicode_string, 33, 44, 55);
112 static const uint16_t expected[] =
113 { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
114 ASSERT (result != NULL);
115 ASSERT (u16_strcmp (result, expected) == 0);
120 my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55);
121 static const uint16_t expected[] =
122 { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
123 ASSERT (result != NULL);
124 ASSERT (u16_strcmp (result, expected) == 0);
129 my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55);
130 static const uint16_t expected[] =
131 { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
132 ASSERT (result != NULL);
133 ASSERT (u16_strcmp (result, expected) == 0);
136 { /* FLAG_ZERO: no effect. */
138 my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55);
139 static const uint16_t expected[] =
140 { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
141 ASSERT (result != NULL);
142 ASSERT (u16_strcmp (result, expected) == 0);
148 static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 };
151 my_xasprintf ("%llU %d", unicode_string, 33, 44, 55);
152 static const uint16_t expected[] =
153 { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
154 ASSERT (result != NULL);
155 ASSERT (u16_strcmp (result, expected) == 0);
160 my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55);
161 static const uint16_t expected[] =
162 { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
163 ASSERT (result != NULL);
164 ASSERT (u16_strcmp (result, expected) == 0);
169 my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55);
170 static const uint16_t expected[] =
171 { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
172 ASSERT (result != NULL);
173 ASSERT (u16_strcmp (result, expected) == 0);
176 { /* FLAG_ZERO: no effect. */
178 my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55);
179 static const uint16_t expected[] =
180 { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
181 ASSERT (result != NULL);
182 ASSERT (u16_strcmp (result, expected) == 0);
187 /* Test the support of the 's' conversion specifier for strings. */
191 my_xasprintf ("Mr. %s %d", "Ronald Reagan", 33, 44, 55);
192 static const uint16_t expected[] =
193 { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd',
194 ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', '3', '3',
197 ASSERT (result != NULL);
198 ASSERT (u16_strcmp (result, expected) == 0);
204 my_xasprintf ("Mr. %20s %d", "Ronald Reagan", 33, 44, 55);
205 static const uint16_t expected[] =
206 { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
207 ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e',
208 'a', 'g', 'a', 'n', ' ', '3', '3', 0
210 ASSERT (result != NULL);
211 ASSERT (u16_strcmp (result, expected) == 0);
217 my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55);
218 static const uint16_t expected[] =
219 { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd',
220 ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ',
221 ' ', ' ', ' ', ' ', ' ', '3', '3', 0
223 ASSERT (result != NULL);
224 ASSERT (u16_strcmp (result, expected) == 0);
228 { /* FLAG_ZERO: no effect. */
230 my_xasprintf ("Mr. %020s %d", "Ronald Reagan", 33, 44, 55);
231 static const uint16_t expected[] =
232 { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
233 ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e',
234 'a', 'g', 'a', 'n', ' ', '3', '3', 0
236 ASSERT (result != NULL);
237 ASSERT (u16_strcmp (result, expected) == 0);
241 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
242 output of floating-point numbers. */
244 { /* A positive number. */
246 my_xasprintf ("%a %d", 3.1416015625, 33, 44, 55);
247 static const uint16_t expected1[] =
248 { '0', 'x', '1', '.', '9', '2', '2', 'p', '+', '1', ' ', '3', '3', 0 };
249 static const uint16_t expected2[] =
250 { '0', 'x', '3', '.', '2', '4', '4', 'p', '+', '0', ' ', '3', '3', 0 };
251 static const uint16_t expected3[] =
252 { '0', 'x', '6', '.', '4', '8', '8', 'p', '-', '1', ' ', '3', '3', 0 };
253 static const uint16_t expected4[] =
254 { '0', 'x', 'c', '.', '9', '1', 'p', '-', '2', ' ', '3', '3', 0 };
255 ASSERT (result != NULL);
256 ASSERT (u16_strcmp (result, expected1) == 0
257 || u16_strcmp (result, expected2) == 0
258 || u16_strcmp (result, expected3) == 0
259 || u16_strcmp (result, expected4) == 0);
265 my_xasprintf ("%10a %d", 1.75, 33, 44, 55);
266 static const uint16_t expected1[] =
267 { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 };
268 static const uint16_t expected2[] =
269 { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 };
270 static const uint16_t expected3[] =
271 { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 };
272 static const uint16_t expected4[] =
273 { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 };
274 ASSERT (result != NULL);
275 ASSERT (u16_strcmp (result, expected1) == 0
276 || u16_strcmp (result, expected2) == 0
277 || u16_strcmp (result, expected3) == 0
278 || u16_strcmp (result, expected4) == 0);
282 { /* Small precision. */
284 my_xasprintf ("%.10a %d", 1.75, 33, 44, 55);
285 static const uint16_t expected1[] =
286 { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0',
287 '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3',
290 static const uint16_t expected2[] =
291 { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0',
292 '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3',
295 static const uint16_t expected3[] =
296 { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0',
297 '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3',
300 static const uint16_t expected4[] =
301 { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0',
302 '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3',
305 ASSERT (result != NULL);
306 ASSERT (u16_strcmp (result, expected1) == 0
307 || u16_strcmp (result, expected2) == 0
308 || u16_strcmp (result, expected3) == 0
309 || u16_strcmp (result, expected4) == 0);
313 { /* Large precision. */
315 my_xasprintf ("%.50a %d", 1.75, 33, 44, 55);
316 static const uint16_t expected1[] =
317 { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0',
318 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
319 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
320 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
321 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
322 '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3',
325 static const uint16_t expected2[] =
326 { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0',
327 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
328 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
329 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
330 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
331 '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3',
334 static const uint16_t expected3[] =
335 { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0',
336 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
337 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
338 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
339 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
340 '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3',
343 static const uint16_t expected4[] =
344 { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0',
345 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
346 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
347 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
348 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
349 '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3',
352 ASSERT (result != NULL);
353 ASSERT (u16_strcmp (result, expected1) == 0
354 || u16_strcmp (result, expected2) == 0
355 || u16_strcmp (result, expected3) == 0
356 || u16_strcmp (result, expected4) == 0);
360 { /* A positive number. */
362 my_xasprintf ("%La %d", 3.1416015625L, 33, 44, 55);
363 static const uint16_t expected1[] =
364 { '0', 'x', '1', '.', '9', '2', '2', 'p', '+', '1',
367 static const uint16_t expected2[] =
368 { '0', 'x', '3', '.', '2', '4', '4', 'p', '+', '0',
371 static const uint16_t expected3[] =
372 { '0', 'x', '6', '.', '4', '8', '8', 'p', '-', '1',
375 static const uint16_t expected4[] =
376 { '0', 'x', 'c', '.', '9', '1', 'p', '-', '2', ' ',
379 ASSERT (result != NULL);
380 ASSERT (u16_strcmp (result, expected1) == 0
381 || u16_strcmp (result, expected2) == 0
382 || u16_strcmp (result, expected3) == 0
383 || u16_strcmp (result, expected4) == 0);
389 my_xasprintf ("%10La %d", 1.75L, 33, 44, 55);
390 static const uint16_t expected1[] =
391 { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 };
392 static const uint16_t expected2[] =
393 { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 };
394 static const uint16_t expected3[] =
395 { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 };
396 static const uint16_t expected4[] =
397 { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 };
398 ASSERT (result != NULL);
399 ASSERT (u16_strcmp (result, expected1) == 0
400 || u16_strcmp (result, expected2) == 0
401 || u16_strcmp (result, expected3) == 0
402 || u16_strcmp (result, expected4) == 0);
406 { /* Small precision. */
408 my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55);
409 static const uint16_t expected1[] =
410 { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0',
411 '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3',
414 static const uint16_t expected2[] =
415 { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0',
416 '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3',
419 static const uint16_t expected3[] =
420 { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0',
421 '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3',
424 static const uint16_t expected4[] =
425 { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0',
426 '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3',
429 ASSERT (result != NULL);
430 ASSERT (u16_strcmp (result, expected1) == 0
431 || u16_strcmp (result, expected2) == 0
432 || u16_strcmp (result, expected3) == 0
433 || u16_strcmp (result, expected4) == 0);
437 { /* Large precision. */
439 my_xasprintf ("%.50La %d", 1.75L, 33, 44, 55);
440 static const uint16_t expected1[] =
441 { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0',
442 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
443 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
444 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
445 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
446 '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3',
449 static const uint16_t expected2[] =
450 { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0',
451 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
452 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
453 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
454 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
455 '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3',
458 static const uint16_t expected3[] =
459 { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0',
460 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
461 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
462 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
463 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
464 '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3',
467 static const uint16_t expected4[] =
468 { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0',
469 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
470 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
471 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
472 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
473 '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3',
476 ASSERT (result != NULL);
477 ASSERT (u16_strcmp (result, expected1) == 0
478 || u16_strcmp (result, expected2) == 0
479 || u16_strcmp (result, expected3) == 0
480 || u16_strcmp (result, expected4) == 0);
484 /* Test the support of the %f format directive. */
486 { /* A positive number. */
488 my_xasprintf ("%f %d", 12.75, 33, 44, 55);
489 static const uint16_t expected[] =
490 { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 };
491 ASSERT (result != NULL);
492 ASSERT (u16_strcmp (result, expected) == 0);
498 my_xasprintf ("%10f %d", 1.75, 33, 44, 55);
499 static const uint16_t expected[] =
500 { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 };
501 ASSERT (result != NULL);
502 ASSERT (u16_strcmp (result, expected) == 0);
508 my_xasprintf ("%.f %d", 1234.0, 33, 44, 55);
509 static const uint16_t expected[] =
510 { '1', '2', '3', '4', ' ', '3', '3', 0 };
511 ASSERT (result != NULL);
512 ASSERT (u16_strcmp (result, expected) == 0);
516 { /* A positive number. */
518 my_xasprintf ("%Lf %d", 12.75L, 33, 44, 55);
519 static const uint16_t expected[] =
520 { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 };
521 ASSERT (result != NULL);
522 ASSERT (u16_strcmp (result, expected) == 0);
528 my_xasprintf ("%10Lf %d", 1.75L, 33, 44, 55);
529 static const uint16_t expected[] =
530 { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 };
531 ASSERT (result != NULL);
532 ASSERT (u16_strcmp (result, expected) == 0);
538 my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55);
539 static const uint16_t expected[] =
540 { '1', '2', '3', '4', ' ', '3', '3', 0 };
541 ASSERT (result != NULL);
542 ASSERT (u16_strcmp (result, expected) == 0);
546 /* Test the support of the %F format directive. */
548 { /* A positive number. */
550 my_xasprintf ("%F %d", 12.75, 33, 44, 55);
551 static const uint16_t expected[] =
552 { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 };
553 ASSERT (result != NULL);
554 ASSERT (u16_strcmp (result, expected) == 0);
560 my_xasprintf ("%.F %d", 1234.0, 33, 44, 55);
561 static const uint16_t expected[] =
562 { '1', '2', '3', '4', ' ', '3', '3', 0 };
563 ASSERT (result != NULL);
564 ASSERT (u16_strcmp (result, expected) == 0);
568 { /* A positive number. */
570 my_xasprintf ("%LF %d", 12.75L, 33, 44, 55);
571 static const uint16_t expected[] =
572 { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 };
573 ASSERT (result != NULL);
574 ASSERT (u16_strcmp (result, expected) == 0);
580 my_xasprintf ("%.LF %d", 1234.0L, 33, 44, 55);
581 static const uint16_t expected[] =
582 { '1', '2', '3', '4', ' ', '3', '3', 0 };
583 ASSERT (result != NULL);
584 ASSERT (u16_strcmp (result, expected) == 0);
588 /* Test the support of the %e format directive. */
590 { /* A positive number. */
592 my_xasprintf ("%e %d", 12.75, 33, 44, 55);
593 static const uint16_t expected1[] =
594 { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+',
595 '0', '1', ' ', '3', '3', 0
597 static const uint16_t expected2[] =
598 { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+',
599 '0', '0', '1', ' ', '3', '3', 0
601 ASSERT (result != NULL);
602 ASSERT (u16_strcmp (result, expected1) == 0
603 || u16_strcmp (result, expected2) == 0);
609 my_xasprintf ("%15e %d", 1.75, 33, 44, 55);
610 static const uint16_t expected1[] =
611 { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0',
612 '0', 'e', '+', '0', '0', ' ', '3', '3', 0
614 static const uint16_t expected2[] =
615 { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0',
616 'e', '+', '0', '0', '0', ' ', '3', '3', 0
618 ASSERT (result != NULL);
619 ASSERT (u16_strcmp (result, expected1) == 0
620 || u16_strcmp (result, expected2) == 0);
626 my_xasprintf ("%.e %d", 1234.0, 33, 44, 55);
627 static const uint16_t expected1[] =
628 { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 };
629 static const uint16_t expected2[] =
630 { '1', 'e', '+', '0', '0', '3', ' ', '3', '3', 0 };
631 ASSERT (result != NULL);
632 ASSERT (u16_strcmp (result, expected1) == 0
633 || u16_strcmp (result, expected2) == 0);
637 { /* A positive number. */
639 my_xasprintf ("%Le %d", 12.75L, 33, 44, 55);
640 static const uint16_t expected[] =
641 { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+',
642 '0', '1', ' ', '3', '3', 0
644 ASSERT (result != NULL);
645 ASSERT (u16_strcmp (result, expected) == 0);
651 my_xasprintf ("%15Le %d", 1.75L, 33, 44, 55);
652 static const uint16_t expected[] =
653 { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0',
654 '0', 'e', '+', '0', '0', ' ', '3', '3', 0
656 ASSERT (result != NULL);
657 ASSERT (u16_strcmp (result, expected) == 0);
663 my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55);
664 static const uint16_t expected[] =
665 { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 };
666 ASSERT (result != NULL);
667 ASSERT (u16_strcmp (result, expected) == 0);
671 /* Test the support of the %g format directive. */
673 { /* A positive number. */
675 my_xasprintf ("%g %d", 12.75, 33, 44, 55);
676 static const uint16_t expected[] =
677 { '1', '2', '.', '7', '5', ' ', '3', '3', 0 };
678 ASSERT (result != NULL);
679 ASSERT (u16_strcmp (result, expected) == 0);
685 my_xasprintf ("%10g %d", 1.75, 33, 44, 55);
686 static const uint16_t expected[] =
687 { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 };
688 ASSERT (result != NULL);
689 ASSERT (u16_strcmp (result, expected) == 0);
695 my_xasprintf ("%.g %d", 1234.0, 33, 44, 55);
696 static const uint16_t expected1[] =
697 { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 };
698 static const uint16_t expected2[] =
699 { '1', 'e', '+', '0', '0', '3', ' ', '3', '3', 0 };
700 ASSERT (result != NULL);
701 ASSERT (u16_strcmp (result, expected1) == 0
702 || u16_strcmp (result, expected2) == 0);
706 { /* A positive number. */
708 my_xasprintf ("%Lg %d", 12.75L, 33, 44, 55);
709 static const uint16_t expected[] =
710 { '1', '2', '.', '7', '5', ' ', '3', '3', 0 };
711 ASSERT (result != NULL);
712 ASSERT (u16_strcmp (result, expected) == 0);
718 my_xasprintf ("%10Lg %d", 1.75L, 33, 44, 55);
719 static const uint16_t expected[] =
720 { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 };
721 ASSERT (result != NULL);
722 ASSERT (u16_strcmp (result, expected) == 0);
728 my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55);
729 static const uint16_t expected[] =
730 { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 };
731 ASSERT (result != NULL);
732 ASSERT (u16_strcmp (result, expected) == 0);
736 /* Test the support of the %n format directive. */
741 my_xasprintf ("%d %n", 123, &count, 33, 44, 55);
742 static const uint16_t expected[] =
743 { '1', '2', '3', ' ', 0 };
744 ASSERT (result != NULL);
745 ASSERT (u16_strcmp (result, expected) == 0);
750 /* Test the support of the POSIX/XSI format strings with positions. */
754 my_xasprintf ("%2$d %1$d", 33, 55);
755 static const uint16_t expected[] =
756 { '5', '5', ' ', '3', '3', 0 };
757 ASSERT (result != NULL);
758 ASSERT (u16_strcmp (result, expected) == 0);
762 /* Test the support of the grouping flag. */
766 my_xasprintf ("%'d %d", 1234567, 99);
767 ASSERT (result != NULL);
768 ASSERT (result[u16_strlen (result) - 1] == '9');
772 /* Test the support of the 'U' conversion specifier for Unicode strings. */
775 static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
778 my_xasprintf ("%U %d", unicode_string, 33, 44, 55);
779 static const uint16_t expected[] =
780 { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
781 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0
783 ASSERT (result != NULL);
784 ASSERT (u16_strcmp (result, expected) == 0);
789 my_xasprintf ("%20U %d", unicode_string, 33, 44, 55);
790 static const uint16_t expected[] =
791 { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
792 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
795 ASSERT (result != NULL);
796 ASSERT (u16_strcmp (result, expected) == 0);
801 my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55);
802 static const uint16_t expected[] =
803 { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
804 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ',
807 ASSERT (result != NULL);
808 ASSERT (u16_strcmp (result, expected) == 0);
811 { /* FLAG_ZERO: no effect. */
813 my_xasprintf ("%020U %d", unicode_string, 33, 44, 55);
814 static const uint16_t expected[] =
815 { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
816 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
819 ASSERT (result != NULL);
820 ASSERT (u16_strcmp (result, expected) == 0);
826 static const uint16_t unicode_string[] = /* Rafał Maszkowski */
828 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
833 my_xasprintf ("%lU %d", unicode_string, 33, 44, 55);
834 static const uint16_t expected[] =
835 { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
836 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0
838 ASSERT (result != NULL);
839 ASSERT (u16_strcmp (result, expected) == 0);
844 my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55);
845 static const uint16_t expected[] =
846 { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
847 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
850 ASSERT (result != NULL);
851 ASSERT (u16_strcmp (result, expected) == 0);
856 my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55);
857 static const uint16_t expected[] =
858 { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
859 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ',
862 ASSERT (result != NULL);
863 ASSERT (u16_strcmp (result, expected) == 0);
866 { /* FLAG_ZERO: no effect. */
868 my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55);
869 static const uint16_t expected[] =
870 { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
871 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
874 ASSERT (result != NULL);
875 ASSERT (u16_strcmp (result, expected) == 0);
881 static const uint32_t unicode_string[] = /* Rafał Maszkowski */
883 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
888 my_xasprintf ("%llU %d", unicode_string, 33, 44, 55);
889 static const uint16_t expected[] =
890 { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
891 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0
893 ASSERT (result != NULL);
894 ASSERT (u16_strcmp (result, expected) == 0);
899 my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55);
900 static const uint16_t expected[] =
901 { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
902 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
905 ASSERT (result != NULL);
906 ASSERT (u16_strcmp (result, expected) == 0);
911 my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55);
912 static const uint16_t expected[] =
913 { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
914 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ',
917 ASSERT (result != NULL);
918 ASSERT (u16_strcmp (result, expected) == 0);
921 { /* FLAG_ZERO: no effect. */
923 my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55);
924 static const uint16_t expected[] =
925 { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
926 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
929 ASSERT (result != NULL);
930 ASSERT (u16_strcmp (result, expected) == 0);
935 /* Test non-ASCII characters in the format string. */
939 my_xasprintf ("\304rger", 33, 44, 55);
940 ASSERT (result == NULL && errno == EINVAL);