Skip to content

Commit

Permalink
Enforce non-null now_fn in TimeControllerClock
Browse files Browse the repository at this point in the history
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
  • Loading branch information
Emerson Knapp committed Apr 12, 2021
1 parent 14afcf6 commit 75ebee6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rosbag2_cpp/src/rosbag2_cpp/clocks/time_controller_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ TimeControllerClock::TimeControllerClock(
std::chrono::milliseconds sleep_time_while_paused)
: impl_(std::make_unique<TimeControllerClockImpl>(now_fn, sleep_time_while_paused))
{
if (now_fn == nullptr) {
throw std::invalid_argument("TimeControllerClock now_fn must be non-empty.");
}
std::lock_guard<std::mutex> lock(impl_->state_mutex);
impl_->reference.ros = starting_time;
impl_->reference.steady = impl_->now_fn();
Expand Down
8 changes: 8 additions & 0 deletions rosbag2_cpp/test/rosbag2_cpp/test_time_controller_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class TimeControllerClockTest : public Test
rcutils_time_point_value_t ros_start_time = 0;
};

TEST_F(TimeControllerClockTest, must_provide_now_fn)
{
NowFunction empty_now;
EXPECT_THROW(
rosbag2_cpp::TimeControllerClock(ros_start_time, 1.0, empty_now),
std::invalid_argument);
}

TEST_F(TimeControllerClockTest, steadytime_precision)
{
const double playback_rate = 1.0;
Expand Down

0 comments on commit 75ebee6

Please sign in to comment.