From c1eb46ab60183e129f9ca96c8ade9c64fa9a1abd Mon Sep 17 00:00:00 2001 From: Yutaka Kondo Date: Wed, 18 Dec 2024 11:09:20 +0900 Subject: [PATCH] test(autoware_geography_utils): add `lanelet2_projector` test (#128) * add test Signed-off-by: Yutaka Kondo * style(pre-commit): autofix --------- Signed-off-by: Yutaka Kondo Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../test/test_lanelet2_projector.cpp | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 common/autoware_geography_utils/test/test_lanelet2_projector.cpp diff --git a/common/autoware_geography_utils/test/test_lanelet2_projector.cpp b/common/autoware_geography_utils/test/test_lanelet2_projector.cpp new file mode 100644 index 0000000000..cb646890f4 --- /dev/null +++ b/common/autoware_geography_utils/test/test_lanelet2_projector.cpp @@ -0,0 +1,81 @@ +// Copyright 2024 TIER IV, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include +#include + +#include +#include + +TEST(GeographyUtilsLanelet2Projector, GetMGRSProjector) +{ + autoware_map_msgs::msg::MapProjectorInfo projector_info; + projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::MGRS; + projector_info.mgrs_grid = "54SUE"; + projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84; + + std::unique_ptr projector = + autoware::geography_utils::get_lanelet2_projector(projector_info); + + // Check if the returned projector is of type MGRSProjector + EXPECT_NE(dynamic_cast(projector.get()), nullptr); +} + +TEST(GeographyUtilsLanelet2Projector, GetLocalCartesianUTMProjector) +{ + autoware_map_msgs::msg::MapProjectorInfo projector_info; + projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::LOCAL_CARTESIAN_UTM; + projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84; + projector_info.map_origin.latitude = 35.62426; + projector_info.map_origin.longitude = 139.74252; + projector_info.map_origin.altitude = 0.0; + + std::unique_ptr projector = + autoware::geography_utils::get_lanelet2_projector(projector_info); + + // Check if the returned projector is of type UtmProjector + EXPECT_NE(dynamic_cast(projector.get()), nullptr); +} + +TEST(GeographyUtilsLanelet2Projector, GetTransverseMercatorProjector) +{ + autoware_map_msgs::msg::MapProjectorInfo projector_info; + projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::TRANSVERSE_MERCATOR; + projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84; + projector_info.map_origin.latitude = 35.62426; + projector_info.map_origin.longitude = 139.74252; + projector_info.map_origin.altitude = 0.0; + + std::unique_ptr projector = + autoware::geography_utils::get_lanelet2_projector(projector_info); + + // Check if the returned projector is of type TransverseMercatorProjector + EXPECT_NE( + dynamic_cast(projector.get()), nullptr); +} + +TEST(GeographyUtilsLanelet2Projector, InvalidProjectorType) +{ + autoware_map_msgs::msg::MapProjectorInfo projector_info; + projector_info.projector_type = "INVALID_TYPE"; + projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84; + + // Check if the function throws an invalid_argument exception for invalid projector type + EXPECT_THROW( + autoware::geography_utils::get_lanelet2_projector(projector_info), std::invalid_argument); +}