diff --git a/server/c_string.cc b/server/c_string.cc index b2f0445..bc05c91 100644 --- a/server/c_string.cc +++ b/server/c_string.cc @@ -12,3 +12,7 @@ Out::~Out() { // don't pEp_free() the value! } + +template<> +In::~In() +{} diff --git a/server/c_string.hh b/server/c_string.hh index 76fc653..361633a 100644 --- a/server/c_string.hh +++ b/server/c_string.hh @@ -89,6 +89,8 @@ struct InLength : In InLength(const js::Value& v, Context* ctx, unsigned param_nr) : Base( ctx->retrieve(param_nr-1) ) {} + + ~InLength() = default; }; diff --git a/server/unittest_rpc.cc b/server/unittest_rpc.cc index 7374b17..f057f16 100644 --- a/server/unittest_rpc.cc +++ b/server/unittest_rpc.cc @@ -35,6 +35,8 @@ public: DummyContext dummyContext; +// some example & test functions: + int add_mul_simple(int x, int y, int z) { return (x+y) * z; @@ -56,10 +58,29 @@ char* add_mul_inout(int x, const char* y_str, int* z_result, char** result) return new_string( ("x" + rs + "x").c_str(), 0); } + +char* tohex(const char* input, size_t length) +{ + std::string h; h.reserve(length*3); + char buffer[8] = { 0 }; + const char* end = input+length; + for(; input, In, In>( &add_mul_simple )), - FP( "add_mul_inout", new Func, In, InOutP, Out>( &add_mul_inout )), + FP( "add_mul_inout" , new Func, In, InOutP, Out>( &add_mul_inout )), FP( "stringlist_add", new Func, InOut, In>( &stringlist_add )), + FP( "tohex_1", new Func, In>( &tohex )), // with explicit length parameter + FP( "tohex_2", new Func, InLength<>>( &tohex )), // with implicit length parameter, with dummy JSON parameter + FP( "tohex_3", new Func, InLength>( &tohex )), // with implicit length parameter, without JSON parameter }; @@ -92,6 +113,22 @@ const std::vector testValues = { "{\"jsonrpc\":\"2.0\", \"id\":24, \"method\":\"stringlist_add\", \"params\":[[\"abc\",\"def\"], \"ADD\"]}", "{\"jsonrpc\":\"2.0\", \"id\":24, \"result\":{ \"outParams\":[[\"abc\", \"def\", \"ADD\"]], \"return\":[\"ADD\"]}}" }, + // tohex: + { "{\"jsonrpc\":\"2.0\", \"id\":25, \"method\":\"tohex_1\", \"params\":[\"tohex\",3]}", + "{\"jsonrpc\":\"2.0\", \"id\":25, \"result\":{ \"outParams\":[], \"return\":\"74 6f 68\"}}" + }, + { "{\"jsonrpc\":\"2.0\", \"id\":26, \"method\":\"tohex_1\", \"params\":[\"tohex\",5]}", + "{\"jsonrpc\":\"2.0\", \"id\":26, \"result\":{ \"outParams\":[], \"return\":\"74 6f 68 65 78\"}}" + }, + { "{\"jsonrpc\":\"2.0\", \"id\":27, \"method\":\"tohex_2\", \"params\":[\"tohex\",0]}", + "{\"jsonrpc\":\"2.0\", \"id\":27, \"result\":{ \"outParams\":[], \"return\":\"74 6f 68 65 78\"}}" + }, + { "{\"jsonrpc\":\"2.0\", \"id\":28, \"method\":\"tohex_2\", \"params\":[\"tohex\",\"dummy_parameter\"]}", + "{\"jsonrpc\":\"2.0\", \"id\":28, \"result\":{ \"outParams\":[], \"return\":\"74 6f 68 65 78\"}}" + }, + { "{\"jsonrpc\":\"2.0\", \"id\":28, \"method\":\"tohex_3\", \"params\":[\"tohex\"]}", + "{\"jsonrpc\":\"2.0\", \"id\":28, \"result\":{ \"outParams\":[], \"return\":\"74 6f 68 65 78\"}}" + }, };