test_nodehandles_same_namespaces.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * test_nodehandles_same_namespaces.cpp
3 *
4 * Software License Agreement (BSD License)
5 *
6 * Copyright (c) 2016, University of Patras
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of University of Patras nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 * Authors: Aris Synodinos
37 *********************************************************************/
38 
39 #include <gtest/gtest.h>
40 #include <std_msgs/Bool.h>
41 #include <std_msgs/Byte.h>
42 #include <std_msgs/Empty.h>
43 #include <std_msgs/String.h>
44 #include <std_msgs/Float32.h>
45 #include <ros/ros.h>
46 
47 TEST(SameNamespaces, NodeletPrivateNodehandle) {
48  ros::NodeHandle nh;
49  ros::Duration(2).sleep();
50  ros::master::V_TopicInfo master_topics;
51  ros::master::getTopics(master_topics);
52  bool found_topic = false;
53 
54  for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
55  const ros::master::TopicInfo& info = *it;
56  if (info.datatype.compare("std_msgs/Bool") == 0) {
57  found_topic = true;
58  EXPECT_STREQ("/common_namespace/nodehandle_test/private", info.name.c_str());
59  }
60  }
61  EXPECT_TRUE(found_topic);
62 }
63 
64 TEST(SameNamespaces, NodeletNamespacedNodehandle) {
65  ros::NodeHandle nh;
66  ros::Duration(2).sleep();
67  ros::master::V_TopicInfo master_topics;
68  ros::master::getTopics(master_topics);
69  bool found_topic = false;
70 
71  for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
72  const ros::master::TopicInfo& info = *it;
73  if (info.datatype.compare("std_msgs/Byte") == 0) {
74  found_topic = true;
75  EXPECT_STREQ("/common_namespace/namespaced", info.name.c_str());
76  }
77  }
78  EXPECT_TRUE(found_topic);
79 }
80 
81 TEST(SameNamespaces, NodeletGlobalNodehandle) {
82  ros::NodeHandle nh;
83  ros::Duration(2).sleep();
84  ros::master::V_TopicInfo master_topics;
85  ros::master::getTopics(master_topics);
86  bool found_topic = false;
87 
88  for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
89  const ros::master::TopicInfo& info = *it;
90  if (info.datatype.compare("std_msgs/Time") == 0) {
91  found_topic = true;
92  EXPECT_STREQ("/global", info.name.c_str());
93  }
94  }
95  EXPECT_TRUE(found_topic);
96 }
97 
98 TEST(SameNamespaces, NodePrivateNodehandle) {
99  ros::NodeHandle nh("~");
100  ros::Publisher pub = nh.advertise<std_msgs::Empty>("private", 10);
101  ros::master::V_TopicInfo master_topics;
102  ros::master::getTopics(master_topics);
103  bool found_topic = false;
104 
105  for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
106  const ros::master::TopicInfo& info = *it;
107  if (info.datatype.compare("std_msgs/Empty") == 0) {
108  found_topic = true;
109  EXPECT_STREQ("/common_namespace/test_nodehandles/private", info.name.c_str());
110  }
111  }
112  EXPECT_TRUE(found_topic);
113 }
114 
115 TEST(SameNamespaces, NodeNamespacedNodehandle) {
116  ros::NodeHandle nh;
117  ros::Publisher pub = nh.advertise<std_msgs::String>("namespaced", 10);
118  ros::master::V_TopicInfo master_topics;
119  ros::master::getTopics(master_topics);
120  bool found_topic = false;
121 
122  for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
123  const ros::master::TopicInfo& info = *it;
124  if (info.datatype.compare("std_msgs/String") == 0) {
125  found_topic = true;
126  EXPECT_STREQ("/common_namespace/namespaced", info.name.c_str());
127  }
128  }
129  EXPECT_TRUE(found_topic);
130 }
131 
132 TEST(SameNamespaces, NodeGlobalNodehandle) {
133  ros::NodeHandle nh;
134  ros::Publisher pub = nh.advertise<std_msgs::Float32>("/public", 10);
135  ros::master::V_TopicInfo master_topics;
136  ros::master::getTopics(master_topics);
137  bool found_topic = false;
138 
139  for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
140  const ros::master::TopicInfo& info = *it;
141  if (info.datatype.compare("std_msgs/Float32") == 0) {
142  found_topic = true;
143  EXPECT_STREQ("/public", info.name.c_str());
144  }
145  }
146  EXPECT_TRUE(found_topic);
147 }
148 
149 int main(int argc, char **argv) {
150  testing::InitGoogleTest(&argc, argv);
151  ros::init(argc, argv, "test_nodehandles_same_namespaces");
152  return RUN_ALL_TESTS();
153 }
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
int main(int argc, char **argv)
std::vector< TopicInfo > V_TopicInfo
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
TEST(SameNamespaces, NodeletPrivateNodehandle)


test_nodelet
Author(s): Tully Foote
autogenerated on Sat Jul 18 2020 03:17:57