diff options
author | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2004-06-27 11:45:11 +0000 |
---|---|---|
committer | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2004-06-27 11:45:11 +0000 |
commit | 5caf3f40824dbe716112f591a57d580857e7d3ad (patch) | |
tree | e7c380620aab2f0d098ca61fa9879fabd1cf4728 /test | |
parent | b3fc9357a6a53de33dc35ecbe02830c1364ba35b (diff) | |
download | libapr-5caf3f40824dbe716112f591a57d580857e7d3ad.tar.gz |
Fix apr_snprintf() to respect precision for small floating point
numbers.
PR: 29621
Submitted by: Artur Zaprzala <zybi talex.pl>
Reviewed by: Jeff Trawick
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/APR_0_9_BRANCH@65221 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r-- | test/teststr.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/teststr.c b/test/teststr.c index 0df64230d..f2757de8f 100644 --- a/test/teststr.c +++ b/test/teststr.c @@ -142,6 +142,24 @@ static void snprintf_int64(CuTest *tc) CuAssertStrEquals(tc, buf, "3141592653589793238"); } +static void snprintf_underflow(CuTest *tc) +{ + char buf[20]; + int rv; + + rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.0001); + CuAssertIntEquals(tc, 4, rv); + CuAssertStrEquals(tc, "0.00", buf); + + rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.001); + CuAssertIntEquals(tc, 4, rv); + CuAssertStrEquals(tc, "0.00", buf); + + rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.01); + CuAssertIntEquals(tc, 4, rv); + CuAssertStrEquals(tc, "0.01", buf); +} + static void string_error(CuTest *tc) { char buf[128], *rv; @@ -271,6 +289,7 @@ CuSuite *teststr(void) SUITE_ADD_TEST(suite, snprintf_0nonNULL); SUITE_ADD_TEST(suite, snprintf_noNULL); SUITE_ADD_TEST(suite, snprintf_int64); + SUITE_ADD_TEST(suite, snprintf_underflow); SUITE_ADD_TEST(suite, test_strtok); SUITE_ADD_TEST(suite, string_error); SUITE_ADD_TEST(suite, string_long); |