1 | #include <locale.h> |
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | #include <string.h> |
5 | |
6 | #define NNBSP "\xe2\x80\xaf" |
7 | |
8 | static const struct |
9 | { |
10 | const char *in; |
11 | const char *out; |
12 | double expected; |
13 | } tests[] = |
14 | { |
15 | { "000" NNBSP"000" NNBSP"000" , "" , 0.0 }, |
16 | { "1" NNBSP"000" NNBSP"000,5x" , "x" , 1000000.5 } |
17 | }; |
18 | #define NTESTS (sizeof (tests) / sizeof (tests[0])) |
19 | |
20 | |
21 | static int |
22 | do_test (void) |
23 | { |
24 | if (setlocale (LC_ALL, "cs_CZ.UTF-8" ) == NULL) |
25 | { |
26 | puts (s: "could not set locale" ); |
27 | return 1; |
28 | } |
29 | |
30 | int status = 0; |
31 | |
32 | for (int i = 0; i < NTESTS; ++i) |
33 | { |
34 | char *ep; |
35 | double r = __strtod_internal (tests[i].in, &ep, 1); |
36 | |
37 | if (strcmp (ep, tests[i].out) != 0) |
38 | { |
39 | printf (format: "%d: got rest string \"%s\", expected \"%s\"\n" , |
40 | i, ep, tests[i].out); |
41 | status = 1; |
42 | } |
43 | |
44 | if (r != tests[i].expected) |
45 | { |
46 | printf (format: "%d: got wrong results %g, expected %g\n" , |
47 | i, r, tests[i].expected); |
48 | status = 1; |
49 | } |
50 | } |
51 | |
52 | return status; |
53 | } |
54 | |
55 | #define TEST_FUNCTION do_test () |
56 | #include "../test-skeleton.c" |
57 | |