From bd3213b17e6ff94bfd1c5deb3ecf2d906dd8d0b6 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Sat, 5 Aug 2017 23:43:05 +0300 Subject: [PATCH] prop224 tests: Better HS time period tests. --- src/test/test_hs_common.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c index 65c6948382..cc62870cb6 100644 --- a/src/test/test_hs_common.c +++ b/src/test/test_hs_common.c @@ -128,7 +128,7 @@ test_time_period(void *arg) (void) arg; uint64_t tn; int retval; - time_t fake_time; + time_t fake_time, correct_time, start_time; /* Let's do the example in prop224 section [TIME-PERIODS] */ retval = parse_rfc1123_time("Wed, 13 Apr 2016 11:00:00 UTC", @@ -145,6 +145,15 @@ test_time_period(void *arg) tn = hs_get_time_period_num(fake_time); tt_u64_op(tn, ==, 16903); + { /* Check start time of next time period */ + retval = parse_rfc1123_time("Wed, 13 Apr 2016 12:00:00 UTC", + &correct_time); + tt_int_op(retval, ==, 0); + + start_time = hs_get_start_time_of_next_time_period(fake_time); + tt_int_op(start_time, OP_EQ, correct_time); + } + /* Now take time to 12:00:00 UTC and check that the time period rotated */ fake_time += 1; tn = hs_get_time_period_num(fake_time); @@ -154,6 +163,24 @@ test_time_period(void *arg) tn = hs_get_next_time_period_num(fake_time); tt_u64_op(tn, ==, 16905); + { /* Check start time of next time period again */ + retval = parse_rfc1123_time("Wed, 14 Apr 2016 12:00:00 UTC", + &correct_time); + tt_int_op(retval, ==, 0); + + start_time = hs_get_start_time_of_next_time_period(fake_time); + tt_int_op(start_time, OP_EQ, correct_time); + } + + /* Now do another sanity check: The time period number at the start of the + * next time period, must be the same time period number as the one returned + * from hs_get_next_time_period_num() */ + { + time_t next_tp_start = hs_get_start_time_of_next_time_period(fake_time); + tt_int_op(hs_get_time_period_num(next_tp_start), OP_EQ, + hs_get_next_time_period_num(fake_time)); + } + done: ; }