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:
Guenter Obiltschnig 2016-10-16 13:39:17 +02:00
parent f777325cea
commit 5df2508986
4 changed files with 41 additions and 3 deletions

View File

@ -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

View File

@ -39,12 +39,14 @@ namespace Util {
XMLConfiguration::XMLConfiguration():
_delim('.')
{
loadEmpty("config");
}
XMLConfiguration::XMLConfiguration(char delim):
_delim(delim)
{
loadEmpty("config");
}

View File

@ -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;
}

View File

@ -30,6 +30,9 @@ public:
void testSave();
void testLoadAppendSave();
void testOtherDelimiter();
void testSaveEmpty();
void testFromScratch();
void testLoadEmpty();
void setUp();
void tearDown();