cyphesis/tests/CorePropertyManagerTest.cpp

480 lines
14 KiB
C++
Raw Permalink Normal View History

// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2013 Alistair Riddoch
//
// 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
#ifdef NDEBUG
#undef NDEBUG
#endif
#ifndef DEBUG
#define DEBUG
#endif
#include "TestBase.h"
#include "server/CorePropertyManager.h"
#include "rules/Domain.h"
#include "rules/simulation/Entity.h"
2018-11-03 16:43:33 +01:00
#include "rules/simulation/ExternalMind.h"
#include "common/CommSocket.h"
#include "common/Inheritance.h"
2013-01-08 22:55:00 +00:00
#include "common/PropertyFactory.h"
#include "common/SystemTime.h"
#include "TestWorld.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/simulation/stubPropelProperty.h"
#include <Atlas/Objects/SmartPtr.h>
#include <Atlas/Objects/Anonymous.h>
#include <Atlas/Objects/Operation.h>
#include <cassert>
using Atlas::Message::Element;
using Atlas::Message::ListType;
using Atlas::Message::MapType;
using Atlas::Objects::Root;
using Atlas::Objects::Entity::RootEntity;
2013-01-08 22:55:00 +00:00
class MinimalProperty : public PropertyBase {
public:
MinimalProperty() { }
virtual int get(Atlas::Message::Element & val) const { return 0; }
virtual void set(const Atlas::Message::Element & val) { }
virtual MinimalProperty * copy() const { return 0; }
};
class CorePropertyManagertest : public Cyphesis::TestBase
{
CorePropertyManager * m_propertyManager;
public:
CorePropertyManagertest();
void setup();
void teardown();
2013-01-08 22:55:00 +00:00
void test_addProperty_int();
void test_addProperty_float();
void test_addProperty_string();
void test_addProperty_list();
void test_addProperty_map();
void test_addProperty_none();
void test_addProperty_named();
void test_installFactory();
Inheritance* m_inheritance;
};
CorePropertyManagertest::CorePropertyManagertest()
{
2013-01-08 22:55:00 +00:00
ADD_TEST(CorePropertyManagertest::test_addProperty_int);
ADD_TEST(CorePropertyManagertest::test_addProperty_float);
ADD_TEST(CorePropertyManagertest::test_addProperty_string);
ADD_TEST(CorePropertyManagertest::test_addProperty_list);
ADD_TEST(CorePropertyManagertest::test_addProperty_map);
ADD_TEST(CorePropertyManagertest::test_addProperty_none);
ADD_TEST(CorePropertyManagertest::test_addProperty_named);
ADD_TEST(CorePropertyManagertest::test_installFactory);
}
void CorePropertyManagertest::setup()
{
m_inheritance = new Inheritance();
m_propertyManager = new CorePropertyManager;
2013-01-08 22:55:00 +00:00
m_propertyManager->m_propertyFactories.insert(
std::make_pair("named_type", new PropertyFactory<MinimalProperty>)
);
}
void CorePropertyManagertest::teardown()
{
delete m_inheritance;
delete m_propertyManager;
}
2013-01-08 22:55:00 +00:00
void CorePropertyManagertest::test_addProperty_int()
{
auto * p = m_propertyManager->addProperty("non_existant_type",
Element::TYPE_INT);
ASSERT_NOT_NULL(p);
ASSERT_NOT_NULL(dynamic_cast<Property<int> *>(p));
}
void CorePropertyManagertest::test_addProperty_float()
{
2013-01-08 22:55:00 +00:00
auto * p = m_propertyManager->addProperty("non_existant_type",
Element::TYPE_FLOAT);
ASSERT_NOT_NULL(p);
ASSERT_NOT_NULL(dynamic_cast<Property<double> *>(p));
}
void CorePropertyManagertest::test_addProperty_string()
{
auto * p = m_propertyManager->addProperty("non_existant_type",
Element::TYPE_STRING);
ASSERT_NOT_NULL(p);
ASSERT_NOT_NULL(dynamic_cast<Property<std::string> *>(p));
}
void CorePropertyManagertest::test_addProperty_list()
{
auto * p = m_propertyManager->addProperty("non_existant_type",
Element::TYPE_LIST);
ASSERT_NOT_NULL(p);
ASSERT_NOT_NULL(dynamic_cast<SoftProperty *>(p));
}
void CorePropertyManagertest::test_addProperty_map()
{
auto * p = m_propertyManager->addProperty("non_existant_type",
Element::TYPE_MAP);
ASSERT_NOT_NULL(p);
ASSERT_NOT_NULL(dynamic_cast<SoftProperty *>(p));
}
void CorePropertyManagertest::test_addProperty_none()
{
auto * p = m_propertyManager->addProperty("non_existant_type",
Element::TYPE_NONE);
ASSERT_NOT_NULL(p);
ASSERT_NOT_NULL(dynamic_cast<SoftProperty *>(p));
}
void CorePropertyManagertest::test_addProperty_named()
{
auto * p = m_propertyManager->addProperty("named_type",
Element::TYPE_NONE);
ASSERT_NOT_NULL(p);
ASSERT_NOT_NULL(dynamic_cast<MinimalProperty *>(p));
}
void CorePropertyManagertest::test_installFactory()
{
int ret = m_propertyManager->installFactory(
"new_named_type",
Root(),
2018-10-30 19:31:27 +01:00
std::make_unique<PropertyFactory<MinimalProperty>>()
);
ASSERT_EQUAL(ret, 0);
}
int main()
{
CorePropertyManagertest t;
return t.run();
}
2017-08-02 10:03:58 +02:00
#include "common/const.h"
#include "common/globals.h"
#include "common/log.h"
#include "common/Monitors.h"
#include "common/PropertyFactory.h"
#include "common/system.h"
#include "common/TypeNode.h"
#include "common/Variable.h"
// stubs
#include "server/ArithmeticBuilder.h"
#include "server/EntityFactory.h"
#include "server/Juncture.h"
#include "server/Persistence.h"
#include "server/Player.h"
#include "server/Ruleset.h"
#include "server/ServerRouting.h"
#include "server/TeleportProperty.h"
2018-11-03 16:43:33 +01:00
#include "rules/simulation/AreaProperty.h"
#include "rules/AtlasProperties.h"
#include "rules/BBoxProperty.h"
2018-11-03 16:43:33 +01:00
#include "rules/simulation/BiomassProperty.h"
#include "rules/simulation/BurnSpeedProperty.h"
#include "rules/simulation/CalendarProperty.h"
#include "rules/simulation/DecaysProperty.h"
#include "rules/simulation/EntityProperty.h"
2018-11-03 16:43:33 +01:00
#include "rules/simulation/ExternalProperty.h"
#include "rules/simulation/InternalProperties.h"
#include "rules/simulation/LineProperty.h"
#include "rules/simulation/MindProperty.h"
#include "rules/SolidProperty.h"
2018-11-03 16:43:33 +01:00
#include "rules/simulation/SpawnProperty.h"
#include "rules/simulation/StatusProperty.h"
#include "rules/simulation/StatisticsProperty.h"
#include "rules/simulation/SuspendedProperty.h"
#include "rules/simulation/TasksProperty.h"
#include "rules/simulation/TerrainModProperty.h"
#include "rules/simulation/TerrainProperty.h"
#include "rules/simulation/TransientProperty.h"
#include "rules/simulation/VisibilityProperty.h"
#include "rules/simulation/SpawnerProperty.h"
#include "rules/simulation/ImmortalProperty.h"
#include "rules/simulation/RespawningProperty.h"
#include "rules/simulation/DefaultLocationProperty.h"
#include "rules/simulation/LimboProperty.h"
#include "rules/simulation/DomainProperty.h"
#include "rules/python/ScriptsProperty.h"
2017-08-02 10:03:58 +02:00
//void Entity::destroy()
//{
// destroyed.emit();
//}
//
//void Entity::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
//{
// ent->setId(getId());
//}
2018-11-03 16:43:33 +01:00
#include "stubs/rules/simulation/stubEntity.h"
#include "stubs/rules/stubLocatedEntity.h"
2017-08-02 10:03:58 +02:00
#include "stubs/common/stubProperty.h"
2018-10-27 13:13:45 +02:00
#include "stubs/common/stubcustom.h"
#include "stubs/common/stubLink.h"
#include "stubs/modules/stubWeakEntityRef.h"
#include "stubs/rules/stubBBoxProperty.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/simulation/stubImmortalProperty.h"
#include "stubs/rules/simulation/stubRespawningProperty.h"
#include "stubs/rules/simulation/stubSpawnerProperty.h"
#include "stubs/rules/simulation/stubTerrainModProperty.h"
#include "stubs/rules/simulation/stubTerrainProperty.h"
#include "stubs/rules/simulation/stubServerBBoxProperty.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/simulation/stubBiomassProperty.h"
#include "stubs/rules/simulation/stubBurnSpeedProperty.h"
#include "stubs/rules/simulation/stubDecaysProperty.h"
#include "stubs/rules/simulation/stubStatusProperty.h"
#include "stubs/rules/simulation/stubTasksProperty.h"
#include "stubs/rules/simulation/stubSpawnProperty.h"
#include "stubs/rules/simulation/stubDefaultLocationProperty.h"
#include "stubs/rules/simulation/stubLimboProperty.h"
#include "stubs/rules/simulation/stubDomainProperty.h"
#include "stubs/rules/simulation/stubSuspendedProperty.h"
#include "stubs/rules/simulation/stubModeProperty.h"
#include "stubs/rules/stubQuaternionProperty.h"
#include "stubs/rules/simulation/stubAngularFactorProperty.h"
#include "stubs/rules/simulation/stubGeometryProperty.h"
#include "stubs/rules/simulation/stubDensityProperty.h"
#include "stubs/rules/stubVector3Property.h"
#include "stubs/rules/simulation/stubThing.h"
#include "stubs/rules/simulation/stubEntityProperty.h"
#include "stubs/rules/simulation/stubInternalProperties.h"
#include "stubs/rules/stubSolidProperty.h"
#include "stubs/rules/simulation/stubPerceptionSightProperty.h"
#include "stubs/rules/stubScaleProperty.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/python/stubScriptsProperty.h"
#include "stubs/rules/simulation/stubMindsProperty.h"
#include "stubs/server/stubAccount.h"
#include "stubs/server/stubArithmeticBuilder.h"
2018-10-27 13:13:45 +02:00
#include "stubs/server/stubConnectableRouter.h"
#define STUB_EntityFactory_newEntity
template <typename T>
2018-07-24 21:18:50 +02:00
Ref<LocatedEntity> EntityFactory<T>::newEntity(const std::string & id, long intId, const Atlas::Objects::Entity::RootEntity & attributes, LocatedEntity* location)
{
return new Entity(id, intId);
}
class Stackable;
class World;
template <>
2018-07-24 21:18:50 +02:00
Ref<LocatedEntity> EntityFactory<World>::newEntity(const std::string & id, long intId,
const Atlas::Objects::Entity::RootEntity & attributes, LocatedEntity* location)
{
return 0;
}
2018-10-27 13:13:45 +02:00
template class EntityFactory<Thing>;
template class EntityFactory<Stackable>;
template class EntityFactory<World>;
#include "stubs/server/stubPersistence.h"
#include "stubs/server/stubPlayer.h"
#include "stubs/server/stubRuleHandler.h"
#include "stubs/server/stubEntityRuleHandler.h"
#include "stubs/server/stubArchetypeRuleHandler.h"
#include "stubs/server/stubOpRuleHandler.h"
#include "stubs/server/stubPropertyRuleHandler.h"
#include "stubs/server/stubRuleset.h"
#include "stubs/server/stubServerRouting.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/simulation/stubTask.h"
#include "stubs/rules/simulation/stubUsagesProperty.h"
#include "stubs/rules/entityfilter/stubFilter.h"
#include "stubs/rules/stubAtlasProperties.h"
#include "stubs/rules/stubSimpleProperty.h"
#include "stubs/rules/simulation/stubCalendarProperty.h"
#include "stubs/rules/simulation/stubAreaProperty.h"
#include "stubs/rules/simulation/stubExternalProperty.h"
2013-01-08 22:55:00 +00:00
template <class T>
PropertyBase * PropertyFactory<T>::newProperty()
{
return new T();
}
2013-02-18 10:16:28 +00:00
template <class T>
PropertyFactory<T> * PropertyFactory<T>::duplicateFactory() const
{
return new PropertyFactory<T>;
}
2013-01-08 22:55:00 +00:00
template class PropertyFactory<MinimalProperty>;
2013-02-14 19:32:24 +00:00
void TeleportProperty::install(LocatedEntity * owner, const std::string & name)
{
}
HandlerResult TeleportProperty::operation(LocatedEntity * ent,
const Operation & op,
OpVector & res)
{
return OPERATION_IGNORED;
}
2018-11-03 16:43:33 +01:00
#include "stubs/rules/simulation/stubLineProperty.h"
#include "stubs/rules/simulation/stubMindProperty.h"
#include "stubs/rules/simulation/stubAttachmentsProperty.h"
#include "stubs/rules/simulation/stubPlantedOnProperty.h"
#include "stubs/rules/simulation/stubAdminProperty.h"
#include "stubs/rules/simulation/stubVisibilityProperty.h"
#include "stubs/rules/simulation/stubStatisticsProperty.h"
#include "stubs/rules/simulation/stubTransientProperty.h"
#include "stubs/rules/stubLocation.h"
#include "stubs/rules/simulation/stubBaseWorld.h"
bool_config_register::bool_config_register(bool & var,
const char * section,
const char * setting,
const char * help)
{
}
#include "stubs/common/stubEntityKit.h"
#include "stubs/server/stubEntityFactory.h"
2018-10-27 13:13:45 +02:00
#include "stubs/server/stubJuncture.h"
Root atlasType(const std::string & name,
const std::string & parent,
bool abstract)
{
return Atlas::Objects::Root();
}
#define STUB_Inheritance_getClass
2018-10-27 13:13:45 +02:00
const Atlas::Objects::Root& Inheritance::getClass(const std::string & parent, Visibility)
{
return noClass;
}
#define STUB_Inheritance_addChild
TypeNode * Inheritance::addChild(const Root & obj)
{
return new TypeNode(obj->getId());
}
#include "stubs/common/stubInheritance.h"
#include "stubs/common/stubMonitors.h"
#include "stubs/common/stubPropertyManager.h"
#include "stubs/common/stubShaker.h"
2018-10-27 13:13:45 +02:00
#define STUB_Router_error
void Router::error(const Operation & op,
const std::string & errstring,
OpVector & res,
const std::string & to) const
{
res.push_back(Atlas::Objects::Operation::Error());
}
2018-10-27 13:13:45 +02:00
#include "stubs/common/stubRouter.h"
2018-10-27 13:13:45 +02:00
#include "stubs/common/stubTypeNode.h"
2015-04-09 14:50:45 +02:00
#include "stubs/common/stubVariable.h"
#include "stubs/server/stubBuildid.h"
2013-11-15 00:16:17 +01:00
const char * const CYPHESIS = "cyphesis";
static const char * DEFAULT_INSTANCE = "cyphesis";
std::string instance(DEFAULT_INSTANCE);
int timeoffset = 0;
bool database_flag = false;
static long idGenerator = 0;
long newId(std::string & id)
{
static char buf[32];
long new_id = ++idGenerator;
sprintf(buf, "%ld", new_id);
id = buf;
assert(!id.empty());
return new_id;
}
void log(LogLevel lvl, const std::string & msg)
{
}
void logEvent(LogEvent lev, const std::string & msg)
{
}
Root atlasClass(const std::string & name, const std::string & parent)
{
return Root();
}
void hash_password(const std::string & pwd, const std::string & salt,
std::string & hash)
{
}
int check_password(const std::string & pwd, const std::string & hash)
{
return -1;
}
void addToEntity(const Point3D & p, std::vector<double> & vd)
{
}