Mercurial > hg > octave-lyh > gnulib-hg
changeset 8850:d1fe16dfbfee
Avoid test failures on IRIX 6.5.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 19 May 2007 22:22:21 +0000 |
parents | c869de19cb7f |
children | 0863989438fc |
files | ChangeLog tests/test-snprintf-posix.h tests/test-sprintf-posix.h tests/test-vasnprintf-posix.c tests/test-vasprintf-posix.c |
diffstat | 5 files changed, 257 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-05-19 Bruno Haible <bruno@clisp.org> + + * tests/test-vasnprintf-posix.c (test_function): Allow NaN to be + printed as "nan0x7fffffff" instead of "nan". + * tests/test-vasprintf-posix.c (test_function): Likewise. + * tests/test-snprintf-posix.h (test_function): Likewise. + * tests/test-sprintf-posix.h (test_function): Likewise. + Needed for IRIX 6.5. + 2007-05-19 Bruno Haible <bruno@clisp.org> * m4/frexp.m4 (gl_FUNC_FREXP_WORKS): Fix C89 syntax error in test code.
--- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -165,7 +165,9 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%a %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -359,10 +361,12 @@ { /* FLAG_ZERO with NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%010a %d", NaN (), 33, 44, 55); + my_snprintf (result, sizeof (result), "%020a %d", NaN (), 33, 44, 55); /* "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 (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -424,7 +428,9 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%La %d", 0.0L / 0.0L, 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -619,10 +625,12 @@ { /* FLAG_ZERO with NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%010La %d", 0.0L / 0.0L, 33, 44, 55); + my_snprintf (result, sizeof (result), "%020La %d", 0.0L / 0.0L, 33, 44, 55); /* "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 (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -779,7 +787,9 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%f %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -857,8 +867,10 @@ { /* FLAG_ZERO with NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%015f %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_snprintf (result, sizeof (result), "%020f %d", NaN (), 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1022,7 +1034,9 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%Lf %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1101,8 +1115,10 @@ static long double zero = 0.0L; char result[100]; int retval = - my_snprintf (result, sizeof (result), "%015Lf %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_snprintf (result, sizeof (result), "%020Lf %d", zero / zero, 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1178,7 +1194,9 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%F %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "NAN", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1270,7 +1288,9 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%LF %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "NAN", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1466,7 +1486,9 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%e %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1554,8 +1576,10 @@ { /* FLAG_ZERO with NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%015e %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_snprintf (result, sizeof (result), "%020e %d", NaN (), 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1720,7 +1744,9 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%Le %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1801,8 +1827,10 @@ static long double zero = 0.0L; char result[100]; int retval = - my_snprintf (result, sizeof (result), "%015Le %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_snprintf (result, sizeof (result), "%020Le %d", zero / zero, 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1977,7 +2005,9 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%g %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2058,8 +2088,10 @@ { /* FLAG_ZERO with NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%015g %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_snprintf (result, sizeof (result), "%020g %d", NaN (), 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2224,7 +2256,9 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%Lg %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2305,8 +2339,10 @@ static long double zero = 0.0L; char result[100]; int retval = - my_snprintf (result, sizeof (result), "%015Lg %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_snprintf (result, sizeof (result), "%020Lg %d", zero / zero, 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); }
--- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -151,7 +151,9 @@ char result[1000]; int retval = my_sprintf (result, "%a %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -345,10 +347,12 @@ { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%010a %d", NaN (), 33, 44, 55); + my_sprintf (result, "%020a %d", NaN (), 33, 44, 55); /* "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 (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -410,7 +414,9 @@ char result[1000]; int retval = my_sprintf (result, "%La %d", 0.0L / 0.0L, 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -605,10 +611,12 @@ { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%010La %d", 0.0L / 0.0L, 33, 44, 55); + my_sprintf (result, "%020La %d", 0.0L / 0.0L, 33, 44, 55); /* "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 (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -765,7 +773,9 @@ char result[1000]; int retval = my_sprintf (result, "%f %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -837,8 +847,10 @@ { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%015f %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_sprintf (result, "%020f %d", NaN (), 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1002,7 +1014,9 @@ char result[1000]; int retval = my_sprintf (result, "%Lf %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1075,8 +1089,10 @@ static long double zero = 0.0L; char result[1000]; int retval = - my_sprintf (result, "%015Lf %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_sprintf (result, "%020Lf %d", zero / zero, 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1152,7 +1168,9 @@ char result[1000]; int retval = my_sprintf (result, "%F %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "NAN", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1244,7 +1262,9 @@ char result[1000]; int retval = my_sprintf (result, "%LF %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "NAN", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1440,7 +1460,9 @@ char result[1000]; int retval = my_sprintf (result, "%e %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1528,8 +1550,10 @@ { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%015e %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_sprintf (result, "%020e %d", NaN (), 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1694,7 +1718,9 @@ char result[1000]; int retval = my_sprintf (result, "%Le %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1775,8 +1801,10 @@ static long double zero = 0.0L; char result[1000]; int retval = - my_sprintf (result, "%015Le %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_sprintf (result, "%020Le %d", zero / zero, 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1951,7 +1979,9 @@ char result[1000]; int retval = my_sprintf (result, "%g %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2032,8 +2062,10 @@ { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%015g %d", NaN (), 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_sprintf (result, "%020g %d", NaN (), 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2198,7 +2230,9 @@ char result[1000]; int retval = my_sprintf (result, "%Lg %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2279,8 +2313,10 @@ static long double zero = 0.0L; char result[1000]; int retval = - my_sprintf (result, "%015Lg %d", zero / zero, 33, 44, 55); - ASSERT (strcmp (result, " nan 33") == 0); + my_sprintf (result, "%020Lg %d", zero / zero, 33, 44, 55); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); }
--- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -217,7 +217,9 @@ char *result = my_asnprintf (NULL, &length, "%a %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -446,11 +448,13 @@ { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%010a %d", NaN (), 33, 44, 55); + my_asnprintf (NULL, &length, "%020a %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 (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -526,7 +530,9 @@ char *result = my_asnprintf (NULL, &length, "%La %d", 0.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -756,11 +762,13 @@ { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%010La %d", 0.0L / 0.0L, 33, 44, 55); + my_asnprintf (NULL, &length, "%020La %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 (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -935,7 +943,9 @@ char *result = my_asnprintf (NULL, &length, "%f %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1024,9 +1034,11 @@ { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%015f %d", NaN (), 33, 44, 55); + my_asnprintf (NULL, &length, "%020f %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1210,7 +1222,9 @@ char *result = my_asnprintf (NULL, &length, "%Lf %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1300,9 +1314,11 @@ static long double zero = 0.0L; size_t length; char *result = - my_asnprintf (NULL, &length, "%015Lf %d", zero / zero, 33, 44, 55); + my_asnprintf (NULL, &length, "%020Lf %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1396,7 +1412,9 @@ char *result = my_asnprintf (NULL, &length, "%F %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "NAN", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1510,7 +1528,9 @@ char *result = my_asnprintf (NULL, &length, "%LF %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "NAN", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1729,7 +1749,9 @@ char *result = my_asnprintf (NULL, &length, "%e %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1836,9 +1858,11 @@ { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%015e %d", NaN (), 33, 44, 55); + my_asnprintf (NULL, &length, "%020e %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2023,7 +2047,9 @@ char *result = my_asnprintf (NULL, &length, "%Le %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2123,9 +2149,11 @@ static long double zero = 0.0L; size_t length; char *result = - my_asnprintf (NULL, &length, "%015Le %d", zero / zero, 33, 44, 55); + my_asnprintf (NULL, &length, "%020Le %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2320,7 +2348,9 @@ char *result = my_asnprintf (NULL, &length, "%g %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2420,9 +2450,11 @@ { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%015g %d", NaN (), 33, 44, 55); + my_asnprintf (NULL, &length, "%020g %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2607,7 +2639,9 @@ char *result = my_asnprintf (NULL, &length, "%Lg %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2707,9 +2741,11 @@ static long double zero = 0.0L; size_t length; char *result = - my_asnprintf (NULL, &length, "%015Lg %d", zero / zero, 33, 44, 55); + my_asnprintf (NULL, &length, "%020Lg %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); }
--- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -198,7 +198,9 @@ int retval = my_asprintf (&result, "%a %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -427,11 +429,13 @@ { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%010a %d", NaN (), 33, 44, 55); + my_asprintf (&result, "%020a %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 (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -507,7 +511,9 @@ int retval = my_asprintf (&result, "%La %d", 0.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -737,11 +743,13 @@ { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%010La %d", 0.0L / 0.0L, 33, 44, 55); + my_asprintf (&result, "%020La %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 (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -916,7 +924,9 @@ int retval = my_asprintf (&result, "%f %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1005,9 +1015,11 @@ { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%015f %d", NaN (), 33, 44, 55); + my_asprintf (&result, "%020f %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1191,7 +1203,9 @@ int retval = my_asprintf (&result, "%Lf %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1281,9 +1295,11 @@ static long double zero = 0.0L; char *result; int retval = - my_asprintf (&result, "%015Lf %d", zero / zero, 33, 44, 55); + my_asprintf (&result, "%020Lf %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1377,7 +1393,9 @@ int retval = my_asprintf (&result, "%F %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "NAN", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1491,7 +1509,9 @@ int retval = my_asprintf (&result, "%LF %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "NAN", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1710,7 +1730,9 @@ int retval = my_asprintf (&result, "%e %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1817,9 +1839,11 @@ { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%015e %d", NaN (), 33, 44, 55); + my_asprintf (&result, "%020e %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2004,7 +2028,9 @@ int retval = my_asprintf (&result, "%Le %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2104,9 +2130,11 @@ static long double zero = 0.0L; char *result; int retval = - my_asprintf (&result, "%015Le %d", zero / zero, 33, 44, 55); + my_asprintf (&result, "%020Le %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2301,7 +2329,9 @@ int retval = my_asprintf (&result, "%g %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2401,9 +2431,11 @@ { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%015g %d", NaN (), 33, 44, 55); + my_asprintf (&result, "%020g %d", NaN (), 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2588,7 +2620,9 @@ int retval = my_asprintf (&result, "%Lg %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (strlen (result) >= 3 + 3 + && memcmp (result, "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2688,9 +2722,11 @@ static long double zero = 0.0L; char *result; int retval = - my_asprintf (&result, "%015Lg %d", zero / zero, 33, 44, 55); + my_asprintf (&result, "%020Lg %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " nan 33") == 0); + ASSERT (strlen (result) == 20 + 3 + && memcmp (result + strspn (result, " "), "nan", 3) == 0 + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); }