Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/tests/test_Simulation2.h
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | public: | ||||
{ | { | ||||
CXeromyces::Terminate(); | CXeromyces::Terminate(); | ||||
g_VFS.reset(); | g_VFS.reset(); | ||||
DeleteDirectory(DataDir()/"_testcache"); | DeleteDirectory(DataDir()/"_testcache"); | ||||
} | } | ||||
void test_AddEntity() | void test_AddEntity() | ||||
{ | { | ||||
CSimulation2 sim(NULL, g_ScriptRuntime, &m_Terrain); | CSimulation2 sim(NULL, g_ScriptContext, &m_Terrain); | ||||
TS_ASSERT(sim.LoadScripts(L"simulation/components/addentity/")); | TS_ASSERT(sim.LoadScripts(L"simulation/components/addentity/")); | ||||
sim.ResetState(true, true); | sim.ResetState(true, true); | ||||
entity_id_t ent1 = sim.AddEntity(L"test1"); | entity_id_t ent1 = sim.AddEntity(L"test1"); | ||||
TS_ASSERT_EQUALS(ent1, (u32)2); | TS_ASSERT_EQUALS(ent1, (u32)2); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (sim.QueryInterface(ent1, IID_Test1))->GetX(), 999); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (sim.QueryInterface(ent1, IID_Test1))->GetX(), 999); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (sim.QueryInterface(ent1, IID_Test2))->GetX(), 12345); | TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (sim.QueryInterface(ent1, IID_Test2))->GetX(), 12345); | ||||
entity_id_t ent2 = sim.AddEntity(L"test1-inherit"); | entity_id_t ent2 = sim.AddEntity(L"test1-inherit"); | ||||
TS_ASSERT_EQUALS(ent2, (u32)3); | TS_ASSERT_EQUALS(ent2, (u32)3); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (sim.QueryInterface(ent2, IID_Test1))->GetX(), 1234); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (sim.QueryInterface(ent2, IID_Test1))->GetX(), 1234); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (sim.QueryInterface(ent2, IID_Test2))->GetX(), 12345); | TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (sim.QueryInterface(ent2, IID_Test2))->GetX(), 12345); | ||||
} | } | ||||
void test_DestroyEntity() | void test_DestroyEntity() | ||||
{ | { | ||||
CSimulation2 sim(NULL, g_ScriptRuntime, &m_Terrain); | CSimulation2 sim(NULL, g_ScriptContext, &m_Terrain); | ||||
TS_ASSERT(sim.LoadScripts(L"simulation/components/addentity/")); | TS_ASSERT(sim.LoadScripts(L"simulation/components/addentity/")); | ||||
sim.ResetState(true, true); | sim.ResetState(true, true); | ||||
entity_id_t ent1 = sim.AddEntity(L"test1"); | entity_id_t ent1 = sim.AddEntity(L"test1"); | ||||
entity_id_t ent2 = sim.AddEntity(L"test1"); | entity_id_t ent2 = sim.AddEntity(L"test1"); | ||||
entity_id_t ent3 = sim.AddEntity(L"test1"); | entity_id_t ent3 = sim.AddEntity(L"test1"); | ||||
Show All 39 Lines | void test_DestroyEntity() | ||||
// Messages mustn't get sent to the destroyed components (else we'll crash) | // Messages mustn't get sent to the destroyed components (else we'll crash) | ||||
CMessageTurnStart msg; | CMessageTurnStart msg; | ||||
sim.BroadcastMessage(msg); | sim.BroadcastMessage(msg); | ||||
} | } | ||||
void test_hotload_scripts() | void test_hotload_scripts() | ||||
{ | { | ||||
CSimulation2 sim(NULL, g_ScriptRuntime, &m_Terrain); | CSimulation2 sim(NULL, g_ScriptContext, &m_Terrain); | ||||
TS_ASSERT_OK(CreateDirectories(DataDir()/"mods"/"_test.sim"/"simulation"/"components"/"hotload"/"", 0700)); | TS_ASSERT_OK(CreateDirectories(DataDir()/"mods"/"_test.sim"/"simulation"/"components"/"hotload"/"", 0700)); | ||||
copyFile(L"simulation/components/test-hotload1.js", L"simulation/components/hotload/hotload.js"); | copyFile(L"simulation/components/test-hotload1.js", L"simulation/components/hotload/hotload.js"); | ||||
TS_ASSERT_OK(g_VFS->RemoveFile(L"simulation/components/hotload/hotload.js")); | TS_ASSERT_OK(g_VFS->RemoveFile(L"simulation/components/hotload/hotload.js")); | ||||
TS_ASSERT_OK(g_VFS->RepopulateDirectory(L"simulation/components/hotload/")); | TS_ASSERT_OK(g_VFS->RepopulateDirectory(L"simulation/components/hotload/")); | ||||
TS_ASSERT(sim.LoadScripts(L"simulation/components/hotload/")); | TS_ASSERT(sim.LoadScripts(L"simulation/components/hotload/")); | ||||
Show All 27 Lines |
Wildfire Games · Phabricator