scenario_simulator_v2 C++ API
expect_equal_macros.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SIMULATION_INTERFACE__TEST__EXPECT_EQUAL_MACROS_HPP_
16 #define SIMULATION_INTERFACE__TEST__EXPECT_EQUAL_MACROS_HPP_
17 
18 #include <geometry_msgs.pb.h>
19 #include <gtest/gtest.h>
20 
21 #include <geometry_msgs/msg/accel.hpp>
22 #include <geometry_msgs/msg/point.hpp>
23 #include <geometry_msgs/msg/pose.hpp>
24 #include <geometry_msgs/msg/quaternion.hpp>
25 #include <geometry_msgs/msg/twist.hpp>
26 #include <geometry_msgs/msg/vector3.hpp>
29 #include <string>
30 
35 #define EXPECT_HEADER_EQ(MSG, PROTO) \
36  EXPECT_STREQ(MSG.frame_id.c_str(), PROTO.frame_id().c_str()); \
37  EXPECT_EQ(MSG.stamp.sec, PROTO.stamp().sec()); \
38  EXPECT_EQ(MSG.stamp.nanosec, PROTO.stamp().nanosec());
39 
43 #define EXPECT_TIME_EQ(MSG, PROTO) \
44  EXPECT_EQ(MSG.nanosec, PROTO.nanosec()); \
45  EXPECT_EQ(MSG.sec, PROTO.sec());
46 
47 #define EXPECT_DURATION_EQ(MSG, PROTO) \
48  EXPECT_EQ(MSG.nanosec, PROTO.nanosec()); \
49  EXPECT_EQ(MSG.sec, PROTO.sec());
50 
54 #define EXPECT_CLOCK_EQ(MSG, PROTO) EXPECT_TIME_EQ(MSG.clock, PROTO.clock());
55 
60 #define EXPECT_POINT_EQ(MSG, PROTO) \
61  EXPECT_DOUBLE_EQ(MSG.x, PROTO.x()); \
62  EXPECT_DOUBLE_EQ(MSG.y, PROTO.y()); \
63  EXPECT_DOUBLE_EQ(MSG.z, PROTO.z());
64 
65 #define EXPECT_QUATERNION_EQ(MSG, PROTO) \
66  EXPECT_DOUBLE_EQ(MSG.x, PROTO.x()); \
67  EXPECT_DOUBLE_EQ(MSG.y, PROTO.y()); \
68  EXPECT_DOUBLE_EQ(MSG.z, PROTO.z()); \
69  EXPECT_DOUBLE_EQ(MSG.w, PROTO.w());
70 
71 #define EXPECT_POSE_EQ(MSG, PROTO) \
72  EXPECT_QUATERNION_EQ(MSG.orientation, PROTO.orientation()); \
73  EXPECT_POINT_EQ(MSG.position, PROTO.position());
74 
75 #define EXPECT_VECTOR3_EQ(MSG, PROTO) \
76  EXPECT_DOUBLE_EQ(MSG.x, PROTO.x()); \
77  EXPECT_DOUBLE_EQ(MSG.y, PROTO.y()); \
78  EXPECT_DOUBLE_EQ(MSG.z, PROTO.z());
79 
80 #define EXPECT_TWIST_EQ(MSG, PROTO) \
81  EXPECT_VECTOR3_EQ(MSG.linear, PROTO.linear()); \
82  EXPECT_VECTOR3_EQ(MSG.angular, PROTO.angular());
83 
84 #define EXPECT_ACCEL_EQ(MSG, PROTO) \
85  EXPECT_VECTOR3_EQ(MSG.linear, PROTO.linear()); \
86  EXPECT_VECTOR3_EQ(MSG.angular, PROTO.angular());
87 
92 #define EXPECT_PERFORMANCE_EQ(MSG, PROTO) \
93  EXPECT_DOUBLE_EQ(MSG.max_speed, PROTO.max_speed()); \
94  EXPECT_DOUBLE_EQ(MSG.max_acceleration, PROTO.max_acceleration()); \
95  EXPECT_DOUBLE_EQ(MSG.max_acceleration_rate, PROTO.max_acceleration_rate()); \
96  EXPECT_DOUBLE_EQ(MSG.max_deceleration, PROTO.max_deceleration()); \
97  EXPECT_DOUBLE_EQ(MSG.max_deceleration_rate, PROTO.max_deceleration_rate());
98 
99 #define EXPECT_AXLE_EQ(MSG, PROTO) \
100  EXPECT_DOUBLE_EQ(MSG.max_steering, PROTO.max_steering()); \
101  EXPECT_DOUBLE_EQ(MSG.wheel_diameter, PROTO.wheel_diameter()); \
102  EXPECT_DOUBLE_EQ(MSG.track_width, PROTO.track_width()); \
103  EXPECT_DOUBLE_EQ(MSG.position_x, PROTO.position_x()); \
104  EXPECT_DOUBLE_EQ(MSG.position_z, PROTO.position_z());
105 
106 #define EXPECT_AXLES_EQ(MSG, PROTO) \
107  EXPECT_AXLE_EQ(MSG.front_axle, PROTO.front_axle()) \
108  EXPECT_AXLE_EQ(MSG.rear_axle, PROTO.rear_axle());
109 
110 #define EXPECT_BOUNDING_BOX_EQ(MSG, PROTO) \
111  EXPECT_POINT_EQ(MSG.center, PROTO.center()); \
112  EXPECT_VECTOR3_EQ(MSG.dimensions, PROTO.dimensions());
113 
114 #define EXPECT_VEHICLE_PARAMETERS_EQ(MSG, PROTO) \
115  EXPECT_STREQ(MSG.name.c_str(), PROTO.name().c_str()); \
116  EXPECT_BOUNDING_BOX_EQ(MSG.bounding_box, PROTO.bounding_box()); \
117  EXPECT_PERFORMANCE_EQ(MSG.performance, PROTO.performance()); \
118  EXPECT_AXLES_EQ(MSG.axles, PROTO.axles());
119 
120 #define EXPECT_PEDESTRIAN_PARAMETERS_EQ(MSG, PROTO) \
121  EXPECT_STREQ(MSG.name.c_str(), PROTO.name().c_str()); \
122  EXPECT_BOUNDING_BOX_EQ(MSG.bounding_box, PROTO.bounding_box());
123 
124 #define EXPECT_MISC_OBJECT_PARAMETERS_EQ(MSG, PROTO) \
125  EXPECT_STREQ(MSG.name.c_str(), PROTO.name().c_str()); \
126  EXPECT_BOUNDING_BOX_EQ(MSG.bounding_box, PROTO.bounding_box());
127 
128 #define EXPECT_ACTION_STATUS_EQ(MSG, PROTO) \
129  EXPECT_STREQ(MSG.current_action.c_str(), PROTO.current_action().c_str()); \
130  EXPECT_TWIST_EQ(MSG.twist, PROTO.twist()); \
131  EXPECT_ACCEL_EQ(MSG.accel, PROTO.accel()); \
132  EXPECT_DOUBLE_EQ(MSG.linear_jerk, PROTO.linear_jerk());
133 
134 #define EXPECT_LANELET_POSE_EQ(MSG, PROTO) \
135  EXPECT_EQ(MSG.lanelet_id, PROTO.lanelet_id()); \
136  EXPECT_DOUBLE_EQ(MSG.s, PROTO.s()); \
137  EXPECT_DOUBLE_EQ(MSG.offset, PROTO.offset()); \
138  EXPECT_VECTOR3_EQ(MSG.rpy, PROTO.rpy());
139 
140 #define EXPECT_ENTITY_STATUS_EQ(MSG, PROTO) \
141  EXPECT_DOUBLE_EQ(MSG.time, PROTO.time()); \
142  EXPECT_STREQ(MSG.name.c_str(), PROTO.name().c_str()); \
143  EXPECT_BOUNDING_BOX_EQ(MSG.bounding_box, PROTO.bounding_box()); \
144  EXPECT_ACTION_STATUS_EQ(MSG.action_status, PROTO.action_status()); \
145  EXPECT_POSE_EQ(MSG.pose, PROTO.pose()); \
146  EXPECT_LANELET_POSE_EQ(MSG.lanelet_pose, PROTO.lanelet_pose()); \
147  EXPECT_EQ(MSG.lanelet_pose_valid, PROTO.lanelet_pose_valid());
148 
149 #define EXPECT_SENT_ENTITY_STATUS_EQ(MSG, PROTO) \
150  EXPECT_DOUBLE_EQ(MSG.time, PROTO.time()); \
151  EXPECT_STREQ(MSG.name.c_str(), PROTO.name().c_str()); \
152  EXPECT_ACTION_STATUS_EQ(MSG.action_status, PROTO.action_status()); \
153  EXPECT_POSE_EQ(MSG.pose, PROTO.pose());
154 
158 #define EXPECT_CONTROL_COMMAND_EQ(MSG, PROTO) \
159  EXPECT_DOUBLE_EQ(MSG.longitudinal.velocity, PROTO.longitudinal().velocity()); \
160  EXPECT_DOUBLE_EQ(MSG.longitudinal.acceleration, PROTO.longitudinal().acceleration()); \
161  EXPECT_DOUBLE_EQ(MSG.lateral.steering_tire_angle, PROTO.lateral().steering_tire_angle()); \
162  EXPECT_DOUBLE_EQ( \
163  MSG.lateral.steering_tire_rotation_rate, PROTO.lateral().steering_tire_rotation_rate());
164 
165 #define EXPECT_VEHICLE_COMMAND_EQ(CONTROL_MSG, GEAR_MSG, EMERGENCY_MSG, PROTO) \
166  EXPECT_CONTROL_COMMAND_EQ(CONTROL_MSG, PROTO.control()); \
167  EXPECT_DOUBLE_EQ(GEAR_MSG.command, PROTO.gear_command().data()); \
168  EXPECT_DOUBLE_EQ(EMERGENCY_MSG.emergency, PROTO.vehicle_emergency_stamped().emergency());
169 
170 #endif // SIMULATION_INTERFACE__TEST__EXPECT_EQUAL_MACROS_HPP_