2020-02-01 15:56:09 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
#include "../../../../extern/catch.hpp"
|
2020-02-02 11:23:50 +00:00
|
|
|
#include "../../../../src/ScriptResolving/AngelScript/AngelScripResolver.hpp"
|
2020-02-01 15:56:09 +00:00
|
|
|
#include "../../../../src/Battling/Pokemon/CreatePokemon.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 testSpecies(Pokemon@ p, const Species@ species){ return p.Species is species; }
|
|
|
|
bool testForme(Pokemon@ p, const Forme@ forme){ return p.Forme is forme; }
|
|
|
|
bool testLevel(Pokemon@ p, uint8 level){ return p.Level == level; }
|
|
|
|
bool testExperience(Pokemon@ p, uint experience){ return p.Experience == experience; }
|
|
|
|
bool testGender(Pokemon@ p, Gender gender){ return p.Gender == gender; }
|
|
|
|
bool testShiny(Pokemon@ p, bool shiny){ return p.Shiny == shiny; }
|
|
|
|
bool testHeldItem(Pokemon@ p, Item@ item){ return p.HeldItem is item; }
|
|
|
|
bool testCurrentHealth(Pokemon@ p, uint health){ return p.CurrentHealth == health; }
|
|
|
|
bool testNickname(Pokemon@ p, const string &in name){ return p.Nickname == name; }
|
|
|
|
bool testActiveAbility(Pokemon@ p, const string &in ability){ return p.ActiveAbility == ability; }
|
|
|
|
bool testIsFainted(Pokemon@ p, bool b){ return p.IsFainted == b; }
|
|
|
|
bool testType(Pokemon@ p, uint index, uint8 type){ return p.GetTypes()[index] == type; }
|
|
|
|
}
|
|
|
|
)"}};
|
|
|
|
|
|
|
|
static const char* _testLoadFunc(const char* name) { return _scripts[name]; }
|
|
|
|
|
|
|
|
struct ScriptData {
|
|
|
|
AngelScriptScript* Script;
|
|
|
|
AngelScripResolver* Resolver;
|
|
|
|
asIScriptFunction* Func;
|
|
|
|
asIScriptContext* Context;
|
|
|
|
|
|
|
|
~ScriptData() {
|
|
|
|
Script->GetContextPool()->ReturnContextToPool(Context);
|
|
|
|
delete Script;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static AngelScripResolver* _resolverCache = nullptr;
|
|
|
|
static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib) {
|
|
|
|
if (_resolverCache == nullptr) {
|
|
|
|
_resolverCache = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
|
|
|
_resolverCache->Initialize(mainLib);
|
|
|
|
_resolverCache->SetCreateFunction(&_testLoadFunc);
|
|
|
|
_resolverCache->CreateScript("testScript1");
|
|
|
|
_resolverCache->FinalizeModule();
|
|
|
|
}
|
|
|
|
return _resolverCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
|
|
|
auto lib = GetScriptResolver(mainLib);
|
|
|
|
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
|
|
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
|
|
|
auto ctxPool = script->GetContextPool();
|
|
|
|
auto ctx = ctxPool->RequestContext();
|
|
|
|
|
|
|
|
auto func = script->PrepareMethod(funcName, ctx);
|
|
|
|
REQUIRE(func != nullptr);
|
|
|
|
|
|
|
|
return {.Script = script, .Resolver = lib, .Func = func, .Context = ctx};
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon Species in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testSpecies");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30).Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
data.Context->SetArgObject(1, (void*)mon->GetSpecies());
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon Forme in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testForme");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30).WithForme("default")->Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
data.Context->SetArgObject(1, (void*)mon->GetForme());
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon Level in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testLevel");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30).WithForme("default")->Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
data.Context->SetArgByte(1, mon->GetLevel());
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon Experience in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testExperience");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30).WithForme("default")->Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
data.Context->SetArgDWord(1, mon->GetExperience());
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon Gender in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testGender");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
|
|
|
.WithForme("default")
|
|
|
|
->WithGender(CreatureLib::Library::Gender::Male)
|
|
|
|
->Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
data.Context->SetArgDWord(1, (int)mon->GetGender());
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon Shininess in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testShiny");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
|
|
|
.WithForme("default")
|
|
|
|
->WithGender(CreatureLib::Library::Gender::Male)
|
|
|
|
->Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
data.Context->SetArgByte(1, mon->IsShiny());
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon HeldItem in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testHeldItem");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
|
|
|
.WithForme("default")
|
|
|
|
->WithHeldItem("testItem")
|
|
|
|
->WithGender(CreatureLib::Library::Gender::Male)
|
|
|
|
->Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
data.Context->SetArgObject(1, (void*)mon->GetHeldItem());
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon CurrentHealth in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testCurrentHealth");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
|
|
|
.WithForme("default")
|
|
|
|
->WithGender(CreatureLib::Library::Gender::Male)
|
|
|
|
->Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
data.Context->SetArgDWord(1, mon->GetCurrentHealth());
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon Nickname in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testNickname");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
|
|
|
.WithForme("default")
|
|
|
|
->WithGender(CreatureLib::Library::Gender::Male)
|
|
|
|
->Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
auto name = mon->GetNickname();
|
|
|
|
data.Context->SetArgAddress(1, &name);
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon Active Ability in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testActiveAbility");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
|
|
|
.WithForme("default")
|
|
|
|
->WithGender(CreatureLib::Library::Gender::Male)
|
|
|
|
->Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
auto name = mon->GetActiveTalent();
|
|
|
|
data.Context->SetArgAddress(1, &name);
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon IsFainted in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
auto data = GetScript(mainLib, "testIsFainted");
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
|
|
|
.WithForme("default")
|
|
|
|
->WithGender(CreatureLib::Library::Gender::Male)
|
|
|
|
->Build();
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
data.Context->SetArgByte(1, mon->IsFainted());
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Validate Pokemon GetTypes in Script") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
|
|
|
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3", 30)
|
|
|
|
.WithForme("default")
|
|
|
|
->WithGender(CreatureLib::Library::Gender::Male)
|
|
|
|
->Build();
|
2020-02-01 16:09:15 +00:00
|
|
|
for (size_t i = 0; i < mon->GetTypes().size(); i++){
|
2020-02-01 15:56:09 +00:00
|
|
|
auto data = GetScript(mainLib, "testType");
|
|
|
|
|
|
|
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
|
|
|
data.Context->SetArgDWord(1, i);
|
|
|
|
data.Context->SetArgByte(2, mon->GetTypes()[i]);
|
|
|
|
|
|
|
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
|
|
|
REQUIRE((bool)data.Context->GetReturnWord());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|