test_ns_node_remapping.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
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()));  // Same as b, but different constructor
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));  // local_remappings don't apply to this nodehandle's name
00064   PRINT(ros::NodeHandle sub_a(a, "a"));             // remapping were fully qualified, so don't apply to /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 }


test_roscpp
Author(s): Morgan Quigley mquigley@cs.stanford.edu, Ken Conley kwc@willowgarage.com
autogenerated on Sat Dec 28 2013 17:36:21