Skip to content

Commit

Permalink
Increase test coverage for timer.cc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmc-88 committed Jan 2, 2017
1 parent a75bd4e commit d3db213
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/util/timer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ TEST_CASE("Interval", "Test the Interval class") {
Interval interval{123, fake_clock.Now(), _100ms, no_op_callback};
REQUIRE(interval.GetRepeatInterval() == _100ms);
}

SECTION("correctly assigns to an interval") {
Interval first_interval{1, fake_clock.Now(), std::chrono::milliseconds(0),
no_op_callback};
Interval second_interval{2, fake_clock.Now(), std::chrono::milliseconds(50),
no_op_callback};
REQUIRE(first_interval.GetRepeatInterval() !=
second_interval.GetRepeatInterval());
first_interval = second_interval;
REQUIRE(first_interval.GetRepeatInterval() ==
std::chrono::milliseconds(50));
REQUIRE(second_interval.GetRepeatInterval() ==
std::chrono::milliseconds(50));
}
}

TEST_CASE("CompareIds", "Sanity of nullable ids comparisons") {
CompareIds compare_fn;
// Left-hand side is nulled-out: right-hand side always comes first.
REQUIRE(!compare_fn(Interval::Id{}, Interval::Id{0}));
// Right-hand side is nulled-out: left-hand side always comes first.
REQUIRE(compare_fn(Interval::Id{0}, Interval::Id{}));
// Smaller left-hand side comes first.
REQUIRE(compare_fn(Interval::Id{0}, Interval::Id{1}));
// Smaller right-hand side comes first.
REQUIRE(!compare_fn(Interval::Id{1}, Interval::Id{0}));
}

class ChronoTimerTestUtils {
Expand Down Expand Up @@ -86,6 +112,13 @@ TEST_CASE("Timer", "Test the Timer class") {
REQUIRE(intervals.empty());
}

SECTION("fails clearing a non-existing interval") {
Interval::Id nulled_interval;
REQUIRE(!timer.ClearInterval(nulled_interval));
Interval::Id no_such_interval{static_cast<uint64_t>(-1)};
REQUIRE(!timer.ClearInterval(no_such_interval));
}

SECTION("correctly processes an interval (single)") {
unsigned int invocations_count = 0;
timer.SetTimeout(std::chrono::milliseconds(100),
Expand Down

0 comments on commit d3db213

Please sign in to comment.