summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2004-06-27 11:46:42 +0000
committertrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2004-06-27 11:46:42 +0000
commit2309b680d6404a535b3736b45a8e0ebb1ad137a5 (patch)
tree1dceaa86b71f067257b9bd010451fca5392b4b84 /test
parenteba9fb1ce9a40c8ffbd2624c44961922abd23abe (diff)
downloadlibapr-2309b680d6404a535b3736b45a8e0ebb1ad137a5.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/trunk@65222 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/teststr.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/teststr.c b/test/teststr.c
index a046660cb..300a1b576 100644
--- a/test/teststr.c
+++ b/test/teststr.c
@@ -125,6 +125,24 @@ static void snprintf_0nonNULL(abts_case *tc, void *data)
ABTS_ASSERT(tc, "buff unmangled", strcmp(buff, "FOOBAR") != 0);
}
+static void snprintf_underflow(abts_case *tc, void *data)
+{
+ char buf[20];
+ int rv;
+
+ rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.0001);
+ ABTS_INT_EQUAL(tc, 4, rv);
+ ABTS_STR_EQUAL(tc, "0.00", buf);
+
+ rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.001);
+ ABTS_INT_EQUAL(tc, 4, rv);
+ ABTS_STR_EQUAL(tc, "0.00", buf);
+
+ rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.01);
+ ABTS_INT_EQUAL(tc, 4, rv);
+ ABTS_STR_EQUAL(tc, "0.01", buf);
+}
+
static void string_error(abts_case *tc, void *data)
{
char buf[128], *rv;
@@ -267,6 +285,7 @@ abts_suite *teststr(abts_suite *suite)
abts_run_test(suite, snprintf_0NULL, NULL);
abts_run_test(suite, snprintf_0nonNULL, NULL);
abts_run_test(suite, snprintf_noNULL, NULL);
+ abts_run_test(suite, snprintf_underflow, NULL);
abts_run_test(suite, test_strtok, NULL);
abts_run_test(suite, string_error, NULL);
abts_run_test(suite, string_long, NULL);