[BZ #9880]
[glibc.git] / stdio-common / tst-fphex.c
blob212e4ed9ec24b7f03917625d1c4c516245c58370
1 /* Test program for %a printf formats. */
3 #include <stdio.h>
4 #include <string.h>
6 struct testcase
8 double value;
9 const char *fmt;
10 const char *expect;
13 static const struct testcase testcases[] =
15 { 0x0.0030p+0, "%a", "0x1.8p-11" },
16 { 0x0.0040p+0, "%a", "0x1p-10" },
17 { 0x0.0030p+0, "%040a", "0x00000000000000000000000000000001.8p-11" },
18 { 0x0.0040p+0, "%040a", "0x0000000000000000000000000000000001p-10" },
19 { 0x0.0040p+0, "%40a", " 0x1p-10" },
20 { 0x0.0040p+0, "%#40a", " 0x1.p-10" },
21 { 0x0.0040p+0, "%-40a", "0x1p-10 " },
22 { 0x0.0040p+0, "%#-40a", "0x1.p-10 " },
23 { 0x0.0030p+0, "%040e", "00000000000000000000000000007.324219e-04" },
24 { 0x0.0040p+0, "%040e", "00000000000000000000000000009.765625e-04" },
28 static int
29 do_test (int argc, char **argv)
31 const struct testcase *t;
32 int result = 0;
34 for (t = testcases;
35 t < &testcases[sizeof testcases / sizeof testcases[0]];
36 ++t)
38 char buf[1024];
39 int n = snprintf (buf, sizeof buf, t->fmt, t->value);
40 if (n != strlen (t->expect) || strcmp (buf, t->expect) != 0)
42 printf ("%s\tExpected \"%s\" (%Zu)\n\tGot \"%s\" (%d, %Zu)\n",
43 t->fmt, t->expect, strlen (t->expect), buf, n, strlen (buf));
44 result = 1;
48 return result;
51 #include "../test-skeleton.c"