[PATCHv2,2/6] Refactor bug-strtod2.c to be type generic

Message ID 3d834fdf00832a3688f48875c295453a651bc4b7.1463524479.git.murphyp@linux.vnet.ibm.com
State Committed
Delegated to: Joseph Myers
Headers

Commit Message

Paul E. Murphy May 17, 2016, 10:52 p.m. UTC
  This only tested for strtod. This expands the testing to
all variants of strto*.

	* stdlib/bug-strtod2.c (do_test): Refactor strtod usage into ...
	[TEST_STRTOD]: New macro.
	[TEST_FUNCTION]: Redefine to use STRTOD_TEST_FOREACH
---
 stdlib/bug-strtod2.c | 47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)
  

Comments

Joseph Myers May 20, 2016, 8 p.m. UTC | #1
This patch is OK.
  
Paul E. Murphy May 23, 2016, 8:48 p.m. UTC | #2
On 05/20/2016 03:00 PM, Joseph Myers wrote:
> This patch is OK.
> 

Thanks, Committed as b26053d.
  

Patch

diff --git a/stdlib/bug-strtod2.c b/stdlib/bug-strtod2.c
index a1f037c..cd13e9a 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 ()