2017-07-20 06:08:49 +02:00
|
|
|
/*
|
|
|
|
* CBattleInfoCallbackTest.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "../../lib/battle/CBattleInfoCallback.h"
|
2022-06-28 10:05:30 +02:00
|
|
|
#include "../../lib/battle/CUnitState.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
#include <vstd/RNG.h>
|
|
|
|
|
|
|
|
#include "mock/mock_BonusBearer.h"
|
|
|
|
#include "mock/mock_battle_IBattleState.h"
|
|
|
|
#include "mock/mock_battle_Unit.h"
|
2023-04-25 21:24:10 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
#include "mock/mock_scripting_Pool.h"
|
2023-04-25 21:24:10 +02:00
|
|
|
#endif
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
using namespace battle;
|
|
|
|
using namespace testing;
|
|
|
|
|
|
|
|
class UnitFake : public UnitMock
|
|
|
|
{
|
2022-06-28 10:05:30 +02:00
|
|
|
private:
|
|
|
|
std::shared_ptr<CUnitState> state;
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
public:
|
2022-06-28 10:05:30 +02:00
|
|
|
UnitFake()
|
|
|
|
{
|
|
|
|
state.reset(new CUnitStateDetached(this, this));
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void addNewBonus(const std::shared_ptr<Bonus> & b)
|
|
|
|
{
|
|
|
|
bonusFake.addNewBonus(b);
|
|
|
|
}
|
|
|
|
|
2024-07-28 13:41:21 +02:00
|
|
|
void addCreatureAbility(BonusType bonusType)
|
|
|
|
{
|
|
|
|
addNewBonus(
|
|
|
|
std::make_shared<Bonus>(
|
|
|
|
BonusDuration::PERMANENT,
|
|
|
|
bonusType,
|
|
|
|
BonusSource::CREATURE_ABILITY,
|
|
|
|
0,
|
|
|
|
CreatureID(0)));
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void makeAlive()
|
|
|
|
{
|
|
|
|
EXPECT_CALL(*this, alive()).WillRepeatedly(Return(true));
|
|
|
|
}
|
|
|
|
|
2024-07-28 13:41:21 +02:00
|
|
|
void setupPoisition(BattleHex pos)
|
|
|
|
{
|
|
|
|
EXPECT_CALL(*this, getPosition()).WillRepeatedly(Return(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
void makeDoubleWide()
|
|
|
|
{
|
|
|
|
EXPECT_CALL(*this, doubleWide()).WillRepeatedly(Return(true));
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void makeWarMachine()
|
|
|
|
{
|
2023-10-21 13:50:42 +02:00
|
|
|
addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::SIEGE_WEAPON, BonusSource::CREATURE_ABILITY, 1, BonusSourceID()));
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void redirectBonusesToFake()
|
|
|
|
{
|
|
|
|
ON_CALL(*this, getAllBonuses(_, _, _, _)).WillByDefault(Invoke(&bonusFake, &BonusBearerMock::getAllBonuses));
|
|
|
|
ON_CALL(*this, getTreeVersion()).WillByDefault(Invoke(&bonusFake, &BonusBearerMock::getTreeVersion));
|
|
|
|
}
|
|
|
|
|
|
|
|
void expectAnyBonusSystemCall()
|
|
|
|
{
|
|
|
|
EXPECT_CALL(*this, getAllBonuses(_, _, _, _)).Times(AtLeast(0));
|
|
|
|
EXPECT_CALL(*this, getTreeVersion()).Times(AtLeast(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDefaultExpectations()
|
|
|
|
{
|
|
|
|
EXPECT_CALL(*this, unitSlot()).WillRepeatedly(Return(SlotID(0)));
|
|
|
|
EXPECT_CALL(*this, creatureIndex()).WillRepeatedly(Return(0));
|
|
|
|
}
|
2022-06-28 10:05:30 +02:00
|
|
|
|
|
|
|
void setDefaultState()
|
|
|
|
{
|
|
|
|
EXPECT_CALL(*this, isClone()).WillRepeatedly(Return(false));
|
|
|
|
EXPECT_CALL(*this, isCaster()).WillRepeatedly(Return(false));
|
|
|
|
EXPECT_CALL(*this, acquireState()).WillRepeatedly(Return(state));
|
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
private:
|
|
|
|
BonusBearerMock bonusFake;
|
|
|
|
};
|
|
|
|
|
|
|
|
class UnitsFake
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<std::shared_ptr<UnitFake>> allUnits;
|
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & add(BattleSide side)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2024-01-16 23:40:48 +02:00
|
|
|
auto * unit = new UnitFake();
|
2017-07-20 06:08:49 +02:00
|
|
|
EXPECT_CALL(*unit, unitSide()).WillRepeatedly(Return(side));
|
|
|
|
unit->setDefaultExpectations();
|
|
|
|
|
|
|
|
allUnits.emplace_back(unit);
|
|
|
|
return *allUnits.back().get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Units getUnitsIf(UnitFilter predicate) const
|
|
|
|
{
|
|
|
|
Units ret;
|
|
|
|
|
|
|
|
for(auto & unit : allUnits)
|
|
|
|
{
|
|
|
|
if(predicate(unit.get()))
|
|
|
|
ret.push_back(unit.get());
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDefaultBonusExpectations()
|
|
|
|
{
|
|
|
|
for(auto & unit : allUnits)
|
|
|
|
{
|
|
|
|
unit->redirectBonusesToFake();
|
|
|
|
unit->expectAnyBonusSystemCall();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CBattleInfoCallbackTest : public Test
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class TestSubject : public CBattleInfoCallback
|
|
|
|
{
|
|
|
|
public:
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
|
2023-08-31 22:36:39 +02:00
|
|
|
const IBattleInfo * battle;
|
2023-04-25 21:24:10 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
scripting::Pool * pool;
|
|
|
|
|
|
|
|
TestSubject(scripting::Pool * p)
|
|
|
|
: CBattleInfoCallback(),
|
|
|
|
pool(p)
|
2023-04-25 21:24:10 +02:00
|
|
|
#else
|
|
|
|
TestSubject()
|
|
|
|
: CBattleInfoCallback()
|
|
|
|
#endif
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-31 22:36:39 +02:00
|
|
|
const IBattleInfo * getBattle() const override
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2023-08-31 22:36:39 +02:00
|
|
|
return battle;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<PlayerColor> getPlayerID() const override
|
|
|
|
{
|
|
|
|
return std::nullopt;
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
|
2023-04-25 21:24:10 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
scripting::Pool * getContextPool() const override
|
|
|
|
{
|
|
|
|
return pool;
|
|
|
|
}
|
2023-04-25 21:24:10 +02:00
|
|
|
#endif
|
2017-07-20 06:08:49 +02:00
|
|
|
};
|
|
|
|
|
2023-04-25 21:24:10 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
StrictMock<scripting::PoolMock> pool;
|
2023-04-25 21:24:10 +02:00
|
|
|
#endif
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
TestSubject subject;
|
|
|
|
|
|
|
|
BattleStateMock battleMock;
|
|
|
|
UnitsFake unitsFake;
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
CBattleInfoCallbackTest()
|
2023-04-25 21:24:10 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
: pool(),
|
|
|
|
subject(&pool)
|
2023-04-25 21:24:10 +02:00
|
|
|
#endif
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void startBattle()
|
|
|
|
{
|
2023-08-31 22:36:39 +02:00
|
|
|
subject.battle = &battleMock;
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void redirectUnitsToFake()
|
|
|
|
{
|
|
|
|
ON_CALL(battleMock, getUnitsIf(_)).WillByDefault(Invoke(&unitsFake, &UnitsFake::getUnitsIf));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-07-28 13:41:21 +02:00
|
|
|
class AttackableHexesTest : public CBattleInfoCallbackTest
|
|
|
|
{
|
|
|
|
public:
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & addRegularMelee(BattleHex hex, BattleSide side)
|
2024-07-28 13:41:21 +02:00
|
|
|
{
|
|
|
|
auto & unit = unitsFake.add(side);
|
|
|
|
|
|
|
|
unit.makeAlive();
|
|
|
|
unit.setDefaultState();
|
|
|
|
unit.setupPoisition(hex);
|
|
|
|
unit.redirectBonusesToFake();
|
|
|
|
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & addDragon(BattleHex hex, BattleSide side)
|
2024-07-28 13:41:21 +02:00
|
|
|
{
|
|
|
|
auto & unit = addRegularMelee(hex, side);
|
|
|
|
|
|
|
|
unit.addCreatureAbility(BonusType::TWO_HEX_ATTACK_BREATH);
|
|
|
|
unit.makeDoubleWide();
|
|
|
|
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
Units getAttackedUnits(UnitFake & attacker, UnitFake & defender, BattleHex defenderHex)
|
|
|
|
{
|
|
|
|
startBattle();
|
|
|
|
redirectUnitsToFake();
|
|
|
|
|
|
|
|
return subject.getAttackedBattleUnits(
|
|
|
|
&attacker, &defender,
|
|
|
|
defenderHex, false,
|
|
|
|
attacker.getPosition(),
|
|
|
|
defender.getPosition());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(AttackableHexesTest, DragonRightRegular_RightHorithontalBreath)
|
|
|
|
{
|
|
|
|
// X A D #
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & attacker = addDragon(35, BattleSide::ATTACKER);
|
|
|
|
UnitFake & defender = addRegularMelee(36, BattleSide::DEFENDER);
|
|
|
|
UnitFake & next = addRegularMelee(37, BattleSide::DEFENDER);
|
2024-07-28 13:41:21 +02:00
|
|
|
|
|
|
|
auto attacked = getAttackedUnits(attacker, defender, defender.getPosition());
|
|
|
|
|
|
|
|
EXPECT_TRUE(vstd::contains(attacked, &next));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AttackableHexesTest, DragonDragonBottomRightHead_BottomRightBreathFromHead)
|
|
|
|
{
|
|
|
|
// X A
|
|
|
|
// D X target D
|
|
|
|
// #
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & attacker = addDragon(35, BattleSide::ATTACKER);
|
|
|
|
UnitFake & defender = addDragon(attacker.getPosition().cloneInDirection(BattleHex::BOTTOM_RIGHT), BattleSide::DEFENDER);
|
|
|
|
UnitFake & next = addRegularMelee(defender.getPosition().cloneInDirection(BattleHex::BOTTOM_RIGHT), BattleSide::DEFENDER);
|
2024-07-28 13:41:21 +02:00
|
|
|
|
|
|
|
auto attacked = getAttackedUnits(attacker, defender, defender.getPosition());
|
|
|
|
|
|
|
|
EXPECT_TRUE(vstd::contains(attacked, &next));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AttackableHexesTest, DragonDragonVerticalDownHead_VerticalDownBreathFromHead)
|
|
|
|
{
|
|
|
|
// X A
|
|
|
|
// D X target D
|
|
|
|
// #
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & attacker = addDragon(35, BattleSide::ATTACKER);
|
|
|
|
UnitFake & defender = addDragon(attacker.getPosition().cloneInDirection(BattleHex::BOTTOM_LEFT), BattleSide::DEFENDER);
|
|
|
|
UnitFake & next = addRegularMelee(defender.getPosition().cloneInDirection(BattleHex::BOTTOM_RIGHT), BattleSide::DEFENDER);
|
2024-07-28 13:41:21 +02:00
|
|
|
|
|
|
|
auto attacked = getAttackedUnits(attacker, defender, defender.getPosition());
|
|
|
|
|
|
|
|
EXPECT_TRUE(vstd::contains(attacked, &next));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AttackableHexesTest, DragonDragonVerticalDownHeadReverse_VerticalDownBreathFromHead)
|
|
|
|
{
|
|
|
|
// A X
|
|
|
|
// X D target D
|
|
|
|
// #
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & attacker = addDragon(36, BattleSide::DEFENDER);
|
|
|
|
UnitFake & defender = addDragon(attacker.getPosition().cloneInDirection(BattleHex::BOTTOM_RIGHT), BattleSide::ATTACKER);
|
|
|
|
UnitFake & next = addRegularMelee(defender.getPosition().cloneInDirection(BattleHex::BOTTOM_LEFT), BattleSide::ATTACKER);
|
2024-07-28 13:41:21 +02:00
|
|
|
|
|
|
|
auto attacked = getAttackedUnits(attacker, defender, defender.getPosition());
|
|
|
|
|
|
|
|
EXPECT_TRUE(vstd::contains(attacked, &next));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AttackableHexesTest, DragonDragonVerticalDownBack_VerticalDownBreath)
|
|
|
|
{
|
|
|
|
// X A
|
|
|
|
// D X target X
|
|
|
|
// #
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & attacker = addDragon(37, BattleSide::ATTACKER);
|
|
|
|
UnitFake & defender = addDragon(attacker.occupiedHex().cloneInDirection(BattleHex::BOTTOM_LEFT), BattleSide::DEFENDER);
|
|
|
|
UnitFake & next = addRegularMelee(defender.getPosition().cloneInDirection(BattleHex::BOTTOM_RIGHT), BattleSide::DEFENDER);
|
2024-07-28 13:41:21 +02:00
|
|
|
|
|
|
|
auto attacked = getAttackedUnits(attacker, defender, defender.occupiedHex());
|
|
|
|
|
|
|
|
EXPECT_TRUE(vstd::contains(attacked, &next));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AttackableHexesTest, DragonDragonHeadBottomRight_BottomRightBreathFromHead)
|
|
|
|
{
|
|
|
|
// X A
|
|
|
|
// D X target D
|
|
|
|
// #
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & attacker = addDragon(37, BattleSide::ATTACKER);
|
|
|
|
UnitFake & defender = addDragon(attacker.occupiedHex().cloneInDirection(BattleHex::BOTTOM_LEFT), BattleSide::DEFENDER);
|
|
|
|
UnitFake & next = addRegularMelee(defender.getPosition().cloneInDirection(BattleHex::BOTTOM_RIGHT), BattleSide::DEFENDER);
|
2024-07-28 13:41:21 +02:00
|
|
|
|
|
|
|
auto attacked = getAttackedUnits(attacker, defender, defender.getPosition());
|
|
|
|
|
|
|
|
EXPECT_TRUE(vstd::contains(attacked, &next));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AttackableHexesTest, DragonVerticalDownDragonBackReverse_VerticalDownBreath)
|
|
|
|
{
|
|
|
|
// A X
|
|
|
|
// X D target X
|
|
|
|
// #
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & attacker = addDragon(36, BattleSide::DEFENDER);
|
|
|
|
UnitFake & defender = addDragon(attacker.occupiedHex().cloneInDirection(BattleHex::BOTTOM_RIGHT), BattleSide::ATTACKER);
|
|
|
|
UnitFake & next = addRegularMelee(defender.getPosition().cloneInDirection(BattleHex::BOTTOM_LEFT), BattleSide::ATTACKER);
|
2024-07-28 13:41:21 +02:00
|
|
|
|
|
|
|
auto attacked = getAttackedUnits(attacker, defender, defender.occupiedHex());
|
|
|
|
|
|
|
|
EXPECT_TRUE(vstd::contains(attacked, &next));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AttackableHexesTest, DragonRightBottomDragonHeadReverse_RightBottomBreathFromHeadHex)
|
|
|
|
{
|
|
|
|
// A X
|
|
|
|
// X D target D
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & attacker = addDragon(36, BattleSide::DEFENDER);
|
|
|
|
UnitFake & defender = addDragon(attacker.occupiedHex().cloneInDirection(BattleHex::BOTTOM_RIGHT), BattleSide::ATTACKER);
|
|
|
|
UnitFake & next = addRegularMelee(defender.getPosition().cloneInDirection(BattleHex::BOTTOM_LEFT), BattleSide::ATTACKER);
|
2024-07-28 13:41:21 +02:00
|
|
|
|
|
|
|
auto attacked = getAttackedUnits(attacker, defender, defender.getPosition());
|
|
|
|
|
|
|
|
EXPECT_TRUE(vstd::contains(attacked, &next));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AttackableHexesTest, DragonLeftBottomDragonBackToBack_LeftBottomBreathFromBackHex)
|
|
|
|
{
|
|
|
|
// X A
|
|
|
|
// D X target X
|
|
|
|
// #
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & attacker = addDragon(8, BattleSide::ATTACKER);
|
|
|
|
UnitFake & defender = addDragon(attacker.occupiedHex().cloneInDirection(BattleHex::BOTTOM_LEFT).cloneInDirection(BattleHex::LEFT), BattleSide::DEFENDER);
|
|
|
|
UnitFake & next = addRegularMelee(defender.getPosition().cloneInDirection(BattleHex::BOTTOM_RIGHT), BattleSide::DEFENDER);
|
2024-07-28 13:41:21 +02:00
|
|
|
|
|
|
|
auto attacked = getAttackedUnits(attacker, defender, defender.occupiedHex());
|
|
|
|
|
|
|
|
EXPECT_TRUE(vstd::contains(attacked, &next));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AttackableHexesTest, DefenderPositionOverride_BreathCountsHypoteticDefenderPosition)
|
|
|
|
{
|
|
|
|
// # N
|
|
|
|
// X D target D
|
|
|
|
// A X
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & attacker = addDragon(35, BattleSide::DEFENDER);
|
|
|
|
UnitFake & defender = addDragon(8, BattleSide::ATTACKER);
|
|
|
|
UnitFake & next = addDragon(2, BattleSide::ATTACKER);
|
2024-07-28 13:41:21 +02:00
|
|
|
|
|
|
|
startBattle();
|
|
|
|
redirectUnitsToFake();
|
|
|
|
|
|
|
|
auto attacked = subject.getAttackedBattleUnits(
|
|
|
|
&attacker,
|
|
|
|
&defender,
|
|
|
|
19,
|
|
|
|
false,
|
|
|
|
attacker.getPosition(),
|
|
|
|
19);
|
|
|
|
|
|
|
|
EXPECT_TRUE(vstd::contains(attacked, &next));
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
class BattleFinishedTest : public CBattleInfoCallbackTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void expectBattleNotFinished()
|
|
|
|
{
|
|
|
|
auto ret = subject.battleIsFinished();
|
|
|
|
EXPECT_FALSE(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
void expectBattleDraw()
|
|
|
|
{
|
|
|
|
auto ret = subject.battleIsFinished();
|
|
|
|
|
|
|
|
EXPECT_TRUE(ret);
|
2024-08-11 22:22:35 +02:00
|
|
|
EXPECT_EQ(*ret, BattleSide::NONE);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
void expectBattleWinner(BattleSide side)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
auto ret = subject.battleIsFinished();
|
|
|
|
|
|
|
|
EXPECT_TRUE(ret);
|
|
|
|
EXPECT_EQ(*ret, side);
|
|
|
|
}
|
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
void expectBattleLooser(BattleSide side)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
auto ret = subject.battleIsFinished();
|
|
|
|
|
|
|
|
EXPECT_TRUE(ret);
|
2024-08-11 22:22:35 +02:00
|
|
|
EXPECT_NE(*ret, side);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setDefaultExpectations()
|
|
|
|
{
|
|
|
|
redirectUnitsToFake();
|
|
|
|
unitsFake.setDefaultBonusExpectations();
|
|
|
|
EXPECT_CALL(battleMock, getUnitsIf(_)).Times(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-01-03 02:26:15 +02:00
|
|
|
TEST_F(BattleFinishedTest, DISABLED_NoBattleIsDraw)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
expectBattleDraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleFinishedTest, EmptyBattleIsDraw)
|
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
|
|
|
startBattle();
|
|
|
|
expectBattleDraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleFinishedTest, LastAliveUnitWins)
|
|
|
|
{
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & unit = unitsFake.add(BattleSide::DEFENDER);
|
2017-07-20 06:08:49 +02:00
|
|
|
unit.makeAlive();
|
2022-06-28 10:05:30 +02:00
|
|
|
unit.setDefaultState();
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
startBattle();
|
2024-08-11 22:22:35 +02:00
|
|
|
expectBattleWinner(BattleSide::DEFENDER);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleFinishedTest, TwoUnitsContinueFight)
|
|
|
|
{
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
2017-07-20 06:08:49 +02:00
|
|
|
unit1.makeAlive();
|
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & unit2 = unitsFake.add(BattleSide::DEFENDER);
|
2017-07-20 06:08:49 +02:00
|
|
|
unit2.makeAlive();
|
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
expectBattleNotFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleFinishedTest, LastWarMachineNotWins)
|
|
|
|
{
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & unit = unitsFake.add(BattleSide::ATTACKER);
|
2017-07-20 06:08:49 +02:00
|
|
|
unit.makeAlive();
|
|
|
|
unit.makeWarMachine();
|
2022-06-28 10:05:30 +02:00
|
|
|
unit.setDefaultState();
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
startBattle();
|
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
expectBattleLooser(BattleSide::ATTACKER);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleFinishedTest, LastWarMachineLoose)
|
|
|
|
{
|
2022-06-28 10:05:30 +02:00
|
|
|
try
|
|
|
|
{
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
2022-06-28 10:05:30 +02:00
|
|
|
unit1.makeAlive();
|
|
|
|
unit1.setDefaultState();
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
UnitFake & unit2 = unitsFake.add(BattleSide::DEFENDER);
|
2022-06-28 10:05:30 +02:00
|
|
|
unit2.makeAlive();
|
|
|
|
unit2.makeWarMachine();
|
|
|
|
unit2.setDefaultState();
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2022-06-28 10:05:30 +02:00
|
|
|
setDefaultExpectations();
|
|
|
|
startBattle();
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
expectBattleWinner(BattleSide::ATTACKER);
|
2022-06-28 10:05:30 +02:00
|
|
|
}
|
2023-04-25 13:08:55 +02:00
|
|
|
catch(const std::exception & e)
|
2022-06-28 10:05:30 +02:00
|
|
|
{
|
|
|
|
logGlobal->error(e.what());
|
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class BattleMatchOwnerTest : public CBattleInfoCallbackTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void setDefaultExpectations()
|
|
|
|
{
|
|
|
|
redirectUnitsToFake();
|
|
|
|
unitsFake.setDefaultBonusExpectations();
|
|
|
|
|
|
|
|
EXPECT_CALL(battleMock, getSidePlayer(Eq(BattleSide::ATTACKER))).WillRepeatedly(Return(PlayerColor(0)));
|
|
|
|
EXPECT_CALL(battleMock, getSidePlayer(Eq(BattleSide::DEFENDER))).WillRepeatedly(Return(PlayerColor(1)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(BattleMatchOwnerTest, normalToSelf)
|
|
|
|
{
|
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit1, unitId()).WillRepeatedly(Return(42));
|
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit1, true));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit1, boost::logic::indeterminate));
|
|
|
|
EXPECT_FALSE(subject.battleMatchOwner(&unit1, &unit1, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleMatchOwnerTest, hypnotizedToSelf)
|
|
|
|
{
|
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit1, unitId()).WillRepeatedly(Return(42));
|
2023-10-21 13:50:42 +02:00
|
|
|
unit1.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::HYPNOTIZED, BonusSource::CREATURE_ABILITY, 0, BonusSourceID()));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit1, true));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit1, boost::logic::indeterminate));
|
|
|
|
EXPECT_FALSE(subject.battleMatchOwner(&unit1, &unit1, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleMatchOwnerTest, normalToNormalAlly)
|
|
|
|
{
|
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit1, unitId()).WillRepeatedly(Return(42));
|
|
|
|
UnitFake & unit2 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit2, unitId()).WillRepeatedly(Return(4242));
|
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, true));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, boost::logic::indeterminate));
|
|
|
|
EXPECT_FALSE(subject.battleMatchOwner(&unit1, &unit2, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleMatchOwnerTest, hypnotizedToNormalAlly)
|
|
|
|
{
|
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit1, unitId()).WillRepeatedly(Return(42));
|
2023-10-21 13:50:42 +02:00
|
|
|
unit1.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::HYPNOTIZED, BonusSource::CREATURE_ABILITY, 0, BonusSourceID()));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
UnitFake & unit2 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit2, unitId()).WillRepeatedly(Return(4242));
|
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
EXPECT_FALSE(subject.battleMatchOwner(&unit1, &unit2, true));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, boost::logic::indeterminate));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleMatchOwnerTest, normalToHypnotizedAlly)
|
|
|
|
{
|
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit1, unitId()).WillRepeatedly(Return(42));
|
|
|
|
UnitFake & unit2 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit2, unitId()).WillRepeatedly(Return(4242));
|
2023-10-21 13:50:42 +02:00
|
|
|
unit2.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::HYPNOTIZED, BonusSource::CREATURE_ABILITY, 0, BonusSourceID()));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, true));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, boost::logic::indeterminate));
|
|
|
|
EXPECT_FALSE(subject.battleMatchOwner(&unit1, &unit2, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleMatchOwnerTest, hypnotizedToHypnotizedAlly)
|
|
|
|
{
|
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit1, unitId()).WillRepeatedly(Return(42));
|
2023-10-21 13:50:42 +02:00
|
|
|
unit1.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::HYPNOTIZED, BonusSource::CREATURE_ABILITY, 0, BonusSourceID()));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
UnitFake & unit2 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit2, unitId()).WillRepeatedly(Return(4242));
|
2023-10-21 13:50:42 +02:00
|
|
|
unit2.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::HYPNOTIZED, BonusSource::CREATURE_ABILITY, 0, BonusSourceID()));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
EXPECT_FALSE(subject.battleMatchOwner(&unit1, &unit2, true));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, boost::logic::indeterminate));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(BattleMatchOwnerTest, normalToNormalEnemy)
|
|
|
|
{
|
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit1, unitId()).WillRepeatedly(Return(42));
|
|
|
|
UnitFake & unit2 = unitsFake.add(BattleSide::DEFENDER);
|
|
|
|
EXPECT_CALL(unit2, unitId()).WillRepeatedly(Return(4242));
|
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
EXPECT_FALSE(subject.battleMatchOwner(&unit1, &unit2, true));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, boost::logic::indeterminate));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleMatchOwnerTest, hypnotizedToNormalEnemy)
|
|
|
|
{
|
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit1, unitId()).WillRepeatedly(Return(42));
|
2023-10-21 13:50:42 +02:00
|
|
|
unit1.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::HYPNOTIZED, BonusSource::CREATURE_ABILITY, 0, BonusSourceID()));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
UnitFake & unit2 = unitsFake.add(BattleSide::DEFENDER);
|
|
|
|
EXPECT_CALL(unit2, unitId()).WillRepeatedly(Return(4242));
|
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, true));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, boost::logic::indeterminate));
|
|
|
|
EXPECT_FALSE(subject.battleMatchOwner(&unit1, &unit2, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleMatchOwnerTest, normalToHypnotizedEnemy)
|
|
|
|
{
|
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit1, unitId()).WillRepeatedly(Return(42));
|
|
|
|
UnitFake & unit2 = unitsFake.add(BattleSide::DEFENDER);
|
|
|
|
EXPECT_CALL(unit2, unitId()).WillRepeatedly(Return(4242));
|
2023-10-21 13:50:42 +02:00
|
|
|
unit2.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::HYPNOTIZED, BonusSource::CREATURE_ABILITY, 0, BonusSourceID()));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
EXPECT_FALSE(subject.battleMatchOwner(&unit1, &unit2, true));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, boost::logic::indeterminate));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BattleMatchOwnerTest, hypnotizedToHypnotizedEnemy)
|
|
|
|
{
|
|
|
|
UnitFake & unit1 = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(unit1, unitId()).WillRepeatedly(Return(42));
|
2023-10-21 13:50:42 +02:00
|
|
|
unit1.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::HYPNOTIZED, BonusSource::CREATURE_ABILITY, 0, BonusSourceID()));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
UnitFake & unit2 = unitsFake.add(BattleSide::DEFENDER);
|
|
|
|
EXPECT_CALL(unit2, unitId()).WillRepeatedly(Return(4242));
|
2023-10-21 13:50:42 +02:00
|
|
|
unit2.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::HYPNOTIZED, BonusSource::CREATURE_ABILITY, 0, BonusSourceID()));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
startBattle();
|
|
|
|
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, true));
|
|
|
|
EXPECT_TRUE(subject.battleMatchOwner(&unit1, &unit2, boost::logic::indeterminate));
|
|
|
|
EXPECT_FALSE(subject.battleMatchOwner(&unit1, &unit2, false));
|
|
|
|
}
|