|
Packit |
6c4009 |
/* Tests for strfromf, strfromd, strfroml functions.
|
|
Packit |
6c4009 |
Copyright (C) 2016-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <float.h>
|
|
Packit |
6c4009 |
#include <math.h>
|
|
Packit |
6c4009 |
#include <locale.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include "tst-strtod.h"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define _CONCAT(a, b) a ## b
|
|
Packit |
6c4009 |
#define CONCAT(a, b) _CONCAT (a, b)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Generator to create an FTYPE member variabled named FSUF
|
|
Packit |
6c4009 |
* used to populate struct member variables. */
|
|
Packit |
6c4009 |
#define FTYPE_MEMBER(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
|
Packit |
6c4009 |
FTYPE FSUF;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define STRUCT_FOREACH_FLOAT_FTYPE GEN_TEST_STRTOD_FOREACH (FTYPE_MEMBER)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define ENTRY(FSUF, FTYPE, FTOSTR, LSUF, CSUF, ...) \
|
|
Packit |
6c4009 |
CONCAT (__VA_ARGS__, LSUF),
|
|
Packit |
6c4009 |
/* This is hacky way around the seemingly unavoidable macro
|
|
Packit |
6c4009 |
* expansion of the INFINITY or HUGE_VAL like macros in the
|
|
Packit |
6c4009 |
* above. It is assumed the compiler will implicitly convert
|
|
Packit |
6c4009 |
* the infinity correctly. */
|
|
Packit |
6c4009 |
#define INF INFINITY + 0.0
|
|
Packit |
6c4009 |
#define NAN_ NAN + 0.0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct test_input
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
STRUCT_FOREACH_FLOAT_FTYPE
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
struct test {
|
|
Packit |
6c4009 |
const char *s;
|
|
Packit |
6c4009 |
const char *fmt;
|
|
Packit |
6c4009 |
int size;
|
|
Packit |
6c4009 |
int rc;
|
|
Packit |
6c4009 |
struct test_input t;
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
#define TEST(s, fmt, size, rc, val) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
s, fmt, size, rc, { GEN_TEST_STRTOD_FOREACH (ENTRY, val) } \
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
/* Hexadecimal tests. */
|
|
Packit |
6c4009 |
struct htests
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
const char *fmt;
|
|
Packit |
6c4009 |
const char *exp[4];
|
|
Packit |
6c4009 |
struct test_input t;
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
#define HTEST(fmt, exp1, exp2, exp3, exp4, val) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
fmt, exp1, exp2, exp3, exp4, { GEN_TEST_STRTOD_FOREACH (ENTRY, val) } \
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define TEST_STRFROM(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
|
Packit |
6c4009 |
static int \
|
|
Packit |
6c4009 |
test_ ## FSUF (void) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
char buf[50], sbuf[5]; \
|
|
Packit |
6c4009 |
int status = 0; \
|
|
Packit |
6c4009 |
int i, rc = 0, rc1 = 0; \
|
|
Packit |
6c4009 |
for (i = 0; i < sizeof (stest) / sizeof (stest[0]); i++) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
rc = FTOSTR (sbuf, stest[i].size, stest[i].fmt, stest[i].t.FSUF); \
|
|
Packit |
6c4009 |
rc1 = (strcmp (sbuf, stest[i].s) != 0) || (rc != stest[i].rc); \
|
|
Packit |
6c4009 |
if (rc1) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
printf (#FTOSTR ": got %s (%d), expected %s (%d)\n", \
|
|
Packit |
6c4009 |
sbuf, rc, stest[i].s, stest[i].rc); \
|
|
Packit |
6c4009 |
status++; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
rc = FTOSTR (buf, tests[i].size, tests[i].fmt, tests[i].t.FSUF); \
|
|
Packit |
6c4009 |
rc1 = (strcmp (buf, tests[i].s) != 0) || (rc != tests[i].rc); \
|
|
Packit |
6c4009 |
if (rc1) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
printf (#FTOSTR ": got %s (%d), expected %s (%d)\n", \
|
|
Packit |
6c4009 |
buf, rc, tests[i].s, tests[i].rc); \
|
|
Packit |
6c4009 |
status++; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
for (i = 0; i < sizeof (htest) / sizeof (htest[0]); i++) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
rc = FTOSTR (buf, 50, htest[i].fmt, htest[i].t.FSUF); \
|
|
Packit |
6c4009 |
if (strcmp (buf, htest[i].exp[0]) == 0 || \
|
|
Packit |
6c4009 |
strcmp (buf, htest[i].exp[1]) == 0 || \
|
|
Packit |
6c4009 |
strcmp (buf, htest[i].exp[2]) == 0 || \
|
|
Packit |
6c4009 |
strcmp (buf, htest[i].exp[3]) == 0) \
|
|
Packit |
6c4009 |
continue; \
|
|
Packit |
6c4009 |
else \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
printf (#FTOSTR ": got %s (%d), expected %s or %s or %s " \
|
|
Packit |
6c4009 |
"or %s\n", buf, rc, htest[i].exp[0], htest[i].exp[1], \
|
|
Packit |
6c4009 |
htest[i].exp[2], htest[i].exp[3]); \
|
|
Packit |
6c4009 |
status++; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
return status; \
|
|
Packit |
6c4009 |
}
|