summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-12-31 09:57:40 -0500
committerBen Boeckel <MathStuf@gmail.com>2008-12-31 09:57:40 -0500
commit79f5886518a75f54bb9612e513a1782745b4e5a0 (patch)
tree1cca47201eca2e656ad01b44ce66c3fa1ce670ad
parentc58572c33f79969da366dc705ed0ea3c3fe53e03 (diff)
Added Status tests
-rw-r--r--sigmod/test/CMakeLists.txt2
-rw-r--r--sigmod/test/TestStatus.cpp153
-rw-r--r--sigmod/test/TestStatus.h53
3 files changed, 207 insertions, 1 deletions
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt
index b16d32a9..feb4eb3c 100644
--- a/sigmod/test/CMakeLists.txt
+++ b/sigmod/test/CMakeLists.txt
@@ -53,7 +53,7 @@ MAKE_TEST(sigmod-tests libraries SpeciesAbility)
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 Status)
# MAKE_TEST(sigmod-tests libraries Store)
# MAKE_TEST(sigmod-tests libraries Tile)
# MAKE_TEST(sigmod-tests libraries Time)
diff --git a/sigmod/test/TestStatus.cpp b/sigmod/test/TestStatus.cpp
new file mode 100644
index 00000000..8ad3cb64
--- /dev/null
+++ b/sigmod/test/TestStatus.cpp
@@ -0,0 +1,153 @@
+/*
+ * 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 "TestStatus.h"
+
+// Sigmod includes
+#include "../Sigmod.h"
+#include "../Status.h"
+
+// Qt includes
+#include <QtCore/QFile>
+#include <QtTest/QTest>
+
+#include <QtCore/QtDebug>
+
+void TestStatus::initTestCase()
+{
+ TestSigmodObject::initTestCase();
+
+ m_status1 = m_sigmod->newStatus();
+ m_status2 = m_sigmod->newStatus();
+ m_status3 = m_sigmod->newStatus();
+}
+
+void TestStatus::cleanupTestCase()
+{
+ TestSigmodObject::cleanupTestCase();
+}
+
+void TestStatus::init()
+{
+ TestSigmodObject::init();
+
+ makeConnections(m_status1);
+ makeConnections(m_status2);
+ makeConnections(m_status3);
+}
+
+void TestStatus::cleanup()
+{
+ closeConnections(m_status1);
+ closeConnections(m_status2);
+ closeConnections(m_status3);
+
+ TestSigmodObject::cleanup();
+}
+
+void TestStatus::validation()
+{
+ m_status1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_status1->setName("Foo");
+ m_status1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestStatus::saving()
+{
+ QDomDocument xml = Sigmod::Object::xml(m_status1);
+ QFile file("status.xml");
+
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ file.write(xml.toByteArray());
+ file.close();
+}
+
+void TestStatus::loading()
+{
+ QDomDocument xml;
+ QFile file("status.xml");
+
+ m_status1->setName("Bar");
+ m_status1->setBattleScript(Sigcore::Script("python", "import os"));
+ m_status1->setWorldScript(Sigcore::Script("python", "import os"));
+
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVERIFY(xml.setContent(&file));
+ m_status1->load(xml.firstChildElement("Status"));
+
+ QCOMPARE(m_status1->name(), QString("Foo"));
+ QCOMPARE(m_status1->battleScript(), Sigcore::Script());
+ QCOMPARE(m_status1->worldScript(), Sigcore::Script());
+}
+
+void TestStatus::setName()
+{
+ m_status2->setName("Foo");
+ m_status2->setName("Foo");
+
+ QCOMPARE(m_status2->name(), QString("Foo"));
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestStatus::setBattleScript()
+{
+ m_status2->setBattleScript(Sigcore::Script("python", "import os"));
+ m_status2->setBattleScript(Sigcore::Script("python", "import os"));
+
+ QCOMPARE(m_status2->battleScript(), Sigcore::Script("python", "import os"));
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestStatus::setWorldScript()
+{
+ m_status2->setWorldScript(Sigcore::Script("python", "import os"));
+ m_status2->setWorldScript(Sigcore::Script("python", "import os"));
+
+ QCOMPARE(m_status2->worldScript(), Sigcore::Script("python", "import os"));
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestStatus::assignment()
+{
+ *m_status3 = *m_status2;
+
+ QCOMPARE(m_status3->name(), QString("Foo"));
+ QCOMPARE(m_status3->battleScript(), Sigcore::Script("python", "import os"));
+ QCOMPARE(m_status3->worldScript(), Sigcore::Script("python", "import os"));
+}
+
+QTEST_APPLESS_MAIN(TestStatus)
diff --git a/sigmod/test/TestStatus.h b/sigmod/test/TestStatus.h
new file mode 100644
index 00000000..d8f09083
--- /dev/null
+++ b/sigmod/test/TestStatus.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_TESTSTATUS
+#define SIGMOD_TESTSTATUS
+
+// Test includes
+#include "TestSigmodObject.h"
+
+// Sigmod includes
+#include "../Status.h"
+
+class TestStatus : public TestSigmodObject
+{
+ Q_OBJECT
+
+ private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void init();
+ void cleanup();
+
+ void validation();
+ void saving();
+ void loading();
+
+ void setName();
+ void setBattleScript();
+ void setWorldScript();
+
+ void assignment();
+ private:
+ Sigmod::Status* m_status1;
+ Sigmod::Status* m_status2;
+ Sigmod::Status* m_status3;
+};
+
+#endif