2006-12-06 07:48:01 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2006 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
|
|
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/BaseWorld.h"
|
2013-09-07 17:00:45 +02:00
|
|
|
#include "common/log.h"
|
2006-12-06 07:48:01 +00:00
|
|
|
|
|
|
|
|
#include <Atlas/Objects/RootOperation.h>
|
|
|
|
|
|
|
|
|
|
#include <sigc++/functors/ptr_fun.h>
|
|
|
|
|
|
2010-03-20 16:15:34 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
|
|
2006-12-06 07:48:01 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2010-03-20 16:15:34 +00:00
|
|
|
static void test_function(Atlas::Objects::Operation::RootOperation)
|
2006-12-06 07:48:01 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../TestWorld.h"
|
2018-10-31 21:38:35 +01:00
|
|
|
#include "rules/simulation/Entity.h"
|
2010-03-20 16:15:34 +00:00
|
|
|
|
2018-07-24 21:18:50 +02:00
|
|
|
class MyTestWorld : public TestWorld {
|
2010-03-20 16:15:34 +00:00
|
|
|
public:
|
2018-08-05 14:31:04 +02:00
|
|
|
explicit MyTestWorld(Ref<LocatedEntity> gw) : TestWorld(gw) {
|
|
|
|
|
m_eobjects[gw->getIntId()] = gw;
|
2010-03-20 16:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-13 15:23:01 +02:00
|
|
|
void addEntity(const Ref<LocatedEntity>& ent, const Ref<LocatedEntity>& parent) override {
|
2010-03-20 16:15:34 +00:00
|
|
|
m_eobjects[ent->getIntId()] = ent;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2006-12-06 07:48:01 +00:00
|
|
|
int main()
|
|
|
|
|
{
|
2018-07-24 21:18:50 +02:00
|
|
|
// We have to use the MyTestWorld class, as it implements the functions
|
2006-12-06 07:48:01 +00:00
|
|
|
// missing from BaseWorld interface.
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Test constructor
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Test destructor
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
BaseWorld * tw = new MyTestWorld(wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
|
|
|
|
|
delete tw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Test constructor sets singleton pointer
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
|
|
|
|
|
assert(&BaseWorld::instance() == &tw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Test constructor installs reference to world entity
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
|
2018-08-05 14:31:04 +02:00
|
|
|
assert(tw.m_gw == wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-07-31 23:33:55 +02:00
|
|
|
// Test retrieving non existent entity by string ID is ok
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
|
2018-08-05 20:47:09 +02:00
|
|
|
assert(!tw.getEntity("2"));
|
2006-12-06 07:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
2009-05-05 23:02:34 +01:00
|
|
|
{
|
2020-07-31 23:33:55 +02:00
|
|
|
// Test retrieving existent entity by string ID is ok
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2009-05-05 23:02:34 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
LocatedEntity * tc = new Entity(2);
|
2009-05-05 23:02:34 +01:00
|
|
|
|
2020-04-13 15:23:01 +02:00
|
|
|
tw.addEntity(tc, wrld);
|
2009-05-05 23:02:34 +01:00
|
|
|
|
|
|
|
|
assert(tw.getEntity("2") == tc);
|
2010-03-20 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-07-31 23:33:55 +02:00
|
|
|
// Test retrieving existent entity by integer ID is ok
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2010-03-20 16:17:48 +00:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
LocatedEntity * tc = new Entity(2);
|
2010-03-20 16:17:48 +00:00
|
|
|
|
2020-04-13 15:23:01 +02:00
|
|
|
tw.addEntity(tc, wrld);
|
2010-03-20 16:17:48 +00:00
|
|
|
|
|
|
|
|
assert(tw.getEntity(2) == tc);
|
2009-05-05 23:02:34 +01:00
|
|
|
}
|
|
|
|
|
|
2006-12-06 07:48:01 +00:00
|
|
|
{
|
2020-07-31 23:33:55 +02:00
|
|
|
// Test retrieving non existent entity by integer ID is ok
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
|
2018-08-05 20:47:09 +02:00
|
|
|
assert(!tw.getEntity(2));
|
2006-12-06 07:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Test retrieving reference to all entities is okay and empty
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
|
2009-11-13 03:10:40 +00:00
|
|
|
assert(tw.getEntities().size() == 1);
|
2006-12-06 07:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Test getting the time
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
|
|
|
|
|
tw.getTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Test getting the uptime
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
|
|
|
|
|
tw.upTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Test connecting to the dispatch signal
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(1));
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld tw(wrld);
|
2006-12-06 07:48:01 +00:00
|
|
|
|
|
|
|
|
tw.Dispatching.connect(sigc::ptr_fun(&test_function));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-03-20 16:15:34 +00:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubid.h"
|
|
|
|
|
#include "../stubs/common/stublog.h"
|
2010-03-20 16:15:34 +00:00
|
|
|
|
2013-09-07 17:00:45 +02:00
|
|
|
|
2010-03-20 16:15:34 +00:00
|
|
|
int timeoffset = 0;
|
2018-07-24 21:18:50 +02:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/rules/stubLocatedEntity.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubEntity.h"
|
|
|
|
|
#include "../stubs/rules/stubLocation.h"
|
|
|
|
|
#include "../stubs/common/stubRouter.h"
|