2
// ConfigurationViewTest.cpp
4
// $Id: //poco/1.2/Util/testsuite/src/ConfigurationViewTest.cpp#1 $
6
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
9
// Permission is hereby granted, free of charge, to any person or organization
10
// obtaining a copy of the software and accompanying documentation covered by
11
// this license (the "Software") to use, reproduce, display, distribute,
12
// execute, and transmit the Software, and to prepare derivative works of the
13
// Software, and to permit third-parties to whom the Software is furnished to
14
// do so, all subject to the following:
16
// The copyright notices in the Software and this entire statement, including
17
// the above license grant, this restriction and the following disclaimer,
18
// must be included in all copies of the Software, in whole or in part, and
19
// all derivative works of the Software, unless such copies or derivative
20
// works are solely in the form of machine-executable object code generated by
21
// a source language processor.
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
26
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
27
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
28
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29
// DEALINGS IN THE SOFTWARE.
33
#include "ConfigurationViewTest.h"
34
#include "CppUnit/TestCaller.h"
35
#include "CppUnit/TestSuite.h"
36
#include "Poco/Util/MapConfiguration.h"
37
#include "Poco/AutoPtr.h"
38
#include "Poco/Exception.h"
42
using Poco::Util::AbstractConfiguration;
43
using Poco::Util::MapConfiguration;
47
ConfigurationViewTest::ConfigurationViewTest(const std::string& name): CppUnit::TestCase(name)
52
ConfigurationViewTest::~ConfigurationViewTest()
57
void ConfigurationViewTest::testView()
59
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
60
AutoPtr<AbstractConfiguration> pView = pConf->createView("");
61
assert (pView->hasProperty("prop1"));
62
assert (pView->hasProperty("prop2"));
64
AbstractConfiguration::Keys keys;
66
assert (keys.size() == 4);
67
assert (std::find(keys.begin(), keys.end(), "prop1") != keys.end());
68
assert (std::find(keys.begin(), keys.end(), "prop2") != keys.end());
69
assert (std::find(keys.begin(), keys.end(), "prop3") != keys.end());
70
assert (std::find(keys.begin(), keys.end(), "prop4") != keys.end());
72
assert (pView->getString("prop1") == "foo");
73
assert (pView->getString("prop3.string1") == "foo");
75
pView->setString("prop5", "foobar");
76
assert (pConf->getString("prop5") == "foobar");
78
pView = pConf->createView("prop1");
80
assert (keys.empty());
81
assert (pView->hasProperty("prop1"));
83
pView->setString("prop11", "foobar");
84
assert (pConf->getString("prop1.prop11") == "foobar");
86
pView = pConf->createView("prop3");
88
assert (keys.size() == 2);
89
assert (std::find(keys.begin(), keys.end(), "string1") != keys.end());
90
assert (std::find(keys.begin(), keys.end(), "string2") != keys.end());
92
assert (pView->getString("string1") == "foo");
93
assert (pView->getString("string2") == "bar");
95
pView->setString("string3", "foobar");
96
assert (pConf->getString("prop3.string3") == "foobar");
98
pView = pConf->createView("prop4");
100
assert (keys.size() == 2);
101
assert (std::find(keys.begin(), keys.end(), "prop41") != keys.end());
102
assert (std::find(keys.begin(), keys.end(), "prop42") != keys.end());
104
assert (pView->getString("prop41.string1") == "FOO");
105
assert (pView->getString("prop42.string2") == "Bar");
107
pView = pConf->createView("prop4.prop41");
109
assert (keys.size() == 2);
110
assert (std::find(keys.begin(), keys.end(), "string1") != keys.end());
111
assert (std::find(keys.begin(), keys.end(), "string2") != keys.end());
113
assert (pView->getString("string1") == "FOO");
114
assert (pView->getString("string2") == "BAR");
116
pView->setString("string3", "foobar");
117
assert (pConf->getString("prop4.prop41.string3") == "foobar");
121
AbstractConfiguration* ConfigurationViewTest::createConfiguration() const
123
AbstractConfiguration* pConfig = new MapConfiguration;
125
pConfig->setString("prop1", "foo");
126
pConfig->setString("prop2", "bar");
127
pConfig->setString("prop3.string1", "foo");
128
pConfig->setString("prop3.string2", "bar");
129
pConfig->setString("prop4.prop41.string1", "FOO");
130
pConfig->setString("prop4.prop41.string2", "BAR");
131
pConfig->setString("prop4.prop42.string1", "Foo");
132
pConfig->setString("prop4.prop42.string2", "Bar");
138
void ConfigurationViewTest::setUp()
143
void ConfigurationViewTest::tearDown()
148
CppUnit::Test* ConfigurationViewTest::suite()
150
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConfigurationViewTest");
152
CppUnit_addTest(pSuite, ConfigurationViewTest, testView);