Skip to content

Commit

Permalink
extended test for shared callback to cover more use cases
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Hampp <j.hampp@denso-adas.de>
  • Loading branch information
Joshua Hampp committed Jan 3, 2024
1 parent 2115b26 commit 4f6e466
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions rclcpp/test/rclcpp/test_intra_process_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ TEST_F(TestIntraProcessSubscriber, constructor) {
}

/*
Test methods of SubscriptionIntraProcess:
Test methods of SubscriptionIntraProcess with shared callback:
* is_serialized
* deserialize_message
* serve_serialized_message
*/
TEST_F(TestIntraProcessSubscriber, methods) {
TEST_F(TestIntraProcessSubscriber, methods_shared) {
using MessageT = test_msgs::msg::Empty;
using Alloc = std::allocator<void>;

Expand Down Expand Up @@ -120,8 +121,51 @@ TEST_F(TestIntraProcessSubscriber, methods) {
take_shared_subscriptions);

// execute subscriber callback
auto data = subscriber->take_data();
subscriber->execute(data);
{
auto data = subscriber->take_data();
subscriber->execute(data);
}

// check if message was received
EXPECT_EQ(1u, counter);

// add a 2nd shared subscriber to cover more code
auto subscriber2 = std::make_shared<rclcpp::experimental::SubscriptionIntraProcess<MessageT,
MessageT>>(
callback,
allocator,
context,
"topic",
rclcpp::SystemDefaultsQoS().keep_last(10),
rclcpp::IntraProcessBufferType::SharedPtr);
const auto sub2_id = ipm->add_subscription(subscriber2);
take_shared_subscriptions.push_back(sub2_id);

subscriber->serve_serialized_message(
&serialized_message,
ipm.get(),
intra_process_publisher_id,
reinterpret_cast<void *>(allocator.get()),
take_ownership_subscriptions,
take_shared_subscriptions);

// execute subscribers callback
{
auto data = subscriber->take_data();
subscriber->execute(data);
}

// check if message was received
EXPECT_EQ(2u, counter);

{
auto data = subscriber2->take_data();
subscriber2->execute(data);
}

// check if message was received
EXPECT_EQ(3u, counter);
}

// check if message was received
EXPECT_EQ(1u, counter);
Expand Down

0 comments on commit 4f6e466

Please sign in to comment.