mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-08 14:20:07 +00:00
Refactor strtod tests
This patch changes strtod* tests to use strfrom* functions.
This commit is contained in:
parent
6962682ffe
commit
bf5eea32ac
@ -1,3 +1,11 @@
|
||||
2016-10-25 Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
|
||||
|
||||
* stdlib/bug-strtod.c: Refactor based on GEN_TEST_STRTOD_FOREACH.
|
||||
* stdlib/bug-strtod2.c: Likewise.
|
||||
* stdlib/tst-strtod-round-skeleton.c: Likewise.
|
||||
* stdlib/tst-strtod6.c: Likewise.
|
||||
* stdlib/tst-strtod.h (GEN_TEST_STRTOD_FOREACH): Use strfrom.
|
||||
|
||||
2016-10-25 Gabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
|
||||
|
||||
* NEWS: Mention the addition of strfromd, strfromf, and strfroml.
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include "tst-strtod.h"
|
||||
|
||||
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
||||
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||
static int \
|
||||
test_strto ## FSUF (void) \
|
||||
{ \
|
||||
@ -45,8 +45,8 @@ test_strto ## FSUF (void) \
|
||||
{ \
|
||||
char fstr[FSTRLENMAX]; \
|
||||
char fcntstr[FSTRLENMAX]; \
|
||||
FTOSTR (fstr, sizeof (fstr), "%" FTOSTRM "g", f); \
|
||||
FTOSTR (fcntstr, sizeof (fstr), "%" FTOSTRM "g", (FTYPE) cnt); \
|
||||
FTOSTR (fstr, sizeof (fstr), "%g", f); \
|
||||
FTOSTR (fcntstr, sizeof (fstr), "%g", (FTYPE) cnt); \
|
||||
printf ("strto" #FSUF "(\"%s\") " \
|
||||
"failed for cnt == %d (%s instead of %s)\n", \
|
||||
buf, cnt, fstr, fcntstr); \
|
||||
|
@ -12,7 +12,7 @@ static const char *tests[] =
|
||||
};
|
||||
#define ntests (sizeof (tests) / sizeof (tests[0]))
|
||||
|
||||
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
||||
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||
static int \
|
||||
test_strto ## FSUF (void) \
|
||||
{ \
|
||||
|
@ -58,11 +58,11 @@
|
||||
|
||||
/* Generator to create an FTYPE member variabled named FSUF
|
||||
used to populate struct member variables. */
|
||||
#define FTYPE_MEMBER(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
||||
#define FTYPE_MEMBER(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||
FTYPE FSUF;
|
||||
|
||||
/* Likewise, but each member is of type bool. */
|
||||
#define BOOL_MEMBER(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
||||
#define BOOL_MEMBER(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||
bool FSUF;
|
||||
|
||||
#define STRUCT_FOREACH_FLOAT_FTYPE GEN_TEST_STRTOD_FOREACH (FTYPE_MEMBER)
|
||||
@ -96,13 +96,13 @@
|
||||
/* long double is special, and handled above. */
|
||||
|
||||
/* Selector for expected result field of a given type. */
|
||||
#define _ENTRY(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF, ...) \
|
||||
#define _ENTRY(FSUF, FTYPE, FTOSTR, LSUF, CSUF, ...) \
|
||||
CONCAT (CHOOSE_ ## FSUF (__VA_ARGS__), LSUF),
|
||||
#define ENTRY(...) \
|
||||
GEN_TEST_STRTOD_FOREACH (_ENTRY, __VA_ARGS__)
|
||||
|
||||
/* Selector for boolean exact tag of expected results. */
|
||||
#define _XNTRY(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF, ...) \
|
||||
#define _XNTRY(FSUF, FTYPE, FTOSTR, LSUF, CSUF, ...) \
|
||||
CHOOSE_ ## FSUF (__VA_ARGS__),
|
||||
#define XNTRY(...) \
|
||||
GEN_TEST_STRTOD_FOREACH (_XNTRY, __VA_ARGS__)
|
||||
@ -157,21 +157,19 @@ struct test {
|
||||
#define STR(x) STRX (x)
|
||||
#define FNPFXS STR (FNPFX)
|
||||
|
||||
#define GEN_ONE_TEST(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
||||
#define GEN_ONE_TEST(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||
{ \
|
||||
FTYPE f = STRTO (FSUF) (s, NULL); \
|
||||
if (f != expected->FSUF \
|
||||
|| (copysign ## CSUF) (1.0 ## LSUF, f) \
|
||||
!= (copysign ## CSUF) (1.0 ## LSUF, expected->FSUF)) \
|
||||
{ \
|
||||
CHAR efstr[FSTRLENMAX]; \
|
||||
CHAR fstr[FSTRLENMAX]; \
|
||||
FTOSTR (efstr, FSTRLENMAX, L_("%") L_(FTOSTRM) L_("a"), \
|
||||
expected->FSUF); \
|
||||
FTOSTR (fstr, FSTRLENMAX, L_("%") L_(FTOSTRM) L_("a"), f);\
|
||||
printf (FNPFXS "to" #FSUF " (" STRM ") returned " STRM \
|
||||
" not " STRM " (%s)\n", \
|
||||
s, fstr, efstr, mode_name); \
|
||||
char efstr[FSTRLENMAX]; \
|
||||
char fstr[FSTRLENMAX]; \
|
||||
FTOSTR (efstr, FSTRLENMAX, "%a", expected->FSUF); \
|
||||
FTOSTR (fstr, FSTRLENMAX, "%a", f); \
|
||||
printf (FNPFXS "to" #FSUF " (" STRM ") returned %s not " \
|
||||
"%s (%s)\n", s, fstr, efstr, mode_name); \
|
||||
if (ROUNDING_TESTS (FTYPE, rnd_mode) || exact->FSUF) \
|
||||
result = 1; \
|
||||
else \
|
||||
|
@ -23,14 +23,13 @@
|
||||
|
||||
/* Splat n variants of the same test for the various strtod functions. */
|
||||
#define GEN_TEST_STRTOD_FOREACH(mfunc, ...) \
|
||||
mfunc ( f, float, snprintf, "", f, f, ##__VA_ARGS__) \
|
||||
mfunc ( d, double, snprintf, "", , , ##__VA_ARGS__) \
|
||||
mfunc ( ld, long double, snprintf, "L", L, l, ##__VA_ARGS__)
|
||||
mfunc ( f, float, strfromf, f, f, ##__VA_ARGS__) \
|
||||
mfunc ( d, double, strfromd, , , ##__VA_ARGS__) \
|
||||
mfunc ( ld, long double, strfroml, L, l, ##__VA_ARGS__)
|
||||
/* The arguments to the generated macros are:
|
||||
FSUF - Function suffix
|
||||
FTYPE - float type
|
||||
FTOSTR - float to string func
|
||||
FTOSTRM - Optional modifier for FTOSTR format
|
||||
LSUF - Literal suffix
|
||||
CSUF - C standardish suffix for many of the math functions
|
||||
*/
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include "tst-strtod.h"
|
||||
|
||||
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
||||
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||
static int \
|
||||
test_strto ## FSUF (const char str[]) \
|
||||
{ \
|
||||
|
Loading…
Reference in New Issue
Block a user