diff --git a/Util/include/Poco/Util/XMLConfiguration.h b/Util/include/Poco/Util/XMLConfiguration.h index 43721015d..99e1ba180 100644 --- a/Util/include/Poco/Util/XMLConfiguration.h +++ b/Util/include/Poco/Util/XMLConfiguration.h @@ -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 diff --git a/Util/src/XMLConfiguration.cpp b/Util/src/XMLConfiguration.cpp index 8cf057ced..23e875620 100644 --- a/Util/src/XMLConfiguration.cpp +++ b/Util/src/XMLConfiguration.cpp @@ -39,12 +39,14 @@ namespace Util { XMLConfiguration::XMLConfiguration(): _delim('.') { + loadEmpty("config"); } XMLConfiguration::XMLConfiguration(char delim): _delim(delim) { + loadEmpty("config"); } diff --git a/Util/testsuite/src/XMLConfigurationTest.cpp b/Util/testsuite/src/XMLConfigurationTest.cpp index 7f3f0862c..45e17e0cb 100644 --- a/Util/testsuite/src/XMLConfigurationTest.cpp +++ b/Util/testsuite/src/XMLConfigurationTest.cpp @@ -272,6 +272,36 @@ AbstractConfiguration* XMLConfigurationTest::allocConfiguration() const } +void XMLConfigurationTest::testSaveEmpty() +{ + Poco::AutoPtr pConfig = new XMLConfiguration; + std::ostringstream ostr; + pConfig->save(ostr); + assert (ostr.str() == "\n"); +} + + +void XMLConfigurationTest::testFromScratch() +{ + Poco::AutoPtr pConfig = new XMLConfiguration; + pConfig->setString("foo", "bar"); + std::ostringstream ostr; + pConfig->save(ostr); + assert (ostr.str() == "\n\tbar\n\n"); +} + + +void XMLConfigurationTest::testLoadEmpty() +{ + Poco::AutoPtr pConfig = new XMLConfiguration; + pConfig->loadEmpty("AppConfig"); + pConfig->setString("foo", "bar"); + std::ostringstream ostr; + pConfig->save(ostr); + assert (ostr.str() == "\n\tbar\n\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; } diff --git a/Util/testsuite/src/XMLConfigurationTest.h b/Util/testsuite/src/XMLConfigurationTest.h index 799918f9c..c77a4d759 100644 --- a/Util/testsuite/src/XMLConfigurationTest.h +++ b/Util/testsuite/src/XMLConfigurationTest.h @@ -30,6 +30,9 @@ public: void testSave(); void testLoadAppendSave(); void testOtherDelimiter(); + void testSaveEmpty(); + void testFromScratch(); + void testLoadEmpty(); void setUp(); void tearDown();