LCOV - code coverage report
Current view: top level - tests/core - RssResponseResolvingTests.cpp (source / functions) Hit Total Coverage
Test: ad_rss Lines: 123 123 100.0 %
Date: 2024-04-23 14:35:54 Functions: 23 23 100.0 %
Branches: 57 162 35.2 %

           Branch data     Line data    Source code
       1                 :            : // ----------------- BEGIN LICENSE BLOCK ---------------------------------
       2                 :            : //
       3                 :            : // Copyright (C) 2018-2021 Intel Corporation
       4                 :            : //
       5                 :            : // SPDX-License-Identifier: LGPL-2.1-only
       6                 :            : //
       7                 :            : // ----------------- END LICENSE BLOCK -----------------------------------
       8                 :            : 
       9                 :            : #include "TestSupport.hpp"
      10                 :            : #include "ad/rss/core/RssResponseResolving.hpp"
      11                 :            : 
      12                 :            : namespace ad {
      13                 :            : namespace rss {
      14                 :            : namespace core {
      15                 :            : 
      16                 :            : using state::LateralResponse;
      17                 :            : using state::LongitudinalResponse;
      18                 :            : 
      19                 :            : class RssResponseResolvingTests : public testing::Test
      20                 :            : {
      21                 :            : protected:
      22                 :          9 :   void SetUp() override
      23                 :            :   {
      24                 :         18 :     state::RssState rssStateT1O1;
      25                 :         18 :     state::RssState rssStateT1O2;
      26                 :         18 :     state::RssState rssStateT2O1;
      27                 :         18 :     state::RssState rssStateT2O2;
      28                 :         18 :     state::RssState rssStateT3O1;
      29                 :         18 :     state::RssState rssStateT3O2;
      30         [ +  - ]:          9 :     resetRssState(rssStateT1O1, 1u, 1u, situation::SituationType::SameDirection);
      31         [ +  - ]:          9 :     resetRssState(rssStateT1O2, 2u, 2u, situation::SituationType::SameDirection);
      32         [ +  - ]:          9 :     resetRssState(rssStateT2O1, 1u, 1u, situation::SituationType::SameDirection);
      33         [ +  - ]:          9 :     resetRssState(rssStateT2O2, 2u, 2u, situation::SituationType::SameDirection);
      34         [ +  - ]:          9 :     resetRssState(rssStateT3O1, 1u, 1u, situation::SituationType::SameDirection);
      35         [ +  - ]:          9 :     resetRssState(rssStateT3O2, 2u, 2u, situation::SituationType::SameDirection);
      36                 :          9 :     rssStateSnapshotT1.timeIndex = 1u;
      37         [ +  - ]:          9 :     rssStateSnapshotT1.defaultEgoVehicleRssDynamics = getEgoRssDynamics();
      38         [ +  - ]:          9 :     rssStateSnapshotT1.individualResponses.push_back(rssStateT1O1);
      39         [ +  - ]:          9 :     rssStateSnapshotT1.individualResponses.push_back(rssStateT1O2);
      40                 :            : 
      41                 :          9 :     rssStateSnapshotT2.timeIndex = 2u;
      42         [ +  - ]:          9 :     rssStateSnapshotT2.defaultEgoVehicleRssDynamics = getEgoRssDynamics();
      43         [ +  - ]:          9 :     rssStateSnapshotT2.individualResponses.push_back(rssStateT2O1);
      44         [ +  - ]:          9 :     rssStateSnapshotT2.individualResponses.push_back(rssStateT2O2);
      45                 :            : 
      46                 :          9 :     rssStateSnapshotT3.timeIndex = 3u;
      47         [ +  - ]:          9 :     rssStateSnapshotT3.defaultEgoVehicleRssDynamics = getEgoRssDynamics();
      48         [ +  - ]:          9 :     rssStateSnapshotT3.individualResponses.push_back(rssStateT3O1);
      49         [ +  - ]:          9 :     rssStateSnapshotT3.individualResponses.push_back(rssStateT3O2);
      50                 :            : 
      51         [ +  - ]:          9 :     resetRssState(resultProperResponseT1);
      52         [ +  - ]:          9 :     resetRssState(resultProperResponseT2);
      53         [ +  - ]:          9 :     resetRssState(resultProperResponseT3);
      54                 :          9 :   }
      55                 :            : 
      56                 :          9 :   void TearDown() override
      57                 :            :   {
      58                 :          9 :   }
      59                 :            : 
      60                 :         14 :   void testResultStateNone(state::ProperResponse &resultProperResponse)
      61                 :            :   {
      62         [ +  - ]:         14 :     testResultState(
      63                 :            :       resultProperResponse, true, LongitudinalResponse::None, LateralResponse::None, LateralResponse::None);
      64                 :         14 :   }
      65                 :            : 
      66                 :         23 :   void testResultState(state::ProperResponse &resultProperResponse,
      67                 :            :                        bool isSafe,
      68                 :            :                        LongitudinalResponse lonResponse,
      69                 :            :                        LateralResponse latResponseLeft,
      70                 :            :                        LateralResponse latResponseRight,
      71                 :            :                        world::ObjectIdVector dangerousObjects = world::ObjectIdVector())
      72                 :            :   {
      73   [ +  -  -  +  :         23 :     EXPECT_EQ(isSafe, resultProperResponse.isSafe);
          -  -  -  -  -  
                      - ]
      74   [ +  -  -  +  :         23 :     EXPECT_EQ(lonResponse, resultProperResponse.longitudinalResponse);
          -  -  -  -  -  
                      - ]
      75   [ +  -  -  +  :         23 :     EXPECT_EQ(latResponseLeft, resultProperResponse.lateralResponseLeft);
          -  -  -  -  -  
                      - ]
      76   [ +  -  -  +  :         23 :     EXPECT_EQ(latResponseRight, resultProperResponse.lateralResponseRight);
          -  -  -  -  -  
                      - ]
      77   [ +  -  -  +  :         23 :     EXPECT_EQ(dangerousObjects, resultProperResponse.dangerousObjects);
          -  -  -  -  -  
                      - ]
      78                 :         23 :   }
      79                 :            : 
      80                 :          9 :   void performTest(bool expectedResultT1 = true, bool expectedResultT2 = true, bool expectedResultT3 = true)
      81                 :            :   {
      82         [ +  - ]:          9 :     RssResponseResolving provider;
      83                 :            : 
      84   [ +  -  +  -  :          9 :     EXPECT_EQ(expectedResultT1, provider.provideProperResponse(rssStateSnapshotT1, resultProperResponseT1));
          -  +  -  -  -  
                -  -  - ]
      85   [ +  -  +  -  :          9 :     EXPECT_EQ(expectedResultT2, provider.provideProperResponse(rssStateSnapshotT2, resultProperResponseT2));
          -  +  -  -  -  
                -  -  - ]
      86   [ +  -  +  -  :          9 :     EXPECT_EQ(expectedResultT3, provider.provideProperResponse(rssStateSnapshotT3, resultProperResponseT3));
          -  +  -  -  -  
                -  -  - ]
      87                 :          9 :   }
      88                 :            : 
      89                 :            :   state::RssStateSnapshot rssStateSnapshotT1;
      90                 :            :   state::RssStateSnapshot rssStateSnapshotT2;
      91                 :            :   state::RssStateSnapshot rssStateSnapshotT3;
      92                 :            : 
      93                 :            :   state::ProperResponse resultProperResponseT1;
      94                 :            :   state::ProperResponse resultProperResponseT2;
      95                 :            :   state::ProperResponse resultProperResponseT3;
      96                 :            : };
      97                 :            : 
      98                 :          2 : TEST_F(RssResponseResolvingTests, validateTestSetup)
      99                 :            : {
     100                 :          1 :   performTest(true);
     101                 :          1 :   testResultStateNone(resultProperResponseT1);
     102                 :          1 :   testResultStateNone(resultProperResponseT2);
     103                 :          1 :   testResultStateNone(resultProperResponseT3);
     104                 :          1 : }
     105                 :            : 
     106                 :          2 : TEST_F(RssResponseResolvingTests, invalidState)
     107                 :            : {
     108                 :          1 :   rssStateSnapshotT1.individualResponses[0].longitudinalState.response = LongitudinalResponse(-1);
     109                 :          1 :   performTest(false);
     110                 :          1 : }
     111                 :            : 
     112                 :          2 : TEST_F(RssResponseResolvingTests, provideProperResponseLateralLeft)
     113                 :            : {
     114                 :          1 :   setRssStateUnsafe(rssStateSnapshotT1.individualResponses[0].longitudinalState, LongitudinalResponse::None);
     115                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].longitudinalState, LongitudinalResponse::None);
     116                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].lateralStateLeft, LateralResponse::BrakeMin);
     117                 :            : 
     118                 :          1 :   performTest();
     119                 :          1 :   testResultStateNone(resultProperResponseT1);
     120         [ +  - ]:          2 :   testResultState(
     121         [ +  - ]:          1 :     resultProperResponseT2, false, LongitudinalResponse::None, LateralResponse::BrakeMin, LateralResponse::None, {1});
     122                 :          1 :   testResultStateNone(resultProperResponseT3);
     123                 :          1 : }
     124                 :            : 
     125                 :          2 : TEST_F(RssResponseResolvingTests, provideProperResponseLateralRight)
     126                 :            : {
     127                 :          1 :   setRssStateUnsafe(rssStateSnapshotT1.individualResponses[0].longitudinalState, LongitudinalResponse::BrakeMin);
     128                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].longitudinalState, LongitudinalResponse::BrakeMin);
     129                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     130                 :            : 
     131                 :          1 :   performTest();
     132                 :          1 :   testResultStateNone(resultProperResponseT1);
     133   [ +  -  +  - ]:          1 :   testResultState(resultProperResponseT2,
     134                 :            :                   false,
     135                 :            :                   LongitudinalResponse::BrakeMin,
     136                 :            :                   LateralResponse::None,
     137                 :            :                   LateralResponse::BrakeMin,
     138                 :            :                   {1});
     139                 :          1 :   testResultStateNone(resultProperResponseT3);
     140                 :          1 : }
     141                 :            : 
     142                 :          2 : TEST_F(RssResponseResolvingTests, provideProperResponseLongitudinal)
     143                 :            : {
     144                 :          1 :   setRssStateUnsafe(rssStateSnapshotT1.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     145                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].longitudinalState, LongitudinalResponse::BrakeMin);
     146                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     147                 :            : 
     148                 :          1 :   performTest();
     149                 :          1 :   testResultStateNone(resultProperResponseT1);
     150   [ +  -  +  - ]:          1 :   testResultState(resultProperResponseT2,
     151                 :            :                   false,
     152                 :            :                   LongitudinalResponse::BrakeMin,
     153                 :            :                   LateralResponse::None,
     154                 :            :                   LateralResponse::BrakeMin,
     155                 :            :                   {1});
     156                 :          1 :   testResultStateNone(resultProperResponseT3);
     157                 :          1 : }
     158                 :            : 
     159                 :          2 : TEST_F(RssResponseResolvingTests, provideProperResponseLongitudinal_None)
     160                 :            : {
     161                 :          1 :   setRssStateUnsafe(rssStateSnapshotT1.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     162                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].longitudinalState, LongitudinalResponse::None);
     163                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     164                 :            : 
     165                 :          1 :   performTest();
     166                 :          1 :   testResultStateNone(resultProperResponseT1);
     167         [ +  - ]:          2 :   testResultState(
     168         [ +  - ]:          1 :     resultProperResponseT2, false, LongitudinalResponse::None, LateralResponse::None, LateralResponse::BrakeMin, {1});
     169                 :          1 : }
     170                 :            : 
     171                 :          2 : TEST_F(RssResponseResolvingTests, provideProperResponseBothDirections)
     172                 :            : {
     173                 :          1 :   setRssStateUnsafe(rssStateSnapshotT1.individualResponses[0].longitudinalState, LongitudinalResponse::BrakeMin);
     174                 :          1 :   setRssStateUnsafe(rssStateSnapshotT1.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     175                 :            : 
     176                 :          1 :   performTest();
     177   [ +  -  +  - ]:          1 :   testResultState(resultProperResponseT1,
     178                 :            :                   false,
     179                 :            :                   LongitudinalResponse::BrakeMin,
     180                 :            :                   LateralResponse::None,
     181                 :            :                   LateralResponse::BrakeMin,
     182                 :            :                   {1});
     183                 :          1 :   testResultStateNone(resultProperResponseT2);
     184                 :          1 :   testResultStateNone(resultProperResponseT3);
     185                 :          1 : }
     186                 :            : 
     187                 :          2 : TEST_F(RssResponseResolvingTests, provideProperResponseLongitudinalMoreSevere)
     188                 :            : {
     189                 :          1 :   setRssStateUnsafe(rssStateSnapshotT1.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     190                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].longitudinalState, LongitudinalResponse::BrakeMinCorrect);
     191                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     192                 :          1 :   setRssStateUnsafe(rssStateSnapshotT3.individualResponses[0].longitudinalState, LongitudinalResponse::BrakeMin);
     193                 :          1 :   setRssStateUnsafe(rssStateSnapshotT3.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     194                 :            : 
     195                 :          1 :   performTest();
     196                 :          1 :   testResultStateNone(resultProperResponseT1);
     197   [ +  -  +  - ]:          1 :   testResultState(resultProperResponseT2,
     198                 :            :                   false,
     199                 :            :                   LongitudinalResponse::BrakeMinCorrect,
     200                 :            :                   LateralResponse::None,
     201                 :            :                   LateralResponse::BrakeMin,
     202                 :            :                   {1});
     203   [ +  -  +  - ]:          1 :   testResultState(resultProperResponseT3,
     204                 :            :                   false,
     205                 :            :                   LongitudinalResponse::BrakeMin,
     206                 :            :                   LateralResponse::None,
     207                 :            :                   LateralResponse::BrakeMin,
     208                 :            :                   {1});
     209                 :          1 : }
     210                 :            : 
     211                 :          2 : TEST_F(RssResponseResolvingTests, provideProperResponseDangerousInitialState)
     212                 :            : {
     213                 :          1 :   setRssStateUnsafe(rssStateSnapshotT1.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     214                 :          1 :   setRssStateUnsafe(rssStateSnapshotT1.individualResponses[0].longitudinalState, LongitudinalResponse::BrakeMin);
     215                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].lateralStateRight, LateralResponse::BrakeMin);
     216                 :          1 :   setRssStateUnsafe(rssStateSnapshotT2.individualResponses[0].longitudinalState, LongitudinalResponse::BrakeMin);
     217                 :            : 
     218                 :          1 :   performTest();
     219   [ +  -  +  - ]:          1 :   testResultState(resultProperResponseT1,
     220                 :            :                   false,
     221                 :            :                   LongitudinalResponse::BrakeMin,
     222                 :            :                   LateralResponse::None,
     223                 :            :                   LateralResponse::BrakeMin,
     224                 :            :                   {1});
     225   [ +  -  +  - ]:          1 :   testResultState(resultProperResponseT2,
     226                 :            :                   false,
     227                 :            :                   LongitudinalResponse::BrakeMin,
     228                 :            :                   LateralResponse::None,
     229                 :            :                   LateralResponse::BrakeMin,
     230                 :            :                   {1});
     231                 :          1 :   testResultStateNone(resultProperResponseT3);
     232                 :          1 : }
     233                 :            : 
     234                 :            : } // namespace core
     235                 :            : } // namespace rss
     236                 :            : } // namespace ad

Generated by: LCOV version 1.14