Skip to content

Commit

Permalink
Reset errors in tests to reduce warnings (#1085)
Browse files Browse the repository at this point in the history
* Clear out the error after trying to reinitialize timer.

This gets rid of a warning.

Signed-off-by: Chris Lalancette <[email protected]>

* Clear out errors in init tests.

Signed-off-by: Chris Lalancette <[email protected]>

* Make sure to reset errors after they occur in discovery options.

Signed-off-by: Chris Lalancette <[email protected]>

* Reset errors after failure in type description tests.

Signed-off-by: Chris Lalancette <[email protected]>

---------

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Aug 4, 2023
1 parent d7a51b5 commit b55c41b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rcl/test/rcl/test_discovery_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,15 @@ TEST(TestDiscoveryInfo, test_bad_argument) {
rcutils_allocator_t allocator = rcutils_get_default_allocator();

EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_get_automatic_discovery_range(nullptr));
rcl_reset_error();
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_get_discovery_static_peers(nullptr, &allocator));
rcl_reset_error();

rmw_discovery_options_t discovery_options_var = rmw_get_zero_initialized_discovery_options();
EXPECT_EQ(
RCL_RET_INVALID_ARGUMENT,
rcl_get_discovery_static_peers(&discovery_options_var, nullptr));
rcl_reset_error();
EXPECT_EQ(RCL_RET_OK, rmw_discovery_options_fini(&discovery_options_var));
}

Expand Down
4 changes: 4 additions & 0 deletions rcl/test/rcl/test_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,16 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_acce
EXPECT_EQ(0u, options->instance_id);
EXPECT_EQ(nullptr, options->impl);
EXPECT_EQ(NULL, rcl_init_options_get_rmw_init_options(nullptr));
rcl_reset_error();
EXPECT_EQ(NULL, rcl_init_options_get_rmw_init_options(&not_ini_init_options));
rcl_reset_error();

const rcl_allocator_t * options_allocator = rcl_init_options_get_allocator(&init_options);
EXPECT_TRUE(rcutils_allocator_is_valid(options_allocator));
EXPECT_EQ(NULL, rcl_init_options_get_allocator(nullptr));
rcl_reset_error();
EXPECT_EQ(NULL, rcl_init_options_get_allocator(&not_ini_init_options));
rcl_reset_error();

size_t domain_id;
ret = rcl_init_options_get_domain_id(NULL, &domain_id);
Expand Down
1 change: 1 addition & 0 deletions rcl/test/rcl/test_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ TEST_F(TestTimerFixture, test_timer_init_state) {
&timer, &clock, this->context_ptr, RCL_S_TO_NS(1), nullptr, rcl_get_default_allocator(),
true);
ASSERT_EQ(RCL_RET_ALREADY_INIT, ret) << rcl_get_error_string().str;
rcl_reset_error();

timer = rcl_get_zero_initialized_timer();

Expand Down
5 changes: 5 additions & 0 deletions rcl/test/rcl/test_type_description_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <gtest/gtest.h>

#include "rcl/error_handling.h"
#include "rcl/type_description_conversions.h"
#include "rosidl_runtime_c/message_type_support_struct.h"
#include "rosidl_runtime_c/type_description/type_description__functions.h"
Expand Down Expand Up @@ -45,7 +46,9 @@ TEST(TestTypeDescriptionConversions, type_description_conversion_round_trip) {

TEST(TestTypeDescriptionConversions, type_description_invalid_input) {
EXPECT_TRUE(NULL == rcl_convert_type_description_runtime_to_msg(NULL));
rcl_reset_error();
EXPECT_TRUE(NULL == rcl_convert_type_description_msg_to_runtime(NULL));
rcl_reset_error();
}

TEST(TestTypeDescriptionConversions, type_source_sequence_conversion_round_trip) {
Expand Down Expand Up @@ -101,7 +104,9 @@ TEST(TestTypeDescriptionConversions, actually_empty_sources_ok) {

TEST(TestTypeDescriptionConversions, type_source_sequence_invalid_input) {
EXPECT_TRUE(NULL == rcl_convert_type_source_sequence_msg_to_runtime(NULL));
rcl_reset_error();
EXPECT_TRUE(NULL == rcl_convert_type_source_sequence_runtime_to_msg(NULL));
rcl_reset_error();
}

int main(int argc, char ** argv)
Expand Down

0 comments on commit b55c41b

Please sign in to comment.