test_state_machine.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 <LeicaStateMachine.h>
22 
23 typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloudRGB;
24 
25 class TestStateMachine : public ::testing::Test
26 {
27 protected:
28 
29  PointCloudRGB::Ptr cloudRGB {new PointCloudRGB};
30 
32  cubePointCloud(cloudRGB, 1, 10000);
33  }
34 
35  void cubePointCloud(PointCloudRGB::Ptr cloud, float dim, int nsamples){
36  pcl::PointXYZRGB p_rgb;
37  for(int i=0; i<nsamples; i++)
38  {
39  p_rgb.x = dim * (double)std::rand() / (double)RAND_MAX;
40  p_rgb.y = dim * (double)std::rand() / (double)RAND_MAX;
41  p_rgb.z = dim * (double)std::rand() / (double)RAND_MAX;
42  p_rgb.r = 255;
43  p_rgb.g = 255;
44  p_rgb.b = 255;
45  cloud->push_back(p_rgb);
46  }
47  }
48 };
49 
50 // Test state machine
52 {
53  ros::NodeHandle nh;
54  PointCloudRGB::Ptr source_cloud = cloudRGB;
55  PointCloudRGB::Ptr target_cloud = cloudRGB;
56 
57  if (Utils::isValidCloud(source_cloud) && Utils::isValidCloud(target_cloud))
58  {
59  std::shared_ptr<StateMachine> FSM = std::make_shared<StateMachine>(source_cloud, target_cloud, nh);
60  FSM->initiate();
61  try
62  {
63  FSM->state_cast<const IdleState &>();
64  }
65  catch(std::exception& e)
66  {
67  ADD_FAILURE() << "Not in IdleState";
68  }
69 
70  FSM->process_event(StartEvent());
71  try
72  {
73  FSM->state_cast<const PublishState &>();
74  }
75  catch(std::exception& e)
76  {
77  ADD_FAILURE() << "Transit to PublishState failed";
78  }
79  }
80 }
81 
82 int main(int argc,char **argv)
83 {
84  ros::init(argc, argv, "test_state_machine");
85  testing::InitGoogleTest(&argc, argv);
86  return RUN_ALL_TESTS();
87 }
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
static bool isValidCloud(PointCloudXYZ::Ptr cloud)
Check whether cloud contains data and is not empty.
Definition: Utils.cpp:46
TEST_F(TestStateMachine, testEvents)
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
PointCloudRGB::Ptr cloudRGB
void cubePointCloud(PointCloudRGB::Ptr cloud, float dim, int nsamples)


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