1 | #include <math.h> |
---|---|
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | #include <string.h> |
5 | |
6 | #include "tst-strtod.h" |
7 | |
8 | #define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \ |
9 | static int \ |
10 | test_strto ## FSUF (const char str[]) \ |
11 | { \ |
12 | char *endp; \ |
13 | int result = 0; \ |
14 | puts (str); \ |
15 | FTYPE d = strto ## FSUF (str, &endp); \ |
16 | if (!isnan (d)) \ |
17 | { \ |
18 | puts ("strto" #FSUF " did not return NAN"); \ |
19 | result = 1; \ |
20 | } \ |
21 | if (issignaling (d)) \ |
22 | { \ |
23 | puts ("strto" #FSUF " returned a sNAN"); \ |
24 | result = 1; \ |
25 | } \ |
26 | if (strcmp (endp, "something") != 0) \ |
27 | { \ |
28 | puts ("strto" #FSUF " set incorrect end pointer"); \ |
29 | result = 1; \ |
30 | } \ |
31 | return result; \ |
32 | } |
33 | |
34 | GEN_TEST_STRTOD_FOREACH (TEST_STRTOD); |
35 | |
36 | static int |
37 | do_test (void) |
38 | { |
39 | int result = 0; |
40 | |
41 | result |= STRTOD_TEST_FOREACH (test_strto, "NaN(blabla)something"); |
42 | result |= STRTOD_TEST_FOREACH (test_strto, "NaN(1234)something"); |
43 | /* UINT32_MAX. */ |
44 | result |= STRTOD_TEST_FOREACH (test_strto, "NaN(4294967295)something"); |
45 | /* UINT64_MAX. */ |
46 | result |= STRTOD_TEST_FOREACH (test_strto, |
47 | "NaN(18446744073709551615)something"); |
48 | /* The case of zero is special in that "something" has to be done to make the |
49 | mantissa different from zero, which would mean infinity instead of |
50 | NaN. */ |
51 | result |= STRTOD_TEST_FOREACH (test_strto, "NaN(0)something"); |
52 | |
53 | return result; |
54 | } |
55 | |
56 | #define TEST_FUNCTION do_test () |
57 | #include "../test-skeleton.c" |
58 |