diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-12-29 15:38:36 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-12-29 15:38:36 -0500 |
| commit | 0e2b7db5661c4c6c8faaf89eede509a18c52949a (patch) | |
| tree | f8028cbef70529afb6088224a85275c9027fc07c | |
| parent | 386378b5568d870f59dbd3c803c60f54c24e82dd (diff) | |
| download | sigen-0e2b7db5661c4c6c8faaf89eede509a18c52949a.tar.gz sigen-0e2b7db5661c4c6c8faaf89eede509a18c52949a.tar.xz sigen-0e2b7db5661c4c6c8faaf89eede509a18c52949a.zip | |
Added SpeciesItem tests
| -rw-r--r-- | sigmod/test/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | sigmod/test/TestSpeciesItem.cpp | 154 | ||||
| -rw-r--r-- | sigmod/test/TestSpeciesItem.h | 52 |
3 files changed, 207 insertions, 1 deletions
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt index 40d23a60..ecf7f110 100644 --- a/sigmod/test/CMakeLists.txt +++ b/sigmod/test/CMakeLists.txt @@ -50,7 +50,7 @@ MAKE_TEST(sigmod-tests libraries ItemType) # MAKE_TEST(sigmod-tests libraries Sound) # MAKE_TEST(sigmod-tests libraries Species) MAKE_TEST(sigmod-tests libraries SpeciesAbility) -# MAKE_TEST(sigmod-tests libraries SpeciesItem) +MAKE_TEST(sigmod-tests libraries SpeciesItem) # MAKE_TEST(sigmod-tests libraries SpeciesMove) # MAKE_TEST(sigmod-tests libraries Sprite) # MAKE_TEST(sigmod-tests libraries Status) diff --git a/sigmod/test/TestSpeciesItem.cpp b/sigmod/test/TestSpeciesItem.cpp new file mode 100644 index 00000000..80b019b3 --- /dev/null +++ b/sigmod/test/TestSpeciesItem.cpp @@ -0,0 +1,154 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "TestSpeciesItem.h" + +// Sigmod includes +#include "../Sigmod.h" +#include "../Species.h" +#include "../SpeciesItem.h" + +// Qt includes +#include <QtCore/QFile> +#include <QtTest/QTest> + +void TestSpeciesItem::initTestCase() +{ + TestSigmodObject::initTestCase(); + + Sigmod::Species* species = m_sigmod->newSpecies(); + + m_speciesItem1 = species->newItem(); + m_speciesItem2 = species->newItem(); + m_speciesItem3 = species->newItem(); +} + +void TestSpeciesItem::cleanupTestCase() +{ + TestSigmodObject::cleanupTestCase(); +} + +void TestSpeciesItem::init() +{ + TestSigmodObject::init(); + + makeConnections(m_speciesItem1); + makeConnections(m_speciesItem2); + makeConnections(m_speciesItem3); +} + +void TestSpeciesItem::cleanup() +{ + closeConnections(m_speciesItem1); + closeConnections(m_speciesItem2); + closeConnections(m_speciesItem3); + + TestSigmodObject::cleanup(); +} + +void TestSpeciesItem::validation() +{ + m_speciesItem1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); + + m_sigmod->newItem(); + + m_speciesItem1->setItem(0); + m_speciesItem1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); +} + +void TestSpeciesItem::saving() +{ + QDomDocument xml = Sigmod::Object::xml(m_speciesItem1); + QFile file("speciesItem.xml"); + + QVERIFY(file.open(QIODevice::WriteOnly)); + file.write(xml.toByteArray()); + file.close(); +} + +void TestSpeciesItem::loading() +{ + QDomDocument xml; + QFile file("speciesItem.xml"); + + m_sigmod->newItem(); + + m_speciesItem1->setItem(1); + m_speciesItem1->setWeight(10); + + QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY(xml.setContent(&file)); + m_speciesItem1->load(xml.firstChildElement("SpeciesItem")); + + QCOMPARE(m_speciesItem1->item(), 0); + QCOMPARE(m_speciesItem1->weight(), 1); +} + +void TestSpeciesItem::setItem() +{ + m_speciesItem2->setItem(2); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); + + m_sigmod->newItem(); + + m_speciesItem2->setItem(2); + m_speciesItem2->setItem(2); + + QCOMPARE(m_speciesItem2->item(), 2); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); +} + +void TestSpeciesItem::setWeight() +{ + m_speciesItem2->setWeight(0); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); + + m_speciesItem2->setWeight(5); + m_speciesItem2->setWeight(5); + + QCOMPARE(m_speciesItem2->weight(), 5); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); +} + +void TestSpeciesItem::assignment() +{ + *m_speciesItem3 = *m_speciesItem2; + + QCOMPARE(m_speciesItem3->item(), 2); + QCOMPARE(m_speciesItem3->weight(), 5); +} + +QTEST_APPLESS_MAIN(TestSpeciesItem) diff --git a/sigmod/test/TestSpeciesItem.h b/sigmod/test/TestSpeciesItem.h new file mode 100644 index 00000000..7a097bf2 --- /dev/null +++ b/sigmod/test/TestSpeciesItem.h @@ -0,0 +1,52 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGMOD_TESTSPECIESITEM +#define SIGMOD_TESTSPECIESITEM + +// Test includes +#include "TestSigmodObject.h" + +// Sigmod includes +#include "../SpeciesItem.h" + +class TestSpeciesItem : public TestSigmodObject +{ + Q_OBJECT + + private slots: + void initTestCase(); + void cleanupTestCase(); + + void init(); + void cleanup(); + + void validation(); + void saving(); + void loading(); + + void setItem(); + void setWeight(); + + void assignment(); + private: + Sigmod::SpeciesItem* m_speciesItem1; + Sigmod::SpeciesItem* m_speciesItem2; + Sigmod::SpeciesItem* m_speciesItem3; +}; + +#endif |
