scenario_simulator_v2 C++ API
common_test_fixtures.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
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 #ifndef TRAFFIC_SIMULATOR__TEST__TRAFFIC_LIGHTS__COMMON_TEST_FIXTURES_HPP_
16 #define TRAFFIC_SIMULATOR__TEST__TRAFFIC_LIGHTS__COMMON_TEST_FIXTURES_HPP_
17 
18 #include <gtest/gtest.h>
19 
20 #include <ament_index_cpp/get_package_share_directory.hpp>
23 
24 constexpr char architecture_old[] = "awf/universe/20230906";
25 constexpr char architecture_new[] = "awf/universe/20240605";
26 
27 template <typename TrafficLightsT, const char * Architecture>
29 {
30 public:
32  : lights([this] {
33  if constexpr (std::is_same_v<TrafficLightsT, traffic_simulator::ConventionalTrafficLights>) {
34  return std::make_unique<TrafficLightsT>(node_ptr, hdmap_utils_ptr);
35  } else if constexpr (std::is_same_v<TrafficLightsT, traffic_simulator::V2ITrafficLights>) {
36  return std::make_unique<TrafficLightsT>(node_ptr, hdmap_utils_ptr, Architecture);
37  }
38  }())
39  {
40  static_assert(
41  std::is_same_v<TrafficLightsT, traffic_simulator::ConventionalTrafficLights> or
42  std::is_same_v<TrafficLightsT, traffic_simulator::V2ITrafficLights>,
43  "Given TrafficLights type is not supported");
44 
45  const auto lanelet_path = ament_index_cpp::get_package_share_directory("traffic_simulator") +
46  "/map/standard_map/lanelet2_map.osm";
48 
49  executor.add_node(node_ptr);
50  }
51 
52  const lanelet::Id id{34836};
53 
54  const lanelet::Id signal_id{34806};
55 
56  const rclcpp::Node::SharedPtr node_ptr = rclcpp::Node::make_shared("TrafficLightsInternalTest");
57 
58  rclcpp::executors::SingleThreadedExecutor executor;
59 
60  const std::string path = ament_index_cpp::get_package_share_directory("traffic_simulator") +
61  "/map/standard_map/lanelet2_map.osm";
62 
63  const std::shared_ptr<hdmap_utils::HdMapUtils> hdmap_utils_ptr =
64  std::make_shared<hdmap_utils::HdMapUtils>(
65  path, geographic_msgs::build<geographic_msgs::msg::GeoPoint>()
66  .latitude(35.61836750154)
67  .longitude(139.78066608243)
68  .altitude(0.0));
69 
70  std::unique_ptr<TrafficLightsT> lights;
71 };
72 
73 template <typename TrafficLightsT>
75 : public TrafficLightsInternalTestArchitectureDependent<TrafficLightsT, architecture_old>
76 {
77 };
78 
79 template <typename TrafficLightsT>
81 : public TrafficLightsInternalTestArchitectureDependent<TrafficLightsT, architecture_new>
82 {
83 };
84 
86 {
87  template <typename TrafficLightsT>
88  static auto GetName(int) -> std::string
89  {
90  if constexpr (std::is_same_v<TrafficLightsT, traffic_simulator::ConventionalTrafficLights>) {
91  return "ConventionalTrafficLights";
92  } else if constexpr (std::is_same_v<TrafficLightsT, traffic_simulator::V2ITrafficLights>) {
93  return "V2ITrafficLights";
94  }
95  }
96 };
97 #endif // TRAFFIC_SIMULATOR__TEST__TRAFFIC_LIGHTS__COMMON_TEST_FIXTURES_HPP_
Definition: common_test_fixtures.hpp:29
const std::shared_ptr< hdmap_utils::HdMapUtils > hdmap_utils_ptr
Definition: common_test_fixtures.hpp:63
const std::string path
Definition: common_test_fixtures.hpp:60
const rclcpp::Node::SharedPtr node_ptr
Definition: common_test_fixtures.hpp:56
std::unique_ptr< TrafficLightsT > lights
Definition: common_test_fixtures.hpp:70
const lanelet::Id signal_id
Definition: common_test_fixtures.hpp:54
TrafficLightsInternalTestArchitectureDependent()
Definition: common_test_fixtures.hpp:31
rclcpp::executors::SingleThreadedExecutor executor
Definition: common_test_fixtures.hpp:58
Definition: common_test_fixtures.hpp:82
Definition: common_test_fixtures.hpp:76
constexpr char architecture_old[]
Definition: common_test_fixtures.hpp:24
constexpr char architecture_new[]
Definition: common_test_fixtures.hpp:25
auto activate(Ts &&... xs)
Definition: lanelet_map.hpp:33
std::string string
Definition: junit5.hpp:26
Definition: common_test_fixtures.hpp:86
static auto GetName(int) -> std::string
Definition: common_test_fixtures.hpp:88