| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 | 
							- /*
 
-  * 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 "../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, ApplicableOnExpert)
 
- {
 
- 	loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
 
- 	context->setGlobal("effectLevel", 3);
 
- 	runClientServer();
 
- 	JsonNode params;
 
- 	JsonNode ret = context->callGlobal("applicable", params);
 
- 	JsonNode expected = JsonUtils::boolNode(true);
 
- 	JsonComparer cmp(false);
 
- 	cmp.compare("applicable result", ret, expected);
 
- }
 
- TEST_F(LuaSpellEffectAPITest, NotApplicableOnAdvanced)
 
- {
 
- 	loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
 
- 	context->setGlobal("effectLevel", 2);
 
- 	runClientServer();
 
- 	JsonNode params;
 
- 	JsonNode ret = context->callGlobal("applicable", params);
 
- 	JsonNode expected = JsonUtils::boolNode(false);
 
- 	JsonComparer cmp(false);
 
- 	cmp.compare("applicable result", ret, expected);
 
- }
 
- TEST_F(LuaSpellEffectAPITest, ApplicableOnLeftSideOfField)
 
- {
 
- 	loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
 
- 	context->setGlobal("effectLevel", 1);
 
- 	runClientServer();
 
- 	JsonNode params;
 
- 	BattleHex hex(2,2);
 
- 	JsonNode first;
 
- 	first.Vector().push_back(JsonUtils::intNode(hex.hex));
 
- 	first.Vector().push_back(JsonNode());
 
- 	JsonNode targets;
 
- 	targets.Vector().push_back(first);
 
- 	params.Vector().push_back(targets);
 
- 	JsonNode ret = context->callGlobal("applicableTarget", params);
 
- 	JsonNode expected = JsonUtils::boolNode(true);
 
- 	JsonComparer cmp(false);
 
- 	cmp.compare("applicable result", ret, expected);
 
- }
 
- TEST_F(LuaSpellEffectAPITest, NotApplicableOnRightSideOfField)
 
- {
 
- 	loadScriptFromFile("test/lua/SpellEffectAPITest.lua");
 
- 	runClientServer();
 
- 	context->setGlobal("effectLevel", 1);
 
- 	JsonNode params;
 
- 	BattleHex hex(11,2);
 
- 	JsonNode first;
 
- 	first.Vector().push_back(JsonUtils::intNode(hex.hex));
 
- 	first.Vector().push_back(JsonUtils::intNode(-1));
 
- 	JsonNode targets;
 
- 	targets.Vector().push_back(first);
 
- 	params.Vector().push_back(targets);
 
- 	JsonNode ret = context->callGlobal("applicableTarget", params);
 
- 	JsonNode expected = JsonUtils::boolNode(false);
 
- 	JsonComparer cmp(false);
 
- 	cmp.compare("applicable result", ret, expected);
 
- }
 
- TEST_F(LuaSpellEffectAPITest, ApplyMoveUnit)
 
- {
 
- 	loadScriptFromFile("test/lua/SpellEffectAPIMoveUnit.lua");
 
- 	runClientServer();
 
- 	BattleHex hex1(11,2);
 
- 	JsonNode unit;
 
- 	unit.Vector().push_back(JsonUtils::intNode(hex1.hex));
 
- 	unit.Vector().push_back(JsonUtils::intNode(42));
 
- 	BattleHex hex2(5,4);
 
- 	JsonNode destination;
 
- 	destination.Vector().push_back(JsonUtils::intNode(hex2.hex));
 
- 	destination.Vector().push_back(JsonUtils::intNode(-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);
 
- 		std::vector<BattleHex> toMove(1, hex2);
 
- 		EXPECT_EQ(pack->tilesToMove, toMove);
 
- 	};
 
- 	EXPECT_CALL(serverMock, apply(Matcher<BattleStackMoved *>(_))).WillOnce(Invoke(checkMove));
 
- 	context->callGlobal(&serverMock, "apply", params);
 
- }
 
- }
 
 
  |