~ubuntu-branches/ubuntu/intrepid/parted/intrepid

« back to all changes in this revision

Viewing changes to gnulib/tests/unistdio/test-u8-printf1.h

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-06-24 14:31:05 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080624143105-rd7yw67a9qnvh51i
Tags: 1.8.8.git.2008.03.24-7ubuntu1
* Resynchronise with Debian (LP: #237568). Remaining changes:
  - swap-uuid.dpatch: Create UUIDs on new swap partitions.
  - gptsync.dpatch: On Intel Mac systems, write a synced MBR rather than a
    protective MBR.
  - Add -fno-stack-protector on sparc.
  - sparc-new-label.dpatch: Fix sparc disk label generation. This is
    required for LDOM and parallel installations with Solaris 10.
  - loop-partitions.dpatch: Loop devices can only have one partition, so
    don't generate device names such as "/dev/loop0p1".
  - unpartitioned-disks.dpatch: Don't try to call BLKPG ioctls on
    unpartitionable disks (only implemented for loop devices at the
    moment), as they will always fail.
  - When building with gcc-4.3, add -Wno-array-bounds to CFLAGS.
  - Cell partition tables are misdetected as pc98, so disable pc98 support
    on powerpc.
  - array-bounds.dpatch: Backport patch from git to allow building with
    gcc-4.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Test of u8_v[a]s[n]printf() function.
 
2
   Copyright (C) 2007 Free Software Foundation, Inc.
 
3
 
 
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)
 
7
   any later version.
 
8
 
 
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.
 
13
 
 
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.  */
 
17
 
 
18
/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
19
 
 
20
static void
 
21
test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
 
22
{
 
23
  /* Test support of size specifiers as in C99.  */
 
24
 
 
25
  {
 
26
    uint8_t *result =
 
27
      my_xasprintf ("%ju %d", (uintmax_t) 12345671, 33, 44, 55);
 
28
    static const uint8_t expected[] = "12345671 33";
 
29
    ASSERT (result != NULL);
 
30
    ASSERT (u8_strcmp (result, expected) == 0);
 
31
    free (result);
 
32
  }
 
33
 
 
34
  {
 
35
    uint8_t *result =
 
36
      my_xasprintf ("%zu %d", (size_t) 12345672, 33, 44, 55);
 
37
    static const uint8_t expected[] = "12345672 33";
 
38
    ASSERT (result != NULL);
 
39
    ASSERT (u8_strcmp (result, expected) == 0);
 
40
    free (result);
 
41
  }
 
42
 
 
43
  {
 
44
    uint8_t *result =
 
45
      my_xasprintf ("%tu %d", (ptrdiff_t) 12345673, 33, 44, 55);
 
46
    static const uint8_t expected[] = "12345673 33";
 
47
    ASSERT (result != NULL);
 
48
    ASSERT (u8_strcmp (result, expected) == 0);
 
49
    free (result);
 
50
  }
 
51
 
 
52
  {
 
53
    uint8_t *result =
 
54
      my_xasprintf ("%Lg %d", (long double) 1.5, 33, 44, 55);
 
55
    static const uint8_t expected[] = "1.5 33";
 
56
    ASSERT (result != NULL);
 
57
    ASSERT (u8_strcmp (result, expected) == 0);
 
58
    free (result);
 
59
  }
 
60
 
 
61
  /* Test the support of the 'U' conversion specifier for Unicode strings.  */
 
62
 
 
63
  {
 
64
    static const uint8_t unicode_string[] = "Hello";
 
65
    {
 
66
      uint8_t *result =
 
67
        my_xasprintf ("%U %d", unicode_string, 33, 44, 55);
 
68
      static const uint8_t expected[] = "Hello 33";
 
69
      ASSERT (result != NULL);
 
70
      ASSERT (u8_strcmp (result, expected) == 0);
 
71
      free (result);
 
72
    }
 
73
    { /* Width.  */
 
74
      uint8_t *result =
 
75
        my_xasprintf ("%10U %d", unicode_string, 33, 44, 55);
 
76
      static const uint8_t expected[] = "     Hello 33";
 
77
      ASSERT (result != NULL);
 
78
      ASSERT (u8_strcmp (result, expected) == 0);
 
79
      free (result);
 
80
    }
 
81
    { /* FLAG_LEFT.  */
 
82
      uint8_t *result =
 
83
        my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55);
 
84
      static const uint8_t expected[] = "Hello      33";
 
85
      ASSERT (result != NULL);
 
86
      ASSERT (u8_strcmp (result, expected) == 0);
 
87
      free (result);
 
88
    }
 
89
    { /* FLAG_ZERO: no effect.  */
 
90
      uint8_t *result =
 
91
        my_xasprintf ("%010U %d", unicode_string, 33, 44, 55);
 
92
      static const uint8_t expected[] = "     Hello 33";
 
93
      ASSERT (result != NULL);
 
94
      ASSERT (u8_strcmp (result, expected) == 0);
 
95
      free (result);
 
96
    }
 
97
  }
 
98
 
 
99
  {
 
100
    static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 };
 
101
    {
 
102
      uint8_t *result =
 
103
        my_xasprintf ("%lU %d", unicode_string, 33, 44, 55);
 
104
      static const uint8_t expected[] = "Hello 33";
 
105
      ASSERT (result != NULL);
 
106
      ASSERT (u8_strcmp (result, expected) == 0);
 
107
      free (result);
 
108
    }
 
109
    { /* Width.  */
 
110
      uint8_t *result =
 
111
        my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55);
 
112
      static const uint8_t expected[] = "     Hello 33";
 
113
      ASSERT (result != NULL);
 
114
      ASSERT (u8_strcmp (result, expected) == 0);
 
115
      free (result);
 
116
    }
 
117
    { /* FLAG_LEFT.  */
 
118
      uint8_t *result =
 
119
        my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55);
 
120
      static const uint8_t expected[] = "Hello      33";
 
121
      ASSERT (result != NULL);
 
122
      ASSERT (u8_strcmp (result, expected) == 0);
 
123
      free (result);
 
124
    }
 
125
    { /* FLAG_ZERO: no effect.  */
 
126
      uint8_t *result =
 
127
        my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55);
 
128
      static const uint8_t expected[] = "     Hello 33";
 
129
      ASSERT (result != NULL);
 
130
      ASSERT (u8_strcmp (result, expected) == 0);
 
131
      free (result);
 
132
    }
 
133
  }
 
134
 
 
135
  {
 
136
    static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 };
 
137
    {
 
138
      uint8_t *result =
 
139
        my_xasprintf ("%llU %d", unicode_string, 33, 44, 55);
 
140
      static const uint8_t expected[] = "Hello 33";
 
141
      ASSERT (result != NULL);
 
142
      ASSERT (u8_strcmp (result, expected) == 0);
 
143
      free (result);
 
144
    }
 
145
    { /* Width.  */
 
146
      uint8_t *result =
 
147
        my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55);
 
148
      static const uint8_t expected[] = "     Hello 33";
 
149
      ASSERT (result != NULL);
 
150
      ASSERT (u8_strcmp (result, expected) == 0);
 
151
      free (result);
 
152
    }
 
153
    { /* FLAG_LEFT.  */
 
154
      uint8_t *result =
 
155
        my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55);
 
156
      static const uint8_t expected[] = "Hello      33";
 
157
      ASSERT (result != NULL);
 
158
      ASSERT (u8_strcmp (result, expected) == 0);
 
159
      free (result);
 
160
    }
 
161
    { /* FLAG_ZERO: no effect.  */
 
162
      uint8_t *result =
 
163
        my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55);
 
164
      static const uint8_t expected[] = "     Hello 33";
 
165
      ASSERT (result != NULL);
 
166
      ASSERT (u8_strcmp (result, expected) == 0);
 
167
      free (result);
 
168
    }
 
169
  }
 
170
 
 
171
  /* Test the support of the 's' conversion specifier for strings.  */
 
172
 
 
173
  {
 
174
    uint8_t *result =
 
175
      my_xasprintf ("Mr. %s %d", "Ronald Reagan", 33, 44, 55);
 
176
    static const uint8_t expected[] = "Mr. Ronald Reagan 33";
 
177
    ASSERT (result != NULL);
 
178
    ASSERT (u8_strcmp (result, expected) == 0);
 
179
    free (result);
 
180
  }
 
