From 14c873f5638333287a91f7dfccdad06adca03b7c Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Mon, 18 Nov 2024 23:25:45 +0000 Subject: [PATCH] fix checking topics Signed-off-by: Ian Chen --- src/Node.cc | 2 +- src/Node_TEST.cc | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Node.cc b/src/Node.cc index a931478d..67160c1a 100644 --- a/src/Node.cc +++ b/src/Node.cc @@ -1019,7 +1019,7 @@ Node::Publisher Node::Advertise(const std::string &_topic, auto currentTopics = this->AdvertisedTopics(); if (std::find(currentTopics.begin(), currentTopics.end(), - fullyQualifiedTopic) != currentTopics.end()) + _topic) != currentTopics.end()) { std::cerr << "Topic [" << topic << "] already advertised. You cannot" << " advertise the same topic twice on the same node." diff --git a/src/Node_TEST.cc b/src/Node_TEST.cc index 0bfb79bc..7ff212d0 100644 --- a/src/Node_TEST.cc +++ b/src/Node_TEST.cc @@ -951,10 +951,12 @@ TEST(NodeTest, AdvertiseTwoEqualTopics) auto pub1 = node1.Advertise(g_topic); EXPECT_TRUE(pub1); - auto pub2 = node1.Advertise(g_topic); + auto pub2 = node1.Advertise(g_topic); EXPECT_FALSE(pub2); - auto pub3 = node2.Advertise(g_topic); - EXPECT_TRUE(pub3); + auto pub3 = node1.Advertise(g_topic); + EXPECT_FALSE(pub3); + auto pub4 = node2.Advertise(g_topic); + EXPECT_TRUE(pub4); } //////////////////////////////////////////////////