From c9e17a9c30348ed1e04a813df627b93ea9afa46d Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 10 Nov 1999 17:55:03 +0000 Subject: Update. * misc/tst-efgcvt.c: Also test ecvt_r and fcvt_r. 1999-11-10 Andreas Jaeger --- misc/tst-efgcvt.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'misc/tst-efgcvt.c') diff --git a/misc/tst-efgcvt.c b/misc/tst-efgcvt.c index 74dd6bd8d3..598bcee1e1 100644 --- a/misc/tst-efgcvt.c +++ b/misc/tst-efgcvt.c @@ -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; -- cgit 1.4.1