From patchwork Mon May 16 22:27:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. Murphy" X-Patchwork-Id: 12298 X-Patchwork-Delegate: joseph@codesourcery.com Received: (qmail 94800 invoked by alias); 16 May 2016 22:27:33 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 94703 invoked by uid 89); 16 May 2016 22:27:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=notorious, Hx-languages-length:2172, 36 X-HELO: e38.co.us.ibm.com X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: murphyp@linux.vnet.ibm.com X-IBM-RcptTo: libc-alpha@sourceware.org From: "Paul E. Murphy" To: libc-alpha@sourceware.org Subject: [PATCH 2/5] Refactor bug-strtod2.c to be type generic Date: Mon, 16 May 2016 17:27:18 -0500 Message-Id: <2d0b40477a4a647a4f6792e68bd735554db1dd6d.1463433827.git.murphyp@linux.vnet.ibm.com> In-Reply-To: References: In-Reply-To: References: X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16051622-0029-0000-0000-00002B8F296F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused This only tested for strtod. This expands the testing to all variants of strto*. * stdlib/bug-strtod2.c (do_test): Refactor into ... [TEST_STRTOD]: New macro. [TEST_FUNCTION]: Redefine to use STRTOD_TEST_FOREACH --- stdlib/bug-strtod2.c | 63 ++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/stdlib/bug-strtod2.c b/stdlib/bug-strtod2.c index a1f037c..64e9be2 100644 --- a/stdlib/bug-strtod2.c +++ b/stdlib/bug-strtod2.c @@ -3,6 +3,8 @@ #include #include +#include "tst-strtod.h" + static const char *tests[] = { "inf", "Inf", "iNf", "inF", "INf", "iNF", "INF", "InF", @@ -10,37 +12,40 @@ static const char *tests[] = }; #define ntests (sizeof (tests) / sizeof (tests[0])) -static int -do_test (void) -{ +#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \ +static int \ +test_strto ## FSUF (void) \ +{ \ /* The Turkish locale is notorious because tolower() maps 'I' to the dotless lowercase 'i' and toupper() maps 'i' to an 'I' with a dot - above. */ - if (setlocale (LC_ALL, "tr_TR.UTF-8") == NULL) - { - puts ("cannot set locale"); - return 0; - } - - int res = 0; - for (int i = 0; i < ntests; ++i) - { - char *endp; - double d = strtod (tests[i], &endp); - if (*endp != '\0') - { - printf ("did not consume all of '%s'\n", tests[i]); - res = 1; - } - if (!isinf (d)) - { - printf ("'%s' does not pass isinf\n", tests[i]); - res = 1; - } - } - - return res; + above. */ \ + if (setlocale (LC_ALL, "tr_TR.UTF-8") == NULL) \ + { \ + puts ("cannot set locale"); \ + return 0; \ + } \ + \ + int res = 0; \ + for (int i = 0; i < ntests; ++i) \ + { \ + char *endp; \ + FTYPE d = strto ## FSUF (tests[i], &endp); \ + if (*endp != '\0') \ + { \ + printf ("did not consume all of '%s'\n", tests[i]); \ + res = 1; \ + } \ + if (!isinf (d)) \ + { \ + printf ("'%s' does not pass isinf\n", tests[i]); \ + res = 1; \ + } \ + } \ + \ + return res; \ } -#define TEST_FUNCTION do_test () +GEN_TEST_STRTOD_FOREACH (TEST_STRTOD) + +#define TEST_FUNCTION STRTOD_TEST_FOREACH (test_strto) #include "../test-skeleton.c"