LuaSpellEffectAPITest.cpp 3.5 KB

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