summaryrefslogtreecommitdiff
path: root/src/test/test_util.c
diff options
context:
space:
mode:
authorteor <teor2345@gmail.com>2014-12-25 20:52:10 +1100
committerteor <teor2345@gmail.com>2015-05-06 18:05:15 +1000
commit09cac24373e5a13cc527bf2f32132a9479d4ae1e (patch)
tree68c859998e732983d6e3524817dde86e5b3942f8 /src/test/test_util.c
parent6d54bdbdcf076167c1b73bfb5bef9fd1c3921796 (diff)
downloadtor-09cac24373e5a13cc527bf2f32132a9479d4ae1e.tar.gz
tor-09cac24373e5a13cc527bf2f32132a9479d4ae1e.zip
Handle edge cases in the round_*_to_next_multiple_of functions
Consistently check for overflow in round_*_to_next_multiple_of. Check all round_*_to_next_multiple_of functions with expected values. Check all round_*_to_next_multiple_of functions with maximal values. Related to HS stats in #13192.
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r--src/test/test_util.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 940f9bde52..74d7227191 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -4054,8 +4054,11 @@ test_util_round_to_next_multiple_of(void *arg)
tt_u64_op(round_uint64_to_next_multiple_of(99,7), ==, 105);
tt_u64_op(round_uint64_to_next_multiple_of(99,9), ==, 99);
- tt_i64_op(round_int64_to_next_multiple_of(0,1), ==, 0);
- tt_i64_op(round_int64_to_next_multiple_of(0,7), ==, 0);
+ tt_assert(round_uint64_to_next_multiple_of(UINT64_MAX,2) ==
+ UINT64_MAX-UINT64_MAX%2);
+
+ tt_assert(round_int64_to_next_multiple_of(0,1) == 0);
+ tt_assert(round_int64_to_next_multiple_of(0,7) == 0);
tt_i64_op(round_int64_to_next_multiple_of(99,1), ==, 99);
tt_i64_op(round_int64_to_next_multiple_of(99,7), ==, 105);
@@ -4068,6 +4071,26 @@ test_util_round_to_next_multiple_of(void *arg)
tt_i64_op(round_int64_to_next_multiple_of(INT64_MIN,2), ==, INT64_MIN);
tt_i64_op(round_int64_to_next_multiple_of(INT64_MAX,2), ==,
INT64_MAX-INT64_MAX%2);
+
+ tt_assert(round_uint32_to_next_multiple_of(0,1) == 0);
+ tt_assert(round_uint32_to_next_multiple_of(0,7) == 0);
+
+ tt_assert(round_uint32_to_next_multiple_of(99,1) == 99);
+ tt_assert(round_uint32_to_next_multiple_of(99,7) == 105);
+ tt_assert(round_uint32_to_next_multiple_of(99,9) == 99);
+
+ tt_assert(round_uint32_to_next_multiple_of(UINT32_MAX,2) ==
+ UINT32_MAX-UINT32_MAX%2);
+
+ tt_assert(round_to_next_multiple_of(0,1) == 0);
+ tt_assert(round_to_next_multiple_of(0,7) == 0);
+
+ tt_assert(round_to_next_multiple_of(99,1) == 99);
+ tt_assert(round_to_next_multiple_of(99,7) == 105);
+ tt_assert(round_to_next_multiple_of(99,9) == 99);
+
+ tt_assert(round_to_next_multiple_of(UINT_MAX,2) ==
+ UINT_MAX-UINT_MAX%2);
done:
;
}