LCOV - code coverage report
Current view: top level - src/simlab - TestFailureScenarios.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 85.2 % 27 23
Test Date: 2026-04-10 19:03:25 Functions: 76.5 % 17 13

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2025 aeml
       3              :  *
       4              :  * This program is free software: you can redistribute it and/or modify
       5              :  * it under the terms of the GNU General Public License as published by
       6              :  * the Free Software Foundation, either version 3 of the License, or
       7              :  * (at your option) any later version.
       8              :  *
       9              :  * This program is distributed in the hope that it will be useful,
      10              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12              :  * GNU General Public License for more details.
      13              :  *
      14              :  * You should have received a copy of the GNU General Public License
      15              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      16              :  */
      17              : 
      18              : #include "simlab/Scenario.hpp"
      19              : 
      20              : #include "ecs/World.hpp"
      21              : 
      22              : #include <stdexcept>
      23              : #include <memory>
      24              : 
      25              : namespace simlab
      26              : {
      27              :     namespace
      28              :     {
      29              :         class FailSetupScenario final : public IScenario
      30              :         {
      31              :         public:
      32            2 :             void Setup(ecs::World&) override
      33              :             {
      34            2 :                 throw std::runtime_error("Test scenario setup failure");
      35              :             }
      36              : 
      37            0 :             void Update(ecs::World&, float) override {}
      38            0 :             void Render(ecs::World&, std::ostream&) override {}
      39              :         };
      40              : 
      41              :         class FailUpdateScenario final : public IScenario
      42              :         {
      43              :         public:
      44            1 :             void Setup(ecs::World&) override {}
      45              : 
      46            1 :             void Update(ecs::World&, float) override
      47              :             {
      48            1 :                 throw std::runtime_error("Test scenario update failure");
      49              :             }
      50              : 
      51            0 :             void Render(ecs::World&, std::ostream&) override {}
      52              :         };
      53              : 
      54              :         class ThrowingWorldUpdateSystem final : public ecs::ISystem
      55              :         {
      56              :         public:
      57            1 :             void Update(ecs::World&, float) override
      58              :             {
      59            1 :                 throw std::runtime_error("Test world update failure");
      60              :             }
      61              :         };
      62              : 
      63              :         class FailWorldUpdateScenario final : public IScenario
      64              :         {
      65              :         public:
      66            1 :             void Setup(ecs::World& world) override
      67              :             {
      68            1 :                 world.AddSystem(std::make_unique<ThrowingWorldUpdateSystem>());
      69            1 :             }
      70              : 
      71            1 :             void Update(ecs::World&, float) override {}
      72            0 :             void Render(ecs::World&, std::ostream&) override {}
      73              :         };
      74              : 
      75              :         class FailRenderScenario final : public IScenario
      76              :         {
      77              :         public:
      78            1 :             void Setup(ecs::World&) override {}
      79            1 :             void Update(ecs::World&, float) override {}
      80              : 
      81            1 :             void Render(ecs::World&, std::ostream&) override
      82              :             {
      83            1 :                 throw std::runtime_error("Test scenario render failure");
      84              :             }
      85              :         };
      86              :     }
      87              : 
      88            4 :     std::unique_ptr<IScenario> CreateFailSetupScenario()
      89              :     {
      90            4 :         return std::make_unique<FailSetupScenario>();
      91              :     }
      92              : 
      93            3 :     std::unique_ptr<IScenario> CreateFailUpdateScenario()
      94              :     {
      95            3 :         return std::make_unique<FailUpdateScenario>();
      96              :     }
      97              : 
      98            3 :     std::unique_ptr<IScenario> CreateFailWorldUpdateScenario()
      99              :     {
     100            3 :         return std::make_unique<FailWorldUpdateScenario>();
     101              :     }
     102              : 
     103            3 :     std::unique_ptr<IScenario> CreateFailRenderScenario()
     104              :     {
     105            3 :         return std::make_unique<FailRenderScenario>();
     106              :     }
     107              : }
        

Generated by: LCOV version 2.0-1