diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-30 12:17:55 +0000 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-30 12:17:55 +0000 | 
| commit | ccbcb92c5e45fb7f8c5fc488cdbbf79498af963a (patch) | |
| tree | 63139838ca21ab38d3c7add260445a465976e5b8 | |
| parent | 32bit compat fix (diff) | |
| download | icespider-ccbcb92c5e45fb7f8c5fc488cdbbf79498af963a.tar.bz2 icespider-ccbcb92c5e45fb7f8c5fc488cdbbf79498af963a.tar.xz icespider-ccbcb92c5e45fb7f8c5fc488cdbbf79498af963a.zip | |
Fix case where operation returns void but has declared exception list (returnsdata == true, but returntype == null)
| -rw-r--r-- | icespider/compile/routeCompiler.cpp | 4 | ||||
| -rw-r--r-- | icespider/unittests/Jamfile.jam | 1 | ||||
| -rw-r--r-- | icespider/unittests/test-api-impl.cpp | 8 | ||||
| -rw-r--r-- | icespider/unittests/test-api.ice | 11 | ||||
| -rw-r--r-- | icespider/unittests/testApp.cpp | 29 | ||||
| -rw-r--r-- | icespider/unittests/testCompile.cpp | 4 | ||||
| -rw-r--r-- | icespider/unittests/testRoutes.json | 10 | 
7 files changed, 58 insertions, 9 deletions
| diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp index 31bf272..9bb3ba0 100644 --- a/icespider/compile/routeCompiler.cpp +++ b/icespider/compile/routeCompiler.cpp @@ -533,7 +533,7 @@ namespace IceSpider {  		RouteCompiler::addSingleOperation(FILE * output, RoutePtr r, Slice::OperationPtr o) const  		{  			auto operation = r->operation->substr(r->operation->find_last_of('.') + 1); -			if (o->returnsData()) { +			if (o->returnType()) {  				fprintbf(4, output, "auto _responseModel = prx0->%s(", operation);  			}  			else { @@ -552,7 +552,7 @@ namespace IceSpider {  			for(const auto & mutator : r->mutators) {  				fprintbf(4, output, "%s(request, _responseModel);\n", mutator);  			} -			if (o->returnsData()) { +			if (o->returnType()) {  				fprintbf(4, output, "request->response(this, _responseModel);\n");  			}  			else { diff --git a/icespider/unittests/Jamfile.jam b/icespider/unittests/Jamfile.jam index 2c24e7d..4dcc450 100644 --- a/icespider/unittests/Jamfile.jam +++ b/icespider/unittests/Jamfile.jam @@ -120,6 +120,7 @@ run  lib test-api :  	test-api.ice +	test-api-impl.cpp  	:  	<slicer>yes  	<library>slicer diff --git a/icespider/unittests/test-api-impl.cpp b/icespider/unittests/test-api-impl.cpp new file mode 100644 index 0000000..7d5b556 --- /dev/null +++ b/icespider/unittests/test-api-impl.cpp @@ -0,0 +1,8 @@ +#include <test-api.h> + +void +TestIceSpider::Ex::ice_print(std::ostream & s) const +{ +	s << message; +} + diff --git a/icespider/unittests/test-api.ice b/icespider/unittests/test-api.ice index 53def7d..c89e0fc 100644 --- a/icespider/unittests/test-api.ice +++ b/icespider/unittests/test-api.ice @@ -14,10 +14,17 @@ module TestIceSpider {  		string s;  	}; +	["cpp:ice_print"] +	exception Ex { +		string message; +	}; +  	interface TestApi { +		int simple() throws Ex; +		string simplei(int i);  		SomeModel index(); -		SomeModel withParams(string s, int i); -		void returnNothing(string s); +		SomeModel withParams(string s, int i) throws Ex; +		void returnNothing(string s) throws Ex;  		void complexParam(optional(0) string s, SomeModel m);  	};  	interface DummyPlugin { diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp index a95bca5..000f983 100644 --- a/icespider/unittests/testApp.cpp +++ b/icespider/unittests/testApp.cpp @@ -29,7 +29,7 @@ void forceEarlyChangeDir()  BOOST_AUTO_TEST_CASE( testLoadConfiguration )  { -	BOOST_REQUIRE_EQUAL(12, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size()); +	BOOST_REQUIRE_EQUAL(14, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size());  }  class CoreWithProps : public CoreWithDefaultRouter { @@ -85,8 +85,8 @@ BOOST_AUTO_TEST_CASE( testCoreSettings )  {  	BOOST_REQUIRE_EQUAL(5, routes.size());  	BOOST_REQUIRE_EQUAL(1, routes[0].size()); -	BOOST_REQUIRE_EQUAL(6, routes[1].size()); -	BOOST_REQUIRE_EQUAL(1, routes[2].size()); +	BOOST_REQUIRE_EQUAL(7, routes[1].size()); +	BOOST_REQUIRE_EQUAL(2, routes[2].size());  	BOOST_REQUIRE_EQUAL(2, routes[3].size());  	BOOST_REQUIRE_EQUAL(2, routes[4].size());  } @@ -151,6 +151,9 @@ class TestSerice : public TestIceSpider::TestApi {  		void returnNothing(const std::string & s, const Ice::Current &) override  		{ +			if (s == "error") { +				throw TestIceSpider::Ex("test error"); +			}  			BOOST_REQUIRE_EQUAL(s, "some value");  		} @@ -161,6 +164,16 @@ class TestSerice : public TestIceSpider::TestApi {  			BOOST_REQUIRE(m);  			BOOST_REQUIRE_EQUAL("some value", m->value);  		} + +		Ice::Int simple(const Ice::Current &) override +		{ +			return 1; +		} + +		std::string simplei(Ice::Int n, const Ice::Current &) override +		{ +			return boost::lexical_cast<std::string>(n); +		}  };  class TestApp : public CoreWithDefaultRouter { @@ -478,5 +491,15 @@ BOOST_AUTO_TEST_CASE( testCookies )  	BOOST_REQUIRE_EQUAL(h["Status"], "200 OK");  } +BOOST_AUTO_TEST_CASE( testErrorHandler ) +{ +	TestRequest requestDeleteItem(this, HttpMethod::DELETE, "/error"); +	process(&requestDeleteItem); +	auto h = requestDeleteItem.getResponseHeaders(); +	BOOST_REQUIRE_EQUAL(h["Status"], "500 test error"); +	requestDeleteItem.output.get(); +	BOOST_REQUIRE(requestDeleteItem.output.eof()); +} +  BOOST_AUTO_TEST_SUITE_END(); diff --git a/icespider/unittests/testCompile.cpp b/icespider/unittests/testCompile.cpp index 00862fa..1337d7d 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(12, cfg->routes.size()); +	BOOST_REQUIRE_EQUAL(14, cfg->routes.size());  	BOOST_REQUIRE_EQUAL("/", cfg->routes["index"]->path);  	BOOST_REQUIRE_EQUAL(HttpMethod::GET, cfg->routes["index"]->method); @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE( testLoad )  	BOOST_TEST_INFO(dlerror());  	BOOST_REQUIRE(lib); -	BOOST_REQUIRE_EQUAL(12, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size()); +	BOOST_REQUIRE_EQUAL(14, 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/testRoutes.json b/icespider/unittests/testRoutes.json index 2fd7aac..7f6dd70 100644 --- a/icespider/unittests/testRoutes.json +++ b/icespider/unittests/testRoutes.json @@ -21,6 +21,16 @@  			"mutators": [ "testMutate" ],  			"operation": "TestIceSpider.TestApi.index"  		}, +		"simple": { +			"path": "/simple", +			"method": "GET", +			"operation": "TestIceSpider.TestApi.simple" +		}, +		"simplei": { +			"path": "/simple/{i}", +			"method": "GET", +			"operation": "TestIceSpider.TestApi.simplei" +		},  		"item": {  			"path": "/view/{s}/{i}",  			"method": "GET", | 
