From: jihwan.seo Date: Thu, 21 Jul 2016 07:40:35 +0000 (+0900) Subject: added Testcase for MQ Client API X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd6cc07a75d10b0c72408745ef65c0f41599e9a4;p=contrib%2Fiotivity.git added Testcase for MQ Client API Change-Id: Iee8e98a922288f90a79e3fd006b797e5c745d107 Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/9539 Tested-by: jenkins-iotivity Reviewed-by: Ashok Babu Channa --- diff --git a/auto_build.py b/auto_build.py index cbd11e2..00dc648 100644 --- a/auto_build.py +++ b/auto_build.py @@ -13,7 +13,7 @@ Usage: build: python %s Allowed values for : 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", "") diff --git a/resource/csdk/stack/test/stacktests.cpp b/resource/csdk/stack/test/stacktests.cpp index 9bafe8e..8cae176 100644 --- a/resource/csdk/stack/test/stacktests.cpp +++ b/resource/csdk/stack/test/stacktests.cpp @@ -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 index 0000000..bf2bcb3 --- /dev/null +++ b/resource/unittests/OCMQResourceTest.cpp @@ -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 +#include +#include +#include +#include + +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) + { + } + + void createdTopic(const HeaderOptions &, const OCRepresentation &, const int, + std::shared_ptr) + { + } + + //Helper method + OCResource::Ptr ConstructResourceObject(std::string host, std::string uri) + { + OCConnectivityType connectivityType = CT_DEFAULT; + std::vector types = {"tkss.wk"}; + std::vector 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 +} + diff --git a/resource/unittests/SConscript b/resource/unittests/SConscript index 70b258e..e11ff13 100644 --- a/resource/unittests/SConscript +++ b/resource/unittests/SConscript @@ -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']