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(SameNamespaces, 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("/common_namespace/nodehandle_test/private", info.name.c_str());
00059 }
00060 }
00061 EXPECT_TRUE(found_topic);
00062 }
00063
00064 TEST(SameNamespaces, NodeletNamespacedNodehandle) {
00065 ros::NodeHandle nh;
00066 ros::Duration(2).sleep();
00067 ros::master::V_TopicInfo master_topics;
00068 ros::master::getTopics(master_topics);
00069 bool found_topic = false;
00070
00071 for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00072 const ros::master::TopicInfo& info = *it;
00073 if (info.datatype.compare("std_msgs/Byte") == 0) {
00074 found_topic = true;
00075 EXPECT_STREQ("/common_namespace/namespaced", info.name.c_str());
00076 }
00077 }
00078 EXPECT_TRUE(found_topic);
00079 }
00080
00081 TEST(SameNamespaces, NodeletGlobalNodehandle) {
00082 ros::NodeHandle nh;
00083 ros::Duration(2).sleep();
00084 ros::master::V_TopicInfo master_topics;
00085 ros::master::getTopics(master_topics);
00086 bool found_topic = false;
00087
00088 for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00089 const ros::master::TopicInfo& info = *it;
00090 if (info.datatype.compare("std_msgs/Time") == 0) {
00091 found_topic = true;
00092 EXPECT_STREQ("/global", info.name.c_str());
00093 }
00094 }
00095 EXPECT_TRUE(found_topic);
00096 }
00097
00098 TEST(SameNamespaces, NodePrivateNodehandle) {
00099 ros::NodeHandle nh("~");
00100 ros::Publisher pub = nh.advertise<std_msgs::Empty>("private", 10);
00101 ros::master::V_TopicInfo master_topics;
00102 ros::master::getTopics(master_topics);
00103 bool found_topic = false;
00104
00105 for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00106 const ros::master::TopicInfo& info = *it;
00107 if (info.datatype.compare("std_msgs/Empty") == 0) {
00108 found_topic = true;
00109 EXPECT_STREQ("/common_namespace/test_nodehandles/private", info.name.c_str());
00110 }
00111 }
00112 EXPECT_TRUE(found_topic);
00113 }
00114
00115 TEST(SameNamespaces, NodeNamespacedNodehandle) {
00116 ros::NodeHandle nh;
00117 ros::Publisher pub = nh.advertise<std_msgs::String>("namespaced", 10);
00118 ros::master::V_TopicInfo master_topics;
00119 ros::master::getTopics(master_topics);
00120 bool found_topic = false;
00121
00122 for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00123 const ros::master::TopicInfo& info = *it;
00124 if (info.datatype.compare("std_msgs/String") == 0) {
00125 found_topic = true;
00126 EXPECT_STREQ("/common_namespace/namespaced", info.name.c_str());
00127 }
00128 }
00129 EXPECT_TRUE(found_topic);
00130 }
00131
00132 TEST(SameNamespaces, NodeGlobalNodehandle) {
00133 ros::NodeHandle nh;
00134 ros::Publisher pub = nh.advertise<std_msgs::Float32>("/public", 10);
00135 ros::master::V_TopicInfo master_topics;
00136 ros::master::getTopics(master_topics);
00137 bool found_topic = false;
00138
00139 for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00140 const ros::master::TopicInfo& info = *it;
00141 if (info.datatype.compare("std_msgs/Float32") == 0) {
00142 found_topic = true;
00143 EXPECT_STREQ("/public", info.name.c_str());
00144 }
00145 }
00146 EXPECT_TRUE(found_topic);
00147 }
00148
00149 int main(int argc, char **argv) {
00150 testing::InitGoogleTest(&argc, argv);
00151 ros::init(argc, argv, "test_nodehandles_same_namespaces");
00152 return RUN_ALL_TESTS();
00153 }