1 /* Tests for strfromf, strfromd, strfroml functions.
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
26 #include "tst-strtod.h"
28 #define _CONCAT(a, b) a ## b
29 #define CONCAT(a, b) _CONCAT (a, b)
31 /* Generator to create an FTYPE member variabled named FSUF
32 * used to populate struct member variables. */
33 #define FTYPE_MEMBER(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
36 #define STRUCT_FOREACH_FLOAT_FTYPE GEN_TEST_STRTOD_FOREACH (FTYPE_MEMBER)
38 #define ENTRY(FSUF, FTYPE, FTOSTR, LSUF, CSUF, ...) \
39 CONCAT (__VA_ARGS__, LSUF),
40 /* This is hacky way around the seemingly unavoidable macro
41 * expansion of the INFINITY or HUGE_VAL like macros in the
42 * above. It is assumed the compiler will implicitly convert
43 * the infinity correctly. */
44 #define INF INFINITY + 0.0
45 #define NAN_ NAN + 0.0
49 STRUCT_FOREACH_FLOAT_FTYPE
58 #define TEST(s, fmt, size, rc, val) \
60 s, fmt, size, rc, { GEN_TEST_STRTOD_FOREACH (ENTRY, val) } \
62 /* Hexadecimal tests. */
69 #define HTEST(fmt, exp1, exp2, exp3, exp4, val) \
71 fmt, exp1, exp2, exp3, exp4, { GEN_TEST_STRTOD_FOREACH (ENTRY, val) } \
74 #define TEST_STRFROM(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
76 test_ ## FSUF (void) \
78 char buf[50], sbuf[5]; \
80 int i, rc = 0, rc1 = 0; \
81 for (i = 0; i < sizeof (stest) / sizeof (stest[0]); i++) \
83 rc = FTOSTR (sbuf, stest[i].size, stest[i].fmt, stest[i].t.FSUF); \
84 rc1 = (strcmp (sbuf, stest[i].s) != 0) || (rc != stest[i].rc); \
87 printf (#FTOSTR ": got %s (%d), expected %s (%d)\n", \
88 sbuf, rc, stest[i].s, stest[i].rc); \
92 for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) \
94 rc = FTOSTR (buf, tests[i].size, tests[i].fmt, tests[i].t.FSUF); \
95 rc1 = (strcmp (buf, tests[i].s) != 0) || (rc != tests[i].rc); \
98 printf (#FTOSTR ": got %s (%d), expected %s (%d)\n", \
99 buf, rc, tests[i].s, tests[i].rc); \
103 for (i = 0; i < sizeof (htest) / sizeof (htest[0]); i++) \
105 rc = FTOSTR (buf, 50, htest[i].fmt, htest[i].t.FSUF); \
106 if (strcmp (buf, htest[i].exp[0]) == 0 || \
107 strcmp (buf, htest[i].exp[1]) == 0 || \
108 strcmp (buf, htest[i].exp[2]) == 0 || \
109 strcmp (buf, htest[i].exp[3]) == 0) \
113 printf (#FTOSTR ": got %s (%d), expected %s or %s or %s " \
114 "or %s\n", buf, rc, htest[i].exp[0], htest[i].exp[1], \
115 htest[i].exp[2], htest[i].exp[3]); \