Skip to content

Commit

Permalink
Add tests bad type_support implementation (#152)
Browse files Browse the repository at this point in the history
Signed-off-by: lobotuerk <[email protected]>
Co-authored-by: Michel Hidalgo <[email protected]>
  • Loading branch information
Lobotuerk and hidmic authored Oct 1, 2020
1 parent 7ab18b7 commit da37756
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test_rmw_implementation/test/test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_with_bad_arguments) {
EXPECT_EQ(nullptr, client);
rmw_reset_error();

rosidl_service_type_support_t * non_const_ts =
const_cast<rosidl_service_type_support_t *>(ts);
const char * typesupport_identifier = non_const_ts->typesupport_identifier;
non_const_ts->typesupport_identifier = "not-a-typesupport-identifier";
client = rmw_create_client(node, non_const_ts, service_name, &rmw_qos_profile_default);
EXPECT_EQ(nullptr, client);
rmw_reset_error();
non_const_ts->typesupport_identifier = typesupport_identifier;

// 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;
Expand Down
9 changes: 9 additions & 0 deletions test_rmw_implementation/test/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ TEST_F(CLASSNAME(TestPublisher, RMW_IMPLEMENTATION), create_with_bad_arguments)
EXPECT_EQ(nullptr, pub);
rmw_reset_error();

rosidl_message_type_support_t * non_const_ts =
const_cast<rosidl_message_type_support_t *>(ts);
const char * typesupport_identifier = non_const_ts->typesupport_identifier;
non_const_ts->typesupport_identifier = "not-a-typesupport-identifier";
pub = rmw_create_publisher(node, non_const_ts, topic_name, &rmw_qos_profile_default, &options);
EXPECT_EQ(nullptr, pub);
rmw_reset_error();
non_const_ts->typesupport_identifier = typesupport_identifier;

// Creating and destroying a publisher still succeeds.
pub = rmw_create_publisher(node, ts, topic_name, &rmw_qos_profile_default, &options);
ASSERT_NE(nullptr, pub) << rmw_get_error_string().str;
Expand Down
18 changes: 18 additions & 0 deletions test_rmw_implementation/test/test_serialize_deserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ TEST_F(CLASSNAME(TestSerializeDeserialize, RMW_IMPLEMENTATION), serialize_with_b
EXPECT_NE(RMW_RET_OK, rmw_serialize(&input_message, ts, &serialized_message));
rmw_reset_error();

EXPECT_EQ(RMW_RET_OK, rmw_serialized_message_fini(&serialized_message)) <<
rmw_get_error_string().str;

rcutils_allocator_t default_allocator = rcutils_get_default_allocator();
ASSERT_EQ(
RMW_RET_OK, rmw_serialized_message_init(
&serialized_message, 0lu, &default_allocator)) << rmw_get_error_string().str;

rosidl_message_type_support_t * non_const_ts =
const_cast<rosidl_message_type_support_t *>(ts);
const char * typesupport_identifier = non_const_ts->typesupport_identifier;
non_const_ts->typesupport_identifier = "not-a-typesupport-identifier";

EXPECT_NE(RMW_RET_OK, rmw_serialize(&input_message, non_const_ts, &serialized_message));
rmw_reset_error();

non_const_ts->typesupport_identifier = typesupport_identifier;

EXPECT_EQ(RMW_RET_OK, rmw_serialized_message_fini(&serialized_message)) <<
rmw_get_error_string().str;
}
Expand Down
9 changes: 9 additions & 0 deletions test_rmw_implementation/test/test_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ TEST_F(CLASSNAME(TestService, RMW_IMPLEMENTATION), create_with_bad_arguments) {
EXPECT_EQ(nullptr, srv);
rmw_reset_error();

rosidl_service_type_support_t * non_const_ts =
const_cast<rosidl_service_type_support_t *>(ts);
const char * typesupport_identifier = non_const_ts->typesupport_identifier;
non_const_ts->typesupport_identifier = "not-a-typesupport-identifier";
srv = rmw_create_service(node, non_const_ts, service_name, &rmw_qos_profile_default);
EXPECT_EQ(nullptr, srv);
rmw_reset_error();
non_const_ts->typesupport_identifier = typesupport_identifier;

// 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;
Expand Down
11 changes: 11 additions & 0 deletions test_rmw_implementation/test/test_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ TEST_F(CLASSNAME(TestSubscription, RMW_IMPLEMENTATION), create_with_bad_argument
EXPECT_EQ(nullptr, sub);
rmw_reset_error();

rosidl_message_type_support_t * non_const_ts =
const_cast<rosidl_message_type_support_t *>(ts);
const char * typesupport_identifier = non_const_ts->typesupport_identifier;
non_const_ts->typesupport_identifier = "not-a-typesupport-identifier";
sub = rmw_create_subscription(
node, non_const_ts, topic_name,
&rmw_qos_profile_default, &options);
EXPECT_EQ(nullptr, sub);
rmw_reset_error();
non_const_ts->typesupport_identifier = typesupport_identifier;

// Creating and destroying a subscription still succeeds.
sub = rmw_create_subscription(node, ts, topic_name, &rmw_qos_profile_default, &options);
ASSERT_NE(nullptr, sub) << rmw_get_error_string().str;
Expand Down

0 comments on commit da37756

Please sign in to comment.