From 0a6ca851fd7e007e15f2b172020eb404554821ec Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 27 Oct 2016 17:16:20 +0100 Subject: Support setting a mutator function to operate on response model before returning it --- icespider/common/routes.ice | 1 + icespider/compile/routeCompiler.cpp | 6 ++++++ icespider/unittests/Jamfile.jam | 5 +++++ icespider/unittests/base2.cpp | 13 +++++++++++++ icespider/unittests/base2.h | 23 +++++++++++++++++++++++ icespider/unittests/testCompile.cpp | 3 ++- icespider/unittests/testRoutes.json | 5 +++-- 7 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 icespider/unittests/base2.cpp create mode 100644 icespider/unittests/base2.h diff --git a/icespider/common/routes.ice b/icespider/common/routes.ice index db6475d..d46d09a 100644 --- a/icespider/common/routes.ice +++ b/icespider/common/routes.ice @@ -46,6 +46,7 @@ module IceSpider { string type; OutputSerializers outputSerializers; StringSeq bases; + optional(1) string mutator; }; ["slicer:json:object"] diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp index f92d941..2cca195 100644 --- a/icespider/compile/routeCompiler.cpp +++ b/icespider/compile/routeCompiler.cpp @@ -548,6 +548,9 @@ namespace IceSpider { } } fprintbf(output, "request->getContext());\n"); + if (r->mutator) { + fprintbf(4, output, "%s(_responseModel);\n", *r->mutator); + } if (o->returnsData()) { fprintbf(4, output, "request->response(this, _responseModel);\n"); } @@ -608,6 +611,9 @@ namespace IceSpider { } fprintf(output, ";\n"); } + if (r->mutator) { + fprintbf(4, output, "%s(_responseModel);\n", *r->mutator); + } fprintbf(4, output, "request->response(this, _responseModel);\n"); } } diff --git a/icespider/unittests/Jamfile.jam b/icespider/unittests/Jamfile.jam index 1b6366d..8a0edff 100644 --- a/icespider/unittests/Jamfile.jam +++ b/icespider/unittests/Jamfile.jam @@ -40,6 +40,7 @@ alias testCommon : : run testCompile.cpp + base2.cpp : : testRoutes.json : @@ -53,12 +54,15 @@ run ../core//icespider-core ../compile//icespider-compile ../compile//icespider-compile + . + test-api ../core : testCompile : ; run testApp.cpp + base2.cpp testRoutes.json : : config/ice.properties @@ -78,6 +82,7 @@ run ../common//icespider-common test-api ../compile + . : testApp ; run diff --git a/icespider/unittests/base2.cpp b/icespider/unittests/base2.cpp new file mode 100644 index 0000000..769d78d --- /dev/null +++ b/icespider/unittests/base2.cpp @@ -0,0 +1,13 @@ +#include "base2.h" + +namespace common { + base2::base2(const IceSpider::Core *) + { + } + + void + base2::testMutate(::TestIceSpider::SomeModelPtr &) const + { + } +} + diff --git a/icespider/unittests/base2.h b/icespider/unittests/base2.h new file mode 100644 index 0000000..84ae9a3 --- /dev/null +++ b/icespider/unittests/base2.h @@ -0,0 +1,23 @@ +#ifndef ICESPIDER_TEST_BASE2_H +#define ICESPIDER_TEST_BASE2_H + +// Standard headers. +#include +#include + +// Interface headers. +#include + +namespace common { + // Base classes. + + class DLL_PUBLIC base2 { + protected: + base2(const IceSpider::Core * core); + + void testMutate(TestIceSpider::SomeModelPtr &) const; + }; // base2 +} // namespace common + +#endif + diff --git a/icespider/unittests/testCompile.cpp b/icespider/unittests/testCompile.cpp index 0d7e36c..06d9450 100644 --- a/icespider/unittests/testCompile.cpp +++ b/icespider/unittests/testCompile.cpp @@ -90,6 +90,7 @@ BOOST_AUTO_TEST_CASE( testCompile ) "-I", "/usr/lib/glib-2.0/include", "-I", "/usr/lib/glibmm-2.4/include", "-I", "/usr/lib/libxml++-2.6/include", + "-I", rootDir.string(), "-I", (rootDir.parent_path() / "core").string(), "-I", (rootDir.parent_path() / "common").string(), "-I", (rootDir.parent_path() / "xslt").string(), @@ -124,7 +125,7 @@ BOOST_AUTO_TEST_CASE( testLoad ) auto outputso = binDir / "testRoutes.so"; BOOST_REQUIRE(boost::filesystem::exists(outputso)); - auto lib = dlopen(outputso.c_str(), RTLD_NOW); + auto lib = dlopen(outputso.c_str(), RTLD_LAZY); BOOST_TEST_INFO(dlerror()); BOOST_REQUIRE(lib); diff --git a/icespider/unittests/testRoutes.json b/icespider/unittests/testRoutes.json index bc1b94f..370f821 100644 --- a/icespider/unittests/testRoutes.json +++ b/icespider/unittests/testRoutes.json @@ -1,6 +1,6 @@ { "name": "common", - "headers": [ "xsltStreamSerializer.h" ], + "headers": [ "xsltStreamSerializer.h", "base2.h" ], "routeBases": { "base1": { "proxies": ["TestIceSpider.TestApi"], @@ -17,7 +17,8 @@ "params": [ "\"xslt/transform.xslt\"" ] } }, - "bases": [ "base1" ], + "bases": [ "base1", "base2" ], + "mutator": "testMutate", "operation": "TestIceSpider.TestApi.index" }, "item": { -- cgit v1.2.3