|
28 | 28 | #include "../utils/rclcpp_gtest_macros.hpp" |
29 | 29 |
|
30 | 30 | #include "test_msgs/msg/empty.hpp" |
| 31 | +#include "std_msgs/msg/string.hpp" |
31 | 32 |
|
32 | 33 | // Note: This is a long running test with rmw_connext_cpp, if you change this file, please check |
33 | 34 | // that this test can complete fully, or adjust the timeout as necessary. |
@@ -148,6 +149,44 @@ class SubscriptionClass |
148 | 149 | } |
149 | 150 | }; |
150 | 151 |
|
| 152 | +class TestCftSubscription : public ::testing::Test |
| 153 | +{ |
| 154 | +public: |
| 155 | + static void SetUpTestCase() |
| 156 | + { |
| 157 | + rclcpp::init(0, nullptr); |
| 158 | + } |
| 159 | + |
| 160 | + static void TearDownTestCase() |
| 161 | + { |
| 162 | + rclcpp::shutdown(); |
| 163 | + } |
| 164 | + |
| 165 | + void SetUp() |
| 166 | + { |
| 167 | + node = std::make_shared<rclcpp::Node>("test_cft_subscription", "/ns"); |
| 168 | + rclcpp::SubscriptionOptionsBase options_base; |
| 169 | + options_base.content_filter_options.filter_expression = |
| 170 | + "data MATCH 'Hello World: 5' or data MATCH %0"; |
| 171 | + options_base.content_filter_options.expression_parameters = {"'Hello World: 10'"}; |
| 172 | + rclcpp::SubscriptionOptionsWithAllocator<std::allocator<void>> subscription_options( |
| 173 | + options_base); |
| 174 | + auto callback = [](std::shared_ptr<const std_msgs::msg::String>) {}; |
| 175 | + sub = node->create_subscription<std_msgs::msg::String>( |
| 176 | + "topic", 10, callback, subscription_options); |
| 177 | + } |
| 178 | + |
| 179 | + void TearDown() |
| 180 | + { |
| 181 | + sub.reset(); |
| 182 | + node.reset(); |
| 183 | + } |
| 184 | + |
| 185 | +protected: |
| 186 | + rclcpp::Node::SharedPtr node; |
| 187 | + rclcpp::Subscription<std_msgs::msg::String>::SharedPtr sub; |
| 188 | +}; |
| 189 | + |
151 | 190 | /* |
152 | 191 | Testing subscription construction and destruction. |
153 | 192 | */ |
@@ -444,6 +483,42 @@ TEST_F(TestSubscription, handle_loaned_message) { |
444 | 483 | EXPECT_NO_THROW(sub->handle_loaned_message(&msg, message_info)); |
445 | 484 | } |
446 | 485 |
|
| 486 | +TEST_F(TestCftSubscription, is_cft_supported) { |
| 487 | + { |
| 488 | + auto mock = mocking_utils::patch_and_return( |
| 489 | + "lib:rclcpp", rcl_subscription_is_cft_supported, false); |
| 490 | + EXPECT_FALSE(sub->is_cft_supported()); |
| 491 | + } |
| 492 | + |
| 493 | + { |
| 494 | + auto mock = mocking_utils::patch_and_return( |
| 495 | + "lib:rclcpp", rcl_subscription_is_cft_supported, true); |
| 496 | + EXPECT_TRUE(sub->is_cft_supported()); |
| 497 | + } |
| 498 | +} |
| 499 | + |
| 500 | +TEST_F(TestCftSubscription, get_cft_expression_parameters_error) { |
| 501 | + auto mock = mocking_utils::patch_and_return( |
| 502 | + "lib:rclcpp", rcl_subscription_get_cft_expression_parameters, RCL_RET_ERROR); |
| 503 | + |
| 504 | + std::string filter_expression; |
| 505 | + std::vector<std::string> expression_parameters; |
| 506 | + EXPECT_THROW( |
| 507 | + sub->get_cft_expression_parameters(filter_expression, expression_parameters), |
| 508 | + rclcpp::exceptions::RCLError); |
| 509 | +} |
| 510 | + |
| 511 | +TEST_F(TestCftSubscription, set_cft_expression_parameters_error) { |
| 512 | + auto mock = mocking_utils::patch_and_return( |
| 513 | + "lib:rclcpp", rcl_subscription_set_cft_expression_parameters, RCL_RET_ERROR); |
| 514 | + |
| 515 | + std::string filter_expression = "data MATCH %0"; |
| 516 | + std::string expression_parameter = "'Hello World: 8'"; |
| 517 | + EXPECT_THROW( |
| 518 | + sub->set_cft_expression_parameters(filter_expression, {expression_parameter}), |
| 519 | + rclcpp::exceptions::RCLError); |
| 520 | +} |
| 521 | + |
447 | 522 | /* |
448 | 523 | Testing subscription with intraprocess enabled and invalid QoS |
449 | 524 | */ |
|
0 commit comments