From 2a8f9629aeda611125a0d7d47760d6dbcb377857 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Tue, 25 Apr 2023 22:24:10 +0300 Subject: [PATCH] tests: attempt to fix build without lua --- test/CMakeLists.txt | 5 ++++- test/battle/CBattleInfoCallbackTest.cpp | 13 +++++++++++++ test/mock/BattleFake.cpp | 11 +++++++---- test/mock/BattleFake.h | 10 ++++++++++ test/mock/mock_IBattleInfoCallback.h | 2 ++ test/mock/mock_IGameCallback.h | 3 +++ test/mock/mock_Services.h | 2 ++ test/mock/mock_spells_Mechanics.h | 2 ++ test/scripting/ScriptFixture.h | 2 ++ test/spells/effects/EffectFixture.cpp | 5 ++++- test/spells/effects/EffectFixture.h | 6 ++++++ 11 files changed, 55 insertions(+), 6 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fb6aaeb39..a93848651 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -172,12 +172,15 @@ if(COPY) endif() check_cxx_compiler_flag(-Wvirtual-move-assign MOVE_ASSIGN) if(MOVE_ASSIGN) - add_compile_options(-Wno-virtual-move-assign) #GCC is too strict here + add_compile_options(-Wno-error=virtual-move-assign) #GCC is too strict here endif() add_subdirectory_with_folder("3rdparty" googletest EXCLUDE_FROM_ALL) add_executable(vcmitest ${test_SRCS} ${test_HEADERS} ${mock_HEADERS}) target_link_libraries(vcmitest PRIVATE gtest gmock vcmi ${SYSTEM_LIBS}) +if(ENABLE_LUA) + target_link_libraries(vcmitest PRIVATE vcmiLua) +endif() target_include_directories(vcmitest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/test/battle/CBattleInfoCallbackTest.cpp b/test/battle/CBattleInfoCallbackTest.cpp index 730eb7ed4..810bca927 100644 --- a/test/battle/CBattleInfoCallbackTest.cpp +++ b/test/battle/CBattleInfoCallbackTest.cpp @@ -19,7 +19,9 @@ #include "mock/mock_BonusBearer.h" #include "mock/mock_battle_IBattleState.h" #include "mock/mock_battle_Unit.h" +#if SCRIPTING_ENABLED #include "mock/mock_scripting_Pool.h" +#endif using namespace battle; using namespace testing; @@ -122,11 +124,16 @@ public: { public: +#if SCRIPTING_ENABLED scripting::Pool * pool; TestSubject(scripting::Pool * p) : CBattleInfoCallback(), pool(p) +#else + TestSubject() + : CBattleInfoCallback() +#endif { } @@ -135,13 +142,17 @@ public: CBattleInfoCallback::setBattle(battleInfo); } +#if SCRIPTING_ENABLED scripting::Pool * getContextPool() const override { return pool; } +#endif }; +#if SCRIPTING_ENABLED StrictMock pool; +#endif TestSubject subject; @@ -149,8 +160,10 @@ public: UnitsFake unitsFake; CBattleInfoCallbackTest() +#if SCRIPTING_ENABLED : pool(), subject(&pool) +#endif { } diff --git a/test/mock/BattleFake.cpp b/test/mock/BattleFake.cpp index f7bf0d595..b1e2af5c4 100644 --- a/test/mock/BattleFake.cpp +++ b/test/mock/BattleFake.cpp @@ -76,12 +76,14 @@ void UnitsFake::setDefaultBonusExpectations() BattleFake::~BattleFake() = default; -BattleFake::BattleFake(std::shared_ptr pool_) - : CBattleInfoCallback(), - BattleStateMock(), +#if SCRIPTING_ENABLED +BattleFake::BattleFake(std::shared_ptr pool_): pool(pool_) { } +#else +BattleFake::BattleFake() = default; +#endif void BattleFake::setUp() { @@ -95,11 +97,12 @@ void BattleFake::setupEmptyBattlefield() EXPECT_CALL(*this, getBattlefieldType()).WillRepeatedly(Return(BattleField::fromString("grass_hills"))); } - +#if SCRIPTING_ENABLED scripting::Pool * BattleFake::getContextPool() const { return pool.get(); } +#endif } } diff --git a/test/mock/BattleFake.h b/test/mock/BattleFake.h index e225f3267..9c9287dac 100644 --- a/test/mock/BattleFake.h +++ b/test/mock/BattleFake.h @@ -15,7 +15,9 @@ #include "mock_BonusBearer.h" #include "mock_battle_IBattleState.h" #include "mock_battle_Unit.h" +#if SCRIPTING_ENABLED #include "mock_scripting_Pool.h" +#endif #include "../../lib/JsonNode.h" #include "../../lib/NetPacksBase.h" @@ -61,16 +63,24 @@ public: class BattleFake : public CBattleInfoCallback, public BattleStateMock { +#if SCRIPTING_ENABLED std::shared_ptr pool; +#endif public: +#if SCRIPTING_ENABLED BattleFake(std::shared_ptr pool_); +#else + BattleFake(); +#endif virtual ~BattleFake(); void setUp(); void setupEmptyBattlefield(); +#if SCRIPTING_ENABLED scripting::Pool * getContextPool() const override; +#endif template void accept(T * pack) diff --git a/test/mock/mock_IBattleInfoCallback.h b/test/mock/mock_IBattleInfoCallback.h index 94fd2dbbb..402439524 100644 --- a/test/mock/mock_IBattleInfoCallback.h +++ b/test/mock/mock_IBattleInfoCallback.h @@ -16,7 +16,9 @@ class IBattleInfoCallbackMock : public IBattleInfoCallback { public: +#if SCRIPTING_ENABLED MOCK_CONST_METHOD0(getContextPool, scripting::Pool *()); +#endif MOCK_CONST_METHOD0(battleTerrainType, TerrainId()); MOCK_CONST_METHOD0(battleGetBattlefieldType, BattleField()); diff --git a/test/mock/mock_IGameCallback.h b/test/mock/mock_IGameCallback.h index 5e0176765..2aadaea3a 100644 --- a/test/mock/mock_IGameCallback.h +++ b/test/mock/mock_IGameCallback.h @@ -91,7 +91,10 @@ public: ///useful callback methods void sendAndApply(CPackForClient * pack) override; +#if SCRIPTING_ENABLED MOCK_CONST_METHOD0(getGlobalContextPool, scripting::Pool *()); +#endif + private: UpperCallback * upperCallback; }; diff --git a/test/mock/mock_Services.h b/test/mock/mock_Services.h index 3a28ae3cb..00330beb8 100644 --- a/test/mock/mock_Services.h +++ b/test/mock/mock_Services.h @@ -21,7 +21,9 @@ public: MOCK_CONST_METHOD0(factions, const FactionService *()); MOCK_CONST_METHOD0(heroClasses, const HeroClassService *()); MOCK_CONST_METHOD0(heroTypes, const HeroTypeService *()); +#if SCRIPTING_ENABLED MOCK_CONST_METHOD0(scripts, const scripting::Service *()); +#endif MOCK_CONST_METHOD0(spells, const spells::Service *()); MOCK_CONST_METHOD0(skills, const SkillService * ()); MOCK_CONST_METHOD0(battlefields, const BattleFieldService *()); diff --git a/test/mock/mock_spells_Mechanics.h b/test/mock/mock_spells_Mechanics.h index 6c759d261..550b9912d 100644 --- a/test/mock/mock_spells_Mechanics.h +++ b/test/mock/mock_spells_Mechanics.h @@ -70,7 +70,9 @@ public: MOCK_CONST_METHOD2(ownerMatches, bool(const battle::Unit *, const boost::logic::tribool)); MOCK_CONST_METHOD0(creatures, const CreatureService *()); +#if SCRIPTING_ENABLED MOCK_CONST_METHOD0(scripts, const scripting::Service *()); +#endif MOCK_CONST_METHOD0(spells, const Service *()); MOCK_CONST_METHOD0(game, const IGameInfoCallback * ()); diff --git a/test/scripting/ScriptFixture.h b/test/scripting/ScriptFixture.h index b1c74e0fa..50a650688 100644 --- a/test/scripting/ScriptFixture.h +++ b/test/scripting/ScriptFixture.h @@ -24,7 +24,9 @@ #include "../mock/mock_IBattleInfoCallback.h" #include "../mock/mock_IGameInfoCallback.h" #include "../mock/mock_battle_IBattleState.h" +#if SCRIPTING_ENABLED #include "../mock/mock_scripting_Pool.h" +#endif #include "../mock/mock_Environment.h" #include "../mock/mock_Services.h" #include "../mock/mock_vstd_CLoggerBase.h" diff --git a/test/spells/effects/EffectFixture.cpp b/test/spells/effects/EffectFixture.cpp index b39539a44..0395700aa 100644 --- a/test/spells/effects/EffectFixture.cpp +++ b/test/spells/effects/EffectFixture.cpp @@ -72,9 +72,12 @@ void EffectFixture::setupEffect(Registry * registry, const JsonNode & effectConf void EffectFixture::setUp() { +#if SCRIPTING_ENABLED pool = std::make_shared(); - battleFake = std::make_shared(pool); +#else + battleFake = std::make_shared(); +#endif battleFake->setUp(); EXPECT_CALL(mechanicsMock, game()).WillRepeatedly(Return(&gameMock)); diff --git a/test/spells/effects/EffectFixture.h b/test/spells/effects/EffectFixture.h index c7ec5085e..bc07ae1fa 100644 --- a/test/spells/effects/EffectFixture.h +++ b/test/spells/effects/EffectFixture.h @@ -26,7 +26,9 @@ #include "../../mock/mock_battle_IBattleState.h" #include "../../mock/mock_battle_Unit.h" #include "../../mock/mock_vstd_RNG.h" +#if SCRIPTING_ENABLED #include "../../mock/mock_scripting_Pool.h" +#endif #include "../../mock/BattleFake.h" #include "../../mock/mock_ServerCallback.h" @@ -48,7 +50,9 @@ namespace test using namespace ::testing; using namespace ::spells; using namespace ::spells::effects; +#if SCRIPTING_ENABLED using namespace ::scripting; +#endif class EffectFixture { @@ -65,7 +69,9 @@ public: battle::UnitsFake unitsFake; +#if SCRIPTING_ENABLED std::shared_ptr pool; +#endif std::shared_ptr battleFake; StrictMock serverMock;