|
| 1 | +// Copyright 2024 TIER IV |
| 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 | +#include <gtest/gtest.h> |
| 16 | + |
| 17 | +// Assuming the parseRouteFile function is in 'RouteHandler.h' |
| 18 | +#include "ament_index_cpp/get_package_share_directory.hpp" |
| 19 | +#include "planning_test_utils/mock_data_parser.hpp" |
| 20 | + |
| 21 | +namespace test_utils |
| 22 | +{ |
| 23 | +// Example YAML structure as a string for testing |
| 24 | +const char g_complete_yaml[] = R"( |
| 25 | +start_pose: |
| 26 | + position: |
| 27 | + x: 1.0 |
| 28 | + y: 2.0 |
| 29 | + z: 3.0 |
| 30 | + orientation: |
| 31 | + x: 0.1 |
| 32 | + y: 0.2 |
| 33 | + z: 0.3 |
| 34 | + w: 0.4 |
| 35 | +goal_pose: |
| 36 | + position: |
| 37 | + x: 4.0 |
| 38 | + y: 5.0 |
| 39 | + z: 6.0 |
| 40 | + orientation: |
| 41 | + x: 0.5 |
| 42 | + y: 0.6 |
| 43 | + z: 0.7 |
| 44 | + w: 0.8 |
| 45 | +segments: |
| 46 | +- preferred_primitive: |
| 47 | + id: 11 |
| 48 | + primitive_type: '' |
| 49 | + primitives: |
| 50 | + - id: 22 |
| 51 | + primitive_type: lane |
| 52 | + - id: 33 |
| 53 | + primitive_type: lane |
| 54 | +)"; |
| 55 | + |
| 56 | +TEST(ParseFunctions, CompleteYAMLTest) |
| 57 | +{ |
| 58 | + YAML::Node config = YAML::Load(g_complete_yaml); |
| 59 | + |
| 60 | + // Test parsing of start_pose and goal_pose |
| 61 | + Pose start_pose = parse_pose(config["start_pose"]); |
| 62 | + Pose goal_pose = parse_pose(config["goal_pose"]); |
| 63 | + |
| 64 | + EXPECT_DOUBLE_EQ(start_pose.position.x, 1.0); |
| 65 | + EXPECT_DOUBLE_EQ(start_pose.position.y, 2.0); |
| 66 | + EXPECT_DOUBLE_EQ(start_pose.position.z, 3.0); |
| 67 | + |
| 68 | + EXPECT_DOUBLE_EQ(start_pose.orientation.x, 0.1); |
| 69 | + EXPECT_DOUBLE_EQ(start_pose.orientation.y, 0.2); |
| 70 | + EXPECT_DOUBLE_EQ(start_pose.orientation.z, 0.3); |
| 71 | + EXPECT_DOUBLE_EQ(start_pose.orientation.w, 0.4); |
| 72 | + |
| 73 | + EXPECT_DOUBLE_EQ(goal_pose.position.x, 4.0); |
| 74 | + EXPECT_DOUBLE_EQ(goal_pose.position.y, 5.0); |
| 75 | + EXPECT_DOUBLE_EQ(goal_pose.position.z, 6.0); |
| 76 | + EXPECT_DOUBLE_EQ(goal_pose.orientation.x, 0.5); |
| 77 | + EXPECT_DOUBLE_EQ(goal_pose.orientation.y, 0.6); |
| 78 | + EXPECT_DOUBLE_EQ(goal_pose.orientation.z, 0.7); |
| 79 | + EXPECT_DOUBLE_EQ(goal_pose.orientation.w, 0.8); |
| 80 | + |
| 81 | + // Test parsing of segments |
| 82 | + std::vector<LaneletSegment> segments = parse_segments(config["segments"]); |
| 83 | + ASSERT_EQ(segments.size(), 1); // Assuming only one segment in the provided YAML for this test |
| 84 | + |
| 85 | + const auto & segment0 = segments[0]; |
| 86 | + EXPECT_EQ(segment0.preferred_primitive.id, 11); |
| 87 | + EXPECT_EQ(segment0.primitives.size(), 2); |
| 88 | + EXPECT_EQ(segment0.primitives[0].id, 22); |
| 89 | + EXPECT_EQ(segment0.primitives[0].primitive_type, "lane"); |
| 90 | + EXPECT_EQ(segment0.primitives[1].id, 33); |
| 91 | + EXPECT_EQ(segment0.primitives[1].primitive_type, "lane"); |
| 92 | +} |
| 93 | + |
| 94 | +TEST(ParseFunction, CompleteFromFilename) |
| 95 | +{ |
| 96 | + const auto planning_test_utils_dir = |
| 97 | + ament_index_cpp::get_package_share_directory("planning_test_utils"); |
| 98 | + const auto parser_test_route = |
| 99 | + planning_test_utils_dir + "/test_data/lanelet_route_parser_test.yaml"; |
| 100 | + |
| 101 | + const auto lanelet_route = parse_lanelet_route_file(parser_test_route); |
| 102 | + EXPECT_DOUBLE_EQ(lanelet_route.start_pose.position.x, 1.0); |
| 103 | + EXPECT_DOUBLE_EQ(lanelet_route.start_pose.position.y, 2.0); |
| 104 | + EXPECT_DOUBLE_EQ(lanelet_route.start_pose.position.z, 3.0); |
| 105 | + |
| 106 | + EXPECT_DOUBLE_EQ(lanelet_route.start_pose.orientation.x, 0.1); |
| 107 | + EXPECT_DOUBLE_EQ(lanelet_route.start_pose.orientation.y, 0.2); |
| 108 | + EXPECT_DOUBLE_EQ(lanelet_route.start_pose.orientation.z, 0.3); |
| 109 | + EXPECT_DOUBLE_EQ(lanelet_route.start_pose.orientation.w, 0.4); |
| 110 | + |
| 111 | + EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.position.x, 4.0); |
| 112 | + EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.position.y, 5.0); |
| 113 | + EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.position.z, 6.0); |
| 114 | + EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.orientation.x, 0.5); |
| 115 | + EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.orientation.y, 0.6); |
| 116 | + EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.orientation.z, 0.7); |
| 117 | + EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.orientation.w, 0.8); |
| 118 | + |
| 119 | + ASSERT_EQ( |
| 120 | + lanelet_route.segments.size(), |
| 121 | + 2); // Assuming only one segment in the provided YAML for this test |
| 122 | + const auto & segment1 = lanelet_route.segments[1]; |
| 123 | + EXPECT_EQ(segment1.preferred_primitive.id, 44); |
| 124 | + EXPECT_EQ(segment1.primitives.size(), 4); |
| 125 | + EXPECT_EQ(segment1.primitives[0].id, 55); |
| 126 | + EXPECT_EQ(segment1.primitives[0].primitive_type, "lane"); |
| 127 | + EXPECT_EQ(segment1.primitives[1].id, 66); |
| 128 | + EXPECT_EQ(segment1.primitives[1].primitive_type, "lane"); |
| 129 | + EXPECT_EQ(segment1.primitives[2].id, 77); |
| 130 | + EXPECT_EQ(segment1.primitives[2].primitive_type, "lane"); |
| 131 | + EXPECT_EQ(segment1.primitives[3].id, 88); |
| 132 | + EXPECT_EQ(segment1.primitives[3].primitive_type, "lane"); |
| 133 | +} |
| 134 | +} // namespace test_utils |
0 commit comments