summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2009-09-02 01:10:10 -0400
committerRoger Dingledine <arma@torproject.org>2009-09-02 01:10:10 -0400
commit3de5ac9baa7dc12f5bc441d75a8be48995e0f3a8 (patch)
treeaec4593508045233c1a1b91633850f23a8c5c10d
parent5fe8d384df7b9594c978bcf3c5e94864d63f5c10 (diff)
downloadtor-3de5ac9baa7dc12f5bc441d75a8be48995e0f3a8.tar.gz
tor-3de5ac9baa7dc12f5bc441d75a8be48995e0f3a8.zip
i couldn't break nick's tor_parse_double()
i guess that means i should call them unit tests and check them in.
-rw-r--r--src/or/test.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/or/test.c b/src/or/test.c
index 9d5169d9ef..d34fc452b9 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -1114,6 +1114,24 @@ test_util(void)
tor_parse_uint64("12345678901",10,500,INT32_MAX, &i, &cp));
test_assert(i == 0);
+ {
+ /* Test tor_parse_double. */
+ double d = tor_parse_double("10", 0, UINT64_MAX,&i,NULL);
+ test_assert(i == 1);
+ test_assert(DBL_TO_U64(d) == 10);
+ d = tor_parse_double("0", 0, UINT64_MAX,&i,NULL);
+ test_assert(i == 1);
+ test_assert(DBL_TO_U64(d) == 0);
+ d = tor_parse_double(" ", 0, UINT64_MAX,&i,NULL);
+ test_assert(i == 0);
+ d = tor_parse_double(".0a", 0, UINT64_MAX,&i,NULL);
+ test_assert(i == 0);
+ d = tor_parse_double(".0a", 0, UINT64_MAX,&i,&cp);
+ test_assert(i == 1);
+ d = tor_parse_double("-.0", 0, UINT64_MAX,&i,NULL);
+ test_assert(i == 1);
+ }
+
/* Test failing snprintf cases */
test_eq(-1, tor_snprintf(buf, 0, "Foo"));
test_eq(-1, tor_snprintf(buf, 2, "Foo"));