Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/tests/test_ComponentManager.h
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | void tearDown() | ||||
CXeromyces::Terminate(); | CXeromyces::Terminate(); | ||||
g_VFS.reset(); | g_VFS.reset(); | ||||
DeleteDirectory(DataDir()/"_testcache"); | DeleteDirectory(DataDir()/"_testcache"); | ||||
} | } | ||||
void test_Load() | void test_Load() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
} | } | ||||
void test_LookupCID() | void test_LookupCID() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT_EQUALS(man.LookupCID("Test1A"), (int)CID_Test1A); | TS_ASSERT_EQUALS(man.LookupCID("Test1A"), (int)CID_Test1A); | ||||
TS_ASSERT_EQUALS(man.LookupCID("Test1B"), (int)CID_Test1B); | TS_ASSERT_EQUALS(man.LookupCID("Test1B"), (int)CID_Test1B); | ||||
} | } | ||||
void test_AllocateNewEntity() | void test_AllocateNewEntity() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)2); | TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)2); | ||||
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)3); | TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)3); | ||||
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)4); | TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)4); | ||||
TS_ASSERT_EQUALS(man.AllocateNewEntity(100), (u32)100); | TS_ASSERT_EQUALS(man.AllocateNewEntity(100), (u32)100); | ||||
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)101); | TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)101); | ||||
// TODO: | // TODO: | ||||
// TS_ASSERT_EQUALS(man.AllocateNewEntity(3), (u32)102); | // TS_ASSERT_EQUALS(man.AllocateNewEntity(3), (u32)102); | ||||
Show All 9 Lines | public: | ||||
} | } | ||||
void test_rng() | void test_rng() | ||||
{ | { | ||||
// Ensure we get the same random number with the same seed | // Ensure we get the same random number with the same seed | ||||
double first; | double first; | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.SetRNGSeed(123); | man.SetRNGSeed(123); | ||||
if (!man.m_ScriptInterface.MathRandom(first)) | if (!man.m_ScriptInterface.MathRandom(first)) | ||||
TS_FAIL("Couldn't get random number!"); | TS_FAIL("Couldn't get random number!"); | ||||
} | } | ||||
double second; | double second; | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.SetRNGSeed(123); | man.SetRNGSeed(123); | ||||
if (!man.m_ScriptInterface.MathRandom(second)) | if (!man.m_ScriptInterface.MathRandom(second)) | ||||
TS_FAIL("Couldn't get random number!"); | TS_FAIL("Couldn't get random number!"); | ||||
} | } | ||||
TS_ASSERT_EQUALS(first, second); | TS_ASSERT_EQUALS(first, second); | ||||
} | } | ||||
void test_AddComponent_errors() | void test_AddComponent_errors() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(1); | CEntityHandle hnd1 = man.AllocateEntityHandle(1); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
TS_ASSERT(man.AddComponent(hnd1, CID_Test1A, noParam)); | TS_ASSERT(man.AddComponent(hnd1, CID_Test1A, noParam)); | ||||
{ | { | ||||
TestLogger log; | TestLogger log; | ||||
TS_ASSERT(! man.AddComponent(hnd1, 12345, noParam)); | TS_ASSERT(! man.AddComponent(hnd1, 12345, noParam)); | ||||
TS_ASSERT_STR_CONTAINS(log.GetOutput(), "ERROR: Invalid component id 12345"); | TS_ASSERT_STR_CONTAINS(log.GetOutput(), "ERROR: Invalid component id 12345"); | ||||
} | } | ||||
{ | { | ||||
TestLogger log; | TestLogger log; | ||||
TS_ASSERT(! man.AddComponent(hnd1, CID_Test1B, noParam)); | TS_ASSERT(! man.AddComponent(hnd1, CID_Test1B, noParam)); | ||||
TS_ASSERT_STR_CONTAINS(log.GetOutput(), "ERROR: Multiple components for interface "); | TS_ASSERT_STR_CONTAINS(log.GetOutput(), "ERROR: Multiple components for interface "); | ||||
} | } | ||||
} | } | ||||
void test_QueryInterface() | void test_QueryInterface() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
entity_id_t ent1 = 1, ent2 = 2; | entity_id_t ent1 = 1, ent2 = 2; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
man.AddComponent(hnd1, CID_Test1A, noParam); | man.AddComponent(hnd1, CID_Test1A, noParam); | ||||
TS_ASSERT(man.QueryInterface(ent1, IID_Test1) != NULL); | TS_ASSERT(man.QueryInterface(ent1, IID_Test1) != NULL); | ||||
TS_ASSERT(man.QueryInterface(ent1, IID_Test2) == NULL); | TS_ASSERT(man.QueryInterface(ent1, IID_Test2) == NULL); | ||||
TS_ASSERT(man.QueryInterface(ent2, IID_Test1) == NULL); | TS_ASSERT(man.QueryInterface(ent2, IID_Test1) == NULL); | ||||
TS_ASSERT(man.QueryInterface(ent2, IID_Test2) == NULL); | TS_ASSERT(man.QueryInterface(ent2, IID_Test2) == NULL); | ||||
man.AddComponent(hnd2, CID_Test1B, noParam); | man.AddComponent(hnd2, CID_Test1B, noParam); | ||||
TS_ASSERT(man.QueryInterface(ent2, IID_Test1) != NULL); | TS_ASSERT(man.QueryInterface(ent2, IID_Test1) != NULL); | ||||
TS_ASSERT(man.QueryInterface(ent2, IID_Test2) == NULL); | TS_ASSERT(man.QueryInterface(ent2, IID_Test2) == NULL); | ||||
man.AddComponent(hnd2, CID_Test2A, noParam); | man.AddComponent(hnd2, CID_Test2A, noParam); | ||||
TS_ASSERT(man.QueryInterface(ent2, IID_Test1) != NULL); | TS_ASSERT(man.QueryInterface(ent2, IID_Test1) != NULL); | ||||
TS_ASSERT(man.QueryInterface(ent2, IID_Test2) != NULL); | TS_ASSERT(man.QueryInterface(ent2, IID_Test2) != NULL); | ||||
} | } | ||||
void test_SendMessage() | void test_SendMessage() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4; | entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3); | CEntityHandle hnd3 = man.AllocateEntityHandle(ent3); | ||||
CEntityHandle hnd4 = man.AllocateEntityHandle(ent4); | CEntityHandle hnd4 = man.AllocateEntityHandle(ent4); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | void test_SendMessage() | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 21150); | TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 21150); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 11003); // local - skipped | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 11003); // local - skipped | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent4, IID_Test2))->GetX(), 21150); | TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent4, IID_Test2))->GetX(), 21150); | ||||
} | } | ||||
void test_ParamNode() | void test_ParamNode() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
entity_id_t ent1 = 1, ent2 = 2; | entity_id_t ent1 = 1, ent2 = 2; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
CParamNode testParam; | CParamNode testParam; | ||||
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>1234</x>"), PSRETURN_OK); | TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>1234</x>"), PSRETURN_OK); | ||||
man.AddComponent(hnd1, CID_Test1A, noParam); | man.AddComponent(hnd1, CID_Test1A, noParam); | ||||
man.AddComponent(hnd2, CID_Test1A, testParam); | man.AddComponent(hnd2, CID_Test1A, testParam); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11000); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11000); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 1234); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 1234); | ||||
} | } | ||||
void test_script_basic() | void test_script_basic() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test.js")); | ||||
TS_ASSERT_EQUALS(man.LookupCID("TestScript1A"), (int)CID__LastNative); | TS_ASSERT_EQUALS(man.LookupCID("TestScript1A"), (int)CID__LastNative); | ||||
TS_ASSERT_EQUALS(man.LookupCID("TestScript1B"), (int)CID__LastNative+1); | TS_ASSERT_EQUALS(man.LookupCID("TestScript1B"), (int)CID__LastNative+1); | ||||
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3; | entity_id_t ent1 = 1, ent2 = 2, ent3 = 3; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
Show All 27 Lines | void test_script_basic() | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 101001); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 101001); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 102001); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 102001); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 201025); | TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 201025); | ||||
} | } | ||||
void test_script_helper_basic() | void test_script_helper_basic() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-helper.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-helper.js")); | ||||
TS_ASSERT(man.LoadScript(L"simulation/helpers/test-helper.js")); | TS_ASSERT(man.LoadScript(L"simulation/helpers/test-helper.js")); | ||||
entity_id_t ent1 = 1; | entity_id_t ent1 = 1; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
man.AddComponent(hnd1, man.LookupCID("TestScript1_Helper"), noParam); | man.AddComponent(hnd1, man.LookupCID("TestScript1_Helper"), noParam); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 3); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 3); | ||||
} | } | ||||
void test_script_global_helper() | void test_script_global_helper() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-global-helper.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-global-helper.js")); | ||||
entity_id_t ent1 = 1; | entity_id_t ent1 = 1; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
man.AddComponent(hnd1, man.LookupCID("TestScript1_GlobalHelper"), noParam); | man.AddComponent(hnd1, man.LookupCID("TestScript1_GlobalHelper"), noParam); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 2); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 2); | ||||
} | } | ||||
void test_script_interface() | void test_script_interface() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/interfaces/test-interface.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/interfaces/test-interface.js")); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-interface.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-interface.js")); | ||||
entity_id_t ent1 = 1; | entity_id_t ent1 = 1; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
man.AddComponent(hnd1, man.LookupCID("TestScript1_Interface"), noParam); | man.AddComponent(hnd1, man.LookupCID("TestScript1_Interface"), noParam); | ||||
man.AddComponent(hnd1, man.LookupCID("TestScript2_Interface"), noParam); | man.AddComponent(hnd1, man.LookupCID("TestScript2_Interface"), noParam); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 1000 + IID__LastNative); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 1000 + IID__LastNative); | ||||
} | } | ||||
void test_script_errors() | void test_script_errors() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
ScriptTestSetup(man.m_ScriptInterface); | ScriptTestSetup(man.m_ScriptInterface); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
{ | { | ||||
TestLogger log; | TestLogger log; | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/error.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/error.js")); | ||||
// In SpiderMonkey 1.6, JS_ReportError calls the error reporter even if it's inside | // In SpiderMonkey 1.6, JS_ReportError calls the error reporter even if it's inside | ||||
// a try{} in the script; in recent versions (not sure when it changed) it doesn't | // a try{} in the script; in recent versions (not sure when it changed) it doesn't | ||||
// so the error here won't get reported. | // so the error here won't get reported. | ||||
TS_ASSERT_STR_NOT_CONTAINS(log.GetOutput(), "ERROR: JavaScript error: simulation/components/error.js line 4\nInvalid interface id"); | TS_ASSERT_STR_NOT_CONTAINS(log.GetOutput(), "ERROR: JavaScript error: simulation/components/error.js line 4\nInvalid interface id"); | ||||
} | } | ||||
} | } | ||||
void test_script_entityID() | void test_script_entityID() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
ScriptTestSetup(man.m_ScriptInterface); | ScriptTestSetup(man.m_ScriptInterface); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-entityid.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-entityid.js")); | ||||
entity_id_t ent1 = 1, ent2 = 234; | entity_id_t ent1 = 1, ent2 = 234; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
man.AddComponent(hnd1, man.LookupCID("TestScript1A"), noParam); | man.AddComponent(hnd1, man.LookupCID("TestScript1A"), noParam); | ||||
man.AddComponent(hnd2, man.LookupCID("TestScript1A"), noParam); | man.AddComponent(hnd2, man.LookupCID("TestScript1A"), noParam); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), (int)ent1); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), (int)ent1); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), (int)ent2); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), (int)ent2); | ||||
} | } | ||||
void test_script_QueryInterface() | void test_script_QueryInterface() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-query.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-query.js")); | ||||
entity_id_t ent1 = 1, ent2 = 2; | entity_id_t ent1 = 1, ent2 = 2; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
man.AddComponent(hnd1, man.LookupCID("TestScript1A"), noParam); | man.AddComponent(hnd1, man.LookupCID("TestScript1A"), noParam); | ||||
man.AddComponent(hnd1, man.LookupCID("TestScript2A"), noParam); | man.AddComponent(hnd1, man.LookupCID("TestScript2A"), noParam); | ||||
man.AddComponent(hnd2, man.LookupCID("TestScript1A"), noParam); | man.AddComponent(hnd2, man.LookupCID("TestScript1A"), noParam); | ||||
man.AddComponent(hnd2, CID_Test2A, noParam); | man.AddComponent(hnd2, CID_Test2A, noParam); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 400); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 400); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 21000); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 21000); | ||||
} | } | ||||
void test_script_AddEntity() | void test_script_AddEntity() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-addentity.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-addentity.js")); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/addentity/test-addentity.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/addentity/test-addentity.js")); | ||||
man.InitSystemEntity(); | man.InitSystemEntity(); | ||||
entity_id_t ent1 = man.AllocateNewEntity(); | entity_id_t ent1 = man.AllocateNewEntity(); | ||||
entity_id_t ent2 = ent1 + 2; | entity_id_t ent2 = ent1 + 2; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
Show All 16 Lines | void test_script_AddEntity() | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 999); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 999); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 12345); | TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 12345); | ||||
} | } | ||||
void test_script_AddLocalEntity() | void test_script_AddLocalEntity() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-addentity.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-addentity.js")); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/addentity/test-addentity.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/addentity/test-addentity.js")); | ||||
man.InitSystemEntity(); | man.InitSystemEntity(); | ||||
entity_id_t ent1 = man.AllocateNewEntity(); | entity_id_t ent1 = man.AllocateNewEntity(); | ||||
entity_id_t ent2 = man.AllocateNewLocalEntity() + 2; | entity_id_t ent2 = man.AllocateNewLocalEntity() + 2; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
Show All 16 Lines | void test_script_AddLocalEntity() | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 999); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 999); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 12345); | TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 12345); | ||||
} | } | ||||
void test_script_DestroyEntity() | void test_script_DestroyEntity() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-destroyentity.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-destroyentity.js")); | ||||
entity_id_t ent1 = 10; | entity_id_t ent1 = 10; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
TS_ASSERT(man.AddComponent(hnd1, man.LookupCID("TestScript1_DestroyEntity"), noParam)); | TS_ASSERT(man.AddComponent(hnd1, man.LookupCID("TestScript1_DestroyEntity"), noParam)); | ||||
TS_ASSERT(man.QueryInterface(ent1, IID_Test1) != NULL); | TS_ASSERT(man.QueryInterface(ent1, IID_Test1) != NULL); | ||||
static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(); | static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(); | ||||
TS_ASSERT(man.QueryInterface(ent1, IID_Test1) != NULL); | TS_ASSERT(man.QueryInterface(ent1, IID_Test1) != NULL); | ||||
man.FlushDestroyedComponents(); | man.FlushDestroyedComponents(); | ||||
TS_ASSERT(man.QueryInterface(ent1, IID_Test1) == NULL); | TS_ASSERT(man.QueryInterface(ent1, IID_Test1) == NULL); | ||||
} | } | ||||
void test_script_messages() | void test_script_messages() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-msg.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-msg.js")); | ||||
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3; | entity_id_t ent1 = 1, ent2 = 2, ent3 = 3; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3); | CEntityHandle hnd3 = man.AllocateEntityHandle(ent3); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
Show All 16 Lines | void test_script_messages() | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 5150); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 5150); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 26050); | TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 26050); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 5650); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 5650); | ||||
} | } | ||||
void test_script_template() | void test_script_template() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js")); | ||||
entity_id_t ent1 = 1, ent2 = 2; | entity_id_t ent1 = 1, ent2 = 2; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
CParamNode testParam; | CParamNode testParam; | ||||
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<node><x>1</x><y>1<z w='100'><a>1000</a></z>0</y></node>"), PSRETURN_OK); | TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<node><x>1</x><y>1<z w='100'><a>1000</a></z>0</y></node>"), PSRETURN_OK); | ||||
man.AddComponent(hnd1, man.LookupCID("TestScript1_Init"), noParam); | man.AddComponent(hnd1, man.LookupCID("TestScript1_Init"), noParam); | ||||
man.AddComponent(hnd2, man.LookupCID("TestScript1_Init"), testParam.GetChild("node")); | man.AddComponent(hnd2, man.LookupCID("TestScript1_Init"), testParam.GetChild("node")); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 100); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 100); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 1+10+100+1000); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 1+10+100+1000); | ||||
} | } | ||||
void test_script_template_readonly() | void test_script_template_readonly() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js")); | ||||
entity_id_t ent1 = 1, ent2 = 2; | entity_id_t ent1 = 1, ent2 = 2; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
CParamNode testParam; | CParamNode testParam; | ||||
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>100</x>"), PSRETURN_OK); | TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>100</x>"), PSRETURN_OK); | ||||
man.AddComponent(hnd1, man.LookupCID("TestScript1_readonly"), testParam); | man.AddComponent(hnd1, man.LookupCID("TestScript1_readonly"), testParam); | ||||
man.AddComponent(hnd2, man.LookupCID("TestScript1_readonly"), testParam); | man.AddComponent(hnd2, man.LookupCID("TestScript1_readonly"), testParam); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 102); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 102); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 102); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 102); | ||||
} | } | ||||
void test_script_hotload() | void test_script_hotload() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-hotload1.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-hotload1.js")); | ||||
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4; | entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3); | CEntityHandle hnd3 = man.AllocateEntityHandle(ent3); | ||||
Show All 19 Lines | void test_script_hotload() | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 1000); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 1000); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 200); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 200); | ||||
} | } | ||||
void test_script_modding() | void test_script_modding() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
CParamNode testParam; | CParamNode testParam; | ||||
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>100</x>"), PSRETURN_OK); | TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>100</x>"), PSRETURN_OK); | ||||
entity_id_t ent1 = 1, ent2 = 2; | entity_id_t ent1 = 1, ent2 = 2; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-modding1.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-modding1.js")); | ||||
man.AddComponent(hnd1, man.LookupCID("Modding"), testParam); | man.AddComponent(hnd1, man.LookupCID("Modding"), testParam); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 100); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 100); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-modding2.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-modding2.js")); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 1000); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 1000); | ||||
man.AddComponent(hnd2, man.LookupCID("Modding"), testParam); | man.AddComponent(hnd2, man.LookupCID("Modding"), testParam); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 1000); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 1000); | ||||
} | } | ||||
void test_serialization() | void test_serialization() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
entity_id_t ent1 = 10, ent2 = 20, ent3 = FIRST_LOCAL_ENTITY; | entity_id_t ent1 = 10, ent2 = 20, ent3 = FIRST_LOCAL_ENTITY; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3); | CEntityHandle hnd3 = man.AllocateEntityHandle(ent3); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | TS_ASSERT_STREAM(stateStream, 73, | ||||
"\xd2\x04\x00\x00" // 1234 | "\xd2\x04\x00\x00" // 1234 | ||||
"\x06\x00\x00\x00Test2A" | "\x06\x00\x00\x00Test2A" | ||||
"\x01\x00\x00\x00" // num ents | "\x01\x00\x00\x00" // num ents | ||||
"\x0a\x00\x00\x00" // ent1 | "\x0a\x00\x00\x00" // ent1 | ||||
"\x08\x52\x00\x00" // 21000 | "\x08\x52\x00\x00" // 21000 | ||||
); | ); | ||||
CSimContext context2; | CSimContext context2; | ||||
CComponentManager man2(context2, g_ScriptRuntime); | CComponentManager man2(context2, g_ScriptContext); | ||||
man2.LoadComponentTypes(); | man2.LoadComponentTypes(); | ||||
TS_ASSERT(man2.QueryInterface(ent1, IID_Test1) == NULL); | TS_ASSERT(man2.QueryInterface(ent1, IID_Test1) == NULL); | ||||
TS_ASSERT(man2.QueryInterface(ent1, IID_Test2) == NULL); | TS_ASSERT(man2.QueryInterface(ent1, IID_Test2) == NULL); | ||||
TS_ASSERT(man2.QueryInterface(ent2, IID_Test1) == NULL); | TS_ASSERT(man2.QueryInterface(ent2, IID_Test1) == NULL); | ||||
TS_ASSERT(man2.QueryInterface(ent3, IID_Test2) == NULL); | TS_ASSERT(man2.QueryInterface(ent3, IID_Test2) == NULL); | ||||
TS_ASSERT(man2.DeserializeState(stateStream)); | TS_ASSERT(man2.DeserializeState(stateStream)); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent1, IID_Test1))->GetX(), 11000); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent1, IID_Test1))->GetX(), 11000); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man2.QueryInterface(ent1, IID_Test2))->GetX(), 21000); | TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man2.QueryInterface(ent1, IID_Test2))->GetX(), 21000); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent2, IID_Test1))->GetX(), 1234); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent2, IID_Test1))->GetX(), 1234); | ||||
TS_ASSERT(man2.QueryInterface(ent3, IID_Test2) == NULL); | TS_ASSERT(man2.QueryInterface(ent3, IID_Test2) == NULL); | ||||
} | } | ||||
void test_script_serialization() | void test_script_serialization() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
ScriptTestSetup(man.m_ScriptInterface); | ScriptTestSetup(man.m_ScriptInterface); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); | ||||
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4; | entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3); | CEntityHandle hnd3 = man.AllocateEntityHandle(ent3); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
}\n\ | }\n\ | ||||
\n" | \n" | ||||
); | ); | ||||
std::stringstream stateStream; | std::stringstream stateStream; | ||||
TS_ASSERT(man.SerializeState(stateStream)); | TS_ASSERT(man.SerializeState(stateStream)); | ||||
CSimContext context2; | CSimContext context2; | ||||
CComponentManager man2(context2, g_ScriptRuntime); | CComponentManager man2(context2, g_ScriptContext); | ||||
man2.LoadComponentTypes(); | man2.LoadComponentTypes(); | ||||
TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js")); | TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js")); | ||||
TS_ASSERT(man2.QueryInterface(ent1, IID_Test1) == NULL); | TS_ASSERT(man2.QueryInterface(ent1, IID_Test1) == NULL); | ||||
TS_ASSERT(man2.DeserializeState(stateStream)); | TS_ASSERT(man2.DeserializeState(stateStream)); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent1, IID_Test1))->GetX(), 1234); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent1, IID_Test1))->GetX(), 1234); | ||||
{ | { | ||||
TestLogger log; // swallow warnings about this.entity being read-only | TestLogger log; // swallow warnings about this.entity being read-only | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent2, IID_Test1))->GetX(), (int)ent2); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent2, IID_Test1))->GetX(), (int)ent2); | ||||
} | } | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent3, IID_Test1))->GetX(), 12); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent3, IID_Test1))->GetX(), 12); | ||||
} | } | ||||
void test_script_serialization_errors() | void test_script_serialization_errors() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); | ||||
entity_id_t ent1 = 1; | entity_id_t ent1 = 1; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
man.AddComponent(hnd1, man.LookupCID("TestScript1_getter"), noParam); | man.AddComponent(hnd1, man.LookupCID("TestScript1_getter"), noParam); | ||||
std::stringstream stateStream; | std::stringstream stateStream; | ||||
TS_ASSERT_THROWS_PSERROR(man.SerializeState(stateStream), PSERROR_Serialize_ScriptError, "Cannot serialize property getters"); | TS_ASSERT_THROWS_PSERROR(man.SerializeState(stateStream), PSERROR_Serialize_ScriptError, "Cannot serialize property getters"); | ||||
// (The script will die if the getter is executed) | // (The script will die if the getter is executed) | ||||
} | } | ||||
void test_script_serialization_template() | void test_script_serialization_template() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); | TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); | ||||
man.InitSystemEntity(); | man.InitSystemEntity(); | ||||
entity_id_t ent2 = 2; | entity_id_t ent2 = 2; | ||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
// The template manager takes care of reloading templates on deserialization, | // The template manager takes care of reloading templates on deserialization, | ||||
// so we need to use it here | // so we need to use it here | ||||
TS_ASSERT(man.AddComponent(man.GetSystemEntity(), CID_TemplateManager, noParam)); | TS_ASSERT(man.AddComponent(man.GetSystemEntity(), CID_TemplateManager, noParam)); | ||||
ICmpTemplateManager* tempMan = static_cast<ICmpTemplateManager*> (man.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager)); | ICmpTemplateManager* tempMan = static_cast<ICmpTemplateManager*> (man.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager)); | ||||
const CParamNode* testParam = tempMan->LoadTemplate(ent2, "template-serialize"); | const CParamNode* testParam = tempMan->LoadTemplate(ent2, "template-serialize"); | ||||
man.AddComponent(hnd2, man.LookupCID("TestScript1_consts"), testParam->GetChild("TestScript1_consts")); | man.AddComponent(hnd2, man.LookupCID("TestScript1_consts"), testParam->GetChild("TestScript1_consts")); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 12347); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 12347); | ||||
std::stringstream stateStream; | std::stringstream stateStream; | ||||
TS_ASSERT(man.SerializeState(stateStream)); | TS_ASSERT(man.SerializeState(stateStream)); | ||||
CSimContext context2; | CSimContext context2; | ||||
CComponentManager man2(context2, g_ScriptRuntime); | CComponentManager man2(context2, g_ScriptContext); | ||||
man2.LoadComponentTypes(); | man2.LoadComponentTypes(); | ||||
TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js")); | TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js")); | ||||
TS_ASSERT(man2.DeserializeState(stateStream)); | TS_ASSERT(man2.DeserializeState(stateStream)); | ||||
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent2, IID_Test1))->GetX(), 12347); | TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent2, IID_Test1))->GetX(), 12347); | ||||
} | } | ||||
void test_dynamic_subscription() | void test_dynamic_subscription() | ||||
{ | { | ||||
CSimContext context; | CSimContext context; | ||||
CComponentManager man(context, g_ScriptRuntime); | CComponentManager man(context, g_ScriptContext); | ||||
man.LoadComponentTypes(); | man.LoadComponentTypes(); | ||||
entity_id_t ent1 = 1; | entity_id_t ent1 = 1; | ||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | ||||
CParamNode noParam; | CParamNode noParam; | ||||
man.AddComponent(hnd1, CID_Test1A, noParam); | man.AddComponent(hnd1, CID_Test1A, noParam); | ||||
Show All 10 Lines |
Wildfire Games · Phabricator