Subscription tests using bind in member callback (#480)
* Add tests for member callbacks * Add tests for member callback in Test class (not working with gcc7) * Uncomment test that was failing * Linter fixup
This commit is contained in:
parent
d298fa4445
commit
2a17232ad0
1 changed files with 70 additions and 1 deletions
|
@ -24,6 +24,12 @@
|
|||
|
||||
class TestSubscription : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
void OnMessage(const rcl_interfaces::msg::IntraProcessMessage::SharedPtr msg)
|
||||
{
|
||||
(void)msg;
|
||||
}
|
||||
|
||||
protected:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
|
@ -32,7 +38,7 @@ protected:
|
|||
|
||||
void SetUp()
|
||||
{
|
||||
node = std::make_shared<rclcpp::Node>("my_node", "/ns");
|
||||
node = std::make_shared<rclcpp::Node>("test_subscription", "/ns");
|
||||
}
|
||||
|
||||
void TearDown()
|
||||
|
@ -43,6 +49,45 @@ protected:
|
|||
rclcpp::Node::SharedPtr node;
|
||||
};
|
||||
|
||||
class SubscriptionClassNodeInheritance : public rclcpp::Node
|
||||
{
|
||||
public:
|
||||
SubscriptionClassNodeInheritance()
|
||||
: Node("subscription_class_node_inheritance")
|
||||
{
|
||||
}
|
||||
|
||||
void OnMessage(const rcl_interfaces::msg::IntraProcessMessage::SharedPtr msg)
|
||||
{
|
||||
(void)msg;
|
||||
}
|
||||
|
||||
void CreateSubscription()
|
||||
{
|
||||
auto callback = std::bind(
|
||||
&SubscriptionClassNodeInheritance::OnMessage, this, std::placeholders::_1);
|
||||
using rcl_interfaces::msg::IntraProcessMessage;
|
||||
auto sub = this->create_subscription<IntraProcessMessage>("topic", callback);
|
||||
}
|
||||
};
|
||||
|
||||
class SubscriptionClass
|
||||
{
|
||||
public:
|
||||
void OnMessage(const rcl_interfaces::msg::IntraProcessMessage::SharedPtr msg)
|
||||
{
|
||||
(void)msg;
|
||||
}
|
||||
|
||||
void CreateSubscription()
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("test_subscription_member_callback", "/ns");
|
||||
auto callback = std::bind(&SubscriptionClass::OnMessage, this, std::placeholders::_1);
|
||||
using rcl_interfaces::msg::IntraProcessMessage;
|
||||
auto sub = node->create_subscription<IntraProcessMessage>("topic", callback);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Testing subscription construction and destruction.
|
||||
*/
|
||||
|
@ -61,3 +106,27 @@ TEST_F(TestSubscription, construction_and_destruction) {
|
|||
}, rclcpp::exceptions::InvalidTopicNameError);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Testing subscriptions using std::bind.
|
||||
*/
|
||||
TEST_F(TestSubscription, callback_bind) {
|
||||
using rcl_interfaces::msg::IntraProcessMessage;
|
||||
{
|
||||
// Member callback for plain class
|
||||
SubscriptionClass subscriptionObject;
|
||||
subscriptionObject.CreateSubscription();
|
||||
}
|
||||
{
|
||||
// Member callback for class inheriting from rclcpp::Node
|
||||
SubscriptionClassNodeInheritance subscriptionObject;
|
||||
subscriptionObject.CreateSubscription();
|
||||
}
|
||||
{
|
||||
// Member callback for class inheriting from testing::Test
|
||||
// Regression test for https://github.com/ros2/rclcpp/issues/479 where the TEST_F GTest macro
|
||||
// was interfering with rclcpp's `function_traits`.
|
||||
auto callback = std::bind(&TestSubscription::OnMessage, this, std::placeholders::_1);
|
||||
auto sub = node->create_subscription<IntraProcessMessage>("topic", callback);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue