From f7a53d028c755b9d1f82ea9d456b0e5318475e47 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 8 Jan 2009 10:55:07 -0500 Subject: Added MapWildList tests --- sigmod/test/CMakeLists.txt | 2 +- sigmod/test/TestMapWildList.cpp | 156 ++++++++++++++++++++++++++++++++++++++++ sigmod/test/TestMapWildList.h | 53 ++++++++++++++ 3 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 sigmod/test/TestMapWildList.cpp create mode 100644 sigmod/test/TestMapWildList.h (limited to 'sigmod/test') diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt index 75bd6612..a824ed07 100644 --- a/sigmod/test/CMakeLists.txt +++ b/sigmod/test/CMakeLists.txt @@ -41,7 +41,7 @@ MAKE_TEST(sigmod-tests libraries MapTile) # MAKE_TEST(sigmod-tests libraries MapTrainer) # MAKE_TEST(sigmod-tests libraries MapTrainerTeamMember) # MAKE_TEST(sigmod-tests libraries MapWarp) -# MAKE_TEST(sigmod-tests libraries MapWildList) +MAKE_TEST(sigmod-tests libraries MapWildList) MAKE_TEST(sigmod-tests libraries MapWildListEncounter) MAKE_TEST(sigmod-tests libraries Move) MAKE_TEST(sigmod-tests libraries Nature) diff --git a/sigmod/test/TestMapWildList.cpp b/sigmod/test/TestMapWildList.cpp new file mode 100644 index 00000000..a39bf743 --- /dev/null +++ b/sigmod/test/TestMapWildList.cpp @@ -0,0 +1,156 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 3 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, see . + */ + +// Header include +#include "TestMapWildList.h" + +// Sigmod includes +#include "../Map.h" +#include "../MapWildList.h" +#include "../MapWildListEncounter.h" +#include "../Sigmod.h" + +// Qt includes +#include +#include + +void TestMapWildList::initTestCase() +{ + TestSigmodObject::initTestCase(); + + Sigmod::Map* map = m_sigmod->newMap(); + + m_wildList1 = map->newWildList(); + m_wildList2 = map->newWildList(); + m_wildList3 = map->newWildList(); +} + +void TestMapWildList::cleanupTestCase() +{ + TestSigmodObject::cleanupTestCase(); +} + +void TestMapWildList::init() +{ + TestSigmodObject::init(); + + makeConnections(m_wildList1); + makeConnections(m_wildList2); + makeConnections(m_wildList3); +} + +void TestMapWildList::cleanup() +{ + closeConnections(m_wildList1); + closeConnections(m_wildList2); + closeConnections(m_wildList3); + + TestSigmodObject::cleanup(); +} + +void TestMapWildList::validation() +{ + m_wildList1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 2); + + m_wildList1->setName("Foo"); + m_wildList1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 3); + + m_wildList1->newEncounter(); + m_wildList1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 3); +} + +void TestMapWildList::saving() +{ + QDomDocument xml = Sigmod::Object::xml(m_wildList1); + QFile file("wildList.xml"); + + QVERIFY(file.open(QIODevice::WriteOnly)); + file.write(xml.toByteArray()); + file.close(); +} + +void TestMapWildList::loading() +{ + QDomDocument xml; + QFile file("wildList.xml"); + + m_wildList1->setName("Bar"); + m_wildList1->newEncounter(); + + QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY(xml.setContent(&file)); + m_wildList1->load(xml.firstChildElement("MapWildList")); + + QCOMPARE(m_wildList1->name(), QString("Foo")); + QCOMPARE(m_wildList1->encounterCount(), 1); +} + +void TestMapWildList::setName() +{ + m_wildList2->setName("Foo"); + m_wildList2->setName("Foo"); + + QCOMPARE(m_wildList2->name(), QString("Foo")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestMapWildList::encounters() +{ + QCOMPARE(m_wildList2->newEncounter()->id(), 0); + QCOMPARE(m_wildList2->newEncounter()->id(), 1); + QCOMPARE(m_wildList2->newEncounter()->id(), 2); + + QCOMPARE(m_wildList2->encounterCount(), 3); + + m_wildList2->deleteEncounter(0); + + QCOMPARE(m_wildList2->encounterCount(), 2); + + QCOMPARE(m_wildList2->newEncounter()->id(), 0); + + QCOMPARE(m_wildList2->encounterIndex(0), 2); + + m_wildList2->deleteEncounterById(1); + + QCOMPARE(m_wildList2->encounterIndex(0), 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestMapWildList::assignment() +{ + *m_wildList3 = *m_wildList2; + + QCOMPARE(m_wildList3->name(), QString("Foo")); + QCOMPARE(m_wildList3->encounterCount(), 2); +} + +QTEST_APPLESS_MAIN(TestMapWildList) diff --git a/sigmod/test/TestMapWildList.h b/sigmod/test/TestMapWildList.h new file mode 100644 index 00000000..39113b10 --- /dev/null +++ b/sigmod/test/TestMapWildList.h @@ -0,0 +1,53 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 3 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, see . + */ + +#ifndef SIGMOD_TESTMAPWILDLIST +#define SIGMOD_TESTMAPWILDLIST + +// Test includes +#include "TestSigmodObject.h" + +// Sigmod includes +#include "../MapWildList.h" + +class TestMapWildList : public TestSigmodObject +{ + Q_OBJECT + + private slots: + void initTestCase(); + void cleanupTestCase(); + + void init(); + void cleanup(); + + void validation(); + void saving(); + void loading(); + + void setName(); + + void encounters(); + + void assignment(); + private: + Sigmod::MapWildList* m_wildList1; + Sigmod::MapWildList* m_wildList2; + Sigmod::MapWildList* m_wildList3; +}; + +#endif -- cgit