1 #include <locale.h>
2 #include <math.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 #include "tst-strtod.h"
7
8 static const char *tests[] =
9 {
10 "inf", "Inf", "iNf", "inF", "INf", "iNF", "INF", "InF",
11 "infinity", "Infinity", "InfInity", "INFINITY"
12 };
13 #define ntests (sizeof (tests) / sizeof (tests[0]))
14
15 #define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
16 static int \
17 test_strto ## FSUF (void) \
18 { \
19 int res = 0; \
20 for (int i = 0; i < ntests; ++i) \
21 { \
22 char *endp; \
23 FTYPE d = strto ## FSUF (tests[i], &endp); \
24 if (*endp != '\0') \
25 { \
26 printf ("did not consume all of '%s'\n", tests[i]); \
27 res = 1; \
28 } \
29 if (!isinf (d)) \
30 { \
31 printf ("'%s' does not pass isinf\n", tests[i]); \
32 res = 1; \
33 } \
34 } \
35 \
36 return res; \
37 }
38
GEN_TEST_STRTOD_FOREACH(TEST_STRTOD)39 GEN_TEST_STRTOD_FOREACH (TEST_STRTOD)
40
41 static int
42 do_test (void)
43 {
44 /* The Turkish locale is notorious because tolower() maps 'I' to the
45 dotless lowercase 'i' and toupper() maps 'i' to an 'I' with a dot
46 above. */
47 if (setlocale (LC_ALL, "tr_TR.UTF-8") == NULL)
48 {
49 puts ("cannot set locale");
50 return 0;
51 }
52
53 return STRTOD_TEST_FOREACH (test_strto);
54 }
55
56 #define TEST_FUNCTION do_test ()
57 #include "../test-skeleton.c"
58