diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-01-17 02:49:39 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-01-17 02:49:39 -0500 |
| commit | a4ee9e75980f498619cbfe7be91f5dc71d6f0f04 (patch) | |
| tree | 4dce6934568f40ec3321ed72a89100cd98c699f2 /sigmod/test/TestMapWarp.cpp | |
| parent | 9ed0876b668849fa3420c1aa3c29a8a672d47ea4 (diff) | |
Added MapWarp tests (with fix to toWarpCheck)
Diffstat (limited to 'sigmod/test/TestMapWarp.cpp')
| -rw-r--r-- | sigmod/test/TestMapWarp.cpp | 275 |
1 files changed, 275 insertions, 0 deletions
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) |
