summaryrefslogtreecommitdiff
path: root/icespider/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'icespider/unittests')
-rw-r--r--icespider/unittests/Jamfile.jam8
-rw-r--r--icespider/unittests/test-fcgi.ice10
-rw-r--r--icespider/unittests/testApp.cpp4
-rw-r--r--icespider/unittests/testCompile.cpp6
-rw-r--r--icespider/unittests/testFcgi.cpp83
-rw-r--r--icespider/unittests/testRoutes.json11
6 files changed, 118 insertions, 4 deletions
diff --git a/icespider/unittests/Jamfile.jam b/icespider/unittests/Jamfile.jam
index f5e8f2f..4ee2bd8 100644
--- a/icespider/unittests/Jamfile.jam
+++ b/icespider/unittests/Jamfile.jam
@@ -23,6 +23,7 @@ lib slicer-json : : : : <include>/usr/include/slicer ;
lib slicer-xml : : : : <include>/usr/include/slicer ;
lib boost_utf : : <name>boost_unit_test_framework ;
lib boost_system ;
+lib boost_filesystem ;
lib dl ;
path-constant me : . ;
@@ -81,14 +82,21 @@ run
run
testFcgi.cpp
+ test-fcgi.ice
../fcgi/cgiRequestBase.cpp
+ ../fcgi/xwwwFormUrlEncoded.cpp
+ ../fcgi/hextable.c
: : :
+ <slicer>yes
<define>BOOST_TEST_DYN_LINK
<library>testCommon
<library>../common//icespider-common
<library>../core//icespider-core
<library>boost_system
+ <library>boost_filesystem
<library>slicer
+ <library>slicer-json
+ <library>adhocutil
<include>../fcgi
: testFcgi ;
diff --git a/icespider/unittests/test-fcgi.ice b/icespider/unittests/test-fcgi.ice
new file mode 100644
index 0000000..6be9086
--- /dev/null
+++ b/icespider/unittests/test-fcgi.ice
@@ -0,0 +1,10 @@
+module TestFcgi {
+ class Complex {
+ string alpha;
+ double number;
+ bool boolean;
+ string spaces;
+ string empty;
+ };
+};
+
diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp
index fc7d66a..5f37f62 100644
--- a/icespider/unittests/testApp.cpp
+++ b/icespider/unittests/testApp.cpp
@@ -27,7 +27,7 @@ void forceEarlyChangeDir()
BOOST_AUTO_TEST_CASE( testLoadConfiguration )
{
- BOOST_REQUIRE_EQUAL(10, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size());
+ BOOST_REQUIRE_EQUAL(11, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size());
}
class TestRequest : public IHttpRequest {
@@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE( testCoreSettings )
{
BOOST_REQUIRE_EQUAL(5, routes.size());
BOOST_REQUIRE_EQUAL(1, routes[0].size());
- BOOST_REQUIRE_EQUAL(4, routes[1].size());
+ BOOST_REQUIRE_EQUAL(5, routes[1].size());
BOOST_REQUIRE_EQUAL(1, routes[2].size());
BOOST_REQUIRE_EQUAL(2, routes[3].size());
BOOST_REQUIRE_EQUAL(2, routes[4].size());
diff --git a/icespider/unittests/testCompile.cpp b/icespider/unittests/testCompile.cpp
index 4fb7827..8d1cefa 100644
--- a/icespider/unittests/testCompile.cpp
+++ b/icespider/unittests/testCompile.cpp
@@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE( testLoadConfiguration )
rc.applyDefaults(cfg, u);
BOOST_REQUIRE_EQUAL("common", cfg->name);
- BOOST_REQUIRE_EQUAL(10, cfg->routes.size());
+ BOOST_REQUIRE_EQUAL(11, cfg->routes.size());
BOOST_REQUIRE_EQUAL("/", cfg->routes["index"]->path);
BOOST_REQUIRE_EQUAL(HttpMethod::GET, cfg->routes["index"]->method);
@@ -106,6 +106,7 @@ BOOST_AUTO_TEST_CASE( testCompile )
BOOST_AUTO_TEST_CASE( testLink )
{
auto outputo = binDir / "testRoutes.o";
+ BOOST_REQUIRE(boost::filesystem::exists(outputo));
auto outputso = binDir / "testRoutes.so";
auto linkCommand = boost::algorithm::join<std::vector<std::string>>({
@@ -121,12 +122,13 @@ BOOST_AUTO_TEST_CASE( testLink )
BOOST_AUTO_TEST_CASE( testLoad )
{
auto outputso = binDir / "testRoutes.so";
+ BOOST_REQUIRE(boost::filesystem::exists(outputso));
auto lib = dlopen(outputso.c_str(), RTLD_NOW);
BOOST_TEST_INFO(dlerror());
BOOST_REQUIRE(lib);
- BOOST_REQUIRE_EQUAL(10, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size());
+ BOOST_REQUIRE_EQUAL(11, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size());
// smoke test (block ensure dlclose dones't cause segfault)
{
auto route = AdHoc::PluginManager::getDefault()->get<IceSpider::RouteHandlerFactory>("common::index");
diff --git a/icespider/unittests/testFcgi.cpp b/icespider/unittests/testFcgi.cpp
index f2a58a4..94ce092 100644
--- a/icespider/unittests/testFcgi.cpp
+++ b/icespider/unittests/testFcgi.cpp
@@ -2,7 +2,9 @@
#include <boost/test/unit_test.hpp>
#include <core.h>
+#include <definedDirs.h>
#include <cgiRequestBase.h>
+#include <test-fcgi.h>
class TestRequest : public IceSpider::CgiRequestBase {
public:
@@ -24,6 +26,24 @@ class TestRequest : public IceSpider::CgiRequestBase {
// LCOV_EXCL_STOP
};
+class TestPayloadRequest : public TestRequest {
+ public:
+ TestPayloadRequest(IceSpider::Core * c, char ** env, std::istream & s) :
+ TestRequest(c, env),
+ in(s)
+ {
+ initialize();
+ }
+
+ std::istream & getInputStream() const override
+ {
+ return in;
+ }
+
+ private:
+ std::istream & in;
+};
+
class CharPtrPtrArray : public std::vector<char *> {
public:
CharPtrPtrArray()
@@ -172,5 +192,68 @@ BOOST_AUTO_TEST_CASE( requestmethod_bad )
BOOST_REQUIRE_THROW(r.getRequestMethod(), IceSpider::Http405_MethodNotAllowed);
}
+BOOST_AUTO_TEST_CASE( postxwwwformurlencoded_simple )
+{
+ CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/x-www-form-urlencoded" });
+ std::stringstream f("value=314");
+ TestPayloadRequest r(this, env, f);
+ auto n = r.getBody<int>();
+ BOOST_REQUIRE_EQUAL(314, n);
+}
+
+BOOST_AUTO_TEST_CASE( postxwwwformurlencoded_dictionary )
+{
+ CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/x-www-form-urlencoded" });
+ std::stringstream f("alpha=abcde&number=3.14&boolean=true&spaces=This+is+a%20string.&empty=");
+ TestPayloadRequest r(this, env, f);
+ auto n = *r.getBody<IceSpider::StringMap>();
+ BOOST_REQUIRE_EQUAL(5, n.size());
+ BOOST_REQUIRE_EQUAL("abcde", n["alpha"]);
+ BOOST_REQUIRE_EQUAL("3.14", n["number"]);
+ BOOST_REQUIRE_EQUAL("true", n["boolean"]);
+ BOOST_REQUIRE_EQUAL("This is a string.", n["spaces"]);
+ BOOST_REQUIRE_EQUAL("", n["empty"]);
+}
+
+BOOST_AUTO_TEST_CASE( postxwwwformurlencoded_complex )
+{
+ CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/x-www-form-urlencoded" });
+ std::stringstream f("alpha=abcde&number=3.14&boolean=true&empty=&spaces=This+is+a%20string.");
+ TestPayloadRequest r(this, env, f);
+ auto n = *r.getBody<TestFcgi::ComplexPtr>();
+ BOOST_REQUIRE_EQUAL("abcde", n->alpha);
+ BOOST_REQUIRE_EQUAL(3.14, n->number);
+ BOOST_REQUIRE_EQUAL(true, n->boolean);
+ BOOST_REQUIRE_EQUAL("This is a string.", n->spaces);
+ BOOST_REQUIRE_EQUAL("", n->empty);
+}
+
+BOOST_AUTO_TEST_CASE( postjson_complex )
+{
+ CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/json" });
+ std::stringstream f("{\"alpha\":\"abcde\",\"number\":3.14,\"boolean\":true,\"empty\":\"\",\"spaces\":\"This is a string.\"}");
+ TestPayloadRequest r(this, env, f);
+ auto n = *r.getBody<TestFcgi::ComplexPtr>();
+ BOOST_REQUIRE_EQUAL("abcde", n->alpha);
+ BOOST_REQUIRE_EQUAL(3.14, n->number);
+ BOOST_REQUIRE_EQUAL(true, n->boolean);
+ BOOST_REQUIRE_EQUAL("This is a string.", n->spaces);
+ BOOST_REQUIRE_EQUAL("", n->empty);
+}
+
+BOOST_AUTO_TEST_CASE( postjson_dictionary )
+{
+ CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/json" });
+ std::stringstream f("{\"alpha\":\"abcde\",\"number\":\"3.14\",\"boolean\":\"true\",\"empty\":\"\",\"spaces\":\"This is a string.\"}");
+ TestPayloadRequest r(this, env, f);
+ auto n = *r.getBody<IceSpider::StringMap>();
+ BOOST_REQUIRE_EQUAL(5, n.size());
+ BOOST_REQUIRE_EQUAL("abcde", n["alpha"]);
+ BOOST_REQUIRE_EQUAL("3.14", n["number"]);
+ BOOST_REQUIRE_EQUAL("true", n["boolean"]);
+ BOOST_REQUIRE_EQUAL("This is a string.", n["spaces"]);
+ BOOST_REQUIRE_EQUAL("", n["empty"]);
+}
+
BOOST_AUTO_TEST_SUITE_END();
diff --git a/icespider/unittests/testRoutes.json b/icespider/unittests/testRoutes.json
index 13a6806..5bf002f 100644
--- a/icespider/unittests/testRoutes.json
+++ b/icespider/unittests/testRoutes.json
@@ -23,6 +23,17 @@
"method": "DELETE",
"operation": "TestIceSpider.TestApi.returnNothing"
},
+ "del2": {
+ "path": "/{s}",
+ "method": "DELETE",
+ "operation": "TestIceSpider.TestApi.returnNothing",
+ "params": {
+ "s": {
+ "source": "Body",
+ "key": "value"
+ }
+ }
+ },
"update": {
"path": "/{id}",
"method": "POST",