56 m_Context(), m_ComponentManager(m_Context, runtime), m_Cmp(NULL)
77 TS_ASSERT(m_Cmp == NULL);
92 m_Cmp = m_ComponentManager.
QueryInterface(ent, T::GetInterfaceId());
93 TS_ASSERT(m_Cmp != NULL);
94 return static_cast<T*
> (
m_Cmp);
124 std::stringstream dbgstr1;
129 std::cout <<
"--------\n" << dbgstr1.str() <<
"--------\n";
134 std::stringstream stdstr1;
149 TS_ASSERT(stdstr1.peek() == EOF);
151 std::stringstream dbgstr2;
153 cmp2->Serialize(dbg2);
156 std::cout <<
"--------\n" << dbgstr2.str() <<
"--------\n";
159 cmp2->Serialize(hash2);
161 std::stringstream stdstr2;
163 cmp2->Serialize(std2);
165 TS_ASSERT_EQUALS(dbgstr1.str(), dbgstr2.str());
167 TS_ASSERT_EQUALS(hash1.
GetHashLength(), hash2.GetHashLength());
170 TS_ASSERT_EQUALS(stdstr1.str(), stdstr2.str());
185 virtual
bool IsLoaded()
const
An entity initialisation parameter node.
Definition: ParamNode.h:148
Definition: IComponent.h:33
A simple fixed-point number class.
Definition: Fixed.h:115
virtual CTerrain * GetCTerrain()
Definition: ComponentTest.h:220
EComponentTypeId
Definition: Components.h:50
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Definition: code_annotation.h:38
CParamNode m_Param
Definition: ComponentTest.h:50
void AddMockComponent(CEntityHandle ent, InterfaceId iid, IComponent &component)
Adds an externally-created component, so that it is returned by QueryInterface but does not get destr...
Definition: ComponentManager.cpp:800
void Roundtrip(bool verbose=false)
Checks that the object roundtrips through its serialize/deserialize functions correctly.
Definition: ComponentTest.h:122
xml
Definition: tests.py:119
const PSRETURN PSRETURN_OK
Definition: Errors.h:103
uint16_t u16
Definition: types.h:38
virtual void Serialize(ISerializer &serialize)=0
IComponent * QueryInterface(entity_id_t ent, InterfaceId iid) const
Definition: ComponentManager.cpp:953
Object wrapping an entity_id_t, with a SEntityComponentCache to support fast QueryInterface() / CmpPt...
Definition: Entity.h:79
virtual void ReloadTerrain(bool ReloadWater)
Call when the underlying CTerrain has been modified behind our backs.
Definition: ComponentTest.h:229
CComponentManager m_ComponentManager
Definition: ComponentTest.h:49
ScriptInterface & GetScriptInterface()
Definition: ComponentManager.h:315
ComponentTestHelper(shared_ptr< ScriptRuntime > runtime)
Definition: ComponentTest.h:55
Definition: Vector3D.h:28
T * Add(EComponentTypeId cid, const std::string &xml, entity_id_t ent=10)
Call this once to initialise the test helper with a component.
Definition: ComponentTest.h:75
Serialize to a human-readable YAML-like format.
Definition: DebugSerializer.h:26
virtual CFixedVector3D CalcNormal(entity_pos_t x, entity_pos_t z) const
Definition: ComponentTest.h:190
Contains pointers to various 'global' objects that are needed by the simulation code, to allow easy access without using real (evil) global variables.
Definition: SimContext.h:32
void LoadComponentTypes()
Definition: ComponentManager.cpp:115
Definition: HashSerializer.h:45
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
Definition: Entity.h:43
virtual float GetExactGroundLevel(float x, float z) const
Definition: ComponentTest.h:205
CEntityHandle LookupEntityHandle(entity_id_t ent, bool allowCreate=false)
Returns a CEntityHandle with id ent.
Definition: ComponentManager.cpp:830
void AddMock(entity_id_t ent, EInterfaceId iid, IComponent &component)
Definition: ComponentTest.h:97
virtual u16 GetVerticesPerSide() const
Returns number of vertices per side on the terrain.
Definition: ComponentTest.h:215
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
Definition: ParamNode.cpp:224
Simple terrain implementation with constant height of 50.
Definition: ComponentTest.h:180
#define DEFAULT_MOCK_COMPONENT()
Definition: Component.h:99
Definition: ComponentManager.h:40
static PSRETURN LoadXMLString(CParamNode &ret, const char *xml, const wchar_t *sourceIdentifier=NULL)
See LoadXML, but parses the XML string xml.
Definition: ParamNode.cpp:55
Definition: FixedVector3D.h:24
#define T(string_literal)
Definition: secure_crt.cpp:76
void InitSystemEntity()
Set up an empty SYSTEM_ENTITY.
Definition: ComponentManager.cpp:845
int32_t i32
Definition: types.h:34
CSimContext m_Context
Definition: ComponentTest.h:48
static CFixed FromInt(int n)
Definition: Fixed.h:136
virtual void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize)=0
bool AddComponent(CEntityHandle ent, ComponentTypeId cid, const CParamNode ¶mNode)
Constructs a component of type 'cid', initialised with data 'paramNode', and attaches it to entity 'e...
Definition: ComponentManager.cpp:703
size_t GetHashLength()
Definition: HashSerializer.cpp:27
IComponent * ConstructComponent(CEntityHandle ent, ComponentTypeId cid)
Allocates a component object of type 'cid', and attaches it to entity 'ent'.
Definition: ComponentManager.cpp:740
IComponent * m_Cmp
Definition: ComponentTest.h:51
void SetSystemEntity(CEntityHandle ent)
Definition: SimContext.h:48
virtual u16 GetTilesPerSide() const
Returns number of tiles per side on the terrain.
Definition: ComponentTest.h:210
virtual void HandleMessage(const CMessage &msg, bool global)
Definition: IComponent.cpp:32
EComponentTypeId m_Cid
Definition: ComponentTest.h:52
CEntityHandle GetSystemEntity()
Returns a CEntityHandle with id SYSTEM_ENTITY.
Definition: ComponentManager.h:197
static Handle handle(size_t idx, u64 tag)
Definition: h_mgr.cpp:121
ScriptInterface & GetScriptInterface()
Definition: ComponentTest.h:61
Abstraction around a SpiderMonkey JSContext.
Definition: ScriptInterface.h:71
void HandleMessage(IComponent *cmp, const CMessage &msg, bool global)
Definition: ComponentTest.h:112
virtual void MakeDirty(i32 i0, i32 j0, i32 i1, i32 j1)
Indicate that terrain tiles within the given region (inclusive lower bound, exclusive upper bound) ha...
Definition: ComponentTest.h:225
CSimContext & GetSimContext()
Definition: ComponentTest.h:66
virtual CVector3D CalcExactNormal(float x, float z) const
Definition: ComponentTest.h:195
Class to test a single component.
Definition: ComponentTest.h:46
virtual entity_pos_t GetGroundLevel(entity_pos_t x, entity_pos_t z) const
Definition: ComponentTest.h:200
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
Definition: StdDeserializer.h:27
const u8 * ComputeHash()
Definition: HashSerializer.cpp:32
Definition: StdSerializer.h:59
EInterfaceId
Definition: Components.h:39
Definition: ICmpTerrain.h:30