~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to Util/testsuite/src/ConfigurationViewTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ConfigurationViewTest.cpp
 
3
//
 
4
// $Id: //poco/1.2/Util/testsuite/src/ConfigurationViewTest.cpp#1 $
 
5
//
 
6
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
 
7
// and Contributors.
 
8
//
 
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:
 
15
// 
 
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.
 
22
// 
 
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.
 
30
//
 
31
 
 
32
 
 
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"
 
39
#include <algorithm>
 
40
 
 
41
 
 
42
using Poco::Util::AbstractConfiguration;
 
43
using Poco::Util::MapConfiguration;
 
44
using Poco::AutoPtr;
 
45
 
 
46
 
 
47
ConfigurationViewTest::ConfigurationViewTest(const std::string& name): CppUnit::TestCase(name)
 
48
{
 
49
}
 
50
 
 
51
 
 
52
ConfigurationViewTest::~ConfigurationViewTest()
 
53
{
 
54
}
 
55
 
 
56
 
 
57
void ConfigurationViewTest::testView()
 
58
{
 
59
        AutoPtr<AbstractConfiguration> pConf = createConfiguration();
 
60
        AutoPtr<AbstractConfiguration> pView = pConf->createView("");
 
61
        assert (pView->hasProperty("prop1"));
 
62
        assert (pView->hasProperty("prop2"));
 
63
 
 
64
        AbstractConfiguration::Keys keys;
 
65
        pView->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());
 
71
        
 
72
        assert (pView->getString("prop1") == "foo");
 
73
        assert (pView->getString("prop3.string1") == "foo");
 
74
        
 
75
        pView->setString("prop5", "foobar");
 
76
        assert (pConf->getString("prop5") == "foobar");
 
77
        
 
78
        pView = pConf->createView("prop1");
 
79
        pView->keys(keys);
 
80
        assert (keys.empty());
 
81
        assert (pView->hasProperty("prop1"));
 
82
 
 
83
        pView->setString("prop11", "foobar");
 
84
        assert (pConf->getString("prop1.prop11") == "foobar");
 
85
 
 
86
        pView = pConf->createView("prop3");
 
87
        pView->keys(keys);
 
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());
 
91
        
 
92
        assert (pView->getString("string1") == "foo");
 
93
        assert (pView->getString("string2") == "bar");
 
94
 
 
95
        pView->setString("string3", "foobar");
 
96
        assert (pConf->getString("prop3.string3") == "foobar");
 
97
 
 
98
        pView = pConf->createView("prop4");
 
99
        pView->keys(keys);
 
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());
 
103
        
 
104
        assert (pView->getString("prop41.string1") == "FOO");
 
105
        assert (pView->getString("prop42.string2") == "Bar");
 
106
 
 
107
        pView = pConf->createView("prop4.prop41");
 
108
        pView->keys(keys);
 
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());
 
112
        
 
113
        assert (pView->getString("string1") == "FOO");
 
114
        assert (pView->getString("string2") == "BAR");
 
115
        
 
116
        pView->setString("string3", "foobar");
 
117
        assert (pConf->getString("prop4.prop41.string3") == "foobar");
 
118
}
 
119
 
 
120
 
 
121
AbstractConfiguration* ConfigurationViewTest::createConfiguration() const
 
122
{
 
123
        AbstractConfiguration* pConfig = new MapConfiguration;
 
124
        
 
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");
 
133
        
 
134
        return pConfig;
 
135
}
 
136
 
 
137
 
 
138
void ConfigurationViewTest::setUp()
 
139
{
 
140
}
 
141
 
 
142
 
 
143
void ConfigurationViewTest::tearDown()
 
144
{
 
145
}
 
146
 
 
147
 
 
148
CppUnit::Test* ConfigurationViewTest::suite()
 
149
{
 
150
        CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConfigurationViewTest");
 
151
 
 
152
        CppUnit_addTest(pSuite, ConfigurationViewTest, testView);
 
153
 
 
154
        return pSuite;
 
155
}