41 #include <gtest/gtest.h>
47 TEST(MultipleLatchedPublishers, LatchedPublisherReceiveMultiple)
50 std::vector<ros::Publisher> latched_publishers = {
55 std::vector<ros::Publisher> unlatched_publishers = {
60 for (
auto& pub : latched_publishers) {
63 for (
auto& pub : unlatched_publishers) {
67 std::size_t msg_count = 0;
68 std::promise<bool> received_promise;
69 auto received_future = received_promise.get_future();
71 const auto sub = nh.
subscribe<std_msgs::Bool>(
"foo", 10, [&](
const std_msgs::Bool::ConstPtr&) {
72 if (++msg_count == latched_publishers.size()) {
73 received_promise.set_value(
true);
77 ASSERT_EQ(std::future_status::ready, received_future.wait_for(std::chrono::seconds(1)));
78 const auto received = received_future.get();
79 EXPECT_TRUE(received);
80 EXPECT_EQ(latched_publishers.size(), msg_count);
83 TEST(MultipleLatchedPublishers, TopicManagerIsLatched)
86 std::vector<ros::Publisher> publishers_bar = {
93 std::vector<ros::Publisher> publishers_baz = {
100 TEST(MultipleLatchedPublishers, TopicManagerLatchShutdown)
111 int main(
int argc,
char **argv) {
112 ::testing::InitGoogleTest(&argc, argv);
113 ros::init(argc, argv,
"test_multiple_latched_publishers");
116 return RUN_ALL_TESTS();