This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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 <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"
-- 
2.4.11


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]