1 | #include <locale.h> |
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | #include <string.h> |
5 | |
6 | #include "tst-strtod.h" |
7 | |
8 | /* This tests internal interfaces, which are only defined for types |
9 | with distinct ABIs, so disable testing for types without distinct |
10 | ABIs. */ |
11 | #undef IF_FLOAT32 |
12 | #define IF_FLOAT32(x) |
13 | #undef IF_FLOAT64 |
14 | #define IF_FLOAT64(x) |
15 | #undef IF_FLOAT32X |
16 | #define IF_FLOAT32X(x) |
17 | #undef IF_FLOAT64X |
18 | #define IF_FLOAT64X(x) |
19 | #if !__HAVE_DISTINCT_FLOAT128 |
20 | # undef IF_FLOAT128 |
21 | # define IF_FLOAT128(x) |
22 | #endif |
23 | |
24 | #define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \ |
25 | static const struct \ |
26 | { \ |
27 | const char *in; \ |
28 | const char *out; \ |
29 | FTYPE expected; \ |
30 | } tests_strto ## FSUF[] = \ |
31 | { \ |
32 | { "000,,,e1", ",,,e1", 0.0 ## LSUF }, \ |
33 | { "000e1", "", 0.0 ## LSUF }, \ |
34 | { "000,1e1", ",1e1", 0.0 ## LSUF } \ |
35 | }; \ |
36 | \ |
37 | static int \ |
38 | test_strto ## FSUF (void) \ |
39 | { \ |
40 | int status = 0; \ |
41 | \ |
42 | for (int i = 0; \ |
43 | i < sizeof (tests_strto ## FSUF) / sizeof (tests_strto ## FSUF[0]); \ |
44 | ++i) \ |
45 | { \ |
46 | char *ep; \ |
47 | FTYPE r = __strto ## FSUF ## _internal (tests_strto ## FSUF[i].in, \ |
48 | &ep, 1); \ |
49 | \ |
50 | if (strcmp (ep, tests_strto ## FSUF[i].out) != 0) \ |
51 | { \ |
52 | printf ("%d: got rest string \"%s\", expected \"%s\"\n", \ |
53 | i, ep, tests_strto ## FSUF[i].out); \ |
54 | status = 1; \ |
55 | } \ |
56 | \ |
57 | if (r != tests_strto ## FSUF[i].expected) \ |
58 | { \ |
59 | char buf1[FSTRLENMAX], buf2[FSTRLENMAX]; \ |
60 | FTOSTR (buf1, sizeof (buf1), "%g", r); \ |
61 | FTOSTR (buf2, sizeof (buf2), "%g", \ |
62 | tests_strto ## FSUF[i].expected); \ |
63 | printf ("%d: got wrong results %s, expected %s\n", \ |
64 | i, buf1, buf2); \ |
65 | status = 1; \ |
66 | } \ |
67 | } \ |
68 | \ |
69 | return status; \ |
70 | } |
71 | |
72 | GEN_TEST_STRTOD_FOREACH (TEST_STRTOD) |
73 | |
74 | static int |
75 | do_test (void) |
76 | { |
77 | if (setlocale (LC_ALL, "en_US.ISO-8859-1" ) == NULL) |
78 | { |
79 | puts (s: "could not set locale" ); |
80 | return 1; |
81 | } |
82 | |
83 | return STRTOD_TEST_FOREACH (test_strto); |
84 | } |
85 | |
86 | #define TEST_FUNCTION do_test () |
87 | #include "../test-skeleton.c" |
88 | |