2
0

TeleportTest.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * TeleportTest.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 "EffectFixture.h"
  12. #include "../../../lib/json/JsonNode.h"
  13. #include <vstd/RNG.h>
  14. namespace test
  15. {
  16. using namespace ::spells;
  17. using namespace ::spells::effects;
  18. using namespace ::testing;
  19. class TeleportTest : public Test, public EffectFixture
  20. {
  21. public:
  22. TeleportTest()
  23. : EffectFixture("core:teleport")
  24. {
  25. }
  26. protected:
  27. void SetUp() override
  28. {
  29. EffectFixture::setUp();
  30. setupEffect(JsonNode());
  31. }
  32. };
  33. class TeleportApplyTest : public Test, public EffectFixture
  34. {
  35. public:
  36. TeleportApplyTest()
  37. : EffectFixture("core:teleport")
  38. {
  39. }
  40. protected:
  41. void SetUp() override
  42. {
  43. EffectFixture::setUp();
  44. setupEffect(JsonNode());
  45. }
  46. };
  47. TEST_F(TeleportApplyTest, MovesUnit)
  48. {
  49. battleFake->setupEmptyBattlefield();
  50. uint32_t unitId = 42;
  51. BattleHex initial(1, 1);
  52. BattleHex destination(10, 10);
  53. EXPECT_CALL(*battleFake, getUnitsIf(_)).Times(AtLeast(0));
  54. auto & unit = unitsFake.add(BattleSide::ATTACKER);
  55. EXPECT_CALL(unit, getPosition()).WillRepeatedly(Return(initial));
  56. EXPECT_CALL(unit, unitId()).Times(AtLeast(1)).WillRepeatedly(Return(unitId));
  57. EXPECT_CALL(unit, doubleWide()).WillRepeatedly(Return(false));
  58. EXPECT_CALL(unit, isValidTarget(Eq(false))).WillRepeatedly(Return(true));
  59. EXPECT_CALL(*battleFake, moveUnit(Eq(unitId), Eq(destination)));
  60. EXPECT_CALL(mechanicsMock, getEffectLevel()).WillRepeatedly(Return(0));
  61. EXPECT_CALL(serverMock, apply(Matcher<BattleStackMoved &>(_))).Times(1);
  62. Target target;
  63. target.emplace_back(&unit, BattleHex());
  64. target.emplace_back(destination);
  65. subject->apply(&serverMock, &mechanicsMock, target);
  66. }
  67. }