ImmunityNegationConditionTest.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * ImmunityNegationConditionTest.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "TargetConditionItemFixture.h"
  12. //FIXME: Orb of vulnerability mechanics is not such trivial (mantis issue 1791)
  13. //TODO: NEGATE_ALL_NATURAL_IMMUNITIES special cases: dispel, chain lightning
  14. //Tests are incomplete and only covers actual implementation for now
  15. namespace test
  16. {
  17. using namespace ::spells;
  18. using namespace ::testing;
  19. class ImmunityNegationConditionTest : public TargetConditionItemTest, public WithParamInterface<std::tuple<bool, bool>>
  20. {
  21. public:
  22. bool ownerMatches;
  23. bool isMagicalEffect;
  24. void setDefaultExpectations()
  25. {
  26. ownerMatches = ::testing::get<0>(GetParam());
  27. isMagicalEffect = ::testing::get<1>(GetParam());
  28. EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(AtLeast(0));
  29. EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
  30. EXPECT_CALL(mechanicsMock, isMagicalEffect()).Times(AtLeast(0)).WillRepeatedly(Return(isMagicalEffect));
  31. EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unitMock), Field(&boost::logic::tribool::value, boost::logic::tribool::false_value))).WillRepeatedly(Return(ownerMatches));
  32. }
  33. protected:
  34. void SetUp() override
  35. {
  36. TargetConditionItemTest::SetUp();
  37. subject = TargetConditionItemFactory::getDefault()->createImmunityNegation();
  38. GTEST_ASSERT_NE(subject, nullptr);
  39. }
  40. };
  41. TEST_P(ImmunityNegationConditionTest, NotReceptiveByDefault)
  42. {
  43. setDefaultExpectations();
  44. EXPECT_FALSE(subject->isReceptive(&mechanicsMock, &unitMock));
  45. }
  46. TEST_P(ImmunityNegationConditionTest, WithHeroNegation)
  47. {
  48. setDefaultExpectations();
  49. unitBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::NEGATE_ALL_NATURAL_IMMUNITIES, BonusSource::OTHER, 0, BonusSourceID(), BonusCustomSubtype::immunityEnemyHero));
  50. EXPECT_EQ(isMagicalEffect, subject->isReceptive(&mechanicsMock, &unitMock));
  51. }
  52. TEST_P(ImmunityNegationConditionTest, WithBattleWideNegation)
  53. {
  54. setDefaultExpectations();
  55. unitBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::NEGATE_ALL_NATURAL_IMMUNITIES, BonusSource::OTHER, 0, BonusSourceID(), BonusCustomSubtype::immunityBattleWide));
  56. //This should return if ownerMatches, because anyone should cast onto owner's stacks, but not on enemyStacks
  57. EXPECT_EQ(ownerMatches && isMagicalEffect, subject->isReceptive(&mechanicsMock, &unitMock));
  58. }
  59. INSTANTIATE_TEST_SUITE_P
  60. (
  61. ByUnitOwner,
  62. ImmunityNegationConditionTest,
  63. Combine
  64. (
  65. Values(false, true),
  66. Values(false, true)
  67. )
  68. );
  69. }