ImmunityNegationConditionTest.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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<bool>
  20. {
  21. public:
  22. bool ownerMatches;
  23. void setDefaultExpectations()
  24. {
  25. ownerMatches = GetParam();
  26. EXPECT_CALL(unitMock, getAllBonuses(_, _, _, _)).Times(AtLeast(0));
  27. EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
  28. EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unitMock), Field(&boost::logic::tribool::value, boost::logic::tribool::false_value))).WillRepeatedly(Return(ownerMatches));
  29. }
  30. protected:
  31. void SetUp() override
  32. {
  33. TargetConditionItemTest::SetUp();
  34. subject = TargetConditionItemFactory::getDefault()->createImmunityNegation();
  35. GTEST_ASSERT_NE(subject, nullptr);
  36. }
  37. };
  38. TEST_P(ImmunityNegationConditionTest, NotReceptiveByDefault)
  39. {
  40. setDefaultExpectations();
  41. EXPECT_FALSE(subject->isReceptive(&mechanicsMock, &unitMock));
  42. }
  43. TEST_P(ImmunityNegationConditionTest, WithHeroNegation)
  44. {
  45. setDefaultExpectations();
  46. unitBonuses.addNewBonus(std::make_shared<Bonus>(Bonus::ONE_BATTLE, Bonus::NEGATE_ALL_NATURAL_IMMUNITIES, Bonus::OTHER, 0, 0, 1));
  47. EXPECT_TRUE(subject->isReceptive(&mechanicsMock, &unitMock));
  48. }
  49. TEST_P(ImmunityNegationConditionTest, WithBattleWideNegation)
  50. {
  51. setDefaultExpectations();
  52. unitBonuses.addNewBonus(std::make_shared<Bonus>(Bonus::ONE_BATTLE, Bonus::NEGATE_ALL_NATURAL_IMMUNITIES, Bonus::OTHER, 0, 0, 0));
  53. EXPECT_EQ(!ownerMatches, subject->isReceptive(&mechanicsMock, &unitMock));
  54. }
  55. INSTANTIATE_TEST_CASE_P
  56. (
  57. ByUnitOwner,
  58. ImmunityNegationConditionTest,
  59. Values(false, true)
  60. );
  61. }