12 #include <std_msgs/typekit/String.h> 13 #include <std_srvs/Empty.h> 19 #include <boost/weak_ptr.hpp> 21 #include <gtest/gtest.h> 25 TEST(TransportTest, OutOfBandTest)
48 EXPECT_TRUE(std::find(advertised_topics.begin(), advertised_topics.end(),
49 topic) != advertised_topics.end());
51 EXPECT_TRUE(std::find(subscribed_topics.begin(), subscribed_topics.end(),
52 topic) != subscribed_topics.end());
55 std_msgs::String sample;
56 sample.data =
"Hello world!";
63 EXPECT_EQ(sample.data, received);
72 advertised_topics.clear();
73 subscribed_topics.clear();
75 EXPECT_FALSE(std::find(advertised_topics.begin(), advertised_topics.end(),
76 topic) != advertised_topics.end());
78 EXPECT_FALSE(std::find(subscribed_topics.begin(), subscribed_topics.end(),
79 topic) != subscribed_topics.end());
82 TEST(TransportTest, VectorTest)
100 static const double sample_array[] = { 1., 2., 3., 4., 5. };
101 std::vector<double> sample(sample_array, sample_array +
sizeof(sample_array)/
sizeof(sample_array[0]));
106 std::vector<double> received;
108 EXPECT_EQ(sample.size(), received.size());
109 if (sample.size() == received.size()) {
110 EXPECT_TRUE(std::equal(received.begin(), received.end(), sample.begin()));
121 bool callback0(std_srvs::Empty::Request&, std_srvs::Empty::Response&)
138 TEST(TransportTest, ServiceServerTest)
154 boost::weak_ptr<rtt_rosservice::ROSService> rosservice;
155 rosservice = tc->
getProvider<rtt_rosservice::ROSService>(
"rosservice");
156 ASSERT_FALSE(rosservice.expired());
159 EXPECT_TRUE(rosservice.lock()->connect(
"empty0", service +
"0",
"std_srvs/Empty"));
160 EXPECT_TRUE(rosservice.lock()->connect(
"empty1", service +
"1",
"std_srvs/Empty"));
161 EXPECT_TRUE(rosservice.lock()->connect(
"empty2", service +
"2",
"std_srvs/Empty"));
172 tc->
requires()->addOperationCaller(service_caller0);
173 tc->
requires()->addOperationCaller(service_caller1);
174 tc->
requires()->addOperationCaller(service_caller2);
175 EXPECT_TRUE(rosservice.lock()->connect(
"empty0", service +
"0",
"std_srvs/Empty"));
176 EXPECT_TRUE(service_caller0.
ready());
177 EXPECT_TRUE(rosservice.lock()->connect(
"empty1", service +
"1",
"std_srvs/Empty"));
178 EXPECT_TRUE(service_caller1.
ready());
179 EXPECT_TRUE(rosservice.lock()->connect(
"empty2", service +
"2",
"std_srvs/Empty"));
180 EXPECT_TRUE(service_caller2.
ready());
184 std_srvs::Empty empty;
185 EXPECT_TRUE(service_caller0(empty.request, empty.response));
187 EXPECT_TRUE(service_caller1(empty.request, empty.response));
189 EXPECT_TRUE(service_caller2(empty.request, empty.response));
193 EXPECT_TRUE(rosservice.lock()->disconnect(service +
"0"));
194 EXPECT_TRUE(rosservice.lock()->disconnect(service +
"1"));
195 EXPECT_TRUE(rosservice.lock()->disconnect(service +
"2"));
202 EXPECT_TRUE(rosservice.expired());
208 int main(
int argc,
char** argv) {
209 testing::InitGoogleTest(&argc, argv);
218 return RUN_ALL_TESTS();
RTT::ConnPolicy topicLatched(const std::string &name)
int __os_init(int argc, char **argv)
int usleep(unsigned int us)
static int callback_called
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
int main(int argc, char **argv)
static boost::shared_ptr< ComponentLoader > Instance()
RTT::ConnPolicy topic(const std::string &name)
static const ServiceManagerPtr & instance()
TEST(TransportTest, OutOfBandTest)
std::vector< std::string > V_string
ServiceRequester::shared_ptr requires()
ROSCPP_DECL void getSubscribedTopics(V_string &topics)
void mayLogStdOut(bool tf)
virtual bool createStream(ConnPolicy const &policy)
virtual bool connectTo(PortInterface *other, ConnPolicy const &policy)
WriteStatus write(const T &sample)
bool callback0(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
virtual bool connected() const
virtual void disconnect()
ROSCPP_DECL void getAdvertisedTopics(V_string &topics)
void setStdStream(std::ostream &stdos)
Operation< Signature > & addOperation(Operation< Signature > &op)
void setLogLevel(LogLevel ll)
boost::shared_ptr< ServiceType > getProvider(const std::string &name)