Skip to content

Commit

Permalink
Fix options usage in implementation, and add test to catch that code …
Browse files Browse the repository at this point in the history
…path.

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
  • Loading branch information
Emerson Knapp committed Mar 29, 2019
1 parent 7591bcf commit e82080f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 7 deletions.
9 changes: 9 additions & 0 deletions rclcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ if(BUILD_TESTING)
)
target_link_libraries(test_publisher ${PROJECT_NAME})
endif()
ament_add_gtest(test_pub_sub_option_interface test/test_pub_sub_option_interface.cpp)
if(TARGET test_pub_sub_option_interface)
ament_target_dependencies(test_pub_sub_option_interface
test_msgs
)
target_link_libraries(test_pub_sub_option_interface
${PROJECT_NAME}
)
endif()
ament_add_gtest(test_publisher_subscription_count_api test/test_publisher_subscription_count_api.cpp)
if(TARGET test_publisher_subscription_count_api)
ament_target_dependencies(test_publisher_subscription_count_api
Expand Down
14 changes: 7 additions & 7 deletions rclcpp/include/rclcpp/node_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ Node::create_publisher(
const PublisherOptions<Alloc> & options,
rclcpp::callback_group::CallbackGroup::SharedPtr group)
{
std::shared_ptr<Alloc> allocator = options.allocator();
std::shared_ptr<Alloc> allocator = options.allocator;
if (!allocator) {
allocator = std::make_shared<Alloc>();
}

return rclcpp::create_publisher<MessageT, Alloc, PublisherT>(
this->node_topics_.get(),
extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()),
options.qos_profile(),
options.event_callbacks(),
options.qos_profile,
options.event_callbacks,
group,
this->get_node_options().use_intra_process_comms(),
allocator);
Expand Down Expand Up @@ -179,7 +179,7 @@ Node::create_subscription(
{
using CallbackMessageT = typename rclcpp::subscription_traits::has_message_type<CallbackT>::type;

std::shared_ptr<Alloc> allocator = options.allocator();
std::shared_ptr<Alloc> allocator = options.allocator;
if (!allocator) {
allocator = std::make_shared<Alloc>();
}
Expand All @@ -193,10 +193,10 @@ Node::create_subscription(
this->node_topics_.get(),
extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()),
std::forward<CallbackT>(callback),
options.qos_profile(),
options.event_callbacks(),
options.qos_profile,
options.event_callbacks,
group,
options.ignore_local_publications(),
options.ignore_local_publications,
this->get_node_options().use_intra_process_comms(),
msg_mem_strat,
allocator);
Expand Down
56 changes: 56 additions & 0 deletions rclcpp/test/test_pub_sub_option_interface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2019 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>
#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "test_msgs/msg/empty.hpp"

class TestPublisher : public ::testing::Test
{
protected:
static void SetUpTestCase()
{
rclcpp::init(0, nullptr);
}

void SetUp()
{
node = std::make_shared<rclcpp::Node>("my_node", "/ns");
}

void TearDown()
{
node.reset();
}

rclcpp::Node::SharedPtr node;
};

/*
Testing construction and destruction.
*/
TEST_F(TestPublisher, construction_and_destruction) {
rclcpp::PublisherOptions<> pub_options;
auto publisher = node->create_publisher<test_msgs::msg::Empty>("topic", pub_options);

rclcpp::SubscriptionOptions<> sub_options;
auto subscription = node->create_subscription<test_msgs::msg::Empty>(
"topic",
[](std::shared_ptr<test_msgs::msg::Empty> test_msg) {(void) test_msg;},
sub_options);
}

0 comments on commit e82080f

Please sign in to comment.