diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-12-31 09:51:36 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-12-31 09:51:36 -0500 |
| commit | c58572c33f79969da366dc705ed0ea3c3fe53e03 (patch) | |
| tree | e4141700af848f5827eefce2f9118a55e465b42d | |
| parent | 76adbe9f9582934ef865337c1ffc58e9106112b6 (diff) | |
| download | sigen-c58572c33f79969da366dc705ed0ea3c3fe53e03.tar.gz sigen-c58572c33f79969da366dc705ed0ea3c3fe53e03.tar.xz sigen-c58572c33f79969da366dc705ed0ea3c3fe53e03.zip | |
Added Sprite tests
| -rw-r--r-- | sigmod/test/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | sigmod/test/TestSprite.cpp | 141 | ||||
| -rw-r--r-- | sigmod/test/TestSprite.h | 52 |
3 files changed, 194 insertions, 1 deletions
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt index 820fa59b..b16d32a9 100644 --- a/sigmod/test/CMakeLists.txt +++ b/sigmod/test/CMakeLists.txt @@ -52,7 +52,7 @@ MAKE_TEST(sigmod-tests libraries Sound) MAKE_TEST(sigmod-tests libraries SpeciesAbility) MAKE_TEST(sigmod-tests libraries SpeciesItem) MAKE_TEST(sigmod-tests libraries SpeciesMove) -# MAKE_TEST(sigmod-tests libraries Sprite) +MAKE_TEST(sigmod-tests libraries Sprite) # MAKE_TEST(sigmod-tests libraries Status) # MAKE_TEST(sigmod-tests libraries Store) # MAKE_TEST(sigmod-tests libraries Tile) diff --git a/sigmod/test/TestSprite.cpp b/sigmod/test/TestSprite.cpp new file mode 100644 index 00000000..82a96d04 --- /dev/null +++ b/sigmod/test/TestSprite.cpp @@ -0,0 +1,141 @@ +/* + * 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 "TestSprite.h" + +// Sigmod includes +#include "../Sprite.h" +#include "../Sigmod.h" + +// Qt includes +#include <QtCore/QFile> +#include <QtTest/QTest> + +void TestSprite::initTestCase() +{ + TestSigmodObject::initTestCase(); + + m_sprite1 = m_sigmod->newSprite(); + m_sprite2 = m_sigmod->newSprite(); + m_sprite3 = m_sigmod->newSprite(); +} + +void TestSprite::cleanupTestCase() +{ + TestSigmodObject::cleanupTestCase(); +} + +void TestSprite::init() +{ + TestSigmodObject::init(); + + makeConnections(m_sprite1); + makeConnections(m_sprite2); + makeConnections(m_sprite3); +} + +void TestSprite::cleanup() +{ + closeConnections(m_sprite1); + closeConnections(m_sprite2); + closeConnections(m_sprite3); + + TestSigmodObject::cleanup(); +} + +void TestSprite::validation() +{ + m_sprite1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 2); + + m_sprite1->setName("Foo"); + m_sprite1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 3); + + m_sprite1->setSprite("blah"); + m_sprite1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 3); +} + +void TestSprite::saving() +{ + QDomDocument xml = Sigmod::Object::xml(m_sprite1); + QFile file("sprite.xml"); + + QVERIFY(file.open(QIODevice::WriteOnly)); + file.write(xml.toByteArray()); + file.close(); +} + +void TestSprite::loading() +{ + QDomDocument xml; + QFile file("sprite.xml"); + + m_sprite1->setName("Bar"); + m_sprite1->setSprite("blargh"); + + QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY(xml.setContent(&file)); + m_sprite1->load(xml.firstChildElement("Sprite")); + + QCOMPARE(m_sprite1->name(), QString("Foo")); + QCOMPARE(m_sprite1->sprite(), QByteArray("blah")); +} + +void TestSprite::setName() +{ + m_sprite2->setName("Foo"); + m_sprite2->setName("Foo"); + + QCOMPARE(m_sprite2->name(), QString("Foo")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestSprite::setSprite() +{ + m_sprite2->setSprite("blah"); + m_sprite2->setSprite("blah"); + + QCOMPARE(m_sprite2->sprite(), QByteArray("blah")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestSprite::assignment() +{ + *m_sprite3 = *m_sprite2; + + QCOMPARE(m_sprite3->name(), QString("Foo")); + QCOMPARE(m_sprite3->sprite(), QByteArray("blah")); +} + +QTEST_APPLESS_MAIN(TestSprite) diff --git a/sigmod/test/TestSprite.h b/sigmod/test/TestSprite.h new file mode 100644 index 00000000..e02f4f1d --- /dev/null +++ b/sigmod/test/TestSprite.h @@ -0,0 +1,52 @@ +/* + * 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_TESTSPRITE +#define SIGMOD_TESTSPRITE + +// Test includes +#include "TestSigmodObject.h" + +// Sigmod includes +#include "../Sprite.h" + +class TestSprite : public TestSigmodObject +{ + Q_OBJECT + + private slots: + void initTestCase(); + void cleanupTestCase(); + + void init(); + void cleanup(); + + void validation(); + void saving(); + void loading(); + + void setName(); + void setSprite(); + + void assignment(); + private: + Sigmod::Sprite* m_sprite1; + Sigmod::Sprite* m_sprite2; + Sigmod::Sprite* m_sprite3; +}; + +#endif |
