This commit is contained in:
Ivan
2022-04-05 11:42:28 +03:00
commit 6dc0eb0fcf
5565 changed files with 1200500 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
cmake_minimum_required(VERSION 2.8.3)
project(test_roscpp)
if(NOT WIN32)
set_directory_properties(PROPERTIES COMPILE_OPTIONS "-Wall;-Wextra")
endif()
find_package(catkin REQUIRED COMPONENTS
message_generation roscpp rostest rosunit std_srvs
)
if(CATKIN_ENABLE_TESTING)
find_package(Boost REQUIRED COMPONENTS signals filesystem system)
include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
# Testing message and service files. See comment below about subdirectory support.
add_message_files(
NOINSTALL
DIRECTORY test/msg
FILES
TestArray.msg
TestEmpty.msg
TestStringInt.msg
TestWithHeader.msg
)
add_service_files(
NOINSTALL
DIRECTORY test/srv
FILES
BadTestStringString.srv
TestStringString.srv
)
# Serialization testing message files.
add_message_files(
NOINSTALL
DIRECTORY test_serialization/msg
FILES
ArrayOfFixedLength.msg
ArrayOfVariableLength.msg
Constants.msg
CustomHeader.msg
EmbeddedExternal.msg
EmbeddedFixedLength.msg
EmbeddedVariableLength.msg
FixedLengthArrayOfExternal.msg
FixedLength.msg
FixedLengthStringArray.msg
HeaderNotFirstMember.msg
VariableLengthArrayOfExternal.msg
VariableLength.msg
VariableLengthStringArray.msg
WithDuration.msg
WithHeader.msg
WithMemberNamedHeaderThatIsNotAHeader.msg
WithTime.msg
)
# Performance testing message files. add_message_files() does not
# currently support being called from a subdirectory, so this is here
# for now.
add_message_files(
NOINSTALL
DIRECTORY perf/msg
FILES
LatencyMessage.msg
ThroughputMessage.msg
)
# Message files for testing the performance of serialization.
add_message_files(
NOINSTALL
DIRECTORY perf_serialization/msg
FILES
ChannelFloat32.msg
Point32.msg
PointCloud.msg
)
# dependencies std_msgs and rosgraph_msgs are needed by tests, but not by roscpp otherwise.
generate_messages(DEPENDENCIES rosgraph_msgs std_msgs)
endif()
catkin_package(
CATKIN_DEPENDS message_runtime rosconsole rosgraph_msgs std_msgs xmlrpcpp
)
if(CATKIN_ENABLE_TESTING)
add_subdirectory(test)
add_subdirectory(perf)
add_subdirectory(test_serialization)
add_subdirectory(perf_serialization)
endif()

View File

@@ -0,0 +1,40 @@
<package>
<name>test_roscpp</name>
<version>1.12.14</version>
<description>
Tests for roscpp which depend on rostest.
</description>
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
<license>BSD</license>
<url>http://ros.org/wiki/roscpp</url>
<author>Morgan Quigley</author>
<author>Josh Faust</author>
<author>Brian Gerkey</author>
<author>Troy Straszheim</author>
<buildtool_depend version_gte="0.5.68">catkin</buildtool_depend>
<build_depend>cpp_common</build_depend>
<build_depend>message_generation</build_depend>
<build_depend>pkg-config</build_depend>
<build_depend>rosconsole</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>roscpp_serialization</build_depend>
<build_depend>roscpp_traits</build_depend>
<build_depend>rosgraph_msgs</build_depend>
<build_depend>roslang</build_depend>
<build_depend>rostest</build_depend>
<build_depend>rostime</build_depend>
<build_depend>rosunit</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>std_srvs</build_depend>
<build_depend>xmlrpcpp</build_depend>
<run_depend>message_runtime</run_depend>
<run_depend>rosconsole</run_depend>
<run_depend>rosgraph_msgs</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>std_srvs</run_depend>
<run_depend>xmlrpcpp</run_depend>
</package>

View File

@@ -0,0 +1,23 @@
find_package(Boost REQUIRED COMPONENTS thread)
include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
# Can't call add_message_files() here because CMake context is lost when we leave this subdir.
# add_message_files(
# DIRECTORY msg
# FILES
# LatencyMessage.msg
# ThroughputMessage.msg
# )
# Can't call generate_messages() here, because currently can only have one instance of it per project.
# This means this file must be included before generate_messages() in the parent.
#common commands for building c++ executables and libraries
add_library(${PROJECT_NAME}_perf EXCLUDE_FROM_ALL src/intra.cpp src/inter.cpp)
add_dependencies(${PROJECT_NAME}_perf ${${PROJECT_NAME}_EXPORTED_TARGETS})
target_link_libraries(${PROJECT_NAME}_perf ${Boost_LIBRARIES} ${catkin_LIBRARIES})
# These performance tests will not be built or executed automatically.
# TODO: automate them in some useful way.
add_executable(${PROJECT_NAME}-intra_suite EXCLUDE_FROM_ALL src/intra_suite.cpp)
target_link_libraries(${PROJECT_NAME}-intra_suite ${PROJECT_NAME}_perf ${catkin_LIBRARIES})

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,102 @@
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2009, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
#ifndef PERF_ROSCPP_INTRA_H
#define PERF_ROSCPP_INTRA_H
#include <ros/types.h>
#include <ros/time.h>
namespace perf_roscpp
{
namespace intra
{
struct ThroughputResult
{
double test_duration;
uint64_t streams;
uint64_t message_size;
uint32_t sender_threads;
uint32_t receiver_threads;
uint64_t messages_sent;
uint64_t messages_received;
uint64_t total_bytes_sent;
uint64_t total_bytes_received;
uint64_t bytes_per_second;
ros::WallTime test_start;
ros::WallTime test_end;
};
ThroughputResult throughput(double duration, uint32_t streams, uint32_t message_size, uint32_t sender_threads, uint32_t receiver_threads);
struct LatencyResult
{
uint64_t count_per_stream;
uint64_t streams;
uint64_t message_size;
uint32_t sender_threads;
uint32_t receiver_threads;
uint64_t total_message_count;
double latency_avg;
double latency_min;
double latency_max;
ros::WallTime test_start;
ros::WallTime test_end;
};
LatencyResult latency(uint32_t count_per_stream, uint32_t streams, uint32_t message_size, uint32_t sender_threads, uint32_t receiver_threads);
struct STLatencyResult
{
uint64_t total_message_count;
double latency_avg;
double latency_min;
double latency_max;
ros::WallTime test_start;
ros::WallTime test_end;
};
STLatencyResult stlatency(uint32_t message_count);
} // namespace intra
} // namespace perf_roscpp
#endif // PERF_ROSCPP_INTRA_H

View File

@@ -0,0 +1,6 @@
float64 publish_time
float64 receipt_time
uint64 count
uint32 thread_index
uint8[] array

View File

