1 /* Copyright (c) 2018-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 #include "core/or/or.h"
7 #include "feature/dircommon/voting_schedule.h"
12 test_voting_schedule_interval_start(void *arg
)
14 #define next_interval voting_schedule_get_start_of_next_interval
16 char buf
[ISO_TIME_LEN
+1];
18 // Midnight UTC tonight (as I am writing this test)
19 const time_t midnight
= 1525651200;
20 format_iso_time(buf
, midnight
);
21 tt_str_op(buf
, OP_EQ
, "2018-05-07 00:00:00");
23 /* Some simple tests with a 50-minute voting interval */
25 tt_i64_op(next_interval(midnight
, 3000, 0), OP_EQ
,
28 tt_i64_op(next_interval(midnight
+100, 3000, 0), OP_EQ
,
31 tt_i64_op(next_interval(midnight
+3000, 3000, 0), OP_EQ
,
34 tt_i64_op(next_interval(midnight
+3001, 3000, 0), OP_EQ
,
37 /* Make sure that we roll around properly at midnight */
38 tt_i64_op(next_interval(midnight
+83000, 3000, 0), OP_EQ
,
41 /* We start fresh at midnight UTC, even if there are leftover seconds. */
42 tt_i64_op(next_interval(midnight
+84005, 3000, 0), OP_EQ
,
45 /* Now try with offsets. (These are only used for test networks.) */
46 tt_i64_op(next_interval(midnight
, 3000, 99), OP_EQ
,
49 tt_i64_op(next_interval(midnight
+100, 3000, 99), OP_EQ
,
57 #define VS(name,flags) \
58 { #name, test_voting_schedule_##name, (flags), NULL, NULL }
60 struct testcase_t voting_schedule_tests
[] = {
61 VS(interval_start
, 0),