LCOV - code coverage report
Current view: top level - test - test_voting_schedule.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 17 17 100.0 %
Date: 2021-11-24 03:28:48 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Copyright (c) 2018-2021, The Tor Project, Inc. */
       2             : /* See LICENSE for licensing information */
       3             : 
       4             : #include "orconfig.h"
       5             : 
       6             : #include "core/or/or.h"
       7             : #include "feature/dirauth/voting_schedule.h"
       8             : #include "feature/nodelist/networkstatus.h"
       9             : 
      10             : #include "test/test.h"
      11             : 
      12             : static void
      13           1 : test_voting_schedule_interval_start(void *arg)
      14             : {
      15             : #define next_interval voting_sched_get_start_of_interval_after
      16           1 :   (void)arg;
      17           1 :   char buf[ISO_TIME_LEN+1];
      18             : 
      19             :   // Midnight UTC tonight (as I am writing this test)
      20           1 :   const time_t midnight = 1525651200;
      21           1 :   format_iso_time(buf, midnight);
      22           1 :   tt_str_op(buf, OP_EQ, "2018-05-07 00:00:00");
      23             : 
      24             :   /* Some simple tests with a 50-minute voting interval */
      25             : 
      26           1 :   tt_i64_op(next_interval(midnight, 3000, 0), OP_EQ,
      27             :             midnight+3000);
      28             : 
      29           1 :   tt_i64_op(next_interval(midnight+100, 3000, 0), OP_EQ,
      30             :             midnight+3000);
      31             : 
      32           1 :   tt_i64_op(next_interval(midnight+3000, 3000, 0), OP_EQ,
      33             :             midnight+6000);
      34             : 
      35           1 :   tt_i64_op(next_interval(midnight+3001, 3000, 0), OP_EQ,
      36             :             midnight+6000);
      37             : 
      38             :   /* Make sure that we roll around properly at midnight */
      39           1 :   tt_i64_op(next_interval(midnight+83000, 3000, 0), OP_EQ,
      40             :             midnight+84000);
      41             : 
      42             :   /* We start fresh at midnight UTC, even if there are leftover seconds. */
      43           1 :   tt_i64_op(next_interval(midnight+84005, 3000, 0), OP_EQ,
      44             :             midnight+86400);
      45             : 
      46             :   /* Now try with offsets.  (These are only used for test networks.) */
      47           1 :   tt_i64_op(next_interval(midnight, 3000, 99), OP_EQ,
      48             :             midnight+99);
      49             : 
      50           1 :   tt_i64_op(next_interval(midnight+100, 3000, 99), OP_EQ,
      51             :             midnight+3099);
      52             : 
      53           1 :  done:
      54           1 :   ;
      55             : #undef next_interval
      56           1 : }
      57             : 
      58             : #define VS(name,flags)                                          \
      59             :   { #name, test_voting_schedule_##name, (flags), NULL, NULL }
      60             : 
      61             : struct testcase_t voting_schedule_tests[] = {
      62             :   VS(interval_start, 0),
      63             :   END_OF_TESTCASES
      64             : };

Generated by: LCOV version 1.14