mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 10:13:51 +01:00
Added LocalConfigurationView to only search inside the viewed scope (#3529)
This commit is contained in:
parent
0081bde084
commit
9a4853582f
@ -8,7 +8,7 @@ include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = AbstractConfiguration Application ConfigurationMapper \
|
||||
ConfigurationView HelpFormatter IniFileConfiguration LayeredConfiguration \
|
||||
LoggingConfigurator LoggingSubsystem MapConfiguration \
|
||||
LocalConfigurationView LoggingConfigurator LoggingSubsystem MapConfiguration \
|
||||
Option OptionException OptionProcessor OptionSet \
|
||||
PropertyFileConfiguration Subsystem SystemConfiguration \
|
||||
FilesystemConfiguration ServerApplication \
|
||||
|
@ -551,6 +551,7 @@
|
||||
<ClInclude Include="include\Poco\Util\IntValidator.h"/>
|
||||
<ClInclude Include="include\Poco\Util\JSONConfiguration.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LayeredConfiguration.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LocalConfigurationView.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LoggingConfigurator.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LoggingSubsystem.h"/>
|
||||
<ClInclude Include="include\Poco\Util\MapConfiguration.h"/>
|
||||
@ -605,6 +606,9 @@
|
||||
<ClCompile Include="src\LayeredConfiguration.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationView.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfigurator.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
|
@ -90,6 +90,9 @@
|
||||
<ClInclude Include="include\Poco\Util\LayeredConfiguration.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Util\LocalConfigurationView.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Util\LoggingConfigurator.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -188,6 +191,9 @@
|
||||
<ClCompile Include="src\LayeredConfiguration.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationView.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfigurator.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -551,6 +551,7 @@
|
||||
<ClInclude Include="include\Poco\Util\IntValidator.h"/>
|
||||
<ClInclude Include="include\Poco\Util\JSONConfiguration.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LayeredConfiguration.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LocalConfigurationView.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LoggingConfigurator.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LoggingSubsystem.h"/>
|
||||
<ClInclude Include="include\Poco\Util\MapConfiguration.h"/>
|
||||
@ -605,6 +606,9 @@
|
||||
<ClCompile Include="src\LayeredConfiguration.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationView.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfigurator.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
|
@ -90,6 +90,9 @@
|
||||
<ClInclude Include="include\Poco\Util\LayeredConfiguration.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Util\LocalConfigurationView.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Util\LoggingConfigurator.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -188,6 +191,9 @@
|
||||
<ClCompile Include="src\LayeredConfiguration.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationView.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfigurator.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -551,6 +551,7 @@
|
||||
<ClInclude Include="include\Poco\Util\IntValidator.h"/>
|
||||
<ClInclude Include="include\Poco\Util\JSONConfiguration.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LayeredConfiguration.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LocalConfigurationView.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LoggingConfigurator.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LoggingSubsystem.h"/>
|
||||
<ClInclude Include="include\Poco\Util\MapConfiguration.h"/>
|
||||
@ -605,6 +606,9 @@
|
||||
<ClCompile Include="src\LayeredConfiguration.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationView.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfigurator.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
|
@ -90,6 +90,9 @@
|
||||
<ClInclude Include="include\Poco\Util\LayeredConfiguration.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Util\LocalConfigurationView.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Util\LoggingConfigurator.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -188,6 +191,9 @@
|
||||
<ClCompile Include="src\LayeredConfiguration.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationView.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfigurator.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -551,6 +551,7 @@
|
||||
<ClInclude Include="include\Poco\Util\IntValidator.h"/>
|
||||
<ClInclude Include="include\Poco\Util\JSONConfiguration.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LayeredConfiguration.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LocalConfigurationView.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LoggingConfigurator.h"/>
|
||||
<ClInclude Include="include\Poco\Util\LoggingSubsystem.h"/>
|
||||
<ClInclude Include="include\Poco\Util\MapConfiguration.h"/>
|
||||
@ -605,6 +606,9 @@
|
||||
<ClCompile Include="src\LayeredConfiguration.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationView.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfigurator.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
|
@ -90,6 +90,9 @@
|
||||
<ClInclude Include="include\Poco\Util\LayeredConfiguration.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Util\LocalConfigurationView.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Util\LoggingConfigurator.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -188,6 +191,9 @@
|
||||
<ClCompile Include="src\LayeredConfiguration.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationView.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfigurator.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -571,6 +571,9 @@
|
||||
RelativePath=".\include\Poco\Util\LayeredConfiguration.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Util\LocalConfigurationView.h"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Util\LoggingConfigurator.h"
|
||||
>
|
||||
@ -623,6 +626,9 @@
|
||||
RelativePath=".\src\LayeredConfiguration.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\LocalConfigurationView.cpp"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\LoggingConfigurator.cpp"
|
||||
>
|
||||
|
@ -300,6 +300,12 @@ public:
|
||||
|
||||
Ptr createView(const std::string& prefix);
|
||||
/// Creates a view (see ConfigurationView) into the configuration.
|
||||
|
||||
const Ptr createLocalView(const std::string& prefix) const;
|
||||
/// Creates a non-mutable view (see LocalConfigurationView) into the configuration.
|
||||
|
||||
Ptr createLocalView(const std::string& prefix);
|
||||
/// Creates a view (see LocalConfigurationView) into the configuration.
|
||||
|
||||
std::string expand(const std::string& value) const;
|
||||
/// Replaces all occurrences of ${<property>} in value with the
|
||||
@ -383,6 +389,7 @@ private:
|
||||
|
||||
friend class LayeredConfiguration;
|
||||
friend class ConfigurationView;
|
||||
friend class LocalConfigurationView;
|
||||
friend class ConfigurationMapper;
|
||||
};
|
||||
|
||||
|
72
Util/include/Poco/Util/LocalConfigurationView.h
Normal file
72
Util/include/Poco/Util/LocalConfigurationView.h
Normal file
@ -0,0 +1,72 @@
|
||||
//
|
||||
// LocalConfigurationView.h
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: LocalConfigurationView
|
||||
//
|
||||
// Definition of the ConfigurationView class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
#ifndef Util_LocalConfigurationView_INCLUDED
|
||||
#define Util_LocalConfigurationView_INCLUDED
|
||||
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include "Poco/Util/Util.h"
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
class Util_API LocalConfigurationView : public AbstractConfiguration
|
||||
/// This configuration implements a "view" into a sub-hierarchy
|
||||
/// of another configuration.
|
||||
///
|
||||
/// For example, given a configuration with the following properties:
|
||||
/// config.value1
|
||||
/// config.value2
|
||||
/// config.sub.value1
|
||||
/// config.sub.value2
|
||||
/// and a LocalConfigurationView with the prefix "config", then
|
||||
/// the above properties will be available via the view as
|
||||
/// value1
|
||||
/// value2
|
||||
/// sub.value1
|
||||
/// sub.value2
|
||||
///
|
||||
/// A LocalConfigurationView is most useful in combination with a
|
||||
/// LayeredConfiguration.
|
||||
///
|
||||
/// The LocalConfigurationView only searches for the properties in the viewed Space.
|
||||
{
|
||||
public:
|
||||
LocalConfigurationView(const std::string& prefix, AbstractConfiguration::Ptr pConfig);
|
||||
/// Creates the LocalConfigurationView. The LocalConfigurationView
|
||||
/// retains (shared) ownership of the passed configuration.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
|
||||
std::string translateKey(const std::string& key) const;
|
||||
|
||||
~LocalConfigurationView();
|
||||
|
||||
private:
|
||||
LocalConfigurationView(const LocalConfigurationView&);
|
||||
LocalConfigurationView& operator=(const LocalConfigurationView&);
|
||||
|
||||
std::string _prefix;
|
||||
AbstractConfiguration::Ptr _pConfig;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Poco
|
||||
|
||||
#endif // Util_LocalConfigurationView_INCLUDED
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include "Poco/Util/ConfigurationView.h"
|
||||
#include "Poco/Util/LocalConfigurationView.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
@ -348,6 +349,18 @@ AbstractConfiguration::Ptr AbstractConfiguration::createView(const std::string&
|
||||
}
|
||||
|
||||
|
||||
const AbstractConfiguration::Ptr AbstractConfiguration::createLocalView(const std::string& prefix) const
|
||||
{
|
||||
return new LocalConfigurationView(prefix, AbstractConfiguration::Ptr(const_cast<AbstractConfiguration*>(this), true));
|
||||
}
|
||||
|
||||
|
||||
AbstractConfiguration::Ptr AbstractConfiguration::createLocalView(const std::string& prefix)
|
||||
{
|
||||
return new LocalConfigurationView(prefix, AbstractConfiguration::Ptr(this, true));
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class AutoCounter
|
||||
|
55
Util/src/LocalConfigurationView.cpp
Normal file
55
Util/src/LocalConfigurationView.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
//
|
||||
// LocalConfigurationView.cpp
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: LocalConfigurationView
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
#include "Poco/Util/LocalConfigurationView.h"
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
LocalConfigurationView::LocalConfigurationView(const std::string& prefix, AbstractConfiguration::Ptr pConfig) : _prefix(prefix),
|
||||
_pConfig(pConfig) {
|
||||
poco_check_ptr(pConfig);
|
||||
}
|
||||
|
||||
LocalConfigurationView::~LocalConfigurationView() {
|
||||
}
|
||||
|
||||
bool LocalConfigurationView::getRaw(const std::string& key, std::string& value) const {
|
||||
std::string translatedKey = translateKey(key);
|
||||
return _pConfig->getRaw(translatedKey, value);
|
||||
}
|
||||
|
||||
void LocalConfigurationView::setRaw(const std::string& key, const std::string& value) {
|
||||
std::string translatedKey = translateKey(key);
|
||||
_pConfig->setRaw(translatedKey, value);
|
||||
}
|
||||
|
||||
void LocalConfigurationView::enumerate(const std::string& key, Keys& range) const {
|
||||
std::string translatedKey = translateKey(key);
|
||||
_pConfig->enumerate(translatedKey, range);
|
||||
}
|
||||
|
||||
void LocalConfigurationView::removeRaw(const std::string& key) {
|
||||
std::string translatedKey = translateKey(key);
|
||||
_pConfig->remove(translatedKey);
|
||||
}
|
||||
|
||||
std::string LocalConfigurationView::translateKey(const std::string& key) const {
|
||||
std::string result = _prefix;
|
||||
if (!result.empty() && !key.empty() && key[0] != '[') result += '.';
|
||||
result += key;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Poco
|
@ -9,7 +9,7 @@ include $(POCO_BASE)/build/rules/global
|
||||
objects = AbstractConfigurationTest ConfigurationTestSuite \
|
||||
ConfigurationMapperTest ConfigurationViewTest Driver \
|
||||
HelpFormatterTest IniFileConfigurationTest LayeredConfigurationTest \
|
||||
LoggingConfiguratorTest MapConfigurationTest \
|
||||
LocalConfigurationView LoggingConfiguratorTest MapConfigurationTest \
|
||||
OptionProcessorTest OptionSetTest OptionTest \
|
||||
OptionsTestSuite PropertyFileConfigurationTest \
|
||||
SystemConfigurationTest UtilTestSuite XMLConfigurationTest \
|
||||
|
@ -607,6 +607,7 @@
|
||||
<ClInclude Include="src\IniFileConfigurationTest.h"/>
|
||||
<ClInclude Include="src\JSONConfigurationTest.h"/>
|
||||
<ClInclude Include="src\LayeredConfigurationTest.h"/>
|
||||
<ClInclude Include="src\LocalConfigurationViewTest.h"/>
|
||||
<ClInclude Include="src\LoggingConfiguratorTest.h"/>
|
||||
<ClInclude Include="src\MapConfigurationTest.h"/>
|
||||
<ClInclude Include="src\OptionProcessorTest.h"/>
|
||||
@ -656,6 +657,9 @@
|
||||
<ClCompile Include="src\LayeredConfigurationTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationViewTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfiguratorTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
|
@ -90,6 +90,9 @@
|
||||
<ClInclude Include="src\LayeredConfigurationTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\LocalConfigurationViewTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\LoggingConfiguratorTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -173,6 +176,9 @@
|
||||
<ClCompile Include="src\LayeredConfigurationTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationViewTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfiguratorTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -607,6 +607,7 @@
|
||||
<ClInclude Include="src\IniFileConfigurationTest.h"/>
|
||||
<ClInclude Include="src\JSONConfigurationTest.h"/>
|
||||
<ClInclude Include="src\LayeredConfigurationTest.h"/>
|
||||
<ClInclude Include="src\LocalConfigurationViewTest.h"/>
|
||||
<ClInclude Include="src\LoggingConfiguratorTest.h"/>
|
||||
<ClInclude Include="src\MapConfigurationTest.h"/>
|
||||
<ClInclude Include="src\OptionProcessorTest.h"/>
|
||||
@ -656,6 +657,9 @@
|
||||
<ClCompile Include="src\LayeredConfigurationTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationViewTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfiguratorTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
|
@ -90,6 +90,9 @@
|
||||
<ClInclude Include="src\LayeredConfigurationTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\LocalConfigurationViewTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\LoggingConfiguratorTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -173,6 +176,9 @@
|
||||
<ClCompile Include="src\LayeredConfigurationTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationViewTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfiguratorTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -607,6 +607,7 @@
|
||||
<ClInclude Include="src\IniFileConfigurationTest.h"/>
|
||||
<ClInclude Include="src\JSONConfigurationTest.h"/>
|
||||
<ClInclude Include="src\LayeredConfigurationTest.h"/>
|
||||
<ClInclude Include="src\LocalConfigurationViewTest.h"/>
|
||||
<ClInclude Include="src\LoggingConfiguratorTest.h"/>
|
||||
<ClInclude Include="src\MapConfigurationTest.h"/>
|
||||
<ClInclude Include="src\OptionProcessorTest.h"/>
|
||||
@ -656,6 +657,9 @@
|
||||
<ClCompile Include="src\LayeredConfigurationTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationViewTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfiguratorTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
|
@ -90,6 +90,9 @@
|
||||
<ClInclude Include="src\LayeredConfigurationTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\LocalConfigurationViewTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\LoggingConfiguratorTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -173,6 +176,9 @@
|
||||
<ClCompile Include="src\LayeredConfigurationTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationViewTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfiguratorTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -607,6 +607,7 @@
|
||||
<ClInclude Include="src\IniFileConfigurationTest.h"/>
|
||||
<ClInclude Include="src\JSONConfigurationTest.h"/>
|
||||
<ClInclude Include="src\LayeredConfigurationTest.h"/>
|
||||
<ClInclude Include="src\LocalConfigurationViewTest.h"/>
|
||||
<ClInclude Include="src\LoggingConfiguratorTest.h"/>
|
||||
<ClInclude Include="src\MapConfigurationTest.h"/>
|
||||
<ClInclude Include="src\OptionProcessorTest.h"/>
|
||||
@ -656,6 +657,9 @@
|
||||
<ClCompile Include="src\LayeredConfigurationTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationViewTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfiguratorTest.cpp">
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
|
@ -93,6 +93,9 @@
|
||||
<ClInclude Include="src\LoggingConfiguratorTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\LocalConfigurationViewTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\MapConfigurationTest.h">
|
||||
<Filter>Configuration\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -173,6 +176,9 @@
|
||||
<ClCompile Include="src\LayeredConfigurationTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LocalConfigurationViewTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\LoggingConfiguratorTest.cpp">
|
||||
<Filter>Configuration\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -491,6 +491,8 @@
|
||||
RelativePath=".\src\JSONConfigurationTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\LayeredConfigurationTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\LocalConfigurationTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\LoggingConfiguratorTest.h"/>
|
||||
<File
|
||||
@ -520,6 +522,8 @@
|
||||
RelativePath=".\src\JSONConfigurationTest.cpp"/>
|
||||
<File
|
||||
RelativePath=".\src\LayeredConfigurationTest.cpp"/>
|
||||
<File
|
||||
RelativePath=".\src\LocalConfigurationViewTest.cpp"/>
|
||||
<File
|
||||
RelativePath=".\src\LoggingConfiguratorTest.cpp"/>
|
||||
<File
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "ConfigurationTestSuite.h"
|
||||
#include "AbstractConfigurationTest.h"
|
||||
#include "ConfigurationViewTest.h"
|
||||
#include "LocalConfigurationViewTest.h"
|
||||
#include "ConfigurationMapperTest.h"
|
||||
#include "MapConfigurationTest.h"
|
||||
#include "LayeredConfigurationTest.h"
|
||||
@ -28,6 +29,7 @@ CppUnit::Test* ConfigurationTestSuite::suite()
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConfigurationTestSuite");
|
||||
|
||||
pSuite->addTest(ConfigurationViewTest::suite());
|
||||
pSuite->addTest(LocalConfigurationViewTest::suite());
|
||||
pSuite->addTest(ConfigurationMapperTest::suite());
|
||||
pSuite->addTest(MapConfigurationTest::suite());
|
||||
pSuite->addTest(LayeredConfigurationTest::suite());
|
||||
|
114
Util/testsuite/src/LocalConfigurationViewTest.cpp
Normal file
114
Util/testsuite/src/LocalConfigurationViewTest.cpp
Normal file
@ -0,0 +1,114 @@
|
||||
//
|
||||
// LocalConfigurationViewTest.cpp
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
#include "LocalConfigurationViewTest.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Util/MapConfiguration.h"
|
||||
|
||||
using Poco::AutoPtr;
|
||||
using Poco::Util::AbstractConfiguration;
|
||||
using Poco::Util::MapConfiguration;
|
||||
|
||||
LocalConfigurationViewTest::LocalConfigurationViewTest(const std::string& name) : AbstractConfigurationTest(name) {
|
||||
}
|
||||
|
||||
LocalConfigurationViewTest::~LocalConfigurationViewTest() {
|
||||
}
|
||||
|
||||
void LocalConfigurationViewTest::testLocalView() {
|
||||
AbstractConfiguration::Ptr pConf = createConfiguration();
|
||||
AbstractConfiguration::Ptr pView = pConf->createLocalView("");
|
||||
assertTrue(pView->hasProperty("prop1"));
|
||||
assertTrue(pView->hasProperty("prop2"));
|
||||
|
||||
AbstractConfiguration::Keys keys;
|
||||
pView->keys(keys);
|
||||
assertTrue(keys.size() == 13);
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "prop1") != keys.end());
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "prop2") != keys.end());
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "prop3") != keys.end());
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "prop4") != keys.end());
|
||||
|
||||
assertTrue(pView->getString("prop1") == "foo");
|
||||
assertTrue(pView->getString("prop3.string1") == "foo");
|
||||
|
||||
pView->setString("prop6", "foobar");
|
||||
assertTrue(pConf->getString("prop6") == "foobar");
|
||||
|
||||
pView = pConf->createLocalView("prop1");
|
||||
pView->keys(keys);
|
||||
assertTrue(keys.empty());
|
||||
assertFalse(pView->hasProperty("prop1"));
|
||||
|
||||
pView->setString("prop11", "foobar");
|
||||
assertTrue(pConf->getString("prop1.prop11") == "foobar");
|
||||
|
||||
pView = pConf->createLocalView("prop3");
|
||||
pView->keys(keys);
|
||||
assertTrue(keys.size() == 2);
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "string1") != keys.end());
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "string2") != keys.end());
|
||||
|
||||
assertTrue(pView->getString("string1") == "foo");
|
||||
assertTrue(pView->getString("string2") == "bar");
|
||||
|
||||
pView->setString("string3", "foobar");
|
||||
assertTrue(pConf->getString("prop3.string3") == "foobar");
|
||||
|
||||
pView = pConf->createLocalView("prop5");
|
||||
pView->keys(keys);
|
||||
assertTrue(keys.size() == 4);
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "string1") != keys.end());
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "string1") != keys.end());
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "sub1") != keys.end());
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "sub2") != keys.end());
|
||||
|
||||
assertTrue(pView->getString("sub1.string1") == "FOO");
|
||||
assertTrue(pView->getString("sub2.string2") == "Bar");
|
||||
|
||||
pView = pConf->createLocalView("prop5.sub1");
|
||||
pView->keys(keys);
|
||||
assertTrue(keys.size() == 2);
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "string1") != keys.end());
|
||||
assertTrue(std::find(keys.begin(), keys.end(), "string2") != keys.end());
|
||||
|
||||
assertTrue(pView->getString("string1") == "FOO");
|
||||
assertTrue(pView->getString("string2") == "BAR");
|
||||
|
||||
pView->setString("string3", "foobar");
|
||||
assertTrue(pConf->getString("prop5.sub1.string3") == "foobar");
|
||||
|
||||
pView->remove("string3");
|
||||
assertTrue(!pConf->hasProperty("prop5.sub1.string3"));
|
||||
}
|
||||
|
||||
AbstractConfiguration::Ptr LocalConfigurationViewTest::allocConfiguration() const {
|
||||
return new MapConfiguration;
|
||||
}
|
||||
|
||||
void LocalConfigurationViewTest::setUp() {
|
||||
}
|
||||
|
||||
void LocalConfigurationViewTest::tearDown() {
|
||||
}
|
||||
|
||||
CppUnit::Test* LocalConfigurationViewTest::suite() {
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("LocalConfigurationViewTest");
|
||||
|
||||
AbstractConfigurationTest_addTests(pSuite, LocalConfigurationViewTest);
|
||||
CppUnit_addTest(pSuite, LocalConfigurationViewTest, testLocalView);
|
||||
|
||||
return pSuite;
|
||||
}
|
34
Util/testsuite/src/LocalConfigurationViewTest.h
Normal file
34
Util/testsuite/src/LocalConfigurationViewTest.h
Normal file
@ -0,0 +1,34 @@
|
||||
//
|
||||
// LocalConfigurationViewTest.h
|
||||
//
|
||||
// Definition of the ConfigurationViewTest class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
#ifndef LocalConfigurationViewTest_INCLUDED
|
||||
#define LocalConfigurationViewTest_INCLUDED
|
||||
|
||||
#include "AbstractConfigurationTest.h"
|
||||
#include "Poco/Util/Util.h"
|
||||
|
||||
class LocalConfigurationViewTest : public AbstractConfigurationTest {
|
||||
public:
|
||||
LocalConfigurationViewTest(const std::string& name);
|
||||
virtual ~LocalConfigurationViewTest();
|
||||
|
||||
void testLocalView();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
virtual Poco::Util::AbstractConfiguration::Ptr allocConfiguration() const;
|
||||
};
|
||||
|
||||
#endif // LocalConfigurationViewTest_INCLUDED
|
Loading…
Reference in New Issue
Block a user