@@ -138,6 +138,8 @@ TEST_F(TestTime, conversions) {
138138
139139 EXPECT_ANY_THROW (rclcpp::Time (-1 , 1 ));
140140
141+ EXPECT_ANY_THROW (rclcpp::Time (-1 ));
142+
141143 EXPECT_ANY_THROW (
142144 {
143145 rclcpp::Time assignment (1 , 2 );
@@ -168,48 +170,6 @@ TEST_F(TestTime, conversions) {
168170 EXPECT_EQ (time_msg.nanosec , HALF_SEC_IN_NS);
169171 EXPECT_EQ (rclcpp::Time (time_msg).nanoseconds (), ONE_AND_HALF_SEC_IN_NS);
170172 }
171-
172- {
173- // Can rclcpp::Time be negative or not? The following constructor works:
174- rclcpp::Time time (-HALF_SEC_IN_NS);
175- auto time_msg = static_cast <builtin_interfaces::msg::Time>(time);
176- EXPECT_EQ (time_msg.sec , -1 );
177- EXPECT_EQ (time_msg.nanosec , HALF_SEC_IN_NS);
178-
179- // The opposite conversion throws...
180- EXPECT_ANY_THROW (
181- {
182- rclcpp::Time negative_time (time_msg);
183- });
184- }
185-
186- {
187- // Can rclcpp::Time be negative or not? The following constructor works:
188- rclcpp::Time time (-ONE_SEC_IN_NS);
189- auto time_msg = static_cast <builtin_interfaces::msg::Time>(time);
190- EXPECT_EQ (time_msg.sec , -1 );
191- EXPECT_EQ (time_msg.nanosec , 0u );
192-
193- // The opposite conversion throws...
194- EXPECT_ANY_THROW (
195- {
196- rclcpp::Time negative_time (time_msg);
197- });
198- }
199-
200- {
201- // Can rclcpp::Time be negative or not? The following constructor works:
202- rclcpp::Time time (-ONE_AND_HALF_SEC_IN_NS);
203- auto time_msg = static_cast <builtin_interfaces::msg::Time>(time);
204- EXPECT_EQ (time_msg.sec , -2 );
205- EXPECT_EQ (time_msg.nanosec , HALF_SEC_IN_NS);
206-
207- // The opposite conversion throws...
208- EXPECT_ANY_THROW (
209- {
210- rclcpp::Time negative_time (time_msg);
211- });
212- }
213173}
214174
215175TEST_F (TestTime, operators) {
@@ -326,31 +286,18 @@ TEST_F(TestTime, overflow_detectors) {
326286
327287TEST_F (TestTime, overflows) {
328288 rclcpp::Time max_time (std::numeric_limits<rcl_time_point_value_t >::max ());
329- rclcpp::Time min_time (std::numeric_limits<rcl_time_point_value_t >::min ());
330289 rclcpp::Duration one (1ns);
331290 rclcpp::Duration two (2ns);
332291
333- // Cross min/ max
292+ // Cross max
334293 EXPECT_THROW (max_time + one, std::overflow_error);
335- EXPECT_THROW (min_time - one, std::underflow_error);
336- EXPECT_THROW (max_time - min_time, std::overflow_error);
337- EXPECT_THROW (min_time - max_time, std::underflow_error);
338294 EXPECT_THROW (rclcpp::Time (max_time) += one, std::overflow_error);
339- EXPECT_THROW (rclcpp::Time (min_time) -= one, std::underflow_error);
340295 EXPECT_NO_THROW (max_time - max_time);
341- EXPECT_NO_THROW (min_time - min_time);
342296
343- // Cross zero in both directions
297+ // Cross zero
344298 rclcpp::Time one_time (1 );
345- EXPECT_NO_THROW (one_time - two);
346- EXPECT_NO_THROW (rclcpp::Time (one_time) -= two);
347-
348- rclcpp::Time minus_one_time (-1 );
349- EXPECT_NO_THROW (minus_one_time + two);
350- EXPECT_NO_THROW (rclcpp::Time (minus_one_time) += two);
351-
352- EXPECT_NO_THROW (one_time - minus_one_time);
353- EXPECT_NO_THROW (minus_one_time - one_time);
299+ EXPECT_THROW (one_time - two, std::runtime_error);
300+ EXPECT_THROW (rclcpp::Time (one_time) -= two, std::runtime_error);
354301
355302 rclcpp::Time two_time (2 );
356303 EXPECT_NO_THROW (one_time - two_time);
@@ -432,41 +379,24 @@ TEST_F(TestTime, test_overflow_underflow_throws) {
432379 RCLCPP_EXPECT_THROW_EQ (
433380 test_time = rclcpp::Time (INT64_MAX) + rclcpp::Duration (1ns),
434381 std::overflow_error (" addition leads to int64_t overflow" ));
435- RCLCPP_EXPECT_THROW_EQ (
436- test_time = rclcpp::Time (INT64_MIN) + rclcpp::Duration (-1ns),
437- std::underflow_error (" addition leads to int64_t underflow" ));
438382
439383 RCLCPP_EXPECT_THROW_EQ (
440384 test_time = rclcpp::Time (INT64_MAX) - rclcpp::Duration (-1ns),
441385 std::overflow_error (" time subtraction leads to int64_t overflow" ));
442- RCLCPP_EXPECT_THROW_EQ (
443- test_time = rclcpp::Time (INT64_MIN) - rclcpp::Duration (1ns),
444- std::underflow_error (" time subtraction leads to int64_t underflow" ));
445386
446387 test_time = rclcpp::Time (INT64_MAX);
447388 RCLCPP_EXPECT_THROW_EQ (
448389 test_time += rclcpp::Duration (1ns),
449390 std::overflow_error (" addition leads to int64_t overflow" ));
450- test_time = rclcpp::Time (INT64_MIN);
451- RCLCPP_EXPECT_THROW_EQ (
452- test_time += rclcpp::Duration (-1ns),
453- std::underflow_error (" addition leads to int64_t underflow" ));
454391
455392 test_time = rclcpp::Time (INT64_MAX);
456393 RCLCPP_EXPECT_THROW_EQ (
457394 test_time -= rclcpp::Duration (-1ns),
458395 std::overflow_error (" time subtraction leads to int64_t overflow" ));
459- test_time = rclcpp::Time (INT64_MIN);
460- RCLCPP_EXPECT_THROW_EQ (
461- test_time -= rclcpp::Duration (1ns),
462- std::underflow_error (" time subtraction leads to int64_t underflow" ));
463396
464397 RCLCPP_EXPECT_THROW_EQ (
465398 test_time = rclcpp::Duration::from_nanoseconds (INT64_MAX) + rclcpp::Time (1 ),
466399 std::overflow_error (" addition leads to int64_t overflow" ));
467- RCLCPP_EXPECT_THROW_EQ (
468- test_time = rclcpp::Duration::from_nanoseconds (INT64_MIN) + rclcpp::Time (-1 ),
469- std::underflow_error (" addition leads to int64_t underflow" ));
470400}
471401
472402class TestClockSleep : public ::testing::Test
0 commit comments