diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-01-07 13:38:32 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-01-07 13:38:32 -0500 |
| commit | bd3ad491ed0aaf16dc955fddc3850cac87ef43c2 (patch) | |
| tree | 3da334f93bd3496a10e2d226f193b49fd63cd2c4 | |
| parent | 390633dceda16bf1d2362891977b4fea43303891 (diff) | |
Added Move tests
| -rw-r--r-- | sigmod/test/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | sigmod/test/TestMove.cpp | 322 | ||||
| -rw-r--r-- | sigmod/test/TestMove.h | 61 |
3 files changed, 384 insertions, 1 deletions
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt index 8620517a..4bb278bb 100644 --- a/sigmod/test/CMakeLists.txt +++ b/sigmod/test/CMakeLists.txt @@ -42,7 +42,7 @@ MAKE_TEST(sigmod-tests libraries MapTile) # MAKE_TEST(sigmod-tests libraries MapTrainerTeamMember) # MAKE_TEST(sigmod-tests libraries MapWarp) # MAKE_TEST(sigmod-tests libraries MapWildList) -# MAKE_TEST(sigmod-tests libraries Move) +MAKE_TEST(sigmod-tests libraries Move) MAKE_TEST(sigmod-tests libraries Nature) # MAKE_TEST(sigmod-tests libraries Rules) # MAKE_TEST(sigmod-tests libraries Sigmod) diff --git a/sigmod/test/TestMove.cpp b/sigmod/test/TestMove.cpp new file mode 100644 index 00000000..5db92068 --- /dev/null +++ b/sigmod/test/TestMove.cpp @@ -0,0 +1,322 @@ +/* + * 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 "TestMove.h" + +// Sigmod includes +#include "../Move.h" +#include "../Sigmod.h" + +// Qt includes +#include <QtCore/QFile> +#include <QtTest/QTest> + +void TestMove::initTestCase() +{ + TestSigmodObject::initTestCase(); + + m_move1 = m_sigmod->newMove(); + m_move2 = m_sigmod->newMove(); + m_move3 = m_sigmod->newMove(); +} + +void TestMove::cleanupTestCase() +{ + TestSigmodObject::cleanupTestCase(); +} + +void TestMove::init() +{ + TestSigmodObject::init(); + + makeConnections(m_move1); + makeConnections(m_move2); + makeConnections(m_move3); +} + +void TestMove::cleanup() +{ + closeConnections(m_move1); + closeConnections(m_move2); + closeConnections(m_move3); + + TestSigmodObject::cleanup(); +} + +void TestMove::validation() +{ + m_move1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 3); + + m_move1->setName("Foo"); + m_move1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 5); + + m_sigmod->newType(); + + m_move1->setType(0); + m_move1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 6); + + m_move1->setPowerPoints(25); + m_move1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 6); +} + +void TestMove::saving() +{ + QDomDocument xml = Sigmod::Object::xml(m_move1); + QFile file("move.xml"); + + QVERIFY(file.open(QIODevice::WriteOnly)); + file.write(xml.toByteArray()); + file.close(); +} + +void TestMove::loading() +{ + QDomDocument xml; + QFile file("move.xml"); + + m_sigmod->newType(); + + m_move1->setName("Bar"); + m_move1->setAccuracy(Sigcore::Fraction(1, 2)); + m_move1->setPower(10); + m_move1->setType(1); + m_move1->setSpecial(true); + m_move1->setPowerPoints(50); + m_move1->setPriority(1); + m_move1->setDescription("blah"); + m_move1->setBattleScript(Sigcore::Script("python", "import os")); + m_move1->setWorldScript(Sigcore::Script("python", "import os")); + m_move1->setPriorityScript(Sigcore::Script("python", "import os")); + + QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY(xml.setContent(&file)); + m_move1->load(xml.firstChildElement("Move")); + + QCOMPARE(m_move1->name(), QString("Foo")); + QCOMPARE(m_move1->accuracy(), Sigcore::Fraction(1, 1)); + QCOMPARE(m_move1->power(), 0); + QCOMPARE(m_move1->type(), 0); + QCOMPARE(m_move1->special(), false); + QCOMPARE(m_move1->powerPoints(), 25); + QCOMPARE(m_move1->priority(), 0); + QCOMPARE(m_move1->description(), QString("")); + QCOMPARE(m_move1->battleScript(), Sigcore::Script("", "")); + QCOMPARE(m_move1->worldScript(), Sigcore::Script("", "")); + QCOMPARE(m_move1->priorityScript(), Sigcore::Script("", "")); +} + +void TestMove::setName() +{ + m_move2->setName("Foo"); + m_move2->setName("Foo"); + + QCOMPARE(m_move2->name(), QString("Foo")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestMove::setAccuracy() +{ + m_move2->setAccuracy(Sigcore::Fraction(3, 2)); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); + + m_move2->setAccuracy(Sigcore::Fraction(-1, 2)); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 2); + + m_move2->setAccuracy(Sigcore::Fraction(1, 2)); + m_move2->setAccuracy(Sigcore::Fraction(1, 2)); + + QCOMPARE(m_move2->accuracy(), Sigcore::Fraction(1, 2)); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 2); +} + +void TestMove::setPower() +{ + m_move2->setPower(-1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); + + m_move2->setPower(10); + m_move2->setPower(10); + + QCOMPARE(m_move2->power(), 10); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); +} + +void TestMove::setType() +{ + m_move2->setType(2); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); + + m_sigmod->newType(); + + m_move2->setType(2); + m_move2->setType(2); + + QCOMPARE(m_move2->type(), 2); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); +} + +void TestMove::setSpecial() +{ + m_move2->setSpecial(true); + m_move2->setSpecial(true); + + QCOMPARE(m_move2->special(), true); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestMove::setPowerPoints() +{ + m_move2->setPowerPoints(0); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); + + m_move2->setPowerPoints(10); + m_move2->setPowerPoints(10); + + QCOMPARE(m_move2->powerPoints(), 10); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); +} + +void TestMove::setPriority() +{ + m_move2->setPriority(25); + m_move2->setPriority(25); + + QCOMPARE(m_move2->priority(), 25); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestMove::setDescription() +{ + m_move2->setDescription("blah"); + m_move2->setDescription("blah"); + + QCOMPARE(m_move2->description(), QString("blah")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestMove::setBattleScript() +{ + m_move2->setBattleScript(Sigcore::Script("python", "import os")); + m_move2->setBattleScript(Sigcore::Script("python", "import os")); + + QCOMPARE(m_move2->battleScript(), Sigcore::Script("python", "import os")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestMove::setWorldScript() +{ + m_move2->setWorldScript(Sigcore::Script("python", "import os")); + m_move2->setWorldScript(Sigcore::Script("python", "import os")); + + QCOMPARE(m_move2->worldScript(), Sigcore::Script("python", "import os")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestMove::setPriorityScript() +{ + m_move2->setPriorityScript(Sigcore::Script("python", "import os")); + m_move2->setPriorityScript(Sigcore::Script("python", "import os")); + + QCOMPARE(m_move2->priorityScript(), Sigcore::Script("python", "import os")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestMove::assignment() +{ + *m_move3 = *m_move2; + + QCOMPARE(m_move3->name(), QString("Foo")); + QCOMPARE(m_move3->accuracy(), Sigcore::Fraction(1, 2)); + QCOMPARE(m_move3->power(), 10); + QCOMPARE(m_move3->type(), 2); + QCOMPARE(m_move3->special(), true); + QCOMPARE(m_move3->powerPoints(), 10); + QCOMPARE(m_move3->priority(), 25); + QCOMPARE(m_move3->description(), QString("blah")); + QCOMPARE(m_move3->battleScript(), Sigcore::Script("python", "import os")); + QCOMPARE(m_move3->worldScript(), Sigcore::Script("python", "import os")); + QCOMPARE(m_move3->priorityScript(), Sigcore::Script("python", "import os")); +} + +QTEST_APPLESS_MAIN(TestMove) diff --git a/sigmod/test/TestMove.h b/sigmod/test/TestMove.h new file mode 100644 index 00000000..3adb4fd1 --- /dev/null +++ b/sigmod/test/TestMove.h @@ -0,0 +1,61 @@ +/* + * 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_TESTMOVE +#define SIGMOD_TESTMOVE + +// Test includes +#include "TestSigmodObject.h" + +// Sigmod includes +#include "../Move.h" + +class TestMove : public TestSigmodObject +{ + Q_OBJECT + + private slots: + void initTestCase(); + void cleanupTestCase(); + + void init(); + void cleanup(); + + void validation(); + void saving(); + void loading(); + + void setName(); + void setAccuracy(); + void setPower(); + void setType(); + void setSpecial(); + void setPowerPoints(); + void setPriority(); + void setDescription(); + void setBattleScript(); + void setWorldScript(); + void setPriorityScript(); + + void assignment(); + private: + Sigmod::Move* m_move1; + Sigmod::Move* m_move2; + Sigmod::Move* m_move3; +}; + +#endif |
