2017-07-20 06:08:49 +02:00
|
|
|
/*
|
|
|
|
* ElementalConditionTest.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 "TargetConditionItemFixture.h"
|
|
|
|
|
|
|
|
namespace test
|
|
|
|
{
|
|
|
|
using namespace ::spells;
|
|
|
|
using namespace ::testing;
|
|
|
|
|
|
|
|
class ElementalConditionTest : public TargetConditionItemTest, public WithParamInterface<bool>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool isPositive;
|
2023-08-19 19:19:59 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void setDefaultExpectations()
|
|
|
|
{
|
2024-08-25 12:44:11 +02:00
|
|
|
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(AtLeast(1));
|
2017-07-20 06:08:49 +02:00
|
|
|
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
|
|
|
|
|
2023-08-19 19:19:59 +02:00
|
|
|
EXPECT_CALL(mechanicsMock, getSpell()).Times(AtLeast(1)).WillRepeatedly(Return(&spellMock));
|
|
|
|
EXPECT_CALL(spellMock, forEachSchool(NotNull())).Times(AtLeast(1)).WillRepeatedly([](const spells::Spell::SchoolCallback & cb)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2023-08-19 19:19:59 +02:00
|
|
|
bool stop = false;
|
2023-11-08 16:13:08 +02:00
|
|
|
cb(SpellSchool::AIR, stop);
|
|
|
|
cb(SpellSchool::FIRE, stop);
|
2023-08-19 19:19:59 +02:00
|
|
|
});
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_CALL(mechanicsMock, isPositiveSpell()).WillRepeatedly(Return(isPositive));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetUp() override
|
|
|
|
{
|
|
|
|
TargetConditionItemTest::SetUp();
|
|
|
|
subject = TargetConditionItemFactory::getDefault()->createElemental();
|
|
|
|
|
|
|
|
isPositive = GetParam();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(ElementalConditionTest, ReceptiveIfNoBonus)
|
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
EXPECT_TRUE(subject->isReceptive(&mechanicsMock, &unitMock));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(ElementalConditionTest, ImmuneIfBonusMatches)
|
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
2023-10-21 13:50:42 +02:00
|
|
|
unitBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::SPELL_SCHOOL_IMMUNITY, BonusSource::SPELL_EFFECT, 0, BonusSourceID(), BonusSubtypeID(SpellSchool::AIR)));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_FALSE(subject->isReceptive(&mechanicsMock, &unitMock));
|
|
|
|
}
|
|
|
|
|
2023-08-19 19:19:59 +02:00
|
|
|
TEST_P(ElementalConditionTest, NotImmuneIfBonusMismatches)
|
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
2023-10-21 13:50:42 +02:00
|
|
|
unitBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::SPELL_SCHOOL_IMMUNITY, BonusSource::SPELL_EFFECT, 0, BonusSourceID(), BonusSubtypeID(SpellSchool::WATER)));
|
2023-08-19 19:19:59 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(subject->isReceptive(&mechanicsMock, &unitMock));
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
TEST_P(ElementalConditionTest, DependsOnPositivness)
|
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
2023-10-21 13:50:42 +02:00
|
|
|
unitBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::NEGATIVE_EFFECTS_IMMUNITY, BonusSource::SPELL_EFFECT, 0, BonusSourceID(), BonusSubtypeID(SpellSchool::AIR)));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_EQ(isPositive, subject->isReceptive(&mechanicsMock, &unitMock));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(ElementalConditionTest, ImmuneIfBothBonusesPresent)
|
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
2023-10-21 13:50:42 +02:00
|
|
|
unitBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::SPELL_SCHOOL_IMMUNITY, BonusSource::SPELL_EFFECT, 0, BonusSourceID(), BonusSubtypeID(SpellSchool::AIR)));
|
|
|
|
unitBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::NEGATIVE_EFFECTS_IMMUNITY, BonusSource::SPELL_EFFECT, 0, BonusSourceID(), BonusSubtypeID(SpellSchool::AIR)));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_FALSE(subject->isReceptive(&mechanicsMock, &unitMock));
|
|
|
|
}
|
|
|
|
|
2023-02-28 13:29:35 +02:00
|
|
|
INSTANTIATE_TEST_SUITE_P
|
2017-07-20 06:08:49 +02:00
|
|
|
(
|
|
|
|
ByPositiveness,
|
|
|
|
ElementalConditionTest,
|
|
|
|
Values(false, true)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|