-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added unit tests for the nodehandles * fix copy-n-paste test suite * disable failing namespace test tracked upstream * various minor fixups
- Loading branch information
1 parent
17d9014
commit a506c89
Showing
9 changed files
with
542 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <nodelet/nodelet.h> | ||
#include <pluginlib/class_list_macros.h> | ||
#include <string> | ||
#include <ros/ros.h> | ||
#include <std_msgs/Bool.h> | ||
#include <std_msgs/Byte.h> | ||
#include <std_msgs/Time.h> | ||
|
||
namespace test_nodelet | ||
{ | ||
|
||
class NodehandleTest : public nodelet::Nodelet | ||
{ | ||
public: | ||
NodehandleTest(){}; | ||
virtual void onInit() | ||
{ | ||
ros::NodeHandle nh = this->getNodeHandle(); | ||
ros::NodeHandle pnh = this->getPrivateNodeHandle(); | ||
global_pub_ = nh.advertise<std_msgs::Time>("/global", 1000); | ||
namespaced_pub_ = nh.advertise<std_msgs::Byte>("namespaced", 1000); | ||
private_pub_ = pnh.advertise<std_msgs::Bool>("private", 1000); | ||
} | ||
private: | ||
ros::Publisher global_pub_, namespaced_pub_, private_pub_; | ||
}; | ||
|
||
} // namespace test_nodelet | ||
|
||
PLUGINLIB_EXPORT_CLASS(test_nodelet::NodehandleTest, nodelet::Nodelet); |
154 changes: 154 additions & 0 deletions
154
test_nodelet/test/test_nodehandles_different_namespaces.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/********************************************************************* | ||
* test_nodehandles_different_namespaces.cpp | ||
* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2016, University of Patras | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of University of Patras nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* Authors: Aris Synodinos | ||
*********************************************************************/ | ||
|
||
#include <gtest/gtest.h> | ||
#include <std_msgs/Bool.h> | ||
#include <std_msgs/Byte.h> | ||
#include <std_msgs/Empty.h> | ||
#include <std_msgs/String.h> | ||
#include <std_msgs/Float32.h> | ||
#include <std_msgs/Float64.h> | ||
#include <ros/ros.h> | ||
|
||
TEST(DifferentNamespaces, NodeletPrivateNodehandle) { | ||
ros::NodeHandle nh; | ||
ros::Duration(2).sleep(); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/Bool") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/nodelet_namespace/nodehandle_test/private", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
TEST(DifferentNamespaces, NodeletNamespacedNodehandle) { | ||
ros::NodeHandle nh; | ||
ros::Duration(2).sleep(); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/Byte") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/nodelet_namespace/namespaced", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
TEST(DifferentNamespaces, NodeletGlobalNodehandle) { | ||
ros::NodeHandle nh; | ||
ros::Duration(2).sleep(); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/Time") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/global", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
TEST(DifferentNamespaces, NodePrivateNodehandle) { | ||
ros::NodeHandle nh("~"); | ||
ros::Publisher pub = nh.advertise<std_msgs::Empty>("private", 10); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/Empty") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/test_namespace/test_nodehandles/private", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
TEST(DifferentNamespaces, NodeNamespacedNodehandle) { | ||
ros::NodeHandle nh; | ||
ros::Publisher pub = nh.advertise<std_msgs::String>("namespaced", 10); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/String") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/test_namespace/namespaced", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
TEST(DifferentNamespaces, NodeGlobalNodehandle) { | ||
ros::NodeHandle nh; | ||
ros::Publisher pub = nh.advertise<std_msgs::Float32>("/public", 10); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/Float32") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/public", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
testing::InitGoogleTest(&argc, argv); | ||
ros::init(argc, argv, "test_nodehandles_different_namespaces"); | ||
return RUN_ALL_TESTS(); | ||
} |
12 changes: 12 additions & 0 deletions
12
test_nodelet/test/test_nodehandles_different_namespaces.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<launch> | ||
<group ns="manager_namespace"> | ||
<node pkg="nodelet" type="nodelet" name="nodelet_manager" args="manager"/> | ||
</group> | ||
<group ns="nodelet_namespace"> | ||
<node pkg="nodelet" type="nodelet" name="nodehandle_test" args="load test_nodelet/NodehandleTest /manager_namespace/nodelet_manager"/> | ||
</group> | ||
<group ns="test_namespace"> | ||
<test test-name="test_nodehandles" pkg="test_nodelet" type="test_nodehandles_different_namespaces"/> | ||
</group> | ||
</launch> |
155 changes: 155 additions & 0 deletions
155
test_nodelet/test/test_nodehandles_manager_namespaced.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/********************************************************************* | ||
* test_nodehandles_same_namespaces.cpp | ||
* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2016, University of Patras | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of University of Patras nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* Authors: Aris Synodinos | ||
*********************************************************************/ | ||
|
||
#include <gtest/gtest.h> | ||
#include <std_msgs/Bool.h> | ||
#include <std_msgs/Byte.h> | ||
#include <std_msgs/Empty.h> | ||
#include <std_msgs/String.h> | ||
#include <std_msgs/Float32.h> | ||
#include <ros/ros.h> | ||
|
||
TEST(ManagerNamespaced, NodeletPrivateNodehandle) { | ||
ros::NodeHandle nh; | ||
ros::Duration(2).sleep(); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/Bool") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/nodehandle_test/private", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
// TODO(mikaelarguedas) reenable this once | ||
// https://github.com/ros/nodelet_core/issues/7 is fixed | ||
// TEST(ManagerNamespaced, NodeletNamespacedNodehandle) { | ||
// ros::NodeHandle nh; | ||
// ros::Duration(2).sleep(); | ||
// ros::master::V_TopicInfo master_topics; | ||
// ros::master::getTopics(master_topics); | ||
// bool found_topic = false; | ||
// | ||
// for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
// const ros::master::TopicInfo& info = *it; | ||
// if (info.datatype.compare("std_msgs/Byte") == 0) { | ||
// found_topic = true; | ||
// EXPECT_STREQ("/namespaced", info.name.c_str()); | ||
// } | ||
// } | ||
// EXPECT_TRUE(found_topic); | ||
// } | ||
|
||
TEST(ManagerNamespaced, NodeletGlobalNodehandle) { | ||
ros::NodeHandle nh; | ||
ros::Duration(2).sleep(); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/Time") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/global", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
TEST(ManagerNamespaced, NodePrivateNodehandle) { | ||
ros::NodeHandle nh("~"); | ||
ros::Publisher pub = nh.advertise<std_msgs::Empty>("private", 10); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/Empty") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/test_nodehandles/private", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
TEST(ManagerNamespaced, NodeNamespacedNodehandle) { | ||
ros::NodeHandle nh; | ||
ros::Publisher pub = nh.advertise<std_msgs::String>("namespaced", 10); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/String") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/namespaced", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
TEST(ManagerNamespaced, NodeGlobalNodehandle) { | ||
ros::NodeHandle nh; | ||
ros::Publisher pub = nh.advertise<std_msgs::Float32>("/public", 10); | ||
ros::master::V_TopicInfo master_topics; | ||
ros::master::getTopics(master_topics); | ||
bool found_topic = false; | ||
|
||
for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { | ||
const ros::master::TopicInfo& info = *it; | ||
if (info.datatype.compare("std_msgs/Float32") == 0) { | ||
found_topic = true; | ||
EXPECT_STREQ("/public", info.name.c_str()); | ||
} | ||
} | ||
EXPECT_TRUE(found_topic); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
testing::InitGoogleTest(&argc, argv); | ||
ros::init(argc, argv, "test_nodehandles_manager_namespaced"); | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<launch> | ||
<group ns="manager_namespace"> | ||
<node pkg="nodelet" type="nodelet" name="nodelet_manager" args="manager"/> | ||
</group> | ||
|
||
<node pkg="nodelet" type="nodelet" name="nodehandle_test" args="load test_nodelet/NodehandleTest manager_namespace/nodelet_manager"/> | ||
<test test-name="test_nodehandles" pkg="test_nodelet" type="test_nodehandles_manager_namespaced"/> | ||
</launch> |
Oops, something went wrong.