initial import

This commit is contained in:
Guenter Obiltschnig
2006-07-11 16:33:40 +00:00
commit f476bd6b32
1463 changed files with 242402 additions and 0 deletions

View File

@@ -0,0 +1,331 @@
//
// AbstractConfigurationTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/AbstractConfigurationTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "AbstractConfigurationTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/MapConfiguration.h"
#include "Foundation/AutoPtr.h"
#include "Foundation/Exception.h"
#include <algorithm>
using Util::AbstractConfiguration;
using Util::MapConfiguration;
using Foundation::AutoPtr;
AbstractConfigurationTest::AbstractConfigurationTest(const std::string& name): CppUnit::TestCase(name)
{
}
AbstractConfigurationTest::~AbstractConfigurationTest()
{
}
void AbstractConfigurationTest::testHasProperty()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
assert (pConf->hasProperty("prop1"));
assert (pConf->hasProperty("prop2"));
assert (pConf->hasProperty("prop3.string1"));
assert (!pConf->hasProperty("prop3.string3"));
assert (!pConf->hasProperty("foobar"));
}
void AbstractConfigurationTest::testGetString()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
assert (pConf->getString("prop1") == "foo");
assert (pConf->getString("prop2") == "bar");
assert (pConf->getString("prop3.string1") == "foo");
assert (pConf->getString("prop3.string2") == "bar");
assert (pConf->getString("ref1") == "foobar");
assert (pConf->getRawString("ref1") == "${prop3.string1}${prop3.string2}");
try
{
std::string res = pConf->getString("foo");
fail("nonexistent property - must throw");
}
catch (Foundation::NotFoundException&)
{
}
assert (pConf->getString("prop1", "FOO") == "foo");
assert (pConf->getString("prop2", "BAR") == "bar");
assert (pConf->getString("prop3.string1", "FOO") == "foo");
assert (pConf->getString("prop3.string2", "BAR") == "bar");
assert (pConf->getString("prop3.string3", "FOOBAR") == "FOOBAR");
}
void AbstractConfigurationTest::testGetInt()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
assert (pConf->getInt("prop4.int1") == 42);
assert (pConf->getInt("prop4.int2") == -42);
assert (pConf->getInt("prop4.hex") == 0x1f);
assert (pConf->getInt("ref2") == 42);
try
{
int x = pConf->getInt("prop1");
fail("not a number - must throw");
}
catch (Foundation::SyntaxException&)
{
}
assert (pConf->getInt("prop4.int1", 100) == 42);
assert (pConf->getInt("prop4.int2", 100) == -42);
assert (pConf->getInt("prop4.int3", 100) == 100);
}
void AbstractConfigurationTest::testGetDouble()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
assert (pConf->getDouble("prop4.double1") == 1);
assert (pConf->getDouble("prop4.double2") == -1.5);
try
{
double x = pConf->getDouble("prop1");
fail("not a number - must throw");
}
catch (Foundation::SyntaxException&)
{
}
assert (pConf->getDouble("prop4.double1", 123.5) == 1);
assert (pConf->getDouble("prop4.double2", 123.5) == -1.5);
assert (pConf->getDouble("prop4.double3", 123.5) == 123.5);
}
void AbstractConfigurationTest::testGetBool()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
assert (pConf->getBool("prop4.bool1"));
assert (!pConf->getBool("prop4.bool2"));
assert (pConf->getBool("prop4.bool3"));
assert (!pConf->getBool("prop4.bool4"));
assert (pConf->getBool("prop4.bool5"));
assert (!pConf->getBool("prop4.bool6"));
assert (pConf->getBool("prop4.bool7"));
assert (!pConf->getBool("prop4.bool8"));
try
{
bool x = pConf->getBool("prop1");
fail("not a boolean - must throw");
}
catch (Foundation::SyntaxException&)
{
}
assert (pConf->getBool("prop4.bool1", false));
assert (!pConf->getBool("prop4.bool2", true));
assert (pConf->getBool("prop4.boolx", true));
assert (!pConf->getBool("prop4.booly", false));
}
void AbstractConfigurationTest::testExpand()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
assert (pConf->getString("ref1") == "foobar");
assert (pConf->getInt("ref2") == 42);
try
{
std::string s = pConf->getString("ref3");
fail("circular reference - must throw");
}
catch (Foundation::CircularReferenceException&)
{
}
assert (pConf->getString("ref5") == "${refx}");
assert (pConf->getString("ref6") == "${refx}");
assert (pConf->expand("answer=${prop4.int1}") == "answer=42");
assert (pConf->expand("bool5='${prop4.bool5}'") == "bool5='Yes'");
assert (pConf->expand("undef='${undef}'") == "undef='${undef}'");
assert (pConf->expand("deep='${ref1}'") == "deep='foobar'");
assert (pConf->expand("deep='${ref7}'") == "deep='foobar'");
}
void AbstractConfigurationTest::testSetString()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
pConf->setString("set.string1", "foobar");
pConf->setString("set.string2", "");
assert (pConf->getString("set.string1") == "foobar");
assert (pConf->getString("set.string2") == "");
}
void AbstractConfigurationTest::testSetInt()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
pConf->setInt("set.int1", 42);
pConf->setInt("set.int2", -100);
assert (pConf->getInt("set.int1") == 42);
assert (pConf->getInt("set.int2") == -100);
}
void AbstractConfigurationTest::testSetDouble()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
pConf->setDouble("set.double1", 1.5);
pConf->setDouble("set.double2", -1.5);
assert (pConf->getDouble("set.double1") == 1.5);
assert (pConf->getDouble("set.double2") == -1.5);
}
void AbstractConfigurationTest::testSetBool()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
pConf->setBool("set.bool1", true);
pConf->setBool("set.bool2", false);
assert (pConf->getBool("set.bool1"));
assert (!pConf->getBool("set.bool2"));
}
void AbstractConfigurationTest::testKeys()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
AbstractConfiguration::Keys keys;
pConf->keys(keys);
assert (keys.size() == 11);
assert (std::find(keys.begin(), keys.end(), "prop1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop3") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop4") != keys.end());
assert (std::find(keys.begin(), keys.end(), "ref1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "ref2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "ref3") != keys.end());
assert (std::find(keys.begin(), keys.end(), "ref4") != keys.end());
assert (std::find(keys.begin(), keys.end(), "ref5") != keys.end());
assert (std::find(keys.begin(), keys.end(), "ref6") != keys.end());
assert (std::find(keys.begin(), keys.end(), "ref7") != keys.end());
pConf->keys("prop1", keys);
assert (keys.empty());
pConf->keys("prop3", keys);
assert (keys.size() == 2);
assert (std::find(keys.begin(), keys.end(), "string1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "string2") != keys.end());
}
AbstractConfiguration* AbstractConfigurationTest::createConfiguration() const
{
AbstractConfiguration* pConfig = new MapConfiguration;
pConfig->setString("prop1", "foo");
pConfig->setString("prop2", "bar");
pConfig->setString("prop3.string1", "foo");
pConfig->setString("prop3.string2", "bar");
pConfig->setString("prop4.int1", "42");
pConfig->setString("prop4.int2", "-42");
pConfig->setString("prop4.hex", "0x1f");
pConfig->setString("prop4.double1", "1");
pConfig->setString("prop4.double2", "-1.5");
pConfig->setString("prop4.bool1", "1");
pConfig->setString("prop4.bool2", "0");
pConfig->setString("prop4.bool3", "True");
pConfig->setString("prop4.bool4", "FALSE");
pConfig->setString("prop4.bool5", "Yes");
pConfig->setString("prop4.bool6", "no");
pConfig->setString("prop4.bool7", "ON");
pConfig->setString("prop4.bool8", "Off");
pConfig->setString("ref1", "${prop3.string1}${prop3.string2}");
pConfig->setString("ref2", "${prop4.int1}");
pConfig->setString("ref3", "${ref4}");
pConfig->setString("ref4", "${ref3}");
pConfig->setString("ref5", "${refx}");
pConfig->setString("ref6", "${refx");
pConfig->setString("ref7", "${ref1}");
return pConfig;
}
void AbstractConfigurationTest::setUp()
{
}
void AbstractConfigurationTest::tearDown()
{
}
CppUnit::Test* AbstractConfigurationTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AbstractConfigurationTest");
CppUnit_addTest(pSuite, AbstractConfigurationTest, testHasProperty);
CppUnit_addTest(pSuite, AbstractConfigurationTest, testGetString);
CppUnit_addTest(pSuite, AbstractConfigurationTest, testGetInt);
CppUnit_addTest(pSuite, AbstractConfigurationTest, testGetDouble);
CppUnit_addTest(pSuite, AbstractConfigurationTest, testGetBool);
CppUnit_addTest(pSuite, AbstractConfigurationTest, testExpand);
CppUnit_addTest(pSuite, AbstractConfigurationTest, testSetString);
CppUnit_addTest(pSuite, AbstractConfigurationTest, testSetInt);
CppUnit_addTest(pSuite, AbstractConfigurationTest, testSetDouble);
CppUnit_addTest(pSuite, AbstractConfigurationTest, testSetBool);
CppUnit_addTest(pSuite, AbstractConfigurationTest, testKeys);
return pSuite;
}

View File

@@ -0,0 +1,76 @@
//
// AbstractConfigurationTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/AbstractConfigurationTest.h#2 $
//
// Definition of the AbstractConfigurationTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef AbstractConfigurationTest_INCLUDED
#define AbstractConfigurationTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
#include "Util/AbstractConfiguration.h"
class AbstractConfigurationTest: public CppUnit::TestCase
{
public:
AbstractConfigurationTest(const std::string& name);
~AbstractConfigurationTest();
void testHasProperty();
void testGetString();
void testGetInt();
void testGetDouble();
void testGetBool();
void testExpand();
void testSetString();
void testSetInt();
void testSetDouble();
void testSetBool();
void testKeys();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
Util::AbstractConfiguration* createConfiguration() const;
};
#endif // AbstractConfigurationTest_INCLUDED

View File

@@ -0,0 +1,207 @@
//
// ConfigurationMapperTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/ConfigurationMapperTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "ConfigurationMapperTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/ConfigurationMapper.h"
#include "Util/MapConfiguration.h"
#include "Foundation/AutoPtr.h"
#include "Foundation/Exception.h"
#include <algorithm>
using Util::AbstractConfiguration;
using Util::ConfigurationMapper;
using Util::MapConfiguration;
using Foundation::AutoPtr;
ConfigurationMapperTest::ConfigurationMapperTest(const std::string& name): CppUnit::TestCase(name)
{
}
ConfigurationMapperTest::~ConfigurationMapperTest()
{
}
void ConfigurationMapperTest::testMapper1()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
AutoPtr<AbstractConfiguration> pMapper = new ConfigurationMapper("", "", pConf);
assert (pMapper->hasProperty("config.value1"));
assert (pMapper->hasProperty("config.value2"));
AbstractConfiguration::Keys keys;
pMapper->keys(keys);
assert (keys.size() == 1);
assert (std::find(keys.begin(), keys.end(), "config") != keys.end());
pMapper->keys("config", keys);
assert (keys.size() == 3);
assert (std::find(keys.begin(), keys.end(), "value1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "value2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "sub") != keys.end());
assert (pMapper->getString("config.value1") == "v1");
assert (pMapper->getString("config.sub.value2") == "v4");
pMapper->setString("config.value3", "v5");
assert (pMapper->getString("config.value3") == "v5");
assert (pConf->getString("config.value3") == "v5");
}
void ConfigurationMapperTest::testMapper2()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
AutoPtr<AbstractConfiguration> pMapper = new ConfigurationMapper("config", "root.conf", pConf);
assert (pMapper->hasProperty("root.conf.value1"));
assert (pMapper->hasProperty("root.conf.value2"));
AbstractConfiguration::Keys keys;
pMapper->keys(keys);
assert (keys.size() == 1);
assert (std::find(keys.begin(), keys.end(), "root") != keys.end());
pMapper->keys("root", keys);
assert (keys.size() == 1);
assert (std::find(keys.begin(), keys.end(), "conf") != keys.end());
pMapper->keys("root.conf", keys);
assert (keys.size() == 3);
assert (std::find(keys.begin(), keys.end(), "value1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "value2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "sub") != keys.end());
assert (pMapper->getString("root.conf.value1") == "v1");
assert (pMapper->getString("root.conf.sub.value2") == "v4");
pMapper->setString("root.conf.value3", "v5");
assert (pMapper->getString("root.conf.value3") == "v5");
assert (pConf->getString("config.value3") == "v5");
}
void ConfigurationMapperTest::testMapper3()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
AutoPtr<AbstractConfiguration> pMapper = new ConfigurationMapper("", "root", pConf);
assert (pMapper->hasProperty("root.config.value1"));
assert (pMapper->hasProperty("root.config.value2"));
AbstractConfiguration::Keys keys;
pMapper->keys(keys);
assert (keys.size() == 1);
assert (std::find(keys.begin(), keys.end(), "root") != keys.end());
pMapper->keys("root", keys);
assert (keys.size() == 1);
assert (std::find(keys.begin(), keys.end(), "config") != keys.end());
pMapper->keys("root.config", keys);
assert (keys.size() == 3);
assert (std::find(keys.begin(), keys.end(), "value1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "value2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "sub") != keys.end());
assert (pMapper->getString("root.config.value1") == "v1");
assert (pMapper->getString("root.config.sub.value2") == "v4");
pMapper->setString("root.config.value3", "v5");
assert (pMapper->getString("root.config.value3") == "v5");
assert (pConf->getString("config.value3") == "v5");
}
void ConfigurationMapperTest::testMapper4()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
AutoPtr<AbstractConfiguration> pMapper = new ConfigurationMapper("config", "", pConf);
assert (pMapper->hasProperty("value1"));
assert (pMapper->hasProperty("value2"));
AbstractConfiguration::Keys keys;
pMapper->keys(keys);
assert (keys.size() == 3);
assert (std::find(keys.begin(), keys.end(), "value1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "value2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "sub") != keys.end());
assert (pMapper->getString("value1") == "v1");
assert (pMapper->getString("sub.value2") == "v4");
pMapper->setString("value3", "v5");
assert (pMapper->getString("value3") == "v5");
assert (pConf->getString("config.value3") == "v5");
}
AbstractConfiguration* ConfigurationMapperTest::createConfiguration() const
{
AbstractConfiguration* pConfig = new MapConfiguration;
pConfig->setString("config.value1", "v1");
pConfig->setString("config.value2", "v2");
pConfig->setString("config.sub.value1", "v3");
pConfig->setString("config.sub.value2", "v4");
return pConfig;
}
void ConfigurationMapperTest::setUp()
{
}
void ConfigurationMapperTest::tearDown()
{
}
CppUnit::Test* ConfigurationMapperTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConfigurationMapperTest");
CppUnit_addTest(pSuite, ConfigurationMapperTest, testMapper1);
CppUnit_addTest(pSuite, ConfigurationMapperTest, testMapper2);
CppUnit_addTest(pSuite, ConfigurationMapperTest, testMapper3);
CppUnit_addTest(pSuite, ConfigurationMapperTest, testMapper4);
return pSuite;
}

