Notification cpp-wrapper UnitTest
authornikhil.a <nikhil.a7@samsung.com>
Fri, 12 Aug 2016 11:46:19 +0000 (17:16 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Tue, 16 Aug 2016 11:15:26 +0000 (11:15 +0000)
1)Added ProviderService unittest
2)Added ConsumerService unittest

Change-Id: Ibb510f4e1e6407ca3ecab791ea4d2e76f03e669c
Signed-off-by: nikhil.a <nikhil.a7@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10345
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/notification/cpp-wrapper/SConscript
service/notification/cpp-wrapper/unittest/NSConsumerServiceSimulator.h [new file with mode: 0644]
service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp [new file with mode: 0644]
service/notification/cpp-wrapper/unittest/NSProviderServiceSimulator.h [new file with mode: 0644]
service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp [new file with mode: 0644]
service/notification/cpp-wrapper/unittest/SConscript [new file with mode: 0644]

index 8178583..81316e3 100755 (executable)
@@ -1,3 +1,23 @@
+#******************************************************************
+#
+# 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
 # build producer notification wrapper
 SConscript('provider/SConscript')
 
 # build producer notification wrapper
 SConscript('provider/SConscript')
 
@@ -6,3 +26,6 @@ SConscript('consumer/SConscript')
 
 # Go to build sample apps using wrapper
 SConscript('examples/linux/SConscript')
 
 # Go to build sample apps using wrapper
 SConscript('examples/linux/SConscript')
