diff --git a/src/maliput_malidrive/test_utilities/road_geometry_configuration_for_xodrs.cc b/src/maliput_malidrive/test_utilities/road_geometry_configuration_for_xodrs.cc index a9c50ec..7bd929b 100644 --- a/src/maliput_malidrive/test_utilities/road_geometry_configuration_for_xodrs.cc +++ b/src/maliput_malidrive/test_utilities/road_geometry_configuration_for_xodrs.cc @@ -52,7 +52,7 @@ std::optional GetRoadGeometryConfigurationFo {"SingleLane.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"LineSingleLane"}, - {"odr/SingleLane.xodr"}, + {"SingleLane.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -64,7 +64,7 @@ std::optional GetRoadGeometryConfigurationFo {"ArcLane.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"ArcSingleLane"}, - {"odr/ArcLane.xodr"}, + {"ArcLane.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -76,7 +76,7 @@ std::optional GetRoadGeometryConfigurationFo {"BikingLineLane.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"BikingLineLane"}, - {"odr/BikingLineLane.xodr"}, + {"BikingLineLane.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -88,7 +88,7 @@ std::optional GetRoadGeometryConfigurationFo {"DisconnectedRoadInJunction.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"DisconnectedRoadInJunction"}, - {"odr/DisconnectedRoadInJunction.xodr"}, + {"DisconnectedRoadInJunction.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -100,7 +100,7 @@ std::optional GetRoadGeometryConfigurationFo {"SShapeRoad.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"SShapeRoad"}, - {"odr/SShapeRoad.xodr"}, + {"SShapeRoad.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -112,7 +112,7 @@ std::optional GetRoadGeometryConfigurationFo {"LShapeRoad.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"LShapeRoad"}, - {"odr/LShapeRoad.xodr"}, + {"LShapeRoad.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -124,7 +124,7 @@ std::optional GetRoadGeometryConfigurationFo {"LShapeRoadVariableLanes.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"LShapeRoadVariableLanes"}, - {"odr/LShapeRoadVariableLanes.xodr"}, + {"LShapeRoadVariableLanes.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -136,7 +136,7 @@ std::optional GetRoadGeometryConfigurationFo {"LineMultipleSections.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"LineMultipleSections"}, - {"odr/LineMultipleSections.xodr"}, + {"LineMultipleSections.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -148,7 +148,7 @@ std::optional GetRoadGeometryConfigurationFo {"LineMultipleSectionsMoreCases.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"LineMultipleSectionsMoreCases"}, - {"odr/LineMultipleSectionsMoreCases.xodr"}, + {"LineMultipleSectionsMoreCases.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -160,7 +160,7 @@ std::optional GetRoadGeometryConfigurationFo {"LineMultipleSpeeds.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"LineMultipleSpeeds"}, - {"odr/LineMultipleSpeeds.xodr"}, + {"LineMultipleSpeeds.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -172,7 +172,7 @@ std::optional GetRoadGeometryConfigurationFo {"LineVariableOffset.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"LineVariableOffset"}, - {"odr/LineVariableOffset.xodr"}, + {"LineVariableOffset.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -184,7 +184,7 @@ std::optional GetRoadGeometryConfigurationFo {"LineVariableWidth.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"LineVariableWidth"}, - {"odr/LineVariableWidth.xodr"}, + {"LineVariableWidth.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -196,7 +196,7 @@ std::optional GetRoadGeometryConfigurationFo {"ParkingGarageRamp.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"ParkingGarageRamp"}, - {"odr/ParkingGarageRamp.xodr"}, + {"ParkingGarageRamp.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -208,7 +208,7 @@ std::optional GetRoadGeometryConfigurationFo {"RRLongRoad.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"RRLongRoad"}, - {"odr/RRLongRoad.xodr"}, + {"RRLongRoad.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -220,7 +220,7 @@ std::optional GetRoadGeometryConfigurationFo {"SShapeSuperelevatedRoad.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"SShapeSuperelevatedRoad"}, - {"odr/SShapeSuperelevatedRoad.xodr"}, + {"SShapeSuperelevatedRoad.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -232,7 +232,7 @@ std::optional GetRoadGeometryConfigurationFo {"TShapeRoad.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"TShapeRoad"}, - {"odr/TShapeRoad.xodr"}, + {"TShapeRoad.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -244,7 +244,7 @@ std::optional GetRoadGeometryConfigurationFo {"Highway.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"Highway"}, - {"odr/Highway.xodr"}, + {"Highway.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -256,7 +256,7 @@ std::optional GetRoadGeometryConfigurationFo {"Figure8.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"Figure8"}, - {"odr/Figure8.xodr"}, + {"Figure8.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 1e-3 /* linear_tolerance */, 1e-2 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -267,7 +267,7 @@ std::optional GetRoadGeometryConfigurationFo kOmitNondrivableLanes}}, {"RRFigure8.xodr", builder::RoadGeometryConfiguration{maliput::api::RoadGeometryId{"RRFigure8"}, - {"odr/RRFigure8.xodr"}, + {"RRFigure8.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-1 /* linear_tolerance */, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -279,7 +279,7 @@ std::optional GetRoadGeometryConfigurationFo {"StraightForward.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"StraightForward"}, - {"odr/StraightForward.xodr"}, + {"StraightForward.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 1e-3 /* linear_tolerance */, 1e-2 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -291,7 +291,7 @@ std::optional GetRoadGeometryConfigurationFo {"SingleRoadComplexDescription.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"SingleRoadComplexDescription"}, - {"odr/SingleRoadComplexDescription.xodr"}, + {"SingleRoadComplexDescription.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -303,7 +303,7 @@ std::optional GetRoadGeometryConfigurationFo {"SingleRoadComplexDescription2.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"SingleRoadComplexDescription2"}, - {"odr/SingleRoadComplexDescription2.xodr"}, + {"SingleRoadComplexDescription2.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -315,7 +315,7 @@ std::optional GetRoadGeometryConfigurationFo {"SingleRoadNanValues.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"SingleRoadNanValues"}, - {"odr/SingleRoadNanValues.xodr"}, + {"SingleRoadNanValues.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -327,7 +327,7 @@ std::optional GetRoadGeometryConfigurationFo {"SingleRoadNegativeWidth.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"SingleRoadNegativeWidth"}, - {"odr/SingleRoadNegativeWidth.xodr"}, + {"SingleRoadNegativeWidth.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -339,7 +339,7 @@ std::optional GetRoadGeometryConfigurationFo {"SingleRoadHighCoefficients.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"SingleRoadHighCoefficients"}, - {"odr/SingleRoadHighCoefficients.xodr"}, + {"SingleRoadHighCoefficients.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -351,7 +351,7 @@ std::optional GetRoadGeometryConfigurationFo {"SingleRoadTinyGeometry.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"SingleRoadTinyGeometry"}, - {"odr/SingleRoadTinyGeometry.xodr"}, + {"SingleRoadTinyGeometry.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -363,7 +363,7 @@ std::optional GetRoadGeometryConfigurationFo {"SingleRoadTwoGeometries.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"SingleRoadTwoGeometries"}, - {"odr/SingleRoadTwoGeometries.xodr"}, + {"SingleRoadTwoGeometries.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -375,7 +375,7 @@ std::optional GetRoadGeometryConfigurationFo {"FlatTown01.xodr", builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"FlatTown01"}, - {"odr/FlatTown01.xodr"}, + {"FlatTown01.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -385,7 +385,7 @@ std::optional GetRoadGeometryConfigurationFo kStandardStrictnessPolicy, kOmitNondrivableLanes}}, {"Town01.xodr", builder::RoadGeometryConfiguration{maliput::api::RoadGeometryId{"Town01"}, - {"odr/Town01.xodr"}, + {"Town01.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, @@ -396,7 +396,7 @@ std::optional GetRoadGeometryConfigurationFo kStandardStrictnessPolicy, kOmitNondrivableLanes}}, {"Town02.xodr", builder::RoadGeometryConfiguration{maliput::api::RoadGeometryId{"Town02"}, - {"odr/Town02.xodr"}, + {"Town02.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, @@ -407,7 +407,7 @@ std::optional GetRoadGeometryConfigurationFo kStandardStrictnessPolicy, kOmitNondrivableLanes}}, {"Town03.xodr", builder::RoadGeometryConfiguration{maliput::api::RoadGeometryId{"Town03"}, - {"odr/Town03.xodr"}, + {"Town03.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, @@ -421,7 +421,7 @@ std::optional GetRoadGeometryConfigurationFo /* linear tolerance restricted by 0.052m elevation gap in Road 735 */ builder::RoadGeometryConfiguration{ maliput::api::RoadGeometryId{"Town04"}, - {"odr/Town04.xodr"}, + {"Town04.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 6e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -431,7 +431,7 @@ std::optional GetRoadGeometryConfigurationFo kStandardStrictnessPolicy, kOmitNondrivableLanes}}, {"Town05.xodr", builder::RoadGeometryConfiguration{maliput::api::RoadGeometryId{"Town05"}, - {"odr/Town05.xodr"}, + {"Town05.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, @@ -442,7 +442,7 @@ std::optional GetRoadGeometryConfigurationFo kStandardStrictnessPolicy, kOmitNondrivableLanes}}, {"Town06.xodr", builder::RoadGeometryConfiguration{maliput::api::RoadGeometryId{"Town06"}, - {"odr/Town06.xodr"}, + {"Town06.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, @@ -453,7 +453,7 @@ std::optional GetRoadGeometryConfigurationFo kStandardStrictnessPolicy, kOmitNondrivableLanes}}, {"Town07.xodr", builder::RoadGeometryConfiguration{maliput::api::RoadGeometryId{"Town07"}, - {"odr/Town07.xodr"}, + {"Town07.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 5e-1 /*max_linear_tolerance*/, 1e-3 /* angular_tolerance */}, @@ -465,7 +465,7 @@ std::optional GetRoadGeometryConfigurationFo kOmitNondrivableLanes}}, {"GapInElevationNonDrivableRoad.xodr", builder::RoadGeometryConfiguration{maliput::api::RoadGeometryId{"GapInElevationNonDrivableRoad"}, - {"odr/GapInElevationNonDrivableRoad.xodr"}, + {"GapInElevationNonDrivableRoad.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -476,7 +476,7 @@ std::optional GetRoadGeometryConfigurationFo kOmitNondrivableLanes}}, {"GapInSuperelevationNonDrivableRoad.xodr", builder::RoadGeometryConfiguration{maliput::api::RoadGeometryId{"GapInSuperelevationNonDrivableRoad"}, - {"odr/GapInSuperelevationNonDrivableRoad.xodr"}, + {"GapInSuperelevationNonDrivableRoad.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 1e-3 /* angular_tolerance */}, constants::kScaleLength, @@ -487,7 +487,7 @@ std::optional GetRoadGeometryConfigurationFo kOmitNondrivableLanes}}, {"GapInLaneWidthNonDrivableLane.xodr", builder::RoadGeometryConfiguration{maliput::api::RoadGeometryId{"GapInLaneWidthNonDrivableLane"}, - {"odr/GapInLaneWidthNonDrivableLane.xodr"}, + {"GapInLaneWidthNonDrivableLane.xodr"}, builder::RoadGeometryConfiguration::BuildTolerance{ 5e-2 /* linear_tolerance */, 1e-3 /* angular_tolerance */}, constants::kScaleLength, diff --git a/src/utility/resources.cc b/src/utility/resources.cc index 5193abb..73e3361 100644 --- a/src/utility/resources.cc +++ b/src/utility/resources.cc @@ -65,10 +65,17 @@ std::string AppendPath(const std::string& base_path, const std::string& relative } // namespace std::string FindResourceInPath(const std::string& resource_name, const std::string& path_to_resources) { + const std::string file_path = AppendPath(path_to_resources, resource_name); + if (std::ifstream(file_path)) { + return file_path; + } + throw std::runtime_error(std::string("Resource: ") + resource_name + std::string(" couldn't be found.")); +} + +std::string FindResourceInEnvPath(const std::string& resource_name, const std::string& path_to_resources) { const std::vector env_paths = GetAllPathDirectories(path_to_resources); - const std::string resources_folder{"resources"}; for (const std::string& env_path : env_paths) { - const std::string file_path = AppendPath(env_path, AppendPath(resources_folder, resource_name)); + const std::string file_path = AppendPath(env_path, resource_name); if (std::ifstream(file_path)) { return file_path; } @@ -77,7 +84,8 @@ std::string FindResourceInPath(const std::string& resource_name, const std::stri } std::string FindResource(const std::string& resource_name) { - return FindResourceInPath(resource_name, kMalidriveEnvVariable); + const std::string resources_folder{"resources"}; + return FindResourceInEnvPath(AppendPath(resources_folder, resource_name), kMalidriveEnvVariable); } } // namespace utility diff --git a/src/utility/resources.h b/src/utility/resources.h index 92e11c1..b552ab0 100644 --- a/src/utility/resources.h +++ b/src/utility/resources.h @@ -48,14 +48,23 @@ std::string FindResource(const std::string& resource_name); // Finds a resource file by its `resource_name` name. // -// The first valid file within path_directory/`resource_name` is returned. -// Where path_directory is indicated by the path that the env variable `path_to_resources` holds. -// Path delimeter is assumed to be `/`. +// The first valid `resource_name` file within the paths pointed by the environment variable `path_to_resources` is +// returned. Path delimeter is assumed to be `/`. +// // @param resource_name The name of the file. -// @param path_to_resources Env variable holding a directory path. +// @param path_to_resources Env variable holding one or many directory path. // @return The complete file path to the resource. -// @throws std::runtime_error When the resource cannot be found under any -// of the possible combinations of 'path_directory/resource_name'. +// @throws std::runtime_error When the resource cannot be found for any path. +std::string FindResourceInEnvPath(const std::string& resource_name, const std::string& path_to_resources); + +// Finds a resource file by its `resource_name` name. +// +// The first valid `resource_name` file within `path_to_resources`. +// +// @param resource_name The name of the file. +// @param path_to_resources Env variable holding one or many directory path. +// @return The complete file path to the resource. +// @throws std::runtime_error When the resource cannot be found for any path. std::string FindResourceInPath(const std::string& resource_name, const std::string& path_to_resources); } // namespace utility diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a73e2ad..7e10248 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -17,6 +17,8 @@ macro(maliput_malidrive_plugin_tests) foreach(GTEST_SOURCE_file ${ARGN}) string(REGEX REPLACE ".cc" "" BINARY_NAME ${GTEST_SOURCE_file}) set(BINARY_NAME ${TEST_TYPE}_${BINARY_NAME}) + set(RESOURCE_FILE_PREFIX ${PROJECT_SOURCE_DIR}/resources/) + set(ROAD_NETWORK_PLUGIN ${CMAKE_INSTALL_PREFIX}/lib/plugins/) ament_add_gtest(${BINARY_NAME} ${GTEST_SOURCE_file} APPEND_LIBRARY_DIRS ${MALIPUT_MALIDRIVE_PLUGIN_LIBRARY_DIRS} TIMEOUT 240) @@ -46,6 +48,12 @@ macro(maliput_malidrive_plugin_tests) # Remove a warning in GTest. target_compile_options(${BINARY_NAME} PRIVATE "-Wno-sign-compare") + target_compile_definitions(${BINARY_NAME} + PRIVATE + DEF_MALIDRIVE_RESOURCES="${RESOURCE_FILE_PREFIX}" + DEF_ROAD_NETWORK_PLUGIN="${ROAD_NETWORK_PLUGIN}" + ) + endforeach() endmacro() @@ -54,14 +62,7 @@ macro(maliput_malidrive_build_tests) foreach(GTEST_SOURCE_file ${ARGN}) string(REGEX REPLACE ".cc" "" BINARY_NAME ${GTEST_SOURCE_file}) set(BINARY_NAME ${TEST_TYPE}_${BINARY_NAME}) - - # When integration tests are disabled, we just skip adding them. - if(NOT MALIDRIVE_INTEGRATION_TESTS) - if(${TEST_TYPE} MATCHES "INTEGRATION") - message(STATUS "Integration tests are disarmed, skipping: " ${BINARY_NAME}) - continue() - endif() - endif() + set(RESOURCE_FILE_PREFIX ${PROJECT_SOURCE_DIR}/resources/) ament_add_gtest(${BINARY_NAME} ${GTEST_SOURCE_file} TIMEOUT 240) @@ -94,6 +95,50 @@ macro(maliput_malidrive_build_tests) # Remove a warning in GTest. target_compile_options(${BINARY_NAME} PRIVATE "-Wno-sign-compare") + target_compile_definitions(${BINARY_NAME} + PRIVATE + DEF_MALIDRIVE_RESOURCES="${RESOURCE_FILE_PREFIX}" + ) + + endforeach() +endmacro() + +macro(maliput_malidrive_utility_tests) + # Build all the tests + foreach(GTEST_SOURCE_file ${ARGN}) + string(REGEX REPLACE ".cc" "" BINARY_NAME ${GTEST_SOURCE_file}) + set(BINARY_NAME ${TEST_TYPE}_${BINARY_NAME}) + + ament_add_gtest(${BINARY_NAME} ${GTEST_SOURCE_file} APPEND_LIBRARY_DIRS ${MALIPUT_MALIDRIVE_PLUGIN_LIBRARY_DIRS} + TIMEOUT 240) + + target_include_directories(${BINARY_NAME} + PRIVATE + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/include + ${PYTHON_INCLUDE_DIRS} + ) + + # Kind of an ugly catch-all bucket + target_link_libraries(${BINARY_NAME} + utility + ) + + # To avoid a false positive when running ubsan the symbols must be exported + # See https://stackoverflow.com/questions/57361776/use-ubsan-with-dynamically-loaded-shared-libraries + set_target_properties(${BINARY_NAME} + PROPERTIES + ENABLE_EXPORTS ON + ) + + # Remove a warning in GTest. + target_compile_options(${BINARY_NAME} PRIVATE "-Wno-sign-compare") + + target_compile_definitions(${BINARY_NAME} + PRIVATE + DEF_PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}" + ) + endforeach() endmacro() diff --git a/test/regression/CMakeLists.txt b/test/regression/CMakeLists.txt index a8f8f38..ac0bfca 100644 --- a/test/regression/CMakeLists.txt +++ b/test/regression/CMakeLists.txt @@ -8,6 +8,7 @@ add_subdirectory(common) add_subdirectory(loader) add_subdirectory(plugin) add_subdirectory(road_curve) +add_subdirectory(utility) add_subdirectory(xodr) ############################################################################## diff --git a/test/regression/base/road_geometry_test.cc b/test/regression/base/road_geometry_test.cc index 883c8fb..d5ff3c4 100644 --- a/test/regression/base/road_geometry_test.cc +++ b/test/regression/base/road_geometry_test.cc @@ -53,6 +53,9 @@ namespace malidrive { namespace tests { namespace { +// Resource folder path defined via compile definition. +static constexpr char kMalidriveResourceFolder[] = DEF_MALIDRIVE_RESOURCES; + std::unique_ptr MakeZeroCubicPolynomial(double p0, double p1, double linear_tolerance) { return std::make_unique(0., 0., 0., 0., p0, p1, linear_tolerance); } @@ -77,8 +80,8 @@ class RoadGeometryTest : public ::testing::Test { MakeZeroCubicPolynomial(kP0, kP1, kLinearTolerance), MakeZeroCubicPolynomial(kP0, kP1, kLinearTolerance), kAssertContiguity); std::unique_ptr reference_line_offset = MakeZeroCubicPolynomial(kP0, kP1, kLinearTolerance); - std::unique_ptr manager = - xodr::LoadDataBaseFromFile(utility::FindResource("odr/SingleLane.xodr"), kParserConfiguration); + std::unique_ptr manager = xodr::LoadDataBaseFromFile( + utility::FindResourceInPath("SingleLane.xodr", kMalidriveResourceFolder), kParserConfiguration); }; // Tests getters and the constructor of an empty RoadGeometry. @@ -145,7 +148,7 @@ class RoadGeometryFigure8Trafficlights : public ::testing::Test { void SetUp() override { road_geometry_configuration_.id = maliput::api::RoadGeometryId("figure8_trafficlights"); road_geometry_configuration_.opendrive_file = - utility::FindResource("odr/figure8_trafficlights/figure8_trafficlights.xodr"); + utility::FindResourceInPath("figure8_trafficlights/figure8_trafficlights.xodr", kMalidriveResourceFolder); road_network_ = ::malidrive::loader::Load<::malidrive::builder::RoadNetworkBuilder>(road_geometry_configuration_.ToStringMap()); } diff --git a/test/regression/builder/builder_tools_test.cc b/test/regression/builder/builder_tools_test.cc index 74908d6..00a85de 100644 --- a/test/regression/builder/builder_tools_test.cc +++ b/test/regression/builder/builder_tools_test.cc @@ -45,6 +45,9 @@ namespace builder { namespace test { namespace { +// Resource folder path defined via compile definition. +static constexpr char kMalidriveResourceFolder[] = DEF_MALIDRIVE_RESOURCES; + // TODO(maliput#341): Remove this operator once it is implemented in maliput. bool operator==(const maliput::api::LaneEnd& end_a, const maliput::api::LaneEnd& end_b) { return end_a.end == end_b.end && end_a.lane == end_b.lane; @@ -246,7 +249,8 @@ class LanePropertiesTest : public ::testing::Test { protected: void SetUp() override { - manager_ = xodr::LoadDataBaseFromFile(utility::FindResource("odr/BikingLineLane.xodr"), {std::nullopt}); + manager_ = xodr::LoadDataBaseFromFile(utility::FindResourceInPath("BikingLineLane.xodr", kMalidriveResourceFolder), + {std::nullopt}); road_header_ = &manager_->GetRoadHeaders().at(xodr::RoadHeader::Id(kRoadId)); } std::unique_ptr manager_; diff --git a/test/regression/builder/phase_provider_builder_test.cc b/test/regression/builder/phase_provider_builder_test.cc index 957c94a..a13e27f 100644 --- a/test/regression/builder/phase_provider_builder_test.cc +++ b/test/regression/builder/phase_provider_builder_test.cc @@ -58,6 +58,9 @@ using maliput::api::rules::Phase; using maliput::api::rules::PhaseProvider; using maliput::api::rules::PhaseRing; +// Resource folder path defined via compile definition. +static constexpr char kMalidriveResourceFolder[] = DEF_MALIDRIVE_RESOURCES; + // Creates the stack of entities that are necessary to populate the ManualPhaseProvider through the PhaseProviderBuilder // functor. class PhaseProviderBuilderTest : public ::testing::Test { @@ -74,12 +77,16 @@ class PhaseProviderBuilderTest : public ::testing::Test { } protected: - const std::string map_id{"odr/figure8_trafficlights/figure8_trafficlights"}; - const std::string xodr_file_path{utility::FindResource(map_id + ".xodr")}; - const std::string rule_registry_path{utility::FindResource(map_id + "_new_rules.yaml")}; - const std::string road_rulebook_path{utility::FindResource(map_id + "_new_rules.yaml")}; - const std::string traffic_light_path{utility::FindResource(map_id + "_new_rules.yaml")}; - const std::string phase_ring_book_path{utility::FindResource(map_id + "_new_rules.yaml")}; + const std::string map_id{"figure8_trafficlights/figure8_trafficlights"}; + const std::string xodr_file_path{utility::FindResourceInPath(map_id + ".xodr", kMalidriveResourceFolder)}; + const std::string rule_registry_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; + const std::string road_rulebook_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; + const std::string traffic_light_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; + const std::string phase_ring_book_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; const RoadGeometryConfiguration road_geometry_configuration_{RoadGeometryConfiguration::FromMap({ {"opendrive_file", xodr_file_path}, {"omit_nondrivable_lanes", "false"}, diff --git a/test/regression/builder/road_geometry_builder_test.cc b/test/regression/builder/road_geometry_builder_test.cc index 117d93e..77a5e31 100644 --- a/test/regression/builder/road_geometry_builder_test.cc +++ b/test/regression/builder/road_geometry_builder_test.cc @@ -57,6 +57,9 @@ using maliput::api::test::IsRBoundsClose; using malidrive::test::GetRoadGeometryConfigurationFor; +// Resource folder path defined via compile definition. +static constexpr char kMalidriveResourceFolder[] = DEF_MALIDRIVE_RESOURCES; + /* Loaded map has the following structure: @@ -77,8 +80,9 @@ class BuilderTestSingleLane : public ::testing::Test { road_geometry_configuration_.tolerances.linear_tolerance = kLinearTolerance; road_geometry_configuration_.tolerances.max_linear_tolerance = std::nullopt; road_geometry_configuration_.tolerances.angular_tolerance = kAngularTolerance; - manager_ = xodr::LoadDataBaseFromFile(utility::FindResource(road_geometry_configuration_.opendrive_file), - {kLinearTolerance}); + manager_ = xodr::LoadDataBaseFromFile( + utility::FindResourceInPath(road_geometry_configuration_.opendrive_file, kMalidriveResourceFolder), + {kLinearTolerance}); } RoadGeometryConfiguration road_geometry_configuration_{GetRoadGeometryConfigurationFor("SingleLane.xodr").value()}; @@ -372,8 +376,9 @@ class RoadGeometryBuilderBaseTest : public ::testing::TestWithParam InstantiateBuilderParameters() { */ // TODO(#510): Test was commented out to avoid blocking development. // See issue for more information. - // {"TShapeRoad", "odr/TShapeRoad.xodr"}, + // {"TShapeRoad", "TShapeRoad.xodr"}, /* LineMultipleSections map has the following structure: @@ -222,7 +225,7 @@ std::vector InstantiateBuilderParameters() { */ // TODO(#510): Test was commented out to avoid blocking development. // See issue for more information. - // {"LineMultipleSections", "odr/LineMultipleSections.xodr"}, + // {"LineMultipleSections", "LineMultipleSections.xodr"}, /* ParkingGarageRamp describes a Road in the form of a parking garage ramp. @@ -282,7 +285,8 @@ TEST_P(RoadNetworkBuilderTest, RoadGeometryBuilding) { const auto rg_config_opt = GetRoadGeometryConfigurationFor(GetParam().path_to_xodr_file); ASSERT_NE(rg_config_opt, std::nullopt); RoadGeometryConfiguration road_geometry_configuration{rg_config_opt.value()}; - road_geometry_configuration.opendrive_file = utility::FindResource(road_geometry_configuration.opendrive_file); + road_geometry_configuration.opendrive_file = + utility::FindResourceInPath(road_geometry_configuration.opendrive_file, kMalidriveResourceFolder); const std::unique_ptr dut = builder::RoadNetworkBuilder(road_geometry_configuration.ToStringMap())(); ASSERT_NE(dynamic_cast(dut->road_geometry()), nullptr); @@ -307,9 +311,10 @@ class BuilderTest : public ::testing::Test { class RuleRegistryBuildTest : public BuilderTest { protected: void SetUp() override { - const std::string kTShapeRoadYAMLPath{utility::FindResource("odr/TShapeRoad.yaml")}; + const std::string kTShapeRoadYAMLPath{utility::FindResourceInPath("TShapeRoad.yaml", kMalidriveResourceFolder)}; RoadGeometryConfiguration road_geometry_configuration{GetRoadGeometryConfigurationFor("TShapeRoad.xodr").value()}; - road_geometry_configuration.opendrive_file = utility::FindResource("odr/TShapeRoad.xodr"); + road_geometry_configuration.opendrive_file = + utility::FindResourceInPath(road_geometry_configuration.opendrive_file, kMalidriveResourceFolder); RoadNetworkConfiguration road_network_configuration{road_geometry_configuration, std::nullopt, kTShapeRoadYAMLPath, kTShapeRoadYAMLPath, kTShapeRoadYAMLPath, std::nullopt}; @@ -397,9 +402,9 @@ TEST_F(RuleRegistryBuildTest, RangeValueRuleTypesLoadTest) { } TEST_F(BuilderTest, CustomRoadNetworkEntitiesLoadersTest) { - const std::string kTShapeRoadYAMLPath{utility::FindResource("odr/TShapeRoad.yaml")}; + const std::string kTShapeRoadYAMLPath{utility::FindResourceInPath("TShapeRoad.yaml", kMalidriveResourceFolder)}; RoadGeometryConfiguration road_geometry_configuration{GetRoadGeometryConfigurationFor("TShapeRoad.xodr").value()}; - road_geometry_configuration.opendrive_file = utility::FindResource("odr/TShapeRoad.xodr"); + road_geometry_configuration.opendrive_file = utility::FindResourceInPath("TShapeRoad.xodr", kMalidriveResourceFolder); const RoadNetworkConfiguration road_network_configuration{road_geometry_configuration, std::nullopt, kTShapeRoadYAMLPath, kTShapeRoadYAMLPath, kTShapeRoadYAMLPath, kTShapeRoadYAMLPath}; @@ -448,9 +453,9 @@ TEST_F(BuilderTest, CustomRoadNetworkEntitiesLoadersTest) { // properties are parsed and added to the RoadNetwork variables are correctly // parsed. TEST_F(BuilderTest, StubProperties) { - const std::string kTShapeRoadYAMLPath{utility::FindResource("odr/TShapeRoad.yaml")}; + const std::string kTShapeRoadYAMLPath{utility::FindResourceInPath("TShapeRoad.yaml", kMalidriveResourceFolder)}; RoadGeometryConfiguration road_geometry_configuration{GetRoadGeometryConfigurationFor("TShapeRoad.xodr").value()}; - road_geometry_configuration.opendrive_file = utility::FindResource("odr/TShapeRoad.xodr"); + road_geometry_configuration.opendrive_file = utility::FindResourceInPath("TShapeRoad.xodr", kMalidriveResourceFolder); const RoadNetworkConfiguration road_network_configuration{road_geometry_configuration, std::nullopt, kTShapeRoadYAMLPath, kTShapeRoadYAMLPath, kTShapeRoadYAMLPath, std::nullopt}; @@ -493,7 +498,8 @@ class DirectionUsageTest : public ::testing::TestWithParam static constexpr double kLinearTolerance{constants::kLinearTolerance}; void SetUp() override { - road_geometry_configuration_.opendrive_file = utility::FindResource(road_geometry_configuration_.opendrive_file); + road_geometry_configuration_.opendrive_file = + utility::FindResourceInPath(road_geometry_configuration_.opendrive_file, kMalidriveResourceFolder); reference_values_ = GetParam().reference_values; } @@ -824,7 +831,8 @@ struct VehicleRulesStateProviderTruthTable { class VehicleRulesStateProviderTest : public ::testing::TestWithParam { protected: void SetUp() override { - road_geometry_configuration_.opendrive_file = utility::FindResource(road_geometry_configuration_.opendrive_file); + road_geometry_configuration_.opendrive_file = + utility::FindResourceInPath(road_geometry_configuration_.opendrive_file, kMalidriveResourceFolder); reference_values_ = GetParam().reference_values; } @@ -912,7 +920,8 @@ class SpeedLimitRuleBuilderTest : public ::testing::TestWithParam { protected: void SetUp() override { - road_geometry_configuration_.opendrive_file = utility::FindResource(road_geometry_configuration_.opendrive_file); + road_geometry_configuration_.opendrive_file = + utility::FindResourceInPath(road_geometry_configuration_.opendrive_file, kMalidriveResourceFolder); reference_values_ = GetParam().reference_values; } @@ -1223,13 +1233,18 @@ class RoadNetworkBuilderPopulationTest : public ::testing::Test { protected: void SetUp() override {} - const std::string map_id{"odr/figure8_trafficlights/figure8_trafficlights"}; - const std::string xodr_file_path{utility::FindResource(map_id + ".xodr")}; - const std::string rule_registry_path{utility::FindResource(map_id + "_new_rules.yaml")}; - const std::string road_rulebook_path{utility::FindResource(map_id + "_new_rules.yaml")}; - const std::string traffic_light_book_path{utility::FindResource(map_id + "_new_rules.yaml")}; - const std::string phase_ring_book_path{utility::FindResource(map_id + "_new_rules.yaml")}; - const std::string intersection_book_path{utility::FindResource(map_id + "_new_rules.yaml")}; + const std::string map_id{"figure8_trafficlights/figure8_trafficlights"}; + const std::string xodr_file_path{utility::FindResourceInPath(map_id + ".xodr", kMalidriveResourceFolder)}; + const std::string rule_registry_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; + const std::string road_rulebook_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; + const std::string traffic_light_book_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; + const std::string phase_ring_book_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; + const std::string intersection_book_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; const RoadNetworkConfiguration road_network_configuration_{RoadNetworkConfiguration::FromMap({ {params::kOpendriveFile, xodr_file_path}, {params::kRuleRegistry, rule_registry_path}, @@ -1287,12 +1302,12 @@ class RoadNetworkBuilderPopulationOldRuleTest : public ::testing::Test { protected: void SetUp() override {} - const std::string map_id{"odr/figure8_trafficlights/figure8_trafficlights"}; - const std::string xodr_file_path{utility::FindResource(map_id + ".xodr")}; - const std::string road_rulebook_path{utility::FindResource(map_id + ".yaml")}; - const std::string traffic_light_book_path{utility::FindResource(map_id + ".yaml")}; - const std::string phase_ring_book_path{utility::FindResource(map_id + ".yaml")}; - const std::string intersection_book_path{utility::FindResource(map_id + ".yaml")}; + const std::string map_id{"figure8_trafficlights/figure8_trafficlights"}; + const std::string xodr_file_path{utility::FindResourceInPath(map_id + ".xodr", kMalidriveResourceFolder)}; + const std::string road_rulebook_path{utility::FindResourceInPath(map_id + ".yaml", kMalidriveResourceFolder)}; + const std::string traffic_light_book_path{utility::FindResourceInPath(map_id + ".yaml", kMalidriveResourceFolder)}; + const std::string phase_ring_book_path{utility::FindResourceInPath(map_id + ".yaml", kMalidriveResourceFolder)}; + const std::string intersection_book_path{utility::FindResourceInPath(map_id + ".yaml", kMalidriveResourceFolder)}; const RoadNetworkConfiguration road_network_configuration_{RoadNetworkConfiguration::FromMap({ {params::kOpendriveFile, xodr_file_path}, {params::kRoadRuleBook, road_rulebook_path}, diff --git a/test/regression/builder/road_rulebook_builder_test.cc b/test/regression/builder/road_rulebook_builder_test.cc index cfc8aac..2ab446f 100644 --- a/test/regression/builder/road_rulebook_builder_test.cc +++ b/test/regression/builder/road_rulebook_builder_test.cc @@ -61,6 +61,9 @@ using maliput::api::rules::DiscreteValueRule; using maliput::api::rules::RangeValueRule; using maliput::api::rules::Rule; +// Resource folder path defined via compile definition. +static constexpr char kMalidriveResourceFolder[] = DEF_MALIDRIVE_RESOURCES; + // Verifies if `rule_a` and `rule_b` are equal based on a `tolerance`. The `tolerance` value applyies when the region // of the rule is being evaluated. // `T` param: DiscreteValueRules or RangeValueRules. @@ -136,10 +139,12 @@ class RoadRulebookBuilderTest : public ::testing::Test { } protected: - const std::string map_id{"odr/figure8_trafficlights/figure8_trafficlights"}; - const std::string xodr_file_path{utility::FindResource(map_id + ".xodr")}; - const std::string rule_registry_path{utility::FindResource(map_id + "_new_rules.yaml")}; - const std::string road_rulebook_path{utility::FindResource(map_id + "_new_rules.yaml")}; + const std::string map_id{"figure8_trafficlights/figure8_trafficlights"}; + const std::string xodr_file_path{utility::FindResourceInPath(map_id + ".xodr", kMalidriveResourceFolder)}; + const std::string rule_registry_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; + const std::string road_rulebook_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; const RoadGeometryConfiguration road_geometry_configuration_{RoadGeometryConfiguration::FromMap({ {"opendrive_file", xodr_file_path}, {"omit_nondrivable_lanes", "false"}, diff --git a/test/regression/builder/rule_registry_builder_test.cc b/test/regression/builder/rule_registry_builder_test.cc index 1ba9866..d58c42f 100644 --- a/test/regression/builder/rule_registry_builder_test.cc +++ b/test/regression/builder/rule_registry_builder_test.cc @@ -48,6 +48,9 @@ namespace builder { namespace test { namespace { +// Resource folder path defined via compile definition. +static constexpr char kMalidriveResourceFolder[] = DEF_MALIDRIVE_RESOURCES; + // Obtains all the keys from `map`. template std::vector GetAllKeysFromMap(std::map map) { @@ -245,9 +248,10 @@ class RuleRegistryBuilderTest : public ::testing::Test { } protected: - const std::string map_id{"odr/figure8_trafficlights/figure8_trafficlights"}; - const std::string xodr_file_path{utility::FindResource(map_id + ".xodr")}; - const std::string rule_registry_path{utility::FindResource(map_id + "_new_rules.yaml")}; + const std::string map_id{"figure8_trafficlights/figure8_trafficlights"}; + const std::string xodr_file_path{utility::FindResourceInPath(map_id + ".xodr", kMalidriveResourceFolder)}; + const std::string rule_registry_path{ + utility::FindResourceInPath(map_id + "_new_rules.yaml", kMalidriveResourceFolder)}; const RoadGeometryConfiguration road_geometry_configuration_{RoadGeometryConfiguration::FromMap({ {"opendrive_file", xodr_file_path}, })}; diff --git a/test/regression/loader/loader_test.cc b/test/regression/loader/loader_test.cc index 9843c42..249aa82 100644 --- a/test/regression/loader/loader_test.cc +++ b/test/regression/loader/loader_test.cc @@ -46,11 +46,14 @@ namespace loader { namespace test { namespace { +// Resource folder path defined via compile definition. +static constexpr char kMalidriveResourceFolder[] = DEF_MALIDRIVE_RESOURCES; + class LoaderTestSingleLane : public ::testing::Test { protected: const std::map road_geometry_configuration_{ {builder::params::kRoadGeometryId, "test_id"}, - {builder::params::kOpendriveFile, utility::FindResource("odr/SingleLane.xodr")}, + {builder::params::kOpendriveFile, utility::FindResourceInPath("SingleLane.xodr", kMalidriveResourceFolder)}, {builder::params::kLinearTolerance, "1e-3"}, {builder::params::kAngularTolerance, "1e-3"}, {builder::params::kScaleLength, "1"}, diff --git a/test/regression/plugin/road_network_plugin_test.cc b/test/regression/plugin/road_network_plugin_test.cc index 6519b4b..96712fa 100644 --- a/test/regression/plugin/road_network_plugin_test.cc +++ b/test/regression/plugin/road_network_plugin_test.cc @@ -44,8 +44,12 @@ namespace malidrive { namespace { +// Resource folder path defined via compile definition. +static constexpr char kMalidriveResourceFolder[] = DEF_MALIDRIVE_RESOURCES; + GTEST_TEST(RoadNetworkLoader, VerifyRoadNetworkPlugin) { - const std::string kXodrFilePath{utility::FindResource("odr/TShapeRoad.xodr")}; + setenv("MALIPUT_PLUGIN_PATH", DEF_ROAD_NETWORK_PLUGIN, 1); + const std::string kXodrFilePath{utility::FindResourceInPath("TShapeRoad.xodr", kMalidriveResourceFolder)}; // RoadNetworkLoader plugin id. const maliput::plugin::MaliputPlugin::Id kMaliputMalidrivePluginId{"maliput_malidrive"}; diff --git a/test/regression/utility/CMakeLists.txt b/test/regression/utility/CMakeLists.txt new file mode 100644 index 0000000..e99ef63 --- /dev/null +++ b/test/regression/utility/CMakeLists.txt @@ -0,0 +1,16 @@ +############################################################################## +# utility +############################################################################## + +# Test binary name prefix, used by malidrive_build_tests +set(TEST_TYPE UNIT) + +############################################################################## +# Tests +############################################################################## + +set(UNIT_UTILITY_TEST_SOURCES + resources_test.cc +) + +maliput_malidrive_utility_tests(${UNIT_UTILITY_TEST_SOURCES}) diff --git a/test/regression/utility/resources_test.cc b/test/regression/utility/resources_test.cc new file mode 100644 index 0000000..e7c8bd2 --- /dev/null +++ b/test/regression/utility/resources_test.cc @@ -0,0 +1,94 @@ +// BSD 3-Clause License +// +// Copyright (c) 2022, Woven Planet +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include "utility/resources.h" + +#include +#include + +#include + +namespace utility { +namespace test { +namespace { + +static constexpr char kMalidriveProjectSourcePath[] = DEF_PROJECT_SOURCE_DIR; + +class FindResourceTest : public ::testing::Test { + public: + static constexpr char kMalidriveResourceEnv[] = "MALIPUT_MALIDRIVE_RESOURCE_ROOT"; + + void SetUp() override { setenv(kMalidriveResourceEnv, kMalidriveProjectSourcePath, 1); } +}; + +TEST_F(FindResourceTest, NotFound) { + const std::string kWrongFile{"WrongFile"}; + EXPECT_THROW(FindResource(kWrongFile), std::runtime_error); +} + +TEST_F(FindResourceTest, Found) { + const std::string kTShapeRoadXodrFile{"TShapeRoad.xodr"}; + EXPECT_NO_THROW(FindResource(kTShapeRoadXodrFile)); +} + +class FindResourceInEnvPathTest : public FindResourceTest { + public: + void SetUp() override { + setenv(kMalidriveResourceEnv, (std::string(kMalidriveProjectSourcePath) + "/resources").c_str(), 1); + } +}; + +TEST_F(FindResourceInEnvPathTest, NotFound) { + const std::string kWrongFile{"WrongFile"}; + EXPECT_THROW(FindResourceInEnvPath(kWrongFile, FindResourceTest::kMalidriveResourceEnv), std::runtime_error); +} + +TEST_F(FindResourceInEnvPathTest, Found) { + const std::string kTShapeRoadXodrFile{"TShapeRoad.xodr"}; + EXPECT_NO_THROW(FindResourceInEnvPath(kTShapeRoadXodrFile, FindResourceTest::kMalidriveResourceEnv)); +} + +class FindResourceInPathTest : public ::testing::Test { + public: + const std::string kMalidriveResourceFolder = std::string(kMalidriveProjectSourcePath) + "/resources"; +}; + +TEST_F(FindResourceInPathTest, NotFound) { + const std::string kWrongFile{"WrongFile"}; + EXPECT_THROW(FindResourceInPath(kWrongFile, kMalidriveResourceFolder), std::runtime_error); +} + +TEST_F(FindResourceInPathTest, Found) { + const std::string kTShapeRoadXodrFile{"TShapeRoad.xodr"}; + EXPECT_NO_THROW(FindResourceInPath(kTShapeRoadXodrFile, kMalidriveResourceFolder)); +} + +} // namespace +} // namespace test +} // namespace utility diff --git a/test/regression/xodr/db_manager_test.cc b/test/regression/xodr/db_manager_test.cc index 4cc616e..eb770e8 100644 --- a/test/regression/xodr/db_manager_test.cc +++ b/test/regression/xodr/db_manager_test.cc @@ -44,6 +44,9 @@ namespace xodr { namespace test { namespace { +// Resource folder path defined via compile definition. +static constexpr char kMalidriveResourceFolder[] = DEF_MALIDRIVE_RESOURCES; + // Template of a XODR description that contains only the xodr header. constexpr const char* kXODRHeaderTemplate = R"R( @@ -83,8 +86,9 @@ constexpr bool kDontAllowSemanticErrors{false}; // Tests the loading of a XODR description from a file. GTEST_TEST(DBManager, LoadFromFile) { - const std::string kXodrFile = "odr/SingleLane.xodr"; - EXPECT_NO_THROW(LoadDataBaseFromFile(utility::FindResource(kXodrFile), {kStrictParserSTolerance})); + const std::string kXodrFile = "SingleLane.xodr"; + EXPECT_NO_THROW(LoadDataBaseFromFile(utility::FindResourceInPath(kXodrFile, kMalidriveResourceFolder), + {kStrictParserSTolerance})); } // Tests the loading of a XODR description from a string. @@ -1269,11 +1273,12 @@ GTEST_TEST(DBManagerTest, GetJunctions) { {kConnection5.id, kConnection5}} /* connections */}; const std::unordered_map kExpectedJunctions{{kExpectedJunction.id, kExpectedJunction}}; - const std::string kXodrFile = "odr/TShapeRoad.xodr"; + const std::string kXodrFile = "TShapeRoad.xodr"; // If I decrease even more the tolerance, the TShapeRoad.xodr's geometries aren't contiguous in terms of the arc // length parameter. // TODO(#482): Decrease tolerance once the xodr file is fixed. - const std::unique_ptr dut = LoadDataBaseFromFile(utility::FindResource(kXodrFile), {1e-6}); + const std::unique_ptr dut = + LoadDataBaseFromFile(utility::FindResourceInPath(kXodrFile, kMalidriveResourceFolder), {1e-6}); const std::unordered_map junctions = dut->GetJunctions(); @@ -1296,7 +1301,7 @@ std::string LaneUserDataTravelDirTemplate(const std::string& travel_dir) { // However, this test's goal is showing the correct functioning by loading a long XODR description and selecting a // random Road and Junction and checking that the values are well parsed. GTEST_TEST(DBManagerTest, Highway) { - const std::string kXodrFile = "odr/Highway.xodr"; + const std::string kXodrFile = "Highway.xodr"; const int NumOfRoads{37}; const int NumOfJunctions{6}; // Road 52 of Highway description: @@ -1580,7 +1585,7 @@ GTEST_TEST(DBManagerTest, Highway) { // @} const std::unique_ptr dut = - LoadDataBaseFromFile(utility::FindResource(kXodrFile), {kStrictParserSTolerance}); + LoadDataBaseFromFile(utility::FindResourceInPath(kXodrFile, kMalidriveResourceFolder), {kStrictParserSTolerance}); const std::map road_headers = dut->GetRoadHeaders(); EXPECT_EQ(NumOfRoads, static_cast(road_headers.size())); @@ -1728,8 +1733,9 @@ GTEST_TEST(DBManagerTest, LoadMapWith2Connections) { // Loads TShapeRoad.xodr and verifies the shortest and largest Geometry in the XODR. GTEST_TEST(DBManager, GetGeometriesLengthInformation) { - const std::string kXodrFile = "odr/TShapeRoad.xodr"; - const auto db_manager = LoadDataBaseFromFile(utility::FindResource(kXodrFile), {constants::kLinearTolerance}); + const std::string kXodrFile = "TShapeRoad.xodr"; + const auto db_manager = LoadDataBaseFromFile(utility::FindResourceInPath(kXodrFile, kMalidriveResourceFolder), + {constants::kLinearTolerance}); const DBManager::XodrGeometryLengthData kExpectedShortest{RoadHeader::Id("6"), 3, 6.8474312421988870e-2}; const DBManager::XodrGeometryLengthData kExpectedLargest{RoadHeader::Id("0"), 0, 46.}; const auto shortest_geometry{db_manager->GetShortestGeometry()}; @@ -1745,8 +1751,9 @@ GTEST_TEST(DBManager, GetGeometriesLengthInformation) { // Loads Highway.xodr and verifies the shortest and largest LaneSection in the XODR. GTEST_TEST(DBManager, GetLaneSectionLengthInformation) { const double kTolerance{1e-14}; - const std::string kXodrFile = "odr/Highway.xodr"; - const auto db_manager = LoadDataBaseFromFile(utility::FindResource(kXodrFile), {constants::kLinearTolerance}); + const std::string kXodrFile = "Highway.xodr"; + const auto db_manager = LoadDataBaseFromFile(utility::FindResourceInPath(kXodrFile, kMalidriveResourceFolder), + {constants::kLinearTolerance}); const DBManager::XodrLaneSectionLengthData kExpectedShortest{RoadHeader::Id("4"), 0, 1.1649945427797022}; const DBManager::XodrLaneSectionLengthData kExpectedLargest{RoadHeader::Id("11"), 0, 2.9161454554383585e+2}; const auto shortest_lane_section{db_manager->GetShortestLaneSection()}; @@ -1762,8 +1769,9 @@ GTEST_TEST(DBManager, GetLaneSectionLengthInformation) { // Loads TShapeRoad.xodr and verifies the shortest and largest GAP between Geometries in the XODR. GTEST_TEST(DBManager, GetGeometriesGapInformation) { const double kTolerance{1e-14}; - const std::string kXodrFile = "odr/TShapeRoad.xodr"; - const auto db_manager = LoadDataBaseFromFile(utility::FindResource(kXodrFile), {constants::kLinearTolerance}); + const std::string kXodrFile = "TShapeRoad.xodr"; + const auto db_manager = LoadDataBaseFromFile(utility::FindResourceInPath(kXodrFile, kMalidriveResourceFolder), + {constants::kLinearTolerance}); const DBManager::XodrGapBetweenGeometries kExpectedShortest{RoadHeader::Id("6"), {2, 3}, 0.}; const DBManager::XodrGapBetweenGeometries kExpectedLargest{RoadHeader::Id("6"), {1, 2}, 1.77636e-15}; const auto shortest_geometry{db_manager->GetShortestGap()};