mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-16 10:19:47 +02:00
ecaa9f5d0b
* Made most Handlers derived from CHandlerBase and moved service API there. * Declared existing Entity APIs. * Added basic script context caching * Started Lua script module * Started Lua spell effect API * Started script state persistence * Started battle info callback binding * CommitPackage removed * Extracted spells::Caster to own header; Expanded Spell API. * implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C * !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented * Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key) * Re-enabled VERM macros. * !?GM0 added * !?TM implemented * Added !!MF:N * Started !?OB, !!BM, !!HE, !!OW, !!UN * Added basic support of w-variables * Added support for ERM indirect variables * Made !?FU regular trigger * !!re (ERA loop receiver) implemented * Fixed ERM receivers with zero args.
100 lines
2.4 KiB
C++
100 lines
2.4 KiB
C++
/*
|
|
* ERM_BM.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 "../scripting/ScriptFixture.h"
|
|
|
|
#include "../../lib/NetPacks.h"
|
|
|
|
namespace test
|
|
{
|
|
namespace scripting
|
|
{
|
|
using namespace ::testing;
|
|
|
|
class ERM_BM : public Test, public ScriptFixture
|
|
{
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
ScriptFixture::setUp();
|
|
}
|
|
};
|
|
|
|
TEST_F(ERM_BM, GetAttack)
|
|
{
|
|
const int32_t ATTACK_VALUE = 345;
|
|
const uint32_t UNIT_ID = 42;
|
|
|
|
battle::UnitFake & unit1 = unitsFake.add(0);
|
|
unit1.addNewBonus(std::make_shared<Bonus>(Bonus::PERMANENT, Bonus::PRIMARY_SKILL, Bonus::CREATURE_ABILITY, ATTACK_VALUE, 0, PrimarySkill::ATTACK));
|
|
|
|
EXPECT_CALL(binfoMock, battleGetUnitByID(Eq(UNIT_ID))).WillOnce(Return(&unit1));
|
|
|
|
unitsFake.setDefaultBonusExpectations();
|
|
|
|
std::stringstream source;
|
|
source << "VERM" << std::endl;
|
|
source << "!?PI;" << std::endl;
|
|
source << "!!BM" << UNIT_ID << ":A?v1;" << std::endl;
|
|
|
|
loadScript(VLC->scriptHandler->erm, source.str());
|
|
SCOPED_TRACE("\n" + subject->code);
|
|
JsonNode actualState = runClientServer();
|
|
|
|
EXPECT_EQ(actualState["ERM"]["v"]["1"].Float(), ATTACK_VALUE);
|
|
}
|
|
|
|
#if 0
|
|
|
|
TEST_F(ERM_BM, SetAttack)
|
|
{
|
|
const int32_t ATTACK_VALUE = 345;
|
|
const uint32_t UNIT_ID = 42;
|
|
|
|
battle::UnitFake & unit1 = unitsFake.add(0);
|
|
|
|
EXPECT_CALL(binfoMock, battleGetUnitByID(Eq(UNIT_ID))).WillOnce(Return(&unit1));
|
|
|
|
auto checkApply = [&](SetStackEffect * pack)
|
|
{
|
|
EXPECT_TRUE(pack->toUpdate.empty());
|
|
EXPECT_TRUE(pack->toRemove.empty());
|
|
GTEST_ASSERT_EQ(pack->toAdd.size(), 1);
|
|
GTEST_ASSERT_EQ(pack->toAdd.back().second.size(), 1);
|
|
|
|
EXPECT_EQ(pack->toAdd.back().first, UNIT_ID);
|
|
|
|
const Bonus & actual = pack->toAdd.back().second.back();
|
|
|
|
EXPECT_EQ(actual.type, Bonus::PRIMARY_SKILL);
|
|
EXPECT_EQ(actual.subtype, PrimarySkill::ATTACK);
|
|
EXPECT_EQ(actual.valType, Bonus::BASE_NUMBER);
|
|
EXPECT_EQ(actual.val, ATTACK_VALUE);
|
|
};
|
|
|
|
EXPECT_CALL(serverMock, apply(Matcher<SetStackEffect *>(_))).WillOnce(Invoke(checkApply));
|
|
|
|
unitsFake.setDefaultBonusExpectations();
|
|
|
|
std::stringstream source;
|
|
source << "VERM" << std::endl;
|
|
source << "!?PI;" << std::endl;
|
|
source << "!!BM"<<UNIT_ID<<":A"<<ATTACK_VALUE<<";" << std::endl;
|
|
|
|
loadScript(VLC->scriptHandler->erm, source.str());
|
|
SCOPED_TRACE("\n" + subject->code);
|
|
run();
|
|
}
|
|
#endif // 0
|
|
|
|
}
|
|
}
|