1 /* Copyright (c) 2018-2020, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 #include "core/or/or.h"
7 #include "feature/dirauth/voting_schedule.h"
8 #include "feature/nodelist/networkstatus.h"
10 #include "test/test.h"
13 test_voting_schedule_interval_start(void *arg
)
15 #define next_interval voting_sched_get_start_of_interval_after
17 char buf
[ISO_TIME_LEN
+1];
19 // Midnight UTC tonight (as I am writing this test)
20 const time_t midnight
= 1525651200;
21 format_iso_time(buf
, midnight
);
22 tt_str_op(buf
, OP_EQ
, "2018-05-07 00:00:00");
24 /* Some simple tests with a 50-minute voting interval */
26 tt_i64_op(next_interval(midnight
, 3000, 0), OP_EQ
,
29 tt_i64_op(next_interval(midnight
+100, 3000, 0), OP_EQ
,
32 tt_i64_op(next_interval(midnight
+3000, 3000, 0), OP_EQ
,
35 tt_i64_op(next_interval(midnight
+3001, 3000, 0), OP_EQ
,
38 /* Make sure that we roll around properly at midnight */
39 tt_i64_op(next_interval(midnight
+83000, 3000, 0), OP_EQ
,
42 /* We start fresh at midnight UTC, even if there are leftover seconds. */
43 tt_i64_op(next_interval(midnight
+84005, 3000, 0), OP_EQ
,
46 /* Now try with offsets. (These are only used for test networks.) */
47 tt_i64_op(next_interval(midnight
, 3000, 99), OP_EQ
,
50 tt_i64_op(next_interval(midnight
+100, 3000, 99), OP_EQ
,
58 #define VS(name,flags) \
59 { #name, test_voting_schedule_##name, (flags), NULL, NULL }
61 struct testcase_t voting_schedule_tests
[] = {
62 VS(interval_start
, 0),