diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2008-12-24 09:53:03 -0500 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2008-12-24 09:53:03 -0500 |
commit | edeb52c290b7a75efd6b0817422c7ffe1960d878 (patch) | |
tree | c489ca18f66a9243b3a71038d6f9943742643627 | |
parent | 32f051a248617409abadbcfe2ffeec6c4192d5fb (diff) | |
download | sigen-edeb52c290b7a75efd6b0817422c7ffe1960d878.tar.gz sigen-edeb52c290b7a75efd6b0817422c7ffe1960d878.tar.xz sigen-edeb52c290b7a75efd6b0817422c7ffe1960d878.zip |
Added CoinListItem tests (enum loading is busted)
-rw-r--r-- | sigmod/test/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sigmod/test/TestCoinListItem.cpp | 178 | ||||
-rw-r--r-- | sigmod/test/TestCoinListItem.h | 53 |
3 files changed, 232 insertions, 1 deletions
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt index b85463dd..601f2976 100644 --- a/sigmod/test/CMakeLists.txt +++ b/sigmod/test/CMakeLists.txt @@ -24,7 +24,7 @@ MAKE_TEST(Ability libraries) MAKE_TEST(Author libraries) MAKE_TEST(Badge libraries) MAKE_TEST(CoinList libraries) -# MAKE_TEST(CoinListItem libraries) +MAKE_TEST(CoinListItem libraries) # MAKE_TEST(EggGroup libraries) # MAKE_TEST(GlobalScript libraries) # MAKE_TEST(Item libraries) diff --git a/sigmod/test/TestCoinListItem.cpp b/sigmod/test/TestCoinListItem.cpp new file mode 100644 index 00000000..475da303 --- /dev/null +++ b/sigmod/test/TestCoinListItem.cpp @@ -0,0 +1,178 @@ +/* + * 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 "TestCoinListItem.h" + +// Sigmod includes +#include "../CoinList.h" +#include "../CoinListItem.h" +#include "../Sigmod.h" + +// Qt includes +#include <QtCore/QFile> +#include <QtTest/QTest> + +void TestCoinListItem::initTestCase() +{ + TestSigmodObject::initTestCase(); + + Sigmod::CoinList* coinList = m_sigmod->newCoinList(); + + m_coinListItem1 = coinList->newItem(); + m_coinListItem2 = coinList->newItem(); + m_coinListItem3 = coinList->newItem(); +} + +void TestCoinListItem::cleanupTestCase() +{ + TestSigmodObject::cleanupTestCase(); +} + +void TestCoinListItem::init() +{ + TestSigmodObject::init(); + + makeConnections(m_coinListItem1); + makeConnections(m_coinListItem2); + makeConnections(m_coinListItem3); +} + +void TestCoinListItem::cleanup() +{ + closeConnections(m_coinListItem1); + closeConnections(m_coinListItem2); + closeConnections(m_coinListItem3); + + TestSigmodObject::cleanup(); +} + +void TestCoinListItem::validation() +{ + m_coinListItem1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 2); + + m_sigmod->newItem(); + + m_coinListItem1->setObject(0); + m_coinListItem1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 3); + + m_coinListItem1->setType(Sigmod::CoinListItem::Species); + m_coinListItem1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 5); + + m_sigmod->newSpecies(); + m_coinListItem1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 6); + + m_coinListItem1->setCost(20); + m_coinListItem1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 6); +} + +void TestCoinListItem::saving() +{ + QDomDocument xml = Sigmod::Object::xml(m_coinListItem1); + QFile file("coinListItem.xml"); + + QVERIFY(file.open(QIODevice::WriteOnly)); + file.write(xml.toByteArray()); + file.close(); +} + +void TestCoinListItem::loading() +{ + QDomDocument xml; + QFile file("coinListItem.xml"); + + m_sigmod->newItem(); + + m_coinListItem1->setType(Sigmod::CoinListItem::Item); + m_coinListItem1->setObject(1); + m_coinListItem1->setCost(25); + + QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY(xml.setContent(&file)); + m_coinListItem1->load(xml.firstChildElement("CoinListItem")); + + // FIXME + QEXPECT_FAIL(0, "Loading enumeration data from XML file doesn't work", Continue); + QCOMPARE(m_coinListItem1->type(), Sigmod::CoinListItem::Species); + QCOMPARE(m_coinListItem1->object(), 0); + QCOMPARE(m_coinListItem1->cost(), 20); +} + +void TestCoinListItem::setType() +{ + m_coinListItem2->setType(Sigmod::CoinListItem::Species); + m_coinListItem2->setType(Sigmod::CoinListItem::Species); + + QCOMPARE(m_coinListItem2->type(), Sigmod::CoinListItem::Species); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestCoinListItem::setObject() +{ + m_coinListItem2->setObject(0); + m_coinListItem2->setObject(0); + + QCOMPARE(m_coinListItem2->object(), 0); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestCoinListItem::setCost() +{ + m_coinListItem2->setCost(15); + m_coinListItem2->setCost(15); + + QCOMPARE(m_coinListItem2->cost(), 15); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestCoinListItem::assignment() +{ + *m_coinListItem3 = *m_coinListItem2; + + QCOMPARE(m_coinListItem3->type(), Sigmod::CoinListItem::Species); + QCOMPARE(m_coinListItem3->object(), 0); + QCOMPARE(m_coinListItem3->cost(), 15); +} + +QTEST_APPLESS_MAIN(TestCoinListItem) diff --git a/sigmod/test/TestCoinListItem.h b/sigmod/test/TestCoinListItem.h new file mode 100644 index 00000000..e5c7e199 --- /dev/null +++ b/sigmod/test/TestCoinListItem.h @@ -0,0 +1,53 @@ +/* + * 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_TESTCOINLISTITEM +#define SIGMOD_TESTCOINLISTITEM + +// Test includes +#include "TestSigmodObject.h" + +// Sigmod includes +#include "../CoinListItem.h" + +class TestCoinListItem : public TestSigmodObject +{ + Q_OBJECT + + private slots: + void initTestCase(); + void cleanupTestCase(); + + void init(); + void cleanup(); + + void validation(); + void saving(); + void loading(); + + void setType(); + void setObject(); + void setCost(); + + void assignment(); + private: + Sigmod::CoinListItem* m_coinListItem1; + Sigmod::CoinListItem* m_coinListItem2; + Sigmod::CoinListItem* m_coinListItem3; +}; + +#endif |