test/service.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include <ros1_template_msgs/Answer.h>
4 #include <std_msgs/Int32.h>
5 #include <ros/service.h>
6 #include <ros/service_client.h>
7 #include <ros/node_handle.h>
8 
9 #include <atomic>
10 #include <iostream>
11 #include <string>
12 
13 TEST(Service, call)
14 {
15  ros::NodeHandle node_handle;
16 
17  std::string service_name = "fibonacci_service";
18  std::string full_service_name = node_handle.resolveName(service_name);
19  bool service_is_up = ros::service::waitForService(full_service_name);
20  EXPECT_TRUE(service_is_up);
21 
22  bool persistent_service = true;
23  ros::ServiceClient service_client = node_handle.serviceClient<ros1_template_msgs::Answer>(
24  service_name, persistent_service);
25 
26  EXPECT_TRUE(service_client.isValid());
27 
28  ros1_template_msgs::Answer service;
29  bool call_successful = service_client.call(service);
30  EXPECT_TRUE(call_successful);
31 }
32 
33 int main(int argc, char **argv)
34 {
35  testing::InitGoogleTest(&argc, argv);
36  int time_seed = static_cast<int>(time(0));
37  srand(time_seed);
38 
39  ros::init(argc, argv, "service");
40 
41  return RUN_ALL_TESTS();
42 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
int main(int argc, char **argv)
std::string resolveName(const std::string &name, bool remap=true) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
TEST(Service, call)
bool isValid() const
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)


ros1_ros_cpptemplate
Author(s): Alexander Reimann
autogenerated on Sat Sep 2 2017 02:38:06