123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- /*
- * LuaSpellEffectAPITest.cpp, part of VCMI engine
- *
- * Authors: listed in file AUTHORS in main folder
- *
- * License: GNU General Public License v2.0 or later
- * Full text of license available in license.txt file, in main folder
- *
- */
- #include "StdInc.h"
- #include "ScriptFixture.h"
- #include "../../lib/networkPacks/PacksForClientBattle.h"
- #include "../../lib/json/JsonUtils.h"
- #include "../mock/mock_ServerCallback.h"
- namespace test
- {
- using namespace ::testing;
- using namespace ::scripting;
- class LuaSpellEffectAPITest : public Test, public ScriptFixture
- {
- public:
- StrictMock<ServerCallbackMock> serverMock;
- protected:
- void SetUp() override
- {
- ScriptFixture::setUp();
- }
- };
- TEST_F(LuaSpellEffectAPITest, DISABLED_ApplicableOnExpert)
- {
- loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
- context->setGlobal("effectLevel", 3);
- runClientServer();
- JsonNode params;
- JsonNode ret = context->callGlobal("applicable", params);
- JsonNode expected(true);
- JsonComparer cmp(false);
- cmp.compare("applicable result", ret, expected);
- }
- TEST_F(LuaSpellEffectAPITest, DISABLED_NotApplicableOnAdvanced)
- {
- loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
- context->setGlobal("effectLevel", 2);
- runClientServer();
- JsonNode params;
- JsonNode ret = context->callGlobal("applicable", params);
- JsonNode expected(false);
- JsonComparer cmp(false);
- cmp.compare("applicable result", ret, expected);
- }
- TEST_F(LuaSpellEffectAPITest, DISABLED_ApplicableOnLeftSideOfField)
- {
- loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
- context->setGlobal("effectLevel", 1);
- runClientServer();
- JsonNode params;
- BattleHex hex(2,2);
- JsonNode first;
- first.Vector().emplace_back(static_cast<si16>(hex));
- first.Vector().emplace_back();
- JsonNode targets;
- targets.Vector().push_back(first);
- params.Vector().push_back(targets);
- JsonNode ret = context->callGlobal("applicableTarget", params);
- JsonNode expected(true);
- JsonComparer cmp(false);
- cmp.compare("applicable result", ret, expected);
- }
- TEST_F(LuaSpellEffectAPITest, DISABLED_NotApplicableOnRightSideOfField)
- {
- loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
- runClientServer();
- context->setGlobal("effectLevel", 1);
- JsonNode params;
- BattleHex hex(11,2);
- JsonNode first;
- first.Vector().emplace_back(static_cast<si16>(hex));
- first.Vector().emplace_back(-1);
- JsonNode targets;
- targets.Vector().push_back(first);
- params.Vector().push_back(targets);
- JsonNode ret = context->callGlobal("applicableTarget", params);
- JsonNode expected(false);
- JsonComparer cmp(false);
- cmp.compare("applicable result", ret, expected);
- }
- TEST_F(LuaSpellEffectAPITest, DISABLED_ApplyMoveUnit)
- {
- loadScriptFromFile("test/lua/SpellEffectAPIMoveUnit.lua");
- runClientServer();
- BattleHex hex1(11,2);
- JsonNode unit;
- unit.Vector().emplace_back(static_cast<si16>(hex1));
- unit.Vector().emplace_back(42);
- BattleHex hex2(5,4);
- JsonNode destination;
- destination.Vector().emplace_back(static_cast<si16>(hex2));
- destination.Vector().emplace_back(-1);
- JsonNode targets;
- targets.Vector().push_back(unit);
- targets.Vector().push_back(destination);
- JsonNode params;
- params.Vector().push_back(targets);
- BattleStackMoved expected;
- BattleStackMoved actual;
- auto checkMove = [&](BattleStackMoved & pack)
- {
- EXPECT_EQ(pack.stack, 42);
- EXPECT_EQ(pack.teleporting, true);
- EXPECT_EQ(pack.distance, 0);
- BattleHexArray toMove = { hex2 };
- EXPECT_EQ(pack.tilesToMove, toMove);
- };
- EXPECT_CALL(serverMock, apply(Matcher<BattleStackMoved &>(_))).WillOnce(Invoke(checkMove));
- context->callGlobal(&serverMock, "apply", params);
- }
- }
|