test_nodehandles_manager_namespaced.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(ManagerNamespaced, 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("/nodehandle_test/private", info.name.c_str());
59  }
60  }
61  EXPECT_TRUE(found_topic);
62 }
63 
64 // TODO(mikaelarguedas) reenable this once
65 // https://github.com/ros/nodelet_core/issues/7 is fixed
66 // TEST(ManagerNamespaced, NodeletNamespacedNodehandle) {
67 // ros::NodeHandle nh;
68 // ros::Duration(2).sleep();
69 // ros::master::V_TopicInfo master_topics;
70 // ros::master::getTopics(master_topics);
71 // bool found_topic = false;
72 //
73 // for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
74 // const ros::master::TopicInfo& info = *it;
75 // if (info.datatype.compare("std_msgs/Byte") == 0) {
76 // found_topic = true;
77 // EXPECT_STREQ("/namespaced", info.name.c_str());
78 // }
79 // }
80 // EXPECT_TRUE(found_topic);
81 // }
82 
83 TEST(ManagerNamespaced, NodeletGlobalNodehandle) {
84  ros::NodeHandle nh;
85  ros::Duration(2).sleep();
86  ros::master::V_TopicInfo master_topics;
87  ros::master::getTopics(master_topics);
88  bool found_topic = false;
89 
90  for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
91  const ros::master::TopicInfo& info = *it;
92  if (info.datatype.compare("std_msgs/Time") == 0) {
93  found_topic = true;
94  EXPECT_STREQ("/global", info.name.c_str());
95  }
96  }
97  EXPECT_TRUE(found_topic);
98 }
99 
100 TEST(ManagerNamespaced, NodePrivateNodehandle) {
101  ros::NodeHandle nh("~");
102  ros::Publisher pub = nh.advertise<std_msgs::Empty>("private", 10);
103  ros::master::V_TopicInfo master_topics;
104  ros::master::getTopics(master_topics);
105  bool found_topic = false;
106 
107  for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
108  const ros::master::TopicInfo& info = *it;
109  if (info.datatype.compare("std_msgs/Empty") == 0) {
110  found_topic = true;
111  EXPECT_STREQ("/test_nodehandles/private", info.name.c_str());
112  }
113  }
114  EXPECT_TRUE(found_topic);
115 }
116 
117 TEST(ManagerNamespaced, NodeNamespacedNodehandle) {
118  ros::NodeHandle nh;
119  ros::Publisher pub = nh.advertise<std_msgs::String>("namespaced", 10);
120  ros::master::V_TopicInfo master_topics;
121  ros::master::getTopics(master_topics);
122  bool found_topic = false;
123 
124  for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
125  const ros::master::TopicInfo& info = *it;
126  if (info.datatype.compare("std_msgs/String") == 0) {
127  found_topic = true;
128  EXPECT_STREQ("/namespaced", info.name.c_str());
129  }
130  }
131  EXPECT_TRUE(found_topic);
132 }
133 
134 TEST(ManagerNamespaced, NodeGlobalNodehandle) {
135  ros::NodeHandle nh;
136  ros::Publisher pub = nh.advertise<std_msgs::Float32>("/public", 10);
137  ros::master::V_TopicInfo master_topics;
138  ros::master::getTopics(master_topics);
139  bool found_topic = false;
140 
141  for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
142  const ros::master::TopicInfo& info = *it;
143  if (info.datatype.compare("std_msgs/Float32") == 0) {
144  found_topic = true;
145  EXPECT_STREQ("/public", info.name.c_str());
146  }
147  }
148  EXPECT_TRUE(found_topic);
149 }
150 
151 int main(int argc, char **argv) {
152  testing::InitGoogleTest(&argc, argv);
153  ros::init(argc, argv, "test_nodehandles_manager_namespaced");
154  return RUN_ALL_TESTS();
155 }
int main(int argc, char **argv)
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)
std::vector< TopicInfo > V_TopicInfo
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
TEST(ManagerNamespaced, NodeletPrivateNodehandle)


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