X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-snprintf-posix.h;h=c0c95939040731120b47734e515c75586c52ff39;hb=454a448e215fff9420769034b21090fd7033975c;hp=b796d5bae56b9d7f475dc3c724c1516633eef796;hpb=8d8eda4eab3d2801251daf4eb31756c3595e2fc6;p=gnulib.git diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index b796d5bae..c0c959390 100644 --- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -1,5 +1,5 @@ /* Test of POSIX compatible vsnprintf() and snprintf() functions. - Copyright (C) 2007-2010 Free Software Foundation, Inc. + Copyright (C) 2007-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,6 +16,7 @@ /* Written by Bruno Haible , 2007. */ +#include "minus-zero.h" #include "nan.h" /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */ @@ -23,30 +24,10 @@ static int have_minus_zero () { static double plus_zero = 0.0; - double minus_zero = - plus_zero; + double minus_zero = minus_zerod; return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0; } -/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0. - So we use -zerod instead. */ -double zerod = 0.0; - -/* On HP-UX 10.20, negating 0.0L does not yield -0.0L. - So we use minus_zerol instead. - IRIX cc can't put -0.0L into .data, but can compute at runtime. - Note that the expression -LDBL_MIN * LDBL_MIN does not work on other - platforms, such as when cross-compiling to PowerPC on MacOS X 10.5. */ -#if defined __hpux || defined __sgi -static long double -compute_minus_zerol (void) -{ - return -LDBL_MIN * LDBL_MIN; -} -# define minus_zerol compute_minus_zerol () -#else -long double minus_zerol = -0.0L; -#endif - /* Representation of an 80-bit 'long double' as an initializer for a sequence of 'unsigned int' words. */ #ifdef WORDS_BIGENDIAN @@ -192,7 +173,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* Negative zero. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%a %d", -zerod, 33, 44, 55); + my_snprintf (result, sizeof (result), "%a %d", minus_zerod, 33, 44, 55); if (have_minus_zero ()) ASSERT (strcmp (result, "-0x0p+0 33") == 0); ASSERT (retval == strlen (result)); @@ -901,7 +882,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* Negative zero. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%f %d", -zerod, 33, 44, 55); + my_snprintf (result, sizeof (result), "%f %d", minus_zerod, 33, 44, 55); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000 33") == 0); ASSERT (retval == strlen (result)); @@ -1415,7 +1396,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* Negative zero. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%F %d", -zerod, 33, 44, 55); + my_snprintf (result, sizeof (result), "%F %d", minus_zerod, 33, 44, 55); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000 33") == 0); ASSERT (retval == strlen (result)); @@ -1738,7 +1719,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* Negative zero. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%e %d", -zerod, 33, 44, 55); + my_snprintf (result, sizeof (result), "%e %d", minus_zerod, 33, 44, 55); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000e+00 33") == 0 || strcmp (result, "-0.000000e+000 33") == 0); @@ -2403,7 +2384,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* Negative zero. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%g %d", -zerod, 33, 44, 55); + my_snprintf (result, sizeof (result), "%g %d", minus_zerod, 33, 44, 55); if (have_minus_zero ()) ASSERT (strcmp (result, "-0 33") == 0); ASSERT (retval == strlen (result)); @@ -3051,6 +3032,32 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) } { + char result[5000]; + int retval = + my_snprintf (result, sizeof (result), "%.4000f %d", 1.0, 99); + size_t i; + ASSERT (result[0] == '1'); + ASSERT (result[1] == '.'); + for (i = 0; i < 4000; i++) + ASSERT (result[2 + i] == '0'); + ASSERT (strcmp (result + 2 + 4000, " 99") == 0); + ASSERT (retval == strlen (result)); + } + + { + char result[1000]; + int retval = + my_snprintf (result, sizeof (result), "%.511f %d", 1.0, 99); + size_t i; + ASSERT (result[0] == '1'); + ASSERT (result[1] == '.'); + for (i = 0; i < 511; i++) + ASSERT (result[2 + i] == '0'); + ASSERT (strcmp (result + 2 + 511, " 99") == 0); + ASSERT (retval == strlen (result)); + } + + { char input[5000]; char result[5000]; int retval;