You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2015/09/03 16:20:23 UTC

[2/2] celix git commit: CELIX-237: added test for json_rpc

CELIX-237: added test for json_rpc


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/c0d4f75a
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/c0d4f75a
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/c0d4f75a

Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: c0d4f75af7601b51de346aed118b01b003411a9b
Parents: 837926e
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Sep 3 16:19:24 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Sep 3 16:19:24 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/json_rpc.c       |  3 +-
 .../json_rpc_tests.cpp                          | 61 ++++++++++++++++++--
 2 files changed, 57 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/c0d4f75a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
index 8a2f15c..5b49f2b 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
@@ -216,6 +216,7 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]
         if (argMeta == NULL) {
             //skip
         } else if (strcmp(argMeta, "pre") == 0) {
+            LOG_DEBUG("found pre argument at %i", i);
             dyn_type *subType = NULL;
             dynType_typedPointer_getTypedType(argType, &subType);
             void *tmp = NULL;
@@ -226,7 +227,7 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]
             dynType_free(subType, tmp);
         } else if (strcmp(argMeta, "out") == 0) {
             assert(false); //TODO
-        } 
+        }
     }
 
     json_decref(replyJson);

http://git-wip-us.apache.org/repos/asf/celix/blob/c0d4f75a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
index 52b7386..60b028f 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
@@ -28,34 +28,83 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
 }
 
 
+    void prepareTest(void) {
+        dyn_function_type *dynFunc = NULL;
+        int rc = dynFunction_parseWithStr("add(#am=handle;PDD#am=pre;*D)N", NULL, &dynFunc);
+        CHECK_EQUAL(0, rc);
+
+        char *result = NULL;
+
+        void *handle = NULL;
+        double arg1 = 1.0;
+        double arg2 = 2.0;
+
+        void *args[4];
+        args[0] = &handle;
+        args[1] = &arg1;
+        args[2] = &arg2;
+
+        rc = jsonRpc_prepareInvokeRequest(dynFunc, "add", args, &result);
+        CHECK_EQUAL(0, rc);
+
+        //printf("result is %s\n", result);
+
+        STRCMP_CONTAINS("\"add\"", result);
+        STRCMP_CONTAINS("1.0", result);
+        STRCMP_CONTAINS("2.0", result);
+
+        free(result);
+        dynFunction_destroy(dynFunc);
+    }
+
     void handleTest(void) {
         dyn_function_type *dynFunc = NULL;
-        int rc = dynFunction_parseWithStr("add(#at=h;PDD#at=pa;*D)N", NULL, &dynFunc);
+        int rc = dynFunction_parseWithStr("add(#am=handle;PDD#am=pre;*D)N", NULL, &dynFunc);
         CHECK_EQUAL(0, rc);
 
-        //TODO jsonRpc_handleReply(dynFunc, )
+        const char *reply = "{\"r\":2.2}";
+        double result = -1.0;
+        double *out = &result;
+        void *args[4];
+        args[3] = &out;
+        rc = jsonRpc_handleReply(dynFunc, reply, args);
+        CHECK_EQUAL(0, rc);
+        //CHECK_EQUAL(2.2, result);
+
+        dynFunction_destroy(dynFunc);
     }
 
-    void prepareTest(void) {
 
+    void callTest(void) {
+        //TODO
     }
 
 }
 
 TEST_GROUP(JsonRpcTests) {
     void setup() {
-        int lvl = 1;
+        int lvl = 4;
         dynCommon_logSetup(stdLog, NULL, lvl);
         dynType_logSetup(stdLog, NULL,lvl);
+        dynFunction_logSetup(stdLog, NULL,lvl);
+        dynInterface_logSetup(stdLog, NULL,lvl);
         jsonSerializer_logSetup(stdLog, NULL, lvl);
+        jsonRpc_logSetup(stdLog, NULL, lvl);
+
     }
 };
 
+
+TEST(JsonRpcTests, prepareTest) {
+    prepareTest();
+}
+
 TEST(JsonRpcTests, handleTest) {
     handleTest();
 }
 
-TEST(JsonRpcTests, prepareTest) {
-    prepareTest();
+TEST(JsonRpcTests, call) {
+    callTest();
 }
 
+