diff options
author | Bruno Haible <bruno@clisp.org> | 2008-04-19 17:26:36 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2008-04-19 17:26:36 +0200 |
commit | f797ae74856a21b4471baec28dbbfd82b48fe2dc (patch) | |
tree | fc1a1a25bd9a89d66437e96c4259e249b3599557 /tests/test-snprintf-posix.h | |
parent | 2e8956774250d3f5636898fea193c5abaf041d08 (diff) | |
download | gnulib-f797ae74856a21b4471baec28dbbfd82b48fe2dc.tar.gz |
Fix rounding when a precision is given.
Diffstat (limited to 'tests/test-snprintf-posix.h')
-rw-r--r-- | tests/test-snprintf-posix.h | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index 570f8b77da..47ad86c4be 100644 --- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -1004,6 +1004,22 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) ASSERT (retval == strlen (result)); } + { /* Precision with no rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.2f %d", 999.951, 33, 44, 55); + ASSERT (strcmp (result, "999.95 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision with rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.2f %d", 999.996, 33, 44, 55); + ASSERT (strcmp (result, "1000.00 33") == 0); + ASSERT (retval == strlen (result)); + } + { /* A positive number. */ char result[100]; int retval = @@ -1338,6 +1354,22 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) ASSERT (retval == strlen (result)); } + { /* Precision with no rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.2Lf %d", 999.951L, 33, 44, 55); + ASSERT (strcmp (result, "999.95 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision with rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.2Lf %d", 999.996L, 33, 44, 55); + ASSERT (strcmp (result, "1000.00 33") == 0); + ASSERT (retval == strlen (result)); + } + /* Test the support of the %F format directive. */ { /* A positive number. */ @@ -1434,6 +1466,22 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) ASSERT (retval == strlen (result)); } + { /* Precision with no rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.2F %d", 999.951, 33, 44, 55); + ASSERT (strcmp (result, "999.95 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision with rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.2F %d", 999.996, 33, 44, 55); + ASSERT (strcmp (result, "1000.00 33") == 0); + ASSERT (retval == strlen (result)); + } + { /* A positive number. */ char result[100]; int retval = @@ -1528,6 +1576,22 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) ASSERT (retval == strlen (result)); } + { /* Precision with no rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.2LF %d", 999.951L, 33, 44, 55); + ASSERT (strcmp (result, "999.95 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision with rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.2LF %d", 999.996L, 33, 44, 55); + ASSERT (strcmp (result, "1000.00 33") == 0); + ASSERT (retval == strlen (result)); + } + /* Test the support of the %e format directive. */ { /* A positive number. */ @@ -1802,6 +1866,24 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) ASSERT (retval == strlen (result)); } + { /* Precision with no rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.4e %d", 999.951, 33, 44, 55); + ASSERT (strcmp (result, "9.9995e+02 33") == 0 + || strcmp (result, "9.9995e+002 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision with rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.4e %d", 999.996, 33, 44, 55); + ASSERT (strcmp (result, "1.0000e+03 33") == 0 + || strcmp (result, "1.0000e+003 33") == 0); + ASSERT (retval == strlen (result)); + } + { /* A positive number. */ char result[100]; int retval = @@ -2138,6 +2220,22 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) ASSERT (retval == strlen (result)); } + { /* Precision with no rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.4Le %d", 999.951L, 33, 44, 55); + ASSERT (strcmp (result, "9.9995e+02 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision with rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.4Le %d", 999.996L, 33, 44, 55); + ASSERT (strcmp (result, "1.0000e+03 33") == 0); + ASSERT (retval == strlen (result)); + } + /* Test the support of the %g format directive. */ { /* A positive number. */ @@ -2401,6 +2499,22 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) ASSERT (retval == strlen (result)); } + { /* Precision with no rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.5g %d", 999.951, 33, 44, 55); + ASSERT (strcmp (result, "999.95 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision with rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.5g %d", 999.996, 33, 44, 55); + ASSERT (strcmp (result, "1000 33") == 0); + ASSERT (retval == strlen (result)); + } + { /* A positive number. */ char result[100]; int retval = @@ -2737,6 +2851,22 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) ASSERT (retval == strlen (result)); } + { /* Precision with no rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.5Lg %d", 999.951L, 33, 44, 55); + ASSERT (strcmp (result, "999.95 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision with rounding. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.5Lg %d", 999.996L, 33, 44, 55); + ASSERT (strcmp (result, "1000 33") == 0); + ASSERT (retval == strlen (result)); + } + /* Test the support of the %n format directive. */ { |