18#ifndef INCLUDED_COMPONENTTEST
19#define INCLUDED_COMPONENTTEST
80 TS_ASSERT(
m_Cmp == NULL);
100 TS_ASSERT(
m_Cmp != NULL);
101 return static_cast<T*
> (
m_Cmp);
135 std::stringstream dbgstr1;
140 std::cout <<
"--------\n" << dbgstr1.str() <<
"--------\n";
145 std::stringstream stdstr1;
160 TS_ASSERT(stdstr1.peek() == EOF);
162 std::stringstream dbgstr2;
167 std::cout <<
"--------\n" << dbgstr2.str() <<
"--------\n";
172 std::stringstream stdstr2;
176 TS_ASSERT_EQUALS(dbgstr1.str(), dbgstr2.str());
181 TS_ASSERT_EQUALS(stdstr1.str(), stdstr2.str());
#define DEFAULT_MOCK_COMPONENT()
Definition: Component.h:47
EComponentTypeId
Definition: Components.h:51
EInterfaceId
Definition: Components.h:40
const PSRETURN PSRETURN_OK
Definition: Errors.h:103
const ssize_t TERRAIN_TILE_SIZE
metres [world space units] per tile in x and z
Definition: Terrain.h:40
Definition: ComponentManager.h:40
void InitSystemEntity()
Set up an empty SYSTEM_ENTITY.
Definition: ComponentManager.cpp:824
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:778
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:680
CEntityHandle LookupEntityHandle(entity_id_t ent, bool allowCreate=false)
Returns a CEntityHandle with id ent.
Definition: ComponentManager.cpp:809
ScriptInterface & GetScriptInterface()
Definition: ComponentManager.h:272
IComponent * QueryInterface(entity_id_t ent, InterfaceId iid) const
Definition: ComponentManager.cpp:943
CEntityHandle GetSystemEntity()
Returns a CEntityHandle with id SYSTEM_ENTITY.
Definition: ComponentManager.h:149
void LoadComponentTypes()
Definition: ComponentManager.cpp:124
IComponent * ConstructComponent(CEntityHandle ent, ComponentTypeId cid)
Allocates a component object of type 'cid', and attaches it to entity 'ent'.
Definition: ComponentManager.cpp:718
Serialize to a human-readable YAML-like format.
Definition: DebugSerializer.h:27
Object wrapping an entity_id_t, with a SEntityComponentCache to support fast QueryInterface() / CmpPt...
Definition: Entity.h:80
Definition: FixedVector3D.h:25
A simple fixed-point number class.
Definition: Fixed.h:120
static constexpr CFixed FromInt(int n)
Definition: Fixed.h:140
Definition: HashSerializer.h:46
const u8 * ComputeHash()
Definition: HashSerializer.cpp:32
size_t GetHashLength()
Definition: HashSerializer.cpp:27
An entity initialisation parameter node.
Definition: ParamNode.h:151
static PSRETURN LoadXMLString(CParamNode &ret, const char *xml, const wchar_t *sourceIdentifier=NULL)
See LoadXML, but parses the XML string xml.
Definition: ParamNode.cpp:58
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:254
Contains pointers to various 'global' objects that are needed by the simulation code,...
Definition: SimContext.h:33
void SetSystemEntity(CEntityHandle ent)
Definition: SimContext.h:48
Definition: StdDeserializer.h:27
Definition: StdSerializer.h:60
Definition: Vector3D.h:31
Class to test a single component.
Definition: ComponentTest.h:49
EComponentTypeId m_Cid
Definition: ComponentTest.h:54
void HandleMessage(IComponent *cmp, const CMessage &msg, bool global)
Definition: ComponentTest.h:123
CComponentManager m_ComponentManager
Definition: ComponentTest.h:51
CParamNode m_Param
Definition: ComponentTest.h:52
IComponent * m_Cmp
Definition: ComponentTest.h:53
CSimContext m_Context
Definition: ComponentTest.h:50
CSimContext & GetSimContext()
Definition: ComponentTest.h:69
bool m_isSystemEntityInit
Definition: ComponentTest.h:55
ComponentTestHelper(ScriptContext &scriptContext)
Definition: ComponentTest.h:58
void AddMock(entity_id_t ent, EInterfaceId iid, IComponent &component)
Definition: ComponentTest.h:104
void Roundtrip(bool verbose=false)
Checks that the object roundtrips through its serialize/deserialize functions correctly.
Definition: ComponentTest.h:133
const ScriptInterface & GetScriptInterface()
Definition: ComponentTest.h:64
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:78
Definition: ICmpTerrain.h:31
Definition: IComponent.h:33
virtual void Serialize(ISerializer &serialize)=0
virtual void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize)=0
virtual void HandleMessage(const CMessage &msg, bool global)
Definition: IComponent.cpp:46
Simple terrain implementation with constant height of 50.
Definition: ComponentTest.h:192
CTerrain * GetCTerrain() override
Definition: ComponentTest.h:236
u16 GetVerticesPerSide() const override
Returns number of vertices per side on the terrain.
Definition: ComponentTest.h:231
void MakeDirty(i32 i0, i32 j0, i32 i1, i32 j1) override
Indicate that terrain tiles within the given region (inclusive lower bound, exclusive upper bound) ha...
Definition: ComponentTest.h:241
u16 GetTilesPerSide() const override
Returns number of tiles per side on the terrain.
Definition: ComponentTest.h:221
CVector3D CalcExactNormal(float x, float z) const override
Definition: ComponentTest.h:206
CFixedVector3D CalcNormal(entity_pos_t x, entity_pos_t z) const override
Definition: ComponentTest.h:201
float GetExactGroundLevel(float x, float z) const override
Definition: ComponentTest.h:216
void ReloadTerrain(bool ReloadWater) override
Call when the underlying CTerrain has been modified behind our backs.
Definition: ComponentTest.h:245
u32 GetMapSize() const override
Returns the map size in metres (world space units).
Definition: ComponentTest.h:226
entity_pos_t GetGroundLevel(entity_pos_t x, entity_pos_t z) const override
Definition: ComponentTest.h:211
bool IsLoaded() const override
Definition: ComponentTest.h:196
Abstraction around a SpiderMonkey JSContext.
Definition: ScriptContext.h:46
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:72
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning.
Definition: code_annotation.h:40
def xml
Definition: tests.py:138
#define T(string_literal)
Definition: secure_crt.cpp:77
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
Definition: Entity.h:43
u32 entity_id_t
Entity ID type.
Definition: Entity.h:29
int32_t i32
Definition: types.h:34
uint16_t u16
Definition: types.h:38
uint32_t u32
Definition: types.h:39