Skip to content

Commit

Permalink
Add tests exceptions duration
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
  • Loading branch information
Blast545 committed Sep 30, 2020
1 parent b29c102 commit 049ba01
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rclcpp/test/rclcpp/test_duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "rclcpp/rclcpp.hpp"
#include "rclcpp/duration.hpp"

#include "../utils/rclcpp_gtest_macros.hpp"

using namespace std::chrono_literals;

Expand Down Expand Up @@ -250,3 +251,13 @@ TEST_F(TestDuration, test_some_constructors) {
rclcpp::Duration duration_from_struct(duration_struct);
EXPECT_EQ(4000, duration_from_struct.nanoseconds());
}

TEST_F(TestDuration, test_some_exceptions) {
rclcpp::Duration test_duration(0u);
RCLCPP_EXPECT_THROW_EQ(
test_duration = rclcpp::Duration(INT64_MAX) - rclcpp::Duration(-1),
std::overflow_error("duration subtraction leads to int64_t overflow"));
RCLCPP_EXPECT_THROW_EQ(
test_duration = test_duration * (1.0 / 0.0),
std::runtime_error("abnormal scale in rclcpp::Duration"));
}

0 comments on commit 049ba01

Please sign in to comment.