| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/tests/src/test_sysmodel.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include <catch2/catch_all.hpp> |
| 5 | #include <catch2/trompeloeil.hpp> |
| 6 | |
| 7 | #include "common/commandqueuestub.h"cxx . . $ `<file>/tests/src/common/commandqueuestub.h`/ |
| 8 | #include "core/info/iswinfo.h"cxx . . $ `<file>/src/core/info/iswinfo.h`/ |
| 9 | #include "core/isyscomponent.h"cxx . . $ `<file>/src/core/isyscomponent.h`/ |
| 10 | #include "core/sysmodel.h"cxx . . $ `<file>/src/core/sysmodel.h`/ |
| 11 | |
| 12 | extern template struct trompeloeil::reportercxx . . $ trompeloeil/reporter#<trompeloeilcxx . . $ trompeloeil/::specializedcxx . . $ trompeloeil/specialized#>; |
| 13 | |
| 14 | namespace Testscxx . . $ Tests/::SysModelcxx . . $ Tests/SysModel/ { |
| 15 | |
| 16 | class SWInfoStubcxx . . $ Tests/SysModel/SWInfoStub# : public ISWInfocxx . . $ ISWInfo# |
| 17 | { |
| 18 | public: |
| 19 | stdcxx . . $ std/::stringcxx . . $ std/string# infocxx . . $ Tests/SysModel/SWInfoStub#info(3654cd48a63d288).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view#) const override |
| 20 | { |
| 21 | return "sw_info"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 22 | } |
| 23 | |
| 24 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> keyscxx . . $ Tests/SysModel/SWInfoStub#keys(491c255a7e496038).() const override |
| 25 | { |
| 26 | return {cxx . . $ std/vector#vector(9619226211e5a241)."sw_info_key"}; |
| 27 | } |
| 28 | |
| 29 | void initializecxx . . $ Tests/SysModel/SWInfoStub#initialize(97df72f1a8cecba1).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<ISWInfocxx . . $ ISWInfo#::IProvidercxx . . $ ISWInfo#IProvider#>> const &) override |
| 30 | { |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | class SysComponentMockcxx . . $ Tests/SysModel/SysComponentMock# : public ISysComponentcxx . . $ ISysComponent# |
| 35 | { |
| 36 | public: |
| 37 | MAKE_MOCK0cxx . . $ `<external>/1068432606165018960/mock.hpp:4222:9`!(init, void(), override); |
| 38 | MAKE_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4223:9`!(preInit, void(ICommandQueue &), override); |
| 39 | MAKE_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4223:9`!(postInit, void(ICommandQueue &), override); |
| 40 | |
| 41 | MAKE_CONST_MOCK0cxx . . $ `<external>/1068432606165018960/mock.hpp:4240:9`!(active, bool(), override); |
| 42 | MAKE_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4223:9`!(activate, void(bool), override); |
| 43 | MAKE_CONST_MOCK0cxx . . $ `<external>/1068432606165018960/mock.hpp:4240:9`!(key, std::string const &(), override); |
| 44 | |
| 45 | // trompeloeil fails to mock this method |
| 46 | stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>>> |
| 47 | componentInfocxx . . $ Tests/SysModel/SysComponentMock#componentInfo(e6b143d762ee67dc).() const override |
| 48 | { |
| 49 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>> cInfocxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 50 | cInfo.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).("c_info_key", "c_info"); |
| 51 | return {cxx . . $ std/pair#pair(62e1774a2dc03c82)."component", stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(cInfo)}; |
| 52 | } |
| 53 | |
| 54 | MAKE_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4223:9`!(sync, void(ICommandQueue &), override); |
| 55 | MAKE_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4223:9`!(updateSensors, |
| 56 | void(std::unordered_map<std::string, |
| 57 | std::unordered_set<std::string>> const &), |
| 58 | override); |
| 59 | MAKE_CONST_MOCK0cxx . . $ `<external>/1068432606165018960/mock.hpp:4240:9`!(ID, std::string const &(), override); |
| 60 | MAKE_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4223:9`!(importWith, void(Importable::Importer &), override); |
| 61 | MAKE_CONST_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4241:9`!(exportWith, void(Exportable::Exporter &), override); |
| 62 | }; |
| 63 | |
| 64 | class SysModelImporterStubcxx . . $ Tests/SysModel/SysModelImporterStub# : public ISysModelcxx . . $ ISysModel#::Importercxx . . $ ISysModel#Importer# |
| 65 | { |
| 66 | public: |
| 67 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Importablecxx . . $ Importable#::Importercxx . . $ Importable#Importer#>> |
| 68 | provideImportercxx . . $ Tests/SysModel/SysModelImporterStub#provideImporter(c13a3bcac0db4745).(Itemcxx . . $ Item# const &) override |
| 69 | { |
| 70 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).this; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | class SysModelExporterStubcxx . . $ Tests/SysModel/SysModelExporterStub# : public ISysModelcxx . . $ ISysModel#::Exportercxx . . $ ISysModel#Exporter# |
| 75 | { |
| 76 | public: |
| 77 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 78 | provideExportercxx . . $ Tests/SysModel/SysModelExporterStub#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &) override |
| 79 | { |
| 80 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).this; |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | TEST_CASEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:144:11`!("SysModel tests", "[SysModel]") |
| 85 | { |
| 86 | CommandQueueStubcxx . . $ CommandQueueStub# ctlCmds; |
| 87 | |
| 88 | auto info = stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<SWInfoStubcxx . . $ Tests/SysModel/SWInfoStub#>(); |
| 89 | |
| 90 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<ISysComponentcxx . . $ ISysComponent#>> componentscxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 91 | components.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<SysComponentMockcxx . . $ Tests/SysModel/SysComponentMock#>()); |
| 92 | auto &componentMock = static_cast<SysComponentMockcxx . . $ Tests/SysModel/SysComponentMock# &>(*cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).components[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]); |
| 93 | |
| 94 | ::SysModelcxx . . $ SysModel# tscxx . . $ SysModel#SysModel(c88aed7df17b1d75).(stdcxx . . $ std/shared_ptr#shared_ptr(9ad45c7d2296bc38).::movecxx . . $ std/move(e35c19a1ba7baa26).(info), stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(components)); |
| 95 | |
| 96 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Has ISysModel ID") |
| 97 | { |
| 98 | REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(ts.ID() == ISysModel::ItemID); |
| 99 | } |
| 100 | |
| 101 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Pre-init components") |
| 102 | { |
| 103 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(componentMock, preInit(trompeloeil::_)); |
| 104 | ts.preInitcxx . . $ SysModel#preInit(151e9138769f295e).(ctlCmds); |
| 105 | } |
| 106 | |
| 107 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Init components") |
| 108 | { |
| 109 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(componentMock, init()); |
| 110 | ts.initcxx . . $ SysModel#init(49f6e7a06ebc5aa8).(); |
| 111 | } |
| 112 | |
| 113 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Post-init components") |
| 114 | { |
| 115 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(componentMock, postInit(trompeloeil::_)); |
| 116 | ts.postInitcxx . . $ SysModel#postInit(151e9138769f295e).(ctlCmds); |
| 117 | } |
| 118 | |
| 119 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Update component's sensors") |
| 120 | { |
| 121 | stdcxx . . $ std/::unordered_mapcxx . . $ std/unordered_map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::unordered_setcxx . . $ std/unordered_set#<stdcxx . . $ std/::stringcxx . . $ std/string#>> ignoredcxx . . $ std/unordered_map#unordered_map(49f6e7a06ebc5aa8).; |
| 122 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(componentMock, updateSensors(trompeloeil::_)) |
| 123 | .LR_WITHcxx . . $ `<external>/1068432606165018960/mock.hpp:4345:9`!(&_1 == &ignored); |
| 124 | ts.updateSensorscxx . . $ SysModel#updateSensors(b9a76d75a3ae6a25).(ignored); |
| 125 | } |
| 126 | |
| 127 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Sync components") |
| 128 | { |
| 129 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(componentMock, sync(trompeloeil::_)); |
| 130 | ts.synccxx . . $ SysModel#sync(151e9138769f295e).(ctlCmds); |
| 131 | } |
| 132 | |
| 133 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("System info can be retrieved") |
| 134 | { |
| 135 | auto sysInfo = ts.infocxx . . $ SysModel#info(909f45ca661bc315).(); |
| 136 | |
| 137 | REQUIRE_FALSEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:128:11`!(sysInfo.empty()); |
| 138 | |
| 139 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Software info is always present") |
| 140 | { |
| 141 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>> swInfoDatacxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 142 | swInfoData.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).("sw_info_key", "sw_info"); |
| 143 | auto swInfo = stdcxx . . $ std/::make_paircxx . . $ std/make_pair(1d30b6e115203116).(stdcxx . . $ std/::stringcxx . . $ std/string#("Software"), |
| 144 | stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(swInfoData)); |
| 145 | |
| 146 | REQUIRE_THATcxx . . $ `<external>/3333208929440565380/catch_matchers.hpp:222:11`!(sysInfo, Catch::Matchers::VectorContains(swInfo)); |
| 147 | } |
| 148 | |
| 149 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Has components info") |
| 150 | { |
| 151 | auto compInfo = componentMock.componentInfocxx . . $ Tests/SysModel/SysComponentMock#componentInfo(e6b143d762ee67dc).(); |
| 152 | |
| 153 | REQUIRE_THATcxx . . $ `<external>/3333208929440565380/catch_matchers.hpp:222:11`!(sysInfo, Catch::Matchers::VectorContains(compInfo)); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Imports its components") |
| 158 | { |
| 159 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(componentMock, importWith(trompeloeil::_)); |
| 160 | |
| 161 | SysModelImporterStubcxx . . $ Tests/SysModel/SysModelImporterStub# i; |
| 162 | ts.importWithcxx . . $ SysModel#importWith(94eddebf9440278).(i); |
| 163 | } |
| 164 | |
| 165 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Exports its components") |
| 166 | { |
| 167 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(componentMock, exportWith(trompeloeil::_)); |
| 168 | |
| 169 | SysModelExporterStubcxx . . $ Tests/SysModel/SysModelExporterStub# e; |
| 170 | ts.exportWithcxx . . $ SysModel#exportWith(5b5c94ff60635419).(e); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | } // namespace Tests::SysModel |