From 79f5886518a75f54bb9612e513a1782745b4e5a0 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 31 Dec 2008 09:57:40 -0500 Subject: Added Status tests --- sigmod/test/TestStatus.cpp | 153 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 sigmod/test/TestStatus.cpp (limited to 'sigmod/test/TestStatus.cpp') diff --git a/sigmod/test/TestStatus.cpp b/sigmod/test/TestStatus.cpp new file mode 100644 index 00000000..8ad3cb64 --- /dev/null +++ b/sigmod/test/TestStatus.cpp @@ -0,0 +1,153 @@ +/* + * Copyright 2008 Ben Boeckel + * + * 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 . + */ + +// Header include +#include "TestStatus.h" + +// Sigmod includes +#include "../Sigmod.h" +#include "../Status.h" + +// Qt includes +#include +#include + +#include + +void TestStatus::initTestCase() +{ + TestSigmodObject::initTestCase(); + + m_status1 = m_sigmod->newStatus(); + m_status2 = m_sigmod->newStatus(); + m_status3 = m_sigmod->newStatus(); +} + +void TestStatus::cleanupTestCase() +{ + TestSigmodObject::cleanupTestCase(); +} + +void TestStatus::init() +{ + TestSigmodObject::init(); + + makeConnections(m_status1); + makeConnections(m_status2); + makeConnections(m_status3); +} + +void TestStatus::cleanup() +{ + closeConnections(m_status1); + closeConnections(m_status2); + closeConnections(m_status3); + + TestSigmodObject::cleanup(); +} + +void TestStatus::validation() +{ + m_status1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); + + m_status1->setName("Foo"); + m_status1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 1); +} + +void TestStatus::saving() +{ + QDomDocument xml = Sigmod::Object::xml(m_status1); + QFile file("status.xml"); + + QVERIFY(file.open(QIODevice::WriteOnly)); + file.write(xml.toByteArray()); + file.close(); +} + +void TestStatus::loading() +{ + QDomDocument xml; + QFile file("status.xml"); + + m_status1->setName("Bar"); + m_status1->setBattleScript(Sigcore::Script("python", "import os")); + m_status1->setWorldScript(Sigcore::Script("python", "import os")); + + QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY(xml.setContent(&file)); + m_status1->load(xml.firstChildElement("Status")); + + QCOMPARE(m_status1->name(), QString("Foo")); + QCOMPARE(m_status1->battleScript(), Sigcore::Script()); + QCOMPARE(m_status1->worldScript(), Sigcore::Script()); +} + +void TestStatus::setName() +{ + m_status2->setName("Foo"); + m_status2->setName("Foo"); + + QCOMPARE(m_status2->name(), QString("Foo")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestStatus::setBattleScript() +{ + m_status2->setBattleScript(Sigcore::Script("python", "import os")); + m_status2->setBattleScript(Sigcore::Script("python", "import os")); + + QCOMPARE(m_status2->battleScript(), Sigcore::Script("python", "import os")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestStatus::setWorldScript() +{ + m_status2->setWorldScript(Sigcore::Script("python", "import os")); + m_status2->setWorldScript(Sigcore::Script("python", "import os")); + + QCOMPARE(m_status2->worldScript(), Sigcore::Script("python", "import os")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestStatus::assignment() +{ + *m_status3 = *m_status2; + + QCOMPARE(m_status3->name(), QString("Foo")); + QCOMPARE(m_status3->battleScript(), Sigcore::Script("python", "import os")); + QCOMPARE(m_status3->worldScript(), Sigcore::Script("python", "import os")); +} + +QTEST_APPLESS_MAIN(TestStatus) -- cgit