1414
1515#include < gtest/gtest.h>
1616
17- #include < scenario_simulator_exception/exception.hpp>
1817#include < traffic_simulator/data_type/lanelet_pose.hpp>
1918
2019#include " ../helper_functions.hpp"
@@ -26,13 +25,19 @@ int main(int argc, char ** argv)
2625 testing::InitGoogleTest (&argc, argv);
2726 return RUN_ALL_TESTS ();
2827}
28+ class CanonicalizedLaneletPoseTest : public testing ::Test
29+ {
30+ protected:
31+ CanonicalizedLaneletPoseTest () : hdmap_utils(makeHdMapUtilsSharedPointer()) {}
32+
33+ std::shared_ptr<hdmap_utils::HdMapUtils> hdmap_utils;
34+ };
2935
3036/* *
3137 * @note Test constructor behavior with route_lanelets argument present when canonicalization function fails.
3238 */
33- TEST (CanonicalizedLaneletPose , CanonicalizedLaneletPose_withRoute_invalid)
39+ TEST_F (CanonicalizedLaneletPoseTest , CanonicalizedLaneletPose_withRoute_invalid)
3440{
35- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
3641 EXPECT_THROW (
3742 CanonicalizedLaneletPose (
3843 traffic_simulator::helper::constructLaneletPose (120576 , 14.6356 , 0.0 ), lanelet::Ids{},
@@ -43,9 +48,8 @@ TEST(CanonicalizedLaneletPose, CanonicalizedLaneletPose_withRoute_invalid)
4348/* *
4449 * @note Test constructor behavior with route_lanelets argument present when canonicalization function succeeds
4550 */
46- TEST (CanonicalizedLaneletPose , CanonicalizedLaneletPose_withRoute)
51+ TEST_F (CanonicalizedLaneletPoseTest , CanonicalizedLaneletPose_withRoute)
4752{
48- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
4953 std::shared_ptr<CanonicalizedLaneletPose> pose;
5054 EXPECT_NO_THROW (
5155 pose = std::make_shared<CanonicalizedLaneletPose>(
@@ -59,9 +63,8 @@ TEST(CanonicalizedLaneletPose, CanonicalizedLaneletPose_withRoute)
5963/* *
6064 * @note Test constructor behavior with route_lanelets argument absent when canonicalization function fails
6165 */
62- TEST (CanonicalizedLaneletPose , CanonicalizedLaneletPose_withoutRoute_invalid)
66+ TEST_F (CanonicalizedLaneletPoseTest , CanonicalizedLaneletPose_withoutRoute_invalid)
6367{
64- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
6568 EXPECT_THROW (
6669 CanonicalizedLaneletPose (
6770 traffic_simulator::helper::constructLaneletPose (120576 , 0.0 , 0.0 ), hdmap_utils),
@@ -71,9 +74,8 @@ TEST(CanonicalizedLaneletPose, CanonicalizedLaneletPose_withoutRoute_invalid)
7174/* *
7275 * @note Test constructor behavior with route_lanelets argument absent when canonicalization function succeeds
7376 */
74- TEST (CanonicalizedLaneletPose , CanonicalizedLaneletPose_withoutRoute)
77+ TEST_F (CanonicalizedLaneletPoseTest , CanonicalizedLaneletPose_withoutRoute)
7578{
76- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
7779 std::shared_ptr<CanonicalizedLaneletPose> pose;
7880 EXPECT_NO_THROW (
7981 pose = std::make_shared<CanonicalizedLaneletPose>(
@@ -86,12 +88,11 @@ TEST(CanonicalizedLaneletPose, CanonicalizedLaneletPose_withoutRoute)
8688/* *
8789 * @note Test copy constructor behavior
8890 */
89- TEST (CanonicalizedLaneletPose , CanonicalizedLaneletPose_copyConstructor)
91+ TEST_F (CanonicalizedLaneletPoseTest , CanonicalizedLaneletPose_copyConstructor)
9092{
91- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
92- CanonicalizedLaneletPose pose (
93+ const CanonicalizedLaneletPose pose (
9394 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
94- CanonicalizedLaneletPose pose_copy (pose);
95+ const CanonicalizedLaneletPose pose_copy (pose);
9596 EXPECT_LANELET_POSE_EQ (
9697 static_cast <traffic_simulator::LaneletPose>(pose),
9798 static_cast <traffic_simulator::LaneletPose>(CanonicalizedLaneletPose (pose)));
@@ -100,13 +101,12 @@ TEST(CanonicalizedLaneletPose, CanonicalizedLaneletPose_copyConstructor)
100101/* *
101102 * @note Test move constructor behavior
102103 */
103- TEST (CanonicalizedLaneletPose , CanonicalizedLaneletPose_moveConstructor)
104+ TEST_F (CanonicalizedLaneletPoseTest , CanonicalizedLaneletPose_moveConstructor)
104105{
105- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
106- CanonicalizedLaneletPose pose (
106+ const CanonicalizedLaneletPose pose (
107107 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
108- CanonicalizedLaneletPose pose2 (pose);
109- CanonicalizedLaneletPose pose_move = std::move (pose2);
108+ const CanonicalizedLaneletPose pose2 (pose);
109+ const CanonicalizedLaneletPose pose_move = std::move (pose2);
110110 EXPECT_LANELET_POSE_EQ (
111111 static_cast <traffic_simulator::LaneletPose>(pose),
112112 static_cast <traffic_simulator::LaneletPose>(pose_move));
@@ -115,10 +115,9 @@ TEST(CanonicalizedLaneletPose, CanonicalizedLaneletPose_moveConstructor)
115115/* *
116116 * @note Test copy assignment operator behavior
117117 */
118- TEST (CanonicalizedLaneletPose , copyAssignment)
118+ TEST_F (CanonicalizedLaneletPoseTest , copyAssignment)
119119{
120- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
121- CanonicalizedLaneletPose pose (
120+ const CanonicalizedLaneletPose pose (
122121 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
123122 CanonicalizedLaneletPose pose_assign (
124123 traffic_simulator::helper::constructLaneletPose (34468 , 0.0 , 0.0 ), hdmap_utils);
@@ -133,12 +132,12 @@ TEST(CanonicalizedLaneletPose, copyAssignment)
133132/* *
134133 * @note Test conversion operator behavior using static_cast<LaneletPose>
135134 */
136- TEST (CanonicalizedLaneletPose , conversionLaneletPose)
135+ TEST_F (CanonicalizedLaneletPoseTest , conversionLaneletPose)
137136{
138- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
139- CanonicalizedLaneletPose pose (
137+ const CanonicalizedLaneletPose pose (
140138 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
141- traffic_simulator::LaneletPose pose_casted = static_cast <traffic_simulator::LaneletPose>(pose);
139+ const traffic_simulator::LaneletPose pose_casted =
140+ static_cast <traffic_simulator::LaneletPose>(pose);
142141
143142 EXPECT_EQ (pose_casted.lanelet_id , 120659 );
144143 EXPECT_DOUBLE_EQ (pose_casted.s , 0.0 );
@@ -149,13 +148,12 @@ TEST(CanonicalizedLaneletPose, conversionLaneletPose)
149148/* *
150149 * @note Test conversion operator behavior using static_cast<Pose>
151150 */
152- TEST (CanonicalizedLaneletPose , conversionPose)
151+ TEST_F (CanonicalizedLaneletPoseTest , conversionPose)
153152{
154- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
155- CanonicalizedLaneletPose pose (
153+ const CanonicalizedLaneletPose pose (
156154 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
157155
158- geometry_msgs::msg::Pose pose1 =
156+ const geometry_msgs::msg::Pose pose1 =
159157 makePose (makePoint (3822.3815 , 73784.9618 , -1.761 ), makeQuaternionFromYaw (2.060578777273 ));
160158
161159 EXPECT_POSE_NEAR (static_cast <geometry_msgs::msg::Pose>(pose), pose1, 0.01 );
@@ -164,10 +162,9 @@ TEST(CanonicalizedLaneletPose, conversionPose)
164162/* *
165163 * @note Test function behavior when alternative poses are present
166164 */
167- TEST (CanonicalizedLaneletPose , hasAlternativeLaneletPose_true)
165+ TEST_F (CanonicalizedLaneletPoseTest , hasAlternativeLaneletPose_true)
168166{
169- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
170- CanonicalizedLaneletPose pose (
167+ const CanonicalizedLaneletPose pose (
171168 traffic_simulator::helper::constructLaneletPose (120659 , -10.0 , 0.0 ), hdmap_utils);
172169
173170 EXPECT_TRUE (pose.hasAlternativeLaneletPose ());
@@ -176,10 +173,9 @@ TEST(CanonicalizedLaneletPose, hasAlternativeLaneletPose_true)
176173/* *
177174 * @note Test function behavior when alternative poses are absent
178175 */
179- TEST (CanonicalizedLaneletPose , hasAlternativeLaneletPose_false)
176+ TEST_F (CanonicalizedLaneletPoseTest , hasAlternativeLaneletPose_false)
180177{
181- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
182- CanonicalizedLaneletPose pose (
178+ const CanonicalizedLaneletPose pose (
183179 traffic_simulator::helper::constructLaneletPose (120659 , 10.0 , 0.0 ), hdmap_utils);
184180
185181 EXPECT_FALSE (pose.hasAlternativeLaneletPose ());
@@ -188,27 +184,28 @@ TEST(CanonicalizedLaneletPose, hasAlternativeLaneletPose_false)
188184/* *
189185 * @note Test function behavior when there are no lanelet_poses
190186 */
191- TEST (CanonicalizedLaneletPose , getAlternativeLaneletPoseBaseOnShortestRouteFrom_empty)
187+ TEST_F (CanonicalizedLaneletPoseTest , getAlternativeLaneletPoseBaseOnShortestRouteFrom_empty)
192188{
193- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
194- CanonicalizedLaneletPose pose (
189+ const CanonicalizedLaneletPose pose (
195190 traffic_simulator::helper::constructLaneletPose (120659 , 20.0 , 0.0 ), hdmap_utils);
196191 const auto from1 = traffic_simulator::helper::constructLaneletPose (34603 , 10.0 , 0.0 );
197192 const auto from2 = traffic_simulator::helper::constructLaneletPose (34579 , 10.0 , 0.0 );
198193
199194 const auto result1 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom (from1, hdmap_utils);
200195 const auto result2 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom (from2, hdmap_utils);
201196
197+ ASSERT_TRUE (result1);
198+ ASSERT_TRUE (result2);
199+
202200 EXPECT_EQ (result1.value ().lanelet_id , 120659 );
203201 EXPECT_EQ (result2.value ().lanelet_id , 120659 );
204202}
205203
206204/* *
207205 * @note Test function behavior when there is only one lanelet_pose
208206 */
209- TEST (CanonicalizedLaneletPose , getAlternativeLaneletPoseBaseOnShortestRouteFrom_single)
207+ TEST_F (CanonicalizedLaneletPoseTest , getAlternativeLaneletPoseBaseOnShortestRouteFrom_single)
210208{
211- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
212209 CanonicalizedLaneletPose pose (
213210 traffic_simulator::helper::constructLaneletPose (34666 , -20.0 , 0.0 ), hdmap_utils);
214211 const auto from1 = traffic_simulator::helper::constructLaneletPose (34603 , 10.0 , 0.0 );
@@ -217,16 +214,18 @@ TEST(CanonicalizedLaneletPose, getAlternativeLaneletPoseBaseOnShortestRouteFrom_
217214 const auto result1 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom (from1, hdmap_utils);
218215 const auto result2 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom (from2, hdmap_utils);
219216
217+ ASSERT_TRUE (result1);
218+ ASSERT_TRUE (result2);
219+
220220 EXPECT_EQ (result1.value ().lanelet_id , 34603 );
221221 EXPECT_EQ (result2.value ().lanelet_id , 34603 );
222222}
223223
224224/* *
225225 * @note Test function behavior when there are multiple lanelet_poses
226226 */
227- TEST (CanonicalizedLaneletPose , getAlternativeLaneletPoseBaseOnShortestRouteFrom_multiple)
227+ TEST_F (CanonicalizedLaneletPoseTest , getAlternativeLaneletPoseBaseOnShortestRouteFrom_multiple)
228228{
229- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
230229 CanonicalizedLaneletPose pose (
231230 traffic_simulator::helper::constructLaneletPose (120659 , -20.0 , 0.0 ), hdmap_utils);
232231 const auto from1 = traffic_simulator::helper::constructLaneletPose (34603 , 10.0 , 0.0 );
@@ -235,6 +234,9 @@ TEST(CanonicalizedLaneletPose, getAlternativeLaneletPoseBaseOnShortestRouteFrom_
235234 const auto result1 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom (from1, hdmap_utils);
236235 const auto result2 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom (from2, hdmap_utils);
237236
237+ ASSERT_TRUE (result1);
238+ ASSERT_TRUE (result2);
239+
238240 EXPECT_EQ (result1.value ().lanelet_id , 34603 );
239241 EXPECT_EQ (result2.value ().lanelet_id , 34579 );
240242}
@@ -260,16 +262,15 @@ TEST(CanonicalizedLaneletPose, setConsiderPoseByRoadSlope)
260262/* *
261263 * @note Test operator calculation correctness with CanonicalizedLaneletPose of lesser, equal and greater lanelet_id
262264 */
263- TEST (CanonicalizedLaneletPose , operatorLessEqual)
265+ TEST_F (CanonicalizedLaneletPoseTest , operatorLessEqual)
264266{
265- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
266- CanonicalizedLaneletPose pose (
267+ const CanonicalizedLaneletPose pose (
267268 traffic_simulator::helper::constructLaneletPose (120659 , 5.0 , 0.0 ), hdmap_utils);
268- CanonicalizedLaneletPose pose_equal (
269+ const CanonicalizedLaneletPose pose_equal (
269270 traffic_simulator::helper::constructLaneletPose (120659 , 5.0 , 0.0 ), hdmap_utils);
270- CanonicalizedLaneletPose pose_less (
271+ const CanonicalizedLaneletPose pose_less (
271272 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
272- CanonicalizedLaneletPose pose_greater (
273+ const CanonicalizedLaneletPose pose_greater (
273274 traffic_simulator::helper::constructLaneletPose (120659 , 6.0 , 0.0 ), hdmap_utils);
274275
275276 EXPECT_TRUE (pose_less <= pose);
@@ -280,16 +281,15 @@ TEST(CanonicalizedLaneletPose, operatorLessEqual)
280281/* *
281282 * @note Test operator calculation correctness with CanonicalizedLaneletPose of lesser, equal and greater lanelet_id
282283 */
283- TEST (CanonicalizedLaneletPose , operatorLess)
284+ TEST_F (CanonicalizedLaneletPoseTest , operatorLess)
284285{
285- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
286- CanonicalizedLaneletPose pose (
286+ const CanonicalizedLaneletPose pose (
287287 traffic_simulator::helper::constructLaneletPose (120659 , 5.0 , 0.0 ), hdmap_utils);
288- CanonicalizedLaneletPose pose_equal (
288+ const CanonicalizedLaneletPose pose_equal (
289289 traffic_simulator::helper::constructLaneletPose (120659 , 5.0 , 0.0 ), hdmap_utils);
290- CanonicalizedLaneletPose pose_less (
290+ const CanonicalizedLaneletPose pose_less (
291291 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
292- CanonicalizedLaneletPose pose_greater (
292+ const CanonicalizedLaneletPose pose_greater (
293293 traffic_simulator::helper::constructLaneletPose (120659 , 6.0 , 0.0 ), hdmap_utils);
294294
295295 EXPECT_TRUE (pose_less < pose);
@@ -300,16 +300,15 @@ TEST(CanonicalizedLaneletPose, operatorLess)
300300/* *
301301 * @note Test operator calculation correctness with CanonicalizedLaneletPose of lesser, equal and greater lanelet_id
302302 */
303- TEST (CanonicalizedLaneletPose , operatorGreaterEqual)
303+ TEST_F (CanonicalizedLaneletPoseTest , operatorGreaterEqual)
304304{
305- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
306- CanonicalizedLaneletPose pose (
305+ const CanonicalizedLaneletPose pose (
307306 traffic_simulator::helper::constructLaneletPose (120659 , 5.0 , 0.0 ), hdmap_utils);
308- CanonicalizedLaneletPose pose_equal (
307+ const CanonicalizedLaneletPose pose_equal (
309308 traffic_simulator::helper::constructLaneletPose (120659 , 5.0 , 0.0 ), hdmap_utils);
310- CanonicalizedLaneletPose pose_less (
309+ const CanonicalizedLaneletPose pose_less (
311310 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
312- CanonicalizedLaneletPose pose_greater (
311+ const CanonicalizedLaneletPose pose_greater (
313312 traffic_simulator::helper::constructLaneletPose (120659 , 6.0 , 0.0 ), hdmap_utils);
314313
315314 EXPECT_FALSE (pose_less >= pose);
@@ -320,16 +319,15 @@ TEST(CanonicalizedLaneletPose, operatorGreaterEqual)
320319/* *
321320 * @note Test operator calculation correctness with CanonicalizedLaneletPose of lesser, equal and greater lanelet_id
322321 */
323- TEST (CanonicalizedLaneletPose , operatorGreater)
322+ TEST_F (CanonicalizedLaneletPoseTest , operatorGreater)
324323{
325- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
326- CanonicalizedLaneletPose pose (
324+ const CanonicalizedLaneletPose pose (
327325 traffic_simulator::helper::constructLaneletPose (120659 , 5.0 , 0.0 ), hdmap_utils);
328- CanonicalizedLaneletPose pose_equal (
326+ const CanonicalizedLaneletPose pose_equal (
329327 traffic_simulator::helper::constructLaneletPose (120659 , 5.0 , 0.0 ), hdmap_utils);
330- CanonicalizedLaneletPose pose_less (
328+ const CanonicalizedLaneletPose pose_less (
331329 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
332- CanonicalizedLaneletPose pose_greater (
330+ const CanonicalizedLaneletPose pose_greater (
333331 traffic_simulator::helper::constructLaneletPose (120659 , 6.0 , 0.0 ), hdmap_utils);
334332
335333 EXPECT_FALSE (pose_less > pose);
@@ -340,12 +338,11 @@ TEST(CanonicalizedLaneletPose, operatorGreater)
340338/* *
341339 * @note Test function behavior when provided two poses occupying the same lanelet_id
342340 */
343- TEST (CanonicalizedLaneletPose , isSameLaneletId_withPose_same)
341+ TEST_F (CanonicalizedLaneletPoseTest , isSameLaneletId_withPose_same)
344342{
345- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
346- CanonicalizedLaneletPose pose1 (
343+ const CanonicalizedLaneletPose pose1 (
347344 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
348- CanonicalizedLaneletPose pose2 (
345+ const CanonicalizedLaneletPose pose2 (
349346 traffic_simulator::helper::constructLaneletPose (120659 , 1.0 , 0.0 ), hdmap_utils);
350347
351348 EXPECT_TRUE (traffic_simulator::isSameLaneletId (pose1, pose2));
@@ -354,10 +351,9 @@ TEST(CanonicalizedLaneletPose, isSameLaneletId_withPose_same)
354351/* *
355352 * @note Test function behavior when provided two poses occupying different lanelet_ids
356353 */
357- TEST (CanonicalizedLaneletPose , isSameLaneletId_withPose_different)
354+ TEST_F (CanonicalizedLaneletPoseTest , isSameLaneletId_withPose_different)
358355{
359- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
360- CanonicalizedLaneletPose pose1 (
356+ const CanonicalizedLaneletPose pose1 (
361357 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
362358 CanonicalizedLaneletPose pose2 (
363359 traffic_simulator::helper::constructLaneletPose (34606 , 1.0 , 0.0 ), hdmap_utils);
@@ -368,10 +364,9 @@ TEST(CanonicalizedLaneletPose, isSameLaneletId_withPose_different)
368364/* *
369365 * @note Test function behavior when provided with a pose having lanelt_id equal to the lanelet_id argument
370366 */
371- TEST (CanonicalizedLaneletPose , isSameLaneletId_withLanelet_same)
367+ TEST_F (CanonicalizedLaneletPoseTest , isSameLaneletId_withLanelet_same)
372368{
373- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
374- CanonicalizedLaneletPose pose (
369+ const CanonicalizedLaneletPose pose (
375370 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
376371
377372 EXPECT_TRUE (traffic_simulator::isSameLaneletId (pose, 120659 ));
@@ -380,10 +375,9 @@ TEST(CanonicalizedLaneletPose, isSameLaneletId_withLanelet_same)
380375/* *
381376 * @note Test function behavior when provided with a pose having lanelet_id different to the lanelet_id argument
382377 */
383- TEST (CanonicalizedLaneletPose , isSameLaneletId_withLanelet_different)
378+ TEST_F (CanonicalizedLaneletPoseTest , isSameLaneletId_withLanelet_different)
384379{
385- auto hdmap_utils = makeHdMapUtilsSharedPointer ();
386- CanonicalizedLaneletPose pose (
380+ const CanonicalizedLaneletPose pose (
387381 traffic_simulator::helper::constructLaneletPose (120659 , 0.0 , 0.0 ), hdmap_utils);
388382
389383 EXPECT_FALSE (traffic_simulator::isSameLaneletId (pose, 34606 ));
0 commit comments