summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-01-08 12:04:44 -0500
committerBen Boeckel <MathStuf@gmail.com>2009-01-08 12:04:44 -0500
commita6d45a0715bc87ca918ae9440bf8990a705f60c7 (patch)
tree3bbd755ac17e5fce8d42829ee4055275d7e82349
parent70af66ff3470c8f774d45006adbc96d3ee812c1f (diff)
Added Store tests
-rw-r--r--sigmod/test/CMakeLists.txt2
-rw-r--r--sigmod/test/TestStore.cpp178
-rw-r--r--sigmod/test/TestStore.h53
3 files changed, 232 insertions, 1 deletions
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt
index 483c1241..361658ce 100644
--- a/sigmod/test/CMakeLists.txt
+++ b/sigmod/test/CMakeLists.txt
@@ -55,7 +55,7 @@ MAKE_TEST(sigmod-tests libraries SpeciesItem)
MAKE_TEST(sigmod-tests libraries SpeciesMove)
MAKE_TEST(sigmod-tests libraries Sprite)
MAKE_TEST(sigmod-tests libraries Status)
-# MAKE_TEST(sigmod-tests libraries Store)
+MAKE_TEST(sigmod-tests libraries Store)
MAKE_TEST(sigmod-tests libraries Tile)
MAKE_TEST(sigmod-tests libraries Time)
MAKE_TEST(sigmod-tests libraries Trainer)
diff --git a/sigmod/test/TestStore.cpp b/sigmod/test/TestStore.cpp
new file mode 100644
index 00000000..8dd568e8
--- /dev/null
+++ b/sigmod/test/TestStore.cpp
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2008-2009 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 "TestStore.h"
+
+// Sigmod includes
+#include "../Sigmod.h"
+#include "../Store.h"
+
+// Qt includes
+#include <QtCore/QFile>
+#include <QtTest/QTest>
+
+void TestStore::initTestCase()
+{
+ TestSigmodObject::initTestCase();
+
+ m_store1 = m_sigmod->newStore();
+ m_store2 = m_sigmod->newStore();
+ m_store3 = m_sigmod->newStore();
+}
+
+void TestStore::cleanupTestCase()
+{
+ TestSigmodObject::cleanupTestCase();
+}
+
+void TestStore::init()
+{
+ TestSigmodObject::init();
+
+ makeConnections(m_store1);
+ makeConnections(m_store2);
+ makeConnections(m_store3);
+}
+
+void TestStore::cleanup()
+{
+ closeConnections(m_store1);
+ closeConnections(m_store2);
+ closeConnections(m_store3);
+
+ TestSigmodObject::cleanup();
+}
+
+void TestStore::validation()
+{
+ m_store1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+
+ m_store1->setName("Foo");
+ m_store1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 3);
+
+ m_sigmod->newItem();
+
+ m_store1->setItem(0, true);
+ m_store1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 3);
+}
+
+void TestStore::saving()
+{
+ QDomDocument xml = Sigmod::Object::xml(m_store1);
+ QFile file("store.xml");
+
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ file.write(xml.toByteArray());
+ file.close();
+}
+
+void TestStore::loading()
+{
+ QDomDocument xml;
+ QFile file("store.xml");
+
+ m_sigmod->newItem();
+
+ m_store1->setName("Bar");
+ m_store1->setItem(0, false);
+ m_store1->setItem(1, true);
+
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVERIFY(xml.setContent(&file));
+ m_store1->load(xml.firstChildElement("Store"));
+
+ QCOMPARE(m_store1->name(), QString("Foo"));
+ QCOMPARE(m_store1->item(0), true);
+ QCOMPARE(m_store1->item(1), false);
+}
+
+void TestStore::setName()
+{
+ m_store2->setName("Foo");
+ m_store2->setName("Foo");
+
+ QCOMPARE(m_store2->name(), QString("Foo"));
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestStore::items()
+{
+ m_sigmod->newItem();
+
+ m_store2->setItem(0, true);
+ m_store2->setItem(0, true);
+
+ QCOMPARE(m_store2->item(0), true);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+
+ m_store2->setItem(1, true);
+
+ QCOMPARE(m_store2->item(1), true);
+
+ QCOMPARE(m_changedCount, 2);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+
+ m_store2->setItem(1, false);
+
+ QCOMPARE(m_store2->item(1), false);
+
+ QCOMPARE(m_changedCount, 3);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+
+ m_store2->setItem(2, false);
+
+ QCOMPARE(m_store2->item(2), false);
+
+ QCOMPARE(m_changedCount, 3);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestStore::assignment()
+{
+ *m_store3 = *m_store2;
+
+ QCOMPARE(m_store3->name(), QString("Foo"));
+ QCOMPARE(m_store3->item(0), true);
+ QCOMPARE(m_store3->item(1), false);
+ QCOMPARE(m_store3->item(2), false);
+}
+
+QTEST_APPLESS_MAIN(TestStore)
diff --git a/sigmod/test/TestStore.h b/sigmod/test/TestStore.h
new file mode 100644
index 00000000..ca8cfcd6
--- /dev/null
+++ b/sigmod/test/TestStore.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2008-2009 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_TESTSTORE
+#define SIGMOD_TESTSTORE
+
+// Test includes
+#include "TestSigmodObject.h"
+
+// Sigmod includes
+#include "../Store.h"
+
+class TestStore : public TestSigmodObject
+{
+ Q_OBJECT
+
+ private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void init();
+ void cleanup();
+
+ void validation();
+ void saving();
+ void loading();
+
+ void setName();
+
+ void items();
+
+ void assignment();
+ private:
+ Sigmod::Store* m_store1;
+ Sigmod::Store* m_store2;
+ Sigmod::Store* m_store3;
+};
+
+#endif