summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-10-08 18:09:35 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-10-08 18:09:35 +0100
commite85a975c9c4b066380bb69358b218eec4cd177d3 (patch)
tree9c09ee647d1e564c4fbfd8a212bd8913ee6f2625
parentClean test app class (diff)
downloadicespider-e85a975c9c4b066380bb69358b218eec4cd177d3.tar.bz2
icespider-e85a975c9c4b066380bb69358b218eec4cd177d3.tar.xz
icespider-e85a975c9c4b066380bb69358b218eec4cd177d3.zip
Imrpove ability to load/parse properties
-rw-r--r--icespider/core/core.cpp10
-rw-r--r--icespider/core/core.h2
-rw-r--r--icespider/fcgi/main.cpp2
-rw-r--r--icespider/unittests/config/custom.properties1
-rw-r--r--icespider/unittests/testApp.cpp49
5 files changed, 57 insertions, 7 deletions
diff --git a/icespider/core/core.cpp b/icespider/core/core.cpp
index b5eec1e..077d481 100644
--- a/icespider/core/core.cpp
+++ b/icespider/core/core.cpp
@@ -17,12 +17,14 @@ namespace IceSpider {
return true;
}
- Core::Core(int argc, char ** argv)
+ Core::Core(const Ice::StringSeq & args)
{
Ice::InitializationData id;
- id.properties = Ice::createProperties(argc, argv);
- if (boost::filesystem::exists(defaultConfig)) {
- id.properties->load(defaultConfig.string());
+ id.properties = Ice::createProperties();
+ id.properties->parseCommandLineOptions("", args);
+ auto config = id.properties->getPropertyWithDefault("IceSpider.Config", defaultConfig.string());
+ if (boost::filesystem::exists(config)) {
+ id.properties->load(config);
}
communicator = Ice::initialize(id);
diff --git a/icespider/core/core.h b/icespider/core/core.h
index 77d338e..e37efd3 100644
--- a/icespider/core/core.h
+++ b/icespider/core/core.h
@@ -13,7 +13,7 @@ namespace IceSpider {
typedef std::vector<const IRouteHandler *> LengthRoutes;
typedef std::vector<LengthRoutes> Routes;
- Core(int = 0, char ** = NULL);
+ Core(const Ice::StringSeq & = {});
~Core();
void process(IHttpRequest *) const;
diff --git a/icespider/fcgi/main.cpp b/icespider/fcgi/main.cpp
index d92dc91..2c543e1 100644
--- a/icespider/fcgi/main.cpp
+++ b/icespider/fcgi/main.cpp
@@ -8,7 +8,7 @@ DLL_PUBLIC
int
main(int argc, char ** argv, char ** env)
{
- Core core(argc, argv);
+ Core core;
if (!FCGX_IsCGI()) {
FCGX_Request request;
diff --git a/icespider/unittests/config/custom.properties b/icespider/unittests/config/custom.properties
new file mode 100644
index 0000000..302ea34
--- /dev/null
+++ b/icespider/unittests/config/custom.properties
@@ -0,0 +1 @@
+InFile=something
diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp
index 67cec50..e19096f 100644
--- a/icespider/unittests/testApp.cpp
+++ b/icespider/unittests/testApp.cpp
@@ -90,7 +90,54 @@ class TestRequest : public IHttpRequest {
const HttpMethod method;
};
-BOOST_FIXTURE_TEST_SUITE(c, Core);
+class CoreWithProps : public Core {
+ public:
+ CoreWithProps() :
+ Core({
+ "--Custom.Prop=value"
+ })
+ {
+ }
+};
+
+BOOST_FIXTURE_TEST_SUITE(props, CoreWithProps);
+
+BOOST_AUTO_TEST_CASE( properties )
+{
+ BOOST_REQUIRE_EQUAL("Test",
+ this->communicator->getProperties()->getProperty("TestIceSpider.TestApi"));
+ BOOST_REQUIRE_EQUAL("value",
+ this->communicator->getProperties()->getProperty("Custom.Prop"));
+}
+
+BOOST_AUTO_TEST_SUITE_END();
+
+class CoreWithFileProps : public Core {
+ public:
+ CoreWithFileProps() :
+ Core({
+ "--IceSpider.Config=config/custom.properties",
+ "--Custom.Prop=value"
+ })
+ {
+ }
+};
+
+BOOST_FIXTURE_TEST_SUITE(fileProps, CoreWithFileProps);
+
+BOOST_AUTO_TEST_CASE( properties )
+{
+ BOOST_REQUIRE_EQUAL("",
+ this->communicator->getProperties()->getProperty("TestIceSpider.TestApi"));
+ BOOST_REQUIRE_EQUAL("something",
+ this->communicator->getProperties()->getProperty("InFile"));
+ BOOST_REQUIRE_EQUAL("value",
+ this->communicator->getProperties()->getProperty("Custom.Prop"));
+}
+
+BOOST_AUTO_TEST_SUITE_END();
+
+BOOST_FIXTURE_TEST_SUITE(defaultProps, Core);
BOOST_AUTO_TEST_CASE( testCoreSettings )
{