summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-01-17 02:49:39 -0500
committerBen Boeckel <MathStuf@gmail.com>2009-01-17 02:49:39 -0500
commita4ee9e75980f498619cbfe7be91f5dc71d6f0f04 (patch)
tree4dce6934568f40ec3321ed72a89100cd98c699f2
parent9ed0876b668849fa3420c1aa3c29a8a672d47ea4 (diff)
Added MapWarp tests (with fix to toWarpCheck)
-rw-r--r--sigmod/MapWarp.cpp5
-rw-r--r--sigmod/test/CMakeLists.txt2
-rw-r--r--sigmod/test/TestMapWarp.cpp275
-rw-r--r--sigmod/test/TestMapWarp.h56
4 files changed, 336 insertions, 2 deletions
diff --git a/sigmod/MapWarp.cpp b/sigmod/MapWarp.cpp
index ba0276dd..c8a67702 100644
--- a/sigmod/MapWarp.cpp
+++ b/sigmod/MapWarp.cpp
@@ -114,9 +114,12 @@ CHECK_END()
CHECK(MapWarp, Type, type)
CHECK_INDEX(MapWarp, int, toMap, sigmod(), map)
CHECK_BEGIN(MapWarp, int, toWarp)
- const Map* map = qobject_cast<const Map*>(parent());
+ const Map* map = sigmod()->mapById(m_toMap);
if (!map)
+ {
EBOUNDS_IDX(m_toMap);
+ return false;
+ }
IBOUNDS(toWarp, map, warp);
CHECK_END()
CHECK(MapWarp, Sigcore::Script&, script)
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt
index 974f3b74..bd12b690 100644
--- a/sigmod/test/CMakeLists.txt
+++ b/sigmod/test/CMakeLists.txt
@@ -40,7 +40,7 @@ MAKE_TEST(sigmod-tests libraries MapEffect)
MAKE_TEST(sigmod-tests libraries MapTile)
MAKE_TEST(sigmod-tests libraries MapTrainer)
MAKE_TEST(sigmod-tests libraries MapTrainerTeamMember)
-# MAKE_TEST(sigmod-tests libraries MapWarp)
+MAKE_TEST(sigmod-tests libraries MapWarp)
MAKE_TEST(sigmod-tests libraries MapWildList)
MAKE_TEST(sigmod-tests libraries MapWildListEncounter)
MAKE_TEST(sigmod-tests libraries Move)
diff --git a/sigmod/test/TestMapWarp.cpp b/sigmod/test/TestMapWarp.cpp
new file mode 100644
index 00000000..4aac1443
--- /dev/null
+++ b/sigmod/test/TestMapWarp.cpp
@@ -0,0 +1,275 @@
+/*
+ * 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 "TestMapWarp.h"
+
+// Sigmod includes
+#include "../Map.h"
+#include "../MapWarp.h"
+#include "../Sigmod.h"
+
+// Qt includes
+#include <QtCore/QFile>
+#include <QtTest/QTest>
+
+void TestMapWarp::initTestCase()
+{
+ TestSigmodObject::initTestCase();
+
+ Sigmod::Map* map = m_sigmod->newMap();
+
+ m_warp1 = map->newWarp();
+ m_warp2 = map->newWarp();
+ m_warp3 = map->newWarp();
+}
+
+void TestMapWarp::cleanupTestCase()
+{
+ TestSigmodObject::cleanupTestCase();
+}
+
+void TestMapWarp::init()
+{
+ TestSigmodObject::init();
+
+ makeConnections(m_warp1);
+ makeConnections(m_warp2);
+ makeConnections(m_warp3);
+}
+
+void TestMapWarp::cleanup()
+{
+ closeConnections(m_warp1);
+ closeConnections(m_warp2);
+ closeConnections(m_warp3);
+
+ TestSigmodObject::cleanup();
+}
+
+void TestMapWarp::validation()
+{
+ m_warp1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 4);
+
+ m_warp1->setName("Foo");
+ m_warp1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 7);
+
+ m_sigmod->map(0)->setWidth(20);
+ m_sigmod->map(0)->setHeight(20);
+
+ m_warp1->setArea(QRect(0, 0, 5, 5));
+ m_warp1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 9);
+
+ m_sigmod->map(0)->setWidth(3);
+ m_sigmod->map(0)->setHeight(3);
+
+ m_warp1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 12);
+
+ m_sigmod->map(0)->setWidth(20);
+ m_sigmod->map(0)->setHeight(20);
+
+ m_warp1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 14);
+
+ m_warp1->setToMap(0);
+ m_warp1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 15);
+
+ m_warp1->setToWarp(2);
+ m_warp1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 15);
+}
+
+void TestMapWarp::saving()
+{
+ QDomDocument xml = Sigmod::Object::xml(m_warp1);
+ QFile file("mapWarp.xml");
+
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ file.write(xml.toByteArray());
+ file.close();
+}
+
+void TestMapWarp::loading()
+{
+ QDomDocument xml;
+ QFile file("mapWarp.xml");
+
+ m_sigmod->newMap()->newWarp();
+
+ m_warp1->setName("Bar");
+ m_warp1->setArea(QRect(1, 1, 3, 3));
+ m_warp1->setType(Sigmod::MapWarp::Warp);
+ m_warp1->setToMap(1);
+ m_warp1->setToWarp(0);
+ m_warp1->setScript(Sigcore::Script("python", "import os"));
+
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVERIFY(xml.setContent(&file));
+ m_warp1->load(xml.firstChildElement("MapWarp"));
+
+ QCOMPARE(m_warp1->name(), QString("Foo"));
+ QCOMPARE(m_warp1->area(), QRect(0, 0, 5, 5));
+ QCOMPARE(m_warp1->type(), Sigmod::MapWarp::Door);
+ QCOMPARE(m_warp1->toMap(), 0);
+ QCOMPARE(m_warp1->toWarp(), 2);
+ QCOMPARE(m_warp1->script(), Sigcore::Script());
+}
+
+void TestMapWarp::setName()
+{
+ m_warp2->setName("Foo");
+ m_warp2->setName("Foo");
+
+ QCOMPARE(m_warp2->name(), QString("Foo"));
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestMapWarp::setArea()
+{
+ m_warp2->setArea(QRect(-1, 0, 5, 5));
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_warp2->setArea(QRect(0, -1, 5, 5));
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 2);
+
+ m_warp2->setArea(QRect(0, 0, 25, 5));
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 3);
+
+ m_warp2->setArea(QRect(0, 0, 5, 25));
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 4);
+
+ m_warp2->setArea(QRect(0, 0, 5, 5));
+ m_warp2->setArea(QRect(0, 0, 5, 5));
+
+ QCOMPARE(m_warp2->area(), QRect(0, 0, 5, 5));
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 4);
+}
+
+void TestMapWarp::setType()
+{
+ m_warp2->setType(Sigmod::MapWarp::Warp);
+ m_warp2->setType(Sigmod::MapWarp::Warp);
+
+ QCOMPARE(m_warp2->type(), Sigmod::MapWarp::Warp);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestMapWarp::setToMap()
+{
+ m_warp2->setToMap(2);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_sigmod->newMap();
+
+ m_warp2->setToMap(2);
+ m_warp2->setToMap(2);
+
+ QCOMPARE(m_warp2->toMap(), 2);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestMapWarp::setToWarp()
+{
+ m_warp2->setToWarp(0);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_sigmod->map(2)->newWarp();
+
+ m_warp2->setToWarp(0);
+ m_warp2->setToWarp(0);
+
+ QCOMPARE(m_warp2->toWarp(), 0);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestMapWarp::setScript()
+{
+ m_warp2->setScript(Sigcore::Script("python", "import os"));
+ m_warp2->setScript(Sigcore::Script("python", "import os"));
+
+ QCOMPARE(m_warp2->script(), Sigcore::Script("python", "import os"));
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 0);
+}
+
+void TestMapWarp::assignment()
+{
+ *m_warp3 = *m_warp2;
+
+ QCOMPARE(m_warp3->name(), QString("Foo"));
+ QCOMPARE(m_warp3->area(), QRect(0, 0, 5, 5));
+ QCOMPARE(m_warp3->type(), Sigmod::MapWarp::Warp);
+ QCOMPARE(m_warp3->toMap(), 2);
+ QCOMPARE(m_warp3->toWarp(), 0);
+ QCOMPARE(m_warp3->script(), Sigcore::Script("python", "import os"));
+}
+
+QTEST_APPLESS_MAIN(TestMapWarp)
diff --git a/sigmod/test/TestMapWarp.h b/sigmod/test/TestMapWarp.h
new file mode 100644
index 00000000..6606ddc0
--- /dev/null
+++ b/sigmod/test/TestMapWarp.h
@@ -0,0 +1,56 @@
+/*
+ * 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_TESTMAPWARP
+#define SIGMOD_TESTMAPWARP
+
+// Test includes
+#include "TestSigmodObject.h"
+
+// Sigmod includes
+#include "../MapWarp.h"
+
+class TestMapWarp : public TestSigmodObject
+{
+ Q_OBJECT
+
+ private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void init();
+ void cleanup();
+
+ void validation();
+ void saving();
+ void loading();
+
+ void setName();
+ void setArea();
+ void setType();
+ void setToMap();
+ void setToWarp();
+ void setScript();
+
+ void assignment();
+ private:
+ Sigmod::MapWarp* m_warp1;
+ Sigmod::MapWarp* m_warp2;
+ Sigmod::MapWarp* m_warp3;
+};
+
+#endif