inspection.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: Brian Gerkey */
31 
32 /*
33  * Test inspection functionality
34  */
35 
36 #include <string>
37 
38 #include <gtest/gtest.h>
39 
40 #include <ros/ros.h>
41 #include <ros/names.h>
42 #include <test_roscpp/TestArray.h>
43 #include <test_roscpp/TestStringInt.h>
44 #include <test_roscpp/TestEmpty.h>
45 
46 const char* g_node_name = "inspection_test";
47 
48 int g_argc;
49 char* g_argv[8];
50 
51 TEST(Inspection, getAdvertisedTopics)
52 {
53  ros::NodeHandle nh;
54 
55  std::vector<std::string> topics;
56 
58  // Note that it's 1, not 0, because the rosout appender has already snuck
59  // in and advertised.
60  ASSERT_EQ((int)topics.size(),1);
61  ASSERT_EQ(topics[0], "/rosout");
62 
63  {
64  ros::Publisher pub1 = nh.advertise<test_roscpp::TestArray>("topic",1);
65  ros::Publisher pub2 = nh.advertise<test_roscpp::TestArray>("ns/topic",1);
66  ros::Publisher pub3 = nh.advertise<test_roscpp::TestArray>("/global/topic",1);
67 
68  topics.clear();
70  // Note that it's 4, not 3, because the rosout appender has already snuck
71  // in and advertised.
72  ASSERT_EQ((int)topics.size(),4);
73 
74  // The following tests assume strict ordering of the topics, which is not
75  // guaranteed by the API.
76  ASSERT_EQ(topics[0], "/rosout");
77  ASSERT_EQ(topics[1], "/topic");
78  ASSERT_EQ(topics[2], "/ns/topic");
79  ASSERT_EQ(topics[3], "/global/topic");
80  }
81 
82  topics.clear();
84  // Note that it's 1, not 0, because the rosout appender has already snuck
85  // in and advertised.
86  ASSERT_EQ((int)topics.size(),1);
87  ASSERT_EQ(topics[0], "/rosout");
88 }
89 
90 TEST(Inspection, commandLineParsing)
91 {
92  ASSERT_EQ(g_argc, 5);
94 
95  ASSERT_STREQ(remappings["/foo"].c_str(), "/bar");
96  ASSERT_STREQ(remappings["/baz"].c_str(), "/bang");
97  ASSERT_STREQ(remappings["/bomb"].c_str(), "/barn");
98 }
99 
100 int
101 main(int argc, char** argv)
102 {
103  testing::InitGoogleTest(&argc, argv);
104 
105  g_argc = 8;
106 
107  g_argv[0] = strdup(argv[0]);
108  g_argv[1] = strdup("foo:=bar");
109  g_argv[2] = strdup("bat");
110  g_argv[3] = strdup("baz:=bang");
111  g_argv[4] = strdup("boom");
112  g_argv[5] = strdup("baz=bomb");
113  g_argv[6] = strdup("bomb:=barn");
114  g_argv[7] = strdup("--bangbang");
115 
116  ros::init( g_argc, g_argv, "inspection" );
117  ros::NodeHandle nh;
118 
119  return RUN_ALL_TESTS();
120 }
char * g_argv[8]
Definition: inspection.cpp:49
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL const M_string & getRemappings()
std::map< std::string, std::string > M_string
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char **argv)
Definition: inspection.cpp:101
const char * g_node_name
Definition: inspection.cpp:46
TEST(Inspection, getAdvertisedTopics)
Definition: inspection.cpp:51
ROSCPP_DECL void getAdvertisedTopics(V_string &topics)
int g_argc
Definition: inspection.cpp:48


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