// Cyphesis Online RPG Server and AI Engine // Copyright (C) 2007 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 "../common/EntityExerciser.h" #include "../TestBase.h" #include "rules/LocatedEntity.h" #include "rules/AtlasProperties.h" #include "rules/Script.h" #include "../TestPropertyManager.h" #include using Atlas::Message::Element; using Atlas::Message::ListType; using Atlas::Message::MapType; class LocatedEntitytest : public Cyphesis::TestBase { private: Ref m_entity; static bool m_TestProperty_remove_called; public: LocatedEntitytest(); void setup(); void teardown(); void test_setProperty(); void test_removeAttr(); void test_coverage(); class TestProperty : public PropertyBase { public: virtual void remove(LocatedEntity&, const std::string & name); virtual TestProperty * copy() const; virtual int get(Atlas::Message::Element&) const; virtual void set(const Atlas::Message::Element&); }; static void TestProperty_remove_called() { m_TestProperty_remove_called = true; } }; bool LocatedEntitytest::m_TestProperty_remove_called; void LocatedEntitytest::TestProperty::remove(LocatedEntity&, const std::string & name) { LocatedEntitytest::TestProperty_remove_called(); } int LocatedEntitytest::TestProperty::get(Atlas::Message::Element&) const { return 0; } void LocatedEntitytest::TestProperty::set(const Atlas::Message::Element&) { } LocatedEntitytest::TestProperty * LocatedEntitytest::TestProperty::copy() const { return new LocatedEntitytest::TestProperty(*this); } LocatedEntitytest::LocatedEntitytest() { ADD_TEST(LocatedEntitytest::test_setProperty); ADD_TEST(LocatedEntitytest::test_removeAttr); ADD_TEST(LocatedEntitytest::test_coverage); } void LocatedEntitytest::setup() { m_entity = new LocatedEntityTest(1); } void LocatedEntitytest::teardown() { m_entity = nullptr; } void LocatedEntitytest::test_setProperty() { std::string test_property("test_property"); ASSERT_TRUE(m_entity->getProperties().find(test_property) == m_entity->getProperties().end()); PropertyBase * tp = new SoftProperty; m_entity->setProperty(test_property, std::unique_ptr(tp)); ASSERT_TRUE(m_entity->getProperties().find(test_property) != m_entity->getProperties().end()); } void LocatedEntitytest::test_removeAttr() { std::string test_property("test_property"); LocatedEntity* entity = new LocatedEntityTest(1); ASSERT_TRUE(!m_TestProperty_remove_called); PropertyBase * tp = new TestProperty(); entity->setProperty(test_property, std::unique_ptr(tp)); ASSERT_TRUE(!m_TestProperty_remove_called); delete entity; ASSERT_TRUE(m_TestProperty_remove_called); } void LocatedEntitytest::test_coverage() { m_entity->setScript(std::make_unique