diff options
author | teor (Tim Wilson-Brown) <teor2345@gmail.com> | 2016-06-30 09:22:29 +1000 |
---|---|---|
committer | teor (Tim Wilson-Brown) <teor2345@gmail.com> | 2016-06-30 09:29:18 +1000 |
commit | 69535f12841aa8041863c81d1c6ac7eb7a95e0c6 (patch) | |
tree | c846b79cf7e6775ee9c7cd85fdbed8a104c78569 /src/test/test_util.c | |
parent | aae14f83466364187dd04334e2f8b02e06002a88 (diff) | |
download | tor-69535f12841aa8041863c81d1c6ac7eb7a95e0c6.tar.gz tor-69535f12841aa8041863c81d1c6ac7eb7a95e0c6.zip |
Add tv_udiff and tv_mdiff unit tests with negative values
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index 89512920f1..c331a662a5 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -303,6 +303,23 @@ test_util_time(void *arg) tt_int_op(1005000L,OP_EQ, tv_udiff(&end, &start)); tt_int_op(1005L,OP_EQ, tv_mdiff(&end, &start)); + /* Negative tv_sec values, these will break on platforms where tv_sec is + * unsigned */ + + end.tv_sec = -10; + + tt_int_op(-15005000L,OP_EQ, tv_udiff(&start, &end)); + tt_int_op(-15005L,OP_EQ, tv_mdiff(&start, &end)); + tt_int_op(15005000L,OP_EQ, tv_udiff(&end, &start)); + tt_int_op(15005L,OP_EQ, tv_mdiff(&end, &start)); + + start.tv_sec = -100; + + tt_int_op(89995000L,OP_EQ, tv_udiff(&start, &end)); + tt_int_op(89995L,OP_EQ, tv_mdiff(&start, &end)); + tt_int_op(-89995000L,OP_EQ, tv_udiff(&end, &start)); + tt_int_op(-89995L,OP_EQ, tv_mdiff(&end, &start)); + /* Test that tv_usec values round away from zero when converted to msec */ start.tv_sec = 0; start.tv_usec = 0; |