Changeset View
Changeset View
Standalone View
Standalone View
source/test_setup.cpp
Show All 30 Lines | |||||
#if OS_WIN | #if OS_WIN | ||||
#include "lib/sysdep/os/win/wdbg_heap.h" | #include "lib/sysdep/os/win/wdbg_heap.h" | ||||
#endif | #endif | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "lib/sysdep/sysdep.h" | #include "lib/sysdep/sysdep.h" | ||||
#include "ps/Profiler2.h" | #include "ps/Profiler2.h" | ||||
#include "scriptinterface/FunctionWrapper.h" | |||||
#include "scriptinterface/ScriptEngine.h" | #include "scriptinterface/ScriptEngine.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
class LeakReporter : public CxxTest::GlobalFixture | class LeakReporter : public CxxTest::GlobalFixture | ||||
{ | { | ||||
virtual bool tearDownWorld() | virtual bool tearDownWorld() | ||||
{ | { | ||||
// Enable leak reporting on exit. | // Enable leak reporting on exit. | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return sys_ExecutablePathname().Parent()/".."/"data"; | return sys_ExecutablePathname().Parent()/".."/"data"; | ||||
} | } | ||||
// Script-based testing setup: | // Script-based testing setup: | ||||
namespace | namespace | ||||
{ | { | ||||
void script_TS_FAIL(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& msg) | void script_TS_FAIL(const std::wstring& msg) | ||||
{ | { | ||||
TS_FAIL(utf8_from_wstring(msg).c_str()); | TS_FAIL(utf8_from_wstring(msg).c_str()); | ||||
} | } | ||||
} | } | ||||
void ScriptTestSetup(const ScriptInterface& scriptinterface) | void ScriptTestSetup(const ScriptInterface& scriptinterface) | ||||
{ | { | ||||
scriptinterface.RegisterFunction<void, std::wstring, script_TS_FAIL>("TS_FAIL"); | ScriptWrapper::WrapAndRegister<decltype(&script_TS_FAIL), &script_TS_FAIL>(scriptinterface, "TS_FAIL"); | ||||
// Load the TS_* function definitions | // Load the TS_* function definitions | ||||
// (We don't use VFS because tests might not have the normal VFS paths loaded) | // (We don't use VFS because tests might not have the normal VFS paths loaded) | ||||
OsPath path = DataDir()/"tests"/"test_setup.js"; | OsPath path = DataDir()/"tests"/"test_setup.js"; | ||||
std::ifstream ifs(OsString(path).c_str()); | std::ifstream ifs(OsString(path).c_str()); | ||||
ENSURE(ifs.good()); | ENSURE(ifs.good()); | ||||
std::string content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); | std::string content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); | ||||
bool ok = scriptinterface.LoadScript(L"test_setup.js", content); | bool ok = scriptinterface.LoadScript(L"test_setup.js", content); | ||||
ENSURE(ok); | ENSURE(ok); | ||||
} | } |
Wildfire Games · Phabricator