181
 
 
182
  { /* Width.  */
 
183
    uint8_t *result =
 
184
      my_xasprintf ("Mr. %20s %d", "Ronald Reagan", 33, 44, 55);
 
185
    static const uint8_t expected[] = "Mr.        Ronald Reagan 33";
 
186
    ASSERT (result != NULL);
 
187
    ASSERT (u8_strcmp (result, expected) == 0);
 
188
    free (result);
 
189
  }
 
190
 
 
191
  { /* FLAG_LEFT.  */
 
192
    uint8_t *result =
 
193
      my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55);
 
194
    static const uint8_t expected[] = "Mr. Ronald Reagan        33";
 
195
    ASSERT (result != NULL);
 
196
    ASSERT (u8_strcmp (result, expected) == 0);
 
197
    free (result);
 
198
  }
 
199
 
 
200
  { /* FLAG_ZERO: no effect.  */
 
201
    uint8_t *result =
 
202
      my_xasprintf ("Mr. %020s %d", "Ronald Reagan", 33, 44, 55);
 
203
    static const uint8_t expected[] = "Mr.        Ronald Reagan 33";
 
204
    ASSERT (result != NULL);
 
205
    ASSERT (u8_strcmp (result, expected) == 0);
 
206
    free (result);
 
207
  }
 
208
 
 
209
  /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
 
210
     output of floating-point numbers.  */
 
211
 
 
212
  { /* A positive number.  */
 
213
    uint8_t *result =
 
214
      my_xasprintf ("%a %d", 3.1416015625, 33, 44, 55);
 
215
    static const uint8_t expected1[] = "0x1.922p+1 33";
 
216
    static const uint8_t expected2[] = "0x3.244p+0 33";
 
217
    static const uint8_t expected3[] = "0x6.488p-1 33";
 
218
    static const uint8_t expected4[] = "0xc.91p-2 33";
 
219
    ASSERT (result != NULL);
 
220
    ASSERT (u8_strcmp (result, expected1) == 0
 
221
            || u8_strcmp (result, expected2) == 0
 
222
            || u8_strcmp (result, expected3) == 0
 
223
            || u8_strcmp (result, expected4) == 0);
 
224
    free (result);
 
225
  }
 
226
 
 
227
  { /* Width.  */
 
228
    uint8_t *result =
 
229
      my_xasprintf ("%10a %d", 1.75, 33, 44, 55);
 
230
    static const uint8_t expected1[] = "  0x1.cp+0 33";
 
231
    static const uint8_t expected2[] = "  0x3.8p-1 33";
 
232
    static const uint8_t expected3[] = "    0x7p-2 33";
 
233
    static const uint8_t expected4[] = "    0xep-3 33";
 
234
    ASSERT (result != NULL);
 
235
    ASSERT (u8_strcmp (result, expected1) == 0
 
236
            || u8_strcmp (result, expected2) == 0
 
237
            || u8_strcmp (result, expected3) == 0
 
238
            || u8_strcmp (result, expected4) == 0);
 
239
    free (result);
 
240
  }
 
241
 
 
242
  { /* Small precision.  */
 
243
    uint8_t *result =
 
244
      my_xasprintf ("%.10a %d", 1.75, 33, 44, 55);
 
245
    static const uint8_t expected1[] = "0x1.c000000000p+0 33";
 
246
    static const uint8_t expected2[] = "0x3.8000000000p-1 33";
 
247
    static const uint8_t expected3[] = "0x7.0000000000p-2 33";
 
248
    static const uint8_t expected4[] = "0xe.0000000000p-3 33";
 
249
    ASSERT (result != NULL);
 
250
    ASSERT (u8_strcmp (result, expected1) == 0
 
251
            || u8_strcmp (result, expected2) == 0
 
252
            || u8_strcmp (result, expected3) == 0
 
253
            || u8_strcmp (result, expected4) == 0);
 
254
    free (result);
 
255
  }
 