View File

@@ -0,0 +1,69 @@
//
// ConfigurationMapperTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/ConfigurationMapperTest.h#2 $
//
// Definition of the ConfigurationMapperTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ConfigurationMapperTest_INCLUDED
#define ConfigurationMapperTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
#include "Util/AbstractConfiguration.h"
class ConfigurationMapperTest: public CppUnit::TestCase
{
public:
ConfigurationMapperTest(const std::string& name);
~ConfigurationMapperTest();
void testMapper1();
void testMapper2();
void testMapper3();
void testMapper4();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
Util::AbstractConfiguration* createConfiguration() const;
};
#endif // ConfigurationMapperTest_INCLUDED

View File

@@ -0,0 +1,64 @@
//
// ConfigurationTestSuite.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/ConfigurationTestSuite.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "ConfigurationTestSuite.h"
#include "AbstractConfigurationTest.h"
#include "ConfigurationViewTest.h"
#include "ConfigurationMapperTest.h"
#include "MapConfigurationTest.h"
#include "LayeredConfigurationTest.h"
#include "SystemConfigurationTest.h"
#include "IniFileConfigurationTest.h"
#include "PropertyFileConfigurationTest.h"
#include "XMLConfigurationTest.h"
#include "FilesystemConfigurationTest.h"
#include "LoggingConfiguratorTest.h"
CppUnit::Test* ConfigurationTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConfigurationTestSuite");
pSuite->addTest(AbstractConfigurationTest::suite());
pSuite->addTest(ConfigurationViewTest::suite());
pSuite->addTest(ConfigurationMapperTest::suite());
pSuite->addTest(MapConfigurationTest::suite());
pSuite->addTest(LayeredConfigurationTest::suite());
pSuite->addTest(SystemConfigurationTest::suite());
pSuite->addTest(IniFileConfigurationTest::suite());
pSuite->addTest(PropertyFileConfigurationTest::suite());
pSuite->addTest(XMLConfigurationTest::suite());
pSuite->addTest(FilesystemConfigurationTest::suite());
pSuite->addTest(LoggingConfiguratorTest::suite());
return pSuite;
}

View File

@@ -0,0 +1,51 @@
//
// ConfigurationTestSuite.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/ConfigurationTestSuite.h#2 $
//
// Definition of the ConfigurationTestSuite class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ConfigurationTestSuite_INCLUDED
#define ConfigurationTestSuite_INCLUDED
#ifndef CppUnit_TestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
#endif
class ConfigurationTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // ConfigurationTestSuite_INCLUDED

View File

