trajectory_info_test.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <ros/package.h>
3 
4 #include <unique_id/unique_id.h>
5 
6 #include <ram_msgs/AdditiveManufacturingTrajectory.h>
7 
8 #include <ram_utils/GetTrajectorySize.h>
9 #include <ram_utils/GetNumberOfLayersLevels.h>
10 #include <ram_utils/GetLayerSize.h>
11 
12 #include <gtest/gtest.h>
13 
14 std::unique_ptr<ros::NodeHandle> nh;
16 ram_msgs::AdditiveManufacturingTrajectory trajectory;
17 
18 // Pose selector services
22 
23 TEST(TestSuite, testSrvsExistence)
24 {
25  get_trajectory_size_client = nh->serviceClient<ram_utils::GetTrajectorySize>("ram/information/get_trajectory_size");
26  bool exists_1(get_trajectory_size_client.waitForExistence(ros::Duration(1)));
27  EXPECT_TRUE(exists_1);
28 
29  get_number_of_layers_levels_client = nh->serviceClient<ram_utils::GetNumberOfLayersLevels>(
30  "ram/information/get_number_of_layers_levels");
31  bool exists_2(get_number_of_layers_levels_client.waitForExistence(ros::Duration(1)));
32  EXPECT_TRUE(exists_2);
33 
34  get_layer_size_client = nh->serviceClient<ram_utils::GetLayerSize>("ram/information/get_layer_size");
35  bool exists_3(get_layer_size_client.waitForExistence(ros::Duration(1)));
36  EXPECT_TRUE(exists_3);
37 }
38 
39 TEST(TestSuite, selectPosesInEmptyTrajectory)
40 {
41  // Publish empty trajectory
42  trajectory.poses.clear();
43  ros::Time timestamp = ros::Time::now();
44  trajectory.generated = timestamp;
45  trajectory.modified = timestamp;
46  test_trajectory_pub.publish(trajectory);
47 
48  ram_utils::GetTrajectorySize get_trajectory_size_srv;
49  get_trajectory_size_client.call(get_trajectory_size_srv);
50  bool success_1 = (get_trajectory_size_srv.response.trajectory_size != 0) ? true : false;
51  EXPECT_FALSE(success_1);
52 
53  ram_utils::GetNumberOfLayersLevels get_number_of_layers_srv;
54  bool success_2(get_number_of_layers_levels_client.call(get_number_of_layers_srv));
55  EXPECT_FALSE(success_2);
56 
57  ram_utils::GetLayerSize get_layer_size_srv;
58  bool success_3(get_layer_size_client.call(get_layer_size_srv));
59  EXPECT_FALSE(success_3);
60 }
61 
62 TEST(TestSuite, getTrajectorySize)
63 {
64  trajectory.poses.clear();
65  // 3 layers. 1 pose in the first layer, 2 poses in the second, etc.
66  for (int i(0); i < 3; ++i)
67  {
68  for (int j(0); j <= i; ++j)
69  {
70  ram_msgs::AdditiveManufacturingPose pose;
71  pose.layer_level = i;
72  pose.unique_id = unique_id::toMsg(unique_id::fromRandom());
73  trajectory.poses.push_back(pose);
74  }
75  }
76  ros::Time timestamp = ros::Time::now();
77  trajectory.generated = timestamp;
78  trajectory.modified = timestamp;
79  test_trajectory_pub.publish(trajectory);
80 
81  ram_utils::GetTrajectorySize srv;
82  bool success(get_trajectory_size_client.call(srv));
83  bool response = (srv.response.trajectory_size == 6) ? true : false;
84  EXPECT_TRUE(success && response);
85 }
86 
87 TEST(TestSuite, numberOfLayersLevels)
88 {
89  ram_utils::GetNumberOfLayersLevels srv;
90  get_number_of_layers_levels_client.call(srv);
91  bool success(get_number_of_layers_levels_client.call(srv));
92  bool response = (srv.response.number_of_layers == 3) ? true : false;
93 
94  EXPECT_TRUE(success && response);
95 }
96 
97 TEST(TestSuite, layerSize)
98 {
99  ram_utils::GetLayerSize srv;
100  srv.request.layer_level = 2;
101  get_layer_size_client.call(srv);
102  bool success(get_layer_size_client.call(srv));
103  bool response = (srv.response.layer_size == 3) ? true : false;
104 
105  EXPECT_TRUE(success && response);
106 }
107 
108 int main(int argc,
109  char **argv)
110 {
111  ros::init(argc, argv, "ram_utils_trajectory_info_test");
112  nh.reset(new ros::NodeHandle);
113 
114  test_trajectory_pub = nh->advertise<ram_msgs::AdditiveManufacturingTrajectory>("ram/trajectory", 10, true);
115 
116  // Make sure we have at least one subscriber to this topic
117  while (test_trajectory_pub.getNumSubscribers() != 1)
118  {
119  ROS_WARN_STREAM_THROTTLE(1, test_trajectory_pub.getTopic() + " has zero subscriber, waiting...");
120  ros::Duration(0.1).sleep();
121  }
122 
123  testing::InitGoogleTest(&argc, argv);
124  return RUN_ALL_TESTS();
125 }
static boost::uuids::uuid fromRandom(void)
ros::Publisher test_trajectory_pub
void publish(const boost::shared_ptr< M > &message) const
ros::ServiceClient get_trajectory_size_client
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
ram_msgs::AdditiveManufacturingTrajectory trajectory
ros::ServiceClient get_number_of_layers_levels_client
int main(int argc, char **argv)
std::unique_ptr< ros::NodeHandle > nh
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
ros::ServiceClient get_layer_size_client
TEST(TestSuite, testSrvsExistence)
#define ROS_WARN_STREAM_THROTTLE(rate, args)
uint32_t getNumSubscribers() const
static Time now()
static uuid_msgs::UniqueID toMsg(boost::uuids::uuid const &uu)
std::string getTopic() const


ram_utils
Author(s): Victor Lamoine - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:49:54