From 1936335569698b09580e69c7423acf7ce44f439d Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Mon, 18 May 2020 16:33:35 -0300 Subject: [PATCH 01/14] Add tests get_rmw_init_options & get_allocator Signed-off-by: Jorge Perez --- rcl/test/rcl/test_init.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rcl/test/rcl/test_init.cpp b/rcl/test/rcl/test_init.cpp index e5446e63c..3b1b2267e 100644 --- a/rcl/test/rcl/test_init.cpp +++ b/rcl/test/rcl/test_init.cpp @@ -271,3 +271,17 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_get_instance_id) ret = rcl_context_fini(&context); EXPECT_EQ(ret, RCL_RET_OK); } + +TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_access) { + rcl_ret_t ret; + rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); + ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + + rmw_init_options_t * options = rcl_init_options_get_rmw_init_options(&init_options); + EXPECT_EQ(0u, options->instance_id); + EXPECT_EQ(nullptr, options->impl); + + const rcl_allocator_t * options_allocator = rcl_init_options_get_allocator(&init_options); + EXPECT_TRUE(rcutils_allocator_is_valid(options_allocator)); +} From b776b29012d22bf5226dfeaa1dae37e74aa245f3 Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Tue, 19 May 2020 11:31:24 -0300 Subject: [PATCH 02/14] Add tests liveliness, access and loan functions Signed-off-by: Jorge Perez --- rcl/test/rcl/test_publisher.cpp | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index 5205817c9..f2d015f7e 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -290,3 +290,84 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_ EXPECT_EQ(RCL_RET_BAD_ALLOC, ret) << rcl_get_error_string().str; rcl_reset_error(); } + +TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_loan) { + rcl_ret_t ret; + rcl_publisher_t publisher = rcl_get_zero_initialized_publisher(); + const rosidl_message_type_support_t * ts = + ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Strings); + const char * topic_name = "chatter"; + rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options(); + ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rcl_ret_t ret = rcl_publisher_fini(&publisher, this->node_ptr); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + }); + + test_msgs__msg__Strings msg_loaned; + if (rcl_publisher_can_loan_messages(&publisher)) { + EXPECT_EQ( + RCL_RET_OK, rcl_borrow_loaned_message( + &publisher, + ts, + reinterpret_cast(&msg_loaned))); + ASSERT_TRUE(rosidl_runtime_c__String__assign(&msg_loaned.string_value, "testing")); + EXPECT_EQ( + RCL_RET_OK, rcl_publish_loaned_message( + &publisher, + reinterpret_cast(&msg_loaned), + nullptr)); + } +} + +TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_access_functions) { + rcl_ret_t ret; + rcl_publisher_t publisher = rcl_get_zero_initialized_publisher(); + const rosidl_message_type_support_t * ts = + ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Strings); + const char * topic_name = "chatter"; + rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options(); + ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rcl_ret_t ret = rcl_publisher_fini(&publisher, this->node_ptr); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + }); + + const rcl_publisher_options_t * publisher_options_rcv; + publisher_options_rcv = rcl_publisher_get_options(&publisher); + EXPECT_EQ(rmw_qos_profile_default.reliability, publisher_options_rcv->qos.reliability); + EXPECT_EQ(rmw_qos_profile_default.history, publisher_options_rcv->qos.history); + EXPECT_EQ(rmw_qos_profile_default.depth, publisher_options_rcv->qos.depth); + EXPECT_EQ(rmw_qos_profile_default.durability, publisher_options_rcv->qos.durability); + EXPECT_TRUE(rcutils_allocator_is_valid(&(publisher_options_rcv->allocator))); + + rmw_publisher_t * pub_rmw_handle = rcl_publisher_get_rmw_handle(&publisher); + EXPECT_NE(nullptr, pub_rmw_handle); + + rcl_context_t * pub_context = rcl_publisher_get_context(&publisher); + EXPECT_TRUE(rcl_context_is_valid(pub_context)); + EXPECT_EQ(rcl_context_get_instance_id(context_ptr), rcl_context_get_instance_id(pub_context)); +} + +TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_assert_lieveliness) { + rcl_ret_t ret; + rcl_publisher_t publisher = rcl_get_zero_initialized_publisher(); + const rosidl_message_type_support_t * ts = + ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Strings); + const char * topic_name = "chatter"; + rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options(); + ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rcl_ret_t ret = rcl_publisher_fini(&publisher, this->node_ptr); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + }); + + EXPECT_EQ(RCL_RET_OK, rcl_publisher_assert_liveliness(&publisher)); + EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_assert_liveliness(nullptr)); +} From 7a884e7fcec6e3a05629d3e4da434b6499932f0a Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Tue, 19 May 2020 13:57:00 -0300 Subject: [PATCH 03/14] Add tests invalid arguments to get funcs Signed-off-by: Jorge Perez --- rcl/test/rcl/test_publisher.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index f2d015f7e..e4c4137f2 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -351,6 +351,15 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_acces rcl_context_t * pub_context = rcl_publisher_get_context(&publisher); EXPECT_TRUE(rcl_context_is_valid(pub_context)); EXPECT_EQ(rcl_context_get_instance_id(context_ptr), rcl_context_get_instance_id(pub_context)); + + EXPECT_EQ(nullptr, rcl_publisher_get_options(nullptr)); + EXPECT_EQ(nullptr, rcl_publisher_get_rmw_handle(nullptr)); + EXPECT_EQ(nullptr, rcl_publisher_get_context(nullptr)); + EXPECT_EQ(nullptr, rcl_publisher_get_actual_qos(nullptr)); + EXPECT_EQ(false, rcl_publisher_can_loan_messages(nullptr)); + EXPECT_EQ(nullptr, rcl_publisher_get_topic_name(nullptr)); + size_t count_size; + EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(nullptr, &count_size)); } TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_assert_lieveliness) { From 31f8b80f7b4f05187df617ee142865a913f7cfb3 Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Tue, 19 May 2020 17:38:48 -0300 Subject: [PATCH 04/14] Add peer review comments Signed-off-by: Jorge Perez --- rcl/test/rcl/test_init.cpp | 4 ++-- rcl/test/rcl/test_publisher.cpp | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/rcl/test/rcl/test_init.cpp b/rcl/test/rcl/test_init.cpp index 3b1b2267e..5df2a084b 100644 --- a/rcl/test/rcl/test_init.cpp +++ b/rcl/test/rcl/test_init.cpp @@ -273,12 +273,12 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_get_instance_id) } TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_access) { - rcl_ret_t ret; rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); - ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); + rcl_ret_t ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; rmw_init_options_t * options = rcl_init_options_get_rmw_init_options(&init_options); + ASSERT_NE(nullptr, options); EXPECT_EQ(0u, options->instance_id); EXPECT_EQ(nullptr, options->impl); diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index e4c4137f2..5861e614a 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -292,13 +292,13 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_ } TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_loan) { - rcl_ret_t ret; rcl_publisher_t publisher = rcl_get_zero_initialized_publisher(); const rosidl_message_type_support_t * ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Strings); const char * topic_name = "chatter"; rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options(); - ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options); + rcl_ret_t ret = + rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( { @@ -306,30 +306,31 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_loan) EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; }); - test_msgs__msg__Strings msg_loaned; + test_msgs__msg__Strings * msg_loaned; + test_msgs__msg__Strings ** msg_loaned_ptr = &msg_loaned; if (rcl_publisher_can_loan_messages(&publisher)) { EXPECT_EQ( RCL_RET_OK, rcl_borrow_loaned_message( &publisher, ts, - reinterpret_cast(&msg_loaned))); - ASSERT_TRUE(rosidl_runtime_c__String__assign(&msg_loaned.string_value, "testing")); + reinterpret_cast(&msg_loaned_ptr))); + ASSERT_TRUE(rosidl_runtime_c__String__assign(&(msg_loaned->string_value), "testing")); EXPECT_EQ( RCL_RET_OK, rcl_publish_loaned_message( &publisher, - reinterpret_cast(&msg_loaned), + &msg_loaned, nullptr)); } } TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_access_functions) { - rcl_ret_t ret; rcl_publisher_t publisher = rcl_get_zero_initialized_publisher(); const rosidl_message_type_support_t * ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Strings); const char * topic_name = "chatter"; rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options(); - ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options); + rcl_ret_t ret = + rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( { @@ -337,8 +338,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_acces EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; }); - const rcl_publisher_options_t * publisher_options_rcv; - publisher_options_rcv = rcl_publisher_get_options(&publisher); + const rcl_publisher_options_t * publisher_options_rcv = rcl_publisher_get_options(&publisher); + ASSERT_NE(nullptr, publisher_options_rcv); EXPECT_EQ(rmw_qos_profile_default.reliability, publisher_options_rcv->qos.reliability); EXPECT_EQ(rmw_qos_profile_default.history, publisher_options_rcv->qos.history); EXPECT_EQ(rmw_qos_profile_default.depth, publisher_options_rcv->qos.depth); @@ -363,13 +364,13 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_acces } TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_assert_lieveliness) { - rcl_ret_t ret; rcl_publisher_t publisher = rcl_get_zero_initialized_publisher(); const rosidl_message_type_support_t * ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Strings); const char * topic_name = "chatter"; rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options(); - ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options); + rcl_ret_t ret = + rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( { From 89af1d03b5e04ea3b394c5cc81bf068a95aac9b2 Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Tue, 19 May 2020 17:55:52 -0300 Subject: [PATCH 05/14] Fix pointer related issues Signed-off-by: Jorge Perez --- rcl/test/rcl/test_publisher.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index 5861e614a..31909b697 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -306,19 +306,19 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_loan) EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; }); - test_msgs__msg__Strings * msg_loaned; + test_msgs__msg__Strings * msg_loaned = nullptr; test_msgs__msg__Strings ** msg_loaned_ptr = &msg_loaned; if (rcl_publisher_can_loan_messages(&publisher)) { EXPECT_EQ( RCL_RET_OK, rcl_borrow_loaned_message( &publisher, ts, - reinterpret_cast(&msg_loaned_ptr))); + reinterpret_cast(msg_loaned_ptr))); ASSERT_TRUE(rosidl_runtime_c__String__assign(&(msg_loaned->string_value), "testing")); EXPECT_EQ( RCL_RET_OK, rcl_publish_loaned_message( &publisher, - &msg_loaned, + msg_loaned, nullptr)); } } From 58da62ab2394192730cbf75670fd0b99ced92d35 Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Wed, 20 May 2020 11:42:38 -0300 Subject: [PATCH 06/14] Add test for publisher implementation null Signed-off-by: Jorge Perez --- rcl/test/rcl/test_publisher.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index 31909b697..9abbddb11 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -353,6 +353,11 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_acces EXPECT_TRUE(rcl_context_is_valid(pub_context)); EXPECT_EQ(rcl_context_get_instance_id(context_ptr), rcl_context_get_instance_id(pub_context)); + struct rcl_publisher_impl_t * impl_pub = publisher.impl; + publisher.impl = nullptr; + EXPECT_FALSE(rcl_publisher_is_valid(&publisher)); + publisher.impl = impl_pub; + EXPECT_EQ(nullptr, rcl_publisher_get_options(nullptr)); EXPECT_EQ(nullptr, rcl_publisher_get_rmw_handle(nullptr)); EXPECT_EQ(nullptr, rcl_publisher_get_context(nullptr)); From 2b24e61f13827df4b7073823ba978088c529823f Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Thu, 21 May 2020 17:38:18 -0300 Subject: [PATCH 07/14] Add tests for valid argument on access functions Signed-off-by: Jorge Perez --- rcl/test/CMakeLists.txt | 1 + rcl/test/rcl/test_publisher.cpp | 63 ++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/rcl/test/CMakeLists.txt b/rcl/test/CMakeLists.txt index e570c786e..407bbc0d7 100644 --- a/rcl/test/CMakeLists.txt +++ b/rcl/test/CMakeLists.txt @@ -186,6 +186,7 @@ function(test_target_function) SRCS rcl/test_publisher.cpp ENV ${rmw_implementation_env_var} APPEND_LIBRARY_DIRS ${extra_lib_dirs} + INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../src/rcl/ LIBRARIES ${PROJECT_NAME} AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" "test_msgs" ) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index 9abbddb11..15b0ea8d2 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -25,6 +25,8 @@ #include "osrf_testing_tools_cpp/scope_exit.hpp" #include "rcl/error_handling.h" +#include "./publisher_impl.h" + #ifdef RMW_IMPLEMENTATION # define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX # define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX) @@ -353,19 +355,64 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_acces EXPECT_TRUE(rcl_context_is_valid(pub_context)); EXPECT_EQ(rcl_context_get_instance_id(context_ptr), rcl_context_get_instance_id(pub_context)); - struct rcl_publisher_impl_t * impl_pub = publisher.impl; + size_t count_size; + rcl_publisher_impl_t * saved_impl = (&publisher)->impl; + rcl_context_t * saved_context = (&publisher)->impl->context; + rmw_publisher_t * saved_rmw_handle = (&publisher)->impl->rmw_handle; + + // Change internal context to nullptr + publisher.impl->context = nullptr; + EXPECT_TRUE(rcl_publisher_is_valid_except_context(&publisher)); + EXPECT_NE(nullptr, rcl_publisher_get_topic_name(&publisher)); + EXPECT_NE(nullptr, rcl_publisher_get_rmw_handle(&publisher)); + EXPECT_NE(nullptr, rcl_publisher_get_actual_qos(&publisher)); + EXPECT_NE(nullptr, rcl_publisher_get_options(&publisher)); + EXPECT_FALSE(rcl_publisher_is_valid(&publisher)); + EXPECT_EQ(nullptr, rcl_publisher_get_context(&publisher)); + EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); + EXPECT_EQ( + RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); + publisher.impl->context = saved_context; + + // Change internal rmw_handle to nullptr + publisher.impl->rmw_handle = nullptr; + EXPECT_FALSE(rcl_publisher_is_valid_except_context(&publisher)); + EXPECT_FALSE(rcl_publisher_is_valid(&publisher)); + EXPECT_EQ(nullptr, rcl_publisher_get_topic_name(&publisher)); + EXPECT_EQ(nullptr, rcl_publisher_get_rmw_handle(&publisher)); + EXPECT_EQ(nullptr, rcl_publisher_get_actual_qos(&publisher)); + EXPECT_EQ(nullptr, rcl_publisher_get_options(&publisher)); + EXPECT_EQ(nullptr, rcl_publisher_get_context(&publisher)); + EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); + EXPECT_EQ( + RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); + publisher.impl->rmw_handle = saved_rmw_handle; + + // Change internal implementation to nullptr publisher.impl = nullptr; + EXPECT_FALSE(rcl_publisher_is_valid_except_context(&publisher)); EXPECT_FALSE(rcl_publisher_is_valid(&publisher)); - publisher.impl = impl_pub; - - EXPECT_EQ(nullptr, rcl_publisher_get_options(nullptr)); + EXPECT_EQ(nullptr, rcl_publisher_get_topic_name(&publisher)); + EXPECT_EQ(nullptr, rcl_publisher_get_rmw_handle(&publisher)); + EXPECT_EQ(nullptr, rcl_publisher_get_actual_qos(&publisher)); + EXPECT_EQ(nullptr, rcl_publisher_get_options(&publisher)); + EXPECT_EQ(nullptr, rcl_publisher_get_context(&publisher)); + EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); + EXPECT_EQ( + RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); + publisher.impl = saved_impl; + + // Null tests + EXPECT_FALSE(rcl_publisher_is_valid_except_context(nullptr)); + EXPECT_FALSE(rcl_publisher_is_valid(nullptr)); + EXPECT_EQ(nullptr, rcl_publisher_get_topic_name(nullptr)); EXPECT_EQ(nullptr, rcl_publisher_get_rmw_handle(nullptr)); - EXPECT_EQ(nullptr, rcl_publisher_get_context(nullptr)); EXPECT_EQ(nullptr, rcl_publisher_get_actual_qos(nullptr)); + EXPECT_EQ(nullptr, rcl_publisher_get_options(nullptr)); + EXPECT_EQ(nullptr, rcl_publisher_get_context(nullptr)); EXPECT_EQ(false, rcl_publisher_can_loan_messages(nullptr)); - EXPECT_EQ(nullptr, rcl_publisher_get_topic_name(nullptr)); - size_t count_size; - EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(nullptr, &count_size)); + EXPECT_EQ( + RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(nullptr, &count_size)); } TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_assert_lieveliness) { From 092911f8bb478db8791868dd12d6335521c45e1a Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Thu, 21 May 2020 18:22:35 -0300 Subject: [PATCH 08/14] Add more tests invalid publisher parameter Signed-off-by: Jorge Perez --- rcl/test/rcl/test_publisher.cpp | 43 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index 15b0ea8d2..59204e468 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -325,7 +325,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_loan) } } -TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_access_functions) { +TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_invalid_publisher) { rcl_publisher_t publisher = rcl_get_zero_initialized_publisher(); const rosidl_message_type_support_t * ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Strings); @@ -355,7 +355,11 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_acces EXPECT_TRUE(rcl_context_is_valid(pub_context)); EXPECT_EQ(rcl_context_get_instance_id(context_ptr), rcl_context_get_instance_id(pub_context)); + EXPECT_EQ(RCL_RET_OK, rcl_publisher_assert_liveliness(&publisher)); + size_t count_size; + test_msgs__msg__BasicTypes msg; + rcl_serialized_message_t serialized_msg = rmw_get_zero_initialized_serialized_message(); rcl_publisher_impl_t * saved_impl = (&publisher)->impl; rcl_context_t * saved_context = (&publisher)->impl->context; rmw_publisher_t * saved_rmw_handle = (&publisher)->impl->rmw_handle; @@ -372,6 +376,11 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_acces EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); + EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_assert_liveliness(&publisher)); + EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publish(&publisher, &msg, nullptr)); + EXPECT_EQ( + RCL_RET_PUBLISHER_INVALID, + rcl_publish_serialized_message(&publisher, &serialized_msg, nullptr)); publisher.impl->context = saved_context; // Change internal rmw_handle to nullptr @@ -386,6 +395,11 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_acces EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); + EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_assert_liveliness(&publisher)); + EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publish(&publisher, &msg, nullptr)); + EXPECT_EQ( + RCL_RET_PUBLISHER_INVALID, + rcl_publish_serialized_message(&publisher, &serialized_msg, nullptr)); publisher.impl->rmw_handle = saved_rmw_handle; // Change internal implementation to nullptr @@ -400,6 +414,11 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_acces EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); + EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_assert_liveliness(&publisher)); + EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publish(&publisher, &msg, nullptr)); + EXPECT_EQ( + RCL_RET_PUBLISHER_INVALID, + rcl_publish_serialized_message(&publisher, &serialized_msg, nullptr)); publisher.impl = saved_impl; // Null tests @@ -413,23 +432,9 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_acces EXPECT_EQ(false, rcl_publisher_can_loan_messages(nullptr)); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(nullptr, &count_size)); -} - -TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_assert_lieveliness) { - rcl_publisher_t publisher = rcl_get_zero_initialized_publisher(); - const rosidl_message_type_support_t * ts = - ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Strings); - const char * topic_name = "chatter"; - rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options(); - rcl_ret_t ret = - rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options); - ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( - { - rcl_ret_t ret = rcl_publisher_fini(&publisher, this->node_ptr); - EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - }); - - EXPECT_EQ(RCL_RET_OK, rcl_publisher_assert_liveliness(&publisher)); EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_assert_liveliness(nullptr)); + EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publish(nullptr, &msg, nullptr)); + EXPECT_EQ( + RCL_RET_PUBLISHER_INVALID, + rcl_publish_serialized_message(nullptr, &serialized_msg, nullptr)); } From 85f871beb654cba643eb3d47609cea4fcd0d476c Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Thu, 21 May 2020 19:00:39 -0300 Subject: [PATCH 09/14] Add rcl_reset_error to clear expected errors Signed-off-by: Jorge Perez --- rcl/test/rcl/test_publisher.cpp | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index 59204e468..423aa08cc 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -371,70 +371,114 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_invalid_publish EXPECT_NE(nullptr, rcl_publisher_get_rmw_handle(&publisher)); EXPECT_NE(nullptr, rcl_publisher_get_actual_qos(&publisher)); EXPECT_NE(nullptr, rcl_publisher_get_options(&publisher)); + rcl_reset_error(); EXPECT_FALSE(rcl_publisher_is_valid(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_context(&publisher)); + rcl_reset_error(); EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); + rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); + rcl_reset_error(); EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_assert_liveliness(&publisher)); + rcl_reset_error(); EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publish(&publisher, &msg, nullptr)); + rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publish_serialized_message(&publisher, &serialized_msg, nullptr)); + rcl_reset_error(); publisher.impl->context = saved_context; // Change internal rmw_handle to nullptr publisher.impl->rmw_handle = nullptr; EXPECT_FALSE(rcl_publisher_is_valid_except_context(&publisher)); + rcl_reset_error(); EXPECT_FALSE(rcl_publisher_is_valid(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_topic_name(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_rmw_handle(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_actual_qos(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_options(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_context(&publisher)); + rcl_reset_error(); EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); + rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); + rcl_reset_error(); EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_assert_liveliness(&publisher)); + rcl_reset_error(); EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publish(&publisher, &msg, nullptr)); + rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publish_serialized_message(&publisher, &serialized_msg, nullptr)); + rcl_reset_error(); publisher.impl->rmw_handle = saved_rmw_handle; // Change internal implementation to nullptr publisher.impl = nullptr; EXPECT_FALSE(rcl_publisher_is_valid_except_context(&publisher)); + rcl_reset_error(); EXPECT_FALSE(rcl_publisher_is_valid(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_topic_name(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_rmw_handle(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_actual_qos(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_options(&publisher)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_context(&publisher)); + rcl_reset_error(); EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); + rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); + rcl_reset_error(); EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_assert_liveliness(&publisher)); + rcl_reset_error(); EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publish(&publisher, &msg, nullptr)); + rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publish_serialized_message(&publisher, &serialized_msg, nullptr)); + rcl_reset_error(); publisher.impl = saved_impl; // Null tests EXPECT_FALSE(rcl_publisher_is_valid_except_context(nullptr)); + rcl_reset_error(); EXPECT_FALSE(rcl_publisher_is_valid(nullptr)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_topic_name(nullptr)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_rmw_handle(nullptr)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_actual_qos(nullptr)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_options(nullptr)); + rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_context(nullptr)); + rcl_reset_error(); EXPECT_EQ(false, rcl_publisher_can_loan_messages(nullptr)); + rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(nullptr, &count_size)); + rcl_reset_error(); EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publisher_assert_liveliness(nullptr)); + rcl_reset_error(); EXPECT_EQ(RCL_RET_PUBLISHER_INVALID, rcl_publish(nullptr, &msg, nullptr)); + rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publish_serialized_message(nullptr, &serialized_msg, nullptr)); + rcl_reset_error(); } From 0281210e3ccd17134fdc65c8b5c17e046d2776d9 Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Fri, 22 May 2020 11:28:25 -0300 Subject: [PATCH 10/14] Add two init-fini tests Signed-off-by: Jorge Perez --- rcl/test/rcl/test_publisher.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index 423aa08cc..62b2ac142 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -204,10 +204,18 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_ ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &default_publisher_options); EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; EXPECT_TRUE(rcl_publisher_is_valid(&publisher)); + // Try init a publisher already init + ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &default_publisher_options); + EXPECT_EQ(RCL_RET_ALREADY_INIT, ret) << rcl_get_error_string().str; ret = rcl_publisher_fini(&publisher, this->node_ptr); EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; rcl_reset_error(); + // Pass invalid node to fini + ret = rcl_publisher_fini(&publisher, nullptr); + EXPECT_EQ(RCL_RET_NODE_INVALID, ret) << rcl_get_error_string().str; + rcl_reset_error(); + // Try passing null for publisher in init. ret = rcl_publisher_init(nullptr, this->node_ptr, ts, topic_name, &default_publisher_options); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str; From 3c9d97b2d4ad28b1851abde0f20ad6932ed7c9ac Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Fri, 22 May 2020 13:02:26 -0300 Subject: [PATCH 11/14] Add tests for init functions Signed-off-by: Jorge Perez --- rcl/test/rcl/test_init.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rcl/test/rcl/test_init.cpp b/rcl/test/rcl/test_init.cpp index 5df2a084b..582b4c2fb 100644 --- a/rcl/test/rcl/test_init.cpp +++ b/rcl/test/rcl/test_init.cpp @@ -111,6 +111,10 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_and_shutdown EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); rcl_reset_error(); ASSERT_FALSE(rcl_context_is_valid(&context)); + // Already init + ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); + EXPECT_EQ(RCL_RET_ALREADY_INIT, ret) << rcl_get_error_string().str; + rcl_reset_error(); // If argc is not 0, but argv is, it should be an invalid argument. ret = rcl_init(42, nullptr, &init_options, &context); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); @@ -122,6 +126,11 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_and_shutdown EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); rcl_reset_error(); ASSERT_FALSE(rcl_context_is_valid(&context)); + // If argc is less than 1, argv is not null, it should be an invalid argument. + ret = rcl_init(0, invalid_args, &init_options, &context); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); + rcl_reset_error(); + ASSERT_FALSE(rcl_context_is_valid(&context)); // If either the allocate or deallocate function pointers are not set, it should be invalid arg. init_options.impl->allocator.allocate = nullptr; ret = rcl_init(0, nullptr, &init_options, &context); @@ -284,4 +293,8 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_acce const rcl_allocator_t * options_allocator = rcl_init_options_get_allocator(&init_options); EXPECT_TRUE(rcutils_allocator_is_valid(options_allocator)); + + rcl_init_options_t init_options_dst = rcl_get_zero_initialized_init_options(); + EXPECT_EQ(RCL_RET_OK, rcl_init_options_copy(&init_options, &init_options_dst)); + EXPECT_EQ(RCL_RET_ALREADY_INIT, rcl_init_options_copy(&init_options, &init_options_dst)); } From 88f93b0372ce0523cc768ff25ddfcf532d2e65d1 Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Wed, 27 May 2020 11:25:55 -0300 Subject: [PATCH 12/14] Address peer review feedack Signed-off-by: Jorge Perez --- rcl/test/rcl/test_publisher.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index 62b2ac142..40cc36c12 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -368,9 +368,9 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_invalid_publish size_t count_size; test_msgs__msg__BasicTypes msg; rcl_serialized_message_t serialized_msg = rmw_get_zero_initialized_serialized_message(); - rcl_publisher_impl_t * saved_impl = (&publisher)->impl; - rcl_context_t * saved_context = (&publisher)->impl->context; - rmw_publisher_t * saved_rmw_handle = (&publisher)->impl->rmw_handle; + rcl_publisher_impl_t * saved_impl = publisher.impl; + rcl_context_t * saved_context = publisher.impl->context; + rmw_publisher_t * saved_rmw_handle = publisher.impl->rmw_handle; // Change internal context to nullptr publisher.impl->context = nullptr; @@ -384,7 +384,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_invalid_publish rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_context(&publisher)); rcl_reset_error(); - EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); + EXPECT_FALSE(rcl_publisher_can_loan_messages(&publisher)); rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); @@ -415,7 +415,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_invalid_publish rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_context(&publisher)); rcl_reset_error(); - EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); + EXPECT_FALSE(rcl_publisher_can_loan_messages(&publisher)); rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); @@ -446,7 +446,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_invalid_publish rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_context(&publisher)); rcl_reset_error(); - EXPECT_EQ(false, rcl_publisher_can_loan_messages(&publisher)); + EXPECT_FALSE(rcl_publisher_can_loan_messages(&publisher)); rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(&publisher, &count_size)); @@ -476,7 +476,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_invalid_publish rcl_reset_error(); EXPECT_EQ(nullptr, rcl_publisher_get_context(nullptr)); rcl_reset_error(); - EXPECT_EQ(false, rcl_publisher_can_loan_messages(nullptr)); + EXPECT_FALSE(rcl_publisher_can_loan_messages(nullptr)); rcl_reset_error(); EXPECT_EQ( RCL_RET_PUBLISHER_INVALID, rcl_publisher_get_subscription_count(nullptr, &count_size)); From cc6e0bb836bf337ce1db947a274148b8fb2fa368 Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Wed, 27 May 2020 11:34:22 -0300 Subject: [PATCH 13/14] Add missing fini calls Signed-off-by: Jorge Perez --- rcl/test/rcl/test_init.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rcl/test/rcl/test_init.cpp b/rcl/test/rcl/test_init.cpp index 582b4c2fb..d3d9ef185 100644 --- a/rcl/test/rcl/test_init.cpp +++ b/rcl/test/rcl/test_init.cpp @@ -297,4 +297,7 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_acce rcl_init_options_t init_options_dst = rcl_get_zero_initialized_init_options(); EXPECT_EQ(RCL_RET_OK, rcl_init_options_copy(&init_options, &init_options_dst)); EXPECT_EQ(RCL_RET_ALREADY_INIT, rcl_init_options_copy(&init_options, &init_options_dst)); + + EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)); + EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options_dst)); } From c6bef037806c68c4d18cc7a64a12abce59d75353 Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Wed, 27 May 2020 13:55:50 -0300 Subject: [PATCH 14/14] Enable fini procedure after scope ends Signed-off-by: Jorge Perez --- rcl/test/rcl/test_init.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rcl/test/rcl/test_init.cpp b/rcl/test/rcl/test_init.cpp index d3d9ef185..da638f1e8 100644 --- a/rcl/test/rcl/test_init.cpp +++ b/rcl/test/rcl/test_init.cpp @@ -285,6 +285,10 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_acce rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); rcl_ret_t ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str; + }); rmw_init_options_t * options = rcl_init_options_get_rmw_init_options(&init_options); ASSERT_NE(nullptr, options); @@ -297,7 +301,5 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_acce rcl_init_options_t init_options_dst = rcl_get_zero_initialized_init_options(); EXPECT_EQ(RCL_RET_OK, rcl_init_options_copy(&init_options, &init_options_dst)); EXPECT_EQ(RCL_RET_ALREADY_INIT, rcl_init_options_copy(&init_options, &init_options_dst)); - - EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)); EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options_dst)); }