1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/test/spells/AbilityCasterTest.cpp
K 462c79e190 remove never used code in CBonusSystemNode
Method CBonusSystemNode::getAllBonuses have 'root' parameter which is never
set to anythig else than nullptr. This patch removes the parameter and all
code that depends on it as preparatory work for further bonus system
optimization.
2024-08-25 14:15:21 +02:00

84 lines
2.3 KiB
C++

/*
* AbilityCasterTest.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 "mock/mock_battle_Unit.h"
#include "mock/mock_BonusBearer.h"
#include "mock/mock_spells_Spell.h"
#include "../../lib/spells/AbilityCaster.h"
namespace test
{
using namespace ::spells;
using namespace ::testing;
class AbilityCasterTest : public Test
{
public:
std::shared_ptr<AbilityCaster> subject;
StrictMock<UnitMock> actualCaster;
BonusBearerMock casterBonuses;
StrictMock<SpellMock> spellMock;
protected:
void SetUp() override
{
ON_CALL(actualCaster, getAllBonuses(_, _, _)).WillByDefault(Invoke(&casterBonuses, &BonusBearerMock::getAllBonuses));
ON_CALL(actualCaster, getTreeVersion()).WillByDefault(Invoke(&casterBonuses, &BonusBearerMock::getTreeVersion));
}
void setupSubject(int skillLevel)
{
subject = std::make_shared<AbilityCaster>(&actualCaster, skillLevel);
}
};
TEST_F(AbilityCasterTest, NonMagicAbilityIgnoresBonuses)
{
EXPECT_CALL(spellMock, getLevel()).WillRepeatedly(Return(0));
setupSubject(1);
EXPECT_EQ(subject->getSpellSchoolLevel(&spellMock), 1);
}
TEST_F(AbilityCasterTest, MagicAbilityAffectedByGenericBonus)
{
EXPECT_CALL(spellMock, getLevel()).WillRepeatedly(Return(1));
casterBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::MAGIC_SCHOOL_SKILL, BonusSource::OTHER, 2, BonusSourceID(), BonusSubtypeID(SpellSchool::ANY)));
EXPECT_CALL(actualCaster, getAllBonuses(_, _, _)).Times(AtLeast(1));
EXPECT_CALL(actualCaster, getTreeVersion()).Times(AtLeast(0));
setupSubject(1);
EXPECT_EQ(subject->getSpellSchoolLevel(&spellMock), 2);
}
TEST_F(AbilityCasterTest, MagicAbilityIgnoresSchoolBonus)
{
EXPECT_CALL(spellMock, getLevel()).WillRepeatedly(Return(1));
casterBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::MAGIC_SCHOOL_SKILL, BonusSource::OTHER, 2, BonusSourceID(), BonusSubtypeID(SpellSchool::AIR)));
EXPECT_CALL(actualCaster, getAllBonuses(_, _, _)).Times(AtLeast(1));
EXPECT_CALL(actualCaster, getTreeVersion()).Times(AtLeast(0));
setupSubject(1);
EXPECT_EQ(subject->getSpellSchoolLevel(&spellMock), 1);
}
}