2
0

LuaSpellEffectAPITest.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * LuaSpellEffectAPITest.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 "ScriptFixture.h"
  12. #include "../../lib/networkPacks/PacksForClientBattle.h"
  13. #include "../mock/mock_ServerCallback.h"
  14. namespace test
  15. {
  16. using namespace ::testing;
  17. using namespace ::scripting;
  18. class LuaSpellEffectAPITest : public Test, public ScriptFixture
  19. {
  20. public:
  21. StrictMock<ServerCallbackMock> serverMock;
  22. protected:
  23. void SetUp() override
  24. {
  25. ScriptFixture::setUp();
  26. }
  27. };
  28. TEST_F(LuaSpellEffectAPITest, DISABLED_ApplicableOnExpert)
  29. {
  30. loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
  31. context->setGlobal("effectLevel", 3);
  32. runClientServer();
  33. JsonNode params;
  34. JsonNode ret = context->callGlobal("applicable", params);
  35. JsonNode expected = JsonUtils::boolNode(true);
  36. JsonComparer cmp(false);
  37. cmp.compare("applicable result", ret, expected);
  38. }
  39. TEST_F(LuaSpellEffectAPITest, DISABLED_NotApplicableOnAdvanced)
  40. {
  41. loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
  42. context->setGlobal("effectLevel", 2);
  43. runClientServer();
  44. JsonNode params;
  45. JsonNode ret = context->callGlobal("applicable", params);
  46. JsonNode expected = JsonUtils::boolNode(false);
  47. JsonComparer cmp(false);
  48. cmp.compare("applicable result", ret, expected);
  49. }
  50. TEST_F(LuaSpellEffectAPITest, DISABLED_ApplicableOnLeftSideOfField)
  51. {
  52. loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
  53. context->setGlobal("effectLevel", 1);
  54. runClientServer();
  55. JsonNode params;
  56. BattleHex hex(2,2);
  57. JsonNode first;
  58. first.Vector().push_back(JsonUtils::intNode(hex.hex));
  59. first.Vector().push_back(JsonNode());
  60. JsonNode targets;
  61. targets.Vector().push_back(first);
  62. params.Vector().push_back(targets);
  63. JsonNode ret = context->callGlobal("applicableTarget", params);
  64. JsonNode expected = JsonUtils::boolNode(true);
  65. JsonComparer cmp(false);
  66. cmp.compare("applicable result", ret, expected);
  67. }
  68. TEST_F(LuaSpellEffectAPITest, DISABLED_NotApplicableOnRightSideOfField)
  69. {
  70. loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
  71. runClientServer();
  72. context->setGlobal("effectLevel", 1);
  73. JsonNode params;
  74. BattleHex hex(11,2);
  75. JsonNode first;
  76. first.Vector().push_back(JsonUtils::intNode(hex.hex));
  77. first.Vector().push_back(JsonUtils::intNode(-1));
  78. JsonNode targets;
  79. targets.Vector().push_back(first);
  80. params.Vector().push_back(targets);
  81. JsonNode ret = context->callGlobal("applicableTarget", params);
  82. JsonNode expected = JsonUtils::boolNode(false);
  83. JsonComparer cmp(false);
  84. cmp.compare("applicable result", ret, expected);
  85. }
  86. TEST_F(LuaSpellEffectAPITest, DISABLED_ApplyMoveUnit)
  87. {
  88. loadScriptFromFile("test/lua/SpellEffectAPIMoveUnit.lua");
  89. runClientServer();
  90. BattleHex hex1(11,2);
  91. JsonNode unit;
  92. unit.Vector().push_back(JsonUtils::intNode(hex1.hex));
  93. unit.Vector().push_back(JsonUtils::intNode(42));
  94. BattleHex hex2(5,4);
  95. JsonNode destination;
  96. destination.Vector().push_back(JsonUtils::intNode(hex2.hex));
  97. destination.Vector().push_back(JsonUtils::intNode(-1));
  98. JsonNode targets;
  99. targets.Vector().push_back(unit);
  100. targets.Vector().push_back(destination);
  101. JsonNode params;
  102. params.Vector().push_back(targets);
  103. BattleStackMoved expected;
  104. BattleStackMoved actual;
  105. auto checkMove = [&](BattleStackMoved * pack)
  106. {
  107. EXPECT_EQ(pack->stack, 42);
  108. EXPECT_EQ(pack->teleporting, true);
  109. EXPECT_EQ(pack->distance, 0);
  110. std::vector<BattleHex> toMove(1, hex2);
  111. EXPECT_EQ(pack->tilesToMove, toMove);
  112. };
  113. EXPECT_CALL(serverMock, apply(Matcher<BattleStackMoved *>(_))).WillOnce(Invoke(checkMove));
  114. context->callGlobal(&serverMock, "apply", params);
  115. }
  116. }