Rework of ScriptResolver to binary handling. Now also serialises the type database to the stream, simplifying it's api.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-05-02 11:13:04 +02:00
parent 846580550a
commit bd77b58743
6 changed files with 221 additions and 37 deletions

View File

@@ -85,21 +85,10 @@ TEST_CASE("Get a script resolver, save the byte code to memory, create new scrip
originLib->FinalizeModule();
size_t size;
auto byteCode = originLib->WriteByteCodeToMemory(size);
auto typeDatabase = originLib->GetTypeDatabase();
Dictionary<ScriptCategory, Dictionary<ConstString, const char*>> types;
for (auto& innerDb : typeDatabase) {
Dictionary<ConstString, const char*> newInnerDb;
for (auto& kv : innerDb.second) {
INFO(kv.second->GetDecl());
newInnerDb.Insert(kv.first, kv.second->GetDecl());
}
types.Insert(innerDb.first, newInnerDb);
}
auto newLib = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
newLib->Initialize(TestLibrary::GetLibrary());
newLib->LoadByteCodeFromMemory(byteCode, size, types);
newLib->LoadByteCodeFromMemory(byteCode, size);
auto obj = dynamic_cast<AngelScriptScript*>(newLib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc));
REQUIRE(obj != nullptr);
delete obj;
@@ -107,4 +96,22 @@ TEST_CASE("Get a script resolver, save the byte code to memory, create new scrip
delete newLib;
free(byteCode);
}
TEST_CASE("Get a script resolver, save the byte code to file, create new script resolver from it") {
auto originLib = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
originLib->Initialize(TestLibrary::GetLibrary());
originLib->CreateScript("testScript1", _scripts["testScript1"]);
originLib->FinalizeModule();
originLib->WriteByteCodeToFile("foo.bin");
auto newLib = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
newLib->Initialize(TestLibrary::GetLibrary());
newLib->LoadByteCodeFromFile("foo.bin");
auto obj = dynamic_cast<AngelScriptScript*>(newLib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc));
REQUIRE(obj != nullptr);
delete obj;
delete originLib;
delete newLib;
// remove("foo.bin");
}
#endif