256
 
 
257
  { /* Large precision.  */
 
258
    uint8_t *result =
 
259
      my_xasprintf ("%.50a %d", 1.75, 33, 44, 55);
 
260
    static const uint8_t expected1[] = "0x1.c0000000000000000000000000000000000000000000000000p+0 33";
 
261
    static const uint8_t expected2[] = "0x3.80000000000000000000000000000000000000000000000000p-1 33";
 
262
    static const uint8_t expected3[] = "0x7.00000000000000000000000000000000000000000000000000p-2 33";
 
263
    static const uint8_t expected4[] = "0xe.00000000000000000000000000000000000000000000000000p-3 33";
 
264
    ASSERT (result != NULL);
 
265
    ASSERT (u8_strcmp (result, expected1) == 0
 
266
            || u8_strcmp (result, expected2) == 0
 
267
            || u8_strcmp (result, expected3) == 0
 
268
            || u8_strcmp (result, expected4) == 0);
 
269
    free (result);
 
270
  }
 
271
 
 
272
  { /* A positive number.  */
 
273
    uint8_t *result =
 
274
      my_xasprintf ("%La %d", 3.1416015625L, 33, 44, 55);
 
275
    static const uint8_t expected1[] = "0x1.922p+1 33";
 
276
    static const uint8_t expected2[] = "0x3.244p+0 33";
 
277
    static const uint8_t expected3[] = "0x6.488p-1 33";
 
278
    static const uint8_t expected4[] = "0xc.91p-2 33";
 
279
    ASSERT (result != NULL);
 
280
    ASSERT (u8_strcmp (result, expected1) == 0
 
281
            || u8_strcmp (result, expected2) == 0
 
282
            || u8_strcmp (result, expected3) == 0
 
283
            || u8_strcmp (result, expected4) == 0);
 
284
    free (result);
 
285
  }
 
286
 
 
287
  { /* Width.  */
 
288
    uint8_t *result =
 
289
      my_xasprintf ("%10La %d", 1.75L, 33, 44, 55);
 
290
    static const uint8_t expected1[] = "  0x1.cp+0 33";
 
291
    static const uint8_t expected2[] = "  0x3.8p-1 33";
 
292
    static const uint8_t expected3[] = "    0x7p-2 33";
 
293
    static const uint8_t expected4[] = "    0xep-3 33";
 
294
    ASSERT (result != NULL);
 
295
    ASSERT (u8_strcmp (result, expected1) == 0
 
296
            || u8_strcmp (result, expected2) == 0
 
297
            || u8_strcmp (result, expected3) == 0
 
298
            || u8_strcmp (result, expected4) == 0);
 
299
    free (result);
 
300
  }
 
301
 
 
302
  { /* Small precision.  */
 
303
    uint8_t *result =
 
304
      my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55);
 
305
    static const uint8_t expected1[] = "0x1.c000000000p+0 33";
 
306
    static const uint8_t expected2[] = "0x3.8000000000p-1 33";
 
307
    static const uint8_t expected3[] = "0x7.0000000000p-2 33";
 
308
    static const uint8_t expected4[] = "0xe.0000000000p-3 33";
 
309
    ASSERT (result != NULL);
 
310
    ASSERT (u8_strcmp (result, expected1) == 0
 
311
            || u8_strcmp (result, expected2) == 0
 
312
            || u8_strcmp (result, expected3) == 0
 
313
            || u8_strcmp (result, expected4) == 0);
 
314
    free (result);
 
315
  }
 
316
 
 
317
  { /* Large precision.  */
 
318
    uint8_t *result =
 
319
      my_xasprintf ("%.50La %d", 1.75L, 33, 44, 55);
 
320
    static const uint8_t expected1[] = "0x1.c0000000000000000000000000000000000000000000000000p+0 33";
 
321
    static const uint8_t expected2[] = "0x3.80000000000000000000000000000000000000000000000000p-1 33";
 
322
    static const uint8_t expected3[] = "0x7.00000000000000000000000000000000000000000000000000p-2 33";
 
323
    static const uint8_t expected4[] = "0xe.00000000000000000000000000000000000000000000000000p-3 33";
 
324
    ASSERT (result != NULL);
 
325
    ASSERT (u8_strcmp (result, expected1) == 0
 
326
            || u8_strcmp (result, expected2) == 0
 
327
            || u8_strcmp (result, expected3) == 0
 
328
            || u8_strcmp (result, expected4) == 0);
 
329
    free (result);
 
330
  }
 
