mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-02 07:31:37 +02:00
XMLConfiguration default (and single-argument delimiter) constructor now loads an empty XML document with "config" root element to make the configuration usable without an additional call to load() or loadEmpty().
This commit is contained in:
parent
f777325cea
commit
5df2508986
@ -83,11 +83,11 @@ class Util_API XMLConfiguration: public AbstractConfiguration
|
||||
{
|
||||
public:
|
||||
XMLConfiguration();
|
||||
/// Creates an empty XMLConfiguration.
|
||||
/// Creates an empty XMLConfiguration with a "config" root element.
|
||||
|
||||
XMLConfiguration(char delim);
|
||||
/// Creates an empty XMLConfiguration, using the given
|
||||
/// delimiter char instead of the default '.'.
|
||||
/// Creates an empty XMLConfiguration with a "config" root element,
|
||||
/// using the given delimiter char instead of the default '.'.
|
||||
|
||||
XMLConfiguration(Poco::XML::InputSource* pInputSource);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
|
@ -39,12 +39,14 @@ namespace Util {
|
||||
XMLConfiguration::XMLConfiguration():
|
||||
_delim('.')
|
||||
{
|
||||
loadEmpty("config");
|
||||
}
|
||||
|
||||
|
||||
XMLConfiguration::XMLConfiguration(char delim):
|
||||
_delim(delim)
|
||||
{
|
||||
loadEmpty("config");
|
||||
}
|
||||
|
||||
|
||||
|
@ -272,6 +272,36 @@ AbstractConfiguration* XMLConfigurationTest::allocConfiguration() const
|
||||
}
|
||||
|
||||
|
||||
void XMLConfigurationTest::testSaveEmpty()
|
||||
{
|
||||
Poco::AutoPtr<XMLConfiguration> pConfig = new XMLConfiguration;
|
||||
std::ostringstream ostr;
|
||||
pConfig->save(ostr);
|
||||
assert (ostr.str() == "<config/>\n");
|
||||
}
|
||||
|
||||
|
||||
void XMLConfigurationTest::testFromScratch()
|
||||
{
|
||||
Poco::AutoPtr<XMLConfiguration> pConfig = new XMLConfiguration;
|
||||
pConfig->setString("foo", "bar");
|
||||
std::ostringstream ostr;
|
||||
pConfig->save(ostr);
|
||||
assert (ostr.str() == "<config>\n\t<foo>bar</foo>\n</config>\n");
|
||||
}
|
||||
|
||||
|
||||
void XMLConfigurationTest::testLoadEmpty()
|
||||
{
|
||||
Poco::AutoPtr<XMLConfiguration> pConfig = new XMLConfiguration;
|
||||
pConfig->loadEmpty("AppConfig");
|
||||
pConfig->setString("foo", "bar");
|
||||
std::ostringstream ostr;
|
||||
pConfig->save(ostr);
|
||||
assert (ostr.str() == "<AppConfig>\n\t<foo>bar</foo>\n</AppConfig>\n");
|
||||
}
|
||||
|
||||
|
||||
void XMLConfigurationTest::setUp()
|
||||
{
|
||||
}
|
||||
@ -291,6 +321,9 @@ CppUnit::Test* XMLConfigurationTest::suite()
|
||||
CppUnit_addTest(pSuite, XMLConfigurationTest, testSave);
|
||||
CppUnit_addTest(pSuite, XMLConfigurationTest, testLoadAppendSave);
|
||||
CppUnit_addTest(pSuite, XMLConfigurationTest, testOtherDelimiter);
|
||||
CppUnit_addTest(pSuite, XMLConfigurationTest, testSaveEmpty);
|
||||
CppUnit_addTest(pSuite, XMLConfigurationTest, testFromScratch);
|
||||
CppUnit_addTest(pSuite, XMLConfigurationTest, testLoadEmpty);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@ -30,6 +30,9 @@ public:
|
||||
void testSave();
|
||||
void testLoadAppendSave();
|
||||
void testOtherDelimiter();
|
||||
void testSaveEmpty();
|
||||
void testFromScratch();
|
||||
void testLoadEmpty();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
Loading…
x
Reference in New Issue
Block a user