Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <gtest/gtest.h>
00040 #include <std_msgs/Bool.h>
00041 #include <std_msgs/Byte.h>
00042 #include <std_msgs/Empty.h>
00043 #include <std_msgs/String.h>
00044 #include <std_msgs/Float32.h>
00045 #include <ros/ros.h>
00046
00047 TEST(ManagerNamespaced, NodeletPrivateNodehandle) {
00048 ros::NodeHandle nh;
00049 ros::Duration(2).sleep();
00050 ros::master::V_TopicInfo master_topics;
00051 ros::master::getTopics(master_topics);
00052 bool found_topic = false;
00053
00054 for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00055 const ros::master::TopicInfo& info = *it;
00056 if (info.datatype.compare("std_msgs/Bool") == 0) {
00057 found_topic = true;
00058 EXPECT_STREQ("/nodehandle_test/private", info.name.c_str());
00059 }
00060 }
00061 EXPECT_TRUE(found_topic);
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 TEST(ManagerNamespaced, NodeletGlobalNodehandle) {
00084 ros::NodeHandle nh;
00085 ros::Duration(2).sleep();
00086 ros::master::V_TopicInfo master_topics;
00087 ros::master::getTopics(master_topics);
00088 bool found_topic = false;
00089
00090 for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00091 const ros::master::TopicInfo& info = *it;
00092 if (info.datatype.compare("std_msgs/Time") == 0) {
00093 found_topic = true;
00094 EXPECT_STREQ("/global", info.name.c_str());
00095 }
00096 }
00097 EXPECT_TRUE(found_topic);
00098 }
00099
00100 TEST(ManagerNamespaced, NodePrivateNodehandle) {
00101 ros::NodeHandle nh("~");
00102 ros::Publisher pub = nh.advertise<std_msgs::Empty>("private", 10);
00103 ros::master::V_TopicInfo master_topics;
00104 ros::master::getTopics(master_topics);
00105 bool found_topic = false;
00106
00107 for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00108 const ros::master::TopicInfo& info = *it;
00109 if (info.datatype.compare("std_msgs/Empty") == 0) {
00110 found_topic = true;
00111 EXPECT_STREQ("/test_nodehandles/private", info.name.c_str());
00112 }
00113 }
00114 EXPECT_TRUE(found_topic);
00115 }
00116
00117 TEST(ManagerNamespaced, NodeNamespacedNodehandle) {
00118 ros::NodeHandle nh;
00119 ros::Publisher pub = nh.advertise<std_msgs::String>("namespaced", 10);
00120 ros::master::V_TopicInfo master_topics;
00121 ros::master::getTopics(master_topics);
00122 bool found_topic = false;
00123
00124 for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00125 const ros::master::TopicInfo& info = *it;
00126 if (info.datatype.compare("std_msgs/String") == 0) {
00127 found_topic = true;
00128 EXPECT_STREQ("/namespaced", info.name.c_str());
00129 }
00130 }
00131 EXPECT_TRUE(found_topic);
00132 }
00133
00134 TEST(ManagerNamespaced, NodeGlobalNodehandle) {
00135 ros::NodeHandle nh;
00136 ros::Publisher pub = nh.advertise<std_msgs::Float32>("/public", 10);
00137 ros::master::V_TopicInfo master_topics;
00138 ros::master::getTopics(master_topics);
00139 bool found_topic = false;
00140
00141 for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00142 const ros::master::TopicInfo& info = *it;
00143 if (info.datatype.compare("std_msgs/Float32") == 0) {
00144 found_topic = true;
00145 EXPECT_STREQ("/public", info.name.c_str());
00146 }
00147 }
00148 EXPECT_TRUE(found_topic);
00149 }
00150
00151 int main(int argc, char **argv) {
00152 testing::InitGoogleTest(&argc, argv);
00153 ros::init(argc, argv, "test_nodehandles_manager_namespaced");
00154 return RUN_ALL_TESTS();
00155 }