Remove unused function: dns_randfn_() in dns.c.
[tor.git] / src / test / test_voting_schedule.c
blobba4d53a4ae91668bac4f2cf25e63fffcc2c12f4f
1 /* Copyright (c) 2018-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #include "orconfig.h"
6 #include "core/or/or.h"
7 #include "feature/dircommon/voting_schedule.h"
9 #include "test/test.h"
11 static void
12 test_voting_schedule_interval_start(void *arg)
14 #define next_interval voting_schedule_get_start_of_next_interval
15 (void)arg;
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,
26 midnight+3000);
28 tt_i64_op(next_interval(midnight+100, 3000, 0), OP_EQ,
29 midnight+3000);
31 tt_i64_op(next_interval(midnight+3000, 3000, 0), OP_EQ,
32 midnight+6000);
34 tt_i64_op(next_interval(midnight+3001, 3000, 0), OP_EQ,
35 midnight+6000);
37 /* Make sure that we roll around properly at midnight */
38 tt_i64_op(next_interval(midnight+83000, 3000, 0), OP_EQ,
39 midnight+84000);
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,
43 midnight+86400);
45 /* Now try with offsets. (These are only used for test networks.) */
46 tt_i64_op(next_interval(midnight, 3000, 99), OP_EQ,
47 midnight+99);
49 tt_i64_op(next_interval(midnight+100, 3000, 99), OP_EQ,
50 midnight+3099);
52 done:
54 #undef next_interval
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),
62 END_OF_TESTCASES