@@ -149,39 +149,58 @@ TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_with_bad_arguments) {
149149 EXPECT_EQ (RMW_RET_OK, ret) << rmw_get_error_string ().str ;
150150}
151151
152- TEST_F (CLASSNAME(TestClient, RMW_IMPLEMENTATION), destroy_with_bad_arguments) {
153- constexpr char service_name[] = " /test" ;
154- const rosidl_service_type_support_t * ts =
155- ROSIDL_GET_SRV_TYPE_SUPPORT (test_msgs, srv, BasicTypes);
156- rmw_client_t * client =
157- rmw_create_client (node, ts, service_name, &rmw_qos_profile_default);
158- ASSERT_NE (nullptr , client) << rmw_get_error_string ().str ;
152+ class CLASSNAME (TestClientUse, RMW_IMPLEMENTATION)
153+ : public CLASSNAME (TestClient, RMW_IMPLEMENTATION)
154+ {
155+ protected:
156+ using Base = CLASSNAME (TestClient, RMW_IMPLEMENTATION);
157+
158+ void SetUp () override
159+ {
160+ Base::SetUp ();
161+ constexpr char service_name[] = " /test" ;
162+ const rosidl_service_type_support_t * ts =
163+ ROSIDL_GET_SRV_TYPE_SUPPORT (test_msgs, srv, BasicTypes);
164+ client = rmw_create_client (node, ts, service_name, &rmw_qos_profile_default);
165+ ASSERT_NE (nullptr , client) << rmw_get_error_string ().str ;
166+ }
167+
168+ void TearDown () override
169+ {
170+ rmw_ret_t ret = rmw_destroy_client (node, client);
171+ EXPECT_EQ (RMW_RET_OK, ret) << rmw_get_error_string ().str ;
172+ Base::TearDown ();
173+ }
159174
160- // Destroying client with invalid arguments fails.
175+ rmw_client_t * client{nullptr };
176+ };
177+
178+ TEST_F (CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_with_null_node) {
161179 rmw_ret_t ret = rmw_destroy_client (nullptr , client);
162180 EXPECT_EQ (RMW_RET_INVALID_ARGUMENT, ret);
163181 rmw_reset_error ();
182+ }
164183
165- ret = rmw_destroy_client (node, nullptr );
184+ TEST_F (CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_null_client) {
185+ rmw_ret_t ret = rmw_destroy_client (node, nullptr );
166186 EXPECT_EQ (RMW_RET_INVALID_ARGUMENT, ret);
167187 rmw_reset_error ();
188+ }
168189
190+ TEST_F (CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_with_node_of_another_impl) {
169191 const char * implementation_identifier = node->implementation_identifier ;
170192 node->implementation_identifier = " not-an-rmw-implementation-identifier" ;
171- ret = rmw_destroy_client (node, client);
193+ rmw_ret_t ret = rmw_destroy_client (node, client);
172194 node->implementation_identifier = implementation_identifier;
173195 EXPECT_EQ (RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret);
174196 rmw_reset_error ();
197+ }
175198
176- implementation_identifier = client->implementation_identifier ;
199+ TEST_F (CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_client_of_another_impl) {
200+ const char * implementation_identifier = client->implementation_identifier ;
177201 client->implementation_identifier = " not-an-rmw-implementation-identifier" ;
178- ret = rmw_destroy_client (node, client);
202+ rmw_ret_t ret = rmw_destroy_client (node, client);
179203 client->implementation_identifier = implementation_identifier;
180204 EXPECT_EQ (RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret);
181205 rmw_reset_error ();
182-
183- // Destroying client still succeeds.
184- ret = rmw_destroy_client (node, client);
185- EXPECT_EQ (RMW_RET_OK, ret);
186- rmw_reset_error ();
187206}
0 commit comments