331
 
 
332
  /* Test the support of the %f format directive.  */
 
333
 
 
334
  { /* A positive number.  */
 
335
    uint8_t *result =
 
336
      my_xasprintf ("%f %d", 12.75, 33, 44, 55);
 
337
    static const uint8_t expected[] = "12.750000 33";
 
338
    ASSERT (result != NULL);
 
339
    ASSERT (u8_strcmp (result, expected) == 0);
 
340
    free (result);
 
341
  }
 
342
 
 
343
  { /* Width.  */
 
344
    uint8_t *result =
 
345
      my_xasprintf ("%10f %d", 1.75, 33, 44, 55);
 
346
    static const uint8_t expected[] = "  1.750000 33";
 
347
    ASSERT (result != NULL);
 
348
    ASSERT (u8_strcmp (result, expected) == 0);
 
349
    free (result);
 
350
  }
 
351
 
 
352
  { /* Precision.  */
 
353
    uint8_t *result =
 
354
      my_xasprintf ("%.f %d", 1234.0, 33, 44, 55);
 
355
    static const uint8_t expected[] = "1234 33";
 
356
    ASSERT (result != NULL);
 
357
    ASSERT (u8_strcmp (result, expected) == 0);
 
358
    free (result);
 
359
  }
 
360
 
 
361
  { /* A positive number.  */
 
362
    uint8_t *result =
 
363
      my_xasprintf ("%Lf %d", 12.75L, 33, 44, 55);
 
364
    static const uint8_t expected[] = "12.750000 33";
 
365
    ASSERT (result != NULL);
 
366
    ASSERT (u8_strcmp (result, expected) == 0);
 
367
    free (result);
 
368
  }
 
369
 
 
370
  { /* Width.  */
 
371
    uint8_t *result =
 
372
      my_xasprintf ("%10Lf %d", 1.75L, 33, 44, 55);
 
373
    static const uint8_t expected[] = "  1.750000 33";
 
374
    ASSERT (result != NULL);
 
375
    ASSERT (u8_strcmp (result, expected) == 0);
 
376
    free (result);
 
377
  }
 
378
 
 
379
  { /* Precision.  */
 
380
    uint8_t *result =
 
381
      my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55);
 
382
    static const uint8_t expected[] = "1234 33";
 
383
    ASSERT (result != NULL);
 
384
    ASSERT (u8_strcmp (result, expected) == 0);
 
385
    free (result);
 
386
  }
 
387
 
 
388
  /* Test the support of the %F format directive.  */
 
389
 
 
390
  { /* A positive number.  */
 
391
    uint8_t *result =
 
392
      my_xasprintf ("%F %d", 12.75, 33, 44, 55);
 
393
    static const uint8_t expected[] = "12.750000 33";
 
394
    ASSERT (result != NULL);
 
395
    ASSERT (u8_strcmp (result, expected) == 0);
 
396
    free (result);
 
397
  }
 
398
 
 
399
  { /* Precision.  */
 
400
    uint8_t *result =
 
401
      my_xasprintf ("%.F %d", 1234.0, 33, 44, 55);
 
402
    static const uint8_t expected[] = "1234 33";
 
403
    ASSERT (result != NULL);
 
404
    ASSERT (u8_strcmp (result, expected) == 0);
 
405
    free (result);
 
406
  }
 
407
 
 
408
  { /* A positive number.  */
 
409
    uint8_t *result =
 
410
      my_xasprintf ("%LF %d", 12.75L, 33, 44, 55);
 
411
    static const uint8_t expected[] = "12.750000 33";
 
412
    ASSERT (result != NULL);
 
413
    ASSERT (u8_strcmp (result, expected) == 0);
 
414
    free (result);
 
415
  }
 