+
+# Go to build Unit test
+SConscript('unittest/SConscript')
\ No newline at end of file
diff --git a/service/notification/cpp-wrapper/unittest/NSConsumerServiceSimulator.h b/service/notification/cpp-wrapper/unittest/NSConsumerServiceSimulator.h
new file mode 100644 (file)
index 0000000..cf22831
--- /dev/null
@@ -0,0 +1,194 @@
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef _NS_CONSUMER_SERVICE_SIMULATOR_H_
+#define _NS_CONSUMER_SERVICE_SIMULATOR_H_
+
+#include <iostream>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+class NSConsumerSimulator
+{
+private:
+    std::function<void(const int&, const std::string&, const std::string&,
+            const std::string&)> m_messageFunc;
+    std::function<void(const int&, const int&)> m_syncFunc;
+
+    std::shared_ptr<OC::OCResource> m_syncResource;
+    std::shared_ptr<OC::OCResource> m_msgResource;
+
+public:
+    NSConsumerSimulator()
+    : m_messageFunc(), m_syncFunc(),
+      m_syncResource() { };
+    ~NSConsumerSimulator() = default;
+
+    NSConsumerSimulator(const NSConsumerSimulator &) = delete;
+    NSConsumerSimulator & operator = (const NSConsumerSimulator &) = delete;
+
+    NSConsumerSimulator(NSConsumerSimulator &&) = delete;
+    NSConsumerSimulator & operator = (NSConsumerSimulator &&) = delete;
+
+    void findProvider()
+    {
+        OC::OCPlatform::findResource("", std::string("/oic/res?rt=oic.r.notification"),
+                OCConnectivityType::CT_DEFAULT,
+                std::bind(&NSConsumerSimulator::findResultCallback, this, std::placeholders::_1),
+                OC::QualityOfService::LowQos);
+    }
+
+    void syncToProvider(int & type, const int & id, const std::string & providerID)
+    {
+        if (m_syncResource == nullptr)
+        {
+            std::cout << "m_syncResource is null" << std::endl;
+            return;
+        }
+
+        OC::OCRepresentation rep;
+        rep.setValue("PROVIDER_ID", providerID);
+        rep.setValue("MESSAGE_ID", id);
+        rep.setValue("STATE", type);
+
+        m_syncResource->post(rep, OC::QueryParamsMap(), &onPost, OC::QualityOfService::LowQos);
+    }
+
+    bool cancelObserves()
+    {
+        if(!msgResourceCancelObserve(OC::QualityOfService::HighQos) &&
+                !syncResourceCancelObserve(OC::QualityOfService::HighQos))
+            return true;
+        return false;
+    }
+
+    void setCallback(std::function<void(const int&, const std::string&,
+            const std::string&, const std::string&)> messageFunc,
+            const std::function<void(const int&, const int&)> & syncFunc)
+    {
+        m_messageFunc = messageFunc;
+        m_syncFunc = syncFunc;
+    }
+
+private:
+    static void onPost(const OC::HeaderOptions &/*headerOption*/,
+                const OC::OCRepresentation & /*rep*/ , const int eCode)
+    {
+        std::cout << __func__ << " result : " << eCode << std::endl;
+    }
+    void findResultCallback(std::shared_ptr<OC::OCResource> resource)
+    {
+
+        std::cout << __func__ << " " << resource->host() << std::endl;
+
+        if(resource->uri() == "/notification")
+        {
+            resource->get(OC::QueryParamsMap(),
+                    std::bind(&NSConsumerSimulator::onGet, this,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, resource),
+                    OC::QualityOfService::LowQos);
+        }
+    }
+    void onGet(const OC::HeaderOptions &/*headerOption*/,
+            const OC::OCRepresentation & rep , const int eCode,
+            std::shared_ptr<OC::OCResource> resource)
+    {
+        std::cout << __func__ << " " << rep.getHost() << " result : " << eCode << std::endl;
+
+        OC::QueryParamsMap map;
+        map.insert(std::pair<std::string,std::string>(std::string("consumerid"), std::string("123456789012345678901234567890123456")));
+
+        try
+        {
+            std::cout << "resourc : host " << resource->host() << std::endl;
+            std::cout << "resourc : uri " << resource->uri() << std::endl;
+            std::cout << " resource->connectivityType() " <<  resource->connectivityType() << std::endl;
+            std::cout << "resourc : getResourceInterfaces " << resource->getResourceInterfaces()[0] << std::endl;
+            std::cout << "resourc : getResourceTypes " << resource->getResourceTypes()[0] << std::endl;
+
+            std::vector<std::string> rts{"oic.r.notification"};
+
+            m_msgResource
+                = OC::OCPlatform::constructResourceObject(
+                        std::string(resource->host()), std::string(resource->uri() + "/message"),
+                        OCConnectivityType(resource->connectivityType()), true, rts,
+                        std::vector<std::string>(resource->getResourceInterfaces()));
+
+            m_msgResource->observe(OC::ObserveType::Observe, map,
+                            std::bind(&NSConsumerSimulator::onObserve, this,
+                                    std::placeholders::_1, std::placeholders::_2,
+                                    std::placeholders::_3, std::placeholders::_4, resource),
+                            OC::QualityOfService::LowQos);
+        }
+        catch(std::exception & e)
+        {
+            std::cout << "OC::ResoureInitException : " << e.what() << std::endl;
+        }
+        m_syncResource
+            = OC::OCPlatform::constructResourceObject(resource->host(), resource->uri() + "/sync",
+                    resource->connectivityType(), true, resource->getResourceTypes(),
+                    resource->getResourceInterfaces());
+
+        m_syncResource->observe(OC::ObserveType::Observe, map,
+                std::bind(&NSConsumerSimulator::onObserve, this,
+                        std::placeholders::_1, std::placeholders::_2,
+                        std::placeholders::_3, std::placeholders::_4, resource),
+                OC::QualityOfService::LowQos);
+
+    }
+    void onObserve(const OC::HeaderOptions &/*headerOption*/,
+            const OC::OCRepresentation &rep , const int &eCode, const int &,
+            std::shared_ptr<OC::OCResource> )
+    {
+        std::cout << __func__ << " " << rep.getHost() << " result : " << eCode;
+        std::cout << " uri : " << rep.getUri() << std::endl;
+
+        if (rep.getUri() == "/notification/message" && rep.hasAttribute("MESSAGE_ID")
+                && rep.getValue<int>("MESSAGE_ID") != 1)
+        {
+            std::cout << "ID : " << rep.getValue<int>("ID") << std::endl;
+            std::cout << "TITLE : " << rep.getValueToString("TITLE") << std::endl;
+            std::cout << "CONTENT : " << rep.getValueToString("CONTENT") << std::endl;
+            m_messageFunc(int(rep.getValue<int>("MESSAGE_ID")),
+                          std::string(rep.getValueToString("TITLE")),
+                          std::string(rep.getValueToString("CONTENT")),
+                          std::string(rep.getValueToString("SOURCE")));
+        }
+        else if (rep.getUri() == "/notification/sync")
+        {
+            std::cout << "else if (rep.getUri() == sync) " << std::endl;
+            m_syncFunc(int(rep.getValue<int>("STATE")), int(rep.getValue<int>("ID")));
+        }
+    }
+
+    OCStackResult msgResourceCancelObserve(OC::QualityOfService qos)
+    {
+        return m_msgResource->cancelObserve(qos);
+    }
+
+    OCStackResult syncResourceCancelObserve(OC::QualityOfService qos)
+    {
+        return m_syncResource->cancelObserve(qos);
+    }
+};
+
+
+#endif //_NS_CONSUMER_SERVICE_SIMULATOR_H_
\ No newline at end of file
diff --git a/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp b/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp
new file mode 100644 (file)
index 0000000..686e7df
--- /dev/null
@@ -0,0 +1,476 @@
+//******************************************************************
+//
+// 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 <gtest/gtest.h>
+#include <HippoMocks/hippomocks.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 "NSProviderServiceSimulator.h"
+
+namespace
+{
+    NSProviderSimulator g_providerSimul;
+     OIC::Service::NSProvider * g_provider;
+
+    std::atomic_bool g_isStartedStack(false);
+
+    std::chrono::milliseconds g_waitForResponse(2000);
+
+    std::condition_variable responseCon;
+    std::mutex mutexForCondition;
+
+    enum class NSSelector
+    {
+        NS_SELECTION_CONSUMER = 0,
+        NS_SELECTION_PROVIDER = 1
+    };
+
+}
+
+class TestWithMock: public testing::Test
+{
+public:
+    MockRepository mocks;
+
+protected:
+    virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
+    {
+
+    }
+
+    virtual void TearDown()
+    {
+        try
+        {
+            mocks.VerifyAll();
+        }
+        catch (...)
+        {
+            mocks.reset();
+            throw;
+        }
+    }
+};
+
+class NotificationServiceConsumerTest : public TestWithMock
+{
+public:
+    NotificationServiceConsumerTest() = default;
+    ~NotificationServiceConsumerTest() = default;
+
+    static void ProviderDiscoveredCallbackEmpty( OIC::Service::NSProvider *)
+    {
+        std::cout << __func__ << std::endl;
+    }
+
+    static void NotificationReceivedCallbackEmpty( OIC::Service::NSMessage *)
+    {
+        std::cout << __func__ << std::endl;
+    }
+
+    static void SyncCallbackEmpty(OIC::Service::NSSyncInfo *)
+    {
+        std::cout << __func__ << std::endl;
+    }
+
+    static void FoundResourceEmpty(std::shared_ptr< OC::OCResource >)
+    {
+        std::cout << __func__ << std::endl;
+    }
+
+    static void ProviderChangedCallbackEmpty( OIC::Service::NSProvider * , OIC::Service::NSResponse )
+    {
+        std::cout << __func__ << std::endl;
+    }
+
+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::NSConsumerService::ConsumerConfig cfg;
+    cfg.m_discoverCb = ProviderDiscoveredCallbackEmpty;
+    cfg.m_changedCb = ProviderChangedCallbackEmpty;
+    OIC::Service::NSConsumerService::getInstance()->Start(cfg);
+}
+
+TEST_F(NotificationServiceConsumerTest, StopConsumerPositive)
+{
+    OIC::Service::NSConsumerService::getInstance()->Stop();
+}
+
+TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithNonAccepterWhenStartedConsumerFirst)
+{
+    mocks.ExpectCallFunc(ProviderDiscoveredCallbackEmpty).Do(
+            [this]( OIC::Service::NSProvider * provider)
+            {
+                std::cout << "Call Discovered" << std::endl;
+                g_provider = provider;
+                g_provider->subscribe();
+                g_provider->setListener((OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallbackEmpty,
+                                                   (OIC::Service::NSProvider::SyncInfoReceivedCallback)SyncCallbackEmpty);
+                responseCon.notify_all();
+            });
+
+    OIC::Service::NSConsumerService::ConsumerConfig cfg;
+    cfg.m_discoverCb = ProviderDiscoveredCallbackEmpty;
+    cfg.m_changedCb = ProviderChangedCallbackEmpty;
+    OIC::Service::NSConsumerService::getInstance()->Start(cfg);
+
+    g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_CONSUMER);
+    g_providerSimul.createNotificationResource();
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+     OIC::Service::NSConsumerService::getInstance()->Stop();
+    g_providerSimul.deleteNotificationResource();
+}
+
+TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithNonAccepterWhenStartedConsumerAfter)
+{
+    g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_CONSUMER);
+    g_providerSimul.createNotificationResource();
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+    mocks.ExpectCallFunc(ProviderDiscoveredCallbackEmpty).Do(
+            [this]( OIC::Service::NSProvider * provider)
+            {
+                std::cout << "Call Discovered" << std::endl;
+                 g_provider->subscribe();
+                g_provider->setListener((OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallbackEmpty,
+                                                   (OIC::Service::NSProvider::SyncInfoReceivedCallback)SyncCallbackEmpty);
+                responseCon.notify_all();
+            });
+
+    OIC::Service::NSConsumerService::ConsumerConfig cfg;
+    cfg.m_discoverCb = ProviderDiscoveredCallbackEmpty;
+    cfg.m_changedCb = ProviderChangedCallbackEmpty;
+    OIC::Service::NSConsumerService::getInstance()->Start(cfg);
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+}
+
+TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithNonAccepterWhenRescan)
+{
+    g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_CONSUMER);
+    mocks.ExpectCallFunc(ProviderDiscoveredCallbackEmpty).Do(
+            [this]( OIC::Service::NSProvider * provider)
+            {
+                std::cout << "Call Discovered" << std::endl;
+                g_provider = provider;
+                 g_provider->subscribe();
+                g_provider->setListener((OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallbackEmpty,
+                                                   (OIC::Service::NSProvider::SyncInfoReceivedCallback)SyncCallbackEmpty);
+                std::cout << g_provider->getProviderId() << std::endl;
+                responseCon.notify_all();
+            });
+
+     OIC::Service::NSConsumerService::getInstance()->RescanProvider();
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+//     OIC::Service::NSConsumerService::getInstance()->Stop();
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectSubscribeSuccess)
+{
+//    mocks.ExpectCallFunc(ProviderChangedCallbackEmpty).Do(
+//            []( OIC::Service::NSProvider * , OIC::Service::NSResponse)
+//            {
+//                std::cout << "Income Accepted subscription : " << std::endl;
+//            });
+
+    g_provider->subscribe();
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectReceiveNotification)
+{
+    uint64_t id = 10;
+    std::string title = "title";
+    std::string msg = "msg";
+
+    mocks.ExpectCallFunc(NotificationReceivedCallbackEmpty).Do(
+            []( OIC::Service::NSMessage * message)
+            {
+                std::cout << "Income Notification : " << message->getMessageId() << std::endl;
+            });
+
+    g_providerSimul.notifyMessage(id, title, msg);
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+     OIC::Service::NSConsumerService::getInstance()->Stop();
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectReceiveNotificationWithAccepterisProvider)
+{
+    uint64_t id = 11;
+    std::string title = "title";
+    std::string msg = "msg";
+
+    g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_PROVIDER);
+
+    OIC::Service::NSConsumerService::ConsumerConfig cfg;
+    cfg.m_discoverCb = ProviderDiscoveredCallbackEmpty;
+    cfg.m_changedCb = ProviderChangedCallbackEmpty;
+    OIC::Service::NSConsumerService::getInstance()->Start(cfg);
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+    mocks.ExpectCallFunc(NotificationReceivedCallbackEmpty).Do(
+            []( OIC::Service::NSMessage * message)
+            {
+                std::cout << "Income Notification : " << message->getMessageId() << std::endl;
+            });
+
+    g_providerSimul.notifyMessage(id, title, msg);
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+//    g_providerSimul.deleteNotificationResource();
+//     OIC::Service::NSConsumerService::getInstance()->Stop();
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectCallbackReadCheckWhenProviderNotifySync)
+{
+    uint64_t id = 12;
+    std::string title = "title";
+    std::string msg = "msg";
+
+    OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
+
+    mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
+            []( OIC::Service::NSMessage * message)
+            {
+                std::cout << "Income Notification : " << message->getMessageId() << std::endl;
+            });
+
+    mocks.ExpectCallFunc(SyncCallbackEmpty).Do(
+            [& type](OIC::Service::NSSyncInfo * sync)
+            {
+                std::cout << "Income SyncInfo : " << sync->getMessageId()
+                        << ", State : " << (int) sync->getState() << std::endl;
+                type = sync->getState();
+
+            });
+
+    g_providerSimul.notifyMessage(id, title, msg);
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+    g_providerSimul.sendRead(id);
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+//    g_providerSimul.deleteNotificationResource();
+//     OIC::Service::NSConsumerService::getInstance()->Stop();
+
+    EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ, type);
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectCallbackDismissCheckWhenProviderNotifySync)
+{
+    uint64_t id = 13;
+    std::string title = "title";
+    std::string msg = "msg";
+
+    OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
+
+    mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
+            []( OIC::Service::NSMessage * message)
+            {
+                std::cout << "Income Notification : " << message->getMessageId() << std::endl;
+            });
+
+    mocks.ExpectCallFunc(SyncCallbackEmpty).Do(
+            [& type](OIC::Service::NSSyncInfo * sync)
+            {
+                std::cout << "Income Notification : " << sync->getMessageId()
+                        << ", State : " << (int) sync->getState() << std::endl;
+                type = sync->getState();
+
+            });
+
+    g_providerSimul.notifyMessage(id, title, msg);
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+    g_providerSimul.sendDismiss(id);
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+//    g_providerSimul.deleteNotificationResource();
+//     OIC::Service::NSConsumerService::getInstance()->Stop();
+
+    EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED, type);
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectCallbackReadCheckWhenConsumerPostSync)
+{
+    uint64_t id = 14;
+    std::string title = "title";
+    std::string msg = "msg";
+
+    OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
+
+    mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
+            []( OIC::Service::NSMessage * message)
+            {
+                std::cout << "Income Notification : " << message->getMessageId() << std::endl;
+                g_provider->SendSyncInfo(message->getMessageId(), OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);
+                std::unique_lock< std::mutex > lock{ mutexForCondition };
+                responseCon.wait_for(lock, g_waitForResponse);
+            });
+
+    mocks.ExpectCallFunc(SyncCallbackEmpty).Do(
+            [& type](OIC::Service::NSSyncInfo * sync)
+            {
+                std::cout << "Income Notification : " << sync->getMessageId()
+                        << ", State : " << (int) sync->getState() << std::endl;
+                type = sync->getState();
+
+            });
+
+    g_providerSimul.notifyMessage(id, title, msg);
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+//    g_providerSimul.deleteNotificationResource();
+//     OIC::Service::NSConsumerService::getInstance()->Stop();
+
+    EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ, type);
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectCallbackDismissCheckWhenConsumerPostSync)
+{
+    uint64_t id = 15;
+    std::string title = "title";
+    std::string msg = "msg";
+
+    OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
+
+    mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
+            []( OIC::Service::NSMessage * message)
+            {
+                std::cout << "Income Notification : " << message->getMessageId() << std::endl;
+                g_provider->SendSyncInfo(message->getMessageId(), OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED);
+                std::unique_lock< std::mutex > lock{ mutexForCondition };
+                responseCon.wait_for(lock, g_waitForResponse);
+            });
+
+    mocks.ExpectCallFunc(SyncCallbackEmpty).Do(
+            [& type](OIC::Service::NSSyncInfo * sync)
+            {
+                std::cout << "Income Notification : " << sync->getMessageId()
+                        << ", State : " << (int) sync->getState() << std::endl;
+                type = sync->getState();
+
+            });
+
+    g_providerSimul.notifyMessage(id, title, msg);
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+    EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED, type);
+}
+
+TEST_F(NotificationServiceConsumerTest, ExpectUnsubscribeSuccess)
+{
+    g_provider->unSubscribe();
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+    g_providerSimul.deleteNotificationResource();
+     OIC::Service::NSConsumerService::getInstance()->Stop();
+
+}
diff --git a/service/notification/cpp-wrapper/unittest/NSProviderServiceSimulator.h b/service/notification/cpp-wrapper/unittest/NSProviderServiceSimulator.h
new file mode 100644 (file)
index 0000000..1371e89
--- /dev/null
@@ -0,0 +1,333 @@
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef _NS_PROVIDER_SERVICE_SIMULATOR_H_
+#define _NS_PROVIDER_SERVICE_SIMULATOR_H_
+
+#include <iostream>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "OCResourceResponse.h"
+
+namespace
+{
+    enum class requestType
+    {
+        NS_NOTIFICATION,
+        NS_MESSAGE,
+        NS_SYNC,
+    };
+}
+
+class NSProviderSimulator
+{
+private:
+    OCResourceHandle m_notificationHandle;
+    OCResourceHandle m_messageHandle;
+    OCResourceHandle m_syncHandle;
+    OC::OCRepresentation m_syncRep;
+    OC::OCRepresentation m_messageRep;
+    int m_accepter;
+
+    std::string m_notificationUri;
+    std::string m_messageUri;
+    std::string m_syncUri;
+
+    OC::ObservationIds m_syncObservers;
+
+public:
+    NSProviderSimulator()
+    : m_notificationHandle(), m_messageHandle(), m_syncHandle(),
+      m_syncRep(), m_messageRep(), m_accepter(0),
+      m_notificationUri(std::string("/notification")),
+      m_messageUri(std::string("/message")),
+      m_syncUri(std::string("/sync")),
+      m_syncObservers()
+    {
+
+    };
+
+    ~NSProviderSimulator() = default;
+
+    NSProviderSimulator(const NSProviderSimulator &) = delete;
+    NSProviderSimulator & operator = (const NSProviderSimulator &) = delete;
+
+    NSProviderSimulator(NSProviderSimulator &&) = delete;
+    NSProviderSimulator & operator = (NSProviderSimulator &&) = delete;
+
+private:
+    std::shared_ptr<OC::OCResourceResponse> getResponse(
+            std::shared_ptr< OC::OCResourceRequest > requests, requestType type)
+    {
+        auto response = std::make_shared<OC::OCResourceResponse>();
+        response->setRequestHandle(requests->getRequestHandle());
+        response->setResourceHandle(requests->getResourceHandle());
+
+        int requestFlag = requests->getRequestHandlerFlag();
+        if (requestFlag == OC::RequestHandlerFlag::RequestFlag)
+        {
+            std::string request = requests->getRequestType();
+
+            response->setErrorCode(200);
+            response->setResponseResult(OC_EH_OK);
+
+            if (request == "GET")
+            {
+                OC::OCRepresentation rep;
+
+                if (type == requestType::NS_NOTIFICATION)
+                {
+                    std::string msgUri = m_notificationUri + m_messageUri;
+                    std::string syncUri = m_notificationUri + m_syncUri;
+                    std::string providerId = "123456789012345678901234567890123456";
+                    rep.setValue("ACCEPTER", m_accepter);
+                    rep.setValue("MESSAGE_URI", msgUri);
+                    rep.setValue("SYNC_URI", syncUri);
+                    rep.setValue("PROVIDER_ID", providerId);
+                }
+                else if (type == requestType::NS_SYNC)
+                {
+                    rep = m_syncRep;
+                }
+                else if (type == requestType::NS_MESSAGE)
+                {
+                    rep = m_messageRep;
+                }
+                else
+                {
+                    return NULL;
+                }
+
+                response->setResourceRepresentation(rep);
+                return response;
+            }
+
+            else if (request == "POST" && type == requestType::NS_SYNC)
+            {
+                m_syncRep = requests->getResourceRepresentation();
+
+                std::cout << "Receive POST at Sync" << std::endl;
+                std::cout << "Sync Id : " << m_syncRep.getValueToString("ID") << std::endl;
+                std::cout << "Sync State : " << m_syncRep.getValueToString("STATE") << std::endl;
+
+                response->setResourceRepresentation(m_syncRep);
+
+                OC::OCPlatform::notifyListOfObservers(m_syncHandle, m_syncObservers, response);
+
+                return response;
+            }
+        }
+
+        return NULL;
+    }
+
+    void setObserver(std::shared_ptr< OC::OCResourceRequest > requests, requestType type)
+    {
+        if (type == requestType::NS_SYNC)
+        {
+            OC::ObservationInfo observationInfo = requests->getObservationInfo();
+            if (OC::ObserveAction::ObserveRegister == observationInfo.action)
+            {
+                m_syncObservers.push_back(observationInfo.obsId);
+            }
+            else if (OC::ObserveAction::ObserveUnregister == observationInfo.action)
+            {
+                m_syncObservers.erase(std::remove(
+                        m_syncObservers.begin(), m_syncObservers.end(),
+                        observationInfo.obsId), m_syncObservers.end());
+            }
+        }
+        else if (type == requestType::NS_MESSAGE)
+        {
+            OC::OCRepresentation rep;
+            std::string providerId = "123456789012345678901234567890123456";
+            rep.setValue<int>("MESSAGE_ID", (int)1);
+            rep.setValue("PROVIDER_ID", providerId);
+
+            auto response = std::make_shared<OC::OCResourceResponse>();
+            response->setRequestHandle(requests->getRequestHandle());
+            response->setResourceHandle(requests->getResourceHandle());
+            response->setErrorCode(200);
+            response->setResponseResult(OC_EH_OK);
+            response->setResourceRepresentation(rep);
+
+            OC::ObservationIds ids;
+            ids.push_back(requests->getObservationInfo().obsId);
+
+            OC::OCPlatform::notifyListOfObservers(m_messageHandle, ids, response);
+        }
+    }
+
+    OCEntityHandlerResult entityHandler(
+            std::shared_ptr< OC::OCResourceRequest > request, requestType type)
+    {
+        if (!request)
+        {
+            return OC_EH_ERROR;
+        }
+
+        std::cout << "Provider : Income request : " << request->getRequestHandlerFlag() << std::endl;
+        if ((request->getRequestHandlerFlag() & OC::RequestHandlerFlag::ObserverFlag))
+        {
+            std::cout << "Provider : Income Observe : " << std::endl;
+            setObserver(request, type);
+            return OC_EH_OK;
+        }
+
+        auto pResponse = getResponse(request, type);
+        if (pResponse == nullptr)
+        {
+            return OC_EH_ERROR;
+        }
+
+        try
+        {
+            OC::OCPlatform::sendResponse(pResponse);
+        }
+        catch (std::exception & e)
+        {
+            return OC_EH_ERROR;
+        }
+
+        return OC_EH_OK;
+    }
+
+public:
+
+    void setAccepter(int accepter)
+    {
+        m_accepter = accepter;
+    }
+
+    void notifyMessage()
+    {
+        std::cout << "Provider : notify~" << std::endl;
+        OC::OCPlatform::notifyAllObservers(m_messageHandle);
+    }
+
+    void notifyMessage(const uint64_t & id, const std::string & title, const std::string & content)
+    {
+        setMessage(id, title, content);
+        notifyMessage();
+    }
+
+    void sendRead(const uint64_t & id)
+    {
+        std::string providerId = "123456789012345678901234567890123456";
+        m_syncRep.setValue<int>("MESSAGE_ID", id);
+        m_syncRep.setValue("STATE", (int)1);
+        m_syncRep.setValue("PROVIDER_ID", providerId);
+        OC::OCPlatform::notifyAllObservers(m_syncHandle);
+    }
+    void sendDismiss(const uint64_t & id)
+    {
+        std::string providerId = "123456789012345678901234567890123456";
+        m_syncRep.setValue<int>("MESSAGE_ID", id);
+        m_syncRep.setValue("STATE", (int)2);
+        m_syncRep.setValue("PROVIDER_ID", providerId);
+        OC::OCPlatform::notifyAllObservers(m_syncHandle);
+    }
+
+    void setMessage(const uint64_t & id, const std::string & title, const std::string & content)
+    {
+        std::string providerId = "123456789012345678901234567890123456";
+        m_messageRep.setValue<int>("MESSAGE_ID", id);
+        m_messageRep.setValue("TITLE", title);
+        m_messageRep.setValue("CONTENTTEXT", content);
+        m_messageRep.setValue("PROVIDER_ID", providerId);
+    }
+
+    void deleteNotificationResource()
+    {
+        OC::OCPlatform::unregisterResource(m_notificationHandle);
+        OC::OCPlatform::unregisterResource(m_messageHandle);
+        OC::OCPlatform::unregisterResource(m_syncHandle);
+    }
+
+    void createNotificationResource()
+    {
+        createNotificationResource(m_notificationUri);
+    }
+
+    void createNotificationResource(const std::string & uri)
+    {
+        if (m_notificationUri != uri)
+        {
+            m_notificationUri = uri;
+        }
+
+        OC::OCPlatform::startPresence(30);
+
+        std::string notificationUri = m_notificationUri;
+        std::string resourceTypeName = "oic.r.message.notification";
+        std::string resourceInterface = OC::DEFAULT_INTERFACE;
+
+        uint8_t resourceProperty = OC_OBSERVABLE;
+        std::string childUri = uri + m_messageUri;
+        try
+        {
+            OC::OCPlatform::registerResource(
+                    m_messageHandle, childUri,
+                    resourceTypeName, resourceInterface,
+                    std::bind(& NSProviderSimulator::entityHandler, this,
+                            std::placeholders::_1, requestType::NS_MESSAGE),
+                            resourceProperty);
+        }
+        catch (std::exception & e)
+        {
+            std::cout << e.what() << std::endl;
+        }
+
+        resourceTypeName = "oic.r.sync.notification";
+        childUri = uri + m_syncUri;
+        try
+        {
+            OC::OCPlatform::registerResource(
+                    m_syncHandle, childUri,
+                    resourceTypeName, resourceInterface,
+                    std::bind(& NSProviderSimulator::entityHandler, this,
+                            std::placeholders::_1, requestType::NS_SYNC),
+                            resourceProperty);
+        }
+        catch (std::exception & e)
+        {
+            std::cout << e.what() << std::endl;
+        }
+
+        resourceProperty = OC_DISCOVERABLE;
+        resourceTypeName = "oic.r.notification";
+        try
+        {
+            OC::OCPlatform::registerResource(
+                    m_notificationHandle, notificationUri,
+                    resourceTypeName, resourceInterface,
+                    std::bind(& NSProviderSimulator::entityHandler, this,
+                            std::placeholders::_1, requestType::NS_NOTIFICATION),
+                            resourceProperty);
+        }
+        catch (std::exception & e)
+        {
+            std::cout << e.what() << std::endl;
+        }
+    }
+};
+
+#endif /* _NS_PROVIDER_SERVICE_SIMULATOR_H_ */
diff --git a/service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp b/service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp
new file mode 100644 (file)
index 0000000..5e9fd0e
--- /dev/null
@@ -0,0 +1,337 @@
+//******************************************************************
+//
+// 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 <gtest/gtest.h>
+#include <HippoMocks/hippomocks.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"
+
+namespace
+{
+    std::atomic_bool g_isStartedStack(false);
+
+    std::chrono::milliseconds g_waitForResponse(3000);
+
+    std::condition_variable responseCon;
+    std::mutex mutexForCondition;
+
+    NSConsumerSimulator g_consumerSimul;
+     OIC::Service::NSConsumer * g_consumer;
+}
+
+class TestWithMock: public testing::Test
+{
+public:
+    MockRepository mocks;
+
+protected:
+    virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test())) {}
+
+    virtual void TearDown() {
+        try
+        {
+            mocks.VerifyAll();
+        }
+        catch (...)
+        {
+            mocks.reset();
+            throw;
+        }
+    }
+};
+
+class NotificationProviderServiceTest : public TestWithMock
+{
+public:
+    NotificationProviderServiceTest() = default;
+    ~NotificationProviderServiceTest() = default;
+
+    static void ConsumerSubscribedCallbackEmpty(OIC::Service::NSConsumer *)
+    {
+        std::cout << __func__ << std::endl;
+    }
+
+    static void MessageSynchronizedCallbackEmpty(OIC::Service::NSSyncInfo *)
+    {
+        std::cout << __func__ << std::endl;
+    }
+
+    static void MessageCallbackFromConsumerEmpty(
+            const int &, const std::string &, const std::string &, const std::string &)
+    {
+        std::cout << __func__ << std::endl;
+    }
+
+    static void SyncCallbackFromConsumerEmpty(int, int)
+    {
+        std::cout << __func__ << std::endl;
+    }
+
+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::HighQos
+            };
+            OC::OCPlatform::Configure(cfg);
+
+            try
+            {
+                OC::OCPlatform::stopPresence();
+            }
+            catch (...)
+            {
+
+            }
+
+            g_isStartedStack = true;
+        }
+
+    }
+
+    void TearDown()
+    {
+        TestWithMock::TearDown();
+    }
+
+};
+
+TEST_F(NotificationProviderServiceTest, StartProviderPositiveWithPolicyTrue)
+{
+    OIC::Service::NSProviderService::ProviderConfig config;
+    config.m_subscribeRequestCb = ConsumerSubscribedCallbackEmpty;
+    config.m_syncInfoCb = MessageSynchronizedCallbackEmpty;
+    config.policy = true;
+
+    OIC::Service::NSResult ret =  OIC::Service::NSProviderService::getInstance()->Start(config);
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+    EXPECT_EQ(ret,  OIC::Service::NSResult::OK);
+}
+
+TEST_F(NotificationProviderServiceTest, StopProviderPositive)
+{
+     OIC::Service::NSResult ret =  OIC::Service::NSProviderService::getInstance()->Stop();
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+    EXPECT_EQ(ret,  OIC::Service::NSResult::OK);
+}
+
+TEST_F(NotificationProviderServiceTest, StartProviderPositiveWithPolicyFalse)
+{
+    OIC::Service::NSProviderService::ProviderConfig  config;
+    config.m_subscribeRequestCb = ConsumerSubscribedCallbackEmpty;
+    config.m_syncInfoCb = MessageSynchronizedCallbackEmpty;
+    config.policy = false;
+
+     OIC::Service::NSResult ret =  OIC::Service::NSProviderService::getInstance()->Start(config);
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, std::chrono::milliseconds(3000));
+    g_consumerSimul.findProvider();
+
+    responseCon.wait_for(lock, std::chrono::milliseconds(3000));
+     OIC::Service::NSProviderService::getInstance()->Stop();
+    EXPECT_EQ(ret,  OIC::Service::NSResult::OK);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectCallbackWhenReceiveSubscribeRequestWithAccepterProvider)
+{
+    mocks.ExpectCallFunc(ConsumerSubscribedCallbackEmpty).Do(
+            []( OIC::Service::NSConsumer * consumer)
+            {
+                std::cout << "ConsumerSubscribedCallbackEmpty" << std::endl;
+                g_consumer = new  OIC::Service::NSConsumer(consumer->getConsumerId());
+                responseCon.notify_all();
+            });
+
+    OIC::Service::NSProviderService::ProviderConfig  config;
+    config.m_subscribeRequestCb = ConsumerSubscribedCallbackEmpty;
+    config.m_syncInfoCb = MessageSynchronizedCallbackEmpty;
+    config.policy = true;
+
+     OIC::Service::NSProviderService::getInstance()->Start(config);
+
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+    g_consumerSimul.setCallback(MessageCallbackFromConsumerEmpty,
+            SyncCallbackFromConsumerEmpty);
+    g_consumerSimul.findProvider();
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, std::chrono::milliseconds(1000));
+}
+
+TEST_F(NotificationProviderServiceTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
+{
+    bool expectTrue = true;
+    int msgID;
+
+    mocks.OnCallFunc(MessageCallbackFromConsumerEmpty).Do(
+            [& expectTrue, &msgID](const int &id, const std::string&, const std::string&, const std::string&)
+            {
+                if (id == msgID)
+                {
+                    std::cout << "This function never call" << std::endl;
+                    expectTrue = false;
+                }
+            });
+
+    g_consumer->acceptSubscription(g_consumer, false);
+
+     OIC::Service::NSMessage * msg =  OIC::Service::NSProviderService::getInstance()->CreateMessage();
+    msgID = (int)msg->getMessageId();
+    msg->setTitle(std::string("Title"));
+    msg->setContentText(std::string("ContentText"));
+    msg->setSourceName(std::string("OCF"));
+
+     OIC::Service::NSProviderService::getInstance()->SendMessage(msg);
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, std::chrono::milliseconds(1000));
+
+    EXPECT_EQ(expectTrue, true);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectCallNotifyOnConsumerByAcceptIsTrue)
+{
+    int msgID;
+
+    mocks.ExpectCallFunc(MessageCallbackFromConsumerEmpty).Do(
+            [&msgID](const int &id, const std::string&, const std::string&, const std::string&)
+            {
+                if (id == msgID)
+                {
+                    std::cout << "ExpectCallNotifyOnConsumerByAcceptIsTrue" << std::endl;
+                    responseCon.notify_all();
+                }
+            });
+
+    g_consumer->acceptSubscription(g_consumer, true);
+
+     OIC::Service::NSMessage * msg =  OIC::Service::NSProviderService::getInstance()->CreateMessage();
+    msgID = (int)msg->getMessageId();
+    msg->setTitle(std::string("Title"));
+    msg->setContentText(std::string("ContentText"));
+    msg->setSourceName(std::string("OCF"));
+
+      OIC::Service::NSProviderService::getInstance()->SendMessage(msg);
+    {
+        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        responseCon.wait_for(lock, g_waitForResponse);
+    }
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectCallbackSyncOnReadToConsumer)
+{
+    int id;
+
+    mocks.ExpectCallFunc(SyncCallbackFromConsumerEmpty).Do(
+            [& id](int & type, int &syncId)
+            {
+        std::cout << "MessageSynchronizedCallbackEmpty" << std::endl;
+                if (syncId == id &&
+                        type == (int)OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ)
+                {
+                    std::cout << "ExpectCallbackSyncOnReadFromConsumer" << std::endl;
+                    responseCon.notify_all();
+                }
+            });
+
+    OIC::Service::NSMessage * msg =  OIC::Service::NSProviderService::getInstance()->CreateMessage();
+    id = (int)msg->getMessageId();
+    msg->setTitle(std::string("Title"));
+    msg->setContentText(std::string("ContentText"));
+    msg->setSourceName(std::string("OCF"));
+
+     OIC::Service::NSProviderService::getInstance()->SendSyncInfo(msg->getMessageId(), OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, std::chrono::milliseconds(5000));
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectCallbackSyncOnReadFromConsumer)
+{
+    int type = (int)OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
+    int id;
+    mocks.ExpectCallFunc(MessageSynchronizedCallbackEmpty).Do(
+            [& id](OIC::Service::NSSyncInfo * sync)
+            {
+                std::cout << "MessageSynchronizedCallbackEmpty" << std::endl;
+                if ((int)sync->getMessageId() == id && sync->getState() == OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ)
+                {
+                    std::cout << "ExpectCallbackSyncOnReadFromConsumer" << std::endl;
+                    responseCon.notify_all();
+                }
+            });
+
+     OIC::Service::NSMessage * msg =  OIC::Service::NSProviderService::getInstance()->CreateMessage();
+    id = (int)msg->getMessageId();
+    msg->setTitle(std::string("Title"));
+    msg->setContentText(std::string("ContentText"));
+    msg->setSourceName(std::string("OCF"));
+
+    g_consumerSimul.syncToProvider(type, id, msg->getProviderId());
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, std::chrono::milliseconds(5000));
+}
+
+TEST_F(NotificationProviderServiceTest, CancelObserves)
+{
+    bool ret = g_consumerSimul.cancelObserves();
+
+    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    responseCon.wait_for(lock, std::chrono::milliseconds(5000));
+
+    EXPECT_EQ(ret, true);
+}
diff --git a/service/notification/cpp-wrapper/unittest/SConscript b/service/notification/cpp-wrapper/unittest/SConscript
new file mode 100644 (file)
index 0000000..0ff9943
--- /dev/null
@@ -0,0 +1,99 @@
+#******************************************************************
+#
+# 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# Notification Unit Test build script
+##
+
+Import('env')
+
+if env.get('RELEASE'):
+       env.AppendUnique(CCFLAGS = ['-Os'])
+       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+       env.AppendUnique(CCFLAGS = ['-g'])
+
+if env.get('LOGGING'):
+       env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+######################################################################
+#unit test setting
+######################################################################
+src_dir = lib_env.get('SRC_DIR')
+gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0'
+
+notification_wrapper_test_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+
+######################################################################
+# Build flags
+######################################################################
+GTest = File(gtest_dir + '/lib/.libs/libgtest.a')
+GTest_Main = File(gtest_dir + '/lib/.libs/libgtest_main.a')
+
+notification_wrapper_test_env.AppendUnique(LIBPATH = [lib_env.get('BUILD_DIR')])
+notification_wrapper_test_env.AppendUnique(LIBS = [
+    'connectivity_abstraction', 'oc', 'octbstack', 'oc_logger', 'coap', 'notification_provider', 'notification_consumer' ,
+    GTest_Main, GTest])
+
+if target_os not in ['windows', 'winrt']:
+    notification_wrapper_test_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+
+notification_wrapper_test_env.AppendUnique(LINKFLAGS = ['-Wl,--no-as-needed'])
+
+notification_wrapper_test_env.AppendUnique(CXXFLAGS = ['-pthread'])
+notification_wrapper_test_env.AppendUnique(LIBS = ['pthread'])
+
+notification_wrapper_test_env.PrependUnique(CPPPATH = [ src_dir + '/extlibs/hippomocks-master', gtest_dir + '/include'])
+notification_wrapper_test_env.AppendUnique(CPPPATH = ['../provider/inc'])
+notification_wrapper_test_env.AppendUnique(CPPPATH = ['../consumer/inc'])
+notification_wrapper_test_env.AppendUnique(CPPPATH = ['../common'])
+notification_wrapper_test_env.AppendUnique(CPPPATH = ['../../include'])
+notification_wrapper_test_env.AppendUnique(CPPPATH = ['../../src/provider'])
+notification_wrapper_test_env.AppendUnique(CPPPATH = ['../../src/consumer'])
+
+######################################################################
+# Build Test
+######################################################################
+
+notification_consumer_wrapper_test_env = notification_wrapper_test_env.Clone()
+notification_consumer_wrapper_test_env.AppendUnique(LIBS = ['notification_consumer_wrapper'])
+
+notification_provider_wrapper_test_env = notification_wrapper_test_env.Clone()
+notification_provider_wrapper_test_env.AppendUnique(LIBS = ['notification_provider_wrapper'])
+
+notification_consumer_wrapper_test_src = env.Glob('./NSConsumerServiceTest.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_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')
+
+if env.get('TEST') == '1':
+    if target_os == 'linux':
+            from tools.scons.RunTest import *
+            run_test(notification_consumer_wrapper_test_env, '', 'service/notification/cpp-wrapper/unittest/notification_consumer_wrapper_test')
+            run_test(notification_provider_wrapper_test_env, '', 'service/notification/cpp-wrapper/unittest/notification_provider_wrapper_test')
\ No newline at end of file