Pass along remappings from parent node handles (#2454)

This commit is contained in:
Josh Faust 2010-03-05 22:37:06 +00:00
parent 189485d7a2
commit cdadb20fbe
2 changed files with 38 additions and 0 deletions

View File

@ -84,6 +84,9 @@ NodeHandle::NodeHandle(const NodeHandle& parent, const std::string& ns)
callback_queue_ = parent.callback_queue_;
construct();
remappings_ = parent.remappings_;
unresolved_remappings_ = parent.unresolved_remappings_;
}
NodeHandle::NodeHandle(const NodeHandle& parent, const std::string& ns, const M_string& remappings)
@ -103,6 +106,7 @@ NodeHandle::NodeHandle(const NodeHandle& rhs)
namespace_ = rhs.namespace_;
callback_queue_ = rhs.callback_queue_;
remappings_ = rhs.remappings_;
unresolved_remappings_ = rhs.unresolved_remappings_;
construct();
}
@ -118,6 +122,7 @@ NodeHandle& NodeHandle::operator=(const NodeHandle& rhs)
namespace_ = rhs.namespace_;
callback_queue_ = rhs.callback_queue_;
remappings_ = rhs.remappings_;
unresolved_remappings_ = rhs.unresolved_remappings_;
return *this;
}

View File

@ -88,6 +88,39 @@ TEST(RoscppHandles, nodeHandleConstructionDestruction)
ASSERT_FALSE(ros::isStarted());
}
TEST(RoscppHandles, nodeHandleParentWithRemappings)
{
ros::M_string remappings;
remappings["a"] = "b";
remappings["c"] = "d";
ros::NodeHandle n1("", remappings);
// sanity checks
EXPECT_STREQ(n1.resolveName("a").c_str(), "/b");
EXPECT_STREQ(n1.resolveName("/a").c_str(), "/b");
EXPECT_STREQ(n1.resolveName("c").c_str(), "/d");
EXPECT_STREQ(n1.resolveName("/c").c_str(), "/d");
ros::NodeHandle n2(n1, "my_ns");
EXPECT_STREQ(n2.resolveName("a").c_str(), "/my_ns/a");
EXPECT_STREQ(n2.resolveName("/a").c_str(), "/b");
EXPECT_STREQ(n2.resolveName("c").c_str(), "/my_ns/c");
EXPECT_STREQ(n2.resolveName("/c").c_str(), "/d");
ros::NodeHandle n3(n2);
EXPECT_STREQ(n3.resolveName("a").c_str(), "/my_ns/a");
EXPECT_STREQ(n3.resolveName("/a").c_str(), "/b");
EXPECT_STREQ(n3.resolveName("c").c_str(), "/my_ns/c");
EXPECT_STREQ(n3.resolveName("/c").c_str(), "/d");
ros::NodeHandle n4;
n4 = n3;
EXPECT_STREQ(n4.resolveName("a").c_str(), "/my_ns/a");
EXPECT_STREQ(n4.resolveName("/a").c_str(), "/b");
EXPECT_STREQ(n4.resolveName("c").c_str(), "/my_ns/c");
EXPECT_STREQ(n4.resolveName("/c").c_str(), "/d");
}
int32_t g_recv_count = 0;
void subscriberCallback(const test_roscpp::TestArray::ConstPtr& msg)
{