Better handling of testing AngelScript types, more tests for species fields and methods
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
4909205c42
commit
2c2039cdb8
|
@ -10,134 +10,137 @@ class testScript1 {
|
|||
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; }
|
||||
bool testGetForme(const Species@ s, const Forme@ forme){ return s.GetForme("default") is forme; }
|
||||
bool testGetDefaultForme(const Species@ s, const Forme@ forme){ return s.GetDefaultForme() is forme; }
|
||||
}
|
||||
)"}};
|
||||
|
||||
static const char* _testLoadFunc(const char* name) { return _scripts[name]; }
|
||||
|
||||
TEST_CASE("Validate Species Name in Script") {
|
||||
struct ScriptData{
|
||||
AngelScriptScript* Script;
|
||||
AngelScripResolver* Resolver;
|
||||
asIScriptFunction* Func;
|
||||
asIScriptContext* Context;
|
||||
|
||||
~ScriptData(){
|
||||
Script->GetContextPool()->ReturnContextToPool(Context);
|
||||
delete Script;
|
||||
delete Resolver;
|
||||
}
|
||||
};
|
||||
|
||||
ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName){
|
||||
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 s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||
auto ctxPool = script->GetContextPool();
|
||||
auto ctx = ctxPool->RequestContext();
|
||||
|
||||
auto func = obj->PrepareMethod("testName", ctx);
|
||||
auto func = script->PrepareMethod(funcName, ctx);
|
||||
REQUIRE(func != nullptr);
|
||||
|
||||
ctx->SetArgObject(
|
||||
return {
|
||||
.Script = script,
|
||||
.Resolver = lib,
|
||||
.Func = func,
|
||||
.Context = ctx
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("Validate Species Name in Script") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto data = GetScript(mainLib, "testName");
|
||||
|
||||
auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
|
||||
data.Context->SetArgObject(
|
||||
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
|
||||
auto name = species->GetName();
|
||||
ctx->SetArgAddress(1, &name);
|
||||
data.Context->SetArgAddress(1, &name);
|
||||
|
||||
auto result = ctx->Execute();
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)ctx->GetReturnWord();
|
||||
auto v = (bool)data.Context->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 data = GetScript(mainLib, "testId");
|
||||
|
||||
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(
|
||||
data.Context->SetArgObject(
|
||||
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
|
||||
ctx->SetArgWord(1, 2);
|
||||
data.Context->SetArgWord(1, species->GetId());
|
||||
|
||||
auto result = ctx->Execute();
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)ctx->GetReturnWord();
|
||||
auto v = (bool)data.Context->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 data = GetScript(mainLib, "testGenderRate");
|
||||
|
||||
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(
|
||||
data.Context->SetArgObject(
|
||||
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
|
||||
ctx->SetArgFloat(1, 0.5);
|
||||
data.Context->SetArgFloat(1, species->GetGenderRate());
|
||||
|
||||
auto result = ctx->Execute();
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)ctx->GetReturnWord();
|
||||
auto v = (bool)data.Context->GetReturnDWord();
|
||||
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 data = GetScript(mainLib, "testCaptureRate");
|
||||
|
||||
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(
|
||||
data.Context->SetArgObject(
|
||||
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
|
||||
ctx->SetArgByte(1, species->GetCaptureRate());
|
||||
data.Context->SetArgByte(1, species->GetCaptureRate());
|
||||
|
||||
auto result = ctx->Execute();
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)ctx->GetReturnWord();
|
||||
auto v = (bool)data.Context->GetReturnWord();
|
||||
REQUIRE(v);
|
||||
}
|
||||
|
||||
ctxPool->ReturnContextToPool(ctx);
|
||||
delete obj;
|
||||
delete lib;
|
||||
TEST_CASE("Validate Species Get Forme in Script") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto data = GetScript(mainLib, "testGetForme");
|
||||
|
||||
auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
|
||||
data.Context->SetArgObject(
|
||||
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
|
||||
data.Context->SetArgObject(1, const_cast<PkmnLib::Library::PokemonForme*>(species->GetForme("default")));
|
||||
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)data.Context->GetReturnWord();
|
||||
REQUIRE(v);
|
||||
}
|
||||
|
||||
TEST_CASE("Validate Species Get Default Forme in Script") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto data = GetScript(mainLib, "testGetDefaultForme");
|
||||
|
||||
auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
|
||||
data.Context->SetArgObject(
|
||||
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
|
||||
data.Context->SetArgObject(1, const_cast<PkmnLib::Library::PokemonForme*>(species->GetDefaultForme()));
|
||||
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)data.Context->GetReturnWord();
|
||||
REQUIRE(v);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue