diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-09-11 00:11:26 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-11 00:11:26 -0400 |
commit | 48558ed1aa070ef121b339eef88e7822f8e45978 (patch) | |
tree | d757235e3645d73e1ca0026afa4f8c6058ad0917 /src/test/test_dir.c | |
parent | 73ee161d8a7bc06eefa58654cbfe421449921eec (diff) | |
parent | 2491eadf002e993bee11aa76597ec7f361d8f6e5 (diff) | |
download | tor-48558ed1aa070ef121b339eef88e7822f8e45978.tar.gz tor-48558ed1aa070ef121b339eef88e7822f8e45978.zip |
Merge remote-tracking branch 'public/bug13104_025'
Diffstat (limited to 'src/test/test_dir.c')
-rw-r--r-- | src/test/test_dir.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/test_dir.c b/src/test/test_dir.c index c5eee46979..d66a3f8162 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -1733,10 +1733,37 @@ test_dir_scale_bw(void *testdata) tt_assert(total <= (U64_LITERAL(1)<<62)); for (i=0; i<8; ++i) { + /* vals[2].u64 is the scaled value of 1.0 */ double ratio = ((double)vals[i].u64) / vals[2].u64; tt_double_op(fabs(ratio - v[i]), <, .00001); } + /* test handling of no entries */ + total = 1; + scale_array_elements_to_u64(vals, 0, &total); + tt_assert(total == 0); + + /* make sure we don't read the array when we have no entries + * may require compiler flags to catch NULL dereferences */ + total = 1; + scale_array_elements_to_u64(NULL, 0, &total); + tt_assert(total == 0); + + scale_array_elements_to_u64(NULL, 0, NULL); + + /* test handling of zero totals */ + total = 1; + vals[0].dbl = 0.0; + scale_array_elements_to_u64(vals, 1, &total); + tt_assert(total == 0); + tt_assert(vals[0].u64 == 0); + + vals[0].dbl = 0.0; + vals[1].dbl = 0.0; + scale_array_elements_to_u64(vals, 2, NULL); + tt_assert(vals[0].u64 == 0); + tt_assert(vals[1].u64 == 0); + done: ; } |