]>
Commit | Line | Data |
---|---|---|
1f55ce48 UD |
1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | ||
43b9d657 UD |
4 | struct test |
5 | { | |
6 | const char *str; | |
7 | double result; | |
8 | size_t offset; | |
9 | } tests[] = | |
10 | { | |
11 | { "0xy", 0.0, 1 }, | |
12 | { "0x.y", 0.0, 1 }, | |
13 | { "0x0.y", 0.0, 4 }, | |
14 | { "0x.0y", 0.0, 4 }, | |
15 | { ".y", 0.0, 0 }, | |
16 | { "0.y", 0.0, 2 }, | |
17 | { ".0y", 0.0, 2 } | |
18 | }; | |
19 | ||
1f55ce48 UD |
20 | static int |
21 | do_test (void) | |
22 | { | |
23 | int status = 0; | |
43b9d657 | 24 | for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i) |
1f55ce48 | 25 | { |
43b9d657 UD |
26 | char *ep; |
27 | double r = strtod (tests[i].str, &ep); | |
28 | if (r != tests[i].result) | |
29 | { | |
30 | printf ("test %zu r = %g, expect %g\n", i, r, tests[i].result); | |
31 | status = 1; | |
32 | } | |
33 | if (ep != tests[i].str + tests[i].offset) | |
34 | { | |
1475e201 | 35 | printf ("test %zu strtod parsed %tu characters, expected %zu\n", |
43b9d657 UD |
36 | i, ep - tests[i].str, tests[i].offset); |
37 | status = 1; | |
38 | } | |
1f55ce48 UD |
39 | } |
40 | return status; | |
41 | } | |
42 | ||
43 | #define TEST_FUNCTION do_test () | |
44 | #include "../test-skeleton.c" |