Initial work on WebAssembly script provider
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -8,4 +8,9 @@ TEST_CASE("Able to build and destroy empty library") {
|
||||
delete lib;
|
||||
}
|
||||
|
||||
|
||||
REGISTER_EXCEPTION_TRANSLATOR(ArbUt::Exception& ex) {
|
||||
return {(std::string(ex.what()) + "\n" + ex.GetStacktrace()).c_str()};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD and ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD and ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include <Arbutils/StringView.hpp>
|
||||
#include <doctest.h>
|
||||
#include "../../src/ScriptResolving/AngelScript/AngelScriptMetadata.hpp"
|
||||
#include "../../../src/ScriptResolving/AngelScript/AngelScriptMetadata.hpp"
|
||||
#include "Arbutils/StringView.hpp"
|
||||
#include "doctest.h"
|
||||
|
||||
TEST_CASE("Metadata without parameters") {
|
||||
auto m = AngelscriptMetadata("Foo");
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD and ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD && ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||
#include "../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD and ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../../../src/Battling/Battle/Battle.hpp"
|
||||
#include "../../../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD and ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD and ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD and ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD and ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD && ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#if TESTS_BUILD and ANGELSCRIPT
|
||||
#include <doctest.h>
|
||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||
63
tests/ScriptTests/WASM/ScriptResolverTests.cpp
Normal file
63
tests/ScriptTests/WASM/ScriptResolverTests.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#if TESTS_BUILD && WASM
|
||||
#include <doctest.h>
|
||||
#include "../../TestLibrary/TestLibrary.hpp"
|
||||
#include "../../src/ScriptResolving/WASM/WebAssemblyFunctionCall.hpp"
|
||||
#include "../../src/ScriptResolving/WASM/WebAssemblyScriptResolver.hpp"
|
||||
|
||||
TEST_CASE("Get a script resolver, initialize it, then delete it") {
|
||||
auto lib = PkmnLib::Battling::BattleLibrary::CreateScriptResolver();
|
||||
lib->Initialize(TestLibrary::GetLibrary());
|
||||
delete lib;
|
||||
}
|
||||
|
||||
TEST_CASE("Get a script resolver, load simple wat, run function") {
|
||||
auto lib = dynamic_cast<WebAssemblyScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||
lib->Initialize(TestLibrary::GetLibrary());
|
||||
auto res = lib->LoadWatFromString(R"(
|
||||
(module
|
||||
(type $add_one_t (func (param i32) (result i32)))
|
||||
(func $add_one_f (type $add_one_t) (param $value i32) (result i32)
|
||||
local.get $value
|
||||
i32.const 1
|
||||
i32.add)
|
||||
(export "add_one" (func $add_one_f))
|
||||
)
|
||||
)");
|
||||
REQUIRE_EQ(0, res);
|
||||
lib->Finalize();
|
||||
auto func_opt = lib->GetFunction<1, 1>("add_one");
|
||||
REQUIRE(func_opt.has_value());
|
||||
auto& func = func_opt.value();
|
||||
func.Loadi32(0, 684);
|
||||
func.Call();
|
||||
REQUIRE_EQ(func.GetResultAsi32(), 685);
|
||||
delete lib;
|
||||
}
|
||||
|
||||
TEST_CASE("Get a script resolver, load a real wasm script") {
|
||||
auto lib = dynamic_cast<WebAssemblyScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||
lib->Initialize(TestLibrary::GetLibrary());
|
||||
std::string file_path = __FILE__;
|
||||
std::string dir_path = file_path.substr(0, file_path.rfind("/"));
|
||||
auto res = lib->LoadWasmFromFile(dir_path + "/gen7_scripts_rs.wasm");
|
||||
REQUIRE_EQ(0, res);
|
||||
lib->Finalize();
|
||||
delete lib;
|
||||
}
|
||||
|
||||
TEST_CASE("Get a script resolver, load a real wasm script, load test script") {
|
||||
ArbUt::ScopedPtr<WebAssemblyScriptResolver> lib =
|
||||
dynamic_cast<WebAssemblyScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||
lib->Initialize(TestLibrary::GetLibrary());
|
||||
std::string file_path = __FILE__;
|
||||
std::string dir_path = file_path.substr(0, file_path.rfind("/"));
|
||||
auto res = lib->LoadWasmFromFile(dir_path + "/gen7_scripts_rs.wasm");
|
||||
REQUIRE_EQ(0, res);
|
||||
lib->Finalize();
|
||||
auto script = lib->LoadScript(nullptr, ScriptCategory::Attack, "test"_cnc);
|
||||
EnsureNotNull(script);
|
||||
script->OnInitialize(TestLibrary::GetLibrary(), {});
|
||||
delete script;
|
||||
}
|
||||
|
||||
#endif
|
||||
BIN
tests/ScriptTests/WASM/gen7_scripts_rs.wasm
Executable file
BIN
tests/ScriptTests/WASM/gen7_scripts_rs.wasm
Executable file
Binary file not shown.
Reference in New Issue
Block a user