[IOT-1939] Fix for failure of test cases in C++ Notification Service due to time...
authorPoovizhi <poovizhi.a@samsung.com>
Mon, 27 Mar 2017 13:49:01 +0000 (19:19 +0530)
committerUze Choi <uzchoi@samsung.com>
Fri, 7 Apr 2017 06:58:39 +0000 (06:58 +0000)
Unit test of notification service sometimes fails due to time delay.
In this patch, network related procedure was separated in C++ layer of notification service.
The changes are based on the C layer changes from the patch "https://gerrit.iotivity.org/gerrit/#/c/17397"

Change-Id: Ib0c859f9052be2049135226cc6abd9f314875b09
Signed-off-by: Poovizhi <poovizhi.a@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18197
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/cpp-wrapper/SConscript
service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp
service/notification/cpp-wrapper/unittest/NSConsumerServiceTest2.cpp [new file with mode: 0644]
service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp
service/notification/cpp-wrapper/unittest/NSProviderServiceTest2.cpp [new file with mode: 0644]
service/notification/cpp-wrapper/unittest/SConscript

index 9929c60..e6455da 100755 (executable)
@@ -34,5 +34,5 @@ if target_os == 'linux':
     SConscript('examples/linux/SConscript')
 
 # Go to build c++ wrapper unittest
-#if target_os == 'linux':
-#    SConscript('unittest/SConscript')
+if target_os == 'linux':
+    SConscript('unittest/SConscript')
index ca7a45b..c04a31c 100644 (file)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+/**
+ * @file NSConsumerServiceTest.cpp
+ *
+ * This file contains Notification consumer service test cases that involves network related methods.
+ * The test cases are excluded from the build. 
+ * They can be executed seperately (local running) from the path <iotivity>/out/linux/<target_os>/<target_arch>/service/notification/cpp-wrapper/unittest
+ */
+
 #include <gtest/gtest.h>
 #include <atomic>
 #include <functional>
