Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/tests/test_ComponentManager.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 602 Lines • ▼ Show 20 Lines | void test_script_hotload() | ||||
man.AddComponent(hnd3, man.LookupCID("HotloadA"), testParam); | man.AddComponent(hnd3, man.LookupCID("HotloadA"), testParam); | ||||
man.AddComponent(hnd4, man.LookupCID("HotloadB"), testParam); | man.AddComponent(hnd4, man.LookupCID("HotloadB"), testParam); | ||||
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() | |||||
{ | |||||
CSimContext context; | |||||
CComponentManager man(context, g_ScriptRuntime); | |||||
man.LoadComponentTypes(); | |||||
CParamNode testParam; | |||||
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>100</x>"), PSRETURN_OK); | |||||
entity_id_t ent1 = 1, ent2 = 2; | |||||
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); | |||||
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); | |||||
TS_ASSERT(man.LoadScript(L"simulation/components/test-modding1.js")); | |||||
man.AddComponent(hnd1, man.LookupCID("Modding"), testParam); | |||||
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_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 1000); | |||||
man.AddComponent(hnd2, man.LookupCID("Modding"), testParam); | |||||
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_ScriptRuntime); | ||||
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); | ||||
▲ Show 20 Lines • Show All 252 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator