00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <ros/ros.h>
00031 #include <gtest/gtest.h>
00032
00033 static int argc_;
00034 static char** argv_;
00035
00036 #define PRINT(cmd) printf(#cmd"\n"); cmd; printf("\n");
00037
00038 TEST(NamespaceRemappingTest, unqualified_remaps)
00039 {
00040 ros::M_string local_remappings;
00041 local_remappings.insert(std::make_pair("a", "Ra"));
00042 local_remappings.insert(std::make_pair("b", "Rb"));
00043 local_remappings.insert(std::make_pair("c", "Rc"));
00044
00045 PRINT(ros::NodeHandle base("a", local_remappings));
00046 PRINT(ros::NodeHandle a1(base, "a"));
00047 PRINT(ros::NodeHandle a2(base, "a", ros::M_string()));
00048 PRINT(ros::NodeHandle b(base, "b"));
00049 PRINT(ros::NodeHandle c(base, "c", ros::M_string()));
00050
00051 EXPECT_STREQ(base.getNamespace().c_str(), "/a");
00052 EXPECT_STREQ(a1.getNamespace().c_str(), "/a/Ra");
00053 EXPECT_STREQ(a2.getNamespace().c_str(), "/a/Ra");
00054 EXPECT_STREQ( b.getNamespace().c_str(), "/a/Rb");
00055 EXPECT_STREQ( c.getNamespace().c_str(), "/a/Rc");
00056 }
00057
00058 TEST(NamespaceRemappingTest, qualified_remaps)
00059 {
00060 ros::M_string local_remappings;
00061 local_remappings.insert(std::make_pair("/a", "/Ra"));
00062
00063 PRINT(ros::NodeHandle a("a", local_remappings));
00064 PRINT(ros::NodeHandle sub_a(a, "a"));
00065
00066 EXPECT_STREQ( a.getNamespace().c_str(), "/a");
00067 EXPECT_STREQ(sub_a.getNamespace().c_str(), "/a/a");
00068 }
00069
00070 TEST(NamespaceRemappingTest, unqualified_root_remaps)
00071 {
00072 ros::M_string local_remappings;
00073 local_remappings.insert(std::make_pair("a", "Ra"));
00074 local_remappings.insert(std::make_pair("b", "Rb"));
00075
00076 ros::NodeHandle base("", local_remappings);
00077 ros::NodeHandle a(base, "a");
00078 ros::NodeHandle b(base, "b", ros::M_string());
00079
00080 EXPECT_STREQ(a.getNamespace().c_str(), "/Ra");
00081 EXPECT_STREQ(b.getNamespace().c_str(), "/Rb");
00082 }
00083
00084 TEST(NamespaceRemappingTest, tilde_namespaces)
00085 {
00086 ros::M_string local_remappings;
00087 local_remappings.insert(std::make_pair("a", "Ra"));
00088 local_remappings.insert(std::make_pair("b", "Rb"));
00089
00090 ros::NodeHandle base("~", local_remappings);
00091 ros::NodeHandle a(base, "a");
00092 ros::NodeHandle b(base, "b", ros::M_string());
00093
00094 EXPECT_STREQ(base.getNamespace().c_str(), ros::this_node::getName().c_str());
00095 EXPECT_STREQ(a.getNamespace().c_str(), (ros::this_node::getName() + "/Ra").c_str());
00096 EXPECT_STREQ(b.getNamespace().c_str(), (ros::this_node::getName() + "/Rb").c_str());
00097 }
00098
00099 int main(int argc, char** argv)
00100 {
00101 testing::InitGoogleTest(&argc, argv);
00102 ros::init(argc, argv, "remapping_tester");
00103 argc_ = argc;
00104 argv_ = argv;
00105 return RUN_ALL_TESTS();
00106 }