[2/5] Refactor bug-strtod2.c to be type generic

Message ID 2d0b40477a4a647a4f6792e68bd735554db1dd6d.1463433827.git.murphyp@linux.vnet.ibm.com
State Superseded
Delegated to: Joseph Myers
Headers

Commit Message

Paul E. Murphy May 16, 2016, 10:27 p.m. UTC
  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(-)
  

Comments

Joseph Myers May 17, 2016, 9:26 p.m. UTC | #1
On Mon, 16 May 2016, Paul E. Murphy wrote:

> +  if (setlocale (LC_ALL, "tr_TR.UTF-8") == NULL)			\
> +    {									\
> +      puts ("cannot set locale");					\
> +      return 0;								\
> +    }									\

I think it's more natural for this to go once in do_test, before calling 
STRTOD_TEST_FOREACH, rather than repeating this for each type.
  

Patch

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 <stdio.h>
 #include <stdlib.h>
 
+#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"