Better handling of testing AngelScript types, more tests for species fields and methods
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		@@ -10,134 +10,137 @@ class testScript1 {
 | 
				
			|||||||
    bool testId(const Species@ s, uint16 id){ return s.Id == id; }
 | 
					    bool testId(const Species@ s, uint16 id){ return s.Id == id; }
 | 
				
			||||||
    bool testGenderRate(const Species@ s, float rate){ return s.GenderRate == rate; }
 | 
					    bool testGenderRate(const Species@ s, float rate){ return s.GenderRate == rate; }
 | 
				
			||||||
    bool testCaptureRate(const Species@ s, uint8 rate){ return s.CaptureRate == 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]; }
 | 
					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 lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
 | 
				
			||||||
    auto mainLib = TestLibrary::GetLibrary();
 | 
					 | 
				
			||||||
    lib->Initialize(mainLib);
 | 
					    lib->Initialize(mainLib);
 | 
				
			||||||
    lib->SetCreateFunction(&_testLoadFunc);
 | 
					    lib->SetCreateFunction(&_testLoadFunc);
 | 
				
			||||||
    lib->CreateScript("testScript1");
 | 
					    lib->CreateScript("testScript1");
 | 
				
			||||||
    lib->FinalizeModule();
 | 
					    lib->FinalizeModule();
 | 
				
			||||||
    auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
 | 
					    auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
 | 
				
			||||||
 | 
					    auto script = dynamic_cast<AngelScriptScript*>(s);
 | 
				
			||||||
    auto obj =
 | 
					    auto ctxPool = script->GetContextPool();
 | 
				
			||||||
        dynamic_cast<AngelScriptScript*>(lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1"));
 | 
					 | 
				
			||||||
    auto ctxPool = obj->GetContextPool();
 | 
					 | 
				
			||||||
    auto ctx = ctxPool->RequestContext();
 | 
					    auto ctx = ctxPool->RequestContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto func = obj->PrepareMethod("testName", ctx);
 | 
					    auto func = script->PrepareMethod(funcName, ctx);
 | 
				
			||||||
    REQUIRE(func != nullptr);
 | 
					    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));
 | 
					        0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
 | 
				
			||||||
    auto name = species->GetName();
 | 
					    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);
 | 
					    REQUIRE(result == asEXECUTION_FINISHED);
 | 
				
			||||||
    auto v = (bool)ctx->GetReturnWord();
 | 
					    auto v = (bool)data.Context->GetReturnWord();
 | 
				
			||||||
    REQUIRE(v);
 | 
					    REQUIRE(v);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    ctxPool->ReturnContextToPool(ctx);
 | 
					 | 
				
			||||||
    delete obj;
 | 
					 | 
				
			||||||
    delete lib;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_CASE("Validate Species Id in Script") {
 | 
					TEST_CASE("Validate Species Id in Script") {
 | 
				
			||||||
    auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
 | 
					 | 
				
			||||||
    auto mainLib = TestLibrary::GetLibrary();
 | 
					    auto mainLib = TestLibrary::GetLibrary();
 | 
				
			||||||
    lib->Initialize(mainLib);
 | 
					    auto data = GetScript(mainLib, "testId");
 | 
				
			||||||
    lib->SetCreateFunction(&_testLoadFunc);
 | 
					
 | 
				
			||||||
    lib->CreateScript("testScript1");
 | 
					 | 
				
			||||||
    lib->FinalizeModule();
 | 
					 | 
				
			||||||
    auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
 | 
					    auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
 | 
				
			||||||
 | 
					    data.Context->SetArgObject(
 | 
				
			||||||
    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));
 | 
					        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);
 | 
					    REQUIRE(result == asEXECUTION_FINISHED);
 | 
				
			||||||
    auto v = (bool)ctx->GetReturnWord();
 | 
					    auto v = (bool)data.Context->GetReturnWord();
 | 
				
			||||||
    REQUIRE(v);
 | 
					    REQUIRE(v);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    ctxPool->ReturnContextToPool(ctx);
 | 
					 | 
				
			||||||
    delete obj;
 | 
					 | 
				
			||||||
    delete lib;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_CASE("Validate Species Gender Rate in Script") {
 | 
					TEST_CASE("Validate Species Gender Rate in Script") {
 | 
				
			||||||
    auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
 | 
					 | 
				
			||||||
    auto mainLib = TestLibrary::GetLibrary();
 | 
					    auto mainLib = TestLibrary::GetLibrary();
 | 
				
			||||||
    lib->Initialize(mainLib);
 | 
					    auto data = GetScript(mainLib, "testGenderRate");
 | 
				
			||||||
    lib->SetCreateFunction(&_testLoadFunc);
 | 
					
 | 
				
			||||||
    lib->CreateScript("testScript1");
 | 
					 | 
				
			||||||
    lib->FinalizeModule();
 | 
					 | 
				
			||||||
    auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
 | 
					    auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
 | 
				
			||||||
 | 
					    data.Context->SetArgObject(
 | 
				
			||||||
    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));
 | 
					        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);
 | 
					    REQUIRE(result == asEXECUTION_FINISHED);
 | 
				
			||||||
    auto v = (bool)ctx->GetReturnWord();
 | 
					    auto v = (bool)data.Context->GetReturnDWord();
 | 
				
			||||||
    REQUIRE(v);
 | 
					    REQUIRE(v);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    ctxPool->ReturnContextToPool(ctx);
 | 
					 | 
				
			||||||
    delete obj;
 | 
					 | 
				
			||||||
    delete lib;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_CASE("Validate Species Capture Rate in Script") {
 | 
					TEST_CASE("Validate Species Capture Rate in Script") {
 | 
				
			||||||
    auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
 | 
					 | 
				
			||||||
    auto mainLib = TestLibrary::GetLibrary();
 | 
					    auto mainLib = TestLibrary::GetLibrary();
 | 
				
			||||||
    lib->Initialize(mainLib);
 | 
					    auto data = GetScript(mainLib, "testCaptureRate");
 | 
				
			||||||
    lib->SetCreateFunction(&_testLoadFunc);
 | 
					
 | 
				
			||||||
    lib->CreateScript("testScript1");
 | 
					 | 
				
			||||||
    lib->FinalizeModule();
 | 
					 | 
				
			||||||
    auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
 | 
					    auto species = mainLib->GetSpeciesLibrary()->GetPkmnSpecies("testSpecies2");
 | 
				
			||||||
 | 
					    data.Context->SetArgObject(
 | 
				
			||||||
    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));
 | 
					        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);
 | 
					    REQUIRE(result == asEXECUTION_FINISHED);
 | 
				
			||||||
    auto v = (bool)ctx->GetReturnWord();
 | 
					    auto v = (bool)data.Context->GetReturnWord();
 | 
				
			||||||
    REQUIRE(v);
 | 
					    REQUIRE(v);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ctxPool->ReturnContextToPool(ctx);
 | 
					TEST_CASE("Validate Species Get Forme in Script") {
 | 
				
			||||||
    delete obj;
 | 
					    auto mainLib = TestLibrary::GetLibrary();
 | 
				
			||||||
    delete lib;
 | 
					    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);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user