diff --git a/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest2.cpp b/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest2.cpp
new file mode 100644 (file)
index 0000000..b0e4e6f
--- /dev/null
@@ -0,0 +1,289 @@
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file NSConsumerServiceTest2.cpp 
+ *
+ * This file contains Notification consumer service test cases that do not involve network related methods.
+ * The test cases are executed during the build by enabling the option 'TEST' in scons build.
+ * Eg., scons [options] TEST=1
+ */
+
+#include <gtest/gtest.h>
+#include <atomic>
+#include <functional>
+#include <condition_variable>
+#include <mutex>
+#include <chrono>
+
+#include "ocstack.h"
+
+#include "NSUtils.h"
+#include "NSSyncInfo.h"
+#include "NSMessage.h"
+#include "NSMediaContents.h"
+#include "NSConsumerService.h"
+#include "NSAcceptedProviders.h"
+#include "NSCommon.h"
+
+#include "NSProviderServiceSimulator.h"
+
+namespace
+{
+
+    NSProviderSimulator g_providerSimul;
+    std::shared_ptr<OIC::Service::NSProvider> g_provider;
+
+    std::atomic_bool g_isStartedStack(false);
+
+    std::chrono::milliseconds g_waitForResponse(1000);
+
+    std::condition_variable responseCon;
+    std::mutex mutexForCondition;
+
+    enum class NSSelector
+    {
+        NS_SELECTION_CONSUMER = 0,
+        NS_SELECTION_PROVIDER = 1
+    };
+
+    OIC::Service::NSProviderState g_expectedState = OIC::Service::NSProviderState::DENY;
+    OIC::Service::NSProviderState g_revState = OIC::Service::NSProviderState::DENY;
+
+    uint64_t g_messageId = 0;
+
+    OIC::Service::NSSyncInfo::NSSyncType g_expectedSyncType =
+        OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
+    OIC::Service::NSSyncInfo::NSSyncType g_syncType =
+        OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
+
+}
+
+class TestWithMock: public testing::Test
+{
+    protected:
+        virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
+        {
+
+        }
+
+        virtual void TearDown()
+        {
+
+        }
+};
+
+class NotificationServiceConsumerTest : public TestWithMock
+{
+    public:
+        NotificationServiceConsumerTest() = default;
+        ~NotificationServiceConsumerTest() = default;
+
+        static void ProviderDiscoveredCallback( std::shared_ptr<OIC::Service::NSProvider> provider)
+        {
+            std::cout << __func__ << std::endl;
+            g_provider = provider;
+            responseCon.notify_all();
+        }
+
+        static void NotificationReceivedCallback( OIC::Service::NSMessage message)
+        {
+            std::cout << "Income Notification : " << message.getMessageId() << std::endl;
+            g_messageId = message.getMessageId();
+            responseCon.notify_all();
+        }
+
+        static void SyncCallback(OIC::Service::NSSyncInfo sync)
+        {
+            std::cout << __func__ << std::endl;
+            g_syncType = sync.getState();
+            if (g_expectedSyncType == sync.getState())
+            {
+                std::cout << "[Expected]" << __func__ << std::endl;
+                responseCon.notify_all();
+            }
+        }
+
+        static void FoundResource(std::shared_ptr< OC::OCResource >)
+        {
+            std::cout << __func__ << std::endl;
+        }
+
+        static void ProviderChangedCallback( OIC::Service::NSProviderState state)
+        {
+            std::cout << __func__ << std::endl;
+
+            if (g_expectedState == state)
+            {
+                g_revState = state;
+                std::cout << "[Expected]" << __func__ << std::endl;
+                responseCon.notify_all();
+            }
+        }
+
+    protected:
+
+        void SetUp()
+        {
+            TestWithMock::SetUp();
+
+            if (g_isStartedStack == false)
+            {
+                OC::PlatformConfig cfg
+                {
+                    OC::ServiceType::InProc,
+                    OC::ModeType::Both,
+                    "0.0.0.0",
+                    0,
+                    OC::QualityOfService::LowQos
+                };
+                OC::OCPlatform::Configure(cfg);
+
+                try
+                {
+                    OC::OCPlatform::stopPresence();
+                }
+                catch (...)
+                {
+
+                }
+
+                g_isStartedStack = true;
+            }
+
+        }
+
+        void TearDown()
+        {
+            TestWithMock::TearDown();
+        }
+
+};
+
+TEST_F(NotificationServiceConsumerTest, StartConsumerPositive)
+{
+
+    OIC::Service::NSResult res = OIC::Service::NSConsumerService::getInstance()->start(
+                                     ProviderDiscoveredCallback);
+    EXPECT_EQ(OIC::Service::NSResult::OK, res);
+}
+
+TEST_F(NotificationServiceConsumerTest, StopConsumerPositive)
+{
+    OIC::Service::NSResult res = OIC::Service::NSConsumerService::getInstance()->stop();
+    EXPECT_EQ(OIC::Service::NSResult::OK, res);
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectSuccessGetValidDiscoverProviderCb)
+{
+    OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallback);
+
+    auto discCb = OIC::Service::NSConsumerService::getInstance()->getProviderDiscoveredCb();
+    ASSERT_NE(nullptr, discCb) << "error: discovery cb register failure";
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectSuccessRescanProvider)
+{
+    OIC::Service::NSResult res = OIC::Service::NSConsumerService::getInstance()->rescanProvider();
+    EXPECT_EQ(OIC::Service::NSResult::OK, res);
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectGetProviderSuccessWithInvalidProviderId)
+{
+    std::shared_ptr<OIC::Service::NSProvider> provider =
+        OIC::Service::NSConsumerService::getInstance()->getProvider("123456");
+    bool res = (provider == nullptr);
+    EXPECT_EQ(res, 1);
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectGetProviderSuccessWithValidProviderId)
+{
+    ::NSProvider *provider = (::NSProvider *)malloc(sizeof(::NSProvider));
+    strcpy(provider->providerId, "test");
+    std::string provId;
+    provId.assign(provider->providerId, NS_UTILS_UUID_STRING_SIZE - 1);
+
+    std::shared_ptr<OIC::Service::NSProvider> providerTemp = std::make_shared<OIC::Service::NSProvider>
+            (provider);
+
+    OIC::Service::NSAcceptedProviders *acceptedProviders =
+        OIC::Service::NSConsumerService::getInstance()->getAcceptedProviders();
+    acceptedProviders->addProvider(providerTemp);
+
+    std::shared_ptr<OIC::Service::NSProvider> resProvider =
+        OIC::Service::NSConsumerService::getInstance()->getProvider(provId);
+    bool res = (resProvider != nullptr);
+    EXPECT_EQ(res, 1);
+    free(provider);
+}
+
+
+TEST_F(NotificationServiceConsumerTest, ExpectSuccessSendSyncInfo)
+{
+    uint64_t msgId = 10;
+    OIC::Service::NSResult res = OIC::Service::NSResult::FAIL;
+    std::string provId;
+
+    ::NSProvider *provider = (::NSProvider *)malloc(sizeof(::NSProvider));
+    strcpy(provider->providerId, "test");
+    provId.assign(provider->providerId, NS_UTILS_UUID_STRING_SIZE - 1);
+
+    std::shared_ptr<OIC::Service::NSProvider> providerTemp = std::make_shared<OIC::Service::NSProvider>
+            (provider);
+
+    OIC::Service::NSAcceptedProviders *acceptedProviders =
+        OIC::Service::NSConsumerService::getInstance()->getAcceptedProviders();
+    acceptedProviders->addProvider(providerTemp);
+
+    std::shared_ptr<OIC::Service::NSProvider> resProvider =
+        OIC::Service::NSConsumerService::getInstance()->getProvider(provId);
+
+    if (resProvider != nullptr)
+    {
+        res = resProvider->sendSyncInfo(msgId, OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);
+    }
+    EXPECT_EQ(OIC::Service::NSResult::OK, res);
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectSuccessGetTopicsList)
+{
+    uint64_t msgId = 10;
+    OIC::Service::NSResult res = OIC::Service::NSResult::FAIL;
+    std::string provId;
+
+    ::NSProvider *provider = (::NSProvider *)malloc(sizeof(::NSProvider));
+    strcpy(provider->providerId, "test");
+    provId.assign(provider->providerId, NS_UTILS_UUID_STRING_SIZE - 1);
+
+    std::shared_ptr<OIC::Service::NSProvider> providerTemp = std::make_shared<OIC::Service::NSProvider>
+            (provider);
+
+    OIC::Service::NSAcceptedProviders *acceptedProviders =
+        OIC::Service::NSConsumerService::getInstance()->getAcceptedProviders();
+    acceptedProviders->addProvider(providerTemp);
+
+    std::shared_ptr<OIC::Service::NSProvider> resProvider =
+        OIC::Service::NSConsumerService::getInstance()->getProvider(provId);
+
+    auto topicList = resProvider->getTopicList();
+
+    ASSERT_NE(nullptr, topicList) << "Get topics list failure";
+}
+
index dc474f5..c75748d 100644 (file)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+/**
+ * @file NSProviderServiceTest.cpp
+ *
+ * This file contains Notification provider service test cases that involves network related methods.
+ * The test cases are excluded from the build. 
+ * They can be executed seperately (local running) from the path <iotivity>/out/linux/<target_os>/<target_arch>/service/notification/cpp-wrapper/unittest
+ */
+
 #include <gtest/gtest.h>
 #include <atomic>
 #include <functional>
