From 0c80d2706fa5c764c806eecf353e5ac720379225 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Mon, 27 Feb 2023 12:40:00 +0800 Subject: [PATCH 1/2] add a test case for cft options not supported Signed-off-by: Chen Lihui --- .../test/test_subscription.cpp | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test_rmw_implementation/test/test_subscription.cpp b/test_rmw_implementation/test/test_subscription.cpp index 38e54db3..e8892bcd 100644 --- a/test_rmw_implementation/test/test_subscription.cpp +++ b/test_rmw_implementation/test/test_subscription.cpp @@ -173,6 +173,47 @@ TEST_F(CLASSNAME(TestSubscription, RMW_IMPLEMENTATION), create_with_bad_argument EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; } +TEST_F(CLASSNAME(TestSubscription, RMW_IMPLEMENTATION), create_with_unsupported_cft_options) { + constexpr char topic_name[] = "/test"; + const rosidl_message_type_support_t * ts = + ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes); + + rmw_subscription_options_t options = rmw_get_default_subscription_options(); + auto allocator = rcutils_get_default_allocator(); + + rmw_subscription_content_filter_options_t * content_filter_options = + static_cast( + allocator.allocate( + sizeof(rmw_subscription_content_filter_options_t), allocator.state)); + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + allocator.deallocate(content_filter_options, allocator.state); + }); + *content_filter_options = rmw_get_zero_initialized_content_filter_options(); + + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filter_options_init( + "float32_value=not_exist_float_max()", + 0, + NULL, + &allocator, + content_filter_options)); + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + EXPECT_EQ( + RMW_RET_OK, + rmw_subscription_content_filter_options_fini(content_filter_options, &allocator)); + }); + options.content_filter_options = content_filter_options; + + rmw_subscription_t * sub = + rmw_create_subscription(node, ts, topic_name, &rmw_qos_profile_default, &options); + ASSERT_NE(nullptr, sub) << rmw_get_error_string().str; + EXPECT_FALSE(sub->is_cft_enabled); + rmw_ret_t ret = rmw_destroy_subscription(node, sub); + EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; +} + TEST_F(CLASSNAME(TestSubscription, RMW_IMPLEMENTATION), create_with_internal_errors) { constexpr char topic_name[] = "/test"; const rosidl_message_type_support_t * ts = From b2ff97eebda298eedf44f3be57afb954c2c79323 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Fri, 14 Apr 2023 08:51:20 +0800 Subject: [PATCH 2/2] unnessary to use heap variable Signed-off-by: Chen Lihui --- .../test/test_subscription.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/test_rmw_implementation/test/test_subscription.cpp b/test_rmw_implementation/test/test_subscription.cpp index e8892bcd..5d859d1f 100644 --- a/test_rmw_implementation/test/test_subscription.cpp +++ b/test_rmw_implementation/test/test_subscription.cpp @@ -181,15 +181,8 @@ TEST_F(CLASSNAME(TestSubscription, RMW_IMPLEMENTATION), create_with_unsupported_ rmw_subscription_options_t options = rmw_get_default_subscription_options(); auto allocator = rcutils_get_default_allocator(); - rmw_subscription_content_filter_options_t * content_filter_options = - static_cast( - allocator.allocate( - sizeof(rmw_subscription_content_filter_options_t), allocator.state)); - OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( - { - allocator.deallocate(content_filter_options, allocator.state); - }); - *content_filter_options = rmw_get_zero_initialized_content_filter_options(); + rmw_subscription_content_filter_options_t content_filter_options = + rmw_get_zero_initialized_content_filter_options(); EXPECT_EQ( RMW_RET_OK, rmw_subscription_content_filter_options_init( @@ -197,14 +190,14 @@ TEST_F(CLASSNAME(TestSubscription, RMW_IMPLEMENTATION), create_with_unsupported_ 0, NULL, &allocator, - content_filter_options)); + &content_filter_options)); OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( { EXPECT_EQ( RMW_RET_OK, - rmw_subscription_content_filter_options_fini(content_filter_options, &allocator)); + rmw_subscription_content_filter_options_fini(&content_filter_options, &allocator)); }); - options.content_filter_options = content_filter_options; + options.content_filter_options = &content_filter_options; rmw_subscription_t * sub = rmw_create_subscription(node, ts, topic_name, &rmw_qos_profile_default, &options);