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/TestMapWildList.cpp | 156 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 sigmod/test/TestMapWildList.cpp (limited to 'sigmod/test/TestMapWildList.cpp') 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) -- cgit