LCOV - code coverage report
Current view: top level - tests/access - AdMapAccessTests.cpp (source / functions) Hit Total Coverage
Test: ad_map_access Lines: 76 79 96.2 %
Date: 2022-10-04 09:48:07 Functions: 10 10 100.0 %
Branches: 118 440 26.8 %

           Branch data     Line data    Source code
       1                 :            : // ----------------- BEGIN LICENSE BLOCK ---------------------------------
       2                 :            : //
       3                 :            : // Copyright (C) 2018-2021 Intel Corporation
       4                 :            : //
       5                 :            : // SPDX-License-Identifier: MIT
       6                 :            : //
       7                 :            : // ----------------- END LICENSE BLOCK -----------------------------------
       8                 :            : 
       9                 :            : #include <ad/map/access/Factory.hpp>
      10                 :            : #include <ad/map/access/Operation.hpp>
      11                 :            : #include <ad/map/lane/LaneOperation.hpp>
      12                 :            : #include <ad/map/point/Operation.hpp>
      13                 :            : #include <ad/map/test_support/NoLogTestMacros.hpp>
      14                 :            : 
      15                 :            : #include <fstream>
      16                 :            : #include <gtest/gtest.h>
      17                 :            : #include <streambuf>
      18                 :            : #include <string>
      19                 :            : 
      20                 :            : using namespace ::ad;
      21                 :            : using namespace ::ad::map;
      22                 :            : using namespace ::ad::map::point;
      23                 :            : 
      24                 :            : struct AdMapAccessTest : ::testing::Test
      25                 :            : {
      26                 :          4 :   virtual void SetUp()
      27                 :            :   {
      28                 :          4 :     access::cleanup();
      29                 :          4 :   }
      30                 :          4 :   virtual void TearDown()
      31                 :            :   {
      32                 :          4 :     access::cleanup();
      33                 :          4 :   }
      34                 :            : };
      35                 :            : 
      36                 :          2 : TEST_F(AdMapAccessTest, read_map)
      37                 :            : {
      38   [ +  -  +  -  :          1 :   ASSERT_TRUE(access::init("test_files/TPK.adm.txt"));
          -  +  -  -  -  
             -  -  -  -  
                      - ]
      39                 :            : 
      40                 :          1 :   point::Longitude validLon(8.4372);
      41                 :          1 :   point::Latitude validLat(49.02);
      42                 :          1 :   point::Altitude validAlt(0.);
      43                 :            : 
      44                 :          1 :   auto p = point::createGeoPoint(validLon, validLat, validAlt);
      45   [ +  -  +  -  :          1 :   EXPECT_NO_THROW(access::setENUReferencePoint(p));
          +  -  +  -  +  
          -  -  -  -  -  
             -  -  -  - ]
      46                 :            : 
      47         [ +  - ]:          1 :   auto lanes = lane::getLanes();
      48   [ +  -  -  +  :          1 :   ASSERT_GT(lanes.size(), 0u);
          -  -  -  -  -  
                      - ]
      49                 :            : }
      50                 :            : 
      51                 :          2 : TEST_F(AdMapAccessTest, initialize)
      52                 :            : {
      53   [ +  -  +  -  :          2 :   ASSERT_FALSE_NO_LOG(access::init("invalid/non_existent.txt"));
          +  -  -  +  -  
          -  -  -  -  -  
                   -  - ]
      54                 :            : 
      55   [ +  -  +  -  :          1 :   ASSERT_TRUE(access::init("test_files/TPK.adm.txt"));
          -  +  -  -  -  
             -  -  -  -  
                      - ]
      56   [ +  -  -  +  :          1 :   ASSERT_TRUE(access::isENUReferencePointSet());
          -  -  -  -  -  
                -  -  - ]
      57                 :            : 
      58   [ +  -  +  -  :          1 :   ASSERT_TRUE(access::init("test_files/TPK.adm.txt"));
          -  +  -  -  -  
             -  -  -  -  
                      - ]
      59                 :            : 
      60   [ +  -  +  -  :          2 :   ASSERT_FALSE_NO_LOG(access::init("test_files/TPK_PFZ.adm.txt"));
          +  -  -  +  -  
          -  -  -  -  -  
                   -  - ]
      61                 :            : }
      62                 :            : 
      63                 :          2 : TEST_F(AdMapAccessTest, initializeFromOpenDriveContent)
      64                 :            : {
      65         [ +  - ]:          1 :   std::ifstream mapFile("test_files/Town01.xodr");
      66         [ +  - ]:          1 :   std::stringstream openDriveContentStream;
      67                 :            : 
      68   [ +  -  +  - ]:          1 :   openDriveContentStream << mapFile.rdbuf();
      69         [ +  - ]:          1 :   std::string openDriveContent = openDriveContentStream.str();
      70                 :            : 
      71   [ +  -  +  -  :          2 :   ASSERT_FALSE_NO_LOG(
          +  -  +  -  -  
          +  -  -  -  -  
          -  -  -  -  +  
                      - ]
      72                 :            :     access::initFromOpenDriveContent(std::string(), 0.2, intersection::IntersectionType::TrafficLight));
      73                 :            : 
      74   [ +  -  -  +  :          1 :   ASSERT_TRUE(access::initFromOpenDriveContent(openDriveContent, 0.2, intersection::IntersectionType::TrafficLight));
          -  -  -  -  -  
                -  -  - ]
      75                 :            : 
      76                 :            :   // twice the same initialization works
      77   [ +  -  -  +  :          1 :   ASSERT_TRUE(access::initFromOpenDriveContent(openDriveContent, 0.2, intersection::IntersectionType::TrafficLight));
          -  -  -  -  -  
                -  -  - ]
      78                 :            : 
      79         [ +  - ]:          1 :   std::ifstream mapFile3("test_files/Town03.xodr");
      80         [ +  - ]:          1 :   openDriveContentStream.clear();
      81   [ +  -  +  - ]:          1 :   openDriveContentStream << mapFile3.rdbuf();
      82         [ +  - ]:          1 :   openDriveContent = openDriveContentStream.str();
      83                 :            : 
      84                 :            :   // but different content fails
      85   [ +  -  +  -  :          2 :   ASSERT_FALSE_NO_LOG(
          +  -  +  -  -  
          +  -  -  -  -  
          -  -  -  -  +  
                      - ]
      86                 :            :     access::initFromOpenDriveContent(openDriveContent, 0.2, intersection::IntersectionType::TrafficLight));
      87                 :            : 
      88         [ +  - ]:          1 :   access::cleanup();
      89                 :            : 
      90   [ +  -  +  -  :          1 :   ASSERT_TRUE(access::init("test_files/TPK.adm.txt"));
          -  +  -  -  -  
             -  -  -  -  
                      - ]
      91   [ +  -  +  -  :          2 :   ASSERT_FALSE_NO_LOG(
          +  -  +  -  -  
          +  -  -  -  -  
          -  -  -  -  +  
                      - ]
      92                 :            :     access::initFromOpenDriveContent(openDriveContent, 0.2, intersection::IntersectionType::TrafficLight));
      93                 :            : 
      94         [ +  - ]:          1 :   access::cleanup();
      95                 :          0 :   access::Store::Ptr mStorePtr;
      96                 :          0 :   std::shared_ptr<access::Factory> pFactory;
      97   [ +  -  +  -  :          1 :   ASSERT_FALSE(access::init("test_files/bad/TPK.adm.bad0.txt"));
          -  +  -  -  -  
             -  -  -  -  
                      - ]
      98   [ +  -  +  -  :          1 :   ASSERT_FALSE(access::init("test_files/bad/TPK.adm.bad1.txt"));
          -  +  -  -  -  
             -  -  -  -  
                      - ]
      99   [ +  -  +  -  :          1 :   ASSERT_FALSE(access::init("test_files/bad/TPK.adm.bad2.txt"));
          -  +  -  -  -  
             -  -  -  -  
                      - ]
     100   [ +  -  +  -  :          1 :   ASSERT_FALSE(access::init("test_files/bad/TPK.adm.bad3.txt"));
          -  +  -  -  -  
             -  -  -  -  
                      - ]
     101                 :            : 
     102   [ +  -  +  -  :          1 :   mStorePtr.reset(new access::Store());
                   +  - ]
     103   [ +  -  +  - ]:          1 :   pFactory.reset(new access::Factory(*mStorePtr));
     104                 :            : 
     105                 :          1 :   ECEFEdge rightPoints, leftPoints;
     106         [ +  - ]:          1 :   leftPoints.push_back(
     107         [ +  - ]:          1 :     toECEF(createGeoPoint(point::Longitude(8.44933898), point::Latitude(49.00737633), point::Altitude(0.))));
     108         [ +  - ]:          1 :   leftPoints.push_back(
     109         [ +  - ]:          1 :     toECEF(createGeoPoint(point::Longitude(8.45006151), point::Latitude(49.00885163), point::Altitude(0.))));
     110         [ +  - ]:          1 :   rightPoints.push_back(
     111         [ +  - ]:          1 :     toECEF(createGeoPoint(point::Longitude(8.44937788), point::Latitude(49.00736837), point::Altitude(0.))));
     112         [ +  - ]:          1 :   rightPoints.push_back(
     113         [ +  - ]:          1 :     toECEF(createGeoPoint(point::Longitude(8.45010064), point::Latitude(49.00884320), point::Altitude(0.))));
     114                 :          1 :   point::Geometry geo1, geo2;
     115         [ +  - ]:          1 :   geo1 = point::createGeometry(leftPoints, false);
     116         [ +  - ]:          1 :   geo2 = point::createGeometry(rightPoints, false);
     117         [ +  - ]:          1 :   pFactory->set(access::TrafficType::RIGHT_HAND_TRAFFIC);
     118         [ +  - ]:          1 :   pFactory->add(access::PartitionId(0), lane::LaneId(11), lane::LaneType::NORMAL, lane::LaneDirection::POSITIVE);
     119         [ +  - ]:          1 :   pFactory->set(lane::LaneId(11), geo1, geo2);
     120                 :            : 
     121   [ +  -  +  -  :          1 :   ASSERT_TRUE(access::init("test_files/TPK.adm.txt"));
          -  +  -  -  -  
             -  -  -  -  
                      - ]
     122                 :          0 :   access::Store::Ptr emptyStore;
     123   [ +  -  -  +  :          1 :   ASSERT_FALSE(access::init(emptyStore));
          -  -  -  -  -  
                -  -  - ]
     124   [ +  -  -  +  :          1 :   ASSERT_FALSE(access::init(mStorePtr));
          -  -  -  -  -  
                -  -  - ]
     125         [ +  - ]:          1 :   access::cleanup();
     126                 :            : 
     127   [ +  -  -  +  :          1 :   ASSERT_TRUE(access::init(mStorePtr));
          -  -  -  -  -  
                -  -  - ]
     128   [ +  -  -  +  :          1 :   ASSERT_TRUE(access::init(mStorePtr));
          -  -  -  -  -  
                -  -  - ]
     129   [ +  -  +  -  :          1 :   ASSERT_FALSE(access::init("test_files/TPK.adm.txt"));
          -  +  -  -  -  
             -  -  -  -  
                      - ]
     130                 :            : 
     131   [ +  -  +  -  :          1 :   emptyStore.reset(new access::Store());
                   +  - ]
     132   [ +  -  -  +  :          1 :   ASSERT_FALSE(access::init(emptyStore));
          -  -  -  -  -  
                -  -  - ]
     133                 :            : }
     134                 :            : 
     135                 :          2 : TEST_F(AdMapAccessTest, readMap_no_reader)
     136                 :            : {
     137                 :          1 :   point::Longitude validLon(8.4372);
     138                 :          1 :   point::Latitude validLat(49.02);
     139                 :          1 :   point::Altitude validAlt(0.);
     140                 :            : 
     141                 :            :   // nothing initialized throws exception
     142                 :          1 :   auto p = point::createGeoPoint(validLon, validLat, validAlt);
     143         [ +  - ]:          1 :   access::setENUReferencePoint(p);
     144   [ +  -  +  -  :          1 :   EXPECT_EQ(access::getENUReferencePoint(), p);
          -  +  -  -  -  
                -  -  - ]
     145                 :          1 : }

Generated by: LCOV version 1.14