test_nodehandles_manager_namespaced.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * test_nodehandles_same_namespaces.cpp
00003 *
00004 * Software License Agreement (BSD License)
00005 *
00006 *  Copyright (c) 2016, University of Patras
00007 *  All rights reserved.
00008 *
00009 *  Redistribution and use in source and binary forms, with or without
00010 *  modification, are permitted provided that the following conditions
00011 *  are met:
00012 *
00013 *   * Redistributions of source code must retain the above copyright
00014 *     notice, this list of conditions and the following disclaimer.
00015 *   * Redistributions in binary form must reproduce the above
00016 *     copyright notice, this list of conditions and the following
00017 *     disclaimer in the documentation and/or other materials provided
00018 *     with the distribution.
00019 *   * Neither the name of University of Patras nor the names of its
00020 *     contributors may be used to endorse or promote products derived
00021 *     from this software without specific prior written permission.
00022 *
00023 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034 *  POSSIBILITY OF SUCH DAMAGE.
00035 *
00036 * Authors: Aris Synodinos
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 // TODO(mikaelarguedas) reenable this once
00065 // https://github.com/ros/nodelet_core/issues/7 is fixed
00066 // TEST(ManagerNamespaced, NodeletNamespacedNodehandle) {
00067 //   ros::NodeHandle nh;
00068 //   ros::Duration(2).sleep();
00069 //   ros::master::V_TopicInfo master_topics;
00070 //   ros::master::getTopics(master_topics);
00071 //   bool found_topic = false;
00072 // 
00073 //   for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) {
00074 //     const ros::master::TopicInfo& info = *it;
00075 //     if (info.datatype.compare("std_msgs/Byte") == 0) {
00076 //       found_topic = true;
00077 //       EXPECT_STREQ("/namespaced", info.name.c_str());
00078 //     }
00079 //   }
00080 //   EXPECT_TRUE(found_topic);
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 }


test_nodelet
Author(s): Tully Foote
autogenerated on Sun Feb 17 2019 03:43:56