From 315aa8b559b1edf41d06b56ea7c11235faa29a10 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Wed, 23 Sep 2020 13:11:06 -0300 Subject: [PATCH 1/3] Add service/client construction/destriction API test coverage. Signed-off-by: Michel Hidalgo --- test_rmw_implementation/CMakeLists.txt | 20 ++ test_rmw_implementation/test/test_client.cpp | 186 ++++++++++++++++++ test_rmw_implementation/test/test_service.cpp | 186 ++++++++++++++++++ 3 files changed, 392 insertions(+) create mode 100644 test_rmw_implementation/test/test_client.cpp create mode 100644 test_rmw_implementation/test/test_service.cpp diff --git a/test_rmw_implementation/CMakeLists.txt b/test_rmw_implementation/CMakeLists.txt index 7b072732e..7c7b1c2a8 100644 --- a/test_rmw_implementation/CMakeLists.txt +++ b/test_rmw_implementation/CMakeLists.txt @@ -109,6 +109,26 @@ if(BUILD_TESTING) ament_target_dependencies(test_unique_identifiers${target_suffix} osrf_testing_tools_cpp rcutils rmw rmw_implementation test_msgs ) + + ament_add_gtest(test_service${target_suffix} + test/test_service.cpp + ENV ${rmw_implementation_env_var} + ) + target_compile_definitions(test_service${target_suffix} + PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}") + ament_target_dependencies(test_service${target_suffix} + osrf_testing_tools_cpp rcutils rmw rmw_implementation test_msgs + ) + + ament_add_gtest(test_client${target_suffix} + test/test_client.cpp + ENV ${rmw_implementation_env_var} + ) + target_compile_definitions(test_client${target_suffix} + PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}") + ament_target_dependencies(test_client${target_suffix} + osrf_testing_tools_cpp rcutils rmw rmw_implementation test_msgs + ) endmacro() call_for_each_rmw_implementation(test_api) diff --git a/test_rmw_implementation/test/test_client.cpp b/test_rmw_implementation/test/test_client.cpp new file mode 100644 index 000000000..047a9dc89 --- /dev/null +++ b/test_rmw_implementation/test/test_client.cpp @@ -0,0 +1,186 @@ +// Copyright 2020 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "osrf_testing_tools_cpp/scope_exit.hpp" + +#include "rcutils/allocator.h" +#include "rcutils/strdup.h" + +#include "rmw/rmw.h" +#include "rmw/error_handling.h" + +#include "test_msgs/srv/basic_types.h" + +#include "./config.hpp" +#include "./testing_macros.hpp" + +#ifdef RMW_IMPLEMENTATION +# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX +# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX) +#else +# define CLASSNAME(NAME, SUFFIX) NAME +#endif + +class CLASSNAME (TestClient, RMW_IMPLEMENTATION) : public ::testing::Test +{ +protected: + void SetUp() override + { + rmw_init_options_t init_options = rmw_get_zero_initialized_init_options(); + rmw_ret_t ret = rmw_init_options_init(&init_options, rcutils_get_default_allocator()); + ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + rmw_ret_t ret = rmw_init_options_fini(&init_options); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; + }); + init_options.enclave = rcutils_strdup("/", rcutils_get_default_allocator()); + ASSERT_STREQ("/", init_options.enclave); + ret = rmw_init(&init_options, &context); + ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; + constexpr char node_name[] = "my_test_node"; + constexpr char node_namespace[] = "/my_test_ns"; + node = rmw_create_node(&context, node_name, node_namespace); + ASSERT_NE(nullptr, node) << rcutils_get_error_string().str; + } + + void TearDown() override + { + rmw_ret_t ret = rmw_destroy_node(node); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; + ret = rmw_shutdown(&context); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; + ret = rmw_context_fini(&context); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; + } + + rmw_context_t context{rmw_get_zero_initialized_context()}; + rmw_node_t * node{nullptr}; +}; + +TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_and_destroy) { + constexpr char service_name[] = "/test"; + const rosidl_service_type_support_t * ts = + ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); + rmw_client_t * client = + rmw_create_client(node, ts, service_name, &rmw_qos_profile_default); + ASSERT_NE(nullptr, client) << rmw_get_error_string().str; + rmw_ret_t ret = rmw_destroy_client(node, client); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; +} + +TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_and_destroy_native) { + constexpr char service_name[] = "/test"; + const rosidl_service_type_support_t * ts = + ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); + rmw_qos_profile_t native_qos_profile = rmw_qos_profile_default; + native_qos_profile.avoid_ros_namespace_conventions = true; + rmw_client_t * client = + rmw_create_client(node, ts, service_name, &native_qos_profile); + ASSERT_NE(nullptr, client) << rmw_get_error_string().str; + rmw_ret_t ret = rmw_destroy_client(node, client); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; +} + +TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_with_bad_arguments) { + constexpr char service_name[] = "/test"; + const rosidl_service_type_support_t * ts = + ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); + + rmw_client_t * client = + rmw_create_client(nullptr, ts, service_name, &rmw_qos_profile_default); + EXPECT_EQ(nullptr, client); + rmw_reset_error(); + + client = rmw_create_client(node, nullptr, service_name, &rmw_qos_profile_default); + EXPECT_EQ(nullptr, client); + rmw_reset_error(); + + const char * implementation_identifier = node->implementation_identifier; + node->implementation_identifier = "not-an-rmw-implementation-identifier"; + client = rmw_create_client(node, ts, service_name, &rmw_qos_profile_default); + node->implementation_identifier = implementation_identifier; + EXPECT_EQ(nullptr, client); + rmw_reset_error(); + + client = rmw_create_client(node, ts, nullptr, &rmw_qos_profile_default); + EXPECT_EQ(nullptr, client); + rmw_reset_error(); + + client = rmw_create_client(node, ts, "", &rmw_qos_profile_default); + EXPECT_EQ(nullptr, client); + rmw_reset_error(); + + constexpr char service_name_with_spaces[] = "/foo bar"; + client = rmw_create_client(node, ts, service_name_with_spaces, &rmw_qos_profile_default); + EXPECT_EQ(nullptr, client); + rmw_reset_error(); + + constexpr char relative_service_name[] = "foo"; + client = rmw_create_client(node, ts, relative_service_name, &rmw_qos_profile_default); + EXPECT_EQ(nullptr, client); + rmw_reset_error(); + + client = rmw_create_client(node, ts, service_name, nullptr); + EXPECT_EQ(nullptr, client); + rmw_reset_error(); + + client = rmw_create_client(node, ts, service_name, &rmw_qos_profile_unknown); + EXPECT_EQ(nullptr, client); + rmw_reset_error(); + + // Creating and destroying a client still succeeds. + client = rmw_create_client(node, ts, service_name, &rmw_qos_profile_default); + ASSERT_NE(nullptr, client) << rmw_get_error_string().str; + rmw_ret_t ret = rmw_destroy_client(node, client); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; +} + +TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), destroy_with_bad_arguments) { + constexpr char service_name[] = "/test"; + const rosidl_service_type_support_t * ts = + ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); + rmw_client_t * client = + rmw_create_client(node, ts, service_name, &rmw_qos_profile_default); + ASSERT_NE(nullptr, client) << rmw_get_error_string().str; + + // Destroying client with invalid arguments fails. + rmw_ret_t ret = rmw_destroy_client(nullptr, client); + EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret); + rmw_reset_error(); + + ret = rmw_destroy_client(node, nullptr); + EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret); + rmw_reset_error(); + + const char * implementation_identifier = node->implementation_identifier; + node->implementation_identifier = "not-an-rmw-implementation-identifier"; + ret = rmw_destroy_client(node, client); + node->implementation_identifier = implementation_identifier; + EXPECT_EQ(RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret); + rmw_reset_error(); + + implementation_identifier = client->implementation_identifier; + client->implementation_identifier = "not-an-rmw-implementation-identifier"; + ret = rmw_destroy_client(node, client); + client->implementation_identifier = implementation_identifier; + EXPECT_EQ(RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret); + rmw_reset_error(); + + // Destroying client still succeeds. + ret = rmw_destroy_client(node, client); + EXPECT_EQ(RMW_RET_OK, ret); + rmw_reset_error(); +} diff --git a/test_rmw_implementation/test/test_service.cpp b/test_rmw_implementation/test/test_service.cpp new file mode 100644 index 000000000..bffdc01fa --- /dev/null +++ b/test_rmw_implementation/test/test_service.cpp @@ -0,0 +1,186 @@ +// Copyright 2020 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "osrf_testing_tools_cpp/scope_exit.hpp" + +#include "rcutils/allocator.h" +#include "rcutils/strdup.h" + +#include "rmw/rmw.h" +#include "rmw/error_handling.h" + +#include "test_msgs/srv/basic_types.h" + +#include "./config.hpp" +#include "./testing_macros.hpp" + +#ifdef RMW_IMPLEMENTATION +# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX +# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX) +#else +# define CLASSNAME(NAME, SUFFIX) NAME +#endif + +class CLASSNAME (TestService, RMW_IMPLEMENTATION) : public ::testing::Test +{ +protected: + void SetUp() override + { + rmw_init_options_t init_options = rmw_get_zero_initialized_init_options(); + rmw_ret_t ret = rmw_init_options_init(&init_options, rcutils_get_default_allocator()); + ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + rmw_ret_t ret = rmw_init_options_fini(&init_options); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; + }); + init_options.enclave = rcutils_strdup("/", rcutils_get_default_allocator()); + ASSERT_STREQ("/", init_options.enclave); + ret = rmw_init(&init_options, &context); + ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; + constexpr char node_name[] = "my_test_node"; + constexpr char node_namespace[] = "/my_test_ns"; + node = rmw_create_node(&context, node_name, node_namespace); + ASSERT_NE(nullptr, node) << rcutils_get_error_string().str; + } + + void TearDown() override + { + rmw_ret_t ret = rmw_destroy_node(node); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; + ret = rmw_shutdown(&context); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; + ret = rmw_context_fini(&context); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; + } + + rmw_context_t context{rmw_get_zero_initialized_context()}; + rmw_node_t * node{nullptr}; +}; + +TEST_F(CLASSNAME(TestService, RMW_IMPLEMENTATION), create_and_destroy) { + constexpr char service_name[] = "/test"; + const rosidl_service_type_support_t * ts = + ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); + rmw_service_t * srv = + rmw_create_service(node, ts, service_name, &rmw_qos_profile_default); + ASSERT_NE(nullptr, srv) << rmw_get_error_string().str; + rmw_ret_t ret = rmw_destroy_service(node, srv); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; +} + +TEST_F(CLASSNAME(TestService, RMW_IMPLEMENTATION), create_and_destroy_native) { + constexpr char service_name[] = "/test"; + const rosidl_service_type_support_t * ts = + ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); + rmw_qos_profile_t native_qos_profile = rmw_qos_profile_default; + native_qos_profile.avoid_ros_namespace_conventions = true; + rmw_service_t * srv = + rmw_create_service(node, ts, service_name, &native_qos_profile); + ASSERT_NE(nullptr, srv) << rmw_get_error_string().str; + rmw_ret_t ret = rmw_destroy_service(node, srv); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; +} + +TEST_F(CLASSNAME(TestService, RMW_IMPLEMENTATION), create_with_bad_arguments) { + constexpr char service_name[] = "/test"; + const rosidl_service_type_support_t * ts = + ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); + + rmw_service_t * srv = + rmw_create_service(nullptr, ts, service_name, &rmw_qos_profile_default); + EXPECT_EQ(nullptr, srv); + rmw_reset_error(); + + srv = rmw_create_service(node, nullptr, service_name, &rmw_qos_profile_default); + EXPECT_EQ(nullptr, srv); + rmw_reset_error(); + + const char * implementation_identifier = node->implementation_identifier; + node->implementation_identifier = "not-an-rmw-implementation-identifier"; + srv = rmw_create_service(node, ts, service_name, &rmw_qos_profile_default); + node->implementation_identifier = implementation_identifier; + EXPECT_EQ(nullptr, srv); + rmw_reset_error(); + + srv = rmw_create_service(node, ts, nullptr, &rmw_qos_profile_default); + EXPECT_EQ(nullptr, srv); + rmw_reset_error(); + + srv = rmw_create_service(node, ts, "", &rmw_qos_profile_default); + EXPECT_EQ(nullptr, srv); + rmw_reset_error(); + + constexpr char service_name_with_spaces[] = "/foo bar"; + srv = rmw_create_service(node, ts, service_name_with_spaces, &rmw_qos_profile_default); + EXPECT_EQ(nullptr, srv); + rmw_reset_error(); + + constexpr char relative_service_name[] = "foo"; + srv = rmw_create_service(node, ts, relative_service_name, &rmw_qos_profile_default); + EXPECT_EQ(nullptr, srv); + rmw_reset_error(); + + srv = rmw_create_service(node, ts, service_name, nullptr); + EXPECT_EQ(nullptr, srv); + rmw_reset_error(); + + srv = rmw_create_service(node, ts, service_name, &rmw_qos_profile_unknown); + EXPECT_EQ(nullptr, srv); + rmw_reset_error(); + + // Creating and destroying a service still succeeds. + srv = rmw_create_service(node, ts, service_name, &rmw_qos_profile_default); + ASSERT_NE(nullptr, srv) << rmw_get_error_string().str; + rmw_ret_t ret = rmw_destroy_service(node, srv); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; +} + +TEST_F(CLASSNAME(TestService, RMW_IMPLEMENTATION), destroy_with_bad_arguments) { + constexpr char service_name[] = "/test"; + const rosidl_service_type_support_t * ts = + ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); + rmw_service_t * srv = + rmw_create_service(node, ts, service_name, &rmw_qos_profile_default); + ASSERT_NE(nullptr, srv) << rmw_get_error_string().str; + + // Destroying service with invalid arguments fails. + rmw_ret_t ret = rmw_destroy_service(nullptr, srv); + EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret); + rmw_reset_error(); + + ret = rmw_destroy_service(node, nullptr); + EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret); + rmw_reset_error(); + + const char * implementation_identifier = node->implementation_identifier; + node->implementation_identifier = "not-an-rmw-implementation-identifier"; + ret = rmw_destroy_service(node, srv); + node->implementation_identifier = implementation_identifier; + EXPECT_EQ(RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret); + rmw_reset_error(); + + implementation_identifier = srv->implementation_identifier; + srv->implementation_identifier = "not-an-rmw-implementation-identifier"; + ret = rmw_destroy_service(node, srv); + srv->implementation_identifier = implementation_identifier; + EXPECT_EQ(RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret); + rmw_reset_error(); + + // Destroying service still succeeds. + ret = rmw_destroy_service(node, srv); + EXPECT_EQ(RMW_RET_OK, ret); + rmw_reset_error(); +} From 399e059a2aa24d3523cc6db54acb059ea5cec348 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Thu, 24 Sep 2020 10:33:04 -0300 Subject: [PATCH 2/3] Please uncrustify. Signed-off-by: Michel Hidalgo --- test_rmw_implementation/test/test_client.cpp | 3 ++- test_rmw_implementation/test/test_service.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test_rmw_implementation/test/test_client.cpp b/test_rmw_implementation/test/test_client.cpp index 047a9dc89..25b46431f 100644 --- a/test_rmw_implementation/test/test_client.cpp +++ b/test_rmw_implementation/test/test_client.cpp @@ -42,7 +42,8 @@ class CLASSNAME (TestClient, RMW_IMPLEMENTATION) : public ::testing::Test rmw_init_options_t init_options = rmw_get_zero_initialized_init_options(); rmw_ret_t ret = rmw_init_options_init(&init_options, rcutils_get_default_allocator()); ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; - OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { rmw_ret_t ret = rmw_init_options_fini(&init_options); EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; }); diff --git a/test_rmw_implementation/test/test_service.cpp b/test_rmw_implementation/test/test_service.cpp index bffdc01fa..1185c2aa9 100644 --- a/test_rmw_implementation/test/test_service.cpp +++ b/test_rmw_implementation/test/test_service.cpp @@ -42,7 +42,8 @@ class CLASSNAME (TestService, RMW_IMPLEMENTATION) : public ::testing::Test rmw_init_options_t init_options = rmw_get_zero_initialized_init_options(); rmw_ret_t ret = rmw_init_options_init(&init_options, rcutils_get_default_allocator()); ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; - OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { rmw_ret_t ret = rmw_init_options_fini(&init_options); EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; }); From 8680b3ea9182f19115ce613d7022dd4d4a398a2a Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Fri, 25 Sep 2020 14:59:52 -0300 Subject: [PATCH 3/3] Address peer review comments. Signed-off-by: Michel Hidalgo --- test_rmw_implementation/test/test_client.cpp | 53 +++++++++++++------ test_rmw_implementation/test/test_service.cpp | 53 +++++++++++++------ 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/test_rmw_implementation/test/test_client.cpp b/test_rmw_implementation/test/test_client.cpp index 25b46431f..18bee27ae 100644 --- a/test_rmw_implementation/test/test_client.cpp +++ b/test_rmw_implementation/test/test_client.cpp @@ -149,39 +149,58 @@ TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_with_bad_arguments) { EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; } -TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), destroy_with_bad_arguments) { - constexpr char service_name[] = "/test"; - const rosidl_service_type_support_t * ts = - ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); - rmw_client_t * client = - rmw_create_client(node, ts, service_name, &rmw_qos_profile_default); - ASSERT_NE(nullptr, client) << rmw_get_error_string().str; +class CLASSNAME (TestClientUse, RMW_IMPLEMENTATION) + : public CLASSNAME(TestClient, RMW_IMPLEMENTATION) +{ +protected: + using Base = CLASSNAME(TestClient, RMW_IMPLEMENTATION); + + void SetUp() override + { + Base::SetUp(); + constexpr char service_name[] = "/test"; + const rosidl_service_type_support_t * ts = + ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); + client = rmw_create_client(node, ts, service_name, &rmw_qos_profile_default); + ASSERT_NE(nullptr, client) << rmw_get_error_string().str; + } + + void TearDown() override + { + rmw_ret_t ret = rmw_destroy_client(node, client); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; + Base::TearDown(); + } - // Destroying client with invalid arguments fails. + rmw_client_t * client{nullptr}; +}; + +TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_with_null_node) { rmw_ret_t ret = rmw_destroy_client(nullptr, client); EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret); rmw_reset_error(); +} - ret = rmw_destroy_client(node, nullptr); +TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_null_client) { + rmw_ret_t ret = rmw_destroy_client(node, nullptr); EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret); rmw_reset_error(); +} +TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_with_node_of_another_impl) { const char * implementation_identifier = node->implementation_identifier; node->implementation_identifier = "not-an-rmw-implementation-identifier"; - ret = rmw_destroy_client(node, client); + rmw_ret_t ret = rmw_destroy_client(node, client); node->implementation_identifier = implementation_identifier; EXPECT_EQ(RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret); rmw_reset_error(); +} - implementation_identifier = client->implementation_identifier; +TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_client_of_another_impl) { + const char * implementation_identifier = client->implementation_identifier; client->implementation_identifier = "not-an-rmw-implementation-identifier"; - ret = rmw_destroy_client(node, client); + rmw_ret_t ret = rmw_destroy_client(node, client); client->implementation_identifier = implementation_identifier; EXPECT_EQ(RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret); rmw_reset_error(); - - // Destroying client still succeeds. - ret = rmw_destroy_client(node, client); - EXPECT_EQ(RMW_RET_OK, ret); - rmw_reset_error(); } diff --git a/test_rmw_implementation/test/test_service.cpp b/test_rmw_implementation/test/test_service.cpp index 1185c2aa9..d68a3c7ab 100644 --- a/test_rmw_implementation/test/test_service.cpp +++ b/test_rmw_implementation/test/test_service.cpp @@ -149,39 +149,58 @@ TEST_F(CLASSNAME(TestService, RMW_IMPLEMENTATION), create_with_bad_arguments) { EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; } -TEST_F(CLASSNAME(TestService, RMW_IMPLEMENTATION), destroy_with_bad_arguments) { - constexpr char service_name[] = "/test"; - const rosidl_service_type_support_t * ts = - ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); - rmw_service_t * srv = - rmw_create_service(node, ts, service_name, &rmw_qos_profile_default); - ASSERT_NE(nullptr, srv) << rmw_get_error_string().str; +class CLASSNAME (TestServiceUse, RMW_IMPLEMENTATION) + : public CLASSNAME(TestService, RMW_IMPLEMENTATION) +{ +protected: + using Base = CLASSNAME(TestService, RMW_IMPLEMENTATION); + + void SetUp() override + { + Base::SetUp(); + constexpr char service_name[] = "/test"; + const rosidl_service_type_support_t * ts = + ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes); + srv = rmw_create_service(node, ts, service_name, &rmw_qos_profile_default); + ASSERT_NE(nullptr, srv) << rmw_get_error_string().str; + } + + void TearDown() override + { + rmw_ret_t ret = rmw_destroy_service(node, srv); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; + Base::TearDown(); + } - // Destroying service with invalid arguments fails. + rmw_service_t * srv{nullptr}; +}; + +TEST_F(CLASSNAME(TestServiceUse, RMW_IMPLEMENTATION), destroy_with_null_node) { rmw_ret_t ret = rmw_destroy_service(nullptr, srv); EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret); rmw_reset_error(); +} - ret = rmw_destroy_service(node, nullptr); +TEST_F(CLASSNAME(TestServiceUse, RMW_IMPLEMENTATION), destroy_null_service) { + rmw_ret_t ret = rmw_destroy_service(node, nullptr); EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret); rmw_reset_error(); +} +TEST_F(CLASSNAME(TestServiceUse, RMW_IMPLEMENTATION), destroy_with_node_of_another_impl) { const char * implementation_identifier = node->implementation_identifier; node->implementation_identifier = "not-an-rmw-implementation-identifier"; - ret = rmw_destroy_service(node, srv); + rmw_ret_t ret = rmw_destroy_service(node, srv); node->implementation_identifier = implementation_identifier; EXPECT_EQ(RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret); rmw_reset_error(); +} - implementation_identifier = srv->implementation_identifier; +TEST_F(CLASSNAME(TestServiceUse, RMW_IMPLEMENTATION), destroy_service_of_another_impl) { + const char * implementation_identifier = srv->implementation_identifier; srv->implementation_identifier = "not-an-rmw-implementation-identifier"; - ret = rmw_destroy_service(node, srv); + rmw_ret_t ret = rmw_destroy_service(node, srv); srv->implementation_identifier = implementation_identifier; EXPECT_EQ(RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret); rmw_reset_error(); - - // Destroying service still succeeds. - ret = rmw_destroy_service(node, srv); - EXPECT_EQ(RMW_RET_OK, ret); - rmw_reset_error(); }