diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-16 20:38:26 -0400 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-17 17:37:35 -0400 |
commit | 9dda8036cd9d08d4f7aa9575a53702320b761ed8 (patch) | |
tree | 323f17da075b6473079e71b610ca48e6b14c7c2e /sigscript | |
parent | de4ecb39402fa695fa814eee0ac031baeecfb6b5 (diff) | |
download | sigen-9dda8036cd9d08d4f7aa9575a53702320b761ed8.tar.gz sigen-9dda8036cd9d08d4f7aa9575a53702320b761ed8.tar.xz sigen-9dda8036cd9d08d4f7aa9575a53702320b761ed8.zip |
Add test for Config
Diffstat (limited to 'sigscript')
-rw-r--r-- | sigscript/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sigscript/test/CMakeLists.txt | 8 | ||||
-rw-r--r-- | sigscript/test/TestConfig.cpp | 165 | ||||
-rw-r--r-- | sigscript/test/TestConfig.h | 55 |
4 files changed, 230 insertions, 0 deletions
diff --git a/sigscript/CMakeLists.txt b/sigscript/CMakeLists.txt index 110c75d6..0a95b0eb 100644 --- a/sigscript/CMakeLists.txt +++ b/sigscript/CMakeLists.txt @@ -98,6 +98,8 @@ target_link_libraries(sigscript LINK_INTERFACE_LIBRARIES sigcore ) +add_subdirectory(test) + install( TARGETS sigscript diff --git a/sigscript/test/CMakeLists.txt b/sigscript/test/CMakeLists.txt new file mode 100644 index 00000000..4b5746cf --- /dev/null +++ b/sigscript/test/CMakeLists.txt @@ -0,0 +1,8 @@ +set(libraries + sigscript +) + +make_test(sigscript-tests sigscript-vtests libraries Config) + +make_test_group(sigscript sigscript-tests) +make_valgrind_group(sigscript sigscript-vtests) 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) diff --git a/sigscript/test/TestConfig.h b/sigscript/test/TestConfig.h new file mode 100644 index 00000000..9a37dc45 --- /dev/null +++ b/sigscript/test/TestConfig.h @@ -0,0 +1,55 @@ +/* + * 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/>. + */ + +#ifndef SIGSCRIPT_TESTCONFIG +#define SIGSCRIPT_TESTCONFIG + +// Qt includes +#include <QtCore/QObject> + +// Forward declarations +namespace Sigscript +{ +class Config; +} + +class TestConfig : public QObject +{ + Q_OBJECT + + private slots: + void initTestCase(); + void cleanupTestCase(); + + void testAddValue(); + void testSetValue(); + void testRemoveValue(); + void testSetOptions(); + void testOptions(); + void testClean(); + void testUnsetOptions(); + void testValueList(); + + void testOptionsRead(); + void testValueRead(); + void testValueCheck(); + void testValueTypeRead(); + private: + Sigscript::Config* m_config; +}; + +#endif |