diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-03-01 08:03:50 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-03-03 09:00:30 (GMT) |
commit | fde71bd59b1412ae475c06f2d4100ce088e86af6 (patch) | |
tree | 4f3d85c700942d666c5ac5d032c757bc45bb1593 /Swift/Controllers/Settings/UnitTest | |
parent | 5271144cb6c0ecf3dc237af25197fa72a8737c09 (diff) | |
download | swift-fde71bd59b1412ae475c06f2d4100ce088e86af6.zip swift-fde71bd59b1412ae475c06f2d4100ce088e86af6.tar.bz2 |
Unit tests for SettingsProviderHierachy
Also fixing up errors they found and an uninitialised read left-over from the original patch.
Diffstat (limited to 'Swift/Controllers/Settings/UnitTest')
-rw-r--r-- | Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp b/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp new file mode 100644 index 0000000..aa4d14f --- /dev/null +++ b/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swift/Controllers/Settings/SettingsProviderHierachy.h> +#include <Swift/Controllers/Settings/DummySettingsProvider.h> +#include <Swift/Controllers/Settings/XMLSettingsProvider.h> + +using namespace Swift; +using namespace std; + +class SettingsProviderHierachyTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(SettingsProviderHierachyTest); + CPPUNIT_TEST(testEmpty); + CPPUNIT_TEST(testTop); + CPPUNIT_TEST(testBottom); + CPPUNIT_TEST(testBoth); + CPPUNIT_TEST(testTopDefault); + CPPUNIT_TEST(testBottomOverrides); + CPPUNIT_TEST(testFinal); + CPPUNIT_TEST_SUITE_END(); + +public: + SettingsProviderHierachyTest() : setting1("somekey", 42) {}; + + void setUp() { + bottom = new DummySettingsProvider(); + top = new DummySettingsProvider(); + testling = new SettingsProviderHierachy(); + testling->addProviderToTopOfStack(bottom); + testling->addProviderToTopOfStack(top); + } + + void tearDown() { + delete testling; + delete top; + delete bottom; + } + + void testEmpty() { + CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1)); + } + + void testTop() { + top->storeSetting(setting1, 37); + CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1)); + } + + void testBottom() { + bottom->storeSetting(setting1, 17); + CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1)); + } + + void testBoth() { + bottom->storeSetting(setting1, 17); + top->storeSetting(setting1, 37); + CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1)); + } + + void testTopDefault() { + bottom->storeSetting(setting1, 17); + top->storeSetting(setting1, 42); + CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1)); + } + + void testBottomOverrides() { + bottom->storeSetting(setting1, 17); + bottom->setFinal(setting1.getKey()); + top->storeSetting(setting1, 5); + CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1)); + } + + void testFinal() { + bottom->storeSetting(setting1, 17); + bottom->setFinal(setting1.getKey()); + testling->storeSetting(setting1, 5); + CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1)); + } +private: + SettingsProviderHierachy* testling; + DummySettingsProvider* bottom; + DummySettingsProvider* top; + SettingsProvider::Setting<int> setting1; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SettingsProviderHierachyTest); |