416
 
 
417
  { /* Precision.  */
 
418
    uint8_t *result =
 
419
      my_xasprintf ("%.LF %d", 1234.0L, 33, 44, 55);
 
420
    static const uint8_t expected[] = "1234 33";
 
421
    ASSERT (result != NULL);
 
422
    ASSERT (u8_strcmp (result, expected) == 0);
 
423
    free (result);
 
424
  }
 
425
 
 
426
  /* Test the support of the %e format directive.  */
 
427
 
 
428
  { /* A positive number.  */
 
429
    uint8_t *result =
 
430
      my_xasprintf ("%e %d", 12.75, 33, 44, 55);
 
431
    static const uint8_t expected1[] = "1.275000e+01 33";
 
432
    static const uint8_t expected2[] = "1.275000e+001 33";
 
433
    ASSERT (result != NULL);
 
434
    ASSERT (u8_strcmp (result, expected1) == 0
 
435
            || u8_strcmp (result, expected2) == 0);
 
436
    free (result);
 
437
  }
 
438
 
 
439
  { /* Width.  */
 
440
    uint8_t *result =
 
441
      my_xasprintf ("%15e %d", 1.75, 33, 44, 55);
 
442
    static const uint8_t expected1[] = "   1.750000e+00 33";
 
443
    static const uint8_t expected2[] = "  1.750000e+000 33";
 
444
    ASSERT (result != NULL);
 
445
    ASSERT (u8_strcmp (result, expected1) == 0
 
446
            || u8_strcmp (result, expected2) == 0);
 
447
    free (result);
 
448
  }
 
449
 
 
450
  { /* Precision.  */
 
451
    uint8_t *result =
 
452
      my_xasprintf ("%.e %d", 1234.0, 33, 44, 55);
 
453
    static const uint8_t expected1[] = "1e+03 33";
 
454
    static const uint8_t expected2[] = "1e+003 33";
 
455
    ASSERT (result != NULL);
 
456
    ASSERT (u8_strcmp (result, expected1) == 0
 
457
            || u8_strcmp (result, expected2) == 0);
 
458
    free (result);
 
459
  }
 
460
 
 
461
  { /* A positive number.  */
 
462
    uint8_t *result =
 
463
      my_xasprintf ("%Le %d", 12.75L, 33, 44, 55);
 
464
    static const uint8_t expected[] = "1.275000e+01 33";
 
465
    ASSERT (result != NULL);
 
466
    ASSERT (u8_strcmp (result, expected) == 0);
 
467
    free (result);
 
468
  }
 
469
 
 
470
  { /* Width.  */
 
471
    uint8_t *result =
 
472
      my_xasprintf ("%15Le %d", 1.75L, 33, 44, 55);
 
473
    static const uint8_t expected[] = "   1.750000e+00 33";
 
474
    ASSERT (result != NULL);
 
475
    ASSERT (u8_strcmp (result, expected) == 0);
 
476
    free (result);
 
477
  }
 
478
 
 
479
  { /* Precision.  */
 
480
    uint8_t *result =
 
481
      my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55);
 
482
    static const uint8_t expected[] = "1e+03 33";
 
483
    ASSERT (result != NULL);
 
484
    ASSERT (u8_strcmp (result, expected) == 0);
 
485
    free (result);
 
486
  }
 
487
 
 
488
  /* Test the support of the %g format directive.  */
 
489
 
 
490
  { /* A positive number.  */
 
491
    uint8_t *result =
 
492
      my_xasprintf ("%g %d", 12.75, 33, 44, 55);
 
493
    static const uint8_t expected[] = "12.75 33";
 
494
    ASSERT (result != NULL);
 
495
    ASSERT (u8_strcmp (result, expected) == 0);
 
496
    free (result);
 
497
  }
 
498
 
 
499
  { /* Width.  */
 
500
    uint8_t *result =
 
501
      my_xasprintf ("%10g %d", 1.75, 33, 44, 55);
 
502
    static const uint8_t expected[] = "      1.75 33";
 
503
    ASSERT (result != NULL);
 
504
    ASSERT (u8_strcmp (result, expected) == 0);
 
505
    free (result);
 
506
  }
 
