summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-12-31 10:41:36 -0500
committerBen Boeckel <MathStuf@gmail.com>2008-12-31 10:41:36 -0500
commit74e5faad79f46369909cb48799ab13aa178f21d4 (patch)
treef39e95925c6ae840fd4d38e122b23da693a9fa02
parent3408195c0059d49c84ce57f440e52d9a68c555b4 (diff)
downloadsigen-74e5faad79f46369909cb48799ab13aa178f21d4.tar.gz
sigen-74e5faad79f46369909cb48799ab13aa178f21d4.tar.xz
sigen-74e5faad79f46369909cb48799ab13aa178f21d4.zip
Added MapTile tests and fixed default zIndex value
-rw-r--r--sigmod/MapTile.cpp2
-rw-r--r--sigmod/test/CMakeLists.txt2
-rw-r--r--sigmod/test/TestMapTile.cpp195
-rw-r--r--sigmod/test/TestMapTile.h53
4 files changed, 250 insertions, 2 deletions
diff --git a/sigmod/MapTile.cpp b/sigmod/MapTile.cpp
index bc978319..b06fee51 100644
--- a/sigmod/MapTile.cpp
+++ b/sigmod/MapTile.cpp
@@ -34,7 +34,7 @@ Sigmod::MapTile::MapTile(const Map* parent, const int id) :
Object(parent, id),
m_tile(-1),
m_position(0, 0),
- m_zIndex(-1)
+ m_zIndex(0)
{
}
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt
index f6912a78..e63d4a23 100644
--- a/sigmod/test/CMakeLists.txt
+++ b/sigmod/test/CMakeLists.txt
@@ -37,7 +37,7 @@ MAKE_TEST(sigmod-tests libraries Item)
MAKE_TEST(sigmod-tests libraries ItemType)
# MAKE_TEST(sigmod-tests libraries Map)
# MAKE_TEST(sigmod-tests libraries MapEffect)
-# MAKE_TEST(sigmod-tests libraries MapTile)
+MAKE_TEST(sigmod-tests libraries MapTile)
# MAKE_TEST(sigmod-tests libraries MapTrainer)
# MAKE_TEST(sigmod-tests libraries MapTrainerTeamMember)
# MAKE_TEST(sigmod-tests libraries MapWarp)
diff --git a/sigmod/test/TestMapTile.cpp b/sigmod/test/TestMapTile.cpp
new file mode 100644
index 00000000..2d0faa0d
--- /dev/null
+++ b/sigmod/test/TestMapTile.cpp
@@ -0,0 +1,195 @@
+/*
+ * 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 "TestMapTile.h"
+
+// Sigmod includes
+#include "../Map.h"
+#include "../MapTile.h"
+#include "../Sigmod.h"
+
+// Qt includes
+#include <QtCore/QFile>
+#include <QtTest/QTest>
+
+void TestMapTile::initTestCase()
+{
+ TestSigmodObject::initTestCase();
+
+ Sigmod::Map* map = m_sigmod->newMap();
+
+ m_mapTile1 = map->newTile();
+ m_mapTile2 = map->newTile();
+ m_mapTile3 = map->newTile();
+}
+
+void TestMapTile::cleanupTestCase()
+{
+ TestSigmodObject::cleanupTestCase();
+}
+
+void TestMapTile::init()
+{
+ TestSigmodObject::init();
+
+ makeConnections(m_mapTile1);
+ makeConnections(m_mapTile2);
+ makeConnections(m_mapTile3);
+}
+
+void TestMapTile::cleanup()
+{
+ closeConnections(m_mapTile1);
+ closeConnections(m_mapTile2);
+ closeConnections(m_mapTile3);
+
+ TestSigmodObject::cleanup();
+}
+
+void TestMapTile::validation()
+{
+ m_mapTile1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+
+ m_sigmod->newTile();
+
+ m_mapTile1->setTile(0);
+ m_mapTile1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 3);
+
+ m_sigmod->map(0)->setHeight(20);
+ m_sigmod->map(0)->setWidth(20);
+
+ m_mapTile1->setPosition(QPoint(10, 10));
+ m_mapTile1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 3);
+
+ m_sigmod->map(0)->setHeight(5);
+ m_sigmod->map(0)->setWidth(5);
+
+ m_mapTile1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 4);
+}
+
+void TestMapTile::saving()
+{
+ QDomDocument xml = Sigmod::Object::xml(m_mapTile1);
+ QFile file("mapTile.xml");
+
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ file.write(xml.toByteArray());
+ file.close();
+}
+
+void TestMapTile::loading()
+{
+ QDomDocument xml;
+ QFile file("mapTile.xml");
+
+ m_sigmod->newTile();
+
+ m_mapTile1->setTile(1);
+ m_mapTile1->setPosition(QPoint(2, 2));
+ m_mapTile1->setZIndex(5);
+
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVERIFY(xml.setContent(&file));
+ m_mapTile1->load(xml.firstChildElement("MapTile"));
+
+ QCOMPARE(m_mapTile1->tile(), 0);
+ QCOMPARE(m_mapTile1->position(), QPoint(10, 10));
+ QCOMPARE(m_mapTile1->zIndex(), 0);
+}
+
+void TestMapTile::setTile()
+{
+ m_mapTile2->setTile(2);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_sigmod->newTile();
+
+ m_mapTile2->setTile(2);
+ m_mapTile2->setTile(2);
+
+ QCOMPARE(m_mapTile2->tile(), 2);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestMapTile::setPosition()
+{
+ m_mapTile2->setPosition(QPoint(5, 25));
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_mapTile2->setPosition(QPoint(25, 5));
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+
+ m_sigmod->map(0)->setHeight(50);
+ m_sigmod->map(0)->setWidth(50);
+
+ m_mapTile2->setPosition(QPoint(25, 25));
+ m_mapTile2->setPosition(QPoint(25, 25));
+
+ QCOMPARE(m_mapTile2->position(), QPoint(25, 25));
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+}
+
+void TestMapTile::setZIndex()
+{
+ m_mapTile2->setZIndex(5);
+ m_mapTile2->setZIndex(5);
+
+ QCOMPARE(m_mapTile2->zIndex(), 5);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestMapTile::assignment()
+{
+ *m_mapTile3 = *m_mapTile2;
+
+ QCOMPARE(m_mapTile3->tile(), 2);
+ QCOMPARE(m_mapTile3->position(), QPoint(25, 25));
+ QCOMPARE(m_mapTile3->zIndex(), 5);
+}
+
+QTEST_APPLESS_MAIN(TestMapTile)
diff --git a/sigmod/test/TestMapTile.h b/sigmod/test/TestMapTile.h
new file mode 100644
index 00000000..fb8a5220
--- /dev/null
+++ b/sigmod/test/TestMapTile.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_TESTMAPTILE
+#define SIGMOD_TESTMAPTILE
+
+// Test includes
+#include "TestSigmodObject.h"
+
+// Sigmod includes
+#include "../MapTile.h"
+
+class TestMapTile : public TestSigmodObject
+{
+ Q_OBJECT
+
+ private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void init();
+ void cleanup();
+
+ void validation();
+ void saving();
+ void loading();
+
+ void setTile();
+ void setPosition();
+ void setZIndex();
+
+ void assignment();
+ private:
+ Sigmod::MapTile* m_mapTile1;
+ Sigmod::MapTile* m_mapTile2;
+ Sigmod::MapTile* m_mapTile3;
+};
+
+#endif