@@ -0,0 +1,2 @@
uint8[] array

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,720 @@
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2009, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
#include "perf_roscpp/intra.h"
#include "test_roscpp/ThroughputMessage.h"
#include "test_roscpp/LatencyMessage.h"
#include <ros/ros.h>
#include <ros/callback_queue.h>
#include <boost/thread.hpp>
#include <vector>
namespace perf_roscpp
{
namespace intra
{
class ThroughputTest
{
public:
ThroughputTest(double test_duration, uint32_t streams, uint32_t message_size, uint32_t sender_threads, uint32_t receiver_threads);
ThroughputResult run();
private:
void sendThread(boost::barrier* all_connected);
void receiveThread(boost::barrier* all_started, boost::barrier* all_start, ros::WallTime* end_time);
void callback(const test_roscpp::ThroughputMessageConstPtr& msg);
boost::mutex mutex_;
struct ReceiveThreadResult
{
uint64_t bytes_received;
uint64_t messages_received;
ros::WallTime last_recv_time;
};
boost::thread_specific_ptr<ReceiveThreadResult> receive_thread_result_;
std::vector<boost::shared_ptr<ReceiveThreadResult> > receive_results_;
struct SendThreadResult
{
uint64_t bytes_sent;
uint64_t messages_sent;
ros::WallTime first_send_time;
};
boost::thread_specific_ptr<SendThreadResult> send_thread_result_;
std::vector<boost::shared_ptr<SendThreadResult> > send_results_;
ros::CallbackQueue queue_;
std::vector<ros::Publisher> pubs_;
boost::thread_group receive_threads_;
boost::thread_group send_threads_;
double test_duration_;
uint32_t streams_;
uint32_t message_size_;
uint32_t sender_threads_;
uint32_t receiver_threads_;
};
ThroughputTest::ThroughputTest(double test_duration, uint32_t streams, uint32_t message_size, uint32_t sender_threads, uint32_t receiver_threads)
: test_duration_(test_duration)
, streams_(streams)
, message_size_(message_size)
, sender_threads_(sender_threads)
, receiver_threads_(receiver_threads)
{
}
void ThroughputTest::callback(const test_roscpp::ThroughputMessageConstPtr& msg)
{
ReceiveThreadResult& r = *receive_thread_result_;
r.bytes_received += ros::serialization::Serializer<test_roscpp::ThroughputMessage>::serializedLength(*msg) + 4; // 4 byte message length field
++r.messages_received;
r.last_recv_time = ros::WallTime::now();
//ROS_INFO_STREAM("Received message " << r.messages_received);
}
void ThroughputTest::receiveThread(boost::barrier* all_ready, boost::barrier* all_start, ros::WallTime* end_time)
{
receive_thread_result_.reset(new ReceiveThreadResult);
ReceiveThreadResult& r = *receive_thread_result_;
r.messages_received = 0;
r.bytes_received = 0;
ROS_INFO_STREAM("Receive thread [" << boost::this_thread::get_id() << "] waiting for all threads to start");
all_ready->wait();
all_start->wait();
ros::WallTime local_end_time = *end_time;
ROS_INFO_STREAM("Receive thread [" << boost::this_thread::get_id() << "] running");
while (ros::WallTime::now() < local_end_time)
{
queue_.callOne(ros::WallDuration(0.01));
}
ROS_INFO_STREAM("Receive thread [" << boost::this_thread::get_id() << "] adding results and exiting");
boost::mutex::scoped_lock lock(mutex_);
receive_results_.push_back(boost::shared_ptr<ReceiveThreadResult>(receive_thread_result_.release()));
}
void ThroughputTest::sendThread(boost::barrier* all_connected)
{
send_thread_result_.reset(new SendThreadResult);
SendThreadResult& r = *send_thread_result_;
ros::NodeHandle nh;
nh.setCallbackQueue(&queue_);
std::vector<ros::Publisher> pubs;
for (uint32_t i = 0; i < streams_; ++i)
{
std::stringstream ss;
ss << "throughput_perf_test_" << i;
pubs.push_back(nh.advertise<test_roscpp::ThroughputMessage>(ss.str(), 1));
}
// Need to keep around the publishers so the connections don't go away
{
boost::mutex::scoped_lock lock(mutex_);
pubs_.insert(pubs_.end(), pubs.begin(), pubs.end());
}
ROS_INFO_STREAM("Publish thread [" << boost::this_thread::get_id() << "] waiting for connections");
bool cont = true;
while (cont)
{
cont = false;
for (uint32_t i = 0; i < streams_; ++i)
{
if (pubs[i].getNumSubscribers() == 0)
{
cont = true;
}
}
}
test_roscpp::ThroughputMessagePtr msg(boost::make_shared<test_roscpp::ThroughputMessage>());
msg->array.resize(message_size_);
all_connected->wait();
ROS_INFO_STREAM("Publish thread [" << boost::this_thread::get_id() << "] all connections established, beginning to publish");
r.first_send_time = ros::WallTime::now();
r.bytes_sent = 0;
r.messages_sent = 0;
try
{
const uint32_t streams = streams_;
while (!boost::this_thread::interruption_requested())
{
for (uint32_t j = 0; j < streams; ++j)
{
pubs[j].publish(msg);
++r.messages_sent;
r.bytes_sent += ros::serialization::Serializer<test_roscpp::ThroughputMessage>::serializedLength(*msg) + 4;
}
boost::this_thread::yield();
}
}
catch (boost::thread_interrupted&)
{
}
ROS_INFO_STREAM("Publish thread [" << boost::this_thread::get_id() << "] exiting");
boost::mutex::scoped_lock lock(mutex_);
send_results_.push_back(boost::shared_ptr<SendThreadResult>(send_thread_result_.release()));
}
ThroughputResult ThroughputTest::run()
{
ROS_INFO("Starting receive threads");
ThroughputResult r;
r.test_start = ros::WallTime::now();
ros::NodeHandle nh;
nh.setCallbackQueue(&queue_);
std::vector<ros::Subscriber> subs;
for (uint32_t i = 0; i < streams_; ++i)
{
std::stringstream ss;
ss << "throughput_perf_test_" << i;
subs.push_back(nh.subscribe(ss.str(), 0, &ThroughputTest::callback, this, ros::TransportHints().tcpNoDelay()));
}
boost::barrier sender_all_connected(sender_threads_ + 1);
boost::barrier receiver_all_ready(receiver_threads_ + 1);
boost::barrier receiver_start(receiver_threads_ + 1);
ros::WallTime test_end_time;
for (uint32_t i = 0; i < receiver_threads_; ++i)
{
receive_threads_.create_thread(boost::bind(&ThroughputTest::receiveThread, this, &receiver_all_ready, &receiver_start, &test_end_time));
}
for (uint32_t i = 0; i < sender_threads_; ++i)
{
send_threads_.create_thread(boost::bind(&ThroughputTest::sendThread, this, &sender_all_connected));
}
receiver_all_ready.wait();
test_end_time = ros::WallTime::now() + ros::WallDuration(test_duration_);
receiver_start.wait();
ros::WallTime pub_start = ros::WallTime::now();
sender_all_connected.wait();
receive_threads_.join_all();
ROS_INFO("All receive threads done");
send_threads_.interrupt_all();
send_threads_.join_all();
ROS_INFO("All publish threads done");
ROS_INFO("Collating results");
r.test_end = ros::WallTime::now();
r.bytes_per_second = 0;
r.message_size = message_size_;
r.messages_received = 0;
r.messages_sent = 0;
r.receiver_threads = receiver_threads_;
r.sender_threads = sender_threads_;
r.total_bytes_received = 0;
r.total_bytes_sent = 0;
r.test_duration = test_duration_;
r.streams = streams_;
ros::WallTime rec_end;
{
std::vector<boost::shared_ptr<ReceiveThreadResult> >::iterator it = receive_results_.begin();
std::vector<boost::shared_ptr<ReceiveThreadResult> >::iterator end = receive_results_.end();
for (; it != end; ++it)
{
ReceiveThreadResult& rr = **it;
r.total_bytes_received += rr.bytes_received;
r.messages_received += rr.messages_received;
rec_end = std::max(rec_end, rr.last_recv_time);
}
}
{
std::vector<boost::shared_ptr<SendThreadResult> >::iterator it = send_results_.begin();
std::vector<boost::shared_ptr<SendThreadResult> >::iterator end = send_results_.end();
for (; it != end; ++it)
{
SendThreadResult& sr = **it;
r.total_bytes_sent += sr.bytes_sent;
r.messages_sent += sr.messages_sent;
pub_start = std::min(pub_start, sr.first_send_time);
}
}
r.bytes_per_second = (double)r.total_bytes_received / (rec_end - pub_start).toSec();
ROS_INFO("Done collating results");
return r;
}
ThroughputResult throughput(double test_duration, uint32_t streams, uint32_t message_size, uint32_t sender_threads, uint32_t receiver_threads)
{
ROS_INFO_STREAM("*****************************************************");
ROS_INFO_STREAM("Running throughput test: "<< "receiver_threads [" << receiver_threads << "], sender_threads [" << sender_threads << "], streams [" << streams << "], test_duration [" << test_duration << "], message_size [" << message_size << "]");
ThroughputTest t(test_duration, streams, message_size, sender_threads, receiver_threads);
return t.run();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class LatencyTest
{
public:
LatencyTest(uint32_t count_per_stream, uint32_t streams, uint32_t message_size, uint32_t sender_threads, uint32_t receiver_threads);
LatencyResult run();
private:
void sendThread(boost::barrier* b, uint32_t i);
void receiveThread();
void receiveCallback(const test_roscpp::LatencyMessageConstPtr& msg, ros::Publisher& pub);
void sendCallback(const test_roscpp::LatencyMessageConstPtr& msg, ros::Publisher& pub, uint32_t thread_index);
boost::mutex mutex_;
struct ThreadResult
{
uint64_t message_count;
std::vector<double> latencies;
};
boost::thread_specific_ptr<ThreadResult> thread_result_;
std::vector<boost::shared_ptr<ThreadResult> > results_;
ros::CallbackQueue receive_queue_;
boost::thread_group send_threads_;
uint32_t count_per_stream_;
uint32_t streams_;
uint32_t message_size_;
uint32_t sender_threads_;
uint32_t receiver_threads_;
};
LatencyTest::LatencyTest(uint32_t count_per_stream, uint32_t streams, uint32_t message_size, uint32_t sender_threads, uint32_t receiver_threads)
: count_per_stream_(count_per_stream)
, streams_(streams)
, message_size_(message_size)
, sender_threads_(sender_threads)
, receiver_threads_(receiver_threads)
{
}
void LatencyTest::receiveCallback(const test_roscpp::LatencyMessageConstPtr& msg, ros::Publisher& pub)
{
ros::WallTime receipt_time = ros::WallTime::now();
test_roscpp::LatencyMessagePtr reply = boost::const_pointer_cast<test_roscpp::LatencyMessage>(msg);
reply->receipt_time = receipt_time.toSec();
pub.publish(reply);
//ROS_INFO("Receiver received message %d", msg->count);
}
void LatencyTest::sendCallback(const test_roscpp::LatencyMessageConstPtr& msg, ros::Publisher& pub, uint32_t thread_index)
{
if (msg->thread_index != thread_index)
{
return;
}
thread_result_->latencies.push_back(msg->receipt_time - msg->publish_time);
++thread_result_->message_count;
test_roscpp::LatencyMessagePtr reply = boost::const_pointer_cast<test_roscpp::LatencyMessage>(msg);
reply->publish_time = ros::WallTime::now().toSec();
++reply->count;
//ROS_INFO("Sender received return message %d", msg->count);
if (reply->count < count_per_stream_ * streams_)
{
pub.publish(reply);
}
}
void LatencyTest::sendThread(boost::barrier* all_connected, uint32_t thread_index)
{
thread_result_.reset(new ThreadResult);
ThreadResult& r = *thread_result_;
ros::NodeHandle nh;
ros::CallbackQueue queue;
nh.setCallbackQueue(&queue);
std::vector<ros::Publisher> pubs;
std::vector<ros::Subscriber> subs;
pubs.reserve(streams_);
for (uint32_t i = 0; i < streams_; ++i)
{
std::stringstream ss;
ss << "latency_perf_test_" << i;
pubs.push_back(nh.advertise<test_roscpp::LatencyMessage>(ss.str(), 0));
ss << "_return";
subs.push_back(nh.subscribe<test_roscpp::LatencyMessage>(ss.str(), 0, boost::bind(&LatencyTest::sendCallback, this, _1, boost::ref(pubs[i]), thread_index), ros::VoidConstPtr(), ros::TransportHints().tcpNoDelay()));
}
bool cont = true;
while (cont)
{
cont = false;
for (uint32_t i = 0; i < streams_; ++i)
{
if (pubs[i].getNumSubscribers() == 0)
{
cont = true;
}
}
}
std::vector<test_roscpp::LatencyMessagePtr> messages;
for (uint32_t i = 0; i < streams_; ++i)
{
test_roscpp::LatencyMessagePtr msg(boost::make_shared<test_roscpp::LatencyMessage>());
msg->thread_index = thread_index;
msg->array.resize(message_size_);
messages.push_back(msg);
}
all_connected->wait();
r.message_count = 0;
const uint32_t count = count_per_stream_;
const uint32_t streams = streams_;
const uint32_t total_messages = count * streams;
for (uint32_t j = 0; j < streams; ++j)
{
messages[j]->publish_time = ros::WallTime::now().toSec();
pubs[j].publish(messages[j]);
}
while (r.latencies.size() < total_messages)
{
queue.callAvailable(ros::WallDuration(0.01));
}
ROS_INFO_STREAM("Publish thread [" << boost::this_thread::get_id() << "] exiting");
boost::mutex::scoped_lock lock(mutex_);
results_.push_back(boost::shared_ptr<ThreadResult>(thread_result_.release()));
}
LatencyResult LatencyTest::run()
{
ROS_INFO("Starting receive threads");
LatencyResult r;
r.test_start = ros::WallTime::now();
ros::NodeHandle nh;
nh.setCallbackQueue(&receive_queue_);
std::vector<ros::Subscriber> subs;
std::vector<ros::Publisher> pubs;
pubs.reserve(streams_ * sender_threads_);
for (uint32_t i = 0; i < streams_; ++i)
{
std::stringstream ss;
ss << "latency_perf_test_" << i;
std::string sub_topic = ss.str();
ss << "_return";
std::string pub_topic = ss.str();
pubs.push_back(nh.advertise<test_roscpp::LatencyMessage>(pub_topic, 0));
subs.push_back(nh.subscribe<test_roscpp::LatencyMessage>(sub_topic, 0, boost::bind(&LatencyTest::receiveCallback, this, _1, boost::ref(pubs.back())), ros::VoidConstPtr(), ros::TransportHints().tcpNoDelay()));
}
boost::barrier all_connected(1 + sender_threads_);
ros::WallTime pub_start = ros::WallTime::now();
ROS_INFO("Starting publish threads");
for (uint32_t i = 0; i < sender_threads_; ++i)
{
send_threads_.create_thread(boost::bind(&LatencyTest::sendThread, this, &all_connected, i));
}
ROS_INFO("Waiting for all connections to establish");
bool cont = true;
while (cont)
{
cont = false;
for (uint32_t i = 0; i < streams_; ++i)
{
if (pubs[i].getNumSubscribers() == 0)
{
cont = true;
}
}
}
all_connected.wait();
ROS_INFO("All connections established");
ros::AsyncSpinner receive_spinner(receiver_threads_, &receive_queue_);
receive_spinner.start();
send_threads_.join_all();
ROS_INFO("All publish threads done");
ROS_INFO("Collating results");
r.test_end = ros::WallTime::now();
r.latency_avg = 0;
r.latency_max = 0;
r.latency_min = 9999999999999ULL;
r.total_message_count = 0;
r.message_size = message_size_;
r.receiver_threads = receiver_threads_;
r.sender_threads = sender_threads_;
r.count_per_stream = count_per_stream_;
r.streams = streams_;
double latency_total = 0.0;
uint32_t latency_count = 0;
{
std::vector<boost::shared_ptr<ThreadResult> >::iterator it = results_.begin();
std::vector<boost::shared_ptr<ThreadResult> >::iterator end = results_.end();
for (; it != end; ++it)
{
ThreadResult& tr = **it;
r.total_message_count += tr.message_count;
std::vector<double>::iterator lat_it = tr.latencies.begin();
std::vector<double>::iterator lat_end = tr.latencies.end();
for (; lat_it != lat_end; ++lat_it)
{
double latency = *lat_it;
r.latency_min = std::min(r.latency_min, latency);
r.latency_max = std::max(r.latency_max, latency);
++latency_count;
latency_total += latency;
}
}
}
r.latency_avg = latency_total / latency_count;
ROS_INFO("Done collating results");
return r;
}
LatencyResult latency(uint32_t count_per_stream, uint32_t streams, uint32_t message_size, uint32_t sender_threads, uint32_t receiver_threads)
{
ROS_INFO_STREAM("*****************************************************");
ROS_INFO_STREAM("Running latency test: "<< "receiver_threads [" << receiver_threads << "], sender_threads [" << sender_threads << "], streams [" << streams << "], count_per_stream [" << count_per_stream << "], message_size [" << message_size << "]");
LatencyTest t(count_per_stream, streams, message_size, sender_threads, receiver_threads);
return t.run();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class STLatencyTest
{
public:
STLatencyTest(uint32_t message_count);
STLatencyResult run();
private:
void receiveCallback(const test_roscpp::LatencyMessageConstPtr& msg, ros::Publisher& pub);
void sendCallback(const test_roscpp::LatencyMessageConstPtr& msg, ros::Publisher& pub);
struct Result
{
std::vector<double> latencies;
};
Result result_;
ros::CallbackQueue receive_queue_;
uint32_t message_count_;
};
STLatencyTest::STLatencyTest(uint32_t message_count)
: message_count_(message_count)
{
}
void STLatencyTest::receiveCallback(const test_roscpp::LatencyMessageConstPtr& msg, ros::Publisher& pub)
{
ros::WallTime receipt_time = ros::WallTime::now();
test_roscpp::LatencyMessagePtr reply = boost::const_pointer_cast<test_roscpp::LatencyMessage>(msg);
reply->receipt_time = receipt_time.toSec();
pub.publish(reply);
//ROS_INFO("Receiver received message %d", msg->count);
}
void STLatencyTest::sendCallback(const test_roscpp::LatencyMessageConstPtr& msg, ros::Publisher& pub)
{
result_.latencies.push_back(msg->receipt_time - msg->publish_time);
test_roscpp::LatencyMessagePtr reply = boost::const_pointer_cast<test_roscpp::LatencyMessage>(msg);
reply->publish_time = ros::WallTime::now().toSec();
++reply->count;
//ROS_INFO("Sender received return message %d", msg->count);
if (reply->count < message_count_)
{
pub.publish(reply);
}
}
STLatencyResult STLatencyTest::run()
{
ROS_INFO("Starting receive threads");
STLatencyResult r;
r.test_start = ros::WallTime::now();
ros::NodeHandle nh;
nh.setCallbackQueue(&receive_queue_);
ros::Publisher recv_pub = nh.advertise<test_roscpp::LatencyMessage>("stlatency_perf_test_return", 0);
ros::Subscriber recv_sub = nh.subscribe<test_roscpp::LatencyMessage>("stlatency_perf_test", 0, boost::bind(&STLatencyTest::receiveCallback, this, _1, boost::ref(recv_pub)), ros::VoidConstPtr(), ros::TransportHints().tcpNoDelay());
ros::Publisher send_pub = nh.advertise<test_roscpp::LatencyMessage>("stlatency_perf_test", 0);
ros::Subscriber send_sub = nh.subscribe<test_roscpp::LatencyMessage>("stlatency_perf_test_return", 0, boost::bind(&STLatencyTest::sendCallback, this, _1, boost::ref(send_pub)), ros::VoidConstPtr(), ros::TransportHints().tcpNoDelay());
ROS_INFO("Waiting for all connections to establish");
bool cont = true;
while (cont)
{
cont = recv_pub.getNumSubscribers() == 0 || send_pub.getNumSubscribers() == 0;
ros::WallDuration(0.001).sleep();
}
ROS_INFO("All connections established");
test_roscpp::LatencyMessagePtr msg(boost::make_shared<test_roscpp::LatencyMessage>());
msg->publish_time = ros::WallTime::now().toSec();
send_pub.publish(msg);
while (msg->count < message_count_)
{
receive_queue_.callAvailable(ros::WallDuration(0.1));
}
r.test_end = ros::WallTime::now();
r.latency_avg = 0;
r.latency_max = 0;
r.latency_min = 9999999999999ULL;
r.total_message_count = message_count_;
double latency_total = 0.0;
uint32_t latency_count = 0;
{
std::vector<double>::iterator lat_it = result_.latencies.begin();
std::vector<double>::iterator lat_end = result_.latencies.end();
for (; lat_it != lat_end; ++lat_it)
{
double latency = *lat_it;
r.latency_min = std::min(r.latency_min, latency);
r.latency_max = std::max(r.latency_max, latency);
++latency_count;
latency_total += latency;
}
}
r.latency_avg = latency_total / latency_count;
ROS_INFO("Done collating results");
return r;
}
STLatencyResult stlatency(uint32_t message_count)
{
ROS_INFO_STREAM("*****************************************************");
ROS_INFO_STREAM("Running single-threaded latency test: message count[" << message_count << "]");
STLatencyTest t(message_count);
return t.run();
}
} // namespace intra
} // namespace perf_roscpp

View File

@@ -0,0 +1,218 @@
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2009, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
#include "perf_roscpp/intra.h"
#include <ros/ros.h>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <vector>
using namespace perf_roscpp;
using namespace std;
typedef std::vector<intra::ThroughputResult> V_ThroughputResult;
typedef std::vector<intra::LatencyResult> V_LatencyResult;
typedef std::vector<intra::STLatencyResult> V_STLatencyResult;
void printResult(std::ostream& out, uint32_t test_num, intra::ThroughputResult& r)
{
out << "----------------------------------------------------------\n";
out << "Throughput Test " << test_num << ": receiver_threads [" << r.receiver_threads << "], sender_threads [" << r.sender_threads << "], streams [" << r.streams << "], test_duration [" << r.test_duration << "], message_size [" << r.message_size << "]\n";
out << "\tMessages Sent: " << r.messages_sent << endl;
out << "\tMessages Received: " << r.messages_received << " (" << (double)r.messages_received / (double)r.messages_sent * 100.0 << "%)" << endl;
out << "\tBytes Sent: " << r.total_bytes_sent << endl;
out << "\tBytes Received: " << r.total_bytes_received << endl;
out << "\tBytes Per Second: " << r.bytes_per_second << " (" << r.bytes_per_second / (1024.0 * 1024.0) << " MB/s)" << endl;
}
void printResult(std::ostream& out, uint32_t test_num, intra::LatencyResult& r)
{
out << "----------------------------------------------------------\n";
out << "Multi-Threaded Latency Test " << test_num << ": receiver_threads [" << r.receiver_threads << "], sender_threads [" << r.sender_threads << "], streams [" << r.streams << "], count_per_stream [" << r.count_per_stream << "], message_size [" << r.message_size << "]\n";
out << "\tMessage Count: " << r.total_message_count << endl;
out << "\tLatency Average: " << r.latency_avg << endl;
out << "\tLatency Min: " << r.latency_min << endl;
out << "\tLatency Max: " << r.latency_max << endl;
}
void printResult(std::ostream& out, uint32_t test_num, intra::STLatencyResult& r)
{
out << "----------------------------------------------------------\n";
out << "Single-Threaded Latency Test " << test_num << endl;
out << "\tMessage Count: " << r.total_message_count << endl;
out << "\tLatency Average: " << r.latency_avg << endl;
out << "\tLatency Min: " << r.latency_min << endl;
out << "\tLatency Max: " << r.latency_max << endl;
}
void addResult(V_ThroughputResult& results, intra::ThroughputResult r, std::ostream& out, uint32_t i)
{
results.push_back(r);
printResult(out, i, results.back());
}
void addResult(V_LatencyResult& results, intra::LatencyResult r, std::ostream& out, uint32_t i)
{
results.push_back(r);
printResult(out, i, results.back());
}
void addResult(V_STLatencyResult& results, intra::STLatencyResult r, std::ostream& out, uint32_t i)
{
results.push_back(r);
printResult(out, i, results.back());
}
void runThroughputTests(std::ostream& out, V_ThroughputResult& results)
{
uint32_t i = 0;
// test duration, streams, message size , send threads, receive threads
addResult(results, intra::throughput(1 , 1 , 100 , 1 , 1 ), out, i++);
addResult(results, intra::throughput(1 , 1 , 1024*1024*10 , 1 , 1 ), out, i++);
addResult(results, intra::throughput(1 , 1 , 1024*1024*100, 1 , 1 ), out, i++);
addResult(results, intra::throughput(10 , 1 , 100 , 1 , 1 ), out, i++);
addResult(results, intra::throughput(10 , 1 , 1024*1024*10 , 1 , 1 ), out, i++);
addResult(results, intra::throughput(10 , 1 , 1024*1024*100, 1 , 1 ), out, i++);
#if 0
addResult(results, intra::throughput(10 , 1 , 100 , 1 , 10 ), out, i++);
addResult(results, intra::throughput(10 , 1 , 1024*1024*10 , 1 , 10 ), out, i++);
addResult(results, intra::throughput(10 , 1 , 1024*1024*100, 1 , 10 ), out, i++);
addResult(results, intra::throughput(1 , 10 , 100 , 1 , 1 ), out, i++);
addResult(results, intra::throughput(1 , 10 , 1024*1024*1 , 1 , 1 ), out, i++);
addResult(results, intra::throughput(1 , 10 , 1024*1024*10 , 1 , 1 ), out, i++);
addResult(results, intra::throughput(10 , 10 , 100 , 1 , 10 ), out, i++);
addResult(results, intra::throughput(10 , 10 , 1024*1024*1 , 1 , 10 ), out, i++);
addResult(results, intra::throughput(10 , 10 , 1024*1024*10 , 1 , 10 ), out, i++);
#endif
}
void runLatencyTests(std::ostream& out, V_LatencyResult& results)
{
uint32_t i = 0;
// count per stream, streams, message size , receive threads
addResult(results, intra::latency(100000 , 1 , 1 , 1 , 1 ), out, i++);
addResult(results, intra::latency(10000 , 1 , 1024 , 1 , 1 ), out, i++);
addResult(results, intra::latency(1000 , 1 , 1024*1024 , 1 , 1 ), out, i++);
addResult(results, intra::latency(100 , 1 , 1024*1024*100, 1 , 1 ), out, i++);
#if 0
addResult(results, intra::latency(100000 , 1 , 1 , 1 , 10 ), out, i++);
addResult(results, intra::latency(10000 , 1 , 1024 , 1 , 10 ), out, i++);
addResult(results, intra::latency(1000 , 1 , 1024*1024 , 1 , 10 ), out, i++);
addResult(results, intra::latency(100 , 1 , 1024*1024*100, 1 , 10 ), out, i++);
addResult(results, intra::latency(100000 , 10 , 1 , 1 , 1 ), out, i++);
addResult(results, intra::latency(10000 , 10 , 1024 , 1 , 1 ), out, i++);
addResult(results, intra::latency(1000 , 10 , 1024*1024 , 1 , 1 ), out, i++);
addResult(results, intra::latency(100 , 10 , 1024*1024*100, 1 , 1 ), out, i++);
addResult(results, intra::latency(10000 , 10 , 1 , 10 , 1 ), out, i++);
addResult(results, intra::latency(1000 , 10 , 1024 , 10 , 1 ), out, i++);
addResult(results, intra::latency(100 , 10 , 1024*1024 , 10 , 1 ), out, i++);
// 100mb test allocates too much memory
#endif
}
void runSTLatencyTests(std::ostream& out, V_STLatencyResult& results)
{
uint32_t i = 0;
addResult(results, intra::stlatency(10000), out, i++);
addResult(results, intra::stlatency(100000), out, i++);
addResult(results, intra::stlatency(1000000), out, i++);
}
int main(int argc, char** argv)
{
std::ofstream out("intra_suite_out.txt", std::ios::out);
out << std::fixed;
out.precision(10);
cout << std::fixed;
cout.precision(10);
ROS_ASSERT(out.is_open());
ros::init(argc, argv, "perf_roscpp_intra_suite", ros::init_options::NoSigintHandler|ros::init_options::NoRosout);
ros::NodeHandle nh;
V_ThroughputResult throughput_results;
runThroughputTests(out, throughput_results);
V_LatencyResult latency_results;
runLatencyTests(out, latency_results);
V_STLatencyResult stlatency_results;
runSTLatencyTests(out, stlatency_results);
printf("\n\n\n***************************** Results *****************************\n\n");
uint32_t i = 0;
{
V_ThroughputResult::iterator it = throughput_results.begin();
V_ThroughputResult::iterator end = throughput_results.end();
for (; it != end; ++it, ++i)
{
intra::ThroughputResult& r = *it;
printResult(cout, i, r);
}
}
i = 0;
{
V_LatencyResult::iterator it = latency_results.begin();
V_LatencyResult::iterator end = latency_results.end();
for (; it != end; ++it, ++i)
{
intra::LatencyResult& r = *it;
printResult(cout, i, r);
}
}
i = 0;
{
V_STLatencyResult::iterator it = stlatency_results.begin();
V_STLatencyResult::iterator end = stlatency_results.end();
for (; it != end; ++it, ++i)
{
intra::STLatencyResult& r = *it;
printResult(cout, i, r);
}
}
}

View File

@@ -0,0 +1,8 @@
add_executable(${PROJECT_NAME}-pointcloud_serdes EXCLUDE_FROM_ALL pointcloud_serdes.cpp)
target_link_libraries(${PROJECT_NAME}-pointcloud_serdes ${catkin_LIBRARIES})
if(TARGET tests)
add_dependencies(tests ${PROJECT_NAME}-pointcloud_serdes)
endif()
add_dependencies(${PROJECT_NAME}-pointcloud_serdes ${${PROJECT_NAME}_EXPORTED_TARGETS})
#rosbuild_add_compile_flags(pointcloud_serdes "-O3 -funroll-loops")
#rosbuild_add_compile_flags(pointcloud_serdes "-march=prescott")

View File

@@ -0,0 +1,2 @@
string name
float32[] vals

View File

@@ -0,0 +1,3 @@
float32 x
float32 y
float32 z

View File

@@ -0,0 +1,3 @@
Header header
Point32[] pts
ChannelFloat32[] chan

View File

@@ -0,0 +1,87 @@
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
#include "test_roscpp/PointCloud.h"
#include <cstdlib>
#include <cstdio>
using namespace ros::serialization;
ros::WallTime t;
inline void tic()
{
t = ros::WallTime::now();
}
inline double toc()
{
return (ros::WallTime::now() - t).toSec();
}
int main(int, char **)
{
test_roscpp::PointCloud pc;
const int NUM_ITER = 100;
const int NUM_PTS = 1000000;
pc.pts.resize(NUM_PTS);
pc.chan.resize(2);
pc.chan[0].vals.resize(NUM_PTS);
pc.chan[1].vals.resize(NUM_PTS);
ros::SerializedMessage m;
m.num_bytes = serializationLength(pc);
m.buf.reset(new uint8_t[m.num_bytes]);
tic();
for (int i = 0; i < NUM_ITER; ++i)
{
OStream s(m.buf.get(), m.num_bytes);
serialize(s, pc);
m.message_start = m.buf.get();
}
printf("avg serialization took %.6f sec\n", toc() / (double)NUM_ITER);
tic();
for (int i = 0; i < NUM_ITER; i++)
{
test_roscpp::PointCloud pc2;
deserializeMessage(m, pc2);
}
printf("avg deserization time %.6f sec\n", toc() / (double)NUM_ITER);
return 0;
}

View File

@@ -0,0 +1,151 @@
catkin_add_gtest(${PROJECT_NAME}-test_version test_version.cpp)
if(TARGET ${PROJECT_NAME}-test_version)
target_link_libraries(${PROJECT_NAME}-test_version ${catkin_LIBRARIES})
endif()
catkin_add_gtest(${PROJECT_NAME}-test_header test_header.cpp)
if(TARGET ${PROJECT_NAME}-test_header)
target_link_libraries(${PROJECT_NAME}-test_header ${catkin_LIBRARIES})
endif()
catkin_add_gtest(${PROJECT_NAME}-test_poll_set test_poll_set.cpp)
if(TARGET ${PROJECT_NAME}-test_poll_set)
target_link_libraries(${PROJECT_NAME}-test_poll_set ${catkin_LIBRARIES})
endif()
catkin_add_gtest(${PROJECT_NAME}-test_transport_tcp test_transport_tcp.cpp)
if(TARGET ${PROJECT_NAME}-test_transport_tcp)
target_link_libraries(${PROJECT_NAME}-test_transport_tcp ${catkin_LIBRARIES})
endif()
catkin_add_gtest(${PROJECT_NAME}-test_subscription_queue test_subscription_queue.cpp)
if(TARGET ${PROJECT_NAME}-test_subscription_queue)
target_link_libraries(${PROJECT_NAME}-test_subscription_queue ${catkin_LIBRARIES})
endif()
catkin_add_gtest(${PROJECT_NAME}-test_callback_queue test_callback_queue.cpp)
if(TARGET ${PROJECT_NAME}-test_callback_queue)
target_link_libraries(${PROJECT_NAME}-test_callback_queue ${catkin_LIBRARIES})
endif()
catkin_add_gtest(${PROJECT_NAME}-test_names test_names.cpp)
if(TARGET ${PROJECT_NAME}-test_names)
target_link_libraries(${PROJECT_NAME}-test_names ${catkin_LIBRARIES})
endif()
catkin_add_gtest(${PROJECT_NAME}-test_args test_args.cpp)
if(TARGET ${PROJECT_NAME}-test_args)
target_link_libraries(${PROJECT_NAME}-test_args ${catkin_LIBRARIES})
endif()
if(GTEST_FOUND)
add_subdirectory(src)
endif()
add_rostest(launch/real_time_test.xml)
add_rostest(launch/sim_time_test.xml)
# Publish one message
add_rostest(launch/pubsub_once.xml)
# Publish a bunch of messages back to back
add_rostest(launch/pubsub_n_fast.xml)
add_rostest(launch/pubsub_n_fast_udp.xml)
# Publish a bunch of empty messages
add_rostest(launch/pubsub_empty.xml)
# Publish only to the subscriber from the subscriber callback
add_rostest(launch/pub_onsub.xml)
# Publish a bunch of large messages back to back
add_rostest(launch/pubsub_n_fast_large_message.xml)
# Subscribe, listen, unsubscribe, re-subscribe to a different topic, listen
# again
add_rostest(launch/pubsub_resub_once.xml)
# Subscribe and unsubscribe repeatedly, ensuring that callbacks don't get
# called when not subscribed.
add_rostest(launch/pubsub_unsub.xml)
# Advertise, then unadvertise, and ensure that subscriber callback doesn't
# get invoked afterward, while a subscriber is constantly subscribing and
# unsubscribing
add_rostest(launch/pubsub_unadv.xml)
# Call a service
add_rostest(launch/service_call.xml)
# disabling the test again since it does not work realiable
#add_rostest(launch/service_deadlock.xml)
add_rostest(launch/service_exception.xml)
add_rostest(launch/service_call_unadv.xml)
add_rostest(launch/service_call_zombie.xml)
# Repeatedly call ros::init() and ros::fini()
add_rostest(launch/multiple_init_fini.xml)
# Test node inspection functionality
add_rostest(launch/inspection.xml)
# Test that advertising a service multiple times fails
add_rostest(launch/service_adv_multiple.xml)
# Test that the second node to advertise a service "wins"
add_rostest(launch/service_multiple_providers.xml)
# Test namespaces
add_rostest(launch/namespaces.xml)
# Test command-line name remapping
add_rostest(launch/name_remapping.xml)
add_rostest(launch/name_not_remappable.xml)
# Test command-line name remapping
add_rostest(launch/name_remapping_ROS_NAMESPACE.xml)
# Test params
add_rostest(launch/params.xml)
# Test getting information from the master
add_rostest(launch/get_master_information.xml)
# Test multiple subscriptions
add_rostest(launch/multiple_subscriptions.xml)
add_rostest(launch/pingpong.xml)
add_rostest(launch/pingpong_large.xml)
add_rostest(launch/subscribe_self.xml)
add_rostest(launch/check_master.xml)
#add_rostest(launch/check_master_false.xml)
add_rostest(launch/handles.xml)
add_rostest(launch/timer_callbacks.xml)
add_rostest(launch/latching_publisher.xml)
add_rostest(launch/loads_of_publishers.xml)
add_rostest(launch/incrementing_sequence.xml)
add_rostest(launch/subscription_callback_types.xml)
add_rostest(launch/service_callback_types.xml)
add_rostest(launch/intraprocess_subscriptions.xml)
add_rostest(launch/nonconst_subscriptions.xml)
add_rostest(launch/subscribe_retry_tcp.xml)
add_rostest(launch/subscribe_star.xml)
add_rostest(launch/parameter_validation.xml)
add_rostest(launch/no_remappings.xml)
add_rostest(launch/local_remappings.xml)
add_rostest(launch/global_remappings.xml)
add_rostest(launch/ns_node_remapping.xml)
add_rostest(launch/search_param.xml)
add_rostest(launch/stamped_topic_statistics_with_empty_timestamp.xml)
# Test spinners
add_rostest(launch/spinners.xml)

View File

@@ -0,0 +1,4 @@
<launch>
<test test-name="check_master_true" pkg="test_roscpp" type="test_roscpp-check_master" args="yes"/>
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<test test-name="check_master_false" pkg="test_roscpp" type="test_roscpp-check_master" args="no"/>
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<node name="publisher" pkg="test_roscpp" type="test_roscpp-publisher" output="screen" />
<node name="subscriber" pkg="test_roscpp" type="test_roscpp-subscriber" output="screen" />
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="get_master_information" pkg="test_roscpp" type="test_roscpp-get_master_information"/>
</launch>

View File

@@ -0,0 +1,8 @@
<launch>
<param name="use_local_remap" type="bool" value="false" />
<remap from="base_namespace" to="remapped_base_namespace" />
<remap from="remapped_base_namespace/sub_namespace" to="remapped_base_namespace/remapped_sub_namespace" />
<test test-name="global_remappings" pkg="test_roscpp" type="test_roscpp-test_remapping"
args="/remapped_base_namespace /remapped_base_namespace/remapped_sub_namespace"/>
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="handles" pkg="test_roscpp" type="test_roscpp-handles"/>
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<test test-name="incrementing_sequence" pkg="test_roscpp" type="test_roscpp-incrementing_sequence"/>
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="inspection" pkg="test_roscpp" type="test_roscpp-inspection"/>
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="intraprocess_subscriptions" pkg="test_roscpp" type="test_roscpp-intraprocess_subscriptions"/>
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="latching_publisher" pkg="test_roscpp" type="test_roscpp-latching_publisher"/>
</launch>

View File

@@ -0,0 +1,14 @@
<!-- This file is not part of automated testing. -->
<launch>
<node pkg="test_roscpp" type="test_roscpp-left_right" name="left_right_swapped">
<remap from="right" to="left"/>
<remap from="left" to="right"/>
</node>
<test test-name="left_right_swappy" pkg="test_roscpp" type="test_roscpp-string_msg_expect"
args="left /right"/>
<test test-name="left_right_swappy_2" pkg="test_roscpp" type="test_roscpp-string_msg_expect"
args="right /left"/>
</launch>

View File

@@ -0,0 +1,107 @@
<launch>
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly1" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly2" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly3" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly4" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly5" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly6" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly7" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly8" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly9" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly10" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly11" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly12" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly13" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly14" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly15" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly16" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly17" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly18" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly19" />
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly20" />
<!--
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly21" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly22" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly23" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly24" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly25" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly26" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly27" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly28" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly29" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly30" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly31" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly32" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly33" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly34" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly35" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly36" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly37" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly38" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly39" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly40" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly41" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly42" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly43" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly44" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly45" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly46" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly47" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly48" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly49" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly50" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly51" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly52" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly53" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly54" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly55" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly56" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly57" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly58" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly59" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly60" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly61" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly62" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly63" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly64" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly65" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly66" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly67" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly68" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly69" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly70" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly71" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly72" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly73" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly74" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly75" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly76" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly77" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly78" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly79" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly80" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly81" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly82" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly83" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly84" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly85" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly86" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly87" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly88" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly89" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly90" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly91" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly92" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly93" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly94" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly95" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly96" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly97" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly98" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly99" />
<node pkg="test_roscpp" type="publish_constantly" name="publish_constantly100" />
-->
<test test-name="loads_of_publishers" pkg="test_roscpp" type="test_roscpp-loads_of_publishers" args="20" time-limit="200" />
</launch>

View File

@@ -0,0 +1,9 @@
<launch>
<param name="use_local_remap" type="bool" value="true" />
<param name="remap_from" value="sub_namespace"/>
<param name="remap_to" value="different_sub_namespace" />
<test test-name="local_remappings" pkg="test_roscpp" type="test_roscpp-test_remapping"
args="/base_namespace /base_namespace/different_sub_namespace" />
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="multiple_init_fini" pkg="test_roscpp" type="test_roscpp-multiple_init_fini" args="15"/>
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly" />
<test test-name="multiple_subscriptions" pkg="test_roscpp" type="test_roscpp-multiple_subscriptions" />
</launch>

View File

@@ -0,0 +1,8 @@
<launch>
<param name="use_local_remap" type="bool" value="false" />
<remap from="NAME" to="something_else_entirely"/>
<test test-name="name_not_remappable" pkg="test_roscpp" type="test_roscpp-name_not_remappable"
name="NAME"/>
</launch>

View File

@@ -0,0 +1,15 @@
<launch>
<param name="mapto" value="mapto_value" type="str"/>
<test test-name="name_remapped" pkg="test_roscpp"
type="test_roscpp-name_remapping"
args="mapfrom:=mapto"/>
<param name="/b/test_full" value="asdf" type="str"/>
<param name="/a/test_local2" value="asdf" type="str"/>
<param name="/b/test_relative" value="asdf" type="str"/>
<test test-name="name_remapped_with_ns"
pkg="test_roscpp"
type="test_roscpp-name_remapping_with_ns"
ns="a"
args="/a/test_full:=/b/test_full /a/test_local:=test_local2 test_relative:=/b/test_relative"/>
</launch>

View File

@@ -0,0 +1,17 @@
<launch>
<param name="mapto" value="mapto_value" type="str"/>
<test test-name="name_remapped" pkg="test_roscpp"
type="test_roscpp-name_remapping"
args="mapfrom:=mapto"/>
<param name="/b/test_full" value="asdf" type="str"/>
<param name="/a/test_local2" value="asdf" type="str"/>
<param name="/b/test_relative" value="asdf" type="str"/>
<test test-name="name_remapped_with_ns"
pkg="test_roscpp"
type="test_roscpp-name_remapping_with_ns"
ns="a"
args="/a/test_full:=/b/test_full /a/test_local:=test_local2 test_relative:=/b/test_relative"/>
<!-- ignored, overridden by ns above -->
<env name="ROS_NAMESPACE" value="ROS_NAMESPACE"/>
</launch>

View File

@@ -0,0 +1,11 @@
<launch>
<param name="/ROS_NAMESPACE/parent" value=":ROS_NAMESPACE:parent"/>
<param name="/ROS_NAMESPACE/NODE_NAME/local"
value=":ROS_NAMESPACE:NODE_NAME:local"/>
<param name="/global" value=":global"/>
<param name="/other_namespace/param" value=":other_namespace:param"/>
<test test-name="namespaces" pkg="test_roscpp"
type="test_roscpp-namespaces" name="NODE_NAME">
<env name="ROS_NAMESPACE" value="ROS_NAMESPACE"/>
</test>
</launch>

View File

@@ -0,0 +1,6 @@
<launch>
<param name="use_local_remap" type="bool" value="false" />
<test test-name="no_remappings" pkg="test_roscpp" type="test_roscpp-test_remapping"
args="/base_namespace /base_namespace/sub_namespace"/>
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="nonconst_subscriptions" pkg="test_roscpp" type="test_roscpp-nonconst_subscriptions"/>
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="ns_node_remapping" pkg="test_roscpp" type="test_roscpp-test_ns_node_remapping"/>
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<test test-name="parameter_validation" pkg="test_roscpp" type="test_roscpp-parameter_validation"/>
</launch>

View File

@@ -0,0 +1,8 @@
<launch>
<param name="string" value="test" type="str"/>
<param name="int" value="10" type="int"/>
<param name="double" value="10.5" type="double"/>
<param name="bool" value="0" type="bool"/>
<test test-name="params" pkg="test_roscpp" type="test_roscpp-params" time-limit="1000000">
</test>
</launch>

View File

@@ -0,0 +1,5 @@
<launch>
<node name="pub_sub" pkg="test_roscpp" type="test_roscpp-pub_sub" args="1"/>
<test test-name="pingpong" pkg="test_roscpp" type="test_roscpp-sub_pub" args="5000 10.0"/>
</launch>

View File

@@ -0,0 +1,6 @@
<launch>
<node pkg="test_roscpp" type="test_roscpp-pub_sub" name="pub_sub" args="1000"/>
<test test-name="pingpong_large" pkg="test_roscpp"
type="test_roscpp-sub_pub" args="100 5.0"/>
</launch>

View File

@@ -0,0 +1,5 @@
<launch>
<node name="publish_onsub" pkg="test_roscpp" type="test_roscpp-publish_onsub" args="10"/>
<test test-name="pub_onsub" pkg="test_roscpp" type="test_roscpp-subscribe_empty" args="10 1.5"/>
</launch>

View File

@@ -0,0 +1,5 @@
<launch>
<node name="publish_empty" pkg="test_roscpp" type="test_roscpp-publish_empty" args="1000"/>
<test test-name="pubsub_empty" pkg="test_roscpp" type="test_roscpp-subscribe_empty" args="1000 1.5"/>
</launch>

View File

@@ -0,0 +1,6 @@
<launch>
<node pkg="test_roscpp" type="test_roscpp-publish_n_fast" name="publish_n_fast" args="10000 1 1"/>
<test test-name="pubsub_n_fast" pkg="test_roscpp"
type="test_roscpp-subscribe_n_fast" args="tcp 10000 10.0"/>
</launch>

View File

@@ -0,0 +1,6 @@
<launch>
<node pkg="test_roscpp" type="test_roscpp-publish_n_fast" name="publish_n_fast" args="50 100000 1000000"/>
<test test-name="pubsub_n_fast_large_message" pkg="test_roscpp"
type="test_roscpp-subscribe_n_fast" args="tcp 50 10.0"/>
</launch>

View File

@@ -0,0 +1,6 @@
<launch>
<node pkg="test_roscpp" type="test_roscpp-publish_n_fast" name="publish_n_fast" args="10000 1 1"/>
<test test-name="pubsub_n_fast_udp" pkg="test_roscpp"
type="test_roscpp-subscribe_n_fast" args="udp 10000 5.0"/>
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<node name="publish_n_fast" pkg="test_roscpp" type="test_roscpp-publish_n_fast" args="1 1 1"/>
<test test-name="pubsub_once" pkg="test_roscpp" type="test_roscpp-subscribe_n_fast" args="tcp 1 1.0"/>
</launch>

View File

@@ -0,0 +1,7 @@
<launch>
<node pkg="test_roscpp" type="test_roscpp-publish_n_fast" name="publish_n_fast" args="1 1 1"/>
<node pkg="test_roscpp" type="test_roscpp-publish_n_fast" name="publish_n_fast2" args="1 1 1 roscpp/pubsub_test:=roscpp/pubsub_test2">
<remap from="roscpp/pubsub_test" to="roscpp/pubsub_test2"/>
</node>
<test test-name="pubsub_resub_once" pkg="test_roscpp" type="test_roscpp-subscribe_resubscribe" args="1 1.0"/>
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<node pkg="test_roscpp" type="test_roscpp-subscribe_unsubscribe_repeatedly" name="subscribe_unsubscribe_repeatedly" />
<test test-name="pubsub_unadv" pkg="test_roscpp" type="test_roscpp-publish_unadvertise" args=""/>
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<node pkg="test_roscpp" type="test_roscpp-publish_constantly" name="publish_constantly" />
<test test-name="pubsub_unsub" pkg="test_roscpp" type="test_roscpp-subscribe_unsubscribe" args="" />
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<test test-name="timetest_real" pkg="test_roscpp" type="test_roscpp-real_time_test" args=""/>
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="test_search_param" pkg="test_roscpp" type="test_roscpp-test_search_param"/>
</launch>

View File

@@ -0,0 +1,5 @@
<launch>
<test test-name="service_adv_multiple" pkg="test_roscpp" type="test_roscpp-service_adv_multiple"/>
</launch>

View File

@@ -0,0 +1,6 @@
<launch>
<node name="service_adv" pkg="test_roscpp" type="test_roscpp-service_adv"/>
<test test-name="service_call" pkg="test_roscpp" type="test_roscpp-service_call"/>
</launch>

View File

@@ -0,0 +1,5 @@
<launch>
<node name="service_call_repeatedly" pkg="test_roscpp" type="test_roscpp-service_call_repeatedly"/>
<test test-name="service_call_unadv" pkg="test_roscpp" type="test_roscpp-service_adv_unadv" args=""/>
</launch>

View File

@@ -0,0 +1,6 @@
<launch>
<node name="dying_service" pkg="test_roscpp" type="test_roscpp-service_adv_zombie"/>
<test test-name="service_call_zombie" pkg="test_roscpp" type="test_roscpp-service_call_zombie" time-limit="30"/>
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<test test-name="service_callback_types" pkg="test_roscpp" type="test_roscpp-service_callback_types"/>
</launch>

View File

@@ -0,0 +1,5 @@
<launch>
<test test-name="service_deadlock" pkg="test_roscpp" type="test_roscpp-service_deadlock"/>
</launch>

View File

@@ -0,0 +1,5 @@
<launch>
<test test-name="service_exception" pkg="test_roscpp" type="test_roscpp-service_exception"/>
</launch>

View File

@@ -0,0 +1,7 @@
<launch>
<node name="service_adv_a" pkg="test_roscpp" type="test_roscpp-service_adv_a"/>
<node name="service_adv_b" pkg="test_roscpp" type="test_roscpp-service_wait_a_adv_b"/>
<test test-name="service_multiple_providers" pkg="test_roscpp" type="test_roscpp-service_call_expect_b"/>
</launch>

View File

@@ -0,0 +1,5 @@
<launch>
<param name="/use_sim_time" type="bool" value="true"/>
<test test-name="timetest_sim" pkg="test_roscpp" type="test_roscpp-sim_time_test" args=""/>
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<test pkg="test_roscpp" type="test_roscpp-spinners" test-name="Spinners_spin" args="--gtest_filter=Spinners.spin"/>
<test pkg="test_roscpp" type="test_roscpp-spinners" test-name="Spinners_multi" args="--gtest_filter=Spinners.multi"/>
</launch>

View File

@@ -0,0 +1,5 @@
<launch>
<param name="enable_statistics" value="true" />
<test test-name="stamped_topic_statistics_with_empty_timestamp" pkg="test_roscpp" type="test_roscpp-stamped_topic_statistics_empty_timestamp"/>
</launch>

View File

@@ -0,0 +1,8 @@
<launch>
<node name="publish_constantly" pkg="test_roscpp" type="test_roscpp-publish_constantly">
<env name="ROSCPP_ENABLE_DEBUG" value="1"/>
</node>
<test test-name="subscribe_retry_tcp" pkg="test_roscpp" type="test_roscpp-subscribe_retry_tcp"/>
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="subscribe_self" pkg="test_roscpp" type="test_roscpp-subscribe_self" args="100 1.0"/>
</launch>

View File

@@ -0,0 +1,5 @@
<launch>
<node pkg="test_roscpp" type="test_roscpp-publisher_for_star_subscriber" name="publisher_for_star_subscriber"/>
<test test-name="subscribe_star" pkg="test_roscpp" type="test_roscpp-subscribe_star" />
</launch>

View File

@@ -0,0 +1,4 @@
<launch>
<test test-name="subscription_callback_types" pkg="test_roscpp" type="test_roscpp-subscription_callback_types"/>
</launch>

View File

@@ -0,0 +1,25 @@
<!-- This file is not part of automated testing. -->
<launch>
<node name="test_node" pkg="test_roscpp" type="test_roscpp-test_node" />
<test test-name="test_roscpp__global" pkg="test_ros" type="test_node_api.py" />
<group>
<!-- test within same namespace with test_node renamed to 'test_node2' -->
<node pkg="test_roscpp" type="test_roscpp-test_node" name="test_node2" />
<test test-name="test_roscpp__global_test_node2" pkg="test_ros" type="test_node_api.py" args="--node=test_node2"/>
</group>
<!-- test with nodes within namespaces -->
<group ns="child_namespace">
<node pkg="test_roscpp" type="test_roscpp-test_node" />
<test test-name="test_roscpp__child_namespace" pkg="test_ros" type="test_node_api.py" />
<group ns="grandchild_namespace">
<node pkg="test_roscpp" type="test_roscpp-test_node" />
<test test-name="test_roscpp__grandchild_namespace" pkg="test_ros" type="test_node_api.py" />
</group>
</group>
</launch>

View File

@@ -0,0 +1,3 @@
<launch>
<test test-name="timer_callbacks" pkg="test_roscpp" type="test_roscpp-timer_callbacks" time-limit="120"/>
</launch>

View File

@@ -0,0 +1,4 @@
<!-- This file is not part of automated testing. -->
<launch>
<test test-name="wait_for_message" pkg="test_roscpp" type="test_roscpp-wait_for_message"/>
</launch>

View File

@@ -0,0 +1,2 @@
int32 counter
float64[] float_arr

View File

@@ -0,0 +1,2 @@
string str
int32 counter

View File

@@ -0,0 +1 @@
Header header

View File

@@ -0,0 +1,21 @@
#!/bin/bash
DROP_PROBABILITY=0.01
IP=192.168.99.99
RULE="-i lo -d $IP -m statistic --mode random --probability $DROP_PROBABILITY -j DROP"
echo "Creating an additional loopback IP for testing..."
sudo ifconfig lo:1 $IP
echo "Using iptables to drop packets at a set probability..."
sudo iptables -A INPUT $RULE
echo "Running the test..."
export ROS_HOSTNAME=$IP
export ROS_MASTER_URI=http://$ROS_HOSTNAME:11311
roslaunch test_roscpp fragmented_udp_data.launch
echo "Cleaning up..."
sudo iptables -D INPUT $RULE
sudo ifconfig lo:1 down

View File

@@ -0,0 +1,348 @@
include_directories(${GTEST_INCLUDE_DIRS})
link_directories(${GTEST_LIBRARY_DIRS})
add_executable(${PROJECT_NAME}-handles EXCLUDE_FROM_ALL handles.cpp)
target_link_libraries(${PROJECT_NAME}-handles ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-timer_callbacks EXCLUDE_FROM_ALL timer_callbacks.cpp)
target_link_libraries(${PROJECT_NAME}-timer_callbacks ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-latching_publisher EXCLUDE_FROM_ALL latching_publisher.cpp)
target_link_libraries(${PROJECT_NAME}-latching_publisher ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-publish_n_fast EXCLUDE_FROM_ALL publish_n_fast.cpp)
target_link_libraries(${PROJECT_NAME}-publish_n_fast ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-subscribe_self EXCLUDE_FROM_ALL subscribe_self.cpp)
target_link_libraries(${PROJECT_NAME}-subscribe_self ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-pub_sub EXCLUDE_FROM_ALL pub_sub.cpp)
target_link_libraries(${PROJECT_NAME}-pub_sub ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-sub_pub EXCLUDE_FROM_ALL sub_pub.cpp)
target_link_libraries(${PROJECT_NAME}-sub_pub ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-publish_empty EXCLUDE_FROM_ALL publish_empty.cpp)
target_link_libraries(${PROJECT_NAME}-publish_empty ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-publish_onsub EXCLUDE_FROM_ALL publish_onsub.cpp)
target_link_libraries(${PROJECT_NAME}-publish_onsub ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-subscribe_n_fast EXCLUDE_FROM_ALL subscribe_n_fast.cpp)
target_link_libraries(${PROJECT_NAME}-subscribe_n_fast ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-subscribe_empty EXCLUDE_FROM_ALL subscribe_empty.cpp)
target_link_libraries(${PROJECT_NAME}-subscribe_empty ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-subscribe_resubscribe EXCLUDE_FROM_ALL subscribe_resubscribe.cpp)
target_link_libraries(${PROJECT_NAME}-subscribe_resubscribe ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-subscribe_unsubscribe EXCLUDE_FROM_ALL subscribe_unsubscribe.cpp)
target_link_libraries(${PROJECT_NAME}-subscribe_unsubscribe ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-publish_unadvertise EXCLUDE_FROM_ALL publish_unadvertise.cpp)
target_link_libraries(${PROJECT_NAME}-publish_unadvertise ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-subscribe_unsubscribe_repeatedly EXCLUDE_FROM_ALL subscribe_unsubscribe_repeatedly.cpp)
target_link_libraries(${PROJECT_NAME}-subscribe_unsubscribe_repeatedly ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-publish_constantly EXCLUDE_FROM_ALL publish_constantly.cpp)
target_link_libraries(${PROJECT_NAME}-publish_constantly ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-param_update_test EXCLUDE_FROM_ALL param_update_test.cpp)
target_link_libraries(${PROJECT_NAME}-param_update_test ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-real_time_test EXCLUDE_FROM_ALL real_time_test.cpp)
target_link_libraries(${PROJECT_NAME}-real_time_test ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-real_time_test ${rosgraph_msgs_EXPORTED_TARGETS})
add_executable(${PROJECT_NAME}-sim_time_test EXCLUDE_FROM_ALL sim_time_test.cpp)
target_link_libraries(${PROJECT_NAME}-sim_time_test ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-sim_time_test ${rosgraph_msgs_EXPORTED_TARGETS})
# Call a service
add_executable(${PROJECT_NAME}-service_adv EXCLUDE_FROM_ALL service_adv.cpp)
target_link_libraries(${PROJECT_NAME}-service_adv ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-service_adv_unadv EXCLUDE_FROM_ALL service_adv_unadv.cpp)
target_link_libraries(${PROJECT_NAME}-service_adv_unadv ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-service_call EXCLUDE_FROM_ALL service_call.cpp)
target_link_libraries(${PROJECT_NAME}-service_call ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-service_call_zombie EXCLUDE_FROM_ALL service_call_zombie.cpp)
target_link_libraries(${PROJECT_NAME}-service_call_zombie ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-service_deadlock EXCLUDE_FROM_ALL service_deadlock.cpp)
target_link_libraries(${PROJECT_NAME}-service_deadlock ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-service_deadlock ${std_srvs_EXPORTED_TARGETS})
add_executable(${PROJECT_NAME}-service_call_repeatedly EXCLUDE_FROM_ALL service_call_repeatedly.cpp)
target_link_libraries(${PROJECT_NAME}-service_call_repeatedly ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-service_exception EXCLUDE_FROM_ALL service_exception.cpp)
target_link_libraries(${PROJECT_NAME}-service_exception ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-service_exception ${std_srvs_EXPORTED_TARGETS})
# Repeatedly call ros::init()
add_executable(${PROJECT_NAME}-multiple_init_fini EXCLUDE_FROM_ALL multiple_init_fini.cpp)
target_link_libraries(${PROJECT_NAME}-multiple_init_fini ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# Test node inspection functionality
add_executable(${PROJECT_NAME}-inspection EXCLUDE_FROM_ALL inspection.cpp)
target_link_libraries(${PROJECT_NAME}-inspection ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# Test that advertising a service multiple times fails
add_executable(${PROJECT_NAME}-service_adv_multiple EXCLUDE_FROM_ALL service_adv_multiple.cpp)
target_link_libraries(${PROJECT_NAME}-service_adv_multiple ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# Test that the second node to advertise a service "wins"
add_executable(${PROJECT_NAME}-service_adv_a EXCLUDE_FROM_ALL service_adv_a.cpp)
target_link_libraries(${PROJECT_NAME}-service_adv_a ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-service_wait_a_adv_b EXCLUDE_FROM_ALL service_wait_a_adv_b.cpp)
target_link_libraries(${PROJECT_NAME}-service_wait_a_adv_b ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# Zombie (node crashed) service
add_executable(${PROJECT_NAME}-service_adv_zombie EXCLUDE_FROM_ALL service_adv_zombie.cpp)
target_link_libraries(${PROJECT_NAME}-service_adv_zombie ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-service_call_expect_b EXCLUDE_FROM_ALL service_call_expect_b.cpp)
target_link_libraries(${PROJECT_NAME}-service_call_expect_b ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# Test command-line name remapping
add_executable(${PROJECT_NAME}-name_remapping EXCLUDE_FROM_ALL name_remapping.cpp)
target_link_libraries(${PROJECT_NAME}-name_remapping ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-name_remapping_with_ns EXCLUDE_FROM_ALL name_remapping_with_ns.cpp)
target_link_libraries(${PROJECT_NAME}-name_remapping_with_ns ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# Test namespaces
add_executable(${PROJECT_NAME}-namespaces EXCLUDE_FROM_ALL namespaces.cpp)
target_link_libraries(${PROJECT_NAME}-namespaces ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# Test params
add_executable(${PROJECT_NAME}-params EXCLUDE_FROM_ALL params.cpp)
target_link_libraries(${PROJECT_NAME}-params ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# Test spinners
add_executable(${PROJECT_NAME}-spinners EXCLUDE_FROM_ALL spinners.cpp)
target_link_libraries(${PROJECT_NAME}-spinners ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# Test getting information from the master
add_executable(${PROJECT_NAME}-get_master_information EXCLUDE_FROM_ALL get_master_information.cpp)
target_link_libraries(${PROJECT_NAME}-get_master_information ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# Test multiple subscriptions
add_executable(${PROJECT_NAME}-multiple_subscriptions EXCLUDE_FROM_ALL multiple_subscriptions.cpp)
target_link_libraries(${PROJECT_NAME}-multiple_subscriptions ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-check_master EXCLUDE_FROM_ALL check_master.cpp)
target_link_libraries(${PROJECT_NAME}-check_master ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-wait_for_message EXCLUDE_FROM_ALL wait_for_message.cpp)
target_link_libraries(${PROJECT_NAME}-wait_for_message ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-loads_of_publishers EXCLUDE_FROM_ALL loads_of_publishers.cpp)
target_link_libraries(${PROJECT_NAME}-loads_of_publishers ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-incrementing_sequence EXCLUDE_FROM_ALL incrementing_sequence.cpp)
target_link_libraries(${PROJECT_NAME}-incrementing_sequence ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-subscription_callback_types EXCLUDE_FROM_ALL subscription_callback_types.cpp)
target_link_libraries(${PROJECT_NAME}-subscription_callback_types ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-subscription_callback_types ${std_msgs_EXPORTED_TARGETS})
add_executable(${PROJECT_NAME}-service_callback_types EXCLUDE_FROM_ALL service_callback_types.cpp)
target_link_libraries(${PROJECT_NAME}-service_callback_types ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-intraprocess_subscriptions EXCLUDE_FROM_ALL intraprocess_subscriptions.cpp)
target_link_libraries(${PROJECT_NAME}-intraprocess_subscriptions ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-nonconst_subscriptions EXCLUDE_FROM_ALL nonconst_subscriptions.cpp)
target_link_libraries(${PROJECT_NAME}-nonconst_subscriptions ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-subscribe_retry_tcp EXCLUDE_FROM_ALL subscribe_retry_tcp.cpp)
target_link_libraries(${PROJECT_NAME}-subscribe_retry_tcp ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-subscribe_star EXCLUDE_FROM_ALL subscribe_star.cpp)
target_link_libraries(${PROJECT_NAME}-subscribe_star ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-subscribe_star ${std_srvs_EXPORTED_TARGETS})
add_executable(${PROJECT_NAME}-publisher_for_star_subscriber EXCLUDE_FROM_ALL publisher_for_star_subscriber.cpp)
target_link_libraries(${PROJECT_NAME}-publisher_for_star_subscriber ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-publisher_for_star_subscriber ${std_srvs_EXPORTED_TARGETS})
add_executable(${PROJECT_NAME}-parameter_validation EXCLUDE_FROM_ALL parameter_validation.cpp)
target_link_libraries(${PROJECT_NAME}-parameter_validation ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-param_locale_avoidance_test EXCLUDE_FROM_ALL param_locale_avoidance_test.cpp)
target_link_libraries(${PROJECT_NAME}-param_locale_avoidance_test ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-crashes_under_gprof EXCLUDE_FROM_ALL crashes_under_gprof.cpp)
target_link_libraries(${PROJECT_NAME}-crashes_under_gprof ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-test_remapping EXCLUDE_FROM_ALL test_remapping.cpp)
target_link_libraries(${PROJECT_NAME}-test_remapping ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-name_not_remappable EXCLUDE_FROM_ALL name_not_remappable.cpp)
target_link_libraries(${PROJECT_NAME}-name_not_remappable ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-test_ns_node_remapping EXCLUDE_FROM_ALL test_ns_node_remapping.cpp)
target_link_libraries(${PROJECT_NAME}-test_ns_node_remapping ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-test_search_param EXCLUDE_FROM_ALL test_search_param.cpp)
target_link_libraries(${PROJECT_NAME}-test_search_param ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_executable(${PROJECT_NAME}-left_right EXCLUDE_FROM_ALL left_right.cpp)
target_link_libraries(${PROJECT_NAME}-left_right ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-left_right ${std_msgs_EXPORTED_TARGETS})
add_executable(${PROJECT_NAME}-string_msg_expect EXCLUDE_FROM_ALL string_msg_expect.cpp)
target_link_libraries(${PROJECT_NAME}-string_msg_expect ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-string_msg_expect ${std_msgs_EXPORTED_TARGETS})
add_executable(${PROJECT_NAME}-stamped_topic_statistics_empty_timestamp EXCLUDE_FROM_ALL stamped_topic_statistics_empty_timestamp.cpp)
target_link_libraries(${PROJECT_NAME}-stamped_topic_statistics_empty_timestamp ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
# The publisher and subscriber are compiled but not registered as a unit test
# since the test execution requires a network connection which drops packages.
# Call scripts/test_udp_with_dropped_packets.sh to run the test.
add_executable(${PROJECT_NAME}-publisher EXCLUDE_FROM_ALL publisher.cpp)
target_link_libraries(${PROJECT_NAME}-publisher ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-publisher ${std_msgs_EXPORTED_TARGETS})
add_executable(${PROJECT_NAME}-subscriber EXCLUDE_FROM_ALL subscriber.cpp)
target_link_libraries(${PROJECT_NAME}-subscriber ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME}-subscriber ${std_msgs_EXPORTED_TARGETS})
if(TARGET tests)
add_dependencies(tests
${PROJECT_NAME}-handles
${PROJECT_NAME}-timer_callbacks
${PROJECT_NAME}-latching_publisher
${PROJECT_NAME}-publish_n_fast
${PROJECT_NAME}-subscribe_self
${PROJECT_NAME}-pub_sub
${PROJECT_NAME}-sub_pub
${PROJECT_NAME}-publish_empty
${PROJECT_NAME}-publish_onsub
${PROJECT_NAME}-subscribe_n_fast
${PROJECT_NAME}-subscribe_empty
${PROJECT_NAME}-subscribe_resubscribe
${PROJECT_NAME}-subscribe_unsubscribe
${PROJECT_NAME}-publish_unadvertise
${PROJECT_NAME}-subscribe_unsubscribe_repeatedly
${PROJECT_NAME}-publish_constantly
${PROJECT_NAME}-param_update_test
${PROJECT_NAME}-real_time_test
${PROJECT_NAME}-sim_time_test
${PROJECT_NAME}-service_adv
${PROJECT_NAME}-service_adv_unadv
${PROJECT_NAME}-service_call
${PROJECT_NAME}-service_call_zombie
${PROJECT_NAME}-service_deadlock
${PROJECT_NAME}-service_exception
${PROJECT_NAME}-service_call_repeatedly
${PROJECT_NAME}-multiple_init_fini
${PROJECT_NAME}-inspection
${PROJECT_NAME}-service_adv_multiple
${PROJECT_NAME}-service_adv_a
${PROJECT_NAME}-service_adv_zombie
${PROJECT_NAME}-service_wait_a_adv_b
${PROJECT_NAME}-service_call_expect_b
${PROJECT_NAME}-name_remapping
${PROJECT_NAME}-name_remapping_with_ns
${PROJECT_NAME}-namespaces
${PROJECT_NAME}-params
${PROJECT_NAME}-spinners
${PROJECT_NAME}-get_master_information
${PROJECT_NAME}-multiple_subscriptions
${PROJECT_NAME}-check_master
${PROJECT_NAME}-wait_for_message
${PROJECT_NAME}-loads_of_publishers
${PROJECT_NAME}-incrementing_sequence
${PROJECT_NAME}-subscription_callback_types
${PROJECT_NAME}-service_callback_types
${PROJECT_NAME}-intraprocess_subscriptions
${PROJECT_NAME}-nonconst_subscriptions
${PROJECT_NAME}-subscribe_retry_tcp
${PROJECT_NAME}-subscribe_star
${PROJECT_NAME}-publisher_for_star_subscriber
${PROJECT_NAME}-parameter_validation
${PROJECT_NAME}-param_locale_avoidance_test
${PROJECT_NAME}-crashes_under_gprof
${PROJECT_NAME}-test_remapping
${PROJECT_NAME}-name_not_remappable
${PROJECT_NAME}-test_ns_node_remapping
${PROJECT_NAME}-test_search_param
${PROJECT_NAME}-left_right
${PROJECT_NAME}-string_msg_expect
${PROJECT_NAME}-publisher
${PROJECT_NAME}-subscriber
${PROJECT_NAME}-stamped_topic_statistics_empty_timestamp
)
endif()
add_dependencies(${PROJECT_NAME}-handles ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-timer_callbacks ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-latching_publisher ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-publish_n_fast ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-subscribe_self ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-pub_sub ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-sub_pub ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-publish_empty ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-publish_onsub ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-subscribe_n_fast ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-subscribe_empty ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-subscribe_resubscribe ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-subscribe_unsubscribe ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-publish_unadvertise ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-subscribe_unsubscribe_repeatedly ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-publish_constantly ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-param_update_test ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-real_time_test ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-sim_time_test ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_adv ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_adv_unadv ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_call ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_call_zombie ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_deadlock ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_exception ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_call_repeatedly ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-multiple_init_fini ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-inspection ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_adv_multiple ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_adv_a ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_wait_a_adv_b ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_call_expect_b ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_adv_zombie ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-name_remapping ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-name_remapping_with_ns ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-namespaces ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-params ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-spinners ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-get_master_information ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-multiple_subscriptions ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-check_master ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-wait_for_message ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-loads_of_publishers ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-incrementing_sequence ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-subscription_callback_types ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-service_callback_types ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-intraprocess_subscriptions ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-nonconst_subscriptions ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-subscribe_retry_tcp ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-subscribe_star ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-publisher_for_star_subscriber ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-parameter_validation ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-param_locale_avoidance_test ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-crashes_under_gprof ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-test_remapping ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-name_not_remappable ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-test_ns_node_remapping ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-test_search_param ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-left_right ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-string_msg_expect ${${PROJECT_NAME}_EXPORTED_TARGETS})
add_dependencies(${PROJECT_NAME}-stamped_topic_statistics_empty_timestamp
${${PROJECT_NAME}_EXPORTED_TARGETS})

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Brian Gerkey */
/*
* Check that the master is running
*/
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include "xmlrpcpp/XmlRpc.h"
using namespace XmlRpc;
bool g_should_exist = true;
TEST(CheckMaster, checkMaster)
{
ASSERT_EQ(ros::master::check(), g_should_exist);
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::V_string args;
ros::removeROSArgs(argc, argv, args);
if (args.size() != 2)
{
ROS_ERROR("Usage: check_master [yes|no]");
return 1;
}
if (args[1] == "no")
{
g_should_exist = false;
setenv("ROS_MASTER_URI", "http://invalid_host_name_blahahahahahahahahahahaha:11311", 1);
std::cout << getenv("ROS_MASTER_URI") << std::endl;
}
ros::init(argc, argv, "check_master");
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,18 @@
#include <ros/ros.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "test_get_param");
ros::NodeHandle nh;
nh.setParam(std::string("monkey"), false);
bool test_bool;
while(ros::ok()) {
if(!nh.getParam("monkey", test_bool)) {
ROS_INFO_STREAM("Failed, bailing");
ros::shutdown();
}
std::cout << ".";
}
return 0;
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
/*
* Test getting various information from the master, like the published topics
*/
#include <string>
#include <sstream>
#include <fstream>
#include <set>
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include "test_roscpp/TestEmpty.h"
TEST(masterInfo, getPublishedTopics)
{
ros::NodeHandle nh;
typedef std::set<std::string> S_string;
S_string advertised_topics;
advertised_topics.insert( "/test_topic_1" );
advertised_topics.insert( "/test_topic_2" );
advertised_topics.insert( "/test_topic_3" );
advertised_topics.insert( "/test_topic_4" );
advertised_topics.insert( "/test_topic_5" );
advertised_topics.insert( "/test_topic_6" );
advertised_topics.insert( "/test_topic_7" );
advertised_topics.insert( "/test_topic_8" );
std::vector<ros::Publisher> pubs;
S_string::iterator adv_it = advertised_topics.begin();
S_string::iterator adv_end = advertised_topics.end();
for ( ; adv_it != adv_end; ++adv_it )
{
const std::string& topic = *adv_it;
pubs.push_back(nh.advertise<test_roscpp::TestEmpty>( topic, 0 ));
}
ros::master::V_TopicInfo master_topics;
ros::master::getTopics(master_topics);
adv_it = advertised_topics.begin();
adv_end = advertised_topics.end();
for ( ; adv_it != adv_end; ++adv_it )
{
const std::string& topic = *adv_it;
bool found = false;
ros::master::V_TopicInfo::iterator master_it = master_topics.begin();
ros::master::V_TopicInfo::iterator master_end = master_topics.end();
for ( ; master_it != master_end; ++master_it )
{
const ros::master::TopicInfo& info = *master_it;
if ( topic == info.name )
{
found = true;
break;
}
}
ASSERT_TRUE( found );
}
}
int
main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init( argc, argv, "get_master_information" );
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,634 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
/*
* Test handles
*/
#include <string>
#include <sstream>
#include <fstream>
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include "ros/callback_queue.h"
#include <test_roscpp/TestArray.h>
#include <test_roscpp/TestStringString.h>
#include <boost/thread.hpp>
using namespace ros;
using namespace test_roscpp;
TEST(RoscppHandles, nodeHandleConstructionDestruction)
{
{
ASSERT_FALSE(ros::isStarted());
ros::NodeHandle n1;
ASSERT_TRUE(ros::isStarted());
{
ros::NodeHandle n2;
ASSERT_TRUE(ros::isStarted());
{
ros::NodeHandle n3(n2);
ASSERT_TRUE(ros::isStarted());
{
ros::NodeHandle n4 = n3;
ASSERT_TRUE(ros::isStarted());
}
}
}
ASSERT_TRUE(ros::isStarted());
}
ASSERT_FALSE(ros::isStarted());
{
ros::NodeHandle n;
ASSERT_TRUE(ros::isStarted());
}
ASSERT_FALSE(ros::isStarted());
}
TEST(RoscppHandles, nodeHandleParentWithRemappings)
{
ros::M_string remappings;
remappings["a"] = "b";
remappings["c"] = "d";
ros::NodeHandle n1("", remappings);
// sanity checks
EXPECT_STREQ(n1.resolveName("a").c_str(), "/b");
EXPECT_STREQ(n1.resolveName("/a").c_str(), "/b");
EXPECT_STREQ(n1.resolveName("c").c_str(), "/d");
EXPECT_STREQ(n1.resolveName("/c").c_str(), "/d");
ros::NodeHandle n2(n1, "my_ns");
EXPECT_STREQ(n2.resolveName("a").c_str(), "/my_ns/a");
EXPECT_STREQ(n2.resolveName("/a").c_str(), "/b");
EXPECT_STREQ(n2.resolveName("c").c_str(), "/my_ns/c");
EXPECT_STREQ(n2.resolveName("/c").c_str(), "/d");
ros::NodeHandle n3(n2);
EXPECT_STREQ(n3.resolveName("a").c_str(), "/my_ns/a");
EXPECT_STREQ(n3.resolveName("/a").c_str(), "/b");
EXPECT_STREQ(n3.resolveName("c").c_str(), "/my_ns/c");
EXPECT_STREQ(n3.resolveName("/c").c_str(), "/d");
ros::NodeHandle n4;
n4 = n3;
EXPECT_STREQ(n4.resolveName("a").c_str(), "/my_ns/a");
EXPECT_STREQ(n4.resolveName("/a").c_str(), "/b");
EXPECT_STREQ(n4.resolveName("c").c_str(), "/my_ns/c");
EXPECT_STREQ(n4.resolveName("/c").c_str(), "/d");
}
int32_t g_recv_count = 0;
void subscriberCallback(const test_roscpp::TestArray::ConstPtr&)
{
++g_recv_count;
}
class SubscribeHelper
{
public:
SubscribeHelper()
: recv_count_(0)
{}
void callback(const test_roscpp::TestArray::ConstPtr&)
{
++recv_count_;
}
int32_t recv_count_;
};
TEST(RoscppHandles, subscriberValidity)
{
ros::NodeHandle n;
ros::Subscriber sub;
ASSERT_FALSE(sub);
sub = n.subscribe("test", 0, subscriberCallback);
ASSERT_TRUE(sub);
}
TEST(RoscppHandles, subscriberDestructionMultipleCallbacks)
{
ros::NodeHandle n;
ros::Publisher pub = n.advertise<test_roscpp::TestArray>("test", 0);
test_roscpp::TestArray msg;
{
SubscribeHelper helper;
ros::Subscriber sub_class = n.subscribe("test", 0, &SubscribeHelper::callback, &helper);
ros::Duration d(0.05);
int32_t last_class_count = helper.recv_count_;
while (last_class_count == helper.recv_count_)
{
pub.publish(msg);
ros::spinOnce();
d.sleep();
}
int32_t last_fn_count = g_recv_count;
{
ros::Subscriber sub_fn = n.subscribe("test", 0, subscriberCallback);
ASSERT_TRUE(sub_fn != sub_class);
last_fn_count = g_recv_count;
while (last_fn_count == g_recv_count)
{
pub.publish(msg);
ros::spinOnce();
d.sleep();
}
}
last_fn_count = g_recv_count;
last_class_count = helper.recv_count_;
while (last_class_count == helper.recv_count_)
{
pub.publish(msg);
ros::spinOnce();
d.sleep();
}
d.sleep();
ASSERT_EQ(last_fn_count, g_recv_count);
}
}
TEST(RoscppHandles, subscriberSpinAfterSubscriberShutdown)
{
ros::NodeHandle n;
ros::Publisher pub = n.advertise<test_roscpp::TestArray>("test", 0);
test_roscpp::TestArray msg;
int32_t last_fn_count = g_recv_count;
{
ros::Subscriber sub_fn = n.subscribe("test", 0, subscriberCallback);
last_fn_count = g_recv_count;
for (int i = 0; i < 10; ++i)
{
pub.publish(msg);
}
ros::WallDuration(0.1).sleep();
}
ros::spinOnce();
ASSERT_EQ(last_fn_count, g_recv_count);
}
TEST(RoscppHandles, subscriberGetNumPublishers)
{
ros::NodeHandle n;
ros::Publisher pub = n.advertise<test_roscpp::TestArray>("test", 0);
ros::Subscriber sub = n.subscribe("test", 0, subscriberCallback);
ros::WallTime begin = ros::WallTime::now();
while (sub.getNumPublishers() < 1 && (ros::WallTime::now() - begin < ros::WallDuration(1)))
{
ros::spinOnce();
ros::WallDuration(0.1).sleep();
}
ASSERT_EQ(sub.getNumPublishers(), 1ULL);
}
TEST(RoscppHandles, subscriberCopy)
{
ros::NodeHandle n;
g_recv_count = 0;
{
ros::Subscriber sub1 = n.subscribe("/test", 0, subscriberCallback);
{
ros::Subscriber sub2 = sub1;
{
ros::Subscriber sub3(sub2);
ASSERT_TRUE(sub3 == sub2);
V_string topics;
this_node::getSubscribedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") != topics.end());
}
ASSERT_TRUE(sub2 == sub1);
V_string topics;
this_node::getSubscribedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") != topics.end());
}
V_string topics;
this_node::getSubscribedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") != topics.end());
}
V_string topics;
this_node::getSubscribedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") == topics.end());
}
TEST(RoscppHandles, publisherCopy)
{
ros::NodeHandle n;
g_recv_count = 0;
{
ros::Publisher pub1 = n.advertise<test_roscpp::TestArray>("/test", 0);
{
ros::Publisher pub2 = pub1;
{
ros::Publisher pub3(pub2);
ASSERT_TRUE(pub3 == pub2);
V_string topics;
this_node::getAdvertisedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") != topics.end());
}
ASSERT_TRUE(pub2 == pub1);
V_string topics;
this_node::getAdvertisedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") != topics.end());
}
V_string topics;
this_node::getAdvertisedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") != topics.end());
}
V_string topics;
this_node::getAdvertisedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") == topics.end());
}
TEST(RoscppHandles, publisherMultiple)
{
ros::NodeHandle n;
g_recv_count = 0;
{
ros::Publisher pub1 = n.advertise<test_roscpp::TestArray>("/test", 0);
{
ros::Publisher pub2 = n.advertise<test_roscpp::TestArray>("/test", 0);
ASSERT_TRUE(pub1 != pub2);
V_string topics;
this_node::getAdvertisedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") != topics.end());
}
V_string topics;
this_node::getAdvertisedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") != topics.end());
}
V_string topics;
this_node::getAdvertisedTopics(topics);
ASSERT_TRUE(std::find(topics.begin(), topics.end(), "/test") == topics.end());
}
bool serviceCallback(TestStringString::Request&, TestStringString::Response&)
{
return true;
}
void pump(ros::CallbackQueue* queue)
{
while (queue->isEnabled())
{
queue->callAvailable(ros::WallDuration(0.1));
}
}
TEST(RoscppHandles, serviceAdv)
{
ros::NodeHandle n;
TestStringString t;
ros::CallbackQueue queue;
n.setCallbackQueue(&queue);
boost::thread th(boost::bind(pump, &queue));
{
ros::ServiceServer srv = n.advertiseService("/test_srv", serviceCallback);
EXPECT_TRUE(ros::service::call("/test_srv", t));
}
queue.disable();
th.join();
ASSERT_FALSE(ros::service::call("/test_srv", t));
}
TEST(RoscppHandles, serviceAdvCopy)
{
ros::NodeHandle n;
TestStringString t;
ros::CallbackQueue queue;
n.setCallbackQueue(&queue);
boost::thread th(boost::bind(pump, &queue));
{
ros::ServiceServer srv1 = n.advertiseService("/test_srv", serviceCallback);
{
ros::ServiceServer srv2 = srv1;
{
ros::ServiceServer srv3(srv2);
ASSERT_TRUE(srv3 == srv2);
EXPECT_TRUE(ros::service::call("/test_srv", t));
}
ASSERT_TRUE(srv2 == srv1);
EXPECT_TRUE(ros::service::call("/test_srv", t));
}
EXPECT_TRUE(ros::service::call("/test_srv", t));
}
ASSERT_FALSE(ros::service::call("/test_srv", t));
queue.disable();
th.join();
}
TEST(RoscppHandles, serviceAdvMultiple)
{
ros::NodeHandle n;
ros::ServiceServer srv = n.advertiseService("/test_srv", serviceCallback);
ros::ServiceServer srv2 = n.advertiseService("/test_srv", serviceCallback);
ASSERT_TRUE(srv);
ASSERT_FALSE(srv2);
ASSERT_TRUE(srv != srv2);
}
int32_t g_sub_count = 0;
void connectedCallback(const ros::SingleSubscriberPublisher&)
{
++g_sub_count;
}
TEST(RoscppHandles, trackedObjectWithAdvertiseSubscriberCallback)
{
ros::NodeHandle n;
boost::shared_ptr<char> tracked(boost::make_shared<char>());
ros::Publisher pub = n.advertise<test_roscpp::TestArray>("/test", 0, connectedCallback, SubscriberStatusCallback(), tracked);
g_recv_count = 0;
g_sub_count = 0;
ros::Subscriber sub = n.subscribe("/test", 0, subscriberCallback);
Duration d(0.01);
while (g_sub_count == 0)
{
d.sleep();
ros::spinOnce();
}
ASSERT_EQ(g_sub_count, 1);
sub.shutdown();
tracked.reset();
sub = n.subscribe("/test", 0, subscriberCallback);
Duration d2(0.01);
for (int i = 0; i < 10; ++i)
{
d2.sleep();
ros::spinOnce();
}
ASSERT_EQ(g_sub_count, 1);
}
TEST(RoscppHandles, spinAfterHandleShutdownWithAdvertiseSubscriberCallback)
{
ros::NodeHandle n;
ros::Publisher pub = n.advertise<test_roscpp::TestArray>("/test", 0, connectedCallback, SubscriberStatusCallback());
g_sub_count = 0;
ros::Subscriber sub = n.subscribe("/test", 0, subscriberCallback);
while (pub.getNumSubscribers() == 0)
{
ros::WallDuration(0.01).sleep();
}
pub.shutdown();
ros::spinOnce();
ASSERT_EQ(g_sub_count, 0);
}
TEST(RoscppHandles, multiplePublishersWithSubscriberConnectCallback)
{
ros::NodeHandle n;
ros::Publisher pub = n.advertise<test_roscpp::TestArray>("/test", 0, connectedCallback, SubscriberStatusCallback());
g_sub_count = 0;
ros::Subscriber sub = n.subscribe("/test", 0, subscriberCallback);
while (g_sub_count == 0)
{
ros::WallDuration(0.01).sleep();
ros::spinOnce();
}
ASSERT_EQ(g_sub_count, 1);
g_sub_count = 0;
ros::Publisher pub2 = n.advertise<test_roscpp::TestArray>("/test", 0, connectedCallback, SubscriberStatusCallback());
ros::spinOnce();
ASSERT_EQ(g_sub_count, 1);
}
class ServiceClass
{
public:
bool serviceCallback(TestStringString::Request&, TestStringString::Response&)
{
return true;
}
};
TEST(RoscppHandles, trackedObjectWithServiceCallback)
{
ros::NodeHandle n;
ros::CallbackQueue queue;
n.setCallbackQueue(&queue);
boost::thread th(boost::bind(pump, &queue));
boost::shared_ptr<ServiceClass> tracked(boost::make_shared<ServiceClass>());
ros::ServiceServer srv = n.advertiseService("/test_srv", &ServiceClass::serviceCallback, tracked);
TestStringString t;
EXPECT_TRUE(ros::service::call("/test_srv", t));
tracked.reset();
ASSERT_FALSE(ros::service::call("/test_srv", t));
queue.disable();
th.join();
}
TEST(RoscppHandles, trackedObjectWithSubscriptionCallback)
{
ros::NodeHandle n;
boost::shared_ptr<SubscribeHelper> tracked(boost::make_shared<SubscribeHelper>());
g_recv_count = 0;
ros::Subscriber sub = n.subscribe("/test", 0, &SubscribeHelper::callback, tracked);
ros::Publisher pub = n.advertise<test_roscpp::TestArray>("/test", 0);
test_roscpp::TestArray msg;
Duration d(0.01);
while (tracked->recv_count_ == 0)
{
pub.publish(msg);
d.sleep();
ros::spinOnce();
}
ASSERT_GE(tracked->recv_count_, 1);
tracked.reset();
pub.publish(msg);
Duration d2(0.01);
for (int i = 0; i < 10; ++i)
{
d2.sleep();
ros::spinOnce();
}
}
TEST(RoscppHandles, nodeHandleNames)
{
ros::NodeHandle n1;
EXPECT_STREQ(n1.resolveName("blah").c_str(), "/blah");
try
{
n1.resolveName("~blah");
FAIL();
}
catch (ros::InvalidNameException&)
{
}
ros::NodeHandle n2("internal_ns");
EXPECT_STREQ(n2.resolveName("blah").c_str(), "/internal_ns/blah");
ros::NodeHandle n3(n2, "2");
EXPECT_STREQ(n3.resolveName("blah").c_str(), "/internal_ns/2/blah");
ros::NodeHandle n4("~");
EXPECT_STREQ(n4.resolveName("blah").c_str(), (ros::this_node::getName() + "/blah").c_str());
try {
ros::NodeHandle n5(n2, "illegal_name!!!");
FAIL();
} catch (ros::InvalidNameException&) { }
}
TEST(RoscppHandles, nodeHandleShutdown)
{
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/test", 0, subscriberCallback);
ros::Publisher pub = n.advertise<test_roscpp::TestArray>("/test", 0);
ros::ServiceServer srv = n.advertiseService("/test_srv", serviceCallback);
n.shutdown();
ASSERT_FALSE(pub);
ASSERT_FALSE(sub);
ASSERT_FALSE(srv);
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "test_handles");
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright (c) 2009, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
#include <string>
#include <sstream>
#include <fstream>
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include <test_roscpp/TestWithHeader.h>
using namespace ros;
using namespace test_roscpp;
uint32_t g_recv_count = 0;
uint32_t g_sequence = 0;
void callback(const TestWithHeaderConstPtr& msg)
{
++g_recv_count;
g_sequence = msg->header.seq;
}
TEST(IncrementingSequence, incrementing)
{
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise<TestWithHeader>("test_with_header", 0);
ros::Subscriber sub = nh.subscribe("test_with_header", 0, callback);
while (g_recv_count < 50)
{
TestWithHeader msg;
msg.header.frame_id = "blah";
msg.header.stamp = ros::Time::now();
pub.publish(msg);
ros::spinOnce();
ros::WallDuration(0.01).sleep();
}
ASSERT_GT(g_sequence, 0UL);
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "incrementing_sequence");
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Brian Gerkey */
/*
* Test inspection functionality
*/
#include <string>
#include <gtest/gtest.h>
#include <ros/ros.h>
#include <ros/names.h>
#include <test_roscpp/TestArray.h>
#include <test_roscpp/TestStringInt.h>
#include <test_roscpp/TestEmpty.h>
const char* g_node_name = "inspection_test";
int g_argc;
char* g_argv[8];
TEST(Inspection, getAdvertisedTopics)
{
ros::NodeHandle nh;
std::vector<std::string> topics;
ros::this_node::getAdvertisedTopics(topics);
// Note that it's 1, not 0, because the rosout appender has already snuck
// in and advertised.
ASSERT_EQ((int)topics.size(),1);
ASSERT_EQ(topics[0], "/rosout");
{
ros::Publisher pub1 = nh.advertise<test_roscpp::TestArray>("topic",1);
ros::Publisher pub2 = nh.advertise<test_roscpp::TestArray>("ns/topic",1);
ros::Publisher pub3 = nh.advertise<test_roscpp::TestArray>("/global/topic",1);
topics.clear();
ros::this_node::getAdvertisedTopics(topics);
// Note that it's 4, not 3, because the rosout appender has already snuck
// in and advertised.
ASSERT_EQ((int)topics.size(),4);
// The following tests assume strict ordering of the topics, which is not
// guaranteed by the API.
ASSERT_EQ(topics[0], "/rosout");
ASSERT_EQ(topics[1], "/topic");
ASSERT_EQ(topics[2], "/ns/topic");
ASSERT_EQ(topics[3], "/global/topic");
}
topics.clear();
ros::this_node::getAdvertisedTopics(topics);
// Note that it's 1, not 0, because the rosout appender has already snuck
// in and advertised.
ASSERT_EQ((int)topics.size(),1);
ASSERT_EQ(topics[0], "/rosout");
}
TEST(Inspection, commandLineParsing)
{
ASSERT_EQ(g_argc, 5);
ros::M_string remappings = ros::names::getRemappings();
ASSERT_STREQ(remappings["/foo"].c_str(), "/bar");
ASSERT_STREQ(remappings["/baz"].c_str(), "/bang");
ASSERT_STREQ(remappings["/bomb"].c_str(), "/barn");
}
int
main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
g_argc = 8;
g_argv[0] = strdup(argv[0]);
g_argv[1] = strdup("foo:=bar");
g_argv[2] = strdup("bat");
g_argv[3] = strdup("baz:=bang");
g_argv[4] = strdup("boom");
g_argv[5] = strdup("baz=bomb");
g_argv[6] = strdup("bomb:=barn");
g_argv[7] = strdup("--bangbang");
ros::init( g_argc, g_argv, "inspection" );
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,297 @@
/*
* Copyright (c) 2010, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
/*
* Subscribe intraprocess, ensuring that no copy happens
*/
#include <string>
#include <gtest/gtest.h>
#include <stdlib.h>
#include "ros/ros.h"
uint32_t g_msg_constructor = 0;
uint32_t g_msg2_constructor = 0;
struct Msg
{
Msg()
: serialized(false)
, deserialized(false)
{
++g_msg_constructor;
}
mutable bool serialized;
bool deserialized;
};
typedef boost::shared_ptr<Msg const> MsgConstPtr;
namespace ros
{
namespace message_traits
{
template<>
struct MD5Sum<Msg>
{
static const char* value() { return "MsgMD5Sum"; }
static const char* value(const Msg&) { return "MsgMD5Sum"; }
};
template<>
struct DataType<Msg>
{
static const char* value() { return "roscpp/MsgDataType"; }
static const char* value(const Msg&) { return "roscpp/MsgDataType"; }
};
template<>
struct Definition<Msg>
{
static const char* value() { return ""; }
static const char* value(const Msg&) { return ""; }
};
} // namespace message_traits
namespace serialization
{
template<>
struct Serializer<Msg>
{
template<typename Stream>
inline static void write(Stream&, const Msg& v)
{
v.serialized = true;
}
template<typename Stream>
inline static void read(Stream&, Msg& v)
{
v.deserialized = true;
}
inline static uint32_t serializedLength(const Msg&)
{
return 0;
}
};
} // namespace serialization
} // namespace ros
MsgConstPtr g_msg;
struct Msg2
{
Msg2()
: serialized(false)
, deserialized(false)
{
++g_msg2_constructor;
}
mutable bool serialized;
bool deserialized;
};
typedef boost::shared_ptr<Msg2 const> Msg2ConstPtr;
namespace ros
{
namespace message_traits
{
template<>
struct MD5Sum<Msg2>
{
static const char* value() { return "MsgMD5Sum"; }
static const char* value(const Msg2&) { return "MsgMD5Sum"; }
};
template<>
struct DataType<Msg2>
{
static const char* value() { return "roscpp/MsgDataType"; }
static const char* value(const Msg2&) { return "roscpp/MsgDataType"; }
};
template<>
struct Definition<Msg2>
{
static const char* value() { return ""; }
static const char* value(const Msg2&) { return ""; }
};
} // namespace message_traits
namespace serialization
{
template<>
struct Serializer<Msg2>
{
template<typename Stream>
inline static void write(Stream&, const Msg2& v)
{
v.serialized = true;
}
template<typename Stream>
inline static void read(Stream&, Msg2& v)
{
v.deserialized = true;
}
inline static uint32_t serializedLength(const Msg2&)
{
return 0;
}
};
} // namespace serialization
} // namespace ros
void messageCallback(const MsgConstPtr& msg)
{
g_msg = msg;
}
TEST(IntraprocessSubscriptions, noCopy)
{
g_msg.reset();
g_msg_constructor = 0;
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("test", 0, messageCallback);
ros::Publisher pub = nh.advertise<Msg>("test", 0);
MsgConstPtr msg(boost::make_shared<Msg>());
while (pub.getNumSubscribers() == 0)
{
ros::Duration(0.01).sleep();
}
pub.publish(msg);
while (!g_msg)
{
ros::spinOnce();
ros::Duration(0.01).sleep();
}
ASSERT_TRUE(g_msg);
EXPECT_EQ(g_msg.get(), msg.get());
EXPECT_FALSE(g_msg->serialized);
EXPECT_FALSE(g_msg->deserialized);
EXPECT_EQ(g_msg_constructor, 1ULL);
}
TEST(IntraprocessSubscriptions, differentRTTI)
{
g_msg_constructor = 0;
g_msg.reset();
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("test", 0, messageCallback);
ros::Publisher pub = nh.advertise<Msg2>("test", 0);
Msg2ConstPtr msg(boost::make_shared<Msg2>());
while (pub.getNumSubscribers() == 0)
{
ros::Duration(0.01).sleep();
}
pub.publish(msg);
while (!g_msg)
{
ros::spinOnce();
ros::Duration(0.01).sleep();
}
ASSERT_TRUE(g_msg);
EXPECT_NE((void*)g_msg.get(), (void*)msg.get());
EXPECT_TRUE(msg->serialized);
EXPECT_TRUE(g_msg->deserialized);
EXPECT_EQ(g_msg_constructor, 1ULL);
EXPECT_EQ(g_msg2_constructor, 1ULL);
}
Msg2ConstPtr g_msg2;
void messageCallback2(const Msg2ConstPtr& msg)
{
g_msg2 = msg;
}
TEST(IntraprocessSubscriptions, noCopyAndDifferentRTTI)
{
g_msg.reset();
ros::NodeHandle nh;
ros::Subscriber sub1 = nh.subscribe("test", 0, messageCallback);
ros::Subscriber sub2 = nh.subscribe("test", 0, messageCallback2);
ros::Publisher pub = nh.advertise<Msg2>("test", 0);
Msg2ConstPtr msg(boost::make_shared<Msg2>());
while (pub.getNumSubscribers() == 0)
{
ros::Duration(0.01).sleep();
}
pub.publish(msg);
while (!g_msg || !g_msg2)
{
ros::spinOnce();
ros::Duration(0.01).sleep();
}
ASSERT_TRUE(g_msg);
EXPECT_NE((void*)g_msg.get(), (void*)msg.get());
EXPECT_TRUE(msg->serialized);
EXPECT_TRUE(g_msg->deserialized);
ASSERT_TRUE(g_msg2);
EXPECT_EQ(g_msg2.get(), msg.get());
EXPECT_TRUE(g_msg2->serialized);
EXPECT_FALSE(g_msg2->deserialized);
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "intraprocess_subscriptions");
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
#include <string>
#include <sstream>
#include <fstream>
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include <test_roscpp/TestArray.h>
using namespace ros;
using namespace test_roscpp;
std::string g_node_name = "test_latching_publisher";
class Helper
{
public:
Helper()
: count_(0)
{}
void cb(const ros::MessageEvent<TestArray>& msg_event)
{
++count_;
last_msg_event_ = msg_event;
}
int32_t count_;
ros::MessageEvent<TestArray> last_msg_event_;
};
TEST(RoscppLatchingPublisher, nonLatching)
{
ros::NodeHandle n;
ros::Publisher pub = n.advertise<TestArray>("test", 1, false);
TestArray arr;
pub.publish(arr);
Helper h;
ros::Subscriber sub = n.subscribe("test", 1, &Helper::cb, &h);
ros::Duration(0.1).sleep();
ros::spinOnce();
ASSERT_EQ(h.count_, 0);
}
TEST(RoscppLatchingPublisher, latching)
{
ros::NodeHandle n;
ros::Publisher pub = n.advertise<TestArray>("test", 1, true);
TestArray arr;
pub.publish(arr);
Helper h;
ros::Subscriber sub = n.subscribe("test", 1, &Helper::cb, &h);
ros::Duration(0.1).sleep();
ros::spinOnce();
ASSERT_EQ(h.count_, 1);
ASSERT_STREQ(h.last_msg_event_.getConnectionHeader()["latching"].c_str(), "1");
}
TEST(RoscppLatchingPublisher, latchingMultipleSubscriptions)
{
ros::NodeHandle n;
ros::Publisher pub = n.advertise<TestArray>("test", 1, true);
TestArray arr;
pub.publish(arr);
Helper h1, h2;
ros::Subscriber sub1 = n.subscribe("test", 1, &Helper::cb, &h1);
ros::Duration(0.1).sleep();
ros::spinOnce();
ASSERT_EQ(h1.count_, 1);
ASSERT_EQ(h2.count_, 0);
ros::Subscriber sub2 = n.subscribe("test", 1, &Helper::cb, &h2);
ros::spinOnce();
ASSERT_EQ(h1.count_, 1);
ASSERT_EQ(h2.count_, 1);
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, g_node_name);
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2011, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Troy Straszheim */
/*
* Basic publisher of two messages.
*/
#include <string>
#include <sstream>
#include <fstream>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include "std_msgs/String.h"
int
main(int argc, char** argv)
{
ros::init( argc, argv, "left_right");
ros::NodeHandle nh;
ros::Publisher left = nh.advertise<std_msgs::String>("left", 0);
ros::Publisher right = nh.advertise<std_msgs::String>("right", 0);
std_msgs::String msg_l, msg_r;
msg_l.data = "left";
msg_r.data = "right";
ros::Rate loop_rate(2);
for (unsigned j=0; j<5; ++j)
{
assert(ros::ok());
left.publish(msg_l);
right.publish(msg_r);
ROS_INFO("ping!");
ros::spinOnce();
loop_rate.sleep();
ros::spinOnce();
}
return 0;
}

View File

@@ -0,0 +1,97 @@
/*
* Copyright (c) 2009, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
#include <gtest/gtest.h>
#include <ros/ros.h>
#include <ros/callback_queue.h>
#include "test_roscpp/TestArray.h"
uint32_t g_pub_count = 0;
void callback(const test_roscpp::TestArrayConstPtr&)
{
}
TEST(LoadsOfPublishers, waitForAll)
{
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("roscpp/pubsub_test", 1000, callback);
while (sub.getNumPublishers() < g_pub_count)
{
ros::getGlobalCallbackQueue()->callAvailable(ros::WallDuration(0.1));
}
ros::WallDuration(10).sleep();
ros::spinOnce();
ASSERT_EQ(sub.getNumPublishers(), g_pub_count);
}
struct Helper
{
void callback(const ros::MessageEvent<test_roscpp::TestArray>& msg_event)
{
alive[msg_event.getPublisherName()] = true;
}
std::map<std::string, bool> alive;
};
TEST(LoadsOfPublishers, receiveFromAll)
{
ros::NodeHandle nh;
Helper helper;
ros::Subscriber sub = nh.subscribe("roscpp/pubsub_test", 1000, &Helper::callback, &helper);
while (helper.alive.size() < g_pub_count)
{
ros::getGlobalCallbackQueue()->callAvailable(ros::WallDuration(0.1));
}
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "loads_of_publishers");
if (argc < 2)
{
ROS_ERROR("Not enough arguments (usage: loads_of_publishers num_publishers)");
return 1;
}
g_pub_count = atoi(argv[1]);
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
/*
* Repeatedly create and destroy a node. Do some stuff in between to be sure things are working
*/
#include <string>
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include <test_roscpp/TestArray.h>
int g_argc;
char** g_argv;
void callback(const test_roscpp::TestArrayConstPtr&)
{
}
TEST(roscpp, multipleInitAndFini)
{
int try_count = 10;
if ( g_argc > 1 )
{
try_count = atoi(g_argv[1]);
}
for ( int i = 0; i < try_count; ++i )
{
ros::init( g_argc, g_argv, "multiple_init_fini" );
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("test", 1, callback);
ASSERT_TRUE(sub);
ros::Publisher pub = nh.advertise<test_roscpp::TestArray>( "test2", 1 );
ASSERT_TRUE(pub);
ros::shutdown();
}
}
int
main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
g_argc = argc;
g_argv = argv;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,191 @@
/*
* Copyright (C) 2008, Morgan Quigley and Willow Garage, Inc.
*
* 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 names of Stanford University or Willow Garage, Inc. 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.
*/
/* Author: Morgan Quigley */
/*
* Subscribe to a topic multiple times
*/
#include <string>
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include <test_roscpp/TestArray.h>
#include <test_roscpp/TestEmpty.h>
int g_argc;
char** g_argv;
class Subscriptions : public testing::Test
{
public:
ros::NodeHandle nh_;
bool got_it[4], should_have_it[4];
ros::Subscriber subs_[4];
ros::Subscriber verify_sub_;
ros::Subscriber reset_sub_;
bool test_ready;
int n_test;
void cb0(const test_roscpp::TestArrayConstPtr&) { if (!test_ready) return; got_it[0] = true; }
void cb1(const test_roscpp::TestArrayConstPtr&) { if (!test_ready) return; got_it[1] = true; }
void cb2(const test_roscpp::TestArrayConstPtr&) { if (!test_ready) return; got_it[2] = true; }
void cb3(const test_roscpp::TestArrayConstPtr&) { if (!test_ready) return; got_it[3] = true; }
void cb_verify(const test_roscpp::TestArrayConstPtr&)
{
if (!test_ready)
return;
n_test++;
/*
ASSERT_TRUE(((should_have_it[0] ? got_it[0] : true) &&
(should_have_it[1] ? got_it[1] : true) &&
(should_have_it[2] ? got_it[2] : true) &&
(should_have_it[3] ? got_it[3] : true)));
*/
}
void cb_reset(const test_roscpp::TestArrayConstPtr&)
{
got_it[0] = got_it[1] = got_it[2] = got_it[3] = false; test_ready = true;
}
protected:
bool sub(int cb_num)
{
ROS_INFO("Subscribing %d", cb_num);
boost::function<void(const test_roscpp::TestArrayConstPtr&)> funcs[4] =
{
boost::bind(&Subscriptions::cb0, this, _1),
boost::bind(&Subscriptions::cb1, this, _1),
boost::bind(&Subscriptions::cb2, this, _1),
boost::bind(&Subscriptions::cb3, this, _1),
};
subs_[cb_num] = nh_.subscribe("roscpp/pubsub_test", 10, funcs[cb_num]);
return subs_[cb_num];
}
bool sub_wrappers()
{
ROS_INFO("sub_wrappers");
verify_sub_ = nh_.subscribe("roscpp/pubsub_test", 10, &Subscriptions::cb_verify, this);
reset_sub_ = nh_.subscribe("roscpp/pubsub_test", 10, &Subscriptions::cb_reset, this);
return verify_sub_ && reset_sub_;
}
bool unsub(int cb_num)
{
ROS_INFO("unsubscribing %d", cb_num);
subs_[cb_num].shutdown();
return true;
}
bool unsub_wrappers()
{
ROS_INFO("unsub wrappers");
verify_sub_.shutdown();
reset_sub_.shutdown();
return true;
}
};
TEST_F(Subscriptions, multipleSubscriptions)
{
test_ready = false;
for (int i = 0; i < 0x10; i++)
{
for (int j = 0; j < 4; j++)
should_have_it[j] = (i & (1 << j) ? true : false);
ROS_INFO(" testing: %d, %d, %d, %d\n",
should_have_it[0],
should_have_it[1],
should_have_it[2],
should_have_it[3]);
for (int j = 0; j < 4; j++)
if (should_have_it[j])
ASSERT_TRUE(sub(j));
ASSERT_TRUE(sub_wrappers());
ros::Time t_start = ros::Time::now();
n_test = 0;
while (n_test < 10 && ros::Time::now() - t_start < ros::Duration(5000.0))
{
static int count = 0;
if (count++ % 10 == 0)
ROS_INFO("%d/100 tests completed...\n", n_test);
ros::spinOnce();
ros::Duration(0.01).sleep();
}
for (int j = 0; j < 4; j++)
if (should_have_it[j])
ASSERT_TRUE(unsub(j));
ASSERT_TRUE(unsub_wrappers());
}
SUCCEED();
}
void callback1(const test_roscpp::TestArrayConstPtr&)
{
}
void callback2(const test_roscpp::TestEmptyConstPtr&)
{
}
TEST(Subscriptions2, multipleDifferentMD5Sums)
{
ros::NodeHandle nh;
ros::Subscriber sub1 = nh.subscribe("test", 0, callback1);
try
{
ros::Subscriber sub2 = nh.subscribe("test", 0, callback2);
FAIL();
}
catch (ros::ConflictingSubscriptionException&)
{
SUCCEED();
}
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "multiple_subscriptions");
ros::NodeHandle nh;
g_argc = argc;
g_argv = argv;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2009, Willow Garage, Inc.
* 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 the Willow Garage, Inc. 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.
*/
#include <ros/ros.h>
#include <gtest/gtest.h>
TEST(RemappingTest, remapping_test)
{
ros::NodeHandle nh;
ASSERT_EQ(ros::this_node::getName(), "/NAME");
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "remapping_tester");
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,103 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
/*
* Test name remapping. Assumes the parameter "test" is remapped to "test_remap", and the node name is remapped to "name_remapped"
*/
#include <string>
#include <sstream>
#include <fstream>
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include <ros/param.h>
#include <ros/names.h>
TEST(roscpp, parameterRemapping)
{
std::string param;
ASSERT_TRUE(ros::param::get("mapfrom", param));
ASSERT_STREQ(ros::names::resolve("mapfrom").c_str(), "/mapto");
ASSERT_TRUE(ros::param::get("/mapto", param));
ASSERT_STREQ(ros::names::resolve("/mapfrom").c_str(), "/mapto");
}
TEST(roscpp, nodeNameRemapping)
{
std::string node_name = ros::this_node::getName();
ASSERT_STREQ(node_name.c_str(), "/name_remapped");
}
TEST(roscpp, cleanName)
{
ASSERT_STREQ(ros::names::clean("////asdf///").c_str(), "/asdf");
ASSERT_STREQ(ros::names::clean("////asdf///jioweioj").c_str(), "/asdf/jioweioj");
ASSERT_STREQ(ros::names::clean("////asdf///jioweioj/").c_str(), "/asdf/jioweioj");
}
TEST(RoscppHandles, nodeHandleNameRemapping)
{
ros::M_string remap;
remap["a"] = "b";
remap["/a/a"] = "/a/b";
remap["c"] = "/a/c";
remap["d/d"] = "/c/e";
remap["d/e"] = "c/f";
ros::NodeHandle n("", remap);
EXPECT_STREQ(n.resolveName("a").c_str(), "/b");
EXPECT_STREQ(n.resolveName("/a/a").c_str(), "/a/b");
EXPECT_STREQ(n.resolveName("c").c_str(), "/a/c");
EXPECT_STREQ(n.resolveName("d/d").c_str(), "/c/e");
ros::NodeHandle n2("z", remap);
EXPECT_STREQ(n2.resolveName("a").c_str(), "/z/b");
EXPECT_STREQ(n2.resolveName("/a/a").c_str(), "/a/b");
EXPECT_STREQ(n2.resolveName("c").c_str(), "/a/c");
EXPECT_STREQ(n2.resolveName("d/d").c_str(), "/c/e");
EXPECT_STREQ(n2.resolveName("d/e").c_str(), "/z/c/f");
}
int
main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init( argc, argv, "name_remapping" );
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
/*
* Test name remapping. Assumes the parameter "test" is remapped to "test_remap", and the node name is remapped to "name_remapped"
*/
#include <string>
#include <sstream>
#include <fstream>
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include <ros/param.h>
#include <ros/names.h>
TEST(roscpp, parameterRemapping)
{
std::string param;
ASSERT_STREQ(ros::names::resolve("test_full").c_str(), "/b/test_full");
ASSERT_TRUE(ros::param::get("test_full", param));
ASSERT_STREQ(ros::names::resolve("/a/test_full").c_str(), "/b/test_full");
ASSERT_TRUE(ros::param::get("/a/test_full", param));
ASSERT_STREQ(ros::names::resolve("test_local").c_str(), "/a/test_local2");
ASSERT_TRUE(ros::param::get("test_local", param));
ASSERT_STREQ(ros::names::resolve("/a/test_local").c_str(), "/a/test_local2");
ASSERT_TRUE(ros::param::get("/a/test_local", param));
ASSERT_STREQ(ros::names::resolve("test_relative").c_str(), "/b/test_relative");
ASSERT_TRUE(ros::param::get("test_relative", param));
ASSERT_STREQ(ros::names::resolve("/a/test_relative").c_str(), "/b/test_relative");
ASSERT_TRUE(ros::param::get("/a/test_relative", param));
}
TEST(roscpp, nodeNameRemapping)
{
std::string node_name = ros::this_node::getName();
ASSERT_STREQ(node_name.c_str(), "/a/name_remapped_with_ns");
}
int
main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init( argc, argv, "name_remapping_with_ns" );
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
/*
* Test namespaces
*/
#include <string>
#include <sstream>
#include <fstream>
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include <ros/ros.h>
#include <ros/param.h>
TEST(namespaces, param)
{
std::string param;
ASSERT_TRUE( ros::param::get( "parent", param ) );
ROS_INFO("parent=%s", param.c_str());
ASSERT_EQ(param, ":ROS_NAMESPACE:parent");
}
TEST(namespaces, localParam)
{
std::string param;
ASSERT_TRUE( ros::param::get( "~/local", param ) );
ROS_INFO("~/local=%s", param.c_str());
ASSERT_EQ(param, ":ROS_NAMESPACE:NODE_NAME:local");
ros::NodeHandle n("~");
std::string param2;
n.param<std::string>("local", param2, param);
ASSERT_STREQ(param2.c_str(), param.c_str());
ASSERT_STREQ(param2.c_str(), ":ROS_NAMESPACE:NODE_NAME:local");
}
TEST(namespaces, globalParam)
{
std::string param;
ASSERT_TRUE( ros::param::get( "/global", param ) );
ASSERT_EQ(param, ":global");
}
TEST(namespaces, otherNamespaceParam)
{
std::string param;
ASSERT_TRUE( ros::param::get( "/other_namespace/param", param ) );
ASSERT_EQ(param, ":other_namespace:param");
}
TEST(namespaces, name)
{
std::string name = ros::this_node::getName();
ASSERT_EQ(name, "/ROS_NAMESPACE/NODE_NAME");
std::string nspace = ros::this_node::getNamespace();
ASSERT_EQ(nspace, "/ROS_NAMESPACE");
}
int
main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init( argc, argv, "namespaces" );
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,144 @@
/*
* Copyright (c) 2010, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
/*
* Subscribe intraprocess, ensuring that no copy happens
*/
#include <string>
#include <gtest/gtest.h>
#include <stdlib.h>
#include "ros/ros.h"
#include "test_roscpp/TestEmpty.h"
struct ConstHelper
{
void callback(const test_roscpp::TestEmptyConstPtr& msg)
{
message_ = msg;
}
test_roscpp::TestEmptyConstPtr message_;
};
struct NonConstHelper
{
void callback(const test_roscpp::TestEmptyPtr& msg)
{
message_ = msg;
}
test_roscpp::TestEmptyPtr message_;
};
TEST(NonConstSubscriptions, oneNonConstSubscriber)
{
NonConstHelper h;
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("test", 0, &NonConstHelper::callback, &h);
ros::Publisher pub = nh.advertise<test_roscpp::TestEmpty>("test", 0);
test_roscpp::TestEmptyPtr msg(boost::make_shared<test_roscpp::TestEmpty>());
pub.publish(msg);
ros::spinOnce();
ASSERT_TRUE(h.message_);
EXPECT_EQ(h.message_, msg);
}
TEST(NonConstSubscriptions, oneConstOneNonConst)
{
NonConstHelper h;
ConstHelper h2;
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("test", 0, &NonConstHelper::callback, &h);
ros::Subscriber sub2 = nh.subscribe("test", 0, &ConstHelper::callback, &h2);
ros::Publisher pub = nh.advertise<test_roscpp::TestEmpty>("test", 0);
test_roscpp::TestEmptyPtr msg(boost::make_shared<test_roscpp::TestEmpty>());
pub.publish(msg);
ros::spinOnce();
ASSERT_TRUE(h.message_);
EXPECT_NE(h.message_, msg);
EXPECT_EQ(h2.message_, msg);
}
TEST(NonConstSubscriptions, twoNonConst)
{
NonConstHelper h;
NonConstHelper h2;
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("test", 0, &NonConstHelper::callback, &h);
ros::Subscriber sub2 = nh.subscribe("test", 0, &NonConstHelper::callback, &h2);
ros::Publisher pub = nh.advertise<test_roscpp::TestEmpty>("test", 0);
test_roscpp::TestEmptyPtr msg(boost::make_shared<test_roscpp::TestEmpty>());
pub.publish(msg);
ros::spinOnce();
ASSERT_TRUE(h.message_);
EXPECT_NE(h.message_, msg);
}
TEST(NonConstSubscriptions, twoConst)
{
ConstHelper h;
ConstHelper h2;
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("test", 0, &ConstHelper::callback, &h);
ros::Subscriber sub2 = nh.subscribe("test", 0, &ConstHelper::callback, &h2);
ros::Publisher pub = nh.advertise<test_roscpp::TestEmpty>("test", 0);
test_roscpp::TestEmptyPtr msg(boost::make_shared<test_roscpp::TestEmpty>());
pub.publish(msg);
ros::spinOnce();
ASSERT_TRUE(h.message_);
EXPECT_EQ(h.message_, msg);
EXPECT_EQ(h2.message_, msg);
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "intraprocess_subscriptions");
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,81 @@
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2010, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
********************************************************************/
#include "ros/ros.h"
#include <locale.h>
#include <gtest/gtest.h>
TEST(Locale, push_pop)
{
int argc = 0;
char argv[1][255] = { "string" };
ros::init(argc, (char**)argv, "locale_push_pop");
ros::NodeHandle nh;
ROS_INFO("locale is %s", setlocale(LC_NUMERIC, 0));
// this test only works on machines that have de_DE installed
if (!setlocale(LC_NUMERIC, "de_DE.utf8"))
{
ROS_WARN("unable to set locale to de_DE.utf8, skipping test");
return;
}
ROS_INFO("locale now %s", setlocale(LC_NUMERIC, 0));
for(unsigned j=0; ros::ok() && j < 5; ++j)
{
ROS_INFO("setting parameters...");
double set = 123.45;
nh.setParam("V", set);
double got;
if (nh.getParam("V", got))
{
ROS_INFO("got pi=%3f <- should have commas in it", got);
ASSERT_EQ(set, got);
} else {
FAIL();
}
ros::WallDuration(0.1).sleep();
}
}
int
main(int argc, char** argv)
{
ros::init(argc, argv, "locale_push_pop");
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,66 @@
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
********************************************************************/
#include "ros/ros.h"
int main(int argc, char** argv)
{
ros::init(argc, argv, "param_update_test");
ros::NodeHandle nh;
while (ros::ok())
{
ROS_INFO("getting parameters...");
int i = -1;
if (nh.getParamCached("test", i))
{
ROS_INFO("test=%d", i);
}
if (nh.getParamCached("test2", i))
{
ROS_INFO("test2=%d", i);
}
if (nh.getParamCached("test3", i))
{
ROS_INFO("test3=%d", i);
}
ros::WallDuration(0.1).sleep();
}
return 0;
}

View File

@@ -0,0 +1,113 @@
/*
* Copyright (c) 2010, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
#include <gtest/gtest.h>
#include <ros/ros.h>
#include <test_roscpp/TestEmpty.h>
#define ASSERT_THROWS(expr) \
try \
{ \
expr; \
FAIL(); \
} \
catch (std::exception& e) \
{ \
ROS_INFO("Caught exception: %s", e.what());\
}
void callback(const test_roscpp::TestEmptyConstPtr&)
{
}
TEST(ParameterValidation, subscribeEmptyMD5Sum)
{
ros::NodeHandle nh;
ros::SubscribeOptions ops;
ops.init<test_roscpp::TestEmpty>("blah", 0, callback);
ops.md5sum.clear();
ASSERT_THROWS(nh.subscribe(ops));
}
TEST(ParameterValidation, subscribeEmptyDataType)
{
ros::NodeHandle nh;
ros::SubscribeOptions ops;
ops.init<test_roscpp::TestEmpty>("blah", 0, callback);
ops.datatype.clear();
ASSERT_THROWS(nh.subscribe(ops));
}
TEST(ParameterValidation, subscribeNoCallback)
{
ros::NodeHandle nh;
ros::SubscribeOptions ops("blah", 0, "blah", "blah");
ASSERT_THROWS(nh.subscribe(ops));
}
TEST(ParameterValidation, advertiseEmptyMD5Sum)
{
ros::NodeHandle nh;
ros::AdvertiseOptions ops("blah", 0, "", "blah", "blah");
ASSERT_THROWS(nh.advertise(ops));
}
TEST(ParameterValidation, advertiseEmptyDataType)
{
ros::NodeHandle nh;
ros::AdvertiseOptions ops("blah", 0, "blah", "", "blah");
ASSERT_THROWS(nh.advertise(ops));
}
TEST(ParameterValidation, advertiseStarMD5Sum)
{
ros::NodeHandle nh;
ros::AdvertiseOptions ops("blah", 0, "*", "blah", "blah");
ASSERT_THROWS(nh.advertise(ops));
}
TEST(ParameterValidation, advertiseStarDataType)
{
ros::NodeHandle nh;
ros::AdvertiseOptions ops("blah", 0, "blah", "*", "blah");
ASSERT_THROWS(nh.advertise(ops));
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "parameter_validation");
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,577 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Josh Faust */
/*
* Test parameters
*/
#include <string>
#include <sstream>
#include <fstream>
#include <gtest/gtest.h>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include <ros/param.h>
using namespace ros;
TEST(Params, allParamTypes)
{
std::string string_param;
EXPECT_TRUE( param::get( "string", string_param ) );
EXPECT_TRUE( string_param == "test" );
int int_param = 0;
EXPECT_TRUE( param::get( "int", int_param ) );
EXPECT_TRUE( int_param == 10 );
double double_param = 0.0;
EXPECT_TRUE( param::get( "double", double_param ) );
EXPECT_DOUBLE_EQ( double_param, 10.5 );
bool bool_param = true;
EXPECT_TRUE( param::get( "bool", bool_param ) );
EXPECT_FALSE( bool_param );
}
TEST(Params, setThenGetString)
{
param::set( "test_set_param", std::string("asdf") );
std::string param;
ASSERT_TRUE( param::get( "test_set_param", param ) );
ASSERT_STREQ( "asdf", param.c_str() );
XmlRpc::XmlRpcValue v;
param::get("test_set_param", v);
ASSERT_EQ(v.getType(), XmlRpc::XmlRpcValue::TypeString);
}
TEST(Params, setThenGetStringCached)
{
std::string param;
ASSERT_FALSE( param::getCached( "test_set_param_setThenGetStringCached", param) );
param::set( "test_set_param_setThenGetStringCached", std::string("asdf") );
ASSERT_TRUE( param::getCached( "test_set_param_setThenGetStringCached", param) );
ASSERT_STREQ( "asdf", param.c_str() );
}
TEST(Params, setThenGetStringCachedNodeHandle)
{
NodeHandle nh;
std::string param;
ASSERT_FALSE( nh.getParamCached( "test_set_param_setThenGetStringCachedNodeHandle", param) );
nh.setParam( "test_set_param_setThenGetStringCachedNodeHandle", std::string("asdf") );
ASSERT_TRUE( nh.getParamCached( "test_set_param_setThenGetStringCachedNodeHandle", param) );
ASSERT_STREQ( "asdf", param.c_str() );
}
TEST(Params, setThenGetNamespaceCached)
{
std::string stringParam;
XmlRpc::XmlRpcValue structParam;
const std::string ns = "test_set_param_setThenGetStringCached2";
ASSERT_FALSE(param::getCached(ns, stringParam));
param::set(ns, std::string("a"));
ASSERT_TRUE(param::getCached(ns, stringParam));
ASSERT_STREQ("a", stringParam.c_str());
param::set(ns + "/foo", std::string("b"));
ASSERT_TRUE(param::getCached(ns + "/foo", stringParam));
ASSERT_STREQ("b", stringParam.c_str());
ASSERT_TRUE(param::getCached(ns, structParam));
ASSERT_TRUE(structParam.hasMember("foo"));
ASSERT_STREQ("b", static_cast<std::string>(structParam["foo"]).c_str());
}
TEST(Params, setThenGetCString)
{
param::set( "test_set_param", "asdf" );
std::string param;
ASSERT_TRUE( param::get( "test_set_param", param ) );
ASSERT_STREQ( "asdf", param.c_str() );
}
TEST(Params, setThenGetInt)
{
param::set( "test_set_param", 42);
int param;
ASSERT_TRUE( param::get( "test_set_param", param ) );
ASSERT_EQ( 42, param );
XmlRpc::XmlRpcValue v;
param::get("test_set_param", v);
ASSERT_EQ(v.getType(), XmlRpc::XmlRpcValue::TypeInt);
}
TEST(Params, unknownParam)
{
std::string param;
ASSERT_FALSE( param::get( "this_param_really_should_not_exist", param ) );
}
TEST(Params, deleteParam)
{
param::set( "test_delete_param", "asdf" );
param::del( "test_delete_param" );
std::string param;
ASSERT_FALSE( param::get( "test_delete_param", param ) );
}
TEST(Params, hasParam)
{
ASSERT_TRUE( param::has( "string" ) );
}
TEST(Params, setIntDoubleGetInt)
{
param::set("test_set_int_as_double", 1);
param::set("test_set_int_as_double", 3.0f);
int i = -1;
ASSERT_TRUE(param::get("test_set_int_as_double", i));
ASSERT_EQ(3, i);
double d = 0.0f;
ASSERT_TRUE(param::get("test_set_int_as_double", d));
ASSERT_EQ(3.0, d);
}
TEST(Params, getIntAsDouble)
{
param::set("int_param", 1);
double d = 0.0;
ASSERT_TRUE(param::get("int_param", d));
ASSERT_EQ(1.0, d);
}
TEST(Params, getDoubleAsInt)
{
param::set("double_param", 2.3);
int i = -1;
ASSERT_TRUE(param::get("double_param", i));
ASSERT_EQ(2, i);
param::set("double_param", 3.8);
i = -1;
ASSERT_TRUE(param::get("double_param", i));
ASSERT_EQ(4, i);
}
TEST(Params, searchParam)
{
std::string ns = "/a/b/c/d/e/f";
std::string result;
param::set("/s_i", 1);
ASSERT_TRUE(param::search(ns, "s_i", result));
ASSERT_STREQ(result.c_str(), "/s_i");
param::del("/s_i");
param::set("/a/b/s_i", 1);
ASSERT_TRUE(param::search(ns, "s_i", result));
ASSERT_STREQ(result.c_str(), "/a/b/s_i");
param::del("/a/b/s_i");
param::set("/a/b/c/d/e/f/s_i", 1);
ASSERT_TRUE(param::search(ns, "s_i", result));
ASSERT_STREQ(result.c_str(), "/a/b/c/d/e/f/s_i");
param::del("/a/b/c/d/e/f/s_i");
bool cont = true;
while (!cont)
{
ros::WallDuration(0.1).sleep();
}
ASSERT_FALSE(param::search(ns, "s_j", result));
}
TEST(Params, searchParamNodeHandle)
{
NodeHandle n("/a/b/c/d/e/f");
std::string result;
n.setParam("/s_i", 1);
ASSERT_TRUE(n.searchParam("s_i", result));
ASSERT_STREQ(result.c_str(), "/s_i");
n.deleteParam("/s_i");
n.setParam("/a/b/s_i", 1);
ASSERT_TRUE(n.searchParam("s_i", result));
ASSERT_STREQ(result.c_str(), "/a/b/s_i");
n.deleteParam("/a/b/s_i");
n.setParam("/a/b/c/d/e/f/s_i", 1);
ASSERT_TRUE(n.searchParam("s_i", result));
ASSERT_STREQ(result.c_str(), "/a/b/c/d/e/f/s_i");
n.deleteParam("/a/b/c/d/e/f/s_i");
ASSERT_FALSE(n.searchParam("s_j", result));
}
TEST(Params, searchParamNodeHandleWithRemapping)
{
M_string remappings;
remappings["s_c"] = "s_b";
NodeHandle n("/a/b/c/d/e/f", remappings);
std::string result;
n.setParam("/s_c", 1);
ASSERT_FALSE(n.searchParam("s_c", result));
n.setParam("/s_b", 1);
ASSERT_TRUE(n.searchParam("s_c", result));
}
// See ROS ticket #2381
TEST(Params, getMissingXmlRpcValueParameterCachedTwice)
{
XmlRpc::XmlRpcValue v;
ASSERT_FALSE(ros::param::getCached("invalid_xmlrpcvalue_param", v));
ASSERT_FALSE(ros::param::getCached("invalid_xmlrpcvalue_param", v));
}
// See ROS ticket #2353
TEST(Params, doublePrecision)
{
ros::param::set("bar", 0.123456789123456789);
double d;
ASSERT_TRUE(ros::param::get("bar", d));
EXPECT_DOUBLE_EQ(d, 0.12345678912345678);
}
std::vector<std::string> vec_s, vec_s2;
std::vector<double> vec_d, vec_d2;
std::vector<float> vec_f, vec_f2;
std::vector<int> vec_i, vec_i2;
std::vector<bool> vec_b, vec_b2;
TEST(Params, vectorStringParam)
{
const std::string param_name = "vec_str_param";
vec_s.clear();
vec_s.push_back("foo");
vec_s.push_back("bar");
vec_s.push_back("baz");
ros::param::set(param_name, vec_s);
ASSERT_FALSE(ros::param::get(param_name, vec_d));
ASSERT_FALSE(ros::param::get(param_name, vec_f));
ASSERT_FALSE(ros::param::get(param_name, vec_i));
ASSERT_FALSE(ros::param::get(param_name, vec_b));
ASSERT_TRUE(ros::param::get(param_name, vec_s2));
ASSERT_EQ(vec_s.size(), vec_s2.size());
ASSERT_TRUE(std::equal(vec_s.begin(), vec_s.end(), vec_s2.begin()));
// Test empty vector
vec_s.clear();
ros::param::set(param_name, vec_s);
ASSERT_TRUE(ros::param::get(param_name, vec_s2));
ASSERT_EQ(vec_s.size(), vec_s2.size());
}
TEST(Params, vectorDoubleParam)
{
const std::string param_name = "vec_double_param";
vec_d.clear();
vec_d.push_back(-0.123456789);
vec_d.push_back(3);
vec_d.push_back(3.01);
vec_d.push_back(7.01);
ros::param::set(param_name, vec_d);
ASSERT_FALSE(ros::param::get(param_name, vec_s));
ASSERT_TRUE(ros::param::get(param_name, vec_i));
ASSERT_TRUE(ros::param::get(param_name, vec_b));
ASSERT_TRUE(ros::param::get(param_name, vec_f));
ASSERT_TRUE(ros::param::get(param_name, vec_d2));
ASSERT_EQ(vec_d.size(), vec_d2.size());
ASSERT_TRUE(std::equal(vec_d.begin(), vec_d.end(), vec_d2.begin()));
}
TEST(Params, vectorFloatParam)
{
const std::string param_name = "vec_float_param";
vec_f.clear();
vec_f.push_back(-0.123456789);
vec_f.push_back(0.0);
vec_f.push_back(3);
vec_f.push_back(3.01);
ros::param::set(param_name, vec_f);
ASSERT_FALSE(ros::param::get(param_name, vec_s));
ASSERT_TRUE(ros::param::get(param_name, vec_i));
ASSERT_TRUE(ros::param::get(param_name, vec_b));
ASSERT_TRUE(ros::param::get(param_name, vec_d));
ASSERT_EQ(vec_b[0],true);
ASSERT_EQ(vec_b[1],false);
ASSERT_TRUE(ros::param::get(param_name, vec_f2));
ASSERT_EQ(vec_f.size(), vec_f2.size());
ASSERT_TRUE(std::equal(vec_f.begin(), vec_f.end(), vec_f2.begin()));
}
TEST(Params, vectorIntParam)
{
const std::string param_name = "vec_int_param";
vec_i.clear();
vec_i.push_back(-1);
vec_i.push_back(0);
vec_i.push_back(1337);
vec_i.push_back(2);
ros::param::set(param_name, vec_i);
ASSERT_FALSE(ros::param::get(param_name, vec_s));
ASSERT_TRUE(ros::param::get(param_name, vec_d));
ASSERT_TRUE(ros::param::get(param_name, vec_f));
ASSERT_TRUE(ros::param::get(param_name, vec_b));
ASSERT_EQ(vec_b[0],true);
ASSERT_EQ(vec_b[1],false);
ASSERT_TRUE(ros::param::get(param_name, vec_i2));
ASSERT_EQ(vec_i.size(), vec_i2.size());
ASSERT_TRUE(std::equal(vec_i.begin(), vec_i.end(), vec_i2.begin()));
}
TEST(Params, vectorBoolParam)
{
const std::string param_name = "vec_bool_param";
vec_b.clear();
vec_b.push_back(true);
vec_b.push_back(false);
vec_b.push_back(true);
vec_b.push_back(true);
ros::param::set(param_name, vec_b);
ASSERT_FALSE(ros::param::get(param_name, vec_s));
ASSERT_TRUE(ros::param::get(param_name, vec_d));
ASSERT_TRUE(ros::param::get(param_name, vec_f));
ASSERT_TRUE(ros::param::get(param_name, vec_i));
ASSERT_EQ(vec_i[0],1);
ASSERT_EQ(vec_i[1],0);
ASSERT_TRUE(ros::param::get(param_name, vec_b2));
ASSERT_EQ(vec_b.size(), vec_b2.size());
ASSERT_TRUE(std::equal(vec_b.begin(), vec_b.end(), vec_b2.begin()));
}
std::map<std::string,std::string> map_s, map_s2;
std::map<std::string,double> map_d, map_d2;
std::map<std::string,float> map_f, map_f2;
std::map<std::string,int> map_i, map_i2;
std::map<std::string,bool> map_b, map_b2;
TEST(Params, mapStringParam)
{
const std::string param_name = "map_str_param";
map_s.clear();
map_s["a"] = "apple";
map_s["b"] = "blueberry";
map_s["c"] = "carrot";
ros::param::set(param_name, map_s);
ASSERT_FALSE(ros::param::get(param_name, map_d));
ASSERT_FALSE(ros::param::get(param_name, map_f));
ASSERT_FALSE(ros::param::get(param_name, map_i));
ASSERT_FALSE(ros::param::get(param_name, map_b));
ASSERT_TRUE(ros::param::get(param_name, map_s2));
ASSERT_EQ(map_s.size(), map_s2.size());
ASSERT_TRUE(std::equal(map_s.begin(), map_s.end(), map_s2.begin()));
}
TEST(Params, mapDoubleParam)
{
const std::string param_name = "map_double_param";
map_d.clear();
map_d["a"] = 0.0;
map_d["b"] = -0.123456789;
map_d["c"] = 123456789;
ros::param::set(param_name, map_d);
ASSERT_FALSE(ros::param::get(param_name, map_s));
ASSERT_TRUE(ros::param::get(param_name, map_f));
ASSERT_TRUE(ros::param::get(param_name, map_i));
ASSERT_TRUE(ros::param::get(param_name, map_b));
ASSERT_TRUE(ros::param::get(param_name, map_d2));
ASSERT_EQ(map_d.size(), map_d2.size());
ASSERT_TRUE(std::equal(map_d.begin(), map_d.end(), map_d2.begin()));
}
TEST(Params, mapFloatParam)
{
const std::string param_name = "map_float_param";
map_f.clear();
map_f["a"] = 0.0;
map_f["b"] = -0.123456789;
map_f["c"] = 123456789;
ros::param::set(param_name, map_f);
ASSERT_FALSE(ros::param::get(param_name, map_s));
ASSERT_TRUE(ros::param::get(param_name, map_d));
ASSERT_TRUE(ros::param::get(param_name, map_i));
ASSERT_TRUE(ros::param::get(param_name, map_b));
ASSERT_TRUE(ros::param::get(param_name, map_f2));
ASSERT_EQ(map_f.size(), map_f2.size());
ASSERT_TRUE(std::equal(map_f.begin(), map_f.end(), map_f2.begin()));
}
TEST(Params, mapIntParam)
{
const std::string param_name = "map_int_param";
map_i.clear();
map_i["a"] = 0;
map_i["b"] = -1;
map_i["c"] = 1337;
ros::param::set(param_name, map_i);
ASSERT_FALSE(ros::param::get(param_name, map_s));
ASSERT_TRUE(ros::param::get(param_name, map_d));
ASSERT_TRUE(ros::param::get(param_name, map_f));
ASSERT_TRUE(ros::param::get(param_name, map_b));
ASSERT_TRUE(ros::param::get(param_name, map_i2));
ASSERT_EQ(map_i.size(), map_i2.size());
ASSERT_TRUE(std::equal(map_i.begin(), map_i.end(), map_i2.begin()));
}
TEST(Params, mapBoolParam)
{
const std::string param_name = "map_bool_param";
map_b.clear();
map_b["a"] = true;
map_b["b"] = false;
map_b["c"] = true;
ros::param::set(param_name, map_b);
ASSERT_FALSE(ros::param::get(param_name, map_s));
ASSERT_TRUE(ros::param::get(param_name, map_d));
ASSERT_TRUE(ros::param::get(param_name, map_f));
ASSERT_TRUE(ros::param::get(param_name, map_i));
ASSERT_EQ(map_i["a"],1);
ASSERT_EQ(map_i["b"],0);
ASSERT_TRUE(ros::param::get(param_name, map_b2));
ASSERT_EQ(map_b.size(), map_b2.size());
ASSERT_TRUE(std::equal(map_b.begin(), map_b.end(), map_b2.begin()));
}
TEST(Params, paramTemplateFunction)
{
EXPECT_EQ( param::param<std::string>( "string", "" ), "test" );
EXPECT_EQ( param::param<std::string>( "gnirts", "test" ), "test" );
EXPECT_EQ( param::param<int>( "int", 0 ), 10 );
EXPECT_EQ( param::param<int>( "tni", 10 ), 10 );
EXPECT_DOUBLE_EQ( param::param<double>( "double", 0.0 ), 10.5 );
EXPECT_DOUBLE_EQ( param::param<double>( "elbuod", 10.5 ), 10.5 );
EXPECT_EQ( param::param<bool>( "bool", true ), false );
EXPECT_EQ( param::param<bool>( "loob", true ), true );
}
TEST(Params, paramNodeHandleTemplateFunction)
{
NodeHandle nh;
EXPECT_EQ( nh.param<std::string>( "string", "" ), "test" );
EXPECT_EQ( nh.param<std::string>( "gnirts", "test" ), "test" );
EXPECT_EQ( nh.param<int>( "int", 0 ), 10 );
EXPECT_EQ( nh.param<int>( "tni", 10 ), 10 );
EXPECT_DOUBLE_EQ( nh.param<double>( "double", 0.0 ), 10.5 );
EXPECT_DOUBLE_EQ( nh.param<double>( "elbuod", 10.5 ), 10.5 );
EXPECT_EQ( nh.param<bool>( "bool", true ), false );
EXPECT_EQ( nh.param<bool>( "loob", true ), true );
}
TEST(Params, getParamNames) {
std::vector<std::string> test_params;
EXPECT_TRUE(ros::param::getParamNames(test_params));
EXPECT_LT(10, test_params.size());
}
int
main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init( argc, argv, "params" );
// ros::NodeHandle nh;
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Brian Gerkey */
/*
* Publish a message N times, back to back
*/
#include <string>
#include <cstdio>
#include <time.h>
#include <stdlib.h>
#include "ros/ros.h"
#include <test_roscpp/TestArray.h>
int32_t g_array_size = 1;
void messageCallback(const test_roscpp::TestArrayConstPtr& msg, ros::Publisher pub)
{
test_roscpp::TestArray copy = *msg;
copy.counter++;
while (ros::ok() && pub.getNumSubscribers() == 0)
{
ros::Duration(0.01).sleep();
}
pub.publish(copy);
}
#define USAGE "USAGE: publish_n_fast <sz>"
int main(int argc, char** argv)
{
ros::init(argc, argv, "pub_sub");
if(argc != 2)
{
puts(USAGE);
exit(-1);
}
g_array_size = atoi(argv[1]);
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise<test_roscpp::TestArray>("roscpp/pubsub_test", 1);
ros::Subscriber sub = nh.subscribe<test_roscpp::TestArray>("roscpp/subpub_test", 1, boost::bind(messageCallback, _1, pub));
ros::spin();
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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.
*/
/* Author: Brian Gerkey */
#include <time.h>
#include "ros/ros.h"
#include "test_roscpp/TestArray.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "publish_constantly");
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise<test_roscpp::TestArray>("roscpp/pubsub_test", 100);
test_roscpp::TestArray msg;
msg.float_arr.resize(100);
ros::WallDuration d(0.01);
while(ros::ok())
{
d.sleep();
pub.publish(msg);
}
return 0;
}

Some files were not shown because too many files have changed in this diff Show More