* misc/tst-efgcvt.c: Also test ecvt_r and fcvt_r.

1999-11-10  Andreas Jaeger  <aj@suse.de>
This commit is contained in:
Ulrich Drepper 1999-11-10 17:55:03 +00:00
parent b9d3d9f726
commit c9e17a9c30
2 changed files with 47 additions and 0 deletions

View file

@ -1,3 +1,7 @@
1999-11-10 Andreas Jaeger <aj@suse.de>
* misc/tst-efgcvt.c: Also test ecvt_r and fcvt_r.
1999-11-10 Andreas Jaeger <aj@suse.de>
* string/strsignal.c (strsignal): Correct check for snprintf

View file

@ -36,6 +36,8 @@ typedef struct
typedef char * ((*efcvt_func) (double, int, int *, int *));
typedef int ((*efcvt_r_func) (double, int, int *, int *, char *, size_t));
static testcase ecvt_tests[] =
{
@ -96,6 +98,21 @@ output_error (const char *name, double value, int ndigit,
++error_count;
}
void
output_r_error (const char *name, double value, int ndigit,
const char *exp_p, int exp_decpt, int exp_sign, int exp_return,
char *res_p, int res_decpt, int res_sign, int res_return)
{
printf ("%s returned wrong result for value: %f, ndigits: %d\n",
name, value, ndigit);
printf ("Result was buf: \"%s\", decpt: %d, sign: %d return value: %d\n",
res_p, res_decpt, res_sign, res_return);
printf ("Should be buf: \"%s\", decpt: %d, sign: %d\n",
exp_p, exp_decpt, exp_sign, exp_return);
++error_count;
}
void
test (testcase tests[], efcvt_func efcvt, const char *name)
{
@ -117,6 +134,30 @@ test (testcase tests[], efcvt_func efcvt, const char *name)
}
}
void
test_r (testcase tests[], efcvt_r_func efcvt_r, const char *name)
{
int no = 0;
int decpt, sign, res;
char buf [1024];
while (tests[no].value != -1.0)
{
res = efcvt_r (tests[no].value, tests[no].ndigit, &decpt, &sign,
buf, sizeof (buf));
if (res != 0
|| decpt != tests[no].decpt
|| sign != (tests[no].value < 0)
|| strcmp (buf, tests[no].result) != 0)
output_r_error (name, tests[no].value, tests[no].ndigit,
tests[no].result, tests[no].decpt, 0,
(tests[no].value < 0),
buf, decpt, sign, res);
++no;
}
}
void
special (void)
{
@ -158,6 +199,8 @@ main (void)
{
test (ecvt_tests, ecvt, "ecvt");
test (fcvt_tests, fcvt, "fcvt");
test_r (ecvt_tests, ecvt_r, "ecvt_r");
test_r (fcvt_tests, fcvt_r, "fcvt_r");
special ();
return error_count;