diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-12-30 12:33:29 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-12-30 12:33:29 -0500 |
| commit | 06387e2d3c6e4396560dfa7d6fe86d4854089858 (patch) | |
| tree | 677498c952a0d7439121a2da83d4ca4e933920e9 /sigmod/test/TestSound.cpp | |
| parent | 7991608b315c7fe26cc42df37a9dc05378232ba0 (diff) | |
Added tests for Sound
Diffstat (limited to 'sigmod/test/TestSound.cpp')
| -rw-r--r-- | sigmod/test/TestSound.cpp | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/sigmod/test/TestSound.cpp b/sigmod/test/TestSound.cpp new file mode 100644 index 00000000..4e12f5a6 --- /dev/null +++ b/sigmod/test/TestSound.cpp @@ -0,0 +1,161 @@ +/* + * 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 "TestSound.h" + +// Sigmod includes +#include "../Sound.h" +#include "../Sigmod.h" + +// Qt includes +#include <QtCore/QFile> +#include <QtTest/QTest> + +void TestSound::initTestCase() +{ + TestSigmodObject::initTestCase(); + + m_sound1 = m_sigmod->newSound(); + m_sound2 = m_sigmod->newSound(); + m_sound3 = m_sigmod->newSound(); + + m_sound1->setType(Sigmod::Sound::Music); +} + +void TestSound::cleanupTestCase() +{ + TestSigmodObject::cleanupTestCase(); +} + +void TestSound::init() +{ + TestSigmodObject::init(); + + makeConnections(m_sound1); + makeConnections(m_sound2); + makeConnections(m_sound3); +} + +void TestSound::cleanup() +{ + closeConnections(m_sound1); + closeConnections(m_sound2); + closeConnections(m_sound3); + + TestSigmodObject::cleanup(); +} + +void TestSound::validation() +{ + m_sound1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 2); + + m_sound1->setName("Foo"); + m_sound1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 3); + + m_sound1->setData("blah"); + m_sound1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 3); +} + +void TestSound::saving() +{ + QDomDocument xml = Sigmod::Object::xml(m_sound1); + QFile file("sound.xml"); + + QVERIFY(file.open(QIODevice::WriteOnly)); + file.write(xml.toByteArray()); + file.close(); +} + +void TestSound::loading() +{ + QDomDocument xml; + QFile file("sound.xml"); + + m_sound1->setName("Bar"); + m_sound1->setType(Sigmod::Sound::SoundEffect); + m_sound1->setData("blargh"); + + QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY(xml.setContent(&file)); + m_sound1->load(xml.firstChildElement("Sound")); + + QCOMPARE(m_sound1->name(), QString("Foo")); + // FIXME + QEXPECT_FAIL(0, "Loading enumeration data from XML file doesn't work", Continue); + QCOMPARE(m_sound1->type(), Sigmod::Sound::Music); + QCOMPARE(m_sound1->data(), QByteArray("blah")); +} + +void TestSound::setName() +{ + m_sound2->setName("Foo"); + m_sound2->setName("Foo"); + + QCOMPARE(m_sound2->name(), QString("Foo")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestSound::setType() +{ + m_sound2->setType(Sigmod::Sound::Music); + m_sound2->setType(Sigmod::Sound::Music); + + QCOMPARE(m_sound2->type(), Sigmod::Sound::Music); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestSound::setData() +{ + m_sound2->setData("blah"); + m_sound2->setData("blah"); + + QCOMPARE(m_sound2->data(), QByteArray("blah")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestSound::assignment() +{ + *m_sound3 = *m_sound2; + + QCOMPARE(m_sound3->name(), QString("Foo")); + QCOMPARE(m_sound3->type(), Sigmod::Sound::Music); + QCOMPARE(m_sound3->data(), QByteArray("blah")); +} + +QTEST_APPLESS_MAIN(TestSound) |
