]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdio-common/tst-fphex.c
Prepare vfscanf to use __strtof128_internal
[thirdparty/glibc.git] / stdio-common / tst-fphex.c
CommitLineData
90d59870
RM
1/* Test program for %a printf formats. */
2
d10b132b 3#include <array_length.h>
90d59870
RM
4#include <stdio.h>
5#include <string.h>
6
aea5d727 7#ifndef WIDE
65b81130 8# define STR_LEN strlen
65b81130 9# define STR_CMP strcmp
65b81130 10# define SPRINT snprintf
65b81130 11# define CHAR_T char
65b81130 12# define PRINT printf
65b81130 13# define L_(Str) Str
aea5d727
UD
14# define S "%s"
15#else
16# define STR_LEN wcslen
17# define SPRINT swprintf
18# define STR_CMP wcscmp
19# define CHAR_T wchar_t
20# define PRINT wprintf
21# define L_(Str) L##Str
22# define S "%ls"
65b81130
MP
23#endif
24
90d59870
RM
25struct testcase
26{
27 double value;
65b81130
MP
28 const CHAR_T *fmt;
29 const CHAR_T *expect;
90d59870
RM
30};
31
32static const struct testcase testcases[] =
33 {
65b81130
MP
34 { 0x0.0030p+0, L_("%a"), L_("0x1.8p-11") },
35 { 0x0.0040p+0, L_("%a"), L_("0x1p-10") },
36 { 0x0.0030p+0, L_("%040a"), L_("0x00000000000000000000000000000001.8p-11") },
37 { 0x0.0040p+0, L_("%040a"), L_("0x0000000000000000000000000000000001p-10") },
38 { 0x0.0040p+0, L_("%40a"), L_(" 0x1p-10") },
39 { 0x0.0040p+0, L_("%#40a"), L_(" 0x1.p-10") },
40 { 0x0.0040p+0, L_("%-40a"), L_("0x1p-10 ") },
41 { 0x0.0040p+0, L_("%#-40a"), L_("0x1.p-10 ") },
42 { 0x0.0030p+0, L_("%040e"), L_("00000000000000000000000000007.324219e-04") },
43 { 0x0.0040p+0, L_("%040e"), L_("00000000000000000000000000009.765625e-04") },
90d59870
RM
44 };
45
46
47static int
65b81130 48do_test (void)
90d59870
RM
49{
50 const struct testcase *t;
51 int result = 0;
52
d10b132b 53 for (t = testcases; t < array_end (testcases); ++t)
90d59870 54 {
65b81130 55 CHAR_T buf[1024];
d10b132b 56 int n = SPRINT (buf, array_length (buf), t->fmt, t->value);
65b81130 57 if (n != STR_LEN (t->expect) || STR_CMP (buf, t->expect) != 0)
90d59870 58 {
aea5d727
UD
59 PRINT (L_("" S "\tExpected \"" S "\" (%Zu)\n\tGot \""
60 S "\" (%d, %Zu)\n"),
61 t->fmt, t->expect, STR_LEN (t->expect),
65b81130 62 buf, n, STR_LEN (buf));
90d59870
RM
63 result = 1;
64 }
65 }
66
67 return result;
68}
69
65b81130 70#define TEST_FUNCTION do_test ()
90d59870 71#include "../test-skeleton.c"