|
22 | 22 |
|
23 | 23 | #include <gtest/gtest.h> |
24 | 24 | #include <lanelet2_core/LaneletMap.h> |
| 25 | +#include <lanelet2_core/primitives/Area.h> |
25 | 26 |
|
26 | 27 | #include <memory> |
27 | 28 |
|
| 29 | +using lanelet::Area; |
28 | 30 | using lanelet::Lanelet; |
29 | 31 | using lanelet::LineString3d; |
| 32 | +using lanelet::LineStrings3d; |
30 | 33 | using lanelet::Point3d; |
31 | 34 | using lanelet::utils::getId; |
32 | 35 |
|
@@ -88,6 +91,60 @@ TEST_F(TestSuite, isRouteValid) // NOLINT for gtest |
88 | 91 | "one"; |
89 | 92 | } |
90 | 93 |
|
| 94 | +TEST_F(TestSuite, isRouteValid_rejects_area_when_allow_area_false) // NOLINT for gtest |
| 95 | +{ |
| 96 | + autoware_planning_msgs::msg::LaneletRoute route_with_area; |
| 97 | + autoware_planning_msgs::msg::LaneletSegment segment; |
| 98 | + autoware_planning_msgs::msg::LaneletPrimitive prim; |
| 99 | + prim.primitive_type = "area"; |
| 100 | + prim.id = 99999; // id is irrelevant when allow_area is false |
| 101 | + segment.primitives.push_back(prim); |
| 102 | + route_with_area.segments.push_back(segment); |
| 103 | + |
| 104 | + ASSERT_FALSE(lanelet::utils::route::isRouteValid(route_with_area, sample_map_ptr, false)) |
| 105 | + << "Route with area primitive must be invalid when allow_area is false"; |
| 106 | + ASSERT_FALSE(lanelet::utils::route::isRouteValid(route_with_area, sample_map_ptr)) |
| 107 | + << "Default allow_area should be false for mixed routes"; |
| 108 | +} |
| 109 | + |
| 110 | +TEST_F(TestSuite, isRouteValid_unknown_area_id_fails_when_allow_area_true) // NOLINT for gtest |
| 111 | +{ |
| 112 | + autoware_planning_msgs::msg::LaneletRoute route_with_area; |
| 113 | + autoware_planning_msgs::msg::LaneletSegment segment; |
| 114 | + autoware_planning_msgs::msg::LaneletPrimitive prim; |
| 115 | + prim.primitive_type = "area"; |
| 116 | + prim.id = 99999; // not on map |
| 117 | + segment.primitives.push_back(prim); |
| 118 | + route_with_area.segments.push_back(segment); |
| 119 | + |
| 120 | + ASSERT_FALSE(lanelet::utils::route::isRouteValid(route_with_area, sample_map_ptr, true)) |
| 121 | + << "Missing area id on map should fail validation"; |
| 122 | +} |
| 123 | + |
| 124 | +TEST_F(TestSuite, isRouteValid_resolves_area_when_allow_area_true) // NOLINT for gtest |
| 125 | +{ |
| 126 | + const lanelet::Id area_id = getId(); |
| 127 | + const Point3d a1(getId(), 10.0, 0.0, 0.0); |
| 128 | + const Point3d a2(getId(), 12.0, 0.0, 0.0); |
| 129 | + const Point3d a3(getId(), 12.0, 2.0, 0.0); |
| 130 | + const Point3d a4(getId(), 10.0, 2.0, 0.0); |
| 131 | + const LineString3d ring(getId(), {a1, a2, a3, a4, a1}); |
| 132 | + const LineStrings3d outer{ring}; |
| 133 | + const Area test_area(area_id, outer); |
| 134 | + sample_map_ptr->add(test_area); |
| 135 | + |
| 136 | + autoware_planning_msgs::msg::LaneletRoute route_with_area; |
| 137 | + autoware_planning_msgs::msg::LaneletSegment segment; |
| 138 | + autoware_planning_msgs::msg::LaneletPrimitive prim; |
| 139 | + prim.primitive_type = "area"; |
| 140 | + prim.id = area_id; |
| 141 | + segment.primitives.push_back(prim); |
| 142 | + route_with_area.segments.push_back(segment); |
| 143 | + |
| 144 | + ASSERT_TRUE(lanelet::utils::route::isRouteValid(route_with_area, sample_map_ptr, true)) |
| 145 | + << "Valid area id on map should pass when allow_area is true"; |
| 146 | +} |
| 147 | + |
91 | 148 | int main(int argc, char ** argv) |
92 | 149 | { |
93 | 150 | testing::InitGoogleTest(&argc, argv); |
|
0 commit comments