Changes tests to use global g_ScriptRuntime instead of creating a new JSRuntime for each test.
The tests crashed on my Debian systems but not on my Ubuntu system. The crash happened in line 142 of SpiderMonkey's ThreadLocal.h. I know that I had to use a workarounnd for contexts to avoid destroying the context that was created first. I also had in mind that in newer versions a JS_Init function got introduced which presumably solves this kind of issues. Based on this experience I assumed runtimes could have a similar problem and this patch indeed fixes the issues. Unfortunately the correct usage of JSRuntimes in that regard is not documented. There's only a rater misterious comment in JSAPI.h which hasn't been cleared up so far and is most likely completely outdated (https://bugzilla.mozilla.org/show_bug.cgi?id=992641). This was SVN commit r14995.
This commit is contained in:
parent
49fc88ff81
commit
7acdde5c86
@ -27,7 +27,7 @@ class TestLOSTexture : public CxxTest::TestSuite
|
||||
public:
|
||||
void test_basic()
|
||||
{
|
||||
CSimulation2 sim(NULL, ScriptInterface::CreateRuntime(), NULL);
|
||||
CSimulation2 sim(NULL, g_ScriptRuntime, NULL);
|
||||
CLOSTexture tex(sim);
|
||||
|
||||
const ssize_t size = 8;
|
||||
|
@ -134,7 +134,7 @@ public:
|
||||
// This doesn't actually test much, it just runs a very quick multiplayer game
|
||||
// and prints a load of debug output so you can see if anything funny's going on
|
||||
|
||||
ScriptInterface scriptInterface("Engine", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface scriptInterface("Engine", "Test", g_ScriptRuntime);
|
||||
TestStdoutLogger logger;
|
||||
|
||||
std::vector<CNetClient*> clients;
|
||||
@ -196,7 +196,7 @@ public:
|
||||
|
||||
void test_rejoin_DISABLED()
|
||||
{
|
||||
ScriptInterface scriptInterface("Engine", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface scriptInterface("Engine", "Test", g_ScriptRuntime);
|
||||
TestStdoutLogger logger;
|
||||
|
||||
std::vector<CNetClient*> clients;
|
||||
|
@ -26,7 +26,7 @@ class TestNetMessage : public CxxTest::TestSuite
|
||||
public:
|
||||
void test_sim()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
CScriptValRooted val;
|
||||
script.Eval("[4]", val);
|
||||
CSimulationMessage msg(script, 1, 2, 3, val.get());
|
||||
|
@ -30,7 +30,7 @@ class TestScriptConversions : public CxxTest::TestSuite
|
||||
template <typename T>
|
||||
void convert_to(const T& value, const std::string& expected)
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
JSContext* cx = script.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
@ -48,7 +48,7 @@ class TestScriptConversions : public CxxTest::TestSuite
|
||||
template <typename T>
|
||||
void roundtrip(const T& value, const char* expected)
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
JSContext* cx = script.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
@ -125,7 +125,7 @@ public:
|
||||
|
||||
void test_integers()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
JSContext* cx = script.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
@ -158,7 +158,7 @@ public:
|
||||
roundtrip<float>(-std::numeric_limits<float>::infinity(), "-Infinity");
|
||||
convert_to<float>(std::numeric_limits<float>::quiet_NaN(), "NaN"); // can't use roundtrip since nan != nan
|
||||
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
JSContext* cx = script.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
|
@ -28,7 +28,7 @@ class TestScriptInterface : public CxxTest::TestSuite
|
||||
public:
|
||||
void test_loadscript_basic()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
TestLogger logger;
|
||||
TS_ASSERT(script.LoadScript(L"test.js", "var x = 1+1;"));
|
||||
TS_ASSERT_WSTR_NOT_CONTAINS(logger.GetOutput(), L"JavaScript error");
|
||||
@ -37,7 +37,7 @@ public:
|
||||
|
||||
void test_loadscript_error()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
TestLogger logger;
|
||||
TS_ASSERT(!script.LoadScript(L"test.js", "1+"));
|
||||
TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"JavaScript error: test.js line 1\nSyntaxError: syntax error");
|
||||
@ -45,7 +45,7 @@ public:
|
||||
|
||||
void test_loadscript_strict_warning()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
TestLogger logger;
|
||||
TS_ASSERT(script.LoadScript(L"test.js", "1+1;"));
|
||||
TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"JavaScript warning: test.js line 1\nuseless expression");
|
||||
@ -53,7 +53,7 @@ public:
|
||||
|
||||
void test_loadscript_strict_error()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
TestLogger logger;
|
||||
TS_ASSERT(!script.LoadScript(L"test.js", "with(1){}"));
|
||||
TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"JavaScript error: test.js line 1\nSyntaxError: strict mode code may not contain \'with\' statements");
|
||||
@ -61,9 +61,8 @@ public:
|
||||
|
||||
void test_clone_basic()
|
||||
{
|
||||
shared_ptr<ScriptRuntime> runtime = ScriptInterface::CreateRuntime();
|
||||
ScriptInterface script1("Test", "Test", runtime);
|
||||
ScriptInterface script2("Test", "Test", runtime);
|
||||
ScriptInterface script1("Test", "Test", g_ScriptRuntime);
|
||||
ScriptInterface script2("Test", "Test", g_ScriptRuntime);
|
||||
|
||||
CScriptVal obj1;
|
||||
TS_ASSERT(script1.Eval("({'x': 123, 'y': [1, 1.5, '2', 'test', undefined, null, true, false]})", obj1));
|
||||
@ -78,10 +77,8 @@ public:
|
||||
void test_clone_getters()
|
||||
{
|
||||
// The tests should be run with JS_SetGCZeal so this can try to find GC bugs
|
||||
|
||||
shared_ptr<ScriptRuntime> runtime = ScriptInterface::CreateRuntime();
|
||||
ScriptInterface script1("Test", "Test", runtime);
|
||||
ScriptInterface script2("Test", "Test", runtime);
|
||||
ScriptInterface script1("Test", "Test", g_ScriptRuntime);
|
||||
ScriptInterface script2("Test", "Test", g_ScriptRuntime);
|
||||
|
||||
CScriptVal obj1;
|
||||
TS_ASSERT(script1.Eval("var s = '?'; var v = ({get x() { return 123 }, 'y': {'w':{get z() { delete v.y; delete v.n; v = null; s += s; return 4 }}}, 'n': 100}); v", obj1));
|
||||
@ -95,9 +92,8 @@ public:
|
||||
|
||||
void test_clone_cyclic()
|
||||
{
|
||||
shared_ptr<ScriptRuntime> runtime = ScriptInterface::CreateRuntime();
|
||||
ScriptInterface script1("Test", "Test", runtime);
|
||||
ScriptInterface script2("Test", "Test", runtime);
|
||||
ScriptInterface script1("Test", "Test", g_ScriptRuntime);
|
||||
ScriptInterface script2("Test", "Test", g_ScriptRuntime);
|
||||
|
||||
CScriptVal obj1;
|
||||
TS_ASSERT(script1.Eval("var x = []; x[0] = x; ({'a': x, 'b': x})", obj1));
|
||||
@ -121,7 +117,7 @@ public:
|
||||
|
||||
void test_random()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
|
||||
double d1, d2;
|
||||
TS_ASSERT(script.Eval("Math.random()", d1));
|
||||
@ -141,7 +137,7 @@ public:
|
||||
|
||||
void test_json()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
|
||||
std::string input = "({'x':1,'z':[2,'3\\u263A\\ud800'],\"y\":true})";
|
||||
CScriptValRooted val;
|
||||
|
@ -27,7 +27,7 @@ class TestScriptVal : public CxxTest::TestSuite
|
||||
public:
|
||||
void test_rooting()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
JSContext* cx = script.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
|
||||
void test_basic()
|
||||
{
|
||||
ComponentTestHelper test(ScriptInterface::CreateRuntime());
|
||||
ComponentTestHelper test(g_ScriptRuntime);
|
||||
|
||||
std::vector<SimulationCommand> empty;
|
||||
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
ent3z = ent2z + ent2r + ent3r; // ensure it just touches the border of ent2
|
||||
ent3g = ent3;
|
||||
|
||||
testHelper = new ComponentTestHelper(ScriptInterface::CreateRuntime());
|
||||
testHelper = new ComponentTestHelper(g_ScriptRuntime);
|
||||
cmp = testHelper->Add<ICmpObstructionManager>(CID_ObstructionManager, "");
|
||||
cmp->SetBounds(fixed::FromInt(0), fixed::FromInt(0), fixed::FromInt(1000), fixed::FromInt(1000));
|
||||
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
{
|
||||
CTerrain terrain;
|
||||
|
||||
CSimulation2 sim2(NULL, ScriptInterface::CreateRuntime(), &terrain);
|
||||
CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain);
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
@ -112,7 +112,7 @@ public:
|
||||
CTerrain terrain;
|
||||
terrain.Initialize(5, NULL);
|
||||
|
||||
CSimulation2 sim2(NULL, ScriptInterface::CreateRuntime(), &terrain);
|
||||
CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain);
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
|
||||
void test_basic()
|
||||
{
|
||||
ComponentTestHelper test(ScriptInterface::CreateRuntime());
|
||||
ComponentTestHelper test(g_ScriptRuntime);
|
||||
|
||||
MockTerrain terrain;
|
||||
test.AddMock(SYSTEM_ENTITY, IID_Terrain, terrain);
|
||||
@ -111,7 +111,7 @@ public:
|
||||
|
||||
void test_serialize()
|
||||
{
|
||||
ComponentTestHelper test(ScriptInterface::CreateRuntime());
|
||||
ComponentTestHelper test(g_ScriptRuntime);
|
||||
|
||||
MockTerrain terrain;
|
||||
test.AddMock(SYSTEM_ENTITY, IID_Terrain, terrain);
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
|
||||
void test_basic()
|
||||
{
|
||||
ComponentTestHelper test(ScriptInterface::CreateRuntime());
|
||||
ComponentTestHelper test(g_ScriptRuntime);
|
||||
|
||||
ICmpRangeManager* cmp = test.Add<ICmpRangeManager>(CID_RangeManager, "");
|
||||
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
for (size_t i = 0; i < paths.size(); ++i)
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager componentManager(context, ScriptInterface::CreateRuntime(), true);
|
||||
CComponentManager componentManager(context, g_ScriptRuntime, true);
|
||||
|
||||
ScriptTestSetup(componentManager.GetScriptInterface());
|
||||
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
void test_LoadTemplate()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
entity_id_t ent1 = 1, ent2 = 2;
|
||||
@ -114,7 +114,7 @@ public:
|
||||
void test_LoadTemplate_scriptcache()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
entity_id_t ent1 = 1, ent2 = 2;
|
||||
@ -153,7 +153,7 @@ public:
|
||||
void test_LoadTemplate_errors()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
entity_id_t ent1 = 1, ent2 = 2;
|
||||
@ -185,7 +185,7 @@ public:
|
||||
void test_LoadTemplate_multiple()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
entity_id_t ent1 = 1, ent2 = 2;
|
||||
@ -244,7 +244,7 @@ public:
|
||||
void test_load_all_DISABLED() // disabled since it's a bit slow and noisy
|
||||
{
|
||||
CTerrain dummy;
|
||||
CSimulation2 sim(NULL, ScriptInterface::CreateRuntime(), &dummy);
|
||||
CSimulation2 sim(NULL, g_ScriptRuntime, &dummy);
|
||||
sim.LoadDefaultScripts();
|
||||
sim.ResetState();
|
||||
|
||||
|
@ -59,14 +59,14 @@ public:
|
||||
void test_Load()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
}
|
||||
|
||||
void test_LookupCID()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
TS_ASSERT_EQUALS(man.LookupCID("Test1A"), (int)CID_Test1A);
|
||||
@ -76,7 +76,7 @@ public:
|
||||
void test_AllocateNewEntity()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
|
||||
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)2);
|
||||
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)3);
|
||||
@ -99,7 +99,7 @@ public:
|
||||
void test_AddComponent_errors()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
CEntityHandle hnd1 = man.AllocateEntityHandle(1);
|
||||
|
||||
@ -122,7 +122,7 @@ public:
|
||||
void test_QueryInterface()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
entity_id_t ent1 = 1, ent2 = 2;
|
||||
@ -147,7 +147,7 @@ public:
|
||||
void test_SendMessage()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4;
|
||||
@ -221,7 +221,7 @@ public:
|
||||
void test_ParamNode()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
entity_id_t ent1 = 1, ent2 = 2;
|
||||
@ -242,7 +242,7 @@ public:
|
||||
void test_script_basic()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test.js"));
|
||||
|
||||
@ -286,7 +286,7 @@ public:
|
||||
void test_script_helper_basic()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-helper.js"));
|
||||
TS_ASSERT(man.LoadScript(L"simulation/helpers/test-helper.js"));
|
||||
@ -303,7 +303,7 @@ public:
|
||||
void test_script_global_helper()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-global-helper.js"));
|
||||
|
||||
@ -319,7 +319,7 @@ public:
|
||||
void test_script_interface()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/interfaces/test-interface.js"));
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-interface.js"));
|
||||
@ -337,7 +337,7 @@ public:
|
||||
void test_script_errors()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
ScriptTestSetup(man.m_ScriptInterface);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
@ -354,7 +354,7 @@ public:
|
||||
void test_script_entityID()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
ScriptTestSetup(man.m_ScriptInterface);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-entityid.js"));
|
||||
@ -374,7 +374,7 @@ public:
|
||||
void test_script_QueryInterface()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-query.js"));
|
||||
|
||||
@ -395,7 +395,7 @@ public:
|
||||
void test_script_AddEntity()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-addentity.js"));
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/addentity/test-addentity.js"));
|
||||
@ -428,7 +428,7 @@ public:
|
||||
void test_script_AddLocalEntity()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-addentity.js"));
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/addentity/test-addentity.js"));
|
||||
@ -461,7 +461,7 @@ public:
|
||||
void test_script_DestroyEntity()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-destroyentity.js"));
|
||||
|
||||
@ -481,7 +481,7 @@ public:
|
||||
void test_script_messages()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-msg.js"));
|
||||
|
||||
@ -514,7 +514,7 @@ public:
|
||||
void test_script_template()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js"));
|
||||
|
||||
@ -536,7 +536,7 @@ public:
|
||||
void test_script_template_readonly()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js"));
|
||||
|
||||
@ -558,7 +558,7 @@ public:
|
||||
void test_script_hotload()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-hotload1.js"));
|
||||
@ -594,8 +594,7 @@ public:
|
||||
void test_serialization()
|
||||
{
|
||||
CSimContext context;
|
||||
shared_ptr<ScriptRuntime> runtime = ScriptInterface::CreateRuntime();
|
||||
CComponentManager man(context, runtime);
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
|
||||
entity_id_t ent1 = 1, ent2 = 2, ent3 = FIRST_LOCAL_ENTITY;
|
||||
@ -665,7 +664,7 @@ public:
|
||||
);
|
||||
|
||||
CSimContext context2;
|
||||
CComponentManager man2(context2, runtime);
|
||||
CComponentManager man2(context2, g_ScriptRuntime);
|
||||
man2.LoadComponentTypes();
|
||||
|
||||
TS_ASSERT(man2.QueryInterface(ent1, IID_Test1) == NULL);
|
||||
@ -684,9 +683,8 @@ public:
|
||||
void test_script_serialization()
|
||||
{
|
||||
CSimContext context;
|
||||
shared_ptr<ScriptRuntime> runtime = ScriptInterface::CreateRuntime();
|
||||
|
||||
CComponentManager man(context, runtime);
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
ScriptTestSetup(man.m_ScriptInterface);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js"));
|
||||
@ -762,7 +760,7 @@ entities:\n\
|
||||
TS_ASSERT(man.SerializeState(stateStream));
|
||||
|
||||
CSimContext context2;
|
||||
CComponentManager man2(context2, runtime);
|
||||
CComponentManager man2(context2, g_ScriptRuntime);
|
||||
man2.LoadComponentTypes();
|
||||
TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js"));
|
||||
|
||||
@ -779,7 +777,7 @@ entities:\n\
|
||||
void test_script_serialization_errors()
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager man(context, ScriptInterface::CreateRuntime());
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js"));
|
||||
|
||||
@ -797,9 +795,8 @@ entities:\n\
|
||||
void test_script_serialization_template()
|
||||
{
|
||||
CSimContext context;
|
||||
shared_ptr<ScriptRuntime> runtime = ScriptInterface::CreateRuntime();
|
||||
|
||||
CComponentManager man(context, runtime);
|
||||
CComponentManager man(context, g_ScriptRuntime);
|
||||
man.LoadComponentTypes();
|
||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js"));
|
||||
man.InitSystemEntity();
|
||||
@ -823,7 +820,7 @@ entities:\n\
|
||||
TS_ASSERT(man.SerializeState(stateStream));
|
||||
|
||||
CSimContext context2;
|
||||
CComponentManager man2(context2, runtime);
|
||||
CComponentManager man2(context2, g_ScriptRuntime);
|
||||
man2.LoadComponentTypes();
|
||||
TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js"));
|
||||
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
|
||||
void test_Debug_basic()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
std::stringstream stream;
|
||||
CDebugSerializer serialize(script, stream);
|
||||
serialize.NumberI32_Unbounded("x", -123);
|
||||
@ -85,7 +85,7 @@ public:
|
||||
|
||||
void test_Debug_floats()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
std::stringstream stream;
|
||||
CDebugSerializer serialize(script, stream);
|
||||
serialize.NumberFloat_Unbounded("x", 1e4f);
|
||||
@ -116,7 +116,7 @@ public:
|
||||
|
||||
void test_Debug_types()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
std::stringstream stream;
|
||||
CDebugSerializer serialize(script, stream);
|
||||
|
||||
@ -147,7 +147,7 @@ public:
|
||||
|
||||
void test_Std_basic()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
std::stringstream stream;
|
||||
CStdSerializer serialize(script, stream);
|
||||
|
||||
@ -173,7 +173,7 @@ public:
|
||||
|
||||
void test_Std_types()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
std::stringstream stream;
|
||||
CStdSerializer serialize(script, stream);
|
||||
|
||||
@ -239,7 +239,7 @@ public:
|
||||
|
||||
void test_Hash_basic()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
CHashSerializer serialize(script);
|
||||
|
||||
serialize.NumberI32_Unbounded("x", -123);
|
||||
@ -253,7 +253,7 @@ public:
|
||||
|
||||
void test_bounds()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
std::stringstream stream;
|
||||
CDebugSerializer serialize(script, stream);
|
||||
serialize.NumberI32("x", 16, -16, 16);
|
||||
@ -266,7 +266,7 @@ public:
|
||||
|
||||
void test_script_basic()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
CScriptVal obj;
|
||||
TS_ASSERT(script.Eval("({'x': 123, 'y': [1, 1.5, '2', 'test', undefined, null, true, false]})", obj));
|
||||
|
||||
@ -339,7 +339,7 @@ public:
|
||||
|
||||
void helper_script_roundtrip(const char* msg, const char* input, const char* expected, size_t expstreamlen = 0, const char* expstream = NULL)
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
CScriptVal obj;
|
||||
TSM_ASSERT(msg, script.Eval(input, obj));
|
||||
|
||||
@ -566,7 +566,7 @@ public:
|
||||
|
||||
void test_script_exceptions()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
CScriptVal obj;
|
||||
|
||||
std::stringstream stream;
|
||||
@ -598,7 +598,7 @@ public:
|
||||
{
|
||||
const char* input = "var x = {}; for (var i=0;i<256;++i) x[i]=Math.pow(i, 2); x";
|
||||
|
||||
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
CScriptVal obj;
|
||||
TS_ASSERT(script.Eval(input, obj));
|
||||
|
||||
@ -640,7 +640,7 @@ public:
|
||||
|
||||
CTerrain terrain;
|
||||
|
||||
CSimulation2 sim2(NULL, ScriptInterface::CreateRuntime(), &terrain);
|
||||
CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain);
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
|
||||
void test_AddEntity()
|
||||
{
|
||||
CSimulation2 sim(NULL, ScriptInterface::CreateRuntime(), &m_Terrain);
|
||||
CSimulation2 sim(NULL, g_ScriptRuntime, &m_Terrain);
|
||||
TS_ASSERT(sim.LoadScripts(L"simulation/components/addentity/"));
|
||||
|
||||
sim.ResetState(true, true);
|
||||
@ -77,7 +77,7 @@ public:
|
||||
|
||||
void test_DestroyEntity()
|
||||
{
|
||||
CSimulation2 sim(NULL, ScriptInterface::CreateRuntime(), &m_Terrain);
|
||||
CSimulation2 sim(NULL, g_ScriptRuntime, &m_Terrain);
|
||||
TS_ASSERT(sim.LoadScripts(L"simulation/components/addentity/"));
|
||||
|
||||
sim.ResetState(true, true);
|
||||
@ -129,7 +129,7 @@ public:
|
||||
|
||||
void test_hotload_scripts()
|
||||
{
|
||||
CSimulation2 sim(NULL, ScriptInterface::CreateRuntime(), &m_Terrain);
|
||||
CSimulation2 sim(NULL, g_ScriptRuntime, &m_Terrain);
|
||||
|
||||
TS_ASSERT_OK(CreateDirectories(DataDir()/"mods"/"_test.sim"/"simulation"/"components"/"hotload"/"", 0700));
|
||||
|
||||
|
@ -81,12 +81,14 @@ class MiscSetup : public CxxTest::GlobalFixture
|
||||
ThreadUtil::SetMainThread();
|
||||
|
||||
g_Profiler2.Initialise();
|
||||
g_ScriptRuntime = ScriptInterface::CreateRuntime();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool tearDownWorld()
|
||||
{
|
||||
g_ScriptRuntime.reset();
|
||||
g_Profiler2.Shutdown();
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user