test_publish_clouds.cpp
Go to the documentation of this file.
1 
18 #include <ros/ros.h>
19 #include <gtest/gtest.h>
20 #include "Utils.h"
21 #include "leica_scanstation_utils/LeicaUtils.h"
22 #include "leica_scanstation_msgs/PointCloudFile.h"
23 #include "sensor_msgs/PointCloud2.h"
24 
25 typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloudRGB;
26 
27 // Test call PointCloudFile service in load_and_publish_clouds node, it should return success
28 TEST(TestNode, testService)
29 {
30  ros::NodeHandle nh;
31  ros::ServiceClient client;
32  client = nh.serviceClient<leica_scanstation_msgs::PointCloudFile>("publish_clouds");
33  bool exists = client.waitForExistence(ros::Duration(1));
34  ASSERT_TRUE(exists);
35 
36  leica_scanstation_msgs::PointCloudFile srv;
37  srv.request.source_cloud_file = "scan.pcd";
38  srv.request.target_cloud_file = "cad.ply";
39 
40  if(client.call(srv)){
41  ASSERT_TRUE(srv.response.success);
42  }
43  else ADD_FAILURE()<< "Failed to call service";
44 }
45 
46 // Test call PointCloudFile service in load_and_publish_clouds node, it should return fail
47 TEST(TestNode, testServiceFail)
48 {
49  ros::NodeHandle nh;
50  ros::ServiceClient client;
51  client = nh.serviceClient<leica_scanstation_msgs::PointCloudFile>("publish_clouds");
52  bool exists = client.waitForExistence(ros::Duration(1));
53  ASSERT_TRUE(exists);
54 
55  leica_scanstation_msgs::PointCloudFile srv;
56  srv.request.source_cloud_file = "scan"; // file names without extension
57  srv.request.target_cloud_file = "cad"; // service should fail
58 
59  if(client.call(srv)){
60  ADD_FAILURE() << "Service doesn't work as expected";
61  }
62  else SUCCEED();
63 }
64 
65 // Test load_and_publish_clouds node is publishing point_clouds
66 TEST(TestNode, testTopics)
67 {
68  sensor_msgs::PointCloud2ConstPtr cloud_msg;
69  cloud_msg = ros::topic::waitForMessage<sensor_msgs::PointCloud2>(SOURCE_CLOUD_TOPIC);
70  EXPECT_TRUE(Utils::isValidCloudMsg(*cloud_msg));
71 
72  cloud_msg = ros::topic::waitForMessage<sensor_msgs::PointCloud2>(TARGET_CLOUD_TOPIC);
73  EXPECT_TRUE(Utils::isValidCloudMsg(*cloud_msg));
74 }
75 
76 int main(int argc,char **argv)
77 {
78  ros::init(argc, argv, "test_publish_clouds");
79  testing::InitGoogleTest(&argc, argv);
80  return RUN_ALL_TESTS();
81 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
const std::string SOURCE_CLOUD_TOPIC
Definition: Utils.cpp:25
TEST(TestNode, testService)
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
const std::string TARGET_CLOUD_TOPIC
Definition: Utils.cpp:24
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
int SUCCEED
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
static bool isValidCloudMsg(const sensor_msgs::PointCloud2 &cloud_msg)
Check whether PointCloud2 contains data and is not empty.
Definition: Utils.cpp:66


leica_point_cloud_processing
Author(s): Ines Lara Sicilia
autogenerated on Fri Feb 5 2021 03:20:30