LCOV - code coverage report
Current view: top level - src/core - RssCheck.cpp (source / functions) Hit Total Coverage
Test: ad_rss Lines: 28 28 100.0 %
Date: 2024-04-16 14:13:10 Functions: 4 4 100.0 %
Branches: 28 42 66.7 %

           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 "ad/rss/core/RssCheck.hpp"
      10                 :            : #include "ad/rss/core/RssResponseResolving.hpp"
      11                 :            : #include "ad/rss/core/RssSituationChecking.hpp"
      12                 :            : #include "ad/rss/core/RssSituationExtraction.hpp"
      13                 :            : #include "spdlog/fmt/ostr.h"
      14                 :            : #include "spdlog/spdlog.h"
      15                 :            : 
      16                 :            : namespace ad {
      17                 :            : namespace rss {
      18                 :            : namespace core {
      19                 :            : 
      20                 :        739 : RssCheck::RssCheck()
      21                 :            : {
      22                 :            :   try
      23                 :            :   {
      24   [ +  +  +  - ]:        739 :     mResponseResolving = std::unique_ptr<RssResponseResolving>(new RssResponseResolving());
      25   [ +  +  +  - ]:        726 :     mSituationChecking = std::unique_ptr<RssSituationChecking>(new RssSituationChecking());
      26   [ +  +  +  - ]:        713 :     mSituationExtraction = std::unique_ptr<RssSituationExtraction>(new RssSituationExtraction());
      27                 :            :   }
      28         [ +  - ]:         78 :   catch (...)
      29                 :            :   {
      30         [ +  - ]:         39 :     spdlog::critical("RssCheck object initialization failed");
      31                 :         39 :     mResponseResolving = nullptr;
      32                 :         39 :     mSituationChecking = nullptr;
      33                 :         39 :     mSituationExtraction = nullptr;
      34                 :            :   }
      35                 :        739 : }
      36                 :            : 
      37                 :        739 : RssCheck::~RssCheck()
      38                 :            : {
      39                 :        739 : }
      40                 :            : 
      41                 :       4269 : bool RssCheck::calculateProperResponse(world::WorldModel const &worldModel,
      42                 :            :                                        situation::SituationSnapshot &situationSnapshot,
      43                 :            :                                        state::RssStateSnapshot &rssStateSnapshot,
      44                 :            :                                        state::ProperResponse &properResponse)
      45                 :            : {
      46                 :       4269 :   bool result = false;
      47                 :            :   // global try catch block to ensure this library call doesn't throw an exception
      48                 :            :   try
      49                 :            :   {
      50         [ +  - ]:       8499 :     if (!static_cast<bool>(mResponseResolving) || !static_cast<bool>(mSituationChecking)
      51   [ +  +  -  +  :       8499 :         || !static_cast<bool>(mSituationExtraction))
                   +  + ]
      52                 :            :     {
      53         [ +  - ]:         39 :       spdlog::critical("RssCheck::calculateProperResponse>> object not properly initialized");
      54                 :         39 :       return false;
      55                 :            :     }
      56                 :            : 
      57         [ +  - ]:       4230 :     result = mSituationExtraction->extractSituations(worldModel, situationSnapshot);
      58                 :            : 
      59         [ +  + ]:       4230 :     if (result)
      60                 :            :     {
      61         [ +  - ]:       3933 :       result = mSituationChecking->checkSituations(situationSnapshot, rssStateSnapshot);
      62                 :            :     }
      63                 :            : 
      64         [ +  + ]:       4230 :     if (result)
      65                 :            :     {
      66         [ +  - ]:       3840 :       result = mResponseResolving->provideProperResponse(rssStateSnapshot, properResponse);
      67                 :            :     }
      68                 :            :   }
      69                 :            :   // LCOV_EXCL_START: unreachable code, keep to be on the safe side
      70                 :            :   catch (...)
      71                 :            :   {
      72                 :            :     spdlog::critical("RssCheck::calculateProperResponse>> Exception caught");
      73                 :            :     result = false;
      74                 :            :   }
      75                 :            :   // LCOV_EXCL_STOP: unreachable code, keep to be on the safe side
      76                 :       4230 :   return result;
      77                 :            : }
      78                 :            : 
      79                 :       4268 : bool RssCheck::calculateProperResponse(world::WorldModel const &worldModel, state::ProperResponse &properResponse)
      80                 :            : {
      81         [ +  - ]:       8536 :   situation::SituationSnapshot situationSnapshot;
      82         [ +  - ]:       8536 :   state::RssStateSnapshot rssStateSnapshot;
      83                 :            : 
      84         [ +  - ]:       8536 :   return calculateProperResponse(worldModel, situationSnapshot, rssStateSnapshot, properResponse);
      85                 :            : }
      86                 :            : 
      87                 :            : } // namespace core
      88                 :            : } // namespace rss
      89                 :            : } // namespace ad

Generated by: LCOV version 1.14