Files
simian/tests/script_engine_tests.cpp
T
nick 4a43160537
CI / build-and-test (push) Successful in 2m19s
feat: math and texture functions. update tests
2025-11-19 15:49:03 +13:00

59 lines
1.7 KiB
C++

#define TEST_NO_MAIN
#include "acutest.h"
#include <filesystem>
#include <fstream>
#include "../include/scripting/ScriptEngine.h"
void test_scriptengine_compile_and_call(void) {
std::filesystem::path tmpDir = std::filesystem::current_path() / "tmp_script";
std::filesystem::create_directories(tmpDir);
std::filesystem::path script = tmpDir / "simple.as";
{
std::ofstream ofs(script);
ofs << "float g_x = 0;\n";
ofs << "void Update(float dt) { g_x += dt * 10.0f; }\n";
}
ScriptEngine se;
TEST_CHECK(se.Initialize() == true);
bool ok = se.CompileScript(script.string());
TEST_CHECK(ok == true);
asIScriptFunction* upd = se.GetUpdateFunction();
TEST_CHECK(upd != nullptr);
se.CallScriptFunction(upd, 0.1f);
se.Shutdown();
std::filesystem::remove(script);
std::filesystem::remove(tmpDir);
}
void test_scriptengine_include(void) {
std::filesystem::path tmpDir = std::filesystem::current_path() / "tmp_include";
std::filesystem::create_directories(tmpDir);
std::filesystem::path inc = tmpDir / "inc.as";
{
std::ofstream ofsinc(inc);
ofsinc << "void Included() { Print(\"Included called\"); }\n";
}
std::filesystem::path main = tmpDir / "main.as";
{
std::ofstream ofsmain(main);
ofsmain << "#include \"inc.as\"\n";
ofsmain << "void Update(float dt) { Included(); }\n";
}
ScriptEngine se;
TEST_CHECK(se.Initialize() == true);
bool ok = se.CompileScript(main.string());
TEST_CHECK(ok == true);
se.Shutdown();
std::filesystem::remove(inc);
std::filesystem::remove(main);
std::filesystem::remove(tmpDir);
}