diff --git a/service/notification/cpp-wrapper/unittest/NSProviderServiceTest2.cpp b/service/notification/cpp-wrapper/unittest/NSProviderServiceTest2.cpp
new file mode 100644 (file)
index 0000000..363990a
--- /dev/null
@@ -0,0 +1,415 @@
+//******************************************************************
+//
+// Copyright 2017 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file NSProviderServiceTest2.cpp
+ *
+ * This file contains Notification provider service test cases that do not involve network related methods.
+ * The test cases are executed during the build by enabling the option 'TEST' in scons build.
+ * Eg., scons [options] TEST=1
+ */
+
+#include <gtest/gtest.h>
+#include <atomic>
+#include <functional>
+#include <condition_variable>
+#include <mutex>
+#include <chrono>
+
+#include "NSProviderService.h"
+#include "NSConsumerServiceSimulator.h"
+#include "NSUtils.h"
+#include "NSSyncInfo.h"
+#include "NSMessage.h"
+#include "NSMediaContents.h"
+#include "NSAcceptedConsumers.h"
+
+namespace
+{
+    std::atomic_bool g_isStartedStack(false);
+    std::chrono::milliseconds g_waitForResponse(1000);
+}
+
+class TestWithMock: public testing::Test
+{
+    protected:
+        virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
+        {
+        }
+
+        virtual void TearDown()
+        {
+
+        }
+};
+
+class NotificationProviderServiceTest : public TestWithMock
+{
+    public:
+        NotificationProviderServiceTest() = default;
+        ~NotificationProviderServiceTest() = default;
+
+        static void ConsumerSubscribedCallback(std::shared_ptr<OIC::Service::NSConsumer> consumer)
+        {
+            std::cout << __func__ << std::endl;
+        }
+
+        static void MessageSynchronizedCallback(OIC::Service::NSSyncInfo sync)
+        {
+            std::cout << __func__ << std::endl;
+        }
+
+        static void MessageCallbackFromConsumer(
+            const int &id, const std::string &, const std::string &, const std::string &)
+        {
+            std::cout << __func__ << std::endl;
+        }
+
+        static void SyncCallbackFromConsumer(const int type, const int syncId)
+        {
+            std::cout << __func__ << std::endl;
+        }
+
+    protected:
+
+        void SetUp()
+        {
+
+            if (g_isStartedStack == false)
+            {
+                OC::PlatformConfig cfg
+                {
+                    OC::ServiceType::InProc,
+                    OC::ModeType::Both,
+                    "0.0.0.0",
+                    0,
+                    OC::QualityOfService::HighQos
+                };
+                OC::OCPlatform::Configure(cfg);
+
+                try
+                {
+                    OC::OCPlatform::stopPresence();
+                }
+                catch (...)
+                {
+
+                }
+
+                g_isStartedStack = true;
+            }
+
+        }
+
+        void TearDown()
+        {
+        }
+
+};
+
+TEST_F(NotificationProviderServiceTest, StartProviderPositiveWithPolicyTrue)
+{
+    OIC::Service::NSProviderService::ProviderConfig config;
+    config.m_subscribeRequestCb = ConsumerSubscribedCallback;
+    config.m_syncInfoCb = MessageSynchronizedCallback;
+    config.subControllability = true;
+    config.userInfo = "user1";
+    config.resourceSecurity = false;
+
+    OIC::Service::NSResult ret =  OIC::Service::NSProviderService::getInstance()->start(config);
+
+    EXPECT_EQ(ret,  OIC::Service::NSResult::OK);
+}
+
+TEST_F(NotificationProviderServiceTest, StopProviderPositive)
+{
+    OIC::Service::NSResult ret =  OIC::Service::NSProviderService::getInstance()->stop();
+
+    EXPECT_EQ(ret,  OIC::Service::NSResult::OK);
+}
+
+TEST_F(NotificationProviderServiceTest, StartProviderPositiveWithPolicyFalse)
+{
+    OIC::Service::NSProviderService::ProviderConfig  config;
+    config.m_subscribeRequestCb = ConsumerSubscribedCallback;
+    config.m_syncInfoCb = MessageSynchronizedCallback;
+    config.subControllability = false;
+    config.resourceSecurity = false;
+
+    OIC::Service::NSResult ret =  OIC::Service::NSProviderService::getInstance()->start(config);
+
+    EXPECT_EQ(ret,  OIC::Service::NSResult::OK);
+    OIC::Service::NSProviderService::getInstance()->stop();
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectSuccessCreateMessage)
+{
+    OIC::Service::NSProviderService::ProviderConfig  config;
+    config.m_subscribeRequestCb = ConsumerSubscribedCallback;
+    config.m_syncInfoCb = MessageSynchronizedCallback;
+    config.subControllability = false;
+    config.resourceSecurity = false;
+
+    OIC::Service::NSProviderService::getInstance()->start(config);
+    OIC::Service::NSMessage msg =  OIC::Service::NSProviderService::getInstance()->createMessage();
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectSuccessSendMessage)
+{
+    OIC::Service::NSResult res = OIC::Service::NSResult::FAIL;
+
+    OIC::Service::NSMessage msg =  OIC::Service::NSProviderService::getInstance()->createMessage();
+    msg.setTitle(std::string("Title"));
+    msg.setContentText(std::string("ContentText"));
+    msg.setSourceName(std::string("OCF"));
+
+    res = OIC::Service::NSProviderService::getInstance()->sendMessage(msg);
+    EXPECT_EQ(OIC::Service::NSResult::OK, res);
+}
+
+
+TEST_F(NotificationProviderServiceTest, ExpectSuccessSendSyncInfo)
+{
+    uint64_t msgId = 10;
+    OIC::Service::NSResult res =
+        OIC::Service::NSProviderService::getInstance()->sendSyncInfo(msgId,
+                OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);
+    EXPECT_EQ(res,  OIC::Service::NSResult::OK);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectSuccessRegisterTopic)
+{
+    std::string str1("TEST1");
+    std::string str2("TEST2");
+
+    OIC::Service::NSResult res = OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
+    EXPECT_EQ(res,  OIC::Service::NSResult::OK);
+    res = OIC::Service::NSProviderService::getInstance()->registerTopic(str2);
+    EXPECT_EQ(res,  OIC::Service::NSResult::OK);
+
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectSuccessUnRegisterTopic)
+{
+    std::string str1("TEST1");
+
+    OIC::Service::NSResult res = OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
+    EXPECT_EQ(res,  OIC::Service::NSResult::OK);
+}
+
+
+TEST_F(NotificationProviderServiceTest, ExpectSuccessGetRegisteredTopicList)
+{
+    std::string str1("TEST1");
+
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
+
+    auto topicList =  OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList();
+    ASSERT_NE(nullptr, topicList) << "error: get TopicList failure";
+    OIC::Service::NSProviderService::getInstance()->stop();
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectFailAcceptSubscriptionInvalidPolicy)
+{
+    OIC::Service::NSProviderService::ProviderConfig  config;
+    config.m_subscribeRequestCb = ConsumerSubscribedCallback;
+    config.m_syncInfoCb = MessageSynchronizedCallback;
+    config.subControllability = false;
+    config.resourceSecurity = false;
+
+    OIC::Service::NSProviderService::getInstance()->start(config);
+    ::NSConsumer *consumer = (::NSConsumer *)malloc(sizeof(::NSConsumer));
+    strcpy(consumer->consumerId, "test");
+
+    std::shared_ptr<OIC::Service::NSConsumer> consumerTemp = std::make_shared<OIC::Service::NSConsumer>
+            (consumer);
+
+    OIC::Service::NSAcceptedConsumers *acceptedConsumers =
+        OIC::Service::NSProviderService::getInstance()->getAcceptedConsumers();
+    acceptedConsumers->addConsumer(consumerTemp);
+
+    OIC::Service::NSResult res = consumerTemp->acceptSubscription(true);
+
+    EXPECT_NE(res,  OIC::Service::NSResult::OK);
+    free(consumer);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectFailSetTopicInvalidPolicy)
+{
+    std::string str1("TEST1");
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
+    ::NSConsumer *consumer = (::NSConsumer *)malloc(sizeof(::NSConsumer));
+    strcpy(consumer->consumerId, "test");
+
+    std::shared_ptr<OIC::Service::NSConsumer> consumerTemp = std::make_shared<OIC::Service::NSConsumer>
+            (consumer);
+
+    OIC::Service::NSAcceptedConsumers *acceptedConsumers =
+        OIC::Service::NSProviderService::getInstance()->getAcceptedConsumers();
+    acceptedConsumers->addConsumer(consumerTemp);
+
+    OIC::Service::NSResult res = consumerTemp->setTopic(str1);
+
+    EXPECT_NE(res,  OIC::Service::NSResult::OK);
+    free(consumer);
+    OIC::Service::NSProviderService::getInstance()->stop();
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectSuccessAcceptSubscription)
+{
+    OIC::Service::NSProviderService::ProviderConfig  config;
+    config.m_subscribeRequestCb = ConsumerSubscribedCallback;
+    config.m_syncInfoCb = MessageSynchronizedCallback;
+    config.subControllability = true;
+    config.resourceSecurity = false;
+
+    OIC::Service::NSProviderService::getInstance()->start(config);
+    ::NSConsumer *consumer = (::NSConsumer *)malloc(sizeof(::NSConsumer));
+    strcpy(consumer->consumerId, "test");
+
+    std::shared_ptr<OIC::Service::NSConsumer> consumerTemp = std::make_shared<OIC::Service::NSConsumer>
+            (consumer);
+
+    OIC::Service::NSAcceptedConsumers *acceptedConsumers =
+        OIC::Service::NSProviderService::getInstance()->getAcceptedConsumers();
+    acceptedConsumers->addConsumer(consumerTemp);
+
+    OIC::Service::NSResult res = consumerTemp->acceptSubscription(true);
+
+    EXPECT_EQ(res,  OIC::Service::NSResult::OK);
+    free(consumer);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectSuccessSetTopic)
+{
+    std::string str1("TEST1");
+
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
+    ::NSConsumer *consumer = (::NSConsumer *)malloc(sizeof(::NSConsumer));
+    strcpy(consumer->consumerId, "test");
+
+    std::shared_ptr<OIC::Service::NSConsumer> consumerTemp = std::make_shared<OIC::Service::NSConsumer>
+            (consumer);
+
+    OIC::Service::NSAcceptedConsumers *acceptedConsumers =
+        OIC::Service::NSProviderService::getInstance()->getAcceptedConsumers();
+    acceptedConsumers->addConsumer(consumerTemp);
+
+    OIC::Service::NSResult res = consumerTemp->setTopic("TEST1");
+
+    EXPECT_EQ(res,  OIC::Service::NSResult::OK);
+    free(consumer);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectSuccessUnSetTopic)
+{
+    ::NSConsumer *consumer = (::NSConsumer *)malloc(sizeof(::NSConsumer));
+    strcpy(consumer->consumerId, "test");
+
+    std::shared_ptr<OIC::Service::NSConsumer> consumerTemp = std::make_shared<OIC::Service::NSConsumer>
+            (consumer);
+
+    OIC::Service::NSAcceptedConsumers *acceptedConsumers =
+        OIC::Service::NSProviderService::getInstance()->getAcceptedConsumers();
+    acceptedConsumers->addConsumer(consumerTemp);
+
+    consumerTemp->setTopic("TEST1");
+    OIC::Service::NSResult res = consumerTemp->unsetTopic("TEST1");
+    EXPECT_EQ(res,  OIC::Service::NSResult::OK);
+    free(consumer);
+    OIC::Service::NSProviderService::getInstance()->stop();
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectEqualAddedTopicsAndRegisteredTopics)
+{
+    OIC::Service::NSProviderService::ProviderConfig  config;
+    config.m_subscribeRequestCb = ConsumerSubscribedCallback;
+    config.m_syncInfoCb = MessageSynchronizedCallback;
+    config.subControllability = true;
+    config.resourceSecurity = false;
+
+    OIC::Service::NSProviderService::getInstance()->start(config);
+    std::string str1("TEST1");
+    std::string str2("TEST2");
+
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str2);
+
+    bool isSame = false;
+    auto topicList =  OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList();
+
+    std::string compString[10];
+    int i = 0;
+    for (auto itr : topicList->getTopicsList())
+    {
+        compString[i] = itr.getTopicName(); i++;
+    }
+    std::cout << compString[0] << std::endl;
+    std::cout << compString[1] << std::endl;
+    if (str1.compare(compString[0]) == 0 && str2.compare(compString[1]) == 0)
+    {
+        isSame = true;
+    }
+
+    EXPECT_EQ(isSame, true);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectEqualSetConsumerTopicsAndGetConsumerTopics)
+{
+    std::string str1("TEST1");
+    std::string str2("TEST2");
+    ::NSConsumer *consumer = (::NSConsumer *)malloc(sizeof(::NSConsumer));
+    strcpy(consumer->consumerId, "test");
+
+    std::shared_ptr<OIC::Service::NSConsumer> consumerTemp = std::make_shared<OIC::Service::NSConsumer>
+            (consumer);
+
+    OIC::Service::NSAcceptedConsumers *acceptedConsumers =
+        OIC::Service::NSProviderService::getInstance()->getAcceptedConsumers();
+    acceptedConsumers->addConsumer(consumerTemp);
+
+    consumerTemp->setTopic(str1);
+
+    bool isSame = false;
+    auto topicList =  consumerTemp->getConsumerTopicList();
+
+    std::string compString[10];
+    int i = 0, state[10] = {0};
+    for (auto itr : topicList->getTopicsList())
+    {
+        compString[i] = itr.getTopicName();
+        state[i++] = (int) itr.getState();
+    }
+    std::cout << compString[0] << std::endl;
+    std::cout << compString[1] << std::endl;
+    if (str1.compare(compString[0]) == 0 && str2.compare(compString[1]) == 0
+        && state[0] == 1 &&  state[1] == 0)
+    {
+        isSame = true;
+    }
+    EXPECT_EQ(isSame, true);
+
+    OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
+    OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
+    free(consumer);
+    usleep(2000);
+    OIC::Service::NSProviderService::getInstance()->stop();
+}
+
index 2a43f72..c2d67df 100644 (file)
@@ -94,16 +94,26 @@ notification_consumer_wrapper_test_env.AppendUnique(LIBS = ['notification_consum
 notification_provider_wrapper_test_env = notification_wrapper_test_env.Clone()
 notification_provider_wrapper_test_env.AppendUnique(LIBS = ['notification_provider_wrapper','notification_provider'])
 
-notification_consumer_wrapper_test_src = env.Glob('./NSConsumerServiceTest.cpp')
+notification_consumer_wrapper_test_src = env.Glob('./NSConsumerServiceTest2.cpp')
 notification_consumer_wrapper_test = notification_consumer_wrapper_test_env.Program('notification_consumer_wrapper_test', notification_consumer_wrapper_test_src)
 Alias("notification_consumer_wrapper_test", notification_consumer_wrapper_test)
 env.AppendTarget('notification_consumer_wrapper_test')
 
-notification_provider_wrapper_test_src = env.Glob('./NSProviderServiceTest.cpp')
+notification_consumer_wrapper_test_src = env.Glob('./NSConsumerServiceTest.cpp')
+notification_consumer_wrapper_internaltest = notification_consumer_wrapper_test_env.Program('notification_consumer_wrapper_internaltest', notification_consumer_wrapper_test_src)
+Alias("notification_consumer_wrapper_internaltest", notification_consumer_wrapper_internaltest)
+env.AppendTarget('notification_consumer_wrapper_test')
+
+notification_provider_wrapper_test_src = env.Glob('./NSProviderServiceTest2.cpp')
 notification_provider_wrapper_test = notification_provider_wrapper_test_env.Program('notification_provider_wrapper_test', notification_provider_wrapper_test_src)
 Alias("notification_provider_wrapper_test", notification_provider_wrapper_test)
 env.AppendTarget('notification_provider_wrapper_test')
 
+notification_provider_wrapper_test_src = env.Glob('./NSProviderServiceTest.cpp')
+notification_provider_wrapper_internaltest = notification_provider_wrapper_test_env.Program('notification_provider_wrapper_internaltest', notification_provider_wrapper_test_src)
+Alias("notification_provider_wrapper_internaltest", notification_provider_wrapper_internaltest)
+env.AppendTarget('notification_provider_wrapper_test')
+
 if env.get('TEST') == '1':
     if env.get('SECURED') != '1':
 # TODO: fix this test for MLK and remove this comment line