oic unittest; start of get/set tests.

Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d886fa15
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d886fa15
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d886fa15

Branch: refs/heads/develop
Commit: d886fa15db9cc74a65be00bfd34fbe11b7be3452
Parents: bcb6607
Author: Marko Kiiskila <[email protected]>
Authored: Fri Jan 13 18:15:01 2017 -0800
Committer: Marko Kiiskila <[email protected]>
Committed: Fri Jan 13 18:15:01 2017 -0800

----------------------------------------------------------------------
 net/oic/test/src/test_discovery.c      |  23 +----
 net/oic/test/src/test_getset.c         | 127 ++++++++++++++++++++++++++++
 net/oic/test/src/test_oic.h            |   4 +
 net/oic/test/src/testcases/oic_tests.c |  33 ++++++++
 4 files changed, 167 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d886fa15/net/oic/test/src/test_discovery.c
----------------------------------------------------------------------
diff --git a/net/oic/test/src/test_discovery.c 
b/net/oic/test/src/test_discovery.c
index 50d2c95..f787a44 100644
--- a/net/oic/test/src/test_discovery.c
+++ b/net/oic/test/src/test_discovery.c
@@ -32,29 +32,15 @@ static struct os_event test_discovery_next_ev = {
 /*
  * Discovery.
  */
-static void
-test_discovery_init(void)
-{
-    oc_init_platform("TestPlatform", NULL, NULL);
-}
-
-static void
-test_discovery_client_requests(void)
-{
-}
-
-static oc_handler_t test_discovery_handler = {
-    .init = test_discovery_init,
-    .requests_entry = test_discovery_client_requests
-};
-
 static oc_discovery_flags_t
 test_discovery_cb(const char *di, const char *uri, oc_string_array_t types,
-                  oc_interface_mask_t interfaces, oc_server_handle_t *server)
+                  oc_interface_mask_t interfaces,
+                  struct oc_server_handle *server)
 {
     if ((server->endpoint.oe.flags & IP) == 0) {
         return 0;
     }
+    oic_test_set_endpoint(server);
     switch (test_discovery_state) {
     case 1:
         TEST_ASSERT(!strcmp(uri, "/oic/p"));
@@ -95,7 +81,6 @@ test_discovery_cb(const char *di, const char *uri, 
oc_string_array_t types,
             TEST_ASSERT(0);
         }
         if (seen_p && seen_d && seen_light) {
-            os_eventq_put(&oic_tapp_evq, &test_discovery_next_ev);
             /*
              * Done.
              */
@@ -158,13 +143,11 @@ test_discovery_next_step(struct os_event *ev)
 void
 test_discovery(void)
 {
-    oc_main_init(&test_discovery_handler);
     os_eventq_put(&oic_tapp_evq, &test_discovery_next_ev);
 
     while (!test_discovery_done) {
         os_eventq_run(&oic_tapp_evq);
     }
-    oc_main_shutdown();
 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d886fa15/net/oic/test/src/test_getset.c
----------------------------------------------------------------------
diff --git a/net/oic/test/src/test_getset.c b/net/oic/test/src/test_getset.c
new file mode 100644
index 0000000..9a0f5e3
--- /dev/null
+++ b/net/oic/test/src/test_getset.c
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "test_oic.h"
+
+#include <os/os.h>
+#include <oic/oc_api.h>
+
+static int test_getset_state;
+static volatile int test_getset_done;
+
+static void test_getset_next_step(struct os_event *);
+static struct os_event test_getset_next_ev = {
+    .ev_cb = test_getset_next_step
+};
+
+static void
+test_getset_get(struct oc_request *request, oc_interface_mask_t interface)
+{
+    switch (test_getset_state) {
+    case 1:
+        oc_rep_start_root_object();
+        oc_rep_end_root_object();
+        oc_send_response(request, OC_STATUS_OK);
+        break;
+    case 2:
+        oc_send_response(request, OC_STATUS_OK);
+        break;
+    case 3:
+        oc_send_response(request, OC_STATUS_BAD_REQUEST);
+        break;
+    }
+}
+
+static void
+test_getset_put(struct oc_request *request, oc_interface_mask_t interface)
+{
+
+}
+
+static void
+test_getset_rsp1(struct oc_client_response *rsp)
+{
+    switch (test_getset_state) {
+    case 1:
+        TEST_ASSERT(rsp->code == OC_STATUS_OK);
+        break;
+    case 2:
+        TEST_ASSERT(rsp->code == OC_STATUS_OK);
+        break;
+    case 3:
+        TEST_ASSERT(rsp->code == OC_STATUS_BAD_REQUEST);
+        break;
+    default:
+        break;
+    }
+    os_eventq_put(&oic_tapp_evq, &test_getset_next_ev);
+}
+
+static void
+test_getset_next_step(struct os_event *ev)
+{
+    bool b_rc;
+    struct oc_server_handle server;
+
+    test_getset_state++;
+    switch (test_getset_state) {
+    case 1: {
+        oc_resource_t *res;
+
+        res = oc_new_resource("/getset", 1, 0);
+        TEST_ASSERT_FATAL(res);
+
+        oc_resource_bind_resource_interface(res, OC_IF_RW);
+        oc_resource_set_default_interface(res, OC_IF_RW);
+
+        oc_resource_set_request_handler(res, OC_GET, test_getset_get);
+        oc_resource_set_request_handler(res, OC_PUT, test_getset_put);
+        b_rc = oc_add_resource(res);
+        TEST_ASSERT(b_rc == true);
+    }
+        /* fall-through */
+    case 2:
+    case 3:
+        oic_test_get_endpoint(&server);
+
+        b_rc = oc_do_get("/getset", &server, NULL, test_getset_rsp1, LOW_QOS);
+        TEST_ASSERT_FATAL(b_rc == true);
+
+        oic_test_reset_tmo();
+        break;
+    case 4:
+        test_getset_done = 1;
+        break;
+    default:
+        TEST_ASSERT_FATAL(0);
+        break;
+    }
+}
+
+void
+test_getset(void)
+{
+    os_eventq_put(&oic_tapp_evq, &test_getset_next_ev);
+
+    while (!test_getset_done) {
+        os_eventq_run(&oic_tapp_evq);
+    }
+    oc_main_shutdown();
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d886fa15/net/oic/test/src/test_oic.h
----------------------------------------------------------------------
diff --git a/net/oic/test/src/test_oic.h b/net/oic/test/src/test_oic.h
index e15ea8c..1511ef5 100644
--- a/net/oic/test/src/test_oic.h
+++ b/net/oic/test/src/test_oic.h
@@ -36,8 +36,12 @@ TEST_CASE_DECL(oic_tests);
 extern struct os_eventq oic_tapp_evq;
 
 void oic_test_reset_tmo(void);
+struct oc_server_handle;
+void oic_test_set_endpoint(struct oc_server_handle *);
+void oic_test_get_endpoint(struct oc_server_handle *);
 
 void test_discovery(void);
+void test_getset(void);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d886fa15/net/oic/test/src/testcases/oic_tests.c
----------------------------------------------------------------------
diff --git a/net/oic/test/src/testcases/oic_tests.c 
b/net/oic/test/src/testcases/oic_tests.c
index c495416..2a4c270 100644
--- a/net/oic/test/src/testcases/oic_tests.c
+++ b/net/oic/test/src/testcases/oic_tests.c
@@ -21,6 +21,8 @@
 #include <os/os.h>
 #include <oic/oc_api.h>
 
+#include <mn_socket/mn_socket.h>
+
 #define OIC_TAPP_PRIO       9
 #define OIC_TAPP_STACK_SIZE 1024
 
@@ -33,6 +35,7 @@ static struct os_task oic_tapp;
 static os_stack_t oic_tapp_stack[OS_STACK_ALIGN(OIC_TAPP_STACK_SIZE)];
 struct os_eventq oic_tapp_evq;
 static struct os_callout oic_test_timer;
+static struct oc_server_handle oic_tgt;
 
 static void
 oic_test_timer_cb(struct os_event *ev)
@@ -47,9 +50,39 @@ oic_test_reset_tmo(void)
 }
 
 static void
+test_platform_init(void)
+{
+    oc_init_platform("TestPlatform", NULL, NULL);
+}
+
+static void
+test_handle_client_requests(void)
+{
+}
+
+static oc_handler_t test_handler = {
+    .init = test_platform_init,
+    .requests_entry = test_handle_client_requests
+};
+
+void
+oic_test_set_endpoint(struct oc_server_handle *ose)
+{
+    memcpy(&oic_tgt, ose, sizeof(*ose));
+}
+
+void
+oic_test_get_endpoint(struct oc_server_handle *ose)
+{
+    memcpy(ose, &oic_tgt, sizeof(*ose));
+}
+
+static void
 oic_test_handler(void *arg)
 {
+    oc_main_init(&test_handler);
     test_discovery();
+    test_getset();
     tu_restart();
 }
 

Reply via email to