Added several tests for species usage in AngelScript.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
175e26d8b4
commit
4909205c42
|
@ -0,0 +1,144 @@
|
||||||
|
#ifdef TESTS_BUILD
|
||||||
|
#include "../../../extern/catch.hpp"
|
||||||
|
#include "../../../src/AngelScript/AngelScripResolver.hpp"
|
||||||
|
#include "../../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
||||||
|
static std::unordered_map<const char*, const char*> _scripts =
|
||||||
|
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||||
|
class testScript1 {
|
||||||
|
bool testName(const Species@ s, const string &in name){ return s.Name == name; }
|
||||||
|
bool testId(const Species@ s, uint16 id){ return s.Id == id; }
|
||||||
|
bool testGenderRate(const Species@ s, float rate){ return s.GenderRate == rate; }
|
||||||
|
bool testCaptureRate(const Species@ s, uint8 rate){ return s.CaptureRate == rate; }
|
||||||
|
}
|
||||||
|
)"}};
|
||||||
|
|
||||||
|
static const char* _testLoadFunc(const char* name) { return _scripts[name]; }
|
||||||
|
|
||||||
|
TEST_CASE("Validate Species Name in Script") {
|
||||||
|
auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
lib->Initialize(mainLib);
|
||||||
|
lib->SetCreateFunction(&_testLoadFunc);
|
||||||
|
lib->CreateScript("testScript1");
|
||||||
|
lib->FinalizeModule();
|
||||||
|
auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
|
||||||
|
|
||||||
|
auto obj =
|
||||||
|
dynamic_cast<AngelScriptScript*>(lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1"));
|
||||||
|
auto ctxPool = obj->GetContextPool();
|
||||||
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
auto func = obj->PrepareMethod("testName", ctx);
|
||||||
|
REQUIRE(func != nullptr);
|
||||||
|
|
||||||
|
ctx->SetArgObject(
|
||||||
|
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
|
||||||
|
auto name = species->GetName();
|
||||||
|
ctx->SetArgAddress(1, &name);
|
||||||
|
|
||||||
|
auto result = ctx->Execute();
|
||||||
|
REQUIRE(result == asEXECUTION_FINISHED);
|
||||||
|
auto v = (bool)ctx->GetReturnWord();
|
||||||
|
REQUIRE(v);
|
||||||
|
|
||||||
|
ctxPool->ReturnContextToPool(ctx);
|
||||||
|
delete obj;
|
||||||
|
delete lib;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Species Id in Script") {
|
||||||
|
auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
lib->Initialize(mainLib);
|
||||||
|
lib->SetCreateFunction(&_testLoadFunc);
|
||||||
|
lib->CreateScript("testScript1");
|
||||||
|
lib->FinalizeModule();
|
||||||
|
auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
|
||||||
|
|
||||||
|
auto obj =
|
||||||
|
dynamic_cast<AngelScriptScript*>(lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1"));
|
||||||
|
auto ctxPool = obj->GetContextPool();
|
||||||
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
auto func = obj->PrepareMethod("testId", ctx);
|
||||||
|
REQUIRE(func != nullptr);
|
||||||
|
|
||||||
|
ctx->SetArgObject(
|
||||||
|
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
|
||||||
|
ctx->SetArgWord(1, 2);
|
||||||
|
|
||||||
|
auto result = ctx->Execute();
|
||||||
|
REQUIRE(result == asEXECUTION_FINISHED);
|
||||||
|
auto v = (bool)ctx->GetReturnWord();
|
||||||
|
REQUIRE(v);
|
||||||
|
|
||||||
|
ctxPool->ReturnContextToPool(ctx);
|
||||||
|
delete obj;
|
||||||
|
delete lib;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Species Gender Rate in Script") {
|
||||||
|
auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
lib->Initialize(mainLib);
|
||||||
|
lib->SetCreateFunction(&_testLoadFunc);
|
||||||
|
lib->CreateScript("testScript1");
|
||||||
|
lib->FinalizeModule();
|
||||||
|
auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
|
||||||
|
|
||||||
|
auto obj =
|
||||||
|
dynamic_cast<AngelScriptScript*>(lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1"));
|
||||||
|
auto ctxPool = obj->GetContextPool();
|
||||||
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
auto func = obj->PrepareMethod("testGenderRate", ctx);
|
||||||
|
REQUIRE(func != nullptr);
|
||||||
|
|
||||||
|
ctx->SetArgObject(
|
||||||
|
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
|
||||||
|
ctx->SetArgFloat(1, 0.5);
|
||||||
|
|
||||||
|
auto result = ctx->Execute();
|
||||||
|
REQUIRE(result == asEXECUTION_FINISHED);
|
||||||
|
auto v = (bool)ctx->GetReturnWord();
|
||||||
|
REQUIRE(v);
|
||||||
|
|
||||||
|
ctxPool->ReturnContextToPool(ctx);
|
||||||
|
delete obj;
|
||||||
|
delete lib;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Species Capture Rate in Script") {
|
||||||
|
auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
lib->Initialize(mainLib);
|
||||||
|
lib->SetCreateFunction(&_testLoadFunc);
|
||||||
|
lib->CreateScript("testScript1");
|
||||||
|
lib->FinalizeModule();
|
||||||
|
auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
|
||||||
|
|
||||||
|
auto obj =
|
||||||
|
dynamic_cast<AngelScriptScript*>(lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1"));
|
||||||
|
auto ctxPool = obj->GetContextPool();
|
||||||
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
auto func = obj->PrepareMethod("testCaptureRate", ctx);
|
||||||
|
REQUIRE(func != nullptr);
|
||||||
|
|
||||||
|
ctx->SetArgObject(
|
||||||
|
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
|
||||||
|
ctx->SetArgByte(1, species->GetCaptureRate());
|
||||||
|
|
||||||
|
auto result = ctx->Execute();
|
||||||
|
REQUIRE(result == asEXECUTION_FINISHED);
|
||||||
|
auto v = (bool)ctx->GetReturnWord();
|
||||||
|
REQUIRE(v);
|
||||||
|
|
||||||
|
ctxPool->ReturnContextToPool(ctx);
|
||||||
|
delete obj;
|
||||||
|
delete lib;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue