2017-07-20 06:08:49 +02:00
|
|
|
/*
|
|
|
|
* CloneTest.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 "EffectFixture.h"
|
|
|
|
|
|
|
|
#include <vstd/RNG.h>
|
|
|
|
|
|
|
|
#include "../../../lib/battle/CUnitState.h"
|
|
|
|
|
|
|
|
namespace test
|
|
|
|
{
|
|
|
|
using namespace ::spells;
|
|
|
|
using namespace ::spells::effects;
|
|
|
|
using namespace ::testing;
|
|
|
|
|
|
|
|
class CloneTest : public Test, public EffectFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CloneTest()
|
|
|
|
: EffectFixture("core:clone")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SetUp() override
|
|
|
|
{
|
|
|
|
EffectFixture::setUp();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(CloneTest, ApplicableToValidTarget)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
JsonNode config(JsonNode::JsonType::DATA_STRUCT);
|
|
|
|
config["maxTier"].Integer() = 7;
|
|
|
|
EffectFixture::setupEffect(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto & unit = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, isValidTarget(Eq(false))).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, hasClone()).WillRepeatedly(Return(false));
|
|
|
|
EXPECT_CALL(unit, isClone()).Times(AtLeast(1)).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
EXPECT_CALL(mechanicsMock, isSmart()).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, getPosition()).WillOnce(Return(BattleHex(5, 5)));
|
|
|
|
EffectTarget target;
|
|
|
|
target.emplace_back(&unit);
|
|
|
|
|
|
|
|
EXPECT_TRUE(subject->applicable(problemMock, &mechanicsMock, target));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CloneTest, CloneIsNotClonable)
|
|
|
|
{
|
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
|
|
|
setupEffect(JsonNode());
|
2017-07-20 06:08:49 +02:00
|
|
|
auto & unit = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, hasClone()).WillRepeatedly(Return(false));
|
|
|
|
EXPECT_CALL(unit, isClone()).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, getPosition()).WillOnce(Return(BattleHex(5, 5)));
|
|
|
|
EffectTarget target;
|
|
|
|
target.emplace_back(&unit);
|
|
|
|
|
|
|
|
EXPECT_FALSE(subject->applicable(problemMock, &mechanicsMock, target));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CloneTest, SecondCloneRejected)
|
|
|
|
{
|
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
|
|
|
setupEffect(JsonNode());
|
2017-07-20 06:08:49 +02:00
|
|
|
auto & unit = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, hasClone()).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
EXPECT_CALL(unit, isClone()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, getPosition()).WillOnce(Return(BattleHex(5, 5)));
|
|
|
|
EffectTarget target;
|
|
|
|
target.emplace_back(&unit);
|
|
|
|
|
|
|
|
EXPECT_FALSE(subject->applicable(problemMock, &mechanicsMock, target));
|
|
|
|
}
|
|
|
|
|
|
|
|
class CloneApplyTest : public Test, public EffectFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::shared_ptr<::battle::UnitInfo> cloneAddInfo;
|
|
|
|
std::shared_ptr<::battle::CUnitState> cloneState;
|
|
|
|
std::shared_ptr<::battle::CUnitState> originalState;
|
|
|
|
|
|
|
|
const uint32_t originalId = 40;
|
|
|
|
const uint32_t cloneId = 42;
|
|
|
|
const int32_t expectedAmount = 10;
|
|
|
|
const int32_t effectDuration = 6;
|
|
|
|
const BattleHex originalPosition = BattleHex(5,5);
|
|
|
|
|
|
|
|
EffectTarget target;
|
|
|
|
|
|
|
|
CloneApplyTest()
|
|
|
|
: EffectFixture("core:clone")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void onUnitAdded(uint32_t id, const JsonNode & data)
|
|
|
|
{
|
|
|
|
using namespace ::battle;
|
|
|
|
|
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
|
|
|
auto & clone = unitsFake.add(BattleSide::ATTACKER);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_CALL(clone, unitId()).WillRepeatedly(Return(id));
|
|
|
|
|
|
|
|
cloneState = std::make_shared<CUnitStateDetached>(&clone, &clone);
|
|
|
|
|
|
|
|
EXPECT_CALL(clone, acquireState()).WillOnce(Return(cloneState));
|
|
|
|
|
|
|
|
cloneAddInfo->load(id, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkCloneLifetimeMarker(uint32_t id, const std::vector<Bonus> & bonus)
|
|
|
|
{
|
|
|
|
EXPECT_EQ(id, cloneId);
|
|
|
|
|
|
|
|
GTEST_ASSERT_EQ(bonus.size(), 1);
|
|
|
|
|
|
|
|
const Bonus & marker = bonus.front();
|
|
|
|
|
|
|
|
EXPECT_EQ(marker.type, Bonus::NONE);
|
|
|
|
EXPECT_EQ(marker.duration, Bonus::N_TURNS);
|
|
|
|
EXPECT_EQ(marker.turnsRemain, effectDuration);
|
|
|
|
EXPECT_EQ(marker.source, Bonus::SPELL_EFFECT);
|
|
|
|
EXPECT_EQ(marker.sid, SpellID::CLONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDefaultExpectations()
|
|
|
|
{
|
|
|
|
using namespace ::battle;
|
|
|
|
|
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
|
|
|
battleFake->setupEmptyBattlefield();
|
|
|
|
|
|
|
|
EXPECT_CALL(serverMock, apply(Matcher<BattleUnitsChanged *>(_))).Times(2);
|
|
|
|
EXPECT_CALL(serverMock, apply(Matcher<SetStackEffect *>(_))).Times(1);
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
EXPECT_CALL(mechanicsMock, getEffectDuration()).WillOnce(Return(effectDuration));
|
|
|
|
EXPECT_CALL(*battleFake, getUnitsIf(_)).Times(AtLeast(1));
|
|
|
|
|
|
|
|
EXPECT_CALL(*battleFake, nextUnitId()).WillOnce(Return(cloneId));
|
|
|
|
EXPECT_CALL(*battleFake, addUnit(_, _)).WillOnce(Invoke(this, &CloneApplyTest::onUnitAdded));
|
|
|
|
|
|
|
|
EXPECT_CALL(*battleFake, setUnitState(Eq(originalId), _, Eq(0))).Times(AtLeast(1));
|
|
|
|
EXPECT_CALL(*battleFake, setUnitState(Eq(cloneId), _, Eq(0))).Times(AtLeast(1));
|
|
|
|
|
|
|
|
auto & original = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(original, isValidTarget(Eq(false))).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
EXPECT_CALL(original, getCount()).WillRepeatedly(Return(expectedAmount));
|
|
|
|
EXPECT_CALL(original, unitId()).WillRepeatedly(Return(originalId));
|
|
|
|
EXPECT_CALL(original, creatureId()).WillRepeatedly(Return(CreatureID(0)));
|
|
|
|
EXPECT_CALL(original, creatureIndex()).WillRepeatedly(Return(0));
|
|
|
|
EXPECT_CALL(original, doubleWide()).WillRepeatedly(Return(false));
|
|
|
|
EXPECT_CALL(original, getPosition()).WillRepeatedly(Return(originalPosition));
|
|
|
|
EXPECT_CALL(original, unitSide()).Times(AnyNumber());
|
|
|
|
|
|
|
|
originalState = std::make_shared<CUnitStateDetached>(&original, &original);
|
|
|
|
|
|
|
|
EXPECT_CALL(original, acquireState()).WillOnce(Return(originalState));
|
|
|
|
|
|
|
|
target.emplace_back(&original);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SetUp() override
|
|
|
|
{
|
|
|
|
EffectFixture::setUp();
|
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
|
|
|
setupEffect(JsonNode());
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
cloneAddInfo = std::make_shared<::battle::UnitInfo>();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(CloneApplyTest, AddsNewUnit)
|
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
EXPECT_CALL(*battleFake, addUnitBonus(_,_)).Times(AtLeast(1));
|
|
|
|
|
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
|
|
|
subject->apply(&serverMock, &mechanicsMock, target);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_EQ(cloneAddInfo->id, cloneId);
|
|
|
|
EXPECT_EQ(cloneAddInfo->count, expectedAmount);
|
|
|
|
EXPECT_EQ(cloneAddInfo->type, CreatureID(0));
|
|
|
|
EXPECT_EQ(cloneAddInfo->side, BattleSide::ATTACKER);
|
|
|
|
EXPECT_TRUE(cloneAddInfo->position.isValid());
|
|
|
|
EXPECT_NE(cloneAddInfo->position, originalPosition);
|
|
|
|
EXPECT_TRUE(cloneAddInfo->summoned);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CloneApplyTest, SetsClonedFlag)
|
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
EXPECT_CALL(*battleFake, addUnitBonus(_,_)).Times(AtLeast(1));
|
|
|
|
|
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
|
|
|
subject->apply(&serverMock, &mechanicsMock, target);
|
|
|
|
|
|
|
|
GTEST_ASSERT_NE(cloneState, nullptr);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(cloneState->cloned);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CloneApplyTest, SetsCloneLink)
|
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
EXPECT_CALL(*battleFake, addUnitBonus(_,_)).Times(AtLeast(1));
|
|
|
|
|
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
|
|
|
subject->apply(&serverMock, &mechanicsMock, target);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_EQ(originalState->cloneID, cloneId);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CloneApplyTest, SetsLifetimeMarker)
|
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
2022-06-28 10:05:30 +02:00
|
|
|
EXPECT_CALL(*battleFake, addUnitBonus(_, _)).WillOnce(Invoke(this, &CloneApplyTest::checkCloneLifetimeMarker));
|
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
|
|
|
subject->apply(&serverMock, &mechanicsMock, target);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|