Branch data Line data Source code
1 : : // ----------------- BEGIN LICENSE BLOCK --------------------------------- 2 : : // 3 : : // Copyright (C) 2019-2021 Intel Corporation 4 : : // 5 : : // SPDX-License-Identifier: LGPL-2.1-only 6 : : // 7 : : // ----------------- END LICENSE BLOCK ----------------------------------- 8 : : 9 : : #pragma once 10 : : 11 : : #include <ad/map/access/Logging.hpp> 12 : : #include <ad/map/access/Operation.hpp> 13 : : #include <ad/rss/map/Logging.hpp> 14 : : #include <fstream> 15 : : #include <gtest/gtest.h> 16 : : #include <streambuf> 17 : : #include "RssObjectAdapterTest.hpp" 18 : : 19 : : namespace ad { 20 : : namespace rss { 21 : : namespace map { 22 : : namespace test_support { 23 : : 24 : : struct RssMapIntegrationTestBase : public ::testing::Test 25 : : { 26 : : typedef RssObjectAdapterTest::ObjectGeoLocationTuple ObjectGeoLocationTuple; 27 : : 28 : : enum class MapToLoad 29 : : { 30 : : Town01, 31 : : Town04, 32 : : None 33 : : }; 34 : : 35 : : virtual MapToLoad getMapToLoad() = 0; 36 : : 37 : 219 : void initMap() 38 : : { 39 : : static MapToLoad loadedMap = MapToLoad::None; 40 : : 41 : 219 : MapToLoad mapToLoad = getMapToLoad(); 42 [ + + ]: 219 : if (mapToLoad != loadedMap) 43 : : { 44 : 2 : ::ad::map::access::cleanup(); 45 [ + + - ]: 2 : switch (mapToLoad) 46 : : { 47 : 1 : case MapToLoad::Town01: 48 : : // using priority to the right intersections 49 [ + - + - : 1 : ASSERT_TRUE(::ad::map::access::init("resources/Town01.txt")); - + - - - - - - - - + - ] 50 : 1 : break; 51 : 1 : case MapToLoad::Town04: 52 : : { 53 [ + - ]: 1 : std::ifstream fileStream("resources/Town04.xodr"); 54 : : std::string town04OpenDriveContent((std::istreambuf_iterator<char>(fileStream)), 55 [ + - ]: 1 : std::istreambuf_iterator<char>()); 56 [ + - - + : 1 : ASSERT_TRUE(::ad::map::access::initFromOpenDriveContent( - - - - - - - - ] 57 [ + - ]: 1 : town04OpenDriveContent, 0.2, ::ad::map::intersection::IntersectionType::TrafficLight)); 58 : 1 : break; 59 [ - + - + ]: 2 : } 60 : 0 : case MapToLoad::None: 61 : : default: 62 [ # # # # : 0 : ASSERT_TRUE(false); # # # # # # # # ] 63 : 0 : break; 64 : : } 65 : 2 : loadedMap = mapToLoad; 66 : : } 67 : : } 68 : : 69 : 219 : void SetUp() override 70 : : { 71 : : //::ad::rss::map::getLogger()->set_level(spdlog::level::trace); 72 : : //::ad::map::access::getLogger()->set_level(spdlog::level::trace); 73 : 219 : initMap(); 74 : 219 : mCheckerControlTest = std::make_shared<CheckerControlTest>(); 75 : 219 : } 76 : : 77 : : enum class TestMode 78 : : { 79 : : withRouteWithSpeedLimit, 80 : : withoutRouteWithoutSpeedLimit 81 : : }; 82 : : virtual TestMode getTestMode() = 0; 83 : : 84 : : /*! 85 : : * @brief create ego vehicle at startLocation 86 : : * 87 : : * - fills RssEgoVehicleAdapterTest::mTestRoute and RssEgoVehicleAdapterTest::mTestMatchObject 88 : : * if test mode is with route and targetLocation is valid 89 : : */ 90 : : RssEgoVehicleAdapterTest::Ptr 91 : 221 : createEgoVehicle(::ad::rss::world::ObjectId const object_id, 92 : : ObjectGeoLocationTuple const &startLocation, 93 : : ::ad::map::point::GeoPoint const &targetLocation = ::ad::map::point::GeoPoint(), 94 : : ObjectGeoLocationTuple const ¤tLocation = ObjectGeoLocationTuple()) 95 : : { 96 : : auto ego_vehicle_instance = std::make_shared<RssObjectInstanceTest>( 97 [ + - ]: 221 : object_id, ::ad::rss::world::ObjectType::EgoVehicle, mCheckerControlTest); 98 [ + - ]: 221 : auto ego_vehicle = std::make_shared<RssEgoVehicleAdapterTest>(ego_vehicle_instance, startLocation); 99 : 221 : ego_vehicle->speed_range.minimum = ::ad::physics::Speed(5.); 100 : 221 : ego_vehicle->speed_range.maximum = ::ad::physics::Speed(7.); 101 : : 102 : 221 : bool routePrepared = false; 103 [ + - + + : 221 : if ((getTestMode() == TestMode::withRouteWithSpeedLimit) && isValid(targetLocation, false)) + - + - + + ] 104 : : { 105 : 152 : mCheckerControlTest->mRestrictSpeedLimitMode = ::ad::rss::map::RssRestrictSpeedLimitMode::IncreasedSpeedLimit10; 106 [ + - + - : 152 : mCheckerControlTest->replaceRoutingTargets(object_id, {RssObjectAdapterTest::getENUPoint(targetLocation)}); + - ] 107 [ + - ]: 152 : ego_vehicle->prepareRoute(); 108 : 152 : routePrepared = true; 109 : : } 110 : : 111 [ + - ]: 221 : ego_vehicle->updatePosition(currentLocation); 112 [ + + ]: 221 : if (routePrepared) 113 : : { 114 [ + - ]: 152 : ego_vehicle->prepareMatchPosition(); 115 [ + - ]: 152 : ego_vehicle->shortenRoute(); 116 : : } 117 : 442 : return ego_vehicle; 118 : 221 : } 119 : : 120 : : /*! 121 : : * @brief create vehicle at startLocation 122 : : */ 123 : 217 : RssVehicleAdapterTest::Ptr createOtherVehicle(::ad::rss::world::ObjectId const object_id, 124 : : ObjectGeoLocationTuple const &startLocation) 125 : : { 126 : : auto other_vehicle_instance = std::make_shared<RssObjectInstanceTest>( 127 [ + - ]: 217 : object_id, ::ad::rss::world::ObjectType::OtherVehicle, mCheckerControlTest); 128 [ + - ]: 217 : auto otherVehicle = std::make_shared<RssVehicleAdapterTest>(other_vehicle_instance, startLocation); 129 : 217 : otherVehicle->speed_range.minimum = ::ad::physics::Speed(5.); 130 : 217 : otherVehicle->speed_range.maximum = ::ad::physics::Speed(7.); 131 : 434 : return otherVehicle; 132 : 217 : } 133 : : 134 : : /*! 135 : : * @brief create pedestrian at startLocation 136 : : */ 137 : 1 : RssPedestrianAdapterTest::Ptr createPedestrian(::ad::rss::world::ObjectId const object_id, 138 : : ObjectGeoLocationTuple const &startLocation) 139 : : { 140 : : auto pedestrian_instance = std::make_shared<RssObjectInstanceTest>( 141 [ + - ]: 1 : object_id, ::ad::rss::world::ObjectType::Pedestrian, mCheckerControlTest); 142 [ + - ]: 1 : auto pedestrian = std::make_shared<RssPedestrianAdapterTest>(pedestrian_instance, startLocation); 143 : 1 : pedestrian->speed_range.minimum = ::ad::physics::Speed(1.); 144 : 1 : pedestrian->speed_range.maximum = ::ad::physics::Speed(1.); 145 : 2 : return pedestrian; 146 : 1 : } 147 : : 148 : : // make static to get rid of virtual inheritance warning 149 : : static std::shared_ptr<CheckerControlTest> mCheckerControlTest; 150 : : }; 151 : : 152 : : } // namespace test_support 153 : : } // namespace map 154 : : } // namespace rss 155 : : } // namespace ad