cyphesis/tests/EntityFactorytest.cpp

623 lines
23 KiB
C++
Raw Normal View History

2006-01-19 Al Riddoch <alriddoch@zepler.org> * aiclient/ClientAccount.cpp, aiclient/ClientAccount.h, aiclient/ClientConnection.cpp, aiclient/ClientConnection.h, aiclient/client.cpp, aiclient/client.h, client/BaseClient.cpp, client/BaseClient.h, client/CharacterClient.cpp, client/CharacterClient.h, client/ClientConnection.cpp, client/ClientConnection.h, client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp, client/define_world.cpp, client/define_world.h, common/Add.h, common/Affect.h, common/AtlasFileLoader.cpp, common/AtlasFileLoader.h, common/Attack.h, common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.cpp, common/BaseWorld.h, common/Burn.h, common/Chop.h, common/Connect.h, common/CustomOp.cpp, common/CustomOp.h, common/CustomOp_impl.h, common/Cut.h, common/Database.cpp, common/Database.h, common/Delve.h, common/Dig.h, common/Eat.h, common/FormattedXMLWriter.cpp, common/FormattedXMLWriter.h, common/Generic.h, common/Load.h, common/Monitor.h, common/Mow.h, common/Nourish.h, common/OOGThing.cpp, common/OOGThing.h, common/Property.cpp, common/Property.h, common/Property_impl.h, common/Save.h, common/Setup.h, common/Tick.h, common/Unseen.h, common/Update.h, common/Use.h, common/Wield.h, common/accountbase.cpp, common/accountbase.h, common/const.cpp, common/const.h, common/custom.cpp, common/debug.h, common/globals.cpp, common/globals.h, common/id.cpp, common/id.h, common/inheritance.cpp, common/inheritance.h, common/inheritance_impl.h, common/log.cpp, common/log.h, common/newid.cpp, common/nls.h, common/op_switch.h, common/operations.cpp, common/operations.h, common/random.h, common/refno.h, common/serialno.cpp, common/serialno.h, common/system.cpp, common/system.h, common/terrain_utils.cpp, common/terrain_utils.h, common/type_utils.h, common/types.h, common/utility.cpp, common/utility.h, modules/DateTime.cpp, modules/DateTime.h, modules/Location.cpp, modules/Location.h, modules/WorldTime.cpp, modules/WorldTime.h, physics/BBox.cpp, physics/BBox.h, physics/Collision.cpp, physics/Collision.h, physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.cpp, physics/Vector3D.h, physics/VectorPol.h, rulesets/Area.cpp, rulesets/Area.h, rulesets/AreaProperty.cpp, rulesets/AreaProperty.h, rulesets/ArithmeticScript.cpp, rulesets/ArithmeticScript.h, rulesets/BaseMind.cpp, rulesets/BaseMind.h, rulesets/CalendarProperty.cpp, rulesets/CalendarProperty.h, rulesets/Character.cpp, rulesets/Character.h, rulesets/Combat.cpp, rulesets/Combat.h, rulesets/Container.cpp, rulesets/Container.h, rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp, rulesets/Entity.h, rulesets/EntityProperties.cpp, rulesets/Entity_getLocation.h, rulesets/Fell.cpp, rulesets/Fell.h, rulesets/Food.cpp, rulesets/Food.h, rulesets/Line.cpp, rulesets/Line.h, rulesets/LineProperty.cpp, rulesets/LineProperty.h, rulesets/MemEntity.cpp, rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h, rulesets/MindFactory.cpp, rulesets/MindFactory.h, rulesets/Missile.h, rulesets/Motion.cpp, rulesets/Motion.h, rulesets/Movement.cpp, rulesets/Movement.h, rulesets/Pedestrian.cpp, rulesets/Pedestrian.h, rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.h, rulesets/Py_EntityWrapper.h, rulesets/Py_Location.cpp, rulesets/Py_Location.h, rulesets/Py_Map.cpp, rulesets/Py_Map.h, rulesets/Py_Mind.cpp, rulesets/Py_Mind.h, rulesets/Py_Object.cpp, rulesets/Py_Object.h, rulesets/Py_Operation.cpp, rulesets/Py_Operation.h, rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h, rulesets/Py_Optime.cpp, rulesets/Py_Optime.h, rulesets/Py_Point3D.cpp, rulesets/Py_Point3D.h, rulesets/Py_Property.cpp, rulesets/Py_Property.h, rulesets/Py_Quaternion.cpp, rulesets/Py_Quaternion.h, rulesets/Py_RootEntity.cpp, rulesets/Py_RootEntity.h, rulesets/Py_Statistics.cpp, rulesets/Py_Statistics.h, rulesets/Py_Task.cpp, rulesets/Py_Task.h, rulesets/Py_Thing.cpp, rulesets/Py_Thing.h, rulesets/Py_Vector3D.cpp, rulesets/Py_Vector3D.h, rulesets/Py_World.cpp, rulesets/Py_World.h, rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h, rulesets/PythonArithmeticScript.cpp, rulesets/PythonArithmeticScript.h, rulesets/PythonMindScript.cpp, rulesets/PythonMindScript.h, rulesets/PythonScript.cpp, rulesets/PythonScript.h, rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h, rulesets/PythonWrapper.cpp, rulesets/PythonWrapper.h, rulesets/Python_API.cpp, rulesets/Python_API.h, rulesets/Python_Script_Utils.h, rulesets/Script.cpp, rulesets/Script.h, rulesets/Stackable.cpp, rulesets/Stackable.h, rulesets/Statistics.cpp, rulesets/Statistics.h, rulesets/StatisticsProperty.cpp, rulesets/StatisticsProperty.h, rulesets/Structure.cpp, rulesets/Structure.h, rulesets/Task.cpp, rulesets/Task.h, rulesets/TaskScript.cpp, rulesets/TaskScript.h, rulesets/TerrainProperty.cpp, rulesets/TerrainProperty.h, rulesets/Thing.cpp, rulesets/Thing.h, rulesets/ThingFactory.cpp, rulesets/ThingFactory.h, rulesets/World.cpp, rulesets/World.h, rulesets/attributes.h, server/Account.cpp, server/Account.h, server/Admin.cpp, server/Admin.h, server/ArithmeticFactory.cpp, server/ArithmeticFactory.h, server/CommClient.cpp, server/CommClient.h, server/CommIdleSocket.cpp, server/CommIdleSocket.h, server/CommListener.cpp, server/CommListener.h, server/CommLocalClient.cpp, server/CommLocalClient.h, server/CommMDNSPublisher.cpp, server/CommMDNSPublisher.h, server/CommMaster.cpp, server/CommMaster.h, server/CommMetaClient.cpp, server/CommMetaClient.h, server/CommPSQLSocket.cpp, server/CommPSQLSocket.h, server/CommPeer.cpp, server/CommPeer.h, server/CommPeerListener.cpp, server/CommPeerListener.h, server/CommRemoteClient.cpp, server/CommRemoteClient.h, server/CommServer.cpp, server/CommServer.h, server/CommSlaveClient.cpp, server/CommSlaveClient.h, server/CommSlaveListener.cpp, server/CommSlaveListener.h, server/CommSocket.cpp, server/CommSocket.h, server/CommUnixListener.cpp, server/CommUnixListener.h, server/Connection.cpp, server/Connection.h, server/Connection_methods.h, server/EntityFactory.cpp, server/EntityFactory.h, server/ExternalMind.cpp, server/ExternalMind.h, server/Idle.cpp, server/Idle.h, server/Lobby.cpp, server/Lobby.h, server/Master.cpp, server/Master.h, server/Peer.cpp, server/Peer.h, server/Persistance.cpp, server/Persistance.h, server/PersistantThingFactory.cpp, server/PersistantThingFactory.h, server/PersistantThingFactory_impl.h, server/Persistor.cpp, server/Persistor.h, server/Persistor_impl.h, server/Player.cpp, server/Player.h, server/Restoration.cpp, server/Restoration.h, server/Restorer.cpp, server/Restorer.h, server/Restorer_impl.h, server/ScriptFactory.cpp, server/ScriptFactory.h, server/ServerRouting.cpp, server/ServerRouting.h, server/ServerRouting_methods.h, server/SlaveClientConnection.cpp, server/SlaveClientConnection.h, server/TaskFactory.cpp, server/TaskFactory.h, server/TrustedConnection.cpp, server/TrustedConnection.h, server/WorldRouter.cpp, server/WorldRouter.h, server/server.cpp, server/server.h, server/slave.cpp, tests/Areatest.cpp, tests/BaseEntitytest.cpp, tests/Charactertest.cpp, tests/Containertest.cpp, tests/Creatortest.cpp, tests/EntityExerciser.h, tests/EntityFactorytest.cpp, tests/Entitytest.cpp, tests/Foodtest.cpp, tests/IGEntityExerciser.h, tests/Linetest.cpp, tests/Locationtest.cpp, tests/OOGThingtest.cpp, tests/Planttest.cpp, tests/Propertytest.cpp, tests/Stackabletest.cpp, tests/Structuretest.cpp, tests/Tasktest.cpp, tests/TestWorld.h, tests/Thingtest.cpp, tests/WorldTimetest.cpp, tests/Worldtest.cpp, tests/allOperations.h, tests/collisiontest.cpp, tests/consttest.cpp, tests/distancetest.cpp, tests/emergencetest.cpp, tests/inheritancetest.cpp, tests/logtest.cpp, tests/randomtest.cpp, tests/systemtest.cpp, tests/transformtest.cpp, tests/type_utilstest.cpp, tests/utilitytest.cpp, tools/AdminClient.cpp, tools/AdminClient.h, tools/cyaddrules.cpp, tools/cycmd.cpp, tools/cyconfig.cpp, tools/cyconvertrules.cpp, tools/cyctrl.cpp, tools/cydbload.cpp, tools/cydumprules.cpp, tools/cyisoload.cpp, tools/cyloadrules.cpp, tools/cypasswd.cpp, tools/cywatchdog.cpp: Replace the copyright and license statements with new versions that include disclaimer of warranty, and permit distribution under later versions of the GPL.
2006-01-19 02:17:06 +00:00
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2005 Alistair Riddoch
2006-01-19 Al Riddoch <alriddoch@zepler.org> * aiclient/ClientAccount.cpp, aiclient/ClientAccount.h, aiclient/ClientConnection.cpp, aiclient/ClientConnection.h, aiclient/client.cpp, aiclient/client.h, client/BaseClient.cpp, client/BaseClient.h, client/CharacterClient.cpp, client/CharacterClient.h, client/ClientConnection.cpp, client/ClientConnection.h, client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp, client/define_world.cpp, client/define_world.h, common/Add.h, common/Affect.h, common/AtlasFileLoader.cpp, common/AtlasFileLoader.h, common/Attack.h, common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.cpp, common/BaseWorld.h, common/Burn.h, common/Chop.h, common/Connect.h, common/CustomOp.cpp, common/CustomOp.h, common/CustomOp_impl.h, common/Cut.h, common/Database.cpp, common/Database.h, common/Delve.h, common/Dig.h, common/Eat.h, common/FormattedXMLWriter.cpp, common/FormattedXMLWriter.h, common/Generic.h, common/Load.h, common/Monitor.h, common/Mow.h, common/Nourish.h, common/OOGThing.cpp, common/OOGThing.h, common/Property.cpp, common/Property.h, common/Property_impl.h, common/Save.h, common/Setup.h, common/Tick.h, common/Unseen.h, common/Update.h, common/Use.h, common/Wield.h, common/accountbase.cpp, common/accountbase.h, common/const.cpp, common/const.h, common/custom.cpp, common/debug.h, common/globals.cpp, common/globals.h, common/id.cpp, common/id.h, common/inheritance.cpp, common/inheritance.h, common/inheritance_impl.h, common/log.cpp, common/log.h, common/newid.cpp, common/nls.h, common/op_switch.h, common/operations.cpp, common/operations.h, common/random.h, common/refno.h, common/serialno.cpp, common/serialno.h, common/system.cpp, common/system.h, common/terrain_utils.cpp, common/terrain_utils.h, common/type_utils.h, common/types.h, common/utility.cpp, common/utility.h, modules/DateTime.cpp, modules/DateTime.h, modules/Location.cpp, modules/Location.h, modules/WorldTime.cpp, modules/WorldTime.h, physics/BBox.cpp, physics/BBox.h, physics/Collision.cpp, physics/Collision.h, physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.cpp, physics/Vector3D.h, physics/VectorPol.h, rulesets/Area.cpp, rulesets/Area.h, rulesets/AreaProperty.cpp, rulesets/AreaProperty.h, rulesets/ArithmeticScript.cpp, rulesets/ArithmeticScript.h, rulesets/BaseMind.cpp, rulesets/BaseMind.h, rulesets/CalendarProperty.cpp, rulesets/CalendarProperty.h, rulesets/Character.cpp, rulesets/Character.h, rulesets/Combat.cpp, rulesets/Combat.h, rulesets/Container.cpp, rulesets/Container.h, rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp, rulesets/Entity.h, rulesets/EntityProperties.cpp, rulesets/Entity_getLocation.h, rulesets/Fell.cpp, rulesets/Fell.h, rulesets/Food.cpp, rulesets/Food.h, rulesets/Line.cpp, rulesets/Line.h, rulesets/LineProperty.cpp, rulesets/LineProperty.h, rulesets/MemEntity.cpp, rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h, rulesets/MindFactory.cpp, rulesets/MindFactory.h, rulesets/Missile.h, rulesets/Motion.cpp, rulesets/Motion.h, rulesets/Movement.cpp, rulesets/Movement.h, rulesets/Pedestrian.cpp, rulesets/Pedestrian.h, rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.h, rulesets/Py_EntityWrapper.h, rulesets/Py_Location.cpp, rulesets/Py_Location.h, rulesets/Py_Map.cpp, rulesets/Py_Map.h, rulesets/Py_Mind.cpp, rulesets/Py_Mind.h, rulesets/Py_Object.cpp, rulesets/Py_Object.h, rulesets/Py_Operation.cpp, rulesets/Py_Operation.h, rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h, rulesets/Py_Optime.cpp, rulesets/Py_Optime.h, rulesets/Py_Point3D.cpp, rulesets/Py_Point3D.h, rulesets/Py_Property.cpp, rulesets/Py_Property.h, rulesets/Py_Quaternion.cpp, rulesets/Py_Quaternion.h, rulesets/Py_RootEntity.cpp, rulesets/Py_RootEntity.h, rulesets/Py_Statistics.cpp, rulesets/Py_Statistics.h, rulesets/Py_Task.cpp, rulesets/Py_Task.h, rulesets/Py_Thing.cpp, rulesets/Py_Thing.h, rulesets/Py_Vector3D.cpp, rulesets/Py_Vector3D.h, rulesets/Py_World.cpp, rulesets/Py_World.h, rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h, rulesets/PythonArithmeticScript.cpp, rulesets/PythonArithmeticScript.h, rulesets/PythonMindScript.cpp, rulesets/PythonMindScript.h, rulesets/PythonScript.cpp, rulesets/PythonScript.h, rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h, rulesets/PythonWrapper.cpp, rulesets/PythonWrapper.h, rulesets/Python_API.cpp, rulesets/Python_API.h, rulesets/Python_Script_Utils.h, rulesets/Script.cpp, rulesets/Script.h, rulesets/Stackable.cpp, rulesets/Stackable.h, rulesets/Statistics.cpp, rulesets/Statistics.h, rulesets/StatisticsProperty.cpp, rulesets/StatisticsProperty.h, rulesets/Structure.cpp, rulesets/Structure.h, rulesets/Task.cpp, rulesets/Task.h, rulesets/TaskScript.cpp, rulesets/TaskScript.h, rulesets/TerrainProperty.cpp, rulesets/TerrainProperty.h, rulesets/Thing.cpp, rulesets/Thing.h, rulesets/ThingFactory.cpp, rulesets/ThingFactory.h, rulesets/World.cpp, rulesets/World.h, rulesets/attributes.h, server/Account.cpp, server/Account.h, server/Admin.cpp, server/Admin.h, server/ArithmeticFactory.cpp, server/ArithmeticFactory.h, server/CommClient.cpp, server/CommClient.h, server/CommIdleSocket.cpp, server/CommIdleSocket.h, server/CommListener.cpp, server/CommListener.h, server/CommLocalClient.cpp, server/CommLocalClient.h, server/CommMDNSPublisher.cpp, server/CommMDNSPublisher.h, server/CommMaster.cpp, server/CommMaster.h, server/CommMetaClient.cpp, server/CommMetaClient.h, server/CommPSQLSocket.cpp, server/CommPSQLSocket.h, server/CommPeer.cpp, server/CommPeer.h, server/CommPeerListener.cpp, server/CommPeerListener.h, server/CommRemoteClient.cpp, server/CommRemoteClient.h, server/CommServer.cpp, server/CommServer.h, server/CommSlaveClient.cpp, server/CommSlaveClient.h, server/CommSlaveListener.cpp, server/CommSlaveListener.h, server/CommSocket.cpp, server/CommSocket.h, server/CommUnixListener.cpp, server/CommUnixListener.h, server/Connection.cpp, server/Connection.h, server/Connection_methods.h, server/EntityFactory.cpp, server/EntityFactory.h, server/ExternalMind.cpp, server/ExternalMind.h, server/Idle.cpp, server/Idle.h, server/Lobby.cpp, server/Lobby.h, server/Master.cpp, server/Master.h, server/Peer.cpp, server/Peer.h, server/Persistance.cpp, server/Persistance.h, server/PersistantThingFactory.cpp, server/PersistantThingFactory.h, server/PersistantThingFactory_impl.h, server/Persistor.cpp, server/Persistor.h, server/Persistor_impl.h, server/Player.cpp, server/Player.h, server/Restoration.cpp, server/Restoration.h, server/Restorer.cpp, server/Restorer.h, server/Restorer_impl.h, server/ScriptFactory.cpp, server/ScriptFactory.h, server/ServerRouting.cpp, server/ServerRouting.h, server/ServerRouting_methods.h, server/SlaveClientConnection.cpp, server/SlaveClientConnection.h, server/TaskFactory.cpp, server/TaskFactory.h, server/TrustedConnection.cpp, server/TrustedConnection.h, server/WorldRouter.cpp, server/WorldRouter.h, server/server.cpp, server/server.h, server/slave.cpp, tests/Areatest.cpp, tests/BaseEntitytest.cpp, tests/Charactertest.cpp, tests/Containertest.cpp, tests/Creatortest.cpp, tests/EntityExerciser.h, tests/EntityFactorytest.cpp, tests/Entitytest.cpp, tests/Foodtest.cpp, tests/IGEntityExerciser.h, tests/Linetest.cpp, tests/Locationtest.cpp, tests/OOGThingtest.cpp, tests/Planttest.cpp, tests/Propertytest.cpp, tests/Stackabletest.cpp, tests/Structuretest.cpp, tests/Tasktest.cpp, tests/TestWorld.h, tests/Thingtest.cpp, tests/WorldTimetest.cpp, tests/Worldtest.cpp, tests/allOperations.h, tests/collisiontest.cpp, tests/consttest.cpp, tests/distancetest.cpp, tests/emergencetest.cpp, tests/inheritancetest.cpp, tests/logtest.cpp, tests/randomtest.cpp, tests/systemtest.cpp, tests/transformtest.cpp, tests/type_utilstest.cpp, tests/utilitytest.cpp, tools/AdminClient.cpp, tools/AdminClient.h, tools/cyaddrules.cpp, tools/cycmd.cpp, tools/cyconfig.cpp, tools/cyconvertrules.cpp, tools/cyctrl.cpp, tools/cydbload.cpp, tools/cydumprules.cpp, tools/cyisoload.cpp, tools/cyloadrules.cpp, tools/cypasswd.cpp, tools/cywatchdog.cpp: Replace the copyright and license statements with new versions that include disclaimer of warranty, and permit distribution under later versions of the GPL.
2006-01-19 02:17:06 +00:00
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "TestWorld.h"
#include "rulesets/World.h"
#include "rulesets/Python_API.h"
#include "server/EntityFactory.h"
#include "server/PersistantThingFactory.h"
#include <Atlas/Objects/Anonymous.h>
#include <cassert>
using Atlas::Message::MapType;
using Atlas::Objects::Entity::Anonymous;
class ExposedEntityFactory : public EntityFactory {
public:
explicit ExposedEntityFactory(BaseWorld & w) : EntityFactory(w) { }
void getRulesFromFiles(MapType & rules) {
EntityFactory::getRulesFromFiles(rules);
}
void installRules() {
EntityFactory::installRules();
}
void installFactory(const std::string & parent,
const std::string & clss, FactoryBase * factory) {
EntityFactory::installFactory(parent, clss, factory);
}
void populateFactory(const std::string & className,
FactoryBase * factory,
const MapType & classDesc) {
EntityFactory::populateFactory(className, factory, classDesc);
}
FactoryBase * getNewFactory(const std::string & clss) {
return EntityFactory::getNewFactory(clss);
}
int installEntityClass(const std::string & className,
const std::string & parent,
const MapType & classDesc) {
return EntityFactory::installEntityClass(className, parent, classDesc);
}
int installOpDefinition(const std::string & opDefName,
const std::string & parent,
const MapType & opDefDesc) {
return EntityFactory::installOpDefinition(opDefName, parent, opDefDesc);
}
const FactoryDict & factoryDict() const { return m_factories; }
};
int main(int argc, char ** argv)
{
loadConfig(argc, argv);
init_python_api();
int ret;
{
World e("1", 1);
TestWorld test_world(e);
Anonymous attributes;
EntityFactory::init(test_world);
assert(EntityFactory::instance() != 0);
assert(EntityFactory::instance()->newEntity("1", 1, "world", attributes) == 0);
assert(EntityFactory::instance()->newEntity("1", 1, "nonexistant", attributes) == 0);
assert(EntityFactory::instance()->newEntity("1", 1, "thing", attributes) != 0);
EntityFactory::del();
assert(EntityFactory::instance() == 0);
}
{
World e("1", 1);
TestWorld test_world(e);
Anonymous attributes;
Atlas::Message::Element val;
EntityFactory::init(test_world);
assert(EntityFactory::instance() != 0);
Entity * test_ent = EntityFactory::instance()->newEntity("1", 1, "thing", attributes);
assert(test_ent != 0);
assert(!test_ent->getAttr("funky", val));
assert(val.isNone());
attributes->setAttr("funky", "true");
test_ent = EntityFactory::instance()->newEntity("1", 1, "thing", attributes);
assert(test_ent != 0);
assert(test_ent->getAttr("funky", val));
assert(val.isString());
assert(val.String() == "true");
EntityFactory::del();
assert(EntityFactory::instance() == 0);
}
{
// Create a test world.
World e("1", 1);
TestWorld test_world(e);
Atlas::Message::Element val;
// Instance of EntityFactory with all protected methods exposed
// for testing
ExposedEntityFactory entity_factory(test_world);
// Attributes for test entities being created
Anonymous attributes;
// Create an entity which is an instance of one of the core classes
Entity * test_ent = entity_factory.newEntity("1", 1, "thing", attributes);
assert(test_ent != 0);
// Check the created entity does not have the attribute values we
// will be testing later
assert(!test_ent->getAttr("funky", val));
assert(val.isNone());
// Set a test attribute
attributes->setAttr("funky", "true");
// Create another entity, and check that it has picked up the new
// attribute value
test_ent = entity_factory.newEntity("1", 1, "thing", attributes);
assert(test_ent != 0);
assert(test_ent->getAttr("funky", val));
assert(val.isString());
assert(val.String() == "true");
// Check that creating an entity of a type we know we have not yet
// installed results in a null pointer.
assert(entity_factory.newEntity("1", 1, "custom_type", attributes) == 0);
// Get a reference to the internal dictionary of entity factories.
const FactoryDict & factory_dict = entity_factory.factoryDict();
// Make sure it has some factories in it already.
assert(!factory_dict.empty());
// Assert the dictionary does not contain the factory we know we have
// have not yet installed.
assert(factory_dict.find("custom_type") == factory_dict.end());
// Set up a type description for a new type, and install it.
{
MapType custom_type_description;
MapType attrs;
MapType test_custom_type_attr;
test_custom_type_attr["default"] = "test_value";
test_custom_type_attr["visibility"] = "public";
attrs["test_custom_type_attr"] = test_custom_type_attr;
custom_type_description["attributes"] = attrs;
ret = entity_factory.installEntityClass("custom_type", "thing", custom_type_description);
assert(ret == 0);
}
// Check that the factory dictionary now contains a factory for
// the custom type we just installed.
FactoryDict::const_iterator I = factory_dict.find("custom_type");
assert(I != factory_dict.end());
FactoryBase * custom_type_factory = I->second;
// Check the factory has the attributes we described on the custom
// type.
MapType::const_iterator J = custom_type_factory->m_attributes.find("test_custom_type_attr");
assert(J != custom_type_factory->m_attributes.end());
assert(J->second.isString());
assert(J->second.String() == "test_value");
// Create an instance of our custom type, ensuring that it works.
test_ent = entity_factory.newEntity("1", 1, "custom_type", attributes);
assert(test_ent != 0);
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute we passed in when creating
// the instance.
assert(test_ent->getAttr("funky", val));
assert(val.isString());
assert(val.String() == "true");
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute described when the
// custom type was installed.
assert(test_ent->getAttr("test_custom_type_attr", val));
assert(val.isString());
assert(val.String() == "test_value");
// Check that creating an entity of a type we know we have not yet
// installed results in a null pointer.
assert(entity_factory.newEntity("1", 1, "custom_inherited_type", attributes) == 0);
// Assert the dictionary does not contain the factory we know we have
// have not yet installed.
assert(factory_dict.find("custom_inherited_type") == factory_dict.end());
// Set up a type description for a second new type which inherits
// from the first, and install it.
{
MapType custom_inherited_type_description;
MapType attrs;
MapType test_custom_type_attr;
test_custom_type_attr["default"] = "test_inherited_value";
test_custom_type_attr["visibility"] = "public";
attrs["test_custom_inherited_type_attr"] = test_custom_type_attr;
custom_inherited_type_description["attributes"] = attrs;
ret = entity_factory.installEntityClass("custom_inherited_type", "custom_type", custom_inherited_type_description);
assert(ret == 0);
}
// Check that the factory dictionary does contain the factory for
// the second newly installed type
I = factory_dict.find("custom_inherited_type");
assert(I != factory_dict.end());
FactoryBase * custom_inherited_type_factory = I->second;
assert(custom_inherited_type_factory != 0);
// Check that the factory has inherited the attributes from the
// first custom type
J = custom_inherited_type_factory->m_attributes.find("test_custom_type_attr");
assert(J != custom_inherited_type_factory->m_attributes.end());
assert(J->second.isString());
assert(J->second.String() == "test_value");
// Check that the factory has the attributes specified when installing
// it
J = custom_inherited_type_factory->m_attributes.find("test_custom_inherited_type_attr");
assert(J != custom_inherited_type_factory->m_attributes.end());
assert(J->second.isString());
assert(J->second.String() == "test_inherited_value");
// Creat an instance of the second custom type, ensuring it works.
test_ent = entity_factory.newEntity("1", 1, "custom_inherited_type", attributes);
assert(test_ent != 0);
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute we passed in when creating
// the instance.
assert(test_ent->getAttr("funky", val));
assert(val.isString());
assert(val.String() == "true");
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the instance of the second custom type has the attribute
// described when the first custom type was installed.
assert(test_ent->getAttr("test_custom_type_attr", val));
assert(val.isString());
assert(val.String() == "test_value");
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute described when the
// second custom type was installed
assert(test_ent->getAttr("test_custom_inherited_type_attr", val));
assert(val.isString());
assert(val.String() == "test_inherited_value");
// FIXME TODO Modify a type, and ensure attribute propagate to inherited types.
// Make sure than attempting to modify a non-existant type fails
{
Anonymous nonexistant_description;
MapType attrs;
MapType test_custom_type_attr;
test_custom_type_attr["default"] = "no_value";
test_custom_type_attr["visibility"] = "public";
attrs["no_custom_type_attr"] = test_custom_type_attr;
nonexistant_description->setAttr("attributes", attrs);
ret = entity_factory.modifyRule("nonexistant", nonexistant_description);
assert(ret != 0);
}
// Modify the second custom type removing its custom attribute
{
Anonymous new_custom_inherited_type_description;
new_custom_inherited_type_description->setAttr("attributes", MapType());
ret = entity_factory.modifyRule("custom_inherited_type", new_custom_inherited_type_description);
assert(ret == 0);
}
// Check that the factory dictionary does contain the factory for
// the second newly installed type
I = factory_dict.find("custom_inherited_type");
assert(I != factory_dict.end());
custom_inherited_type_factory = I->second;
assert(custom_inherited_type_factory != 0);
// Check that the factory has inherited the attributes from the
// first custom type
J = custom_inherited_type_factory->m_attributes.find("test_custom_type_attr");
assert(J != custom_inherited_type_factory->m_attributes.end());
assert(J->second.isString());
assert(J->second.String() == "test_value");
// Check that the factory no longer has the attributes we removed
J = custom_inherited_type_factory->m_attributes.find("test_custom_inherited_type_attr");
assert(J == custom_inherited_type_factory->m_attributes.end());
// Creat an instance of the second custom type, ensuring it works.
test_ent = entity_factory.newEntity("1", 1, "custom_inherited_type", attributes);
assert(test_ent != 0);
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Make sure test nonexistant attribute isn't present
assert(!test_ent->getAttr("nonexistant", val));
// Make sure nonexistant attribute isn't present
assert(!test_ent->getAttr("nonexistant_attribute", val));
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute we passed in when creating
// the instance.
assert(test_ent->getAttr("funky", val));
assert(val.isString());
assert(val.String() == "true");
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the instance of the second custom type has the attribute
// described when the first custom type was installed.
assert(test_ent->getAttr("test_custom_type_attr", val));
assert(val.isString());
assert(val.String() == "test_value");
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute described when the
// second custom type was installed
assert(!test_ent->getAttr("test_custom_inherited_type_attr", val));
// Modify the first custom type removing its custom attribute
{
Anonymous new_custom_type_description;
new_custom_type_description->setAttr("attributes", MapType());
ret = entity_factory.modifyRule("custom_type", new_custom_type_description);
assert(ret == 0);
}
// Check that the factory dictionary now contains a factory for
// the custom type we just installed.
I = factory_dict.find("custom_type");
assert(I != factory_dict.end());
custom_type_factory = I->second;
// Check the factory has the attributes we described on the custom
// type.
J = custom_type_factory->m_attributes.find("test_custom_type_attr");
assert(J == custom_type_factory->m_attributes.end());
// Create an instance of our custom type, ensuring that it works.
test_ent = entity_factory.newEntity("1", 1, "custom_type", attributes);
assert(test_ent != 0);
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute we passed in when creating
// the instance.
assert(test_ent->getAttr("funky", val));
assert(val.isString());
assert(val.String() == "true");
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type no longer has the custom attribute
assert(!test_ent->getAttr("test_custom_type_attr", val));
// Check that the factory dictionary does contain the factory for
// the second newly installed type
I = factory_dict.find("custom_inherited_type");
assert(I != factory_dict.end());
custom_inherited_type_factory = I->second;
assert(custom_inherited_type_factory != 0);
// Check that the factory no longer has inherited the attributes
// from the first custom type which we removed
J = custom_inherited_type_factory->m_attributes.find("test_custom_type_attr");
assert(J == custom_inherited_type_factory->m_attributes.end());
// Check that the factory no longer has the attributes we removed
J = custom_inherited_type_factory->m_attributes.find("test_custom_inherited_type_attr");
assert(J == custom_inherited_type_factory->m_attributes.end());
// Creat an instance of the second custom type, ensuring it works.
test_ent = entity_factory.newEntity("1", 1, "custom_inherited_type", attributes);
assert(test_ent != 0);
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Make sure test nonexistant attribute isn't present
assert(!test_ent->getAttr("nonexistant", val));
// Make sure nonexistant attribute isn't present
assert(!test_ent->getAttr("nonexistant_attribute", val));
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute we passed in when creating
// the instance.
assert(test_ent->getAttr("funky", val));
assert(val.isString());
assert(val.String() == "true");
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the instance of the second custom type has the attribute
// described when the first custom type was installed.
assert(!test_ent->getAttr("test_custom_type_attr", val));
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute described when the
// second custom type was installed
assert(!test_ent->getAttr("test_custom_inherited_type_attr", val));
// Add more custom attributes to the first type
{
Anonymous new_custom_type_description;
MapType attrs;
MapType test_custom_type_attr;
test_custom_type_attr["default"] = "test_value";
test_custom_type_attr["visibility"] = "public";
attrs["test_custom_type_attr"] = test_custom_type_attr;
MapType new_custom_type_attr;
new_custom_type_attr["default"] = "new_value";
new_custom_type_attr["visibility"] = "public";
attrs["new_custom_type_attr"] = new_custom_type_attr;
new_custom_type_description->setAttr("attributes", attrs);
ret = entity_factory.modifyRule("custom_type", new_custom_type_description);
assert(ret == 0);
}
// Check that the factory dictionary now contains a factory for
// the custom type we just installed.
I = factory_dict.find("custom_type");
assert(I != factory_dict.end());
custom_type_factory = I->second;
// Check the factory has the attributes we described on the custom
// type.
J = custom_type_factory->m_attributes.find("test_custom_type_attr");
assert(J != custom_type_factory->m_attributes.end());
assert(J->second.isString());
assert(J->second.String() == "test_value");
J = custom_type_factory->m_attributes.find("new_custom_type_attr");
assert(J != custom_type_factory->m_attributes.end());
assert(J->second.isString());
assert(J->second.String() == "new_value");
// Create an instance of our custom type, ensuring that it works.
test_ent = entity_factory.newEntity("1", 1, "custom_type", attributes);
assert(test_ent != 0);
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute we passed in when creating
// the instance.
assert(test_ent->getAttr("funky", val));
assert(val.isString());
assert(val.String() == "true");
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type now has the custom attributes
assert(test_ent->getAttr("test_custom_type_attr", val));
assert(val.isString());
assert(val.String() == "test_value");
assert(test_ent->getAttr("new_custom_type_attr", val));
assert(val.isString());
assert(val.String() == "new_value");
// Check that the factory dictionary does contain the factory for
// the second newly installed type
I = factory_dict.find("custom_inherited_type");
assert(I != factory_dict.end());
custom_inherited_type_factory = I->second;
assert(custom_inherited_type_factory != 0);
// Check that the factory now has inherited the attributes
// from the first custom type
J = custom_inherited_type_factory->m_attributes.find("test_custom_type_attr");
assert(J != custom_inherited_type_factory->m_attributes.end());
assert(J->second.isString());
assert(J->second.String() == "test_value");
J = custom_inherited_type_factory->m_attributes.find("new_custom_type_attr");
assert(J != custom_inherited_type_factory->m_attributes.end());
assert(J->second.isString());
assert(J->second.String() == "new_value");
// Check that the factory no longer has the attributes we removed
J = custom_inherited_type_factory->m_attributes.find("test_custom_inherited_type_attr");
assert(J == custom_inherited_type_factory->m_attributes.end());
// Creat an instance of the second custom type, ensuring it works.
test_ent = entity_factory.newEntity("1", 1, "custom_inherited_type", attributes);
assert(test_ent != 0);
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Make sure test nonexistant attribute isn't present
assert(!test_ent->getAttr("nonexistant", val));
// Make sure nonexistant attribute isn't present
assert(!test_ent->getAttr("nonexistant_attribute", val));
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type has the attribute we passed in when creating
// the instance.
assert(test_ent->getAttr("funky", val));
assert(val.isString());
assert(val.String() == "true");
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the instance of the second custom type has the attribute
// described when the first custom type was installed.
assert(test_ent->getAttr("test_custom_type_attr", val));
assert(val.isString());
assert(val.String() == "test_value");
assert(test_ent->getAttr("new_custom_type_attr", val));
assert(val.isString());
assert(val.String() == "new_value");
// Reset val.
val = Atlas::Message::Element();
assert(val.isNone());
// Check the custom type no longer has the attribute described when the
// second custom type was installed
assert(!test_ent->getAttr("test_custom_inherited_type_attr", val));
}
}