Skip to content

Commit 1e0ec1d

Browse files
committed
add test
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
1 parent 051d227 commit 1e0ec1d

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2024 TIER IV, Inc.
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 <autoware/geography_utils/lanelet2_projector.hpp>
16+
#include <autoware_lanelet2_extension/projection/mgrs_projector.hpp>
17+
#include <autoware_lanelet2_extension/projection/transverse_mercator_projector.hpp>
18+
19+
#include <gtest/gtest.h>
20+
21+
#include <lanelet2_projection/UTM.h>
22+
#include <memory>
23+
#include <stdexcept>
24+
25+
TEST(GeographyUtilsLanelet2Projector, GetMGRSProjector)
26+
{
27+
autoware_map_msgs::msg::MapProjectorInfo projector_info;
28+
projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::MGRS;
29+
projector_info.mgrs_grid = "54SUE";
30+
projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84;
31+
32+
std::unique_ptr<lanelet::Projector> projector =
33+
autoware::geography_utils::get_lanelet2_projector(projector_info);
34+
35+
// Check if the returned projector is of type MGRSProjector
36+
EXPECT_NE(dynamic_cast<lanelet::projection::MGRSProjector*>(projector.get()), nullptr);
37+
}
38+
39+
TEST(GeographyUtilsLanelet2Projector, GetLocalCartesianUTMProjector)
40+
{
41+
autoware_map_msgs::msg::MapProjectorInfo projector_info;
42+
projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::LOCAL_CARTESIAN_UTM;
43+
projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84;
44+
projector_info.map_origin.latitude = 35.62426;
45+
projector_info.map_origin.longitude = 139.74252;
46+
projector_info.map_origin.altitude = 0.0;
47+
48+
std::unique_ptr<lanelet::Projector> projector =
49+
autoware::geography_utils::get_lanelet2_projector(projector_info);
50+
51+
// Check if the returned projector is of type UtmProjector
52+
EXPECT_NE(dynamic_cast<lanelet::projection::UtmProjector*>(projector.get()), nullptr);
53+
}
54+
55+
TEST(GeographyUtilsLanelet2Projector, GetTransverseMercatorProjector)
56+
{
57+
autoware_map_msgs::msg::MapProjectorInfo projector_info;
58+
projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::TRANSVERSE_MERCATOR;
59+
projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84;
60+
projector_info.map_origin.latitude = 35.62426;
61+
projector_info.map_origin.longitude = 139.74252;
62+
projector_info.map_origin.altitude = 0.0;
63+
64+
std::unique_ptr<lanelet::Projector> projector =
65+
autoware::geography_utils::get_lanelet2_projector(projector_info);
66+
67+
// Check if the returned projector is of type TransverseMercatorProjector
68+
EXPECT_NE(dynamic_cast<lanelet::projection::TransverseMercatorProjector*>(projector.get()), nullptr);
69+
}
70+
71+
TEST(GeographyUtilsLanelet2Projector, InvalidProjectorType)
72+
{
73+
autoware_map_msgs::msg::MapProjectorInfo projector_info;
74+
projector_info.projector_type = "INVALID_TYPE";
75+
projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84;
76+
77+
// Check if the function throws an invalid_argument exception for invalid projector type
78+
EXPECT_THROW(
79+
autoware::geography_utils::get_lanelet2_projector(projector_info),
80+
std::invalid_argument);
81+
}

0 commit comments

Comments
 (0)