Merge branch 'maint-0.4.5' into release-0.4.5
[tor.git] / src / test / test_voting_schedule.c
blobdf64b7916744af4619dfc9b3e82a02cc4f8c99cf
1 /* Copyright (c) 2018-2020, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #include "orconfig.h"
6 #include "core/or/or.h"
7 #include "feature/dirauth/voting_schedule.h"
8 #include "feature/nodelist/networkstatus.h"
10 #include "test/test.h"
12 static void
13 test_voting_schedule_interval_start(void *arg)
15 #define next_interval voting_sched_get_start_of_interval_after
16 (void)arg;
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,
27 midnight+3000);
29 tt_i64_op(next_interval(midnight+100, 3000, 0), OP_EQ,
30 midnight+3000);
32 tt_i64_op(next_interval(midnight+3000, 3000, 0), OP_EQ,
33 midnight+6000);
35 tt_i64_op(next_interval(midnight+3001, 3000, 0), OP_EQ,
36 midnight+6000);
38 /* Make sure that we roll around properly at midnight */
39 tt_i64_op(next_interval(midnight+83000, 3000, 0), OP_EQ,
40 midnight+84000);
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,
44 midnight+86400);
46 /* Now try with offsets. (These are only used for test networks.) */
47 tt_i64_op(next_interval(midnight, 3000, 99), OP_EQ,
48 midnight+99);
50 tt_i64_op(next_interval(midnight+100, 3000, 99), OP_EQ,
51 midnight+3099);
53 done:
55 #undef next_interval
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),
63 END_OF_TESTCASES