summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-12-31 10:10:06 -0500
committerBen Boeckel <MathStuf@gmail.com>2008-12-31 10:10:06 -0500
commit965b82938ba85a029bcbda48d2fd4c1762596801 (patch)
tree3b3639be9b36112b3f3a43089ed5a30d3b551aa0
parent660eeb9a088e435176425f125a10a6b261763fa1 (diff)
downloadsigen-965b82938ba85a029bcbda48d2fd4c1762596801.tar.gz
sigen-965b82938ba85a029bcbda48d2fd4c1762596801.tar.xz
sigen-965b82938ba85a029bcbda48d2fd4c1762596801.zip
Added Time tests
-rw-r--r--sigmod/test/CMakeLists.txt2
-rw-r--r--sigmod/test/TestTime.cpp171
-rw-r--r--sigmod/test/TestTime.h53
3 files changed, 225 insertions, 1 deletions
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt
index 1b5af526..84ffe453 100644
--- a/sigmod/test/CMakeLists.txt
+++ b/sigmod/test/CMakeLists.txt
@@ -56,7 +56,7 @@ MAKE_TEST(sigmod-tests libraries Sprite)
MAKE_TEST(sigmod-tests libraries Status)
# MAKE_TEST(sigmod-tests libraries Store)
# MAKE_TEST(sigmod-tests libraries Tile)
-# MAKE_TEST(sigmod-tests libraries Time)
+MAKE_TEST(sigmod-tests libraries Time)
# MAKE_TEST(sigmod-tests libraries Trainer)
MAKE_TEST(sigmod-tests libraries Type)
MAKE_TEST(sigmod-tests libraries Weather)
diff --git a/sigmod/test/TestTime.cpp b/sigmod/test/TestTime.cpp
new file mode 100644
index 00000000..0cc0f9df
--- /dev/null
+++ b/sigmod/test/TestTime.cpp
@@ -0,0 +1,171 @@
+/*
+ * 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 "TestTime.h"
+
+// Sigmod includes
+#include "../Time.h"
+#include "../Sigmod.h"
+
+// Qt includes
+#include <QtCore/QFile>
+#include <QtTest/QTest>
+
+void TestTime::initTestCase()
+{
+ TestSigmodObject::initTestCase();
+
+ m_time1 = m_sigmod->newTime();
+ m_time2 = m_sigmod->newTime();
+ m_time3 = m_sigmod->newTime();
+}
+
+void TestTime::cleanupTestCase()
+{
+ TestSigmodObject::cleanupTestCase();
+}
+
+void TestTime::init()
+{
+ TestSigmodObject::init();
+
+ makeConnections(m_time1);
+ makeConnections(m_time2);
+ makeConnections(m_time3);
+}
+
+void TestTime::cleanup()
+{
+ closeConnections(m_time1);
+ closeConnections(m_time2);
+ closeConnections(m_time3);
+
+ TestSigmodObject::cleanup();
+}
+
+void TestTime::validation()
+{
+ m_time1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_time1->setName("Foo");
+ m_time1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestTime::saving()
+{
+ QDomDocument xml = Sigmod::Object::xml(m_time1);
+ QFile file("time.xml");
+
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ file.write(xml.toByteArray());
+ file.close();
+}
+
+void TestTime::loading()
+{
+ QDomDocument xml;
+ QFile file("time.xml");
+
+ m_time1->setName("Bar");
+ m_time1->setHour(12);
+ m_time1->setMinute(30);
+
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVERIFY(xml.setContent(&file));
+ m_time1->load(xml.firstChildElement("Time"));
+
+ QCOMPARE(m_time1->name(), QString("Foo"));
+ QCOMPARE(m_time1->hour(), 0);
+ QCOMPARE(m_time1->minute(), 0);
+}
+
+void TestTime::setName()
+{
+ m_time2->setName("Foo");
+ m_time2->setName("Foo");
+
+ QCOMPARE(m_time2->name(), QString("Foo"));
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestTime::setHour()
+{
+ m_time2->setHour(-1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_time2->setHour(24);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+
+ m_time2->setHour(12);
+ m_time2->setHour(12);
+
+ QCOMPARE(m_time2->hour(), 12);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+}
+
+void TestTime::setMinute()
+{
+ m_time2->setMinute(-1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_time2->setMinute(60);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+
+ m_time2->setMinute(30);
+ m_time2->setMinute(30);
+
+ QCOMPARE(m_time2->minute(), 30);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+}
+
+void TestTime::assignment()
+{
+ *m_time3 = *m_time2;
+
+ QCOMPARE(m_time3->name(), QString("Foo"));
+ QCOMPARE(m_time3->hour(), 12);
+ QCOMPARE(m_time3->minute(), 30);
+}
+
+QTEST_APPLESS_MAIN(TestTime)
diff --git a/sigmod/test/TestTime.h b/sigmod/test/TestTime.h
new file mode 100644
index 00000000..8cde0fdf
--- /dev/null
+++ b/sigmod/test/TestTime.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_TESTTIME
+#define SIGMOD_TESTTIME
+
+// Test includes
+#include "TestSigmodObject.h"
+
+// Sigmod includes
+#include "../Time.h"
+
+class TestTime : public TestSigmodObject
+{
+ Q_OBJECT
+
+ private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void init();
+ void cleanup();
+
+ void validation();
+ void saving();
+ void loading();
+
+ void setName();
+ void setHour();
+ void setMinute();
+
+ void assignment();
+ private:
+ Sigmod::Time* m_time1;
+ Sigmod::Time* m_time2;
+ Sigmod::Time* m_time3;
+};
+
+#endif