Guard against FreeBSD 6.1 bug.
[gnulib.git] / tests / test-vasprintf-posix.c
index 5b43891..4333622 100644 (file)
@@ -21,7 +21,7 @@
 # include <config.h>
 #endif
 
-#include "vasprintf.h"
+#include <stdio.h>
 
 #include <stdarg.h>
 #include <stddef.h>
 
 #define ASSERT(expr) if (!(expr)) abort ();
 
+/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
+#ifdef __DECC
+static double
+NaN ()
+{
+  static double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaN() (0.0 / 0.0)
+#endif
+
 static void
 test_function (int (*my_asprintf) (char **, const char *, ...))
 {
@@ -80,7 +92,6 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     free (result);
   }
 
-#if HAVE_LONG_DOUBLE
   {
     char *result;
     int retval =
@@ -90,7 +101,6 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     ASSERT (retval == strlen (result));
     free (result);
   }
-#endif
 
   /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
      output of floating-point numbers.  */
@@ -164,7 +174,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
   { /* NaN.  */
     char *result;
     int retval =
-      my_asprintf (&result, "%a %d", 0.0 / 0.0, 33, 44, 55);
+      my_asprintf (&result, "%a %d", NaN (), 33, 44, 55);
     ASSERT (result != NULL);
     ASSERT (strcmp (result, "nan 33") == 0);
     ASSERT (retval == strlen (result));
@@ -385,6 +395,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     int retval =
       my_asprintf (&result, "%010a %d", 1.0 / 0.0, 33, 44, 55);
     ASSERT (result != NULL);
+    /* "0000000inf 33" is not a valid result; see
+       <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
     ASSERT (strcmp (result, "       inf 33") == 0);
     ASSERT (retval == strlen (result));
     free (result);
@@ -393,15 +405,15 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
   { /* FLAG_ZERO with NaN.  */
     char *result;
     int retval =
-      my_asprintf (&result, "%010a %d", 0.0 / 0.0, 33, 44, 55);
+      my_asprintf (&result, "%010a %d", NaN (), 33, 44, 55);
     ASSERT (result != NULL);
+    /* "0000000nan 33" is not a valid result; see
+       <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
     ASSERT (strcmp (result, "       nan 33") == 0);
     ASSERT (retval == strlen (result));
     free (result);
   }
 
-#if HAVE_LONG_DOUBLE
-
   { /* A positive number.  */
     char *result;
     int retval =
@@ -693,6 +705,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     int retval =
       my_asprintf (&result, "%010La %d", 1.0L / 0.0L, 33, 44, 55);
     ASSERT (result != NULL);
+    /* "0000000inf 33" is not a valid result; see
+       <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
     ASSERT (strcmp (result, "       inf 33") == 0);
     ASSERT (retval == strlen (result));
     free (result);
@@ -703,13 +717,13 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     int retval =
       my_asprintf (&result, "%010La %d", 0.0L / 0.0L, 33, 44, 55);
     ASSERT (result != NULL);
+    /* "0000000nan 33" is not a valid result; see
+       <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
     ASSERT (strcmp (result, "       nan 33") == 0);
     ASSERT (retval == strlen (result));
     free (result);
   }
 
-#endif
-
   /* Test the support of the %n format directive.  */
 
   {