summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-12-24 10:51:48 -0500
committerBen Boeckel <MathStuf@gmail.com>2008-12-24 10:51:48 -0500
commitfad3ad4d5bc6e888eb769cb746f83e86ed6aff9c (patch)
treec2b375f1fbd105e5b7ed91c6afdd234606d45c52
parente41c9e8e1f6279f51421d9c325a59837bbce0767 (diff)
Added ItemType tests
-rw-r--r--sigmod/test/CMakeLists.txt2
-rw-r--r--sigmod/test/TestItemType.cpp223
-rw-r--r--sigmod/test/TestItemType.h55
3 files changed, 279 insertions, 1 deletions
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt
index b7911d26..7f951e71 100644
--- a/sigmod/test/CMakeLists.txt
+++ b/sigmod/test/CMakeLists.txt
@@ -28,7 +28,7 @@ MAKE_TEST(CoinListItem libraries)
MAKE_TEST(EggGroup libraries)
MAKE_TEST(GlobalScript libraries)
MAKE_TEST(Item libraries)
-# MAKE_TEST(ItemType libraries)
+MAKE_TEST(ItemType libraries)
# MAKE_TEST(Map libraries)
# MAKE_TEST(MapEffect libraries)
# MAKE_TEST(MapTile libraries)
diff --git a/sigmod/test/TestItemType.cpp b/sigmod/test/TestItemType.cpp
new file mode 100644
index 00000000..343a89b8
--- /dev/null
+++ b/sigmod/test/TestItemType.cpp
@@ -0,0 +1,223 @@
+/*
+ * 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 "TestItemType.h"
+
+// Sigmod includes
+#include "../ItemType.h"
+#include "../Rules.h"
+#include "../Sigmod.h"
+
+// Qt includes
+#include <QtCore/QFile>
+#include <QtTest/QTest>
+
+void TestItemType::initTestCase()
+{
+ TestSigmodObject::initTestCase();
+
+ m_itemType1 = m_sigmod->newItemType();
+ m_itemType2 = m_sigmod->newItemType();
+ m_itemType3 = m_sigmod->newItemType();
+}
+
+void TestItemType::cleanupTestCase()
+{
+ TestSigmodObject::cleanupTestCase();
+}
+
+void TestItemType::init()
+{
+ TestSigmodObject::init();
+
+ makeConnections(m_itemType1);
+ makeConnections(m_itemType2);
+ makeConnections(m_itemType3);
+}
+
+void TestItemType::cleanup()
+{
+ closeConnections(m_itemType1);
+ closeConnections(m_itemType2);
+ closeConnections(m_itemType3);
+
+ TestSigmodObject::cleanup();
+}
+
+void TestItemType::validation()
+{
+ m_itemType1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_itemType1->setName("Foo");
+ m_itemType1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_sigmod->rules()->setMaxTotalWeight(100);
+
+ m_itemType1->setMaxWeight(50);
+ m_itemType1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_sigmod->rules()->setMaxTotalWeight(25);
+
+ m_itemType1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+
+ m_sigmod->rules()->setMaxTotalWeight(100);
+
+ m_itemType1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+}
+
+void TestItemType::saving()
+{
+ QDomDocument xml = Sigmod::Object::xml(m_itemType1);
+ QFile file("itemType.xml");
+
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ file.write(xml.toByteArray());
+ file.close();
+}
+
+void TestItemType::loading()
+{
+ QDomDocument xml;
+ QFile file("itemType.xml");
+
+ m_itemType1->setName("Bar");
+ m_itemType1->setComputer(10);
+ m_itemType1->setPlayer(25);
+ m_itemType1->setMaxWeight(75);
+ m_itemType1->setCount(Sigmod::ItemType::Total);
+
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVERIFY(xml.setContent(&file));
+ m_itemType1->load(xml.firstChildElement("ItemType"));
+
+ QCOMPARE(m_itemType1->name(), QString("Foo"));
+ QCOMPARE(m_itemType1->computer(), 0);
+ QCOMPARE(m_itemType1->player(), 1);
+ QCOMPARE(m_itemType1->maxWeight(), 50);
+ // FIXME
+ QEXPECT_FAIL(0, "Loading enumeration data from XML file doesn't work", Continue);
+ QCOMPARE(m_itemType1->count(), Sigmod::ItemType::Distinct);
+}
+
+void TestItemType::setName()
+{
+ m_itemType2->setName("Foo");
+ m_itemType2->setName("Foo");
+
+ QCOMPARE(m_itemType2->name(), QString("Foo"));
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestItemType::setComputer()
+{
+ m_itemType2->setComputer(-1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_itemType2->setComputer(10);
+ m_itemType2->setComputer(10);
+
+ QCOMPARE(m_itemType2->computer(), 10);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestItemType::setPlayer()
+{
+ m_itemType2->setPlayer(0);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_itemType2->setPlayer(5);
+ m_itemType2->setPlayer(5);
+
+ QCOMPARE(m_itemType2->player(), 5);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestItemType::setMaxWeight()
+{
+ m_itemType2->setMaxWeight(1000);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_itemType2->setMaxWeight(25);
+ m_itemType2->setMaxWeight(25);
+
+ QCOMPARE(m_itemType2->maxWeight(), 25);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestItemType::setCount()
+{
+ m_itemType2->setCount(Sigmod::ItemType::Total);
+ m_itemType2->setCount(Sigmod::ItemType::Total);
+
+ QCOMPARE(m_itemType2->count(), Sigmod::ItemType::Total);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestItemType::assignment()
+{
+ *m_itemType3 = *m_itemType2;
+
+ QCOMPARE(m_itemType3->name(), QString("Foo"));
+ QCOMPARE(m_itemType3->computer(), 10);
+ QCOMPARE(m_itemType3->player(), 5);
+ QCOMPARE(m_itemType3->maxWeight(), 25);
+ QCOMPARE(m_itemType3->count(), Sigmod::ItemType::Total);
+}
+
+QTEST_APPLESS_MAIN(TestItemType)
diff --git a/sigmod/test/TestItemType.h b/sigmod/test/TestItemType.h
new file mode 100644
index 00000000..7ab0af78
--- /dev/null
+++ b/sigmod/test/TestItemType.h
@@ -0,0 +1,55 @@
+/*
+ * 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_TESTITEMTYPE
+#define SIGMOD_TESTITEMTYPE
+
+// Test includes
+#include "TestSigmodObject.h"
+
+// Sigmod includes
+#include "../ItemType.h"
+
+class TestItemType : public TestSigmodObject
+{
+ Q_OBJECT
+
+ private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void init();
+ void cleanup();
+
+ void validation();
+ void saving();
+ void loading();
+
+ void setName();
+ void setComputer();
+ void setPlayer();
+ void setMaxWeight();
+ void setCount();
+
+ void assignment();
+ private:
+ Sigmod::ItemType* m_itemType1;
+ Sigmod::ItemType* m_itemType2;
+ Sigmod::ItemType* m_itemType3;
+};
+
+#endif