Skip to content

Commit

Permalink
move to planning test utils
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Zulfaqar Azmi <[email protected]>
  • Loading branch information
zulfaqar-azmi-t4 committed May 17, 2024
1 parent 3f3ed45 commit 66a8518
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 74 deletions.
16 changes: 16 additions & 0 deletions planning/planning_test_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ project(planning_test_utils)
find_package(autoware_cmake REQUIRED)
autoware_package()

ament_auto_add_library(route_parser SHARED
src/route_parser.cpp)

target_link_libraries(route_parser
yaml-cpp
)

if(BUILD_TESTING)
ament_add_ros_isolated_gtest(test_route_parser
test/test_route_parser.cpp)

target_link_libraries(test_route_parser
route_parser)
endif()

ament_auto_package(INSTALL_TO_SHARE
config
test_map
test_data
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef ROUTE_PARSER_HPP_
#define ROUTE_PARSER_HPP_
#ifndef PLANNING_TEST_UTILS__ROUTE_PARSER_HPP_
#define PLANNING_TEST_UTILS__ROUTE_PARSER_HPP_

#include <autoware_planning_msgs/msg/lanelet_primitive.hpp>
#include <autoware_planning_msgs/msg/lanelet_route.hpp>
Expand All @@ -25,7 +25,7 @@
#include <string>
#include <vector>

namespace route_handler::test
namespace test_utils
{
using autoware_planning_msgs::msg::LaneletPrimitive;
using autoware_planning_msgs::msg::LaneletRoute;
Expand All @@ -41,6 +41,6 @@ std::vector<LaneletPrimitive> parse_lanelet_primitives(const YAML::Node & node);
std::vector<LaneletSegment> parse_segments(const YAML::Node & node);

LaneletRoute parse_route_file(const std::string & filename);
} // namespace route_handler::test
} // namespace test_utils

#endif // ROUTE_PARSER_HPP_
#endif // PLANNING_TEST_UTILS__ROUTE_PARSER_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "route_parser.hpp"
#include "planning_test_utils/route_parser.hpp"

#include <rclcpp/logging.hpp>

Expand All @@ -27,7 +27,7 @@
#include <string>
#include <vector>

namespace route_handler::test
namespace test_utils
{
Pose parse_pose(const YAML::Node & node)
{
Expand Down Expand Up @@ -89,4 +89,4 @@ LaneletRoute parse_route_file(const std::string & filename)
}
return lanelet_route;
}
} // namespace route_handler::test
} // namespace test_utils
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

// Assuming the parseRouteFile function is in 'RouteHandler.h'
#include "ament_index_cpp/get_package_share_directory.hpp"
#include "route_parser.hpp"
#include "planning_test_utils/route_parser.hpp"

namespace route_handler::test
namespace test_utils
{
// Example YAML structure as a string for testing
const char g_complete_yaml[] = R"(
Expand Down Expand Up @@ -94,8 +94,9 @@ TEST(ParseFunctions, CompleteYAMLTest)
TEST(ParseFunction, CompleteFromFilename)
{
const auto planning_test_utils_dir =
ament_index_cpp::get_package_share_directory("route_handler");
const auto parser_test_route = planning_test_utils_dir + "/test_route/parser_test.route";
ament_index_cpp::get_package_share_directory("planning_test_utils");
const auto parser_test_route =
planning_test_utils_dir + "/test_data/lanelet_route_parser_test.yaml";

const auto lanelet_route = parse_route_file(parser_test_route);
EXPECT_DOUBLE_EQ(lanelet_route.start_pose.position.x, 1.0);
Expand Down Expand Up @@ -130,4 +131,4 @@ TEST(ParseFunction, CompleteFromFilename)
EXPECT_EQ(segment1.primitives[3].id, 88);
EXPECT_EQ(segment1.primitives[3].primitive_type, "lane");
}
} // namespace route_handler::test
} // namespace test_utils
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
start_pose:
position:
x: 1.0
y: 2.0
z: 3.0
orientation:
x: 0.1
y: 0.2
z: 0.3
w: 0.4
goal_pose:
position:
x: 4.0
y: 5.0
z: 6.0
orientation:
x: 0.5
y: 0.6
z: 0.7
w: 0.8
segments:
- preferred_primitive:
id: 11
primitive_type: ""
primitives:
- id: 22
primitive_type: lane
- id: 33
primitive_type: lane
- preferred_primitive:
id: 44
primitive_type: ""
primitives:
- id: 55
primitive_type: lane
- id: 66
primitive_type: lane
- id: 77
primitive_type: lane
- id: 88
primitive_type: lane
15 changes: 0 additions & 15 deletions planning/route_handler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,15 @@ ament_auto_add_library(route_handler SHARED
)

if(BUILD_TESTING)
ament_auto_add_library(route_parser SHARED
test/route_parser.cpp)

target_link_libraries(route_parser
yaml-cpp
)

ament_add_ros_isolated_gtest(test_route_parser
test/test_route_parser.cpp)

ament_add_ros_isolated_gtest(test_route_handler
test/test_route_handler.cpp)

target_link_libraries(test_route_parser
route_parser)

target_link_libraries(test_route_handler
route_handler
route_parser
)

endif()

ament_auto_package(INSTALL_TO_SHARE
test_map
test_route
)
1 change: 1 addition & 0 deletions planning/route_handler/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<depend>autoware_planning_msgs</depend>
<depend>geometry_msgs</depend>
<depend>lanelet2_extension</depend>
<depend>planning_test_utils</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>tf2_ros</depend>
Expand Down
6 changes: 3 additions & 3 deletions planning/route_handler/test/test_route_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "test_route_handler.hpp"

#include "route_parser.hpp"
#include "planning_test_utils/route_parser.hpp"

#include <rclcpp/rclcpp.hpp>

Expand All @@ -28,7 +28,7 @@ TEST_F(TestRouteHandler, isRouteHandlerReadyTest)
ament_index_cpp::get_package_share_directory("route_handler");
const auto rh_test_route = planning_test_utils_dir + "/test_route/rh_test.route";
ASSERT_FALSE(route_handler_->isHandlerReady());
route_handler_->setRoute(parse_route_file(rh_test_route));
route_handler_->setRoute(test_utils::parse_route_file(rh_test_route));
ASSERT_TRUE(route_handler_->isHandlerReady());
}

Expand All @@ -38,7 +38,7 @@ TEST_F(TestRouteHandler, checkIfIDReturned)
ament_index_cpp::get_package_share_directory("route_handler");
const auto rh_test_route = planning_test_utils_dir + "/test_route/rh_test.route";

route_handler_->setRoute(parse_route_file(rh_test_route));
route_handler_->setRoute(test_utils::parse_route_file(rh_test_route));
const auto lanelet = route_handler_->getLaneletsFromId(4870);

const auto is_in_goal_route_section = route_handler_->isInGoalRouteSection(lanelet);
Expand Down
4 changes: 2 additions & 2 deletions planning/route_handler/test/test_route_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class TestRouteHandler : public ::testing::Test
static HADMapBin makeMapBinMsg()
{
const auto planning_test_utils_dir =
ament_index_cpp::get_package_share_directory("route_handler");
const auto lanelet2_path = planning_test_utils_dir + "/test_map/lanelet2_map.osm";
ament_index_cpp::get_package_share_directory("planning_test_utils");
const auto lanelet2_path = planning_test_utils_dir + "/test_map/2km_test.osm";
double center_line_resolution = 5.0;
// load map from file
const auto map = loadMap(lanelet2_path);
Expand Down
41 changes: 0 additions & 41 deletions planning/route_handler/test_route/parser_test.route

This file was deleted.

0 comments on commit 66a8518

Please sign in to comment.