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 NNBSP "\xe2\x80\xaf" |
25 | |
26 | #define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \ |
27 | static const struct \ |
28 | { \ |
29 | const char *in; \ |
30 | const char *out; \ |
31 | FTYPE expected; \ |
32 | } tests_strto ## FSUF[] = \ |
33 | { \ |
34 | { "000"NNBSP"000"NNBSP"000", "", 0.0 ## LSUF }, \ |
35 | { "1"NNBSP"000"NNBSP"000,5x", "x", 1000000.5 ## LSUF }, \ |
36 | /* Bug 30964 */ \ |
37 | { "10"NNBSP NNBSP"200", NNBSP NNBSP"200", 10.0 ## LSUF } \ |
38 | }; \ |
39 | \ |
40 | static int \ |
41 | test_strto ## FSUF (void) \ |
42 | { \ |
43 | int status = 0; \ |
44 | \ |
45 | for (int i = 0; \ |
46 | i < sizeof (tests_strto ## FSUF) / sizeof (tests_strto ## FSUF[0]); \ |
47 | ++i) \ |
48 | { \ |
49 | char *ep; \ |
50 | FTYPE r = __strto ## FSUF ## _internal (tests_strto ## FSUF[i].in, \ |
51 | &ep, 1); \ |
52 | \ |
53 | if (strcmp (ep, tests_strto ## FSUF[i].out) != 0) \ |
54 | { \ |
55 | printf ("%d: got rest string \"%s\", expected \"%s\"\n", \ |
56 | i, ep, tests_strto ## FSUF[i].out); \ |
57 | status = 1; \ |
58 | } \ |
59 | \ |
60 | if (r != tests_strto ## FSUF[i].expected) \ |
61 | { \ |
62 | char buf1[FSTRLENMAX], buf2[FSTRLENMAX]; \ |
63 | FTOSTR (buf1, sizeof (buf1), "%g", r); \ |
64 | FTOSTR (buf2, sizeof (buf2), "%g", \ |
65 | tests_strto ## FSUF[i].expected); \ |
66 | printf ("%d: got wrong results %s, expected %s\n", \ |
67 | i, buf1, buf2); \ |
68 | status = 1; \ |
69 | } \ |
70 | } \ |
71 | \ |
72 | return status; \ |
73 | } |
74 | |
75 | GEN_TEST_STRTOD_FOREACH (TEST_STRTOD) |
76 | |
77 | static int |
78 | do_test (void) |
79 | { |
80 | if (setlocale (LC_ALL, "cs_CZ.UTF-8" ) == NULL) |
81 | { |
82 | puts (s: "could not set locale" ); |
83 | return 1; |
84 | } |
85 | |
86 | return STRTOD_TEST_FOREACH (test_strto); |
87 | } |
88 | |
89 | #define TEST_FUNCTION do_test () |
90 | #include "../test-skeleton.c" |
91 | |