Mercurial > hg > octave-lyh > gnulib-hg
changeset 8839:5efc1d668039
Accomodate for implementations that produce 3 exponent digits in %e and %g.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 19 May 2007 10:22:11 +0000 |
parents | db95bdbeb72c |
children | 792e05ae7ac8 |
files | tests/test-snprintf-posix.h tests/test-sprintf-posix.h tests/test-vasnprintf-posix.c tests/test-vasprintf-posix.c |
diffstat | 4 files changed, 222 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -1305,7 +1305,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%e %d", 12.75, 33, 44, 55); - ASSERT (strcmp (result, "1.275000e+01 33") == 0); + ASSERT (strcmp (result, "1.275000e+01 33") == 0 + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -1313,7 +1314,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%e %d", 1234567.0, 33, 44, 55); - ASSERT (strcmp (result, "1.234567e+06 33") == 0); + ASSERT (strcmp (result, "1.234567e+06 33") == 0 + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (retval == strlen (result)); } @@ -1401,7 +1403,16 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%e", data[k].value); - ASSERT (strmatch (data[k].string, result)); + const char *expected = data[k].string; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); ASSERT (retval == strlen (result)); } } @@ -1410,7 +1421,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%e %d", -0.03125, 33, 44, 55); - ASSERT (strcmp (result, "-3.125000e-02 33") == 0); + ASSERT (strcmp (result, "-3.125000e-02 33") == 0 + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (retval == strlen (result)); } @@ -1418,7 +1430,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%e %d", 0.0, 33, 44, 55); - ASSERT (strcmp (result, "0.000000e+00 33") == 0); + ASSERT (strcmp (result, "0.000000e+00 33") == 0 + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1426,7 +1439,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%e %d", -0.0, 33, 44, 55); - ASSERT (strcmp (result, "-0.000000e+00 33") == 0); + ASSERT (strcmp (result, "-0.000000e+00 33") == 0 + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1460,7 +1474,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%15e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, " 1.750000e+00 33") == 0); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0 + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1468,7 +1483,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%-15e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, "1.750000e+00 33") == 0); + ASSERT (strcmp (result, "1.750000e+00 33") == 0 + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1476,7 +1492,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%+e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, "+1.750000e+00 33") == 0); + ASSERT (strcmp (result, "+1.750000e+00 33") == 0 + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1484,7 +1501,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "% e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, " 1.750000e+00 33") == 0); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0 + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1492,7 +1510,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%#e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, "1.750000e+00 33") == 0); + ASSERT (strcmp (result, "1.750000e+00 33") == 0 + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1500,7 +1519,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%#.e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, "2.e+00 33") == 0); + ASSERT (strcmp (result, "2.e+00 33") == 0 + || strcmp (result, "2.e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1508,7 +1528,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%#.e %d", 9.75, 33, 44, 55); - ASSERT (strcmp (result, "1.e+01 33") == 0); + ASSERT (strcmp (result, "1.e+01 33") == 0 + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -1516,7 +1537,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%015e %d", 1234.0, 33, 44, 55); - ASSERT (strcmp (result, "0001.234000e+03 33") == 0); + ASSERT (strcmp (result, "0001.234000e+03 33") == 0 + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -1541,7 +1563,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%.e %d", 1234.0, 33, 44, 55); - ASSERT (strcmp (result, "1e+03 33") == 0); + ASSERT (strcmp (result, "1e+03 33") == 0 + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -1645,7 +1668,7 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%Le", data[k].value); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, data[k].string) == 0); ASSERT (retval == strlen (result)); } } @@ -1805,7 +1828,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%g %d", 1234567.0, 33, 44, 55); - ASSERT (strcmp (result, "1.23457e+06 33") == 0); + ASSERT (strcmp (result, "1.23457e+06 33") == 0 + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (retval == strlen (result)); } @@ -1893,7 +1917,16 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%g", data[k].value); - ASSERT (strmatch (data[k].string, result)); + const char *expected = data[k].string; + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); ASSERT (retval == strlen (result)); } } @@ -2000,7 +2033,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%#.g %d", 9.75, 33, 44, 55); - ASSERT (strcmp (result, "1.e+01 33") == 0); + ASSERT (strcmp (result, "1.e+01 33") == 0 + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -2033,7 +2067,8 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%.g %d", 1234.0, 33, 44, 55); - ASSERT (strcmp (result, "1e+03 33") == 0); + ASSERT (strcmp (result, "1e+03 33") == 0 + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -2137,7 +2172,7 @@ char result[100]; int retval = my_snprintf (result, sizeof (result), "%Lg", data[k].value); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, data[k].string) == 0); ASSERT (retval == strlen (result)); } }
--- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -1279,7 +1279,8 @@ char result[1000]; int retval = my_sprintf (result, "%e %d", 12.75, 33, 44, 55); - ASSERT (strcmp (result, "1.275000e+01 33") == 0); + ASSERT (strcmp (result, "1.275000e+01 33") == 0 + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -1287,7 +1288,8 @@ char result[1000]; int retval = my_sprintf (result, "%e %d", 1234567.0, 33, 44, 55); - ASSERT (strcmp (result, "1.234567e+06 33") == 0); + ASSERT (strcmp (result, "1.234567e+06 33") == 0 + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (retval == strlen (result)); } @@ -1375,7 +1377,16 @@ char result[1000]; int retval = my_sprintf (result, "%e", data[k].value); - ASSERT (strmatch (data[k].string, result)); + const char *expected = data[k].string; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); ASSERT (retval == strlen (result)); } } @@ -1384,7 +1395,8 @@ char result[1000]; int retval = my_sprintf (result, "%e %d", -0.03125, 33, 44, 55); - ASSERT (strcmp (result, "-3.125000e-02 33") == 0); + ASSERT (strcmp (result, "-3.125000e-02 33") == 0 + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (retval == strlen (result)); } @@ -1392,7 +1404,8 @@ char result[1000]; int retval = my_sprintf (result, "%e %d", 0.0, 33, 44, 55); - ASSERT (strcmp (result, "0.000000e+00 33") == 0); + ASSERT (strcmp (result, "0.000000e+00 33") == 0 + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1400,7 +1413,8 @@ char result[1000]; int retval = my_sprintf (result, "%e %d", -0.0, 33, 44, 55); - ASSERT (strcmp (result, "-0.000000e+00 33") == 0); + ASSERT (strcmp (result, "-0.000000e+00 33") == 0 + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1434,7 +1448,8 @@ char result[1000]; int retval = my_sprintf (result, "%15e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, " 1.750000e+00 33") == 0); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0 + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1442,7 +1457,8 @@ char result[1000]; int retval = my_sprintf (result, "%-15e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, "1.750000e+00 33") == 0); + ASSERT (strcmp (result, "1.750000e+00 33") == 0 + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1450,7 +1466,8 @@ char result[1000]; int retval = my_sprintf (result, "%+e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, "+1.750000e+00 33") == 0); + ASSERT (strcmp (result, "+1.750000e+00 33") == 0 + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1458,7 +1475,8 @@ char result[1000]; int retval = my_sprintf (result, "% e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, " 1.750000e+00 33") == 0); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0 + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1466,7 +1484,8 @@ char result[1000]; int retval = my_sprintf (result, "%#e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, "1.750000e+00 33") == 0); + ASSERT (strcmp (result, "1.750000e+00 33") == 0 + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1474,7 +1493,8 @@ char result[1000]; int retval = my_sprintf (result, "%#.e %d", 1.75, 33, 44, 55); - ASSERT (strcmp (result, "2.e+00 33") == 0); + ASSERT (strcmp (result, "2.e+00 33") == 0 + || strcmp (result, "2.e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1482,7 +1502,8 @@ char result[1000]; int retval = my_sprintf (result, "%#.e %d", 9.75, 33, 44, 55); - ASSERT (strcmp (result, "1.e+01 33") == 0); + ASSERT (strcmp (result, "1.e+01 33") == 0 + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -1490,7 +1511,8 @@ char result[1000]; int retval = my_sprintf (result, "%015e %d", 1234.0, 33, 44, 55); - ASSERT (strcmp (result, "0001.234000e+03 33") == 0); + ASSERT (strcmp (result, "0001.234000e+03 33") == 0 + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -1515,7 +1537,8 @@ char result[1000]; int retval = my_sprintf (result, "%.e %d", 1234.0, 33, 44, 55); - ASSERT (strcmp (result, "1e+03 33") == 0); + ASSERT (strcmp (result, "1e+03 33") == 0 + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -1619,7 +1642,7 @@ char result[1000]; int retval = my_sprintf (result, "%Le", data[k].value); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, data[k].string) == 0); ASSERT (retval == strlen (result)); } } @@ -1779,7 +1802,8 @@ char result[1000]; int retval = my_sprintf (result, "%g %d", 1234567.0, 33, 44, 55); - ASSERT (strcmp (result, "1.23457e+06 33") == 0); + ASSERT (strcmp (result, "1.23457e+06 33") == 0 + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (retval == strlen (result)); } @@ -1867,7 +1891,16 @@ char result[1000]; int retval = my_sprintf (result, "%g", data[k].value); - ASSERT (strmatch (data[k].string, result)); + const char *expected = data[k].string; + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); ASSERT (retval == strlen (result)); } } @@ -1974,7 +2007,8 @@ char result[1000]; int retval = my_sprintf (result, "%#.g %d", 9.75, 33, 44, 55); - ASSERT (strcmp (result, "1.e+01 33") == 0); + ASSERT (strcmp (result, "1.e+01 33") == 0 + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -2007,7 +2041,8 @@ char result[1000]; int retval = my_sprintf (result, "%.g %d", 1234.0, 33, 44, 55); - ASSERT (strcmp (result, "1e+03 33") == 0); + ASSERT (strcmp (result, "1e+03 33") == 0 + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -2111,7 +2146,7 @@ char result[1000]; int retval = my_sprintf (result, "%Lg", data[k].value); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, data[k].string) == 0); ASSERT (retval == strlen (result)); } }
--- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -1553,7 +1553,8 @@ char *result = my_asnprintf (NULL, &length, "%e %d", 12.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.275000e+01 33") == 0); + ASSERT (strcmp (result, "1.275000e+01 33") == 0 + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1563,7 +1564,8 @@ char *result = my_asnprintf (NULL, &length, "%e %d", 1234567.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.234567e+06 33") == 0); + ASSERT (strcmp (result, "1.234567e+06 33") == 0 + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1652,8 +1654,16 @@ size_t length; char *result = my_asnprintf (NULL, &length, "%e", data[k].value); + const char *expected = data[k].string; ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); ASSERT (length == strlen (result)); free (result); } @@ -1664,7 +1674,8 @@ char *result = my_asnprintf (NULL, &length, "%e %d", -0.03125, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "-3.125000e-02 33") == 0); + ASSERT (strcmp (result, "-3.125000e-02 33") == 0 + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1674,7 +1685,8 @@ char *result = my_asnprintf (NULL, &length, "%e %d", 0.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "0.000000e+00 33") == 0); + ASSERT (strcmp (result, "0.000000e+00 33") == 0 + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1684,7 +1696,8 @@ char *result = my_asnprintf (NULL, &length, "%e %d", -0.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "-0.000000e+00 33") == 0); + ASSERT (strcmp (result, "-0.000000e+00 33") == 0 + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1726,7 +1739,8 @@ char *result = my_asnprintf (NULL, &length, "%15e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " 1.750000e+00 33") == 0); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0 + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1736,7 +1750,8 @@ char *result = my_asnprintf (NULL, &length, "%-15e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.750000e+00 33") == 0); + ASSERT (strcmp (result, "1.750000e+00 33") == 0 + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1746,7 +1761,8 @@ char *result = my_asnprintf (NULL, &length, "%+e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "+1.750000e+00 33") == 0); + ASSERT (strcmp (result, "+1.750000e+00 33") == 0 + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1756,7 +1772,8 @@ char *result = my_asnprintf (NULL, &length, "% e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " 1.750000e+00 33") == 0); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0 + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1766,7 +1783,8 @@ char *result = my_asnprintf (NULL, &length, "%#e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.750000e+00 33") == 0); + ASSERT (strcmp (result, "1.750000e+00 33") == 0 + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1776,7 +1794,8 @@ char *result = my_asnprintf (NULL, &length, "%#.e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "2.e+00 33") == 0); + ASSERT (strcmp (result, "2.e+00 33") == 0 + || strcmp (result, "2.e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1786,7 +1805,8 @@ char *result = my_asnprintf (NULL, &length, "%#.e %d", 9.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.e+01 33") == 0); + ASSERT (strcmp (result, "1.e+01 33") == 0 + || strcmp (result, "1.e+001 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1796,7 +1816,8 @@ char *result = my_asnprintf (NULL, &length, "%015e %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "0001.234000e+03 33") == 0); + ASSERT (strcmp (result, "0001.234000e+03 33") == 0 + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1827,7 +1848,8 @@ char *result = my_asnprintf (NULL, &length, "%.e %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1e+03 33") == 0); + ASSERT (strcmp (result, "1e+03 33") == 0 + || strcmp (result, "1e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1937,7 +1959,7 @@ char *result = my_asnprintf (NULL, &length, "%Le", data[k].value); ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, data[k].string) == 0); ASSERT (length == strlen (result)); free (result); } @@ -2135,7 +2157,8 @@ char *result = my_asnprintf (NULL, &length, "%g %d", 1234567.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.23457e+06 33") == 0); + ASSERT (strcmp (result, "1.23457e+06 33") == 0 + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2224,8 +2247,17 @@ size_t length; char *result = my_asnprintf (NULL, &length, "%g", data[k].value); + const char *expected = data[k].string; ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); ASSERT (length == strlen (result)); free (result); } @@ -2358,7 +2390,8 @@ char *result = my_asnprintf (NULL, &length, "%#.g %d", 9.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.e+01 33") == 0); + ASSERT (strcmp (result, "1.e+01 33") == 0 + || strcmp (result, "1.e+001 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2399,7 +2432,8 @@ char *result = my_asnprintf (NULL, &length, "%.g %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1e+03 33") == 0); + ASSERT (strcmp (result, "1e+03 33") == 0 + || strcmp (result, "1e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2509,7 +2543,7 @@ char *result = my_asnprintf (NULL, &length, "%Lg", data[k].value); ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, data[k].string) == 0); ASSERT (length == strlen (result)); free (result); }
--- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -1534,7 +1534,8 @@ int retval = my_asprintf (&result, "%e %d", 12.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.275000e+01 33") == 0); + ASSERT (strcmp (result, "1.275000e+01 33") == 0 + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1544,7 +1545,8 @@ int retval = my_asprintf (&result, "%e %d", 1234567.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.234567e+06 33") == 0); + ASSERT (strcmp (result, "1.234567e+06 33") == 0 + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1633,8 +1635,16 @@ char *result; int retval = my_asprintf (&result, "%e", data[k].value); + const char *expected = data[k].string; ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); ASSERT (retval == strlen (result)); free (result); } @@ -1645,7 +1655,8 @@ int retval = my_asprintf (&result, "%e %d", -0.03125, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "-3.125000e-02 33") == 0); + ASSERT (strcmp (result, "-3.125000e-02 33") == 0 + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1655,7 +1666,8 @@ int retval = my_asprintf (&result, "%e %d", 0.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "0.000000e+00 33") == 0); + ASSERT (strcmp (result, "0.000000e+00 33") == 0 + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1665,7 +1677,8 @@ int retval = my_asprintf (&result, "%e %d", -0.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "-0.000000e+00 33") == 0); + ASSERT (strcmp (result, "-0.000000e+00 33") == 0 + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1707,7 +1720,8 @@ int retval = my_asprintf (&result, "%15e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " 1.750000e+00 33") == 0); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0 + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1717,7 +1731,8 @@ int retval = my_asprintf (&result, "%-15e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.750000e+00 33") == 0); + ASSERT (strcmp (result, "1.750000e+00 33") == 0 + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1727,7 +1742,8 @@ int retval = my_asprintf (&result, "%+e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "+1.750000e+00 33") == 0); + ASSERT (strcmp (result, "+1.750000e+00 33") == 0 + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1737,7 +1753,8 @@ int retval = my_asprintf (&result, "% e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, " 1.750000e+00 33") == 0); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0 + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1747,7 +1764,8 @@ int retval = my_asprintf (&result, "%#e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.750000e+00 33") == 0); + ASSERT (strcmp (result, "1.750000e+00 33") == 0 + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1757,7 +1775,8 @@ int retval = my_asprintf (&result, "%#.e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "2.e+00 33") == 0); + ASSERT (strcmp (result, "2.e+00 33") == 0 + || strcmp (result, "2.e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1767,7 +1786,8 @@ int retval = my_asprintf (&result, "%#.e %d", 9.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.e+01 33") == 0); + ASSERT (strcmp (result, "1.e+01 33") == 0 + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1777,7 +1797,8 @@ int retval = my_asprintf (&result, "%015e %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "0001.234000e+03 33") == 0); + ASSERT (strcmp (result, "0001.234000e+03 33") == 0 + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1808,7 +1829,8 @@ int retval = my_asprintf (&result, "%.e %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1e+03 33") == 0); + ASSERT (strcmp (result, "1e+03 33") == 0 + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1918,7 +1940,7 @@ int retval = my_asprintf (&result, "%Le", data[k].value); ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, data[k].string) == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2116,7 +2138,8 @@ int retval = my_asprintf (&result, "%g %d", 1234567.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.23457e+06 33") == 0); + ASSERT (strcmp (result, "1.23457e+06 33") == 0 + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2205,8 +2228,17 @@ char *result; int retval = my_asprintf (&result, "%g", data[k].value); + const char *expected = data[k].string; ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); ASSERT (retval == strlen (result)); free (result); } @@ -2339,7 +2371,8 @@ int retval = my_asprintf (&result, "%#.g %d", 9.75, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1.e+01 33") == 0); + ASSERT (strcmp (result, "1.e+01 33") == 0 + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2380,7 +2413,8 @@ int retval = my_asprintf (&result, "%.g %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); - ASSERT (strcmp (result, "1e+03 33") == 0); + ASSERT (strcmp (result, "1e+03 33") == 0 + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2490,7 +2524,7 @@ int retval = my_asprintf (&result, "%Lg", data[k].value); ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); + ASSERT (strcmp (result, data[k].string) == 0); ASSERT (retval == strlen (result)); free (result); }