507
 
 
508
  { /* Precision.  */
 
509
    uint8_t *result =
 
510
      my_xasprintf ("%.g %d", 1234.0, 33, 44, 55);
 
511
    static const uint8_t expected1[] = "1e+03 33";
 
512
    static const uint8_t expected2[] = "1e+003 33";
 
513
    ASSERT (result != NULL);
 
514
    ASSERT (u8_strcmp (result, expected1) == 0
 
515
            || u8_strcmp (result, expected2) == 0);
 
516
    free (result);
 
517
  }
 
518
 
 
519
  { /* A positive number.  */
 
520
    uint8_t *result =
 
521
      my_xasprintf ("%Lg %d", 12.75L, 33, 44, 55);
 
522
    static const uint8_t expected[] = "12.75 33";
 
523
    ASSERT (result != NULL);
 
524
    ASSERT (u8_strcmp (result, expected) == 0);
 
525
    free (result);
 
526
  }
 
527
 
 
528
  { /* Width.  */
 
529
    uint8_t *result =
 
530
      my_xasprintf ("%10Lg %d", 1.75L, 33, 44, 55);
 
531
    static const uint8_t expected[] = "      1.75 33";
 
532
    ASSERT (result != NULL);
 
533
    ASSERT (u8_strcmp (result, expected) == 0);
 
534
    free (result);
 
535
  }
 
536
 
 
537
  { /* Precision.  */
 
538
    uint8_t *result =
 
539
      my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55);
 
540
    static const uint8_t expected[] = "1e+03 33";
 
541
    ASSERT (result != NULL);
 
542
    ASSERT (u8_strcmp (result, expected) == 0);
 
543
    free (result);
 
544
  }
 
545
 
 
546
  /* Test the support of the %n format directive.  */
 
547
 
 
548
  {
 
549
    int count = -1;
 
550
    uint8_t *result =
 
551
      my_xasprintf ("%d %n", 123, &count, 33, 44, 55);
 
552
    static const uint8_t expected[] = "123 ";
 
553
    ASSERT (result != NULL);
 
554
    ASSERT (u8_strcmp (result, expected) == 0);
 
555
    ASSERT (count == 4);
 
556
    free (result);
 
557
  }
 
558
 
 
559
  /* Test the support of the POSIX/XSI format strings with positions.  */
 
560
 
 
561
  {
 
562
    uint8_t *result =
 
563
      my_xasprintf ("%2$d %1$d", 33, 55);
 
564
    static const uint8_t expected[] = "55 33";
 
565
    ASSERT (result != NULL);
 
566
    ASSERT (u8_strcmp (result, expected) == 0);
 
567
    free (result);
 
568
  }
 
569
 
 
570
  /* Test the support of the grouping flag.  */
 
571
 
 
572
  {
 
573
    uint8_t *result =
 
574
      my_xasprintf ("%'d %d", 1234567, 99);
 
575
    ASSERT (result != NULL);
 
576
    ASSERT (result[u8_strlen (result) - 1] == '9');
 
577
    free (result);
 
578
  }
 
579
 
 
580
  /* Test the support of the 'U' conversion specifier for Unicode strings.  */
 
581
 
 
582
  {
 
583
    static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
 
584
    {
 
585
      uint8_t *result =
 
586
        my_xasprintf ("%U %d", unicode_string, 33, 44, 55);
 
587
      static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33";
 
588
      ASSERT (result != NULL);
 
589
      ASSERT (u8_strcmp (result, expected) == 0);
 
590
      free (result);
 
591
    }
 
592
    { /* Width.  */
 
593
      uint8_t *result =
 
594
        my_xasprintf ("%20U %d", unicode_string, 33, 44, 55);
 
595
      static const uint8_t expected[] = "    Rafa\305\202 Maszkowski 33";
 
596
      ASSERT (result != NULL);
 
597
      ASSERT (u8_strcmp (result, expected) == 0);
 
598
      free (result);
 
599
    }
 
600
    { /* FLAG_LEFT.  */
 
601
      uint8_t *result =
 
602
        my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55);
 
603
      static const uint8_t expected[] = "Rafa\305\202 Maszkowski     33";
 
604
      ASSERT (result != NULL);
 
605
      ASSERT (u8_strcmp (result, expected) == 0);
 
606
      free (result);
 
607
    }
 
