summary refs log tree commit diff
path: root/stdlib/bug-strtod2.c
diff options
context:
space:
mode:
authorPaul E. Murphy <murphyp@linux.vnet.ibm.com>2016-05-06 16:13:29 -0500
committerPaul E. Murphy <murphyp@linux.vnet.ibm.com>2016-05-23 14:13:11 -0500
commitb26053dd9a0170b58bb01226056e3140b1fb9911 (patch)
tree2e5a15f64a6250b3722d6107adabc198b29f6ea3 /stdlib/bug-strtod2.c
parentdba0832af1eeb0d749aec072ce20f9811fb4b7d6 (diff)
downloadglibc-b26053dd9a0170b58bb01226056e3140b1fb9911.tar.gz
glibc-b26053dd9a0170b58bb01226056e3140b1fb9911.tar.xz
glibc-b26053dd9a0170b58bb01226056e3140b1fb9911.zip
Refactor bug-strtod2.c to be type generic
This only tested for strtod. This expands the testing to
all variants of strto*.
Diffstat (limited to 'stdlib/bug-strtod2.c')
-rw-r--r--stdlib/bug-strtod2.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/stdlib/bug-strtod2.c b/stdlib/bug-strtod2.c
index a1f037cdc8..cd13e9aa5b 100644
--- a/stdlib/bug-strtod2.c
+++ b/stdlib/bug-strtod2.c
@@ -3,6 +3,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "tst-strtod.h"
+
 static const char *tests[] =
   {
     "inf", "Inf", "iNf", "inF", "INf", "iNF", "INF", "InF",
@@ -10,6 +12,32 @@ static const char *tests[] =
   };
 #define ntests (sizeof (tests) / sizeof (tests[0]))
 
+#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF)		\
+static int								\
+test_strto ## FSUF (void)						\
+{									\
+  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;								\
+}
+
+GEN_TEST_STRTOD_FOREACH (TEST_STRTOD)
+
 static int
 do_test (void)
 {
@@ -22,24 +50,7 @@ do_test (void)
       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;
+  return STRTOD_TEST_FOREACH (test_strto);
 }
 
 #define TEST_FUNCTION do_test ()