cyphesis/tests/StorageManagerTest.cpp

429 lines
8.6 KiB
C++
Raw Permalink Normal View History

2010-07-29 16:14:24 +01:00
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2010 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
2011-02-15 09:30:46 +00:00
#ifdef NDEBUG
#undef NDEBUG
#endif
#ifndef DEBUG
#define DEBUG
#endif
2010-07-29 16:14:24 +01:00
#include "server/StorageManager.h"
#include "server/WorldRouter.h"
2013-08-22 14:20:33 +02:00
#include "server/MindInspector.h"
#include "rules/simulation/Entity.h"
2018-11-03 16:43:33 +01:00
#include "rules/simulation/MindProperty.h"
2011-10-31 12:47:56 +01:00
#include "common/SystemTime.h"
#include "DatabaseNull.h"
2011-10-31 12:47:56 +01:00
2010-07-29 16:14:24 +01:00
#include <cassert>
#include <server/EntityBuilder.h>
2013-08-22 14:20:33 +02:00
using Atlas::Message::Element;
2010-07-29 16:14:24 +01:00
class TestStorageManager : public StorageManager
{
public:
TestStorageManager(WorldRouter&w) : StorageManager(w) { }
void test_entityInserted(LocatedEntity * e) {
entityInserted(e);
}
void test_entityUpdated(LocatedEntity * e) {
entityUpdated(e);
}
void test_encodeProperty(PropertyBase * p, std::string & s) {
encodeProperty(p, s);
}
void test_restoreProperties(LocatedEntity * e) {
restorePropertiesRecursively(e);
}
void test_insertEntity(LocatedEntity * e) {
insertEntity(e);
}
void test_updateEntity(LocatedEntity * e) {
updateEntity(e);
}
void test_restoreChildren(LocatedEntity * e) {
restoreChildren(e);
}
};
2010-07-29 16:14:24 +01:00
int main()
{
EntityBuilder eb;
DatabaseNull database;
Persistence persistence(database);
2018-07-24 21:18:50 +02:00
Ref<LocatedEntity> le = new Entity("", 0);
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
StorageManager store(world);
}
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
StorageManager store(world);
2018-07-24 21:18:50 +02:00
store.initWorld(le);
}
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
StorageManager store(world);
2018-07-24 21:18:50 +02:00
store.restoreWorld(le);
}
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
StorageManager store(world);
store.tick();
}
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
TestStorageManager store(world);
store.test_entityInserted(new Entity("1", 1));
}
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
TestStorageManager store(world);
store.test_entityUpdated(new Entity("1", 1));
}
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
TestStorageManager store(world);
std::string val;
// store.test_encodeProperty(0, val);
}
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
TestStorageManager store(world);
store.test_restoreProperties(new Entity("1", 1));
}
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
TestStorageManager store(world);
store.test_insertEntity(new Entity("1", 1));
}
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
TestStorageManager store(world);
store.test_updateEntity(new Entity("1", 1));
}
{
2011-10-31 12:47:56 +01:00
SystemTime time;
2018-07-24 21:18:50 +02:00
WorldRouter world(time, le);
TestStorageManager store(world);
store.test_restoreChildren(new Entity("1", 1));
}
2010-07-29 16:14:24 +01:00
return 0;
}
// stubs
#include "server/CorePropertyManager.h"
2010-07-29 16:14:24 +01:00
#include "server/EntityBuilder.h"
#include "rules/Script.h"
2010-07-29 16:14:24 +01:00
#include "modules/WeakEntityRef.h"
#include "rules/Location.h"
2010-07-29 16:14:24 +01:00
#include "common/const.h"
2010-07-29 16:14:24 +01:00
#include "common/Database.h"
#include "common/globals.h"
#include "common/log.h"
#include "common/Monitors.h"
#include "common/PropertyManager.h"
2011-10-31 12:47:56 +01:00
#include "common/SystemTime.h"
2010-07-29 16:14:24 +01:00
#include "common/Variable.h"
#include "stubs/server/stubWorldRouter.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/stubLocation.h"
#include "stubs/rules/simulation/stubEntity.h"
#include "stubs/rules/simulation/stubThing.h"
#include "stubs/rules/simulation/stubBaseWorld.h"
#include <Atlas/Objects/RootOperation.h>
#include <Atlas/Objects/SmartPtr.h>
2010-07-29 16:14:24 +01:00
#include <cstdlib>
#include <iostream>
using Atlas::Message::MapType;
using Atlas::Objects::Entity::RootEntity;
2018-07-24 21:18:50 +02:00
#include "stubs/server/stubEntityBuilder.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/stubLocatedEntity.h"
#include "stubs/common/stubRouter.h"
#define STUB_Database_selectEntities
DatabaseResult Database::selectEntities(const std::string & loc)
{
return DatabaseResult(std::unique_ptr<DatabaseNullResultWorker>(new DatabaseNullResultWorker()));
}
#define STUB_Database_selectProperties
DatabaseResult Database::selectProperties(const std::string& loc)
{
return DatabaseResult(std::unique_ptr<DatabaseNullResultWorker>(new DatabaseNullResultWorker()));
}
#define STUB_Database_selectThoughts
DatabaseResult Database::selectThoughts(const std::string& loc)
{
return DatabaseResult(std::unique_ptr<DatabaseNullResultWorker>(new DatabaseNullResultWorker()));
}
#include "stubs/common/stubDatabase.h"
#include "stubs/server/stubPersistence.h"
#include "stubs/common/stubPropertyManager.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/stubScript.h"
#include "stubs/modules/stubWeakEntityRef.h"
2010-07-29 16:14:24 +01:00
VariableBase::~VariableBase()
{
}
template <typename T>
Variable<T>::Variable(const T & variable) : m_variable(variable)
{
}
template <typename T>
Variable<T>::~Variable()
{
}
template <typename T>
void Variable<T>::send(std::ostream & o)
{
o << m_variable;
}
2015-04-09 14:50:45 +02:00
template <typename T>
bool Variable<T>::isNumeric() const
2010-07-29 16:14:24 +01:00
{
2015-04-09 14:50:45 +02:00
return false;
2010-07-29 16:14:24 +01:00
}
2015-04-09 14:50:45 +02:00
template class Variable<int>;
template class Variable<const char *>;
template class Variable<std::string>;
2010-07-29 16:14:24 +01:00
2015-04-09 14:50:45 +02:00
#include "stubs/common/stubMonitors.h"
2015-05-23 16:47:45 +02:00
#include "stubs/common/stubOperationsDispatcher.h"
2010-07-29 16:14:24 +01:00
2013-08-22 14:20:33 +02:00
MindInspector::MindInspector() :
m_serial(0)
{
}
MindInspector::~MindInspector()
{
}
void MindInspector::queryEntityForThoughts(const std::string& entityId)
{
}
void MindInspector::relayResponseReceived(const Operation& op,
const std::string& entityId)
{
}
PropertyBase::PropertyBase(unsigned int flags) : m_flags(flags)
{
}
void PropertyBase::install(LocatedEntity *, const std::string & name)
2013-08-22 14:20:33 +02:00
{
}
void PropertyBase::install(TypeNode *, const std::string & name)
2013-08-22 14:20:33 +02:00
{
}
void PropertyBase::remove(LocatedEntity *, const std::string & name)
{
}
2013-08-22 14:20:33 +02:00
void PropertyBase::apply(LocatedEntity *)
{
}
void PropertyBase::add(const std::string & s,
Atlas::Message::MapType & ent) const
{
get(ent[s]);
}
void PropertyBase::add(const std::string & s,
const Atlas::Objects::Entity::RootEntity & ent) const
{
}
HandlerResult PropertyBase::operation(LocatedEntity *,
const Operation &,
OpVector &)
{
return OPERATION_IGNORED;
}
template <typename T>
Property<T>::Property(unsigned int flags) :
PropertyBase(flags)
{
}
template <typename T>
int Property<T>::get(Atlas::Message::Element & e) const
{
return 0;
}
// The following two are obsolete.
template <typename T>
void Property<T>::add(const std::string & s,
Atlas::Message::MapType & ent) const
{
}
template <typename T>
void Property<T>::add(const std::string & s,
const Atlas::Objects::Entity::RootEntity & ent) const
{
}
template <typename T>
void Property<T>::set(const Atlas::Message::Element & e)
{
}
template <typename T>
Property<T> * Property<T>::copy() const
{
return new Property<T>(*this);
}
template class Property<MapType>;
2013-08-22 14:20:33 +02:00
bool MindProperty::isMindEnabled() const {
return false;
}
void MindProperty::set(const Element & val)
{
}
MindProperty * MindProperty::copy() const
{
return 0;
}
void MindProperty::apply(LocatedEntity * ent)
{
}
2010-07-29 16:14:24 +01:00
long forceIntegerId(const std::string & id)
{
long intId = strtol(id.c_str(), 0, 10);
if (intId == 0 && id != "0") {
abort();
}
return intId;
}
void log(LogLevel lvl, const std::string & msg)
{
}
bool database_flag = true;
namespace consts {
// Id of root world entity
const char * rootWorldId = "0";
// Integer id of root world entity
const long rootWorldIntId = 0L;
}
2013-04-20 18:27:53 +02:00
namespace Atlas { namespace Objects { namespace Operation {
2013-08-22 14:20:33 +02:00
int THINK_NO = -1;
2013-04-20 18:27:53 +02:00
} } }