LCOV - code coverage report
Current view: top level - tests/landmark - LandmarkTestBase.hpp (source / functions) Hit Total Coverage
Test: ad_map_access Lines: 43 44 97.7 %
Date: 2022-10-04 09:48:07 Functions: 4 4 100.0 %
Branches: 47 140 33.6 %

           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 <gtest/gtest.h>
      10                 :            : 
      11                 :            : #include <ad/map/access/Factory.hpp>
      12                 :            : #include <ad/map/access/Operation.hpp>
      13                 :            : #include <ad/map/point/Operation.hpp>
      14                 :            : #include <ad/map/serialize/SerializerFileCRC32.hpp>
      15                 :            : 
      16                 :            : using namespace ::ad;
      17                 :            : using namespace ::ad::map;
      18                 :            : using namespace ::ad::map::point;
      19                 :            : 
      20                 :            : struct LandmarkTestBase : public ::testing::Test
      21                 :            : {
      22                 :          5 :   virtual void SetUp()
      23                 :            :   {
      24         [ +  - ]:          5 :     access::cleanup();
      25   [ +  -  +  -  :          5 :     access::Store::Ptr storePtr(new access::Store());
                   +  - ]
      26   [ +  -  +  - ]:          5 :     mFactory = std::shared_ptr<access::Factory>(new access::Factory(*storePtr));
      27         [ +  - ]:          5 :     mFactory->set(access::TrafficType::RIGHT_HAND_TRAFFIC);
      28                 :            : 
      29         [ +  - ]:          5 :     mLaneId = addLane();
      30   [ +  -  -  +  :          5 :     ASSERT_TRUE(isValid(mLaneId));
          -  -  -  -  -  
                -  -  - ]
      31   [ +  -  -  +  :          5 :     ASSERT_TRUE(access::init(storePtr));
          -  -  -  -  -  
                -  -  - ]
      32         [ +  - ]:          5 :     access::setENUReferencePoint(createGeoPoint(Longitude(8.4), Latitude(49.), Altitude(115.)));
      33                 :            :   }
      34                 :            : 
      35                 :          5 :   virtual void TearDown()
      36                 :            :   {
      37                 :          5 :     access::cleanup();
      38                 :          5 :   }
      39                 :            : 
      40                 :          7 :   lane::LaneId addLane()
      41                 :            :   {
      42   [ +  +  +  - ]:          7 :     static lane::LaneId currentLaneId(10);
      43         [ +  - ]:          7 :     currentLaneId = currentLaneId + lane::LaneId(1);
      44                 :          7 :     lane::LaneId laneId = currentLaneId;
      45                 :            : 
      46                 :            :     // create lane
      47         [ +  - ]:          7 :     auto laneAddResult = mFactory->add(mPartitionId, laneId, lane::LaneType::NORMAL, lane::LaneDirection::POSITIVE);
      48         [ +  - ]:          7 :     if (laneAddResult)
      49                 :            :     {
      50                 :            :       // left border
      51                 :         14 :       GeoEdge leftBorderPoints;
      52         [ +  - ]:          7 :       leftBorderPoints.push_back(createGeoPoint(Longitude(8.3), Latitude(49.2), Altitude(115.)));
      53         [ +  - ]:          7 :       leftBorderPoints.push_back(createGeoPoint(Longitude(8.5), Latitude(49.2), Altitude(115.)));
      54                 :            :       // right border
      55                 :          7 :       GeoEdge rightBorderPoints;
      56         [ +  - ]:          7 :       rightBorderPoints.push_back(createGeoPoint(Longitude(8.3), Latitude(49.), Altitude(115.)));
      57         [ +  - ]:          7 :       rightBorderPoints.push_back(createGeoPoint(Longitude(8.5), Latitude(49.), Altitude(115.)));
      58                 :            : 
      59         [ +  - ]:         14 :       laneAddResult = mFactory->set(
      60   [ +  -  +  -  :         14 :         laneId, createGeometry(toECEF(leftBorderPoints), false), createGeometry(toECEF(rightBorderPoints), false));
             +  -  +  - ]
      61                 :            :     }
      62                 :            : 
      63         [ -  + ]:          7 :     if (!laneAddResult)
      64                 :            :     {
      65                 :          0 :       laneId = lane::LaneId();
      66                 :            :     }
      67                 :            : 
      68                 :          7 :     return laneId;
      69                 :            :   }
      70                 :            : 
      71                 :          3 :   void reinitFromWrittenMap(std::string const &fileName)
      72                 :            :   {
      73                 :            :     // write the map
      74                 :          3 :     size_t version_major = 0;
      75                 :          3 :     size_t version_minor = 0;
      76         [ +  - ]:          6 :     serialize::SerializerFileCRC32 serializer(true);
      77         [ +  - ]:          3 :     serializer.open(fileName, version_major, version_minor);
      78   [ +  -  +  - ]:          3 :     access::getStore().save(serializer);
      79         [ +  - ]:          3 :     serializer.close();
      80                 :            : 
      81                 :            :     // read the map
      82   [ +  -  +  -  :          6 :     access::Store::Ptr storePtr(new access::Store());
                   +  - ]
      83         [ +  - ]:          6 :     serialize::SerializerFileCRC32 deserializer(false);
      84   [ +  -  -  +  :          3 :     EXPECT_TRUE(deserializer.open(fileName, version_major, version_minor));
          -  -  -  -  -  
                -  -  - ]
      85   [ +  -  -  +  :          3 :     EXPECT_TRUE(storePtr->load(deserializer));
          -  -  -  -  -  
                -  -  - ]
      86   [ +  -  -  +  :          3 :     EXPECT_TRUE(deserializer.close());
          -  -  -  -  -  
                -  -  - ]
      87                 :            : 
      88                 :            :     // reinit access interface
      89         [ +  - ]:          3 :     access::cleanup();
      90   [ +  -  -  +  :          3 :     EXPECT_TRUE(access::init(storePtr));
          -  -  -  -  -  
                -  -  - ]
      91                 :          3 :   }
      92                 :            : 
      93                 :            :   std::shared_ptr<access::Factory> mFactory;
      94                 :            :   access::PartitionId mPartitionId{0};
      95                 :            :   lane::LaneId mLaneId;
      96                 :            : };

Generated by: LCOV version 1.14