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