-
Notifications
You must be signed in to change notification settings - Fork 537
Add tests type_support module #1308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
bba1121
b027cca
bdd02e7
4bb4fe6
0ba1439
624d35c
05d3db0
040abc4
f9df887
35f474d
811ad25
5b0137c
2c9b77e
82d7ae7
e8af00e
7add35f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| // Copyright 2017 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 <gtest/gtest.h> | ||
|
|
||
| #include <string> | ||
|
Blast545 marked this conversation as resolved.
Outdated
|
||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "rclcpp/exceptions.hpp" | ||
|
Blast545 marked this conversation as resolved.
Outdated
|
||
| #include "rclcpp/rclcpp.hpp" | ||
| #include "rclcpp/type_support_decl.hpp" | ||
| #include "test_msgs/msg/empty.hpp" | ||
|
|
||
| class TestTypeSupport : public ::testing::Test | ||
| { | ||
| public: | ||
| static void SetUpTestCase() | ||
|
Blast545 marked this conversation as resolved.
|
||
| { | ||
| if (!rclcpp::ok()) { | ||
| rclcpp::init(0, nullptr); | ||
| } | ||
| } | ||
|
|
||
| protected: | ||
| void initialize(const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions()) | ||
|
Blast545 marked this conversation as resolved.
Outdated
|
||
| { | ||
| node = std::make_shared<rclcpp::Node>("my_node", "/ns", node_options); | ||
| } | ||
|
|
||
| void TearDown() | ||
| { | ||
| node.reset(); | ||
|
Blast545 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| rclcpp::Node::SharedPtr node; | ||
| }; | ||
|
|
||
| const rcl_publisher_options_t PublisherOptions() | ||
| { | ||
| return rclcpp::PublisherOptionsWithAllocator<std::allocator<void>>().template | ||
| to_rcl_publisher_options<test_msgs::msg::Empty>(rclcpp::QoS(10)); | ||
| } | ||
|
|
||
| // Auxiliary classes used to test rosidl_message_type_support_t getters | ||
| // defined in type_support.hpp | ||
| const rosidl_message_type_support_t *ts_parameter_event = | ||
| rclcpp::type_support::get_parameter_event_msg_type_support(); | ||
|
|
||
| class TestTSParameterEvent : public rclcpp::PublisherBase | ||
| { | ||
| public: | ||
| explicit TestTSParameterEvent(rclcpp::Node * node) | ||
| : rclcpp::PublisherBase( | ||
| node->get_node_base_interface().get(), | ||
| "topicTSParameterEvent", | ||
| *ts_parameter_event, | ||
| PublisherOptions()) {} | ||
| }; | ||
|
|
||
| const rosidl_message_type_support_t *ts_set_parameter_result = | ||
| rclcpp::type_support::get_set_parameters_result_msg_type_support(); | ||
|
|
||
| class TestTSSetParameterResult : public rclcpp::PublisherBase | ||
| { | ||
| public: | ||
| explicit TestTSSetParameterResult(rclcpp::Node * node) | ||
| : rclcpp::PublisherBase( | ||
| node->get_node_base_interface().get(), | ||
| "topicTSSetParameterResult", | ||
| *ts_set_parameter_result, | ||
| PublisherOptions()) {} | ||
| }; | ||
|
|
||
| const rosidl_message_type_support_t *ts_parameter_descriptor = | ||
| rclcpp::type_support::get_parameter_descriptor_msg_type_support(); | ||
|
|
||
| class TestTSParameterDescriptor : public rclcpp::PublisherBase | ||
| { | ||
| public: | ||
| explicit TestTSParameterDescriptor(rclcpp::Node * node) | ||
| : rclcpp::PublisherBase( | ||
| node->get_node_base_interface().get(), | ||
| "topicTSParameterDescriptor", | ||
| *ts_parameter_descriptor, | ||
| PublisherOptions()) {} | ||
| }; | ||
|
|
||
| const rosidl_message_type_support_t *ts_list_parameter_result = | ||
| rclcpp::type_support::get_list_parameters_result_msg_type_support(); | ||
|
|
||
| class TestTSListParametersResult : public rclcpp::PublisherBase | ||
| { | ||
| public: | ||
| explicit TestTSListParametersResult(rclcpp::Node * node) | ||
| : rclcpp::PublisherBase( | ||
| node->get_node_base_interface().get(), | ||
| "topicTSListParametersResult", | ||
| *ts_list_parameter_result, | ||
| PublisherOptions()) {} | ||
| }; | ||
|
|
||
| /* | ||
| Test that the publisher is created properly for different msg typesupport | ||
| */ | ||
| TEST_F(TestTypeSupport, basic_getters) { | ||
| initialize(); | ||
| { | ||
| auto publisher = TestTSParameterEvent(node.get()); | ||
| std::shared_ptr<const rcl_publisher_t> publisher_handle = publisher.get_publisher_handle(); | ||
| EXPECT_NE(nullptr, publisher_handle); | ||
| } | ||
| { | ||
| auto publisher = TestTSSetParameterResult(node.get()); | ||
| std::shared_ptr<const rcl_publisher_t> publisher_handle = publisher.get_publisher_handle(); | ||
| EXPECT_NE(nullptr, publisher_handle); | ||
| } | ||
| { | ||
| auto publisher = TestTSParameterDescriptor(node.get()); | ||
| std::shared_ptr<const rcl_publisher_t> publisher_handle = publisher.get_publisher_handle(); | ||
| EXPECT_NE(nullptr, publisher_handle); | ||
| } | ||
| { | ||
| auto publisher = TestTSListParametersResult(node.get()); | ||
| std::shared_ptr<const rcl_publisher_t> publisher_handle = publisher.get_publisher_handle(); | ||
| EXPECT_NE(nullptr, publisher_handle); | ||
| } | ||
| } | ||
|
|
||
| void test_type_support_init_fini(const rosidl_service_type_support_t * ts){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be part of the TestTypeSupport fixture? If you chopped up each check in Also, I think this function should return an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take a look to the complete I made based in your comments, let me know if you think this is ok |
||
| auto node_handle_int = rclcpp::Node::make_shared("base_node"); | ||
| rcl_service_t service_handle = rcl_get_zero_initialized_service(); | ||
| rcl_service_options_t service_options = rcl_service_get_default_options(); | ||
| rcl_ret_t ret = rcl_service_init( | ||
| &service_handle, | ||
| node_handle_int->get_node_base_interface()->get_rcl_node_handle(), | ||
| ts, "base_node_service", &service_options); | ||
| if (ret != RCL_RET_OK) { | ||
| FAIL(); | ||
| return; | ||
|
Blast545 marked this conversation as resolved.
Outdated
|
||
| } | ||
| EXPECT_EQ(RCL_RET_OK, rcl_service_fini( | ||
| &service_handle, | ||
| node_handle_int->get_node_base_interface()->get_rcl_node_handle())); | ||
| } | ||
|
|
||
| /* Testing type support getters */ | ||
| TEST_F(TestTypeSupport, test_service_getters) { | ||
| initialize(); | ||
| { | ||
| const rosidl_service_type_support_t * ts = | ||
|
Blast545 marked this conversation as resolved.
Outdated
|
||
| rclcpp::type_support::get_get_parameters_srv_type_support(); | ||
| test_type_support_init_fini(ts); | ||
| } | ||
| { | ||
| const rosidl_service_type_support_t * ts = | ||
| rclcpp::type_support::get_get_parameters_srv_type_support(); | ||
| test_type_support_init_fini(ts); | ||
| } | ||
| { | ||
| const rosidl_service_type_support_t * ts = | ||
| rclcpp::type_support::get_get_parameter_types_srv_type_support(); | ||
| test_type_support_init_fini(ts); | ||
| } | ||
| { | ||
| const rosidl_service_type_support_t * ts = | ||
| rclcpp::type_support::get_set_parameters_srv_type_support(); | ||
| test_type_support_init_fini(ts); | ||
| } | ||
| { | ||
| const rosidl_service_type_support_t * ts = | ||
| rclcpp::type_support::get_list_parameters_srv_type_support(); | ||
| test_type_support_init_fini(ts); | ||
| } | ||
| { | ||
| const rosidl_service_type_support_t * ts = | ||
| rclcpp::type_support::get_describe_parameters_srv_type_support(); | ||
| test_type_support_init_fini(ts); | ||
| } | ||
| { | ||
| const rosidl_service_type_support_t * ts = | ||
| rclcpp::type_support::get_set_parameters_atomically_srv_type_support(); | ||
| test_type_support_init_fini(ts); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.