test_remapping.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, 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 the 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 #include <ros/ros.h>
31 #include <gtest/gtest.h>
32 
33 static int argc_;
34 static char** argv_;
35 
36 TEST(RemappingTest, remapping_test)
37 {
38  EXPECT_TRUE(argc_ >= 3);
39 
40  std::string expected_base_ns = argv_[1];
41  std::string expected_sub_ns = argv_[2];
42 
43  ros::NodeHandle nh;
44  //ros::NodeHandle pnh("~");
45 
46  bool use_local_remap = false;
47  EXPECT_TRUE(nh.getParam("use_local_remap", use_local_remap))
48  << "Param [~use_local_remap] must be defined\n";
49 
50  if (use_local_remap)
51  {
52  std::string remap_from, remap_to;
53  EXPECT_TRUE(nh.getParam("remap_from", remap_from)) << "Param [~remap_from] must be defined\n";
54  EXPECT_TRUE(nh.getParam("remap_to", remap_to)) << "Param [~remap_to] must be defined\n";
55 
56  // Construct the new node by passing in a dictionary of remaps
57  ros::M_string local_remappings;
58  local_remappings.insert(std::make_pair(remap_from, remap_to));
59 
60  ros::NodeHandle base_nh(nh, "base_namespace", local_remappings);
61  EXPECT_TRUE(base_nh.getNamespace() == expected_base_ns)
62  << "Error: \"" << base_nh.getNamespace() << "\" != \"" << expected_base_ns << "\"\n";
63 
64  ros::NodeHandle sub_nh(base_nh, "sub_namespace");
65  EXPECT_TRUE(sub_nh.getNamespace() == expected_sub_ns)
66  << "Error: \"" << sub_nh.getNamespace() << "\" != \"" << expected_sub_ns << "\"\n";
67  }
68  else
69  {
70  std::cout << "***********************************************************************\n";
71  ros::NodeHandle base_nh(nh, "base_namespace");
72  EXPECT_EQ(base_nh.getNamespace(), expected_base_ns);
73 
74  ros::NodeHandle sub_nh(base_nh, "sub_namespace");
75  EXPECT_EQ(sub_nh.getNamespace(), expected_sub_ns);
76  }
77 }
78 
79 int main(int argc, char** argv)
80 {
81  testing::InitGoogleTest(&argc, argv);
82  ros::init(argc, argv, "remapping_tester");
83  argc_ = argc;
84  argv_ = argv;
85  return RUN_ALL_TESTS();
86 }
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::map< std::string, std::string > M_string
int main(int argc, char **argv)
const std::string & getNamespace() const
static int argc_
bool getParam(const std::string &key, std::string &s) const
TEST(RemappingTest, remapping_test)
static char ** argv_


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