@@ -0,0 +1,155 @@
//
// ConfigurationViewTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/ConfigurationViewTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "ConfigurationViewTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/MapConfiguration.h"
#include "Foundation/AutoPtr.h"
#include "Foundation/Exception.h"
#include <algorithm>
using Util::AbstractConfiguration;
using Util::MapConfiguration;
using Foundation::AutoPtr;
ConfigurationViewTest::ConfigurationViewTest(const std::string& name): CppUnit::TestCase(name)
{
}
ConfigurationViewTest::~ConfigurationViewTest()
{
}
void ConfigurationViewTest::testView()
{
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
AutoPtr<AbstractConfiguration> pView = pConf->createView("");
assert (pView->hasProperty("prop1"));
assert (pView->hasProperty("prop2"));
AbstractConfiguration::Keys keys;
pView->keys(keys);
assert (keys.size() == 4);
assert (std::find(keys.begin(), keys.end(), "prop1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop3") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop4") != keys.end());
assert (pView->getString("prop1") == "foo");
assert (pView->getString("prop3.string1") == "foo");
pView->setString("prop5", "foobar");
assert (pConf->getString("prop5") == "foobar");
pView = pConf->createView("prop1");
pView->keys(keys);
assert (keys.empty());
assert (pView->hasProperty("prop1"));
pView->setString("prop11", "foobar");
assert (pConf->getString("prop1.prop11") == "foobar");
pView = pConf->createView("prop3");
pView->keys(keys);
assert (keys.size() == 2);
assert (std::find(keys.begin(), keys.end(), "string1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "string2") != keys.end());
assert (pView->getString("string1") == "foo");
assert (pView->getString("string2") == "bar");
pView->setString("string3", "foobar");
assert (pConf->getString("prop3.string3") == "foobar");
pView = pConf->createView("prop4");
pView->keys(keys);
assert (keys.size() == 2);
assert (std::find(keys.begin(), keys.end(), "prop41") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop42") != keys.end());
assert (pView->getString("prop41.string1") == "FOO");
assert (pView->getString("prop42.string2") == "Bar");
pView = pConf->createView("prop4.prop41");
pView->keys(keys);
assert (keys.size() == 2);
assert (std::find(keys.begin(), keys.end(), "string1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "string2") != keys.end());
assert (pView->getString("string1") == "FOO");
assert (pView->getString("string2") == "BAR");
pView->setString("string3", "foobar");
assert (pConf->getString("prop4.prop41.string3") == "foobar");
}
AbstractConfiguration* ConfigurationViewTest::createConfiguration() const
{
AbstractConfiguration* pConfig = new MapConfiguration;
pConfig->setString("prop1", "foo");
pConfig->setString("prop2", "bar");
pConfig->setString("prop3.string1", "foo");
pConfig->setString("prop3.string2", "bar");
pConfig->setString("prop4.prop41.string1", "FOO");
pConfig->setString("prop4.prop41.string2", "BAR");
pConfig->setString("prop4.prop42.string1", "Foo");
pConfig->setString("prop4.prop42.string2", "Bar");
return pConfig;
}
void ConfigurationViewTest::setUp()
{
}
void ConfigurationViewTest::tearDown()
{
}
CppUnit::Test* ConfigurationViewTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConfigurationViewTest");
CppUnit_addTest(pSuite, ConfigurationViewTest, testView);
return pSuite;
}

View File

@@ -0,0 +1,66 @@
//
// ConfigurationViewTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/ConfigurationViewTest.h#2 $
//
// Definition of the ConfigurationViewTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ConfigurationViewTest_INCLUDED
#define ConfigurationViewTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
#include "Util/AbstractConfiguration.h"
class ConfigurationViewTest: public CppUnit::TestCase
{
public:
ConfigurationViewTest(const std::string& name);
~ConfigurationViewTest();
void testView();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
Util::AbstractConfiguration* createConfiguration() const;
};
#endif // ConfigurationViewTest_INCLUDED

View File

@@ -0,0 +1,39 @@
//
// Driver.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/Driver.cpp#2 $
//
// Console-based test driver for Poco Util.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "CppUnit/TestRunner.h"
#include "UtilTestSuite.h"
CppUnitMain(UtilTestSuite)

View File

@@ -0,0 +1,119 @@
//
// FilesystemConfigurationTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/FilesystemConfigurationTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "FilesystemConfigurationTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/FilesystemConfiguration.h"
#include "Foundation/AutoPtr.h"
#include <algorithm>
using Util::FilesystemConfiguration;
using Util::AbstractConfiguration;
using Foundation::AutoPtr;
FilesystemConfigurationTest::FilesystemConfigurationTest(const std::string& name): CppUnit::TestCase(name)
{
}
FilesystemConfigurationTest::~FilesystemConfigurationTest()
{
}
void FilesystemConfigurationTest::testFilesystemConfiguration()
{
AutoPtr<FilesystemConfiguration> config = new FilesystemConfiguration("TestConfiguration");
config->setString("logging.loggers.root.channel.class", "ConsoleChannel");
config->setString("logging.loggers.app.name", "Application");
config->setString("logging.loggers.app.channel", "c1");
config->setString("logging.formatters.f1.class", "PatternFormatter");
config->setString("logging.formatters.f1.pattern", "[%p] %t");
config->setString("logging.channels.c1.class", "ConsoleChannel");
assert (config->getString("logging.loggers.root.channel.class") == "ConsoleChannel");
assert (config->getString("logging.loggers.app.name") == "Application");
assert (config->getString("logging.loggers.app.channel") == "c1");
assert (config->getString("logging.formatters.f1.class") == "PatternFormatter");
assert (config->getString("logging.formatters.f1.pattern") == "[%p] %t");
config->setString("logging.loggers.app.channel", "c2");
assert (config->getString("logging.loggers.app.channel") == "c2");
AbstractConfiguration::Keys keys;
config->keys(keys);
assert (keys.size() == 1);
assert (std::find(keys.begin(), keys.end(), "logging") != keys.end());
config->keys("logging", keys);
assert (keys.size() == 3);
assert (std::find(keys.begin(), keys.end(), "loggers") != keys.end());
assert (std::find(keys.begin(), keys.end(), "formatters") != keys.end());
assert (std::find(keys.begin(), keys.end(), "channels") != keys.end());
config->keys("logging.formatters", keys);
assert (keys.size() == 1);
assert (std::find(keys.begin(), keys.end(), "f1") != keys.end());
config->keys("logging.formatters.f1", keys);
assert (keys.size() == 2);
assert (std::find(keys.begin(), keys.end(), "class") != keys.end());
assert (std::find(keys.begin(), keys.end(), "pattern") != keys.end());
assert (config->hasProperty("logging.loggers.root.channel.class"));
config->clear();
assert (!config->hasProperty("logging.loggers.root.channel.class"));
}
void FilesystemConfigurationTest::setUp()
{
}
void FilesystemConfigurationTest::tearDown()
{
}
CppUnit::Test* FilesystemConfigurationTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FilesystemConfigurationTest");
CppUnit_addTest(pSuite, FilesystemConfigurationTest, testFilesystemConfiguration);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// FilesystemConfigurationTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/FilesystemConfigurationTest.h#2 $
//
// Definition of the FilesystemConfigurationTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef FilesystemConfigurationTest_INCLUDED
#define FilesystemConfigurationTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class FilesystemConfigurationTest: public CppUnit::TestCase
{
public:
FilesystemConfigurationTest(const std::string& name);
~FilesystemConfigurationTest();
void testFilesystemConfiguration();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // FilesystemConfigurationTest_INCLUDED

View File

@@ -0,0 +1,131 @@
//
// HelpFormatterTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/HelpFormatterTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "HelpFormatterTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/Option.h"
#include "Util/OptionSet.h"
#include "Util/HelpFormatter.h"
#include <iostream>
using Util::Option;
using Util::OptionSet;
using Util::HelpFormatter;
HelpFormatterTest::HelpFormatterTest(const std::string& name): CppUnit::TestCase(name)
{
}
HelpFormatterTest::~HelpFormatterTest()
{
}
void HelpFormatterTest::testHelpFormatter()
{
OptionSet set;
set.addOption(
Option("include-dir", "I", "specify a search path for locating header files")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("library-dir", "L", "specify a search path for locating library files")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("output", "o", "specify the output file", true)
.argument("file", true));
set.addOption(
Option("verbose", "v")
.description("enable verbose mode")
.required(false)
.repeatable(false));
set.addOption(
Option("optimize", "O")
.description("enable optimization")
.required(false)
.repeatable(false)
.argument("level", false));
HelpFormatter formatter(set);
formatter.format(std::cout);
formatter.setCommand("cc");
formatter.format(std::cout);
formatter.setUsage("OPTIONS FILES");
formatter.setHeader("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
"Vivamus volutpat imperdiet massa. Nulla at ipsum vitae risus facilisis posuere. "
"Cras convallis, lacus ac vulputate convallis, metus nisl euismod ligula, "
"ac euismod diam wisi in dolor.\nMauris vitae leo.");
formatter.setFooter("Cras semper mollis tellus. Mauris eleifend mauris et lorem. "
"Etiam odio dolor, fermentum quis, mollis nec, sodales sed, tellus. "
"Quisque consequat orci eu augue. Aliquam ac nibh ac neque hendrerit iaculis.");
formatter.format(std::cout);
formatter.setUnixStyle(false);
formatter.format(std::cout);
formatter.setHeader("");
formatter.setFooter("tab: a\tb\tcde\tf\n\ta\n\t\tb");
formatter.format(std::cout);
}
void HelpFormatterTest::setUp()
{
}
void HelpFormatterTest::tearDown()
{
}
CppUnit::Test* HelpFormatterTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HelpFormatterTest");
CppUnit_addTest(pSuite, HelpFormatterTest, testHelpFormatter);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// HelpFormatterTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/HelpFormatterTest.h#2 $
//
// Definition of the HelpFormatterTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef HelpFormatterTest_INCLUDED
#define HelpFormatterTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class HelpFormatterTest: public CppUnit::TestCase
{
public:
HelpFormatterTest(const std::string& name);
~HelpFormatterTest();
void testHelpFormatter();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // HelpFormatterTest_INCLUDED

View File

@@ -0,0 +1,138 @@
//
// IniFileConfigurationTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/IniFileConfigurationTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "IniFileConfigurationTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/IniFileConfiguration.h"
#include "Foundation/AutoPtr.h"
#include "Foundation/Exception.h"
#include <sstream>
#include <algorithm>
using Util::IniFileConfiguration;
using Util::AbstractConfiguration;
using Foundation::AutoPtr;
using Foundation::NotImplementedException;
using Foundation::NotFoundException;
IniFileConfigurationTest::IniFileConfigurationTest(const std::string& name): CppUnit::TestCase(name)
{
}
IniFileConfigurationTest::~IniFileConfigurationTest()
{
}
void IniFileConfigurationTest::testLoad()
{
static const std::string iniFile =
"; comment\n"
" ; comment \n"
"prop1=value1\n"
" prop2 = value2 \n"
"[section1]\n"
"prop1 = value3\r\n"
"\tprop2=value4\r\n"
";prop3=value7\r\n"
"\n"
" [ section 2 ]\n"
"prop1 = value 5\n"
"\t \n"
"Prop2 = value6";
std::istringstream istr(iniFile);
AutoPtr<IniFileConfiguration> pConf = new IniFileConfiguration(istr);
assert (pConf->getString("prop1") == "value1");
assert (pConf->getString("prop2") == "value2");
assert (pConf->getString("section1.prop1") == "value3");
assert (pConf->getString("Section1.Prop2") == "value4");
assert (pConf->getString("section 2.prop1") == "value 5");
assert (pConf->getString("section 2.prop2") == "value6");
assert (pConf->getString("SECTION 2.PROP2") == "value6");
AbstractConfiguration::Keys keys;
pConf->keys(keys);
assert (keys.size() == 4);
assert (std::find(keys.begin(), keys.end(), "prop1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "section1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "section 2") != keys.end());
pConf->keys("Section1", keys);
assert (keys.size() == 2);
assert (std::find(keys.begin(), keys.end(), "prop1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop2") != keys.end());
try
{
pConf->setString("foo", "bar");
fail("Not supported - must throw");
}
catch (NotImplementedException&)
{
}
try
{
std::string s = pConf->getString("foo");
fail("No property - must throw");
}
catch (NotFoundException&)
{
}
}
void IniFileConfigurationTest::setUp()
{
}
void IniFileConfigurationTest::tearDown()
{
}
CppUnit::Test* IniFileConfigurationTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("IniFileConfigurationTest");
CppUnit_addTest(pSuite, IniFileConfigurationTest, testLoad);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// IniFileConfigurationTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/IniFileConfigurationTest.h#2 $
//
// Definition of the IniFileConfigurationTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef IniFileConfigurationTest_INCLUDED
#define IniFileConfigurationTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class IniFileConfigurationTest: public CppUnit::TestCase
{
public:
IniFileConfigurationTest(const std::string& name);
~IniFileConfigurationTest();
void testLoad();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // IniFileConfigurationTest_INCLUDED

View File

@@ -0,0 +1,170 @@
//
// LayeredConfigurationTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/LayeredConfigurationTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "LayeredConfigurationTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/LayeredConfiguration.h"
#include "Util/MapConfiguration.h"
#include "Foundation/AutoPtr.h"
#include "Foundation/Exception.h"
#include <algorithm>
using Util::AbstractConfiguration;
using Util::LayeredConfiguration;
using Util::MapConfiguration;
using Foundation::AutoPtr;
using Foundation::NotFoundException;
using Foundation::RuntimeException;
LayeredConfigurationTest::LayeredConfigurationTest(const std::string& name): CppUnit::TestCase(name)
{
}
LayeredConfigurationTest::~LayeredConfigurationTest()
{
}
void LayeredConfigurationTest::testEmpty()
{
AutoPtr<LayeredConfiguration> pLC = new LayeredConfiguration;
AbstractConfiguration::Keys keys;
pLC->keys(keys);
assert (keys.empty());
assert (!pLC->hasProperty("foo"));
try
{
pLC->setString("foo", "bar");
fail("empty LayeredConfiguration - must throw");
}
catch (RuntimeException&)
{
}
try
{
std::string s = pLC->getString("foo");
fail("empty LayeredConfiguration - must throw");
}
catch (NotFoundException&)
{
}
}
void LayeredConfigurationTest::testOneLayer()
{
AutoPtr<LayeredConfiguration> pLC = new LayeredConfiguration;
AutoPtr<MapConfiguration> pMC = new MapConfiguration;
pMC->setString("prop1", "value1");
pMC->setString("prop2", "value2");
pLC->add(pMC);
AbstractConfiguration::Keys keys;
pLC->keys(keys);
assert (keys.size() == 2);
assert (std::find(keys.begin(), keys.end(), "prop1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop2") != keys.end());
assert (pLC->getString("prop1") == "value1");
assert (pLC->getString("prop2") == "value2");
pLC->setString("prop3", "value3");
assert (pLC->getString("prop3") == "value3");
}
void LayeredConfigurationTest::testTwoLayers()
{
AutoPtr<LayeredConfiguration> pLC = new LayeredConfiguration;
AutoPtr<MapConfiguration> pMC1 = new MapConfiguration;
AutoPtr<MapConfiguration> pMC2 = new MapConfiguration;
pMC1->setString("prop1", "value1");
pMC1->setString("prop2", "value2");
pMC2->setString("prop2", "value3");
pMC2->setString("prop3", "value4");
pLC->add(pMC1);
pLC->add(pMC2);
AbstractConfiguration::Keys keys;
pLC->keys(keys);
assert (keys.size() == 3);
assert (std::find(keys.begin(), keys.end(), "prop1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop3") != keys.end());
assert (pLC->getString("prop1") == "value1");
assert (pLC->getString("prop2") == "value2");
assert (pLC->getString("prop3") == "value4");
pLC->setString("prop4", "value4");
assert (pLC->getString("prop4") == "value4");
assert (!pMC1->hasProperty("prop4"));
assert (pMC2->hasProperty("prop4"));
pLC->setString("prop1", "value11");
assert (pLC->getString("prop1") == "value1");
assert (pMC2->getString("prop1") == "value11");
}
void LayeredConfigurationTest::setUp()
{
}
void LayeredConfigurationTest::tearDown()
{
}
CppUnit::Test* LayeredConfigurationTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("LayeredConfigurationTest");
CppUnit_addTest(pSuite, LayeredConfigurationTest, testEmpty);
CppUnit_addTest(pSuite, LayeredConfigurationTest, testOneLayer);
CppUnit_addTest(pSuite, LayeredConfigurationTest, testTwoLayers);
return pSuite;
}

View File

@@ -0,0 +1,66 @@
//
// LayeredConfigurationTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/LayeredConfigurationTest.h#2 $
//
// Definition of the LayeredConfigurationTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef LayeredConfigurationTest_INCLUDED
#define LayeredConfigurationTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class LayeredConfigurationTest: public CppUnit::TestCase
{
public:
LayeredConfigurationTest(const std::string& name);
~LayeredConfigurationTest();
void testEmpty();
void testOneLayer();
void testTwoLayers();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // LayeredConfigurationTest_INCLUDED

View File

@@ -0,0 +1,324 @@
//
// LoggingConfiguratorTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/LoggingConfiguratorTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "LoggingConfiguratorTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/LoggingConfigurator.h"
#include "Util/PropertyFileConfiguration.h"
#include "Foundation/LoggingRegistry.h"
#include "Foundation/ConsoleChannel.h"
#include "Foundation/FileChannel.h"
#include "Foundation/SplitterChannel.h"
#include "Foundation/FormattingChannel.h"
#include "Foundation/PatternFormatter.h"
#include "Foundation/Logger.h"
#include "Foundation/Message.h"
#include "Foundation/AutoPtr.h"
#include <sstream>
using Util::LoggingConfigurator;
using Util::PropertyFileConfiguration;
using Foundation::LoggingRegistry;
using Foundation::Channel;
using Foundation::ConsoleChannel;
using Foundation::FileChannel;
using Foundation::SplitterChannel;
using Foundation::FormattingChannel;
using Foundation::PatternFormatter;
using Foundation::Logger;
using Foundation::Message;
using Foundation::AutoPtr;
LoggingConfiguratorTest::LoggingConfiguratorTest(const std::string& name): CppUnit::TestCase(name)
{
}
LoggingConfiguratorTest::~LoggingConfiguratorTest()
{
}
void LoggingConfiguratorTest::testConfigurator()
{
static const std::string config =
"logging.loggers.root.channel = c1\n"
"logging.loggers.root.level = warning\n"
"logging.loggers.l1.name = logger1\n"
"logging.loggers.l1.channel.class = FileChannel\n"
"logging.loggers.l1.channel.pattern = %s: [%p] %t\n"
"logging.loggers.l1.channel.path = logfile.log\n"
"logging.loggers.l1.level = information\n"
"logging.loggers.l2.name = logger2\n"
"logging.loggers.l2.channel.class = SplitterChannel\n"
"logging.loggers.l2.channel.channel1 = c2\n"
"logging.loggers.l2.channel.channel2 = c3\n"
"logging.loggers.l2.level = debug\n"
"logging.channels.c1.class = ConsoleChannel\n"
"logging.channels.c1.formatter = f1\n"
"logging.channels.c2.class = FileChannel\n"
"logging.channels.c2.path = ${system.tempDir}/sample.log\n"
"logging.channels.c2.formatter.class = PatternFormatter\n"
"logging.channels.c2.formatter.pattern = %s: {%p} %t\n"
"logging.channels.c3.class = ConsoleChannel\n"
"logging.channels.c3.pattern = %s: [%p] %t\n"
"logging.formatters.f1.class = PatternFormatter\n"
"logging.formatters.f1.pattern = %s-[%p] %t\n"
"logging.formatters.f1.times = UTC\n";
std::istringstream istr(config);
AutoPtr<PropertyFileConfiguration> pConfig = new PropertyFileConfiguration(istr);
LoggingConfigurator configurator;
configurator.configure(pConfig);
Logger& root = Logger::get("");
assert (root.getLevel() == Message::PRIO_WARNING);
FormattingChannel* pFC = dynamic_cast<FormattingChannel*>(root.getChannel());
assertNotNull (pFC);
assertNotNull (dynamic_cast<ConsoleChannel*>(pFC->getChannel()));
assertNotNull (dynamic_cast<PatternFormatter*>(pFC->getFormatter()));
assert (static_cast<PatternFormatter*>(pFC->getFormatter())->getProperty("pattern") == "%s-[%p] %t");
Logger& logger1 = Logger::get("logger1");
assert (logger1.getLevel() == Message::PRIO_INFORMATION);
pFC = dynamic_cast<FormattingChannel*>(logger1.getChannel());
assertNotNull (pFC);
assertNotNull (dynamic_cast<FileChannel*>(pFC->getChannel()));
assertNotNull (dynamic_cast<PatternFormatter*>(pFC->getFormatter()));
assert (static_cast<PatternFormatter*>(pFC->getFormatter())->getProperty("pattern") == "%s: [%p] %t");
Logger& logger2 = Logger::get("logger2");
assert (logger2.getLevel() == Message::PRIO_DEBUG);
assertNotNull (dynamic_cast<SplitterChannel*>(logger2.getChannel()));
}
void LoggingConfiguratorTest::testBadConfiguration1()
{
// this is mainly testing for memory leaks in case of
// a bad configuration.
static const std::string config =
"logging.loggers.root.channel = c1\n"
"logging.loggers.root.level = warning\n"
"logging.loggers.l1.name = logger1\n"
"logging.loggers.l1.channel.class = FileChannel\n"
"logging.loggers.l1.channel.pattern = %s: [%p] %t\n"
"logging.loggers.l1.channel.path = logfile.log\n"
"logging.loggers.l1.level = information\n"
"logging.loggers.l2.name = logger2\n"
"logging.loggers.l2.channel.class = UnknownChannel\n"
"logging.loggers.l2.level = debug\n"
"logging.channels.c1.class = ConsoleChannel\n"
"logging.channels.c1.formatter = f1\n"
"logging.channels.c2.class = FileChannel\n"
"logging.channels.c2.path = ${system.tempDir}/sample.log\n"
"logging.channels.c2.formatter.class = PatternFormatter\n"
"logging.channels.c2.formatter.pattern = %s: {%p} %t\n"
"logging.channels.c3.class = ConsoleChannel\n"
"logging.channels.c3.pattern = %s: [%p] %t\n"
"logging.formatters.f1.class = PatternFormatter\n"
"logging.formatters.f1.pattern = %s-[%p] %t\n"
"logging.formatters.f1.times = UTC\n";
std::istringstream istr(config);
AutoPtr<PropertyFileConfiguration> pConfig = new PropertyFileConfiguration(istr);
LoggingConfigurator configurator;
try
{
configurator.configure(pConfig);
fail("bad configuration - must throw");
}
catch (Foundation::Exception&)
{
}
}
void LoggingConfiguratorTest::testBadConfiguration2()
{
// this is mainly testing for memory leaks in case of
// a bad configuration.
static const std::string config =
"logging.loggers.root.channel = c1\n"
"logging.loggers.root.level = unknown\n"
"logging.loggers.l1.name = logger1\n"
"logging.loggers.l1.channel.class = FileChannel\n"
"logging.loggers.l1.channel.pattern = %s: [%p] %t\n"
"logging.loggers.l1.channel.path = logfile.log\n"
"logging.loggers.l1.level = information\n"
"logging.loggers.l2.name = logger2\n"
"logging.loggers.l2.channel.class = SplitterChannel\n"
"logging.loggers.l2.level = debug\n"
"logging.channels.c1.class = ConsoleChannel\n"
"logging.channels.c1.formatter = f1\n"
"logging.channels.c2.class = FileChannel\n"
"logging.channels.c2.path = ${system.tempDir}/sample.log\n"
"logging.channels.c2.formatter.class = PatternFormatter\n"
"logging.channels.c2.formatter.pattern = %s: {%p} %t\n"
"logging.channels.c3.class = ConsoleChannel\n"
"logging.channels.c3.pattern = %s: [%p] %t\n"
"logging.formatters.f1.class = PatternFormatter\n"
"logging.formatters.f1.pattern = %s-[%p] %t\n"
"logging.formatters.f1.times = UTC\n";
std::istringstream istr(config);
AutoPtr<PropertyFileConfiguration> pConfig = new PropertyFileConfiguration(istr);
LoggingConfigurator configurator;
try
{
configurator.configure(pConfig);
fail("bad configuration - must throw");
}
catch (Foundation::Exception&)
{
}
}
void LoggingConfiguratorTest::testBadConfiguration3()
{
// this is mainly testing for memory leaks in case of
// a bad configuration.
static const std::string config =
"logging.loggers.root.channel = c1\n"
"logging.loggers.root.level = warning\n"
"logging.loggers.l1.name = logger1\n"
"logging.loggers.l1.channel.class = FileChannel\n"
"logging.loggers.l1.channel.pattern = %s: [%p] %t\n"
"logging.loggers.l1.channel.path = logfile.log\n"
"logging.loggers.l1.level = information\n"
"logging.loggers.l2.name = logger2\n"
"logging.loggers.l2.channel.class = UnknownChannel\n"
"logging.loggers.l2.level = debug\n"
"logging.channels.c1.class = ConsoleChannel\n"
"logging.channels.c1.formatter = f1\n"
"logging.channels.c2.class = FileChannel\n"
"logging.channels.c2.path = ${system.tempDir}/sample.log\n"
"logging.channels.c2.formatter.class = UnknownFormatter\n"
"logging.channels.c2.formatter.pattern = %s: {%p} %t\n"
"logging.channels.c3.class = ConsoleChannel\n"
"logging.channels.c3.pattern = %s: [%p] %t\n"
"logging.formatters.f1.class = PatternFormatter\n"
"logging.formatters.f1.pattern = %s-[%p] %t\n"
"logging.formatters.f1.times = UTC\n";
std::istringstream istr(config);
AutoPtr<PropertyFileConfiguration> pConfig = new PropertyFileConfiguration(istr);
LoggingConfigurator configurator;
try
{
configurator.configure(pConfig);
fail("bad configuration - must throw");
}
catch (Foundation::Exception&)
{
}
}
void LoggingConfiguratorTest::testBadConfiguration4()
{
// this is mainly testing for memory leaks in case of
// a bad configuration.
static const std::string config =
"logging.loggers.root.channel = c1\n"
"logging.loggers.root.level = warning\n"
"logging.loggers.l1.name = logger1\n"
"logging.loggers.l1.channel.class = FileChannel\n"
"logging.loggers.l1.channel.pattern = %s: [%p] %t\n"
"logging.loggers.l1.channel.path = logfile.log\n"
"logging.loggers.l1.level = information\n"
"logging.loggers.l2.name = logger2\n"
"logging.loggers.l2.channel.class = UnknownChannel\n"
"logging.loggers.l2.level = debug\n"
"logging.channels.c1.class = ConsoleChannel\n"
"logging.channels.c1.formatter = f1\n"
"logging.channels.c2.class = FileChannel\n"
"logging.channels.c2.path = ${system.tempDir}/sample.log\n"
"logging.channels.c2.formatter.class = PatternFormatter\n"
"logging.channels.c2.formatter.pattern = %s: {%p} %t\n"
"logging.channels.c2.formatter.unknown = FOO\n"
"logging.channels.c3.class = ConsoleChannel\n"
"logging.channels.c3.pattern = %s: [%p] %t\n"
"logging.formatters.f1.class = PatternFormatter\n"
"logging.formatters.f1.pattern = %s-[%p] %t\n"
"logging.formatters.f1.times = UTC\n";
std::istringstream istr(config);
AutoPtr<PropertyFileConfiguration> pConfig = new PropertyFileConfiguration(istr);
LoggingConfigurator configurator;
try
{
configurator.configure(pConfig);
fail("bad configuration - must throw");
}
catch (Foundation::Exception&)
{
}
}
void LoggingConfiguratorTest::setUp()
{
LoggingRegistry::defaultRegistry().clear();
}
void LoggingConfiguratorTest::tearDown()
{
}
CppUnit::Test* LoggingConfiguratorTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("LoggingConfiguratorTest");
CppUnit_addTest(pSuite, LoggingConfiguratorTest, testConfigurator);
CppUnit_addTest(pSuite, LoggingConfiguratorTest, testBadConfiguration1);
CppUnit_addTest(pSuite, LoggingConfiguratorTest, testBadConfiguration2);
CppUnit_addTest(pSuite, LoggingConfiguratorTest, testBadConfiguration3);
CppUnit_addTest(pSuite, LoggingConfiguratorTest, testBadConfiguration4);
return pSuite;
}

View File

@@ -0,0 +1,68 @@
//
// LoggingConfiguratorTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/LoggingConfiguratorTest.h#2 $
//
// Definition of the LoggingConfiguratorTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef LoggingConfiguratorTest_INCLUDED
#define LoggingConfiguratorTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class LoggingConfiguratorTest: public CppUnit::TestCase
{
public:
LoggingConfiguratorTest(const std::string& name);
~LoggingConfiguratorTest();
void testConfigurator();
void testBadConfiguration1();
void testBadConfiguration2();
void testBadConfiguration3();
void testBadConfiguration4();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // LoggingConfiguratorTest_INCLUDED

View File

@@ -0,0 +1,83 @@
//
// MapConfigurationTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/MapConfigurationTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "MapConfigurationTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/MapConfiguration.h"
#include "Foundation/AutoPtr.h"
using Util::MapConfiguration;
using Foundation::AutoPtr;
MapConfigurationTest::MapConfigurationTest(const std::string& name): CppUnit::TestCase(name)
{
}
MapConfigurationTest::~MapConfigurationTest()
{
}
void MapConfigurationTest::testClear()
{
AutoPtr<MapConfiguration> pConf = new MapConfiguration;
pConf->setString("foo", "bar");
assert (pConf->hasProperty("foo"));
pConf->clear();
assert (!pConf->hasProperty("foo"));
}
void MapConfigurationTest::setUp()
{
}
void MapConfigurationTest::tearDown()
{
}
CppUnit::Test* MapConfigurationTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MapConfigurationTest");
CppUnit_addTest(pSuite, MapConfigurationTest, testClear);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// MapConfigurationTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/MapConfigurationTest.h#2 $
//
// Definition of the MapConfigurationTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef MapConfigurationTest_INCLUDED
#define MapConfigurationTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class MapConfigurationTest: public CppUnit::TestCase
{
public:
MapConfigurationTest(const std::string& name);
~MapConfigurationTest();
void testClear();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // MapConfigurationTest_INCLUDED

View File

@@ -0,0 +1,298 @@
//
// OptionProcessorTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/OptionProcessorTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "OptionProcessorTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/Option.h"
#include "Util/OptionSet.h"
#include "Util/OptionProcessor.h"
#include "Util/OptionException.h"
using Util::Option;
using Util::OptionSet;
using Util::OptionProcessor;
OptionProcessorTest::OptionProcessorTest(const std::string& name): CppUnit::TestCase(name)
{
}
OptionProcessorTest::~OptionProcessorTest()
{
}
void OptionProcessorTest::testUnix()
{
OptionSet set;
set.addOption(
Option("include-dir", "I", "specify a search path for locating header files")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("library-dir", "L", "specify a search path for locating library files")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("output", "o", "specify the output file", true)
.argument("file", true));
set.addOption(
Option("verbose", "v")
.description("enable verbose mode")
.required(false)
.repeatable(false));
set.addOption(
Option("optimize", "O")
.description("enable optimization")
.required(false)
.repeatable(false)
.argument("level", false)
.group("mode"));
set.addOption(
Option("debug", "g")
.description("generate debug information")
.required(false)
.repeatable(false)
.group("mode"));
set.addOption(
Option("info", "i")
.description("print information")
.required(false)
.repeatable(false));
OptionProcessor p1(set);
std::string name;
std::string value;
assert (p1.process("-I/usr/include", name, value));
assert (name == "include-dir");
assert (value == "/usr/include");
assert (p1.process("--include:/usr/local/include", name, value));
assert (name == "include-dir");
assert (value == "/usr/local/include");
assert (p1.process("--lib=/usr/local/lib", name, value));
assert (name == "library-dir");
assert (value == "/usr/local/lib");
assert (p1.process("-ofile", name, value));
assert (name == "output");
assert (value == "file");
assert (!p1.process("src/file.cpp", name, value));
assert (!p1.process("/src/file.cpp", name, value));
try
{
p1.process("--output:file", name, value);
fail("duplicate - must throw");
}
catch (Util::DuplicateOptionException&)
{
}
assert (p1.process("-g", name, value));
assert (name == "debug");
assert (value == "");
try
{
p1.process("--optimize", name, value);
fail("incompatible - must throw");
}
catch (Util::IncompatibleOptionsException&)
{
}
try
{
p1.process("-x", name, value);
fail("unknown option - must throw");
}
catch (Util::UnknownOptionException&)
{
}
try
{
p1.process("--in", name, value);
fail("ambiguous option - must throw");
}
catch (Util::AmbiguousOptionException&)
{
}
}
void OptionProcessorTest::testDefault()
{
OptionSet set;
set.addOption(
Option("include-dir", "I", "specify a search path for locating header files")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("library-dir", "L", "specify a search path for locating library files")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("output", "o", "specify the output file", true)
.argument("file", true));
set.addOption(
Option("verbose", "v")
.description("enable verbose mode")
.required(false)
.repeatable(false));
set.addOption(
Option("optimize", "O")
.description("enable optimization")
.required(false)
.repeatable(false)
.argument("level", false)
.group("mode"));
set.addOption(
Option("debug", "g")
.description("generate debug information")
.required(false)
.repeatable(false)
.group("mode"));
set.addOption(
Option("info", "i")
.description("print information")
.required(false)
.repeatable(false));
OptionProcessor p1(set);
p1.setUnixStyle(false);
std::string name;
std::string value;
assert (p1.process("/Inc:/usr/include", name, value));
assert (name == "include-dir");
assert (value == "/usr/include");
assert (p1.process("/include:/usr/local/include", name, value));
assert (name == "include-dir");
assert (value == "/usr/local/include");
assert (p1.process("/lib=/usr/local/lib", name, value));
assert (name == "library-dir");
assert (value == "/usr/local/lib");
assert (p1.process("/out:file", name, value));
assert (name == "output");
assert (value == "file");
assert (!p1.process("src/file.cpp", name, value));
assert (!p1.process("\\src\\file.cpp", name, value));
try
{
p1.process("/output:file", name, value);
fail("duplicate - must throw");
}
catch (Util::DuplicateOptionException&)
{
}
assert (p1.process("/debug", name, value));
assert (name == "debug");
assert (value == "");
try
{
p1.process("/OPT", name, value);
fail("incompatible - must throw");
}
catch (Util::IncompatibleOptionsException&)
{
}
try
{
p1.process("/x", name, value);
fail("unknown option - must throw");
}
catch (Util::UnknownOptionException&)
{
}
try
{
p1.process("/in", name, value);
fail("ambiguous option - must throw");
}
catch (Util::AmbiguousOptionException&)
{
}
}
void OptionProcessorTest::setUp()
{
}
void OptionProcessorTest::tearDown()
{
}
CppUnit::Test* OptionProcessorTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("OptionProcessorTest");
CppUnit_addTest(pSuite, OptionProcessorTest, testUnix);
CppUnit_addTest(pSuite, OptionProcessorTest, testDefault);
return pSuite;
}

View File

@@ -0,0 +1,65 @@
//
// OptionProcessorTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/OptionProcessorTest.h#2 $
//
// Definition of the OptionProcessorTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef OptionProcessorTest_INCLUDED
#define OptionProcessorTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class OptionProcessorTest: public CppUnit::TestCase
{
public:
OptionProcessorTest(const std::string& name);
~OptionProcessorTest();
void testUnix();
void testDefault();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // OptionProcessorTest_INCLUDED

View File

@@ -0,0 +1,137 @@
//
// OptionSetTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/OptionSetTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "OptionSetTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/OptionSet.h"
#include "Util/Option.h"
#include "Util/OptionException.h"
using Util::OptionSet;
using Util::Option;
OptionSetTest::OptionSetTest(const std::string& name): CppUnit::TestCase(name)
{
}
OptionSetTest::~OptionSetTest()
{
}
void OptionSetTest::testOptionSet()
{
OptionSet set;
set.addOption(
Option("include-dir", "I", "specify a search path for locating header files")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("library-dir", "L", "specify a search path for locating library files")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("insert", "it", "insert something")
.required(false)
.repeatable(true)
.argument("path"));
set.addOption(
Option("item", "", "insert something")
.required(false)
.repeatable(true)
.argument("path"));
assert (set.hasOption("include", false));
assert (set.hasOption("I", true));
assert (set.hasOption("Include", true));
assert (set.hasOption("insert", false));
assert (set.hasOption("it", true));
assert (set.hasOption("Insert", false));
assert (set.hasOption("item", false));
assert (!set.hasOption("i", false));
assert (!set.hasOption("in", false));
const Option& opt1 = set.getOption("include");
assert (opt1.fullName() == "include-dir");
const Option& opt2 = set.getOption("item");
assert (opt2.fullName() == "item");
const Option& opt3 = set.getOption("I", true);
assert (opt3.fullName() == "include-dir");
try
{
set.getOption("in");
fail("ambiguous - must throw");
}
catch (Util::AmbiguousOptionException&)
{
}
try
{
set.getOption("i");
fail("ambiguous - must throw");
}
catch (Util::AmbiguousOptionException&)
{
}
}
void OptionSetTest::setUp()
{
}
void OptionSetTest::tearDown()
{
}
CppUnit::Test* OptionSetTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("OptionSetTest");
CppUnit_addTest(pSuite, OptionSetTest, testOptionSet);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// OptionSetTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/OptionSetTest.h#2 $
//
// Definition of the OptionSetTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef OptionSetTest_INCLUDED
#define OptionSetTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class OptionSetTest: public CppUnit::TestCase
{
public:
OptionSetTest(const std::string& name);
~OptionSetTest();
void testOptionSet();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // OptionSetTest_INCLUDED

View File

@@ -0,0 +1,361 @@
//
// OptionTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/OptionTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "OptionTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/Option.h"
#include "Util/OptionException.h"
using Util::Option;
OptionTest::OptionTest(const std::string& name): CppUnit::TestCase(name)
{
}
OptionTest::~OptionTest()
{
}
void OptionTest::testOption()
{
Option incOpt = Option("include-dir", "I", "specify an include search path")
.required(false)
.repeatable(true)
.argument("path");
Option libOpt = Option("library-dir", "L", "specify a library search path", false)
.repeatable(true)
.argument("path");
Option outOpt = Option("output", "o", "specify the output file", true)
.argument("file", true);
Option vrbOpt = Option("verbose", "v")
.description("enable verbose mode")
.required(false)
.repeatable(false);
Option optOpt = Option("optimize", "O")
.description("enable optimization")
.required(false)
.repeatable(false)
.argument("level", false);
assert (incOpt.shortName() == "I");
assert (incOpt.fullName() == "include-dir");
assert (incOpt.repeatable());
assert (!incOpt.required());
assert (incOpt.argumentName() == "path");
assert (incOpt.argumentRequired());
assert (incOpt.takesArgument());
assert (libOpt.shortName() == "L");
assert (libOpt.fullName() == "library-dir");
assert (libOpt.repeatable());
assert (!libOpt.required());
assert (libOpt.argumentName() == "path");
assert (libOpt.argumentRequired());
assert (incOpt.takesArgument());
assert (outOpt.shortName() == "o");
assert (outOpt.fullName() == "output");
assert (!outOpt.repeatable());
assert (outOpt.required());
assert (outOpt.argumentName() == "file");
assert (outOpt.argumentRequired());
assert (incOpt.takesArgument());
assert (vrbOpt.shortName() == "v");
assert (vrbOpt.fullName() == "verbose");
assert (!vrbOpt.repeatable());
assert (!vrbOpt.required());
assert (!vrbOpt.argumentRequired());
assert (!vrbOpt.takesArgument());
assert (optOpt.shortName() == "O");
assert (optOpt.fullName() == "optimize");
assert (!optOpt.repeatable());
assert (!optOpt.required());
assert (optOpt.argumentName() == "level");
assert (optOpt.takesArgument());
assert (!optOpt.argumentRequired());
}
void OptionTest::testMatches1()
{
Option incOpt = Option("include-dir", "I", "specify an include search path")
.required(false)
.repeatable(true)
.argument("path");
assert (incOpt.matchesShort("Iinclude"));
assert (incOpt.matchesFull("include:include"));
assert (incOpt.matchesFull("include-dir:include"));
assert (incOpt.matchesFull("inc=include"));
assert (incOpt.matchesFull("INCLUDE=include"));
assert (incOpt.matchesFull("include"));
assert (incOpt.matchesShort("I"));
assert (incOpt.matchesFull("i"));
assert (!incOpt.matchesFull("include-dir2=include"));
assert (!incOpt.matchesShort("linclude"));
}
void OptionTest::testMatches2()
{
Option incOpt = Option("include-dir", "", "specify an include search path")
.required(false)
.repeatable(true)
.argument("path");
assert (!incOpt.matchesShort("Iinclude"));
assert (incOpt.matchesFull("include:include"));
assert (incOpt.matchesFull("include-dir:include"));
assert (incOpt.matchesFull("inc=include"));
assert (incOpt.matchesFull("INCLUDE=include"));
assert (incOpt.matchesFull("I"));
assert (incOpt.matchesFull("i"));
assert (!incOpt.matchesFull("include-dir2=include"));
assert (!incOpt.matchesShort("linclude"));
}
void OptionTest::testProcess1()
{
Option incOpt = Option("include-dir", "I", "specify an include search path")
.required(false)
.repeatable(true)
.argument("path");
std::string arg;
incOpt.process("Iinclude", arg);
assert (arg == "include");
incOpt.process("I/usr/include", arg);
assert (arg == "/usr/include");
incOpt.process("include:/usr/local/include", arg);
assert (arg == "/usr/local/include");
incOpt.process("include=/proj/include", arg);
assert (arg == "/proj/include");
incOpt.process("include-dir=/usr/include", arg);
assert (arg == "/usr/include");
incOpt.process("Include-dir:/proj/include", arg);
assert (arg == "/proj/include");
try
{
incOpt.process("I", arg);
fail("argument required - must throw");
}
catch (Util::MissingArgumentException&)
{
}
try
{
incOpt.process("Include", arg);
fail("argument required - must throw");
}
catch (Util::MissingArgumentException&)
{
}
try
{
incOpt.process("Llib", arg);
fail("wrong option - must throw");
}
catch (Util::UnknownOptionException&)
{
}
Option vrbOpt = Option("verbose", "v")
.description("enable verbose mode")
.required(false)
.repeatable(false);
vrbOpt.process("v", arg);
assert (arg.empty());
vrbOpt.process("verbose", arg);
assert (arg.empty());
try
{
vrbOpt.process("v2", arg);
fail("no argument expected - must throw");
}
catch (Util::UnexpectedArgumentException&)
{
}
try
{
vrbOpt.process("verbose:2", arg);
fail("no argument expected - must throw");
}
catch (Util::UnexpectedArgumentException&)
{
}
Option optOpt = Option("optimize", "O")
.description("enable optimization")
.required(false)
.repeatable(false)
.argument("level", false);
optOpt.process("O", arg);
assert (arg.empty());
optOpt.process("O2", arg);
assert (arg == "2");
optOpt.process("optimize:1", arg);
assert (arg == "1");
optOpt.process("opt", arg);
assert (arg.empty());
optOpt.process("opt=3", arg);
assert (arg == "3");
optOpt.process("opt=", arg);
assert (arg.empty());
}
void OptionTest::testProcess2()
{
Option incOpt = Option("include-dir", "", "specify an include search path")
.required(false)
.repeatable(true)
.argument("path");
std::string arg;
incOpt.process("include:/usr/local/include", arg);
assert (arg == "/usr/local/include");
incOpt.process("include=/proj/include", arg);
assert (arg == "/proj/include");
incOpt.process("include-dir=/usr/include", arg);
assert (arg == "/usr/include");
incOpt.process("Include-dir:/proj/include", arg);
assert (arg == "/proj/include");
try
{
incOpt.process("Iinclude", arg);
fail("unknown option - must throw");
}
catch (Util::UnknownOptionException&)
{
}
try
{
incOpt.process("I", arg);
fail("argument required - must throw");
}
catch (Util::MissingArgumentException&)
{
}
try
{
incOpt.process("Include", arg);
fail("argument required - must throw");
}
catch (Util::MissingArgumentException&)
{
}
try
{
incOpt.process("Llib", arg);
fail("wrong option - must throw");
}
catch (Util::UnknownOptionException&)
{
}
Option vrbOpt = Option("verbose", "")
.description("enable verbose mode")
.required(false)
.repeatable(false);
vrbOpt.process("v", arg);
assert (arg.empty());
vrbOpt.process("verbose", arg);
assert (arg.empty());
try
{
vrbOpt.process("v2", arg);
fail("no argument expected - must throw");
}
catch (Util::UnknownOptionException&)
{
}
try
{
vrbOpt.process("verbose:2", arg);
fail("no argument expected - must throw");
}
catch (Util::UnexpectedArgumentException&)
{
}
}
void OptionTest::setUp()
{
}
void OptionTest::tearDown()
{
}
CppUnit::Test* OptionTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("OptionTest");
CppUnit_addTest(pSuite, OptionTest, testOption);
CppUnit_addTest(pSuite, OptionTest, testMatches1);
CppUnit_addTest(pSuite, OptionTest, testMatches2);
CppUnit_addTest(pSuite, OptionTest, testProcess1);
CppUnit_addTest(pSuite, OptionTest, testProcess2);
return pSuite;
}

View File

@@ -0,0 +1,68 @@
//
// OptionTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/OptionTest.h#2 $
//
// Definition of the OptionTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef OptionTest_INCLUDED
#define OptionTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class OptionTest: public CppUnit::TestCase
{
public:
OptionTest(const std::string& name);
~OptionTest();
void testOption();
void testMatches1();
void testMatches2();
void testProcess1();
void testProcess2();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // OptionTest_INCLUDED

View File

@@ -0,0 +1,50 @@
//
// OptionsTestSuite.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/OptionsTestSuite.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "OptionsTestSuite.h"
#include "OptionTest.h"
#include "OptionSetTest.h"
#include "HelpFormatterTest.h"
#include "OptionProcessorTest.h"
CppUnit::Test* OptionsTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("OptionsTestSuite");
pSuite->addTest(OptionTest::suite());
pSuite->addTest(OptionSetTest::suite());
pSuite->addTest(HelpFormatterTest::suite());
pSuite->addTest(OptionProcessorTest::suite());
return pSuite;
}

View File

@@ -0,0 +1,51 @@
//
// OptionsTestSuite.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/OptionsTestSuite.h#2 $
//
// Definition of the OptionsTestSuite class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef OptionsTestSuite_INCLUDED
#define OptionsTestSuite_INCLUDED
#ifndef CppUnit_TestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
#endif
class OptionsTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // OptionsTestSuite_INCLUDED

View File

@@ -0,0 +1,146 @@
//
// PropertyFileConfigurationTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/PropertyFileConfigurationTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "PropertyFileConfigurationTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/PropertyFileConfiguration.h"
#include "Foundation/AutoPtr.h"
#include "Foundation/Exception.h"
#include <sstream>
#include <algorithm>
using Util::PropertyFileConfiguration;
using Util::AbstractConfiguration;
using Foundation::AutoPtr;
using Foundation::NotFoundException;
PropertyFileConfigurationTest::PropertyFileConfigurationTest(const std::string& name): CppUnit::TestCase(name)
{
}
PropertyFileConfigurationTest::~PropertyFileConfigurationTest()
{
}
void PropertyFileConfigurationTest::testLoad()
{
static const std::string propFile =
"! comment\n"
"! comment\n"
"prop1=value1\n"
"prop2 = value2 \n"
"prop3.prop31: value3\n"
"# comment\n"
" prop3.prop32: value 4\n"
"prop3.prop33: value5, value6,\\\n"
"value7, value8,\\\r\n"
"value9\n"
"prop4 = escaped[\\t\\r\\n\\f]\n"
"#prop4 = foo\n"
"prop5:foo";
std::istringstream istr(propFile);
AutoPtr<PropertyFileConfiguration> pConf = new PropertyFileConfiguration(istr);
assert (pConf->getString("prop1") == "value1");
assert (pConf->getString("prop2") == "value2");
assert (pConf->getString("prop3.prop31") == "value3");
assert (pConf->getString("prop3.prop32") == "value 4");
assert (pConf->getString("prop3.prop33") == "value5, value6, value7, value8, value9");
assert (pConf->getString("prop4") == "escaped[\t\r\n\f]");
assert (pConf->getString("prop5") == "foo");
AbstractConfiguration::Keys keys;
pConf->keys(keys);
assert (keys.size() == 5);
assert (std::find(keys.begin(), keys.end(), "prop1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop3") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop4") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop5") != keys.end());
pConf->keys("prop3", keys);
assert (keys.size() == 3);
assert (std::find(keys.begin(), keys.end(), "prop31") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop32") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop33") != keys.end());
try
{
std::string s = pConf->getString("foo");
fail("No property - must throw");
}
catch (NotFoundException&)
{
}
}
void PropertyFileConfigurationTest::testSave()
{
AutoPtr<PropertyFileConfiguration> pConf = new PropertyFileConfiguration;
pConf->setString("prop1", "value1");
pConf->setInt("prop2", 42);
std::ostringstream ostr;
pConf->save(ostr);
std::string propFile = ostr.str();
assert (propFile == "prop1: value1\n"
"prop2: 42\n");
}
void PropertyFileConfigurationTest::setUp()
{
}
void PropertyFileConfigurationTest::tearDown()
{
}
CppUnit::Test* PropertyFileConfigurationTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("PropertyFileConfigurationTest");
CppUnit_addTest(pSuite, PropertyFileConfigurationTest, testLoad);
CppUnit_addTest(pSuite, PropertyFileConfigurationTest, testSave);
return pSuite;
}

View File

@@ -0,0 +1,65 @@
//
// PropertyFileConfigurationTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/PropertyFileConfigurationTest.h#2 $
//
// Definition of the PropertyFileConfigurationTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef PropertyFileConfigurationTest_INCLUDED
#define PropertyFileConfigurationTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class PropertyFileConfigurationTest: public CppUnit::TestCase
{
public:
PropertyFileConfigurationTest(const std::string& name);
~PropertyFileConfigurationTest();
void testLoad();
void testSave();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // PropertyFileConfigurationTest_INCLUDED

View File

@@ -0,0 +1,124 @@
//
// SystemConfigurationTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/SystemConfigurationTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SystemConfigurationTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/SystemConfiguration.h"
#include "Foundation/AutoPtr.h"
#include "Foundation/Exception.h"
#include "Foundation/Environment.h"
#include "Foundation/Path.h"
#include <algorithm>
using Util::SystemConfiguration;
using Util::AbstractConfiguration;
using Foundation::AutoPtr;
using Foundation::Environment;
using Foundation::Path;
using Foundation::InvalidAccessException;
using Foundation::NotFoundException;
SystemConfigurationTest::SystemConfigurationTest(const std::string& name): CppUnit::TestCase(name)
{
}
SystemConfigurationTest::~SystemConfigurationTest()
{
}
void SystemConfigurationTest::testProperties()
{
AutoPtr<SystemConfiguration> pConf = new SystemConfiguration;
assert (pConf->getString("system.osName") == Environment::osName());
assert (pConf->getString("system.osVersion") == Environment::osVersion());
assert (pConf->getString("system.osArchitecture") == Environment::osArchitecture());
assert (pConf->getString("system.nodeName") == Environment::nodeName());
assert (pConf->getString("system.currentDir") == Path::current());
assert (pConf->getString("system.homeDir") == Path::home());
assert (pConf->getString("system.tempDir") == Path::temp());
#if defined(POCO_OS_FAMILY_WINDOWS)
std::string home = pConf->getString("system.env.HOMEPATH");
#else
std::string home = pConf->getString("system.env.HOME");
#endif
assert (!home.empty());
}
void SystemConfigurationTest::testKeys()
{
AutoPtr<SystemConfiguration> pConf = new SystemConfiguration;
AbstractConfiguration::Keys keys;
pConf->keys(keys);
assert (keys.size() == 1);
assert (std::find(keys.begin(), keys.end(), "system") != keys.end());
pConf->keys("system", keys);
assert (keys.size() == 8);
assert (std::find(keys.begin(), keys.end(), "osName") != keys.end());
assert (std::find(keys.begin(), keys.end(), "osVersion") != keys.end());
assert (std::find(keys.begin(), keys.end(), "osArchitecture") != keys.end());
assert (std::find(keys.begin(), keys.end(), "nodeName") != keys.end());
assert (std::find(keys.begin(), keys.end(), "currentDir") != keys.end());
assert (std::find(keys.begin(), keys.end(), "homeDir") != keys.end());
assert (std::find(keys.begin(), keys.end(), "tempDir") != keys.end());
assert (std::find(keys.begin(), keys.end(), "env") != keys.end());
}
void SystemConfigurationTest::setUp()
{
}
void SystemConfigurationTest::tearDown()
{
}
CppUnit::Test* SystemConfigurationTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SystemConfigurationTest");
CppUnit_addTest(pSuite, SystemConfigurationTest, testProperties);
CppUnit_addTest(pSuite, SystemConfigurationTest, testKeys);
return pSuite;
}

View File

@@ -0,0 +1,65 @@
//
// SystemConfigurationTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/SystemConfigurationTest.h#2 $
//
// Definition of the SystemConfigurationTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef SystemConfigurationTest_INCLUDED
#define SystemConfigurationTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class SystemConfigurationTest: public CppUnit::TestCase
{
public:
SystemConfigurationTest(const std::string& name);
~SystemConfigurationTest();
void testProperties();
void testKeys();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // SystemConfigurationTest_INCLUDED

View File

@@ -0,0 +1,52 @@
//
// UtilTestSuite.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/UtilTestSuite.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "UtilTestSuite.h"
#include "ConfigurationTestSuite.h"
#include "OptionsTestSuite.h"
#if defined(_WIN32)
#include "WindowsTestSuite.h"
#endif
CppUnit::Test* UtilTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConfigurationTestSuite");
pSuite->addTest(ConfigurationTestSuite::suite());
pSuite->addTest(OptionsTestSuite::suite());
#if defined(_WIN32)
pSuite->addTest(WindowsTestSuite::suite());
#endif
return pSuite;
}

View File

@@ -0,0 +1,51 @@
//
// UtilTestSuite.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/UtilTestSuite.h#2 $
//
// Definition of the UtilTestSuite class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef UtilTestSuite_INCLUDED
#define UtilTestSuite_INCLUDED
#ifndef CppUnit_TestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
#endif
class UtilTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // UtilTestSuite_INCLUDED

View File

@@ -0,0 +1,50 @@
//
// WinDriver.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/WinDriver.cpp#2 $
//
// Windows test driver for Poco Util.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "WinTestRunner/WinTestRunner.h"
#include "UtilTestSuite.h"
class TestDriver: public CppUnit::WinTestRunnerApp
{
void TestMain()
{
CppUnit::WinTestRunner runner;
runner.addTest(UtilTestSuite::suite());
runner.run();
}
};
TestDriver theDriver;

View File

@@ -0,0 +1,100 @@
//
// WinRegistryTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/WinRegistryTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "WinRegistryTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/WinRegistryKey.h"
#include "Foundation/Environment.h"
using Util::WinRegistryKey;
using Foundation::Environment;
WinRegistryTest::WinRegistryTest(const std::string& name): CppUnit::TestCase(name)
{
}
WinRegistryTest::~WinRegistryTest()
{
}
void WinRegistryTest::testRegistry()
{
WinRegistryKey regKey("HKEY_CURRENT_USER\\Software\\Applied Informatics\\Test");
regKey.setString("name1", "value1");
assert (regKey.getString("name1") == "value1");
regKey.setString("name1", "Value1");
assert (regKey.getString("name1") == "Value1");
regKey.setString("name2", "value2");
assert (regKey.getString("name2") == "value2");
assert (regKey.exists("name1"));
assert (regKey.exists("name2"));
assert (regKey.exists());
Environment::set("FOO", "bar");
regKey.setStringExpand("name3", "%FOO%");
assert (regKey.getStringExpand("name3") == "bar");
regKey.setInt("name4", 42);
assert (regKey.getInt("name4") == 42);
assert (regKey.exists("name4"));
regKey.deleteValue("name4");
assert (!regKey.exists("name4"));
regKey.deleteKey();
assert (!regKey.exists());
}
void WinRegistryTest::setUp()
{
}
void WinRegistryTest::tearDown()
{
}
CppUnit::Test* WinRegistryTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("WinRegistryTest");
CppUnit_addTest(pSuite, WinRegistryTest, testRegistry);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// WinRegistryTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/WinRegistryTest.h#2 $
//
// Definition of the WinRegistryTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef WinRegistryTest_INCLUDED
#define WinRegistryTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class WinRegistryTest: public CppUnit::TestCase
{
public:
WinRegistryTest(const std::string& name);
~WinRegistryTest();
void testRegistry();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // WinRegistryTest_INCLUDED

View File

@@ -0,0 +1,44 @@
//
// WindowsTestSuite.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/WindowsTestSuite.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "WindowsTestSuite.h"
#include "WinRegistryTest.h"
CppUnit::Test* WindowsTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("WindowsTestSuite");
pSuite->addTest(WinRegistryTest::suite());
return pSuite;
}

View File

@@ -0,0 +1,51 @@
//
// WindowsTestSuite.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/WindowsTestSuite.h#2 $
//
// Definition of the WindowsTestSuite class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef WindowsTestSuite_INCLUDED
#define WindowsTestSuite_INCLUDED
#ifndef CppUnit_TestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
#endif
class WindowsTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // WindowsTestSuite_INCLUDED

View File

@@ -0,0 +1,136 @@
//
// XMLConfigurationTest.cpp
//
// $Id: //poco/1.1.0/Util/testsuite/src/XMLConfigurationTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "XMLConfigurationTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Util/XMLConfiguration.h"
#include "Foundation/AutoPtr.h"
#include "Foundation/Exception.h"
#include <sstream>
#include <algorithm>
using Util::XMLConfiguration;
using Util::AbstractConfiguration;
using Foundation::AutoPtr;
using Foundation::NotImplementedException;
using Foundation::NotFoundException;
XMLConfigurationTest::XMLConfigurationTest(const std::string& name): CppUnit::TestCase(name)
{
}
XMLConfigurationTest::~XMLConfigurationTest()
{
}
void XMLConfigurationTest::testLoad()
{
static const std::string xmlFile =
"<config>"
" <prop1>value1</prop1>"
" <prop2>value2</prop2>"
" <prop3>"
" <prop4 attr='value3'/>"
" <prop4 attr='value4'/>"
" </prop3>"
" <prop5>value5</prop5>"
" <prop5>value6</prop5>"
"</config>";
std::istringstream istr(xmlFile);
AutoPtr<XMLConfiguration> pConf = new XMLConfiguration(istr);
assert (pConf->getString("prop1") == "value1");
assert (pConf->getString("prop2") == "value2");
assert (pConf->getString("prop3.prop4[@attr]") == "value3");
assert (pConf->getString("prop3.prop4[1][@attr]") == "value4");
assert (pConf->getString("prop5") == "value5");
assert (pConf->getString("prop5[0]") == "value5");
assert (pConf->getString("prop5[1]") == "value6");
AbstractConfiguration::Keys keys;
pConf->keys(keys);
assert (keys.size() == 5);
assert (std::find(keys.begin(), keys.end(), "prop1") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop2") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop3") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop5") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop5[1]") != keys.end());
pConf->keys("prop3", keys);
assert (keys.size() == 2);
assert (std::find(keys.begin(), keys.end(), "prop4") != keys.end());
assert (std::find(keys.begin(), keys.end(), "prop4[1]") != keys.end());
try
{
pConf->setString("foo", "bar");
fail("Not supported - must throw");
}
catch (NotImplementedException&)
{
}
try
{
std::string s = pConf->getString("foo");
fail("No property - must throw");
}
catch (NotFoundException&)
{
}
}
void XMLConfigurationTest::setUp()
{
}
void XMLConfigurationTest::tearDown()
{
}
CppUnit::Test* XMLConfigurationTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("XMLConfigurationTest");
CppUnit_addTest(pSuite, XMLConfigurationTest, testLoad);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// XMLConfigurationTest.h
//
// $Id: //poco/1.1.0/Util/testsuite/src/XMLConfigurationTest.h#2 $
//
// Definition of the XMLConfigurationTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef XMLConfigurationTest_INCLUDED
#define XMLConfigurationTest_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class XMLConfigurationTest: public CppUnit::TestCase
{
public:
XMLConfigurationTest(const std::string& name);
~XMLConfigurationTest();
void testLoad();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // XMLConfigurationTest_INCLUDED