cyphesis/tests/TerrainModPropertyIntegration.cpp

199 lines
4.9 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 "rules/simulation/Entity.h"
2018-11-03 16:43:33 +01:00
#include "rules/simulation/TerrainModProperty.h"
#include "rules/simulation/TerrainProperty.h"
#include "common/OperationRouter.h"
#include "common/PropertyFactory_impl.h"
2018-11-03 16:43:33 +01:00
#include "rules/simulation/BaseWorld.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/stubLocation.h"
#include <Atlas/Objects/Operation.h>
using Atlas::Message::MapType;
using Atlas::Objects::Operation::Delete;
using Atlas::Objects::Operation::Move;
2018-07-24 21:18:50 +02:00
#include "TestWorld.h"
class TerrainModPropertyintegration : public Cyphesis::TestBase
{
private:
Ref<Entity> m_rootEntity;
Ref<Entity> m_entity;
PropertyBase * m_property;
2013-01-12 01:19:19 +00:00
PropertyBase * m_terrainProperty;
std::unique_ptr<TestWorld> m_world;
public:
TerrainModPropertyintegration();
void setup();
void teardown();
void test_move_handler();
void test_delete_handler();
};
TerrainModPropertyintegration::TerrainModPropertyintegration()
{
ADD_TEST(TerrainModPropertyintegration::test_move_handler);
ADD_TEST(TerrainModPropertyintegration::test_delete_handler);
}
void TerrainModPropertyintegration::setup()
{
m_rootEntity = new Entity("0", 0);
m_world.reset();
m_world.reset(new TestWorld(m_rootEntity));
m_entity = new Entity("1", 1);
m_entity->m_location.m_pos = Point3D(5.f, 5.f, 5.f);
2018-08-17 22:04:07 +02:00
m_entity->m_location.m_parent = m_rootEntity;
ASSERT_TRUE(m_entity->m_location.isValid());
PropertyFactory<TerrainModProperty> terrainmod_property_factory;
2013-01-12 01:19:19 +00:00
m_terrainProperty = new TerrainProperty;
m_terrainProperty->install(m_rootEntity.get(), "terrain");
m_rootEntity->setProperty("terrain", m_terrainProperty);
m_terrainProperty->apply(m_rootEntity.get());
m_rootEntity->propertyApplied("terrain", *m_terrainProperty);
m_property = terrainmod_property_factory.newProperty();
m_property->install(m_entity.get(), "terrainmod");
2013-01-12 01:19:19 +00:00
m_entity->setProperty("terrainmod", m_property);
m_property->apply(m_entity.get());
m_entity->propertyApplied("terrainmod", *m_property);
}
void TerrainModPropertyintegration::teardown()
{
}
void TerrainModPropertyintegration::test_move_handler()
{
Move m;
2013-01-12 01:19:19 +00:00
// FIXME Move needs some args, and also probably requires the position to
// to be set up on the entity first
OpVector res;
m_entity->operation(m, res);
// FIXME Check what gives
}
void TerrainModPropertyintegration::test_delete_handler()
{
Delete d;
OpVector res;
m_entity->operation(d, res);
// FIXME Check what gives
}
int main()
{
TerrainModPropertyintegration t;
return t.run();
}
// stubs
#include "rules/AtlasProperties.h"
#include "rules/Domain.h"
#include "rules/Script.h"
2018-11-03 16:43:33 +01:00
#include "rules/simulation/BaseWorld.h"
#include "common/id.h"
#include "common/log.h"
#include "common/PropertyManager.h"
#include "physics/Vector3D.h"
2018-11-03 16:43:33 +01:00
#include "rules/simulation/DomainProperty.h"
2018-10-27 13:13:45 +02:00
#include "stubs/common/stubcustom.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/stubDomain.h"
#include "stubs/rules/simulation/stubDomainProperty.h"
2015-04-09 14:50:45 +02:00
#include "stubs/common/stubVariable.h"
#include "stubs/common/stubMonitors.h"
void addToEntity(const Point3D & p, std::vector<double> & vd)
{
vd.resize(3);
vd[0] = p[0];
vd[1] = p[1];
vd[2] = p[2];
}
2018-10-27 13:13:45 +02:00
#include "stubs/common/stubRouter.h"
#ifndef STUB_BaseWorld_getEntity
#define STUB_BaseWorld_getEntity
Ref<LocatedEntity> BaseWorld::getEntity(const std::string & id) const
{
return getEntity(integerId(id));
}
Ref<LocatedEntity> BaseWorld::getEntity(long id) const
{
auto I = m_eobjects.find(id);
if (I != m_eobjects.end()) {
assert(I->second);
return I->second;
} else {
return nullptr;
}
}
#endif //STUB_BaseWorld_getEntity
2018-10-27 13:13:45 +02:00
#include "stubs/common/stubLink.h"
2018-11-03 16:43:33 +01:00
#include "stubs/rules/simulation/stubBaseWorld.h"
#include "stubs/rules/stubScript.h"
#include "stubs/rules/stubAtlasProperties.h"
#include "stubs/common/stubPropertyManager.h"
long integerId(const std::string & id)
{
long intId = strtol(id.c_str(), 0, 10);
if (intId == 0 && id != "0") {
intId = -1L;
}
return intId;
}
void log(LogLevel lvl, const std::string & msg)
{
}