608
    { /* FLAG_ZERO: no effect.  */
 
609
      uint8_t *result =
 
610
        my_xasprintf ("%020U %d", unicode_string, 33, 44, 55);
 
611
      static const uint8_t expected[] = "    Rafa\305\202 Maszkowski 33";
 
612
      ASSERT (result != NULL);
 
613
      ASSERT (u8_strcmp (result, expected) == 0);
 
614
      free (result);
 
615
    }
 
616
  }
 
617
 
 
618
  {
 
619
    static const uint16_t unicode_string[] = /* Rafał Maszkowski */
 
620
      {
 
621
        'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
 
622
        's', 'k', 'i', 0
 
623
      };
 
624
    {
 
625
      uint8_t *result =
 
626
        my_xasprintf ("%lU %d", unicode_string, 33, 44, 55);
 
627
      static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33";
 
628
      ASSERT (result != NULL);
 
629
      ASSERT (u8_strcmp (result, expected) == 0);
 
630
      free (result);
 
631
    }
 
632
    { /* Width.  */
 
633
      uint8_t *result =
 
634
        my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55);
 
635
      static const uint8_t expected[] = "    Rafa\305\202 Maszkowski 33";
 
636
      ASSERT (result != NULL);
 
637
      ASSERT (u8_strcmp (result, expected) == 0);
 
638
      free (result);
 
639
    }
 
640
    { /* FLAG_LEFT.  */
 
641
      uint8_t *result =
 
642
        my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55);
 
643
      static const uint8_t expected[] = "Rafa\305\202 Maszkowski     33";
 
644
      ASSERT (result != NULL);
 
645
      ASSERT (u8_strcmp (result, expected) == 0);
 
646
      free (result);
 
647
    }
 
648
    { /* FLAG_ZERO: no effect.  */
 
649
      uint8_t *result =
 
650
        my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55);
 
651
      static const uint8_t expected[] = "    Rafa\305\202 Maszkowski 33";
 
652
      ASSERT (result != NULL);
 
653
      ASSERT (u8_strcmp (result, expected) == 0);
 
654
      free (result);
 
655
    }
 
656
  }
 
657
 
 
658
  {
 
659
    static const uint32_t unicode_string[] = /* Rafał Maszkowski */
 
660
      {
 
661
        'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
 
662
        's', 'k', 'i', 0
 
663
      };
 
664
    {
 
665
      uint8_t *result =
 
666
        my_xasprintf ("%llU %d", unicode_string, 33, 44, 55);
 
667
      static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33";
 
668
      ASSERT (result != NULL);
 
669
      ASSERT (u8_strcmp (result, expected) == 0);
 
670
      free (result);
 
671
    }
 
672
    { /* Width.  */
 
673
      uint8_t *result =
 
674
        my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55);
 
675
      static const uint8_t expected[] = "    Rafa\305\202 Maszkowski 33";
 
676
      ASSERT (result != NULL);
 
677
      ASSERT (u8_strcmp (result, expected) == 0);
 
678
      free (result);
 
679
    }
 
680
    { /* FLAG_LEFT.  */
 
681
      uint8_t *result =
 
682
        my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55);
 
683
      static const uint8_t expected[] = "Rafa\305\202 Maszkowski     33";
 
684
      ASSERT (result != NULL);
 
685
      ASSERT (u8_strcmp (result, expected) == 0);
 
686
      free (result);
 
687
    }
 
688
    { /* FLAG_ZERO: no effect.  */
 
689
      uint8_t *result =
 
690
        my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55);
 
691
      static const uint8_t expected[] = "    Rafa\305\202 Maszkowski 33";
 
692
      ASSERT (result != NULL);
 
693
      ASSERT (u8_strcmp (result, expected) == 0);
 
694
      free (result);
 
695
    }
 
696
  }
 
697
 
 
698
  /* Test non-ASCII characters in the format string.  */
 
699
 
 
700
  {
 
701
    uint8_t *result =
 
702
      my_xasprintf ("\304rger", 33, 44, 55);
 
703
    ASSERT (result == NULL && errno == EINVAL);
 
704
  }
 
705
}