2009-11-19 01:12:39 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2009 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
|
|
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
#include "TestBase.h"
|
|
|
|
|
|
2009-11-19 01:12:39 +00:00
|
|
|
#include "server/EntityFactory.h"
|
|
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/Stackable.h"
|
|
|
|
|
#include "rules/simulation/World.h"
|
2009-11-19 01:12:39 +00:00
|
|
|
|
2011-12-16 08:33:58 +00:00
|
|
|
#include "common/ScriptKit.h"
|
2011-09-15 23:54:33 +01:00
|
|
|
#include "common/TypeNode.h"
|
|
|
|
|
|
2013-10-23 22:36:55 +02:00
|
|
|
#include <Atlas/Objects/Entity.h>
|
2009-11-19 01:12:39 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
class TestScriptFactory : public ScriptKit<LocatedEntity> {
|
2011-11-08 20:32:35 +00:00
|
|
|
protected:
|
|
|
|
|
std::string m_package;
|
2009-11-19 01:12:39 +00:00
|
|
|
public:
|
2011-11-08 20:32:35 +00:00
|
|
|
virtual const std::string & package() const {
|
|
|
|
|
return m_package;
|
|
|
|
|
}
|
2009-11-19 01:12:39 +00:00
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
virtual int addScript(LocatedEntity * entity) const {
|
2009-11-19 01:12:39 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual int refreshClass() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
class EntityFactorytest : public Cyphesis::TestBase
|
2009-11-19 01:12:39 +00:00
|
|
|
{
|
2013-02-21 23:22:04 +00:00
|
|
|
private:
|
2013-10-23 22:36:55 +02:00
|
|
|
EntityFactoryBase * m_ek;
|
2013-02-21 23:22:04 +00:00
|
|
|
public:
|
|
|
|
|
EntityFactorytest();
|
2009-11-19 01:12:39 +00:00
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
void setup();
|
|
|
|
|
void teardown();
|
2009-11-19 01:12:39 +00:00
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
void test_newEntity();
|
|
|
|
|
void test_destructor();
|
|
|
|
|
void test_updateProperties();
|
2013-10-23 22:36:55 +02:00
|
|
|
void test_updateProperties_child();
|
2013-02-21 23:22:04 +00:00
|
|
|
};
|
2009-11-19 01:12:39 +00:00
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
EntityFactorytest::EntityFactorytest()
|
|
|
|
|
{
|
|
|
|
|
ADD_TEST(EntityFactorytest::test_newEntity);
|
|
|
|
|
ADD_TEST(EntityFactorytest::test_destructor);
|
|
|
|
|
ADD_TEST(EntityFactorytest::test_updateProperties);
|
2013-10-23 22:36:55 +02:00
|
|
|
ADD_TEST(EntityFactorytest::test_updateProperties_child);
|
2013-02-21 23:22:04 +00:00
|
|
|
}
|
2009-11-19 01:12:39 +00:00
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
void EntityFactorytest::setup()
|
|
|
|
|
{
|
|
|
|
|
m_ek = new EntityFactory<Thing>;
|
|
|
|
|
m_ek->m_type = new TypeNode("foo");
|
|
|
|
|
}
|
2009-11-19 01:12:39 +00:00
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
void EntityFactorytest::teardown()
|
|
|
|
|
{
|
|
|
|
|
delete m_ek->m_type;
|
|
|
|
|
delete m_ek;
|
|
|
|
|
}
|
2009-11-19 01:12:39 +00:00
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
void EntityFactorytest::test_newEntity()
|
|
|
|
|
{
|
2018-08-05 20:47:09 +02:00
|
|
|
auto e = m_ek->newEntity("1", 1, Atlas::Objects::Entity::RootEntity(), nullptr);
|
2009-11-19 01:12:39 +00:00
|
|
|
|
2018-08-05 20:47:09 +02:00
|
|
|
ASSERT_TRUE(e);
|
2013-02-21 23:22:04 +00:00
|
|
|
}
|
2009-11-19 01:12:39 +00:00
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
void EntityFactorytest::test_destructor()
|
|
|
|
|
{
|
|
|
|
|
}
|
2011-09-15 23:05:41 +01:00
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
void EntityFactorytest::test_updateProperties()
|
|
|
|
|
{
|
2018-05-10 00:21:30 +02:00
|
|
|
std::map<const TypeNode*, TypeNode::PropertiesUpdate> changes;
|
|
|
|
|
m_ek->updateProperties(changes);
|
2013-02-21 23:22:04 +00:00
|
|
|
}
|
2011-09-15 23:05:41 +01:00
|
|
|
|
2013-10-23 22:36:55 +02:00
|
|
|
void EntityFactorytest::test_updateProperties_child()
|
|
|
|
|
{
|
|
|
|
|
EntityFactory<Thing> * ekc = new EntityFactory<Thing>;
|
|
|
|
|
ekc->m_type = m_ek->m_type;
|
|
|
|
|
ekc->m_classAttributes.insert(std::make_pair("foo", "value"));
|
|
|
|
|
|
|
|
|
|
m_ek->m_children.insert(ekc);
|
|
|
|
|
|
2018-05-10 00:21:30 +02:00
|
|
|
std::map<const TypeNode*, TypeNode::PropertiesUpdate> changes;
|
|
|
|
|
m_ek->updateProperties(changes);
|
2013-10-23 22:36:55 +02:00
|
|
|
|
|
|
|
|
assert(ekc->m_attributes.find("foo") != ekc->m_attributes.end());
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
EntityFactorytest t;
|
2011-09-15 23:05:41 +01:00
|
|
|
|
2013-02-21 23:22:04 +00:00
|
|
|
return t.run();
|
2009-11-19 01:12:39 +00:00
|
|
|
}
|
2010-03-23 01:32:29 +00:00
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
|
|
|
|
Stackable::Stackable(const std::string & id, long intId) :
|
2012-12-04 23:45:53 +00:00
|
|
|
Thing(id, intId), m_num(1)
|
2010-03-23 01:32:29 +00:00
|
|
|
{
|
|
|
|
|
// m_properties["num"] = new Property<int>(m_num, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Stackable::~Stackable()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Stackable::CombineOperation(const Operation & op, OpVector & res)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Stackable::DivideOperation(const Operation & op, OpVector & res)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "stubs/rules/simulation/stubThing.h"
|
|
|
|
|
#include "stubs/rules/simulation/stubEntity.h"
|
|
|
|
|
#include "stubs/rules/stubLocatedEntity.h"
|
2014-09-29 19:24:05 +02:00
|
|
|
#include "stubs/common/stubRouter.h"
|
|
|
|
|
#include "stubs/common/stubTypeNode.h"
|
2016-01-18 16:21:00 +01:00
|
|
|
#include "stubs/common/stubProperty.h"
|
|
|
|
|
#include "common/Property_impl.h"
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "stubs/rules/stubLocation.h"
|
2013-10-23 22:36:55 +02:00
|
|
|
|
|
|
|
|
void log(LogLevel lvl, const std::string & msg)
|
|
|
|
|
{
|
|
|
|
|
}
|