From a6d45a0715bc87ca918ae9440bf8990a705f60c7 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 8 Jan 2009 12:04:44 -0500 Subject: Added Store tests --- sigmod/test/TestStore.cpp | 178 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 sigmod/test/TestStore.cpp (limited to 'sigmod/test/TestStore.cpp') diff --git a/sigmod/test/TestStore.cpp b/sigmod/test/TestStore.cpp new file mode 100644 index 00000000..8dd568e8 --- /dev/null +++ b/sigmod/test/TestStore.cpp @@ -0,0 +1,178 @@ +/* + * Copyright 2008-2009 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 "TestStore.h" + +// Sigmod includes +#include "../Sigmod.h" +#include "../Store.h" + +// Qt includes +#include +#include + +void TestStore::initTestCase() +{ + TestSigmodObject::initTestCase(); + + m_store1 = m_sigmod->newStore(); + m_store2 = m_sigmod->newStore(); + m_store3 = m_sigmod->newStore(); +} + +void TestStore::cleanupTestCase() +{ + TestSigmodObject::cleanupTestCase(); +} + +void TestStore::init() +{ + TestSigmodObject::init(); + + makeConnections(m_store1); + makeConnections(m_store2); + makeConnections(m_store3); +} + +void TestStore::cleanup() +{ + closeConnections(m_store1); + closeConnections(m_store2); + closeConnections(m_store3); + + TestSigmodObject::cleanup(); +} + +void TestStore::validation() +{ + m_store1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 2); + + m_store1->setName("Foo"); + m_store1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 3); + + m_sigmod->newItem(); + + m_store1->setItem(0, true); + m_store1->validate(); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 3); +} + +void TestStore::saving() +{ + QDomDocument xml = Sigmod::Object::xml(m_store1); + QFile file("store.xml"); + + QVERIFY(file.open(QIODevice::WriteOnly)); + file.write(xml.toByteArray()); + file.close(); +} + +void TestStore::loading() +{ + QDomDocument xml; + QFile file("store.xml"); + + m_sigmod->newItem(); + + m_store1->setName("Bar"); + m_store1->setItem(0, false); + m_store1->setItem(1, true); + + QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY(xml.setContent(&file)); + m_store1->load(xml.firstChildElement("Store")); + + QCOMPARE(m_store1->name(), QString("Foo")); + QCOMPARE(m_store1->item(0), true); + QCOMPARE(m_store1->item(1), false); +} + +void TestStore::setName() +{ + m_store2->setName("Foo"); + m_store2->setName("Foo"); + + QCOMPARE(m_store2->name(), QString("Foo")); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestStore::items() +{ + m_sigmod->newItem(); + + m_store2->setItem(0, true); + m_store2->setItem(0, true); + + QCOMPARE(m_store2->item(0), true); + + QCOMPARE(m_changedCount, 1); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); + + m_store2->setItem(1, true); + + QCOMPARE(m_store2->item(1), true); + + QCOMPARE(m_changedCount, 2); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); + + m_store2->setItem(1, false); + + QCOMPARE(m_store2->item(1), false); + + QCOMPARE(m_changedCount, 3); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); + + m_store2->setItem(2, false); + + QCOMPARE(m_store2->item(2), false); + + QCOMPARE(m_changedCount, 3); + + QCOMPARE(m_warnings.size(), 0); + QCOMPARE(m_errors.size(), 0); +} + +void TestStore::assignment() +{ + *m_store3 = *m_store2; + + QCOMPARE(m_store3->name(), QString("Foo")); + QCOMPARE(m_store3->item(0), true); + QCOMPARE(m_store3->item(1), false); + QCOMPARE(m_store3->item(2), false); +} + +QTEST_APPLESS_MAIN(TestStore) -- cgit