name_remapping_with_ns.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /* Author: Josh Faust */
31 
32 /*
33  * Test name remapping. Assumes the parameter "test" is remapped to "test_remap", and the node name is remapped to "name_remapped"
34  */
35 
36 #include <string>
37 #include <sstream>
38 #include <fstream>
39 
40 #include <gtest/gtest.h>
41 
42 #include <time.h>
43 #include <stdlib.h>
44 
45 #include "ros/ros.h"
46 #include <ros/param.h>
47 #include <ros/names.h>
48 
49 TEST(roscpp, parameterRemapping)
50 {
51  std::string param;
52  ASSERT_STREQ(ros::names::resolve("test_full").c_str(), "/b/test_full");
53  ASSERT_TRUE(ros::param::get("test_full", param));
54  ASSERT_STREQ(ros::names::resolve("/a/test_full").c_str(), "/b/test_full");
55  ASSERT_TRUE(ros::param::get("/a/test_full", param));
56 
57  ASSERT_STREQ(ros::names::resolve("test_local").c_str(), "/a/test_local2");
58  ASSERT_TRUE(ros::param::get("test_local", param));
59  ASSERT_STREQ(ros::names::resolve("/a/test_local").c_str(), "/a/test_local2");
60  ASSERT_TRUE(ros::param::get("/a/test_local", param));
61 
62  ASSERT_STREQ(ros::names::resolve("test_relative").c_str(), "/b/test_relative");
63  ASSERT_TRUE(ros::param::get("test_relative", param));
64  ASSERT_STREQ(ros::names::resolve("/a/test_relative").c_str(), "/b/test_relative");
65  ASSERT_TRUE(ros::param::get("/a/test_relative", param));
66 }
67 
68 TEST(roscpp, nodeNameRemapping)
69 {
70  std::string node_name = ros::this_node::getName();
71  ASSERT_STREQ(node_name.c_str(), "/a/name_remapped_with_ns");
72 }
73 int
74 main(int argc, char** argv)
75 {
76  testing::InitGoogleTest(&argc, argv);
77  ros::init( argc, argv, "name_remapping_with_ns" );
78  ros::NodeHandle nh;
79 
80  return RUN_ALL_TESTS();
81 }
bool param(const std::string &param_name, T &param_val, const T &default_val)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL const std::string & getName()
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
int main(int argc, char **argv)
TEST(roscpp, parameterRemapping)
ROSCPP_DECL bool get(const std::string &key, std::string &s)


test_roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:46