test_nodehandles_same_namespaces.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(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 }


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