Go to the documentation of this file.00001 #include <gtest/gtest.h>
00002
00003 #include <ros1_template_msgs/Answer.h>
00004 #include <std_msgs/Int32.h>
00005 #include <ros/service.h>
00006 #include <ros/service_client.h>
00007 #include <ros/node_handle.h>
00008
00009 #include <atomic>
00010 #include <iostream>
00011 #include <string>
00012
00013 TEST(Service, call)
00014 {
00015 ros::NodeHandle node_handle;
00016
00017 std::string service_name = "fibonacci_service";
00018 std::string full_service_name = node_handle.resolveName(service_name);
00019 bool service_is_up = ros::service::waitForService(full_service_name);
00020 EXPECT_TRUE(service_is_up);
00021
00022 bool persistent_service = true;
00023 ros::ServiceClient service_client = node_handle.serviceClient<ros1_template_msgs::Answer>(
00024 service_name, persistent_service);
00025
00026 EXPECT_TRUE(service_client.isValid());
00027
00028 ros1_template_msgs::Answer service;
00029 bool call_successful = service_client.call(service);
00030 EXPECT_TRUE(call_successful);
00031 }
00032
00033 int main(int argc, char **argv)
00034 {
00035 testing::InitGoogleTest(&argc, argv);
00036 int time_seed = static_cast<int>(time(0));
00037 srand(time_seed);
00038
00039 ros::init(argc, argv, "service");
00040
00041 return RUN_ALL_TESTS();
00042 }