1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

tests: attempt to fix build without lua

This commit is contained in:
Konstantin 2023-04-25 22:24:10 +03:00 committed by Konstantin P
parent f03819fba2
commit 2a8f9629ae
11 changed files with 55 additions and 6 deletions

View File

@ -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}

View File

@ -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<scripting::PoolMock> pool;
#endif
TestSubject subject;
@ -149,8 +160,10 @@ public:
UnitsFake unitsFake;
CBattleInfoCallbackTest()
#if SCRIPTING_ENABLED
: pool(),
subject(&pool)
#endif
{
}

View File

@ -76,12 +76,14 @@ void UnitsFake::setDefaultBonusExpectations()
BattleFake::~BattleFake() = default;
BattleFake::BattleFake(std::shared_ptr<scripting::PoolMock> pool_)
: CBattleInfoCallback(),
BattleStateMock(),
#if SCRIPTING_ENABLED
BattleFake::BattleFake(std::shared_ptr<scripting::PoolMock> 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
}
}

View File

@ -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<scripting::PoolMock> pool;
#endif
public:
#if SCRIPTING_ENABLED
BattleFake(std::shared_ptr<scripting::PoolMock> pool_);
#else
BattleFake();
#endif
virtual ~BattleFake();
void setUp();
void setupEmptyBattlefield();
#if SCRIPTING_ENABLED
scripting::Pool * getContextPool() const override;
#endif
template <typename T>
void accept(T * pack)

View File

@ -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());

View File

@ -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;
};

View File

@ -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 *());

View File

@ -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 * ());

View File

@ -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"

View File

@ -72,9 +72,12 @@ void EffectFixture::setupEffect(Registry * registry, const JsonNode & effectConf
void EffectFixture::setUp()
{
#if SCRIPTING_ENABLED
pool = std::make_shared<PoolMock>();
battleFake = std::make_shared<battle::BattleFake>(pool);
#else
battleFake = std::make_shared<battle::BattleFake>();
#endif
battleFake->setUp();
EXPECT_CALL(mechanicsMock, game()).WillRepeatedly(Return(&gameMock));

View File

@ -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<PoolMock> pool;
#endif
std::shared_ptr<battle::BattleFake> battleFake;
StrictMock<ServerCallbackMock> serverMock;