added Testcase for MQ Client API
authorjihwan.seo <jihwan.seo@samsung.com>
Thu, 21 Jul 2016 07:40:35 +0000 (16:40 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Fri, 5 Aug 2016 06:32:37 +0000 (06:32 +0000)
Change-Id: Iee8e98a922288f90a79e3fd006b797e5c745d107
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9539
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
auto_build.py
resource/csdk/stack/test/stacktests.cpp
resource/unittests/OCMQResourceTest.cpp [new file with mode: 0644]
resource/unittests/SConscript

index cbd11e2..00dc648 100644 (file)
@@ -13,7 +13,7 @@ Usage:
     build:
         python %s <targetbuild>
         Allowed values for <target_build>: all, linux_unsecured, linux_secured, linux_unsecured_with_ra, linux_secured_with_ra, linux_unsecured_with_rd, linux_secured_with_rd, android, arduino, tizen, simulator, darwin, windows, msys
-        Note: \"linux\" will build \"linux_unsecured\", \"linux_secured\", \"linux_unsecured_with_ra\", \"linux_secured_with_ra\", \"linux_secured_with_rd\" & \"linux_unsecured_with_rd\".
+        Note: \"linux\" will build \"linux_unsecured\", \"linux_secured\", \"linux_unsecured_with_ra\", \"linux_secured_with_ra\", \"linux_secured_with_rd\", \"linux_unsecured_with_mq\" & \"linux_unsecured_with_rd\".
         Any selection will build both debug and release versions of all available targets in the scope you've selected.
         To choose any specific command, please use the SCons commandline directly. Please refer to [IOTIVITY_REPO]/Readme.scons.txt.
     clean:
@@ -47,6 +47,7 @@ def build_all(flag, extra_option_str):
         build_linux_unsecured_with_rm(flag, extra_option_str)
         build_linux_unsecured_with_rd(flag, extra_option_str)
         build_linux_secured_with_rd(flag, extra_option_str)
+        build_linux_unsecured_with_mq(flag, extra_option_str)
         build_simulator(flag, extra_option_str)
 
     build_android(flag, extra_option_str)
@@ -122,6 +123,14 @@ def build_linux_secured_with_rd(flag, extra_option_str):
                     }
     call_scons(build_options, extra_option_str)
 
+def build_linux_unsecured_with_mq(flag, extra_option_str):
+    print ("*********** Build for linux With Message Queue ************")
+    build_options = {
+                        'RELEASE':flag,
+                        'WITH_MQ':'PUB,SUB,BROKER',
+                    }
+    call_scons(build_options, extra_option_str)
+
 def build_android(flag, extra_option_str):
     # Note: for android, as oic-resource uses C++11 feature stoi and to_string,
     # it requires gcc-4.9, currently only android-ndk-r10(for linux)
@@ -416,6 +425,10 @@ elif arg_num == 2:
         build_linux_secured_with_rd("true", "")
         build_linux_secured_with_rd("false", "")
 
+    elif str(sys.argv[1]) == "linux_unsecured_with_mq":
+        build_linux_unsecured_with_mq("true", "")
+        build_linux_unsecured_with_mq("false", "")
+
     elif str(sys.argv[1]) == "android":
         build_android("true", "")
         build_android("false", "")
index 9bafe8e..8cae176 100644 (file)
@@ -898,7 +898,11 @@ TEST(StackResource, GetResourceProperties)
                                             NULL,
                                             OC_DISCOVERABLE|OC_OBSERVABLE));
 
+#ifdef MQ_PUBLISHER
+    EXPECT_EQ(OC_ACTIVE|OC_DISCOVERABLE|OC_OBSERVABLE|OC_MQ_PUBLISHER, OCGetResourceProperties(handle));
+#else
     EXPECT_EQ(OC_ACTIVE|OC_DISCOVERABLE|OC_OBSERVABLE, OCGetResourceProperties(handle));
+#endif
     EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle));
 
     EXPECT_EQ(OC_STACK_OK, OCStop());
diff --git a/resource/unittests/OCMQResourceTest.cpp b/resource/unittests/OCMQResourceTest.cpp
new file mode 100644 (file)
index 0000000..bf2bcb3
--- /dev/null
@@ -0,0 +1,119 @@
+/* ****************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed 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 <OCPlatform.h>
+#include <OCApi.h>
+#include <gtest/gtest.h>
+#include <string>
+#include <map>
+
+namespace OCMQResourceTest
+{
+    using namespace OC;
+
+#ifdef MQ_SUBSCRIBER
+    void onObserve(const HeaderOptions, const OCRepresentation&, const int&, const int&)
+    {
+    }
+#endif
+
+#ifdef MQ_PUBLISHER
+    void onGetPut(const HeaderOptions&, const OCRepresentation& , const int eCode)
+    {
+    }
+#endif
+
+    void foundResource(std::shared_ptr<OCResource>)
+    {
+    }
+
+    void createdTopic(const HeaderOptions &, const OCRepresentation &, const int,
+                      std::shared_ptr<OCResource>)
+    {
+    }
+
+    //Helper method
+    OCResource::Ptr ConstructResourceObject(std::string host, std::string uri)
+    {
+        OCConnectivityType connectivityType = CT_DEFAULT;
+        std::vector<std::string> types = {"tkss.wk"};
+        std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
+
+        auto ret = OCPlatform::constructResourceObject(host, uri,
+                connectivityType, false, types, ifaces);
+
+        if (!ret)
+        {
+            ADD_FAILURE() << "ConstructResourceObject result was null";
+            return nullptr;
+        }
+
+        return ret;
+    }
+
+    // Message Queue Test
+    TEST(MessageQueueTest, DiscoveryMQTopicsValid)
+    {
+        OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
+        EXPECT_TRUE(resource != NULL);
+        QueryParamsMap query = {};
+        EXPECT_EQ(OC_STACK_OK, resource->discoveryMQTopics(query, &foundResource));
+    }
+
+    TEST(MessageQueueTest, CreateMQTopicValid)
+    {
+        OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
+        EXPECT_TRUE(resource != NULL);
+        OCRepresentation rep;
+        QueryParamsMap query = {};
+        EXPECT_EQ(OC_STACK_OK, resource->createMQTopic(rep, "/ps/nweTopic", query, &createdTopic));
+    }
+
+#ifdef MQ_PUBLISHER
+    TEST(MessageQueueTest, PublishMQTopicValid)
+    {
+        OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
+        EXPECT_TRUE(resource != NULL);
+        OCRepresentation rep;
+        QueryParamsMap query = {};
+        EXPECT_EQ(OC_STACK_OK, resource->publishMQTopic(rep, query, &onGetPut));
+    }
+#endif
+
+#ifdef MQ_SUBSCRIBER
+    TEST(MessageQueueTest, SubscribeMQTopicValid)
+    {
+        OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
+        EXPECT_TRUE(resource != NULL);
+        QueryParamsMap query = {};
+        EXPECT_EQ(OC_STACK_OK, resource->subscribeMQTopic(ObserveType::Observe, query, &onObserve));
+    }
+
+    TEST(MessageQueueTest, RequestMQPublishValid)
+    {
+        OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
+        EXPECT_TRUE(resource != NULL);
+        QueryParamsMap query = {};
+        EXPECT_EQ(OC_STACK_OK, resource->requestMQPublish(query, &onGetPut));
+    }
+#endif
+}
+
index 70b258e..e11ff13 100644 (file)
@@ -26,6 +26,7 @@ gtest_env = SConscript('#extlibs/gtest/SConscript')
 unittests_env = gtest_env.Clone()
 src_dir = unittests_env.get('SRC_DIR')
 target_os = unittests_env.get('TARGET_OS')
+with_mq = unittests_env.get('WITH_MQ')
 
 ######################################################################
 # Build flags
@@ -78,6 +79,9 @@ unittests_src = [
                'OCHeaderOptionTest.cpp'
        ]
 
+if (('SUB' in with_mq) or ('PUB' in with_mq) or ('BROKER' in with_mq)):
+       unittests_src = unittests_src + ['OCMQResourceTest.cpp']
+
 if unittests_env.get('WITH_CLOUD'):
        unittests_src = unittests_src + ['OCAccountManagerTest.cpp']