From 7c56fbd16b74e510e5aa53953a97f59bdbb16cfa Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 23 Mar 2023 12:01:13 +0300 Subject: [PATCH] vcmi: fix test building for 1.2 --- test/erm/ERM_MA.cpp | 6 +++--- test/mock/mock_IBattleInfoCallback.h | 2 +- test/mock/mock_Services.h | 1 + test/mock/mock_battle_IBattleState.h | 2 +- test/mock/mock_spells_Mechanics.h | 1 + test/mock/mock_spells_Spell.h | 1 + test/spells/TargetConditionTest.cpp | 1 + test/spells/effects/CatapultTest.cpp | 5 +++++ test/spells/effects/DamageTest.cpp | 1 - test/spells/effects/DispelTest.cpp | 1 - test/spells/effects/HealTest.cpp | 15 +++++---------- .../AbsoluteLevelConditionTest.cpp | 1 + .../targetConditions/NormalLevelConditionTest.cpp | 1 + 13 files changed, 21 insertions(+), 17 deletions(-) diff --git a/test/erm/ERM_MA.cpp b/test/erm/ERM_MA.cpp index 0a1f138b8..b45888366 100644 --- a/test/erm/ERM_MA.cpp +++ b/test/erm/ERM_MA.cpp @@ -85,7 +85,7 @@ TEST_F(ERM_MA, Example) static_assert(FLAG_MASK_NEW == (1 << 0 | 1 << 1 | 1 << 7 | 1 << 12 | 1 << 17 | 1 << 18), "Wrong flag mask meaning"); creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::FLYING, Bonus::CREATURE_ABILITY, 0, 0)); - creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::KING1, Bonus::CREATURE_ABILITY, 0, 0)); + creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::KING, Bonus::CREATURE_ABILITY, 0, 0)); std::shared_ptr removed = std::make_shared(Bonus::PERMANENT, Bonus::MIND_IMMUNITY, Bonus::CREATURE_ABILITY, 0, 0); @@ -204,7 +204,7 @@ TEST_F(ERM_MA, Bonuses) static_assert(FLAG_MASK_NEW == ( 1 << 1 | 1 << 7 | 1 << 12 | 1 << 17 | 1 << 18), "Wrong flag mask meaning"); creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::FLYING, Bonus::CREATURE_ABILITY, 0, 0)); - creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::KING1, Bonus::CREATURE_ABILITY, 0, 0)); + creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::KING, Bonus::CREATURE_ABILITY, 0, 0)); std::shared_ptr removed = std::make_shared(Bonus::PERMANENT, Bonus::MIND_IMMUNITY, Bonus::CREATURE_ABILITY, 0, 0); @@ -266,7 +266,7 @@ TEST_F(ERM_MA, BonusesNoChanges) static_assert(FLAG_MASK == (1 << 1 | 1 << 7 | 1 << 10 | 1 << 17 | 1 << 18), "Wrong flag mask meaning"); creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::FLYING, Bonus::CREATURE_ABILITY, 0, 0)); - creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::KING1, Bonus::CREATURE_ABILITY, 0, 0)); + creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::KING, Bonus::CREATURE_ABILITY, 0, 0)); creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::MIND_IMMUNITY, Bonus::CREATURE_ABILITY, 0, 0)); creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::NO_MORALE, Bonus::CREATURE_ABILITY, 0, 0)); creatureBonuses.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::UNDEAD, Bonus::CREATURE_ABILITY, 0, 0)); diff --git a/test/mock/mock_IBattleInfoCallback.h b/test/mock/mock_IBattleInfoCallback.h index ba03a75ae..a089e8e26 100644 --- a/test/mock/mock_IBattleInfoCallback.h +++ b/test/mock/mock_IBattleInfoCallback.h @@ -34,7 +34,7 @@ public: MOCK_CONST_METHOD0(battleActiveUnit, const battle::Unit *()); MOCK_CONST_METHOD2(battleGetAllObstaclesOnPos, std::vector>(BattleHex, bool)); - MOCK_CONST_METHOD1(getAllAffectedObstaclesByStack, std::vector>(const battle::Unit *)); + MOCK_CONST_METHOD2(getAllAffectedObstaclesByStack, std::vector>(const battle::Unit *, const std::set &)); }; diff --git a/test/mock/mock_Services.h b/test/mock/mock_Services.h index 2ebd30c4a..3a28ae3cb 100644 --- a/test/mock/mock_Services.h +++ b/test/mock/mock_Services.h @@ -26,6 +26,7 @@ public: MOCK_CONST_METHOD0(skills, const SkillService * ()); MOCK_CONST_METHOD0(battlefields, const BattleFieldService *()); MOCK_CONST_METHOD0(obstacles, const ObstacleService *()); + MOCK_CONST_METHOD0(settings, const IGameSettings *()); MOCK_METHOD3(updateEntity, void(Metatype, int32_t, const JsonNode &)); diff --git a/test/mock/mock_battle_IBattleState.h b/test/mock/mock_battle_IBattleState.h index 7064b41d5..dbd30c0ce 100644 --- a/test/mock/mock_battle_IBattleState.h +++ b/test/mock/mock_battle_IBattleState.h @@ -33,7 +33,7 @@ public: MOCK_CONST_METHOD0(getTacticsSide, ui8()); MOCK_CONST_METHOD0(getBonusBearer, const IBonusBearer *()); MOCK_CONST_METHOD0(nextUnitId, uint32_t()); - MOCK_CONST_METHOD3(getActualDamage, int64_t(const TDmgRange &, int32_t, vstd::RNG &)); + MOCK_CONST_METHOD3(getActualDamage, int64_t(const DamageRange &, int32_t, vstd::RNG &)); MOCK_METHOD1(nextRound, void(int32_t)); MOCK_METHOD1(nextTurn, void(uint32_t)); diff --git a/test/mock/mock_spells_Mechanics.h b/test/mock/mock_spells_Mechanics.h index ea70b1cad..6c759d261 100644 --- a/test/mock/mock_spells_Mechanics.h +++ b/test/mock/mock_spells_Mechanics.h @@ -57,6 +57,7 @@ public: MOCK_CONST_METHOD0(requiresClearTiles, bool()); MOCK_CONST_METHOD0(isNegativeSpell, bool()); MOCK_CONST_METHOD0(isPositiveSpell, bool()); + MOCK_CONST_METHOD0(isMagicalEffect, bool()); MOCK_CONST_METHOD1(adjustEffectValue,int64_t(const battle::Unit *)); MOCK_CONST_METHOD2(applySpellBonus,int64_t(int64_t, const battle::Unit *)); diff --git a/test/mock/mock_spells_Spell.h b/test/mock/mock_spells_Spell.h index 53825a94c..0e3b19d24 100644 --- a/test/mock/mock_spells_Spell.h +++ b/test/mock/mock_spells_Spell.h @@ -43,6 +43,7 @@ public: MOCK_CONST_METHOD0(isDamage, bool()); MOCK_CONST_METHOD0(isOffensive, bool()); MOCK_CONST_METHOD0(isSpecial, bool()); + MOCK_CONST_METHOD0(isMagical, bool()); MOCK_CONST_METHOD1(forEachSchool, void(const SchoolCallback &)); MOCK_CONST_METHOD0(getCastSound, const std::string &()); MOCK_CONST_METHOD1(registerIcons, void(const IconRegistar &)); diff --git a/test/spells/TargetConditionTest.cpp b/test/spells/TargetConditionTest.cpp index a90270fca..b74fa68b1 100644 --- a/test/spells/TargetConditionTest.cpp +++ b/test/spells/TargetConditionTest.cpp @@ -43,6 +43,7 @@ public: MOCK_CONST_METHOD0(createElemental, Object()); MOCK_CONST_METHOD0(createNormalLevel, Object()); MOCK_CONST_METHOD0(createNormalSpell, Object()); + MOCK_CONST_METHOD1(createFromJsonStruct, Object(const JsonNode &)); MOCK_CONST_METHOD3(createConfigurable, Object(std::string, std::string, std::string)); MOCK_CONST_METHOD0(createReceptiveFeature, Object()); MOCK_CONST_METHOD0(createImmunityNegation, Object()); diff --git a/test/spells/effects/CatapultTest.cpp b/test/spells/effects/CatapultTest.cpp index 652c100b1..56356ff0b 100644 --- a/test/spells/effects/CatapultTest.cpp +++ b/test/spells/effects/CatapultTest.cpp @@ -118,13 +118,18 @@ TEST_F(CatapultApplyTest, DamageToIntactPart) { JsonNode config(JsonNode::JsonType::DATA_STRUCT); config["targetsToAttack"].Integer() = 1; + config["chanceToNormalHit"].Integer() = 100; EffectFixture::setupEffect(config); } setDefaultExpectations(); const EWallPart targetPart = EWallPart::BELOW_GATE; + auto & actualCaster = unitsFake.add(BattleSide::ATTACKER); + mechanicsMock.caster = &actualCaster; + EXPECT_CALL(actualCaster, getCasterUnitId()).WillRepeatedly(Return(-1)); + EXPECT_CALL(mechanicsMock, isMassive()).WillRepeatedly(Return(true)); EXPECT_CALL(*battleFake, getWallState(_)).WillRepeatedly(Return(EWallState::DESTROYED)); EXPECT_CALL(*battleFake, getWallState(Eq(targetPart))).WillRepeatedly(Return(EWallState::INTACT)); EXPECT_CALL(*battleFake, setWallState(Eq(targetPart), Eq(EWallState::DAMAGED))).Times(1); diff --git a/test/spells/effects/DamageTest.cpp b/test/spells/effects/DamageTest.cpp index 91da534cd..3b4a38032 100644 --- a/test/spells/effects/DamageTest.cpp +++ b/test/spells/effects/DamageTest.cpp @@ -45,7 +45,6 @@ TEST_F(DamageTest, ApplicableToAliveUnit) EXPECT_CALL(unit, isValidTarget(Eq(false))).WillOnce(Return(true)); EXPECT_CALL(mechanicsMock, isSmart()).WillOnce(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).WillOnce(Return(true)); EffectTarget target; target.emplace_back(&unit, BattleHex()); diff --git a/test/spells/effects/DispelTest.cpp b/test/spells/effects/DispelTest.cpp index 10ece325b..91acf58fd 100644 --- a/test/spells/effects/DispelTest.cpp +++ b/test/spells/effects/DispelTest.cpp @@ -79,7 +79,6 @@ TEST_F(DispelTest, ApplicableToAliveUnitWithTimedEffect) EXPECT_CALL(unit, isValidTarget(Eq(false))).WillOnce(Return(true)); EXPECT_CALL(mechanicsMock, isSmart()).WillOnce(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).WillOnce(Return(true)); EXPECT_CALL(mechanicsMock, getSpellIndex()).Times(AtLeast(1)).WillRepeatedly(Return(neutralID.toEnum())); setDefaultExpectaions(); diff --git a/test/spells/effects/HealTest.cpp b/test/spells/effects/HealTest.cpp index a32f2c918..cb0ed65a1 100644 --- a/test/spells/effects/HealTest.cpp +++ b/test/spells/effects/HealTest.cpp @@ -49,7 +49,6 @@ TEST_F(HealTest, NotApplicableToHealthyUnit) EXPECT_CALL(unit, getAvailableHealth()).WillOnce(Return(200)); EXPECT_CALL(mechanicsMock, isSmart()).Times(AtMost(1)).WillRepeatedly(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).Times(AtMost(1)).WillRepeatedly(Return(true)); EffectTarget target; target.emplace_back(&unit, BattleHex()); @@ -67,7 +66,6 @@ TEST_F(HealTest, ApplicableToWoundedUnit) EXPECT_CALL(unit, getAvailableHealth()).WillOnce(Return(100)); EXPECT_CALL(mechanicsMock, isSmart()).WillOnce(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).WillOnce(Return(true)); EffectTarget target; target.emplace_back(&unit, BattleHex()); @@ -92,7 +90,6 @@ TEST_F(HealTest, ApplicableIfActuallyResurrects) EXPECT_CALL(mechanicsMock, getEffectValue()).Times(AtLeast(1)).WillRepeatedly(Return(1000)); EXPECT_CALL(mechanicsMock, isSmart()).WillOnce(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).WillOnce(Return(true)); unit.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::STACK_HEALTH, Bonus::CREATURE_ABILITY, 200, 0)); unitsFake.setDefaultBonusExpectations(); @@ -119,7 +116,6 @@ TEST_F(HealTest, NotApplicableIfNotEnoughCasualties) EXPECT_CALL(mechanicsMock, getEffectValue()).Times(AtLeast(1)).WillRepeatedly(Return(999)); EXPECT_CALL(mechanicsMock, isSmart()).WillRepeatedly(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).WillRepeatedly(Return(true)); unit.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::STACK_HEALTH, Bonus::CREATURE_ABILITY, 200, 0)); unitsFake.setDefaultBonusExpectations(); @@ -146,7 +142,6 @@ TEST_F(HealTest, NotApplicableIfResurrectsLessThanRequired) EXPECT_CALL(mechanicsMock, getEffectValue()).Times(AtLeast(1)).WillRepeatedly(Return(999)); EXPECT_CALL(mechanicsMock, isSmart()).WillRepeatedly(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).WillRepeatedly(Return(true)); unit.addNewBonus(std::make_shared(Bonus::PERMANENT, Bonus::STACK_HEALTH, Bonus::CREATURE_ABILITY, 200, 0)); unitsFake.setDefaultBonusExpectations(); @@ -179,7 +174,6 @@ TEST_F(HealTest, ApplicableToDeadUnit) EXPECT_CALL(mechanicsMock, isSmart()).WillOnce(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).WillOnce(Return(true)); EXPECT_CALL(*battleFake, getUnitsIf(_)).Times(AtLeast(0)); @@ -217,7 +211,6 @@ TEST_F(HealTest, NotApplicableIfDeadUnitIsBlocked) EXPECT_CALL(blockingUnit, unitSide()).Times(AnyNumber()); EXPECT_CALL(mechanicsMock, isSmart()).WillRepeatedly(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).WillRepeatedly(Return(true)); EXPECT_CALL(*battleFake, getUnitsIf(_)).Times(AtLeast(1)); @@ -255,7 +248,6 @@ TEST_F(HealTest, ApplicableWithAnotherDeadUnitInSamePosition) EXPECT_CALL(blockingUnit, unitSide()).Times(AnyNumber()); EXPECT_CALL(mechanicsMock, isSmart()).WillRepeatedly(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).WillRepeatedly(Return(true)); EXPECT_CALL(*battleFake, getUnitsIf(_)).Times(AtLeast(1)); @@ -284,7 +276,6 @@ TEST_F(HealTest, NotApplicableIfEffectValueTooLow) EXPECT_CALL(mechanicsMock, getEffectValue()).Times(AtLeast(1)).WillRepeatedly(Return(199)); EXPECT_CALL(mechanicsMock, isSmart()).Times(AtMost(1)).WillRepeatedly(Return(false)); - EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).Times(AtMost(1)).WillRepeatedly(Return(true)); unitsFake.setDefaultBonusExpectations(); @@ -352,6 +343,7 @@ TEST_P(HealApplyTest, Heals) auto & targetUnit = unitsFake.add(BattleSide::ATTACKER); + auto & actualCaster = unitsFake.add(BattleSide::ATTACKER); EXPECT_CALL(targetUnit, unitBaseAmount()).WillRepeatedly(Return(unitAmount)); EXPECT_CALL(targetUnit, unitId()).WillRepeatedly(Return(unitId)); EXPECT_CALL(targetUnit, unitType()).WillRepeatedly(Return(pikeman)); @@ -367,16 +359,19 @@ TEST_P(HealApplyTest, Heals) targetUnitState->health.damage(initialDmg); } + mechanicsMock.caster = &actualCaster; EXPECT_CALL(mechanicsMock, getEffectValue()).WillRepeatedly(Return(effectValue)); EXPECT_CALL(mechanicsMock, applySpellBonus(Eq(effectValue), Eq(&targetUnit))).WillRepeatedly(Return(effectValue)); GTEST_ASSERT_EQ(targetUnitState->getAvailableHealth(), unitAmount * unitHP / 2 + 1); GTEST_ASSERT_EQ(targetUnitState->getFirstHPleft(), 1); - EXPECT_CALL(targetUnit, acquire()).WillOnce(Return(targetUnitState)); + EXPECT_CALL(targetUnit, acquire()).WillRepeatedly(Return(targetUnitState)); EXPECT_CALL(*battleFake, setUnitState(Eq(unitId), _, Gt(0))).Times(1); + EXPECT_CALL(actualCaster, getCasterUnitId()).WillRepeatedly(Return(-1)); + //There should be battle log message if resurrect switch(healLevel) { diff --git a/test/spells/targetConditions/AbsoluteLevelConditionTest.cpp b/test/spells/targetConditions/AbsoluteLevelConditionTest.cpp index 4fa0c166a..5f1d558e2 100644 --- a/test/spells/targetConditions/AbsoluteLevelConditionTest.cpp +++ b/test/spells/targetConditions/AbsoluteLevelConditionTest.cpp @@ -23,6 +23,7 @@ public: void setDefaultExpectations() { + EXPECT_CALL(mechanicsMock, isMagicalEffect()).WillRepeatedly(Return(true)); EXPECT_CALL(unitMock, getAllBonuses(_, _, _, _)).Times(AtLeast(1)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); } diff --git a/test/spells/targetConditions/NormalLevelConditionTest.cpp b/test/spells/targetConditions/NormalLevelConditionTest.cpp index e799c2ae4..2cbbbd230 100644 --- a/test/spells/targetConditions/NormalLevelConditionTest.cpp +++ b/test/spells/targetConditions/NormalLevelConditionTest.cpp @@ -23,6 +23,7 @@ public: void setDefaultExpectations() { + EXPECT_CALL(mechanicsMock, isMagicalEffect()).WillRepeatedly(Return(true)); EXPECT_CALL(unitMock, getAllBonuses(_, _, _, _)).Times(AtLeast(1)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); }