diff options
Diffstat (limited to 'sigscript/test/TestConfig.cpp')
| -rw-r--r-- | sigscript/test/TestConfig.cpp | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/sigscript/test/TestConfig.cpp b/sigscript/test/TestConfig.cpp new file mode 100644 index 00000000..7393269a --- /dev/null +++ b/sigscript/test/TestConfig.cpp @@ -0,0 +1,165 @@ +/* + * Copyright 2009 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 "TestConfig.h" + +// Sigscript includes +#include <sigscript/Config.h> + +// Qt includes +#include <QtTest/QSignalSpy> +#include <QtTest/QTest> + +using namespace Sigscript; + +void TestConfig::initTestCase() +{ + qRegisterMetaType<QVariant>("QVariant"); + qRegisterMetaType<Config::Options>("Sigscript::Config::Options"); + m_config = new Config(NULL); +} + +void TestConfig::cleanupTestCase() +{ + delete m_config; +} + +// void valueAdded(const QString& name, const QVariant& value); +// void valueChanged(const QString& name, const QVariant& newValue); +// void valueRemoved(const QString& name); +// void optionsChanged(const QString& name, const Sigscript::Config::Options newOptions); + +void TestConfig::testAddValue() +{ + QSignalSpy addSpy(m_config, SIGNAL(valueAdded(QString, QVariant))); + QSignalSpy changeSpy(m_config, SIGNAL(valueChanged(QString, QVariant))); + + QCOMPARE(m_config->addValue("foo", 10), true); + QCOMPARE(m_config->addValue("bar", 20), true); + QCOMPARE(m_config->addValue("bar", 25), false); + + QCOMPARE(addSpy.count(), 2); + QCOMPARE(changeSpy.count(), 2); +} + +void TestConfig::testSetValue() +{ + QSignalSpy addSpy(m_config, SIGNAL(valueAdded(QString, QVariant))); + QSignalSpy changeSpy(m_config, SIGNAL(valueChanged(QString, QVariant))); + + QCOMPARE(m_config->setValue("foo", 5), true); + QCOMPARE(m_config->setValue("baz", 30), true); + + QCOMPARE(addSpy.count(), 1); + QCOMPARE(changeSpy.count(), 2); + + QCOMPARE(m_config->setValue("op1", 1), true); + QCOMPARE(m_config->setValue("op2", 2), true); + QCOMPARE(m_config->setValue("op3", 3), true); + QCOMPARE(m_config->setValue("op4", 4), true); +} + +void TestConfig::testRemoveValue() +{ + Config* subConfig = new Config(m_config); + + QSignalSpy removeSpy(m_config, SIGNAL(valueRemoved(QString))); + QSignalSpy removeSpySub(subConfig, SIGNAL(valueRemoved(QString))); + + QCOMPARE(m_config->removeValue("foo"), true); + QCOMPARE(m_config->removeValue("quux", true), true); + QCOMPARE(m_config->removeValue("blag", false), false); + QCOMPARE(subConfig->removeValue("bar", true), true); + QCOMPARE(subConfig->removeValue("baz", false), false); + + QCOMPARE(removeSpy.count(), 2); + QCOMPARE(removeSpySub.count(), 1); + + delete subConfig; +} + +void TestConfig::testSetOptions() +{ + QSignalSpy changeSpy(m_config, SIGNAL(optionsChanged(QString, Sigscript::Config::Options))); + + m_config->setOptions("op1", Config::Deleted); + m_config->setOptions("op2", Config::Hidden); + m_config->setOptions("op3", Config::ReadOnly); + m_config->setOptions("op4", Config::Temporary); + + QCOMPARE(changeSpy.count(), 4); +} + +void TestConfig::testOptions() +{ + QSignalSpy addSpy(m_config, SIGNAL(valueAdded(QString, QVariant))); + QSignalSpy changeSpy(m_config, SIGNAL(valueChanged(QString, QVariant))); + + QCOMPARE(m_config->hasValue("op1"), false); + QCOMPARE(m_config->hasValue("op2"), false); + QCOMPARE(m_config->hasValue("op3"), true); + QCOMPARE(m_config->hasValue("op4"), true); + + QCOMPARE(m_config->addValue("op1", 10), true); + QCOMPARE(m_config->addValue("op2", 20), false); + QCOMPARE(m_config->setValue("op3", 30), false); + + QCOMPARE(m_config->value("op3").toInt(), 3); + + QCOMPARE(addSpy.count(), 1); + QCOMPARE(changeSpy.count(), 1); + +} + +void TestConfig::testClean() +{ + QSignalSpy removeSpy(m_config, SIGNAL(valueRemoved(QString))); + QSignalSpy changeSpy(m_config, SIGNAL(optionsChanged(QString, Sigscript::Config::Options))); + + m_config->clean(); + + QCOMPARE(removeSpy.count(), 1); + QCOMPARE(changeSpy.count(), 1); +} + +void TestConfig::testUnsetOptions() +{ + QSignalSpy changeSpy(m_config, SIGNAL(optionsChanged(QString, Sigscript::Config::Options))); +} + +void TestConfig::testValueList() +{ +} + +void TestConfig::testOptionsRead() +{ +} + +void TestConfig::testValueRead() +{ +} + +void TestConfig::testValueCheck() +{ +} + +void TestConfig::testValueTypeRead() +{ +} + +QTEST_APPLESS_MAIN(TestConfig) |
