Updated cpp wrapper UnitTest
authornikhil.a <nikhil.a7@samsung.com>
Thu, 8 Sep 2016 10:58:18 +0000 (16:28 +0530)
committerUze Choi <uzchoi@samsung.com>
Fri, 9 Sep 2016 02:24:02 +0000 (02:24 +0000)
1) Updated code according to latest API names.
2) Added new test cases required for checking topic resource apis

Change-Id: Ib68d1a8dfe1aea2bc07d50def87cc366d4f60a84
Signed-off-by: nikhil.a <nikhil.a7@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11503
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
service/notification/cpp-wrapper/SConscript
service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp
service/notification/cpp-wrapper/unittest/NSProviderServiceSimulator.h
service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp
service/notification/cpp-wrapper/unittest/SConscript

index 98c2c3d..e3b4d90 100755 (executable)
@@ -31,5 +31,5 @@ SConscript('consumer/SConscript')
 SConscript('examples/linux/SConscript')
 
 # Go to build Unit test
-#if target_os == 'linux':
-#    SConscript('unittest/SConscript')
+if target_os == 'linux':
+    SConscript('unittest/SConscript')
index 686e7df..87cb5b2 100644 (file)
 namespace
 {
     NSProviderSimulator g_providerSimul;
-     OIC::Service::NSProvider * g_provider;
+    OIC::Service::NSProvider *g_provider;
 
     std::atomic_bool g_isStartedStack(false);
 
-    std::chrono::milliseconds g_waitForResponse(2000);
+    std::chrono::milliseconds g_waitForResponse(1000);
 
     std::condition_variable responseCon;
     std::mutex mutexForCondition;
@@ -58,137 +58,128 @@ namespace
 
 class TestWithMock: public testing::Test
 {
-public:
-    MockRepository mocks;
+    public:
+        MockRepository mocks;
 
-protected:
-    virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
-    {
-
-    }
-
-    virtual void TearDown()
-    {
-        try
+    protected:
+        virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
         {
-            mocks.VerifyAll();
+
         }
-        catch (...)
+
+        virtual void TearDown()
         {
-            mocks.reset();
-            throw;
+            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;
-    }
+    public:
+        NotificationServiceConsumerTest() = default;
+        ~NotificationServiceConsumerTest() = default;
 
-    static void NotificationReceivedCallbackEmpty( OIC::Service::NSMessage *)
-    {
-        std::cout << __func__ << std::endl;
-    }
+        static void ProviderDiscoveredCallbackEmpty( OIC::Service::NSProvider *)
+        {
+            std::cout << __func__ << std::endl;
+        }
 
-    static void SyncCallbackEmpty(OIC::Service::NSSyncInfo *)
-    {
-        std::cout << __func__ << std::endl;
-    }
+        static void NotificationReceivedCallbackEmpty( OIC::Service::NSMessage *)
+        {
+            std::cout << __func__ << std::endl;
+        }
 
-    static void FoundResourceEmpty(std::shared_ptr< OC::OCResource >)
-    {
-        std::cout << __func__ << std::endl;
-    }
+        static void SyncCallbackEmpty(OIC::Service::NSSyncInfo *)
+        {
+            std::cout << __func__ << std::endl;
+        }
 
-    static void ProviderChangedCallbackEmpty( OIC::Service::NSProvider * , OIC::Service::NSResponse )
-    {
-        std::cout << __func__ << std::endl;
-    }
+        static void FoundResourceEmpty(std::shared_ptr< OC::OCResource >)
+        {
+            std::cout << __func__ << std::endl;
+        }
 
-protected:
+        static void ProviderChangedCallbackEmpty( OIC::Service::NSProviderState )
+        {
+            std::cout << __func__ << std::endl;
+        }
 
-    void SetUp()
-    {
-        TestWithMock::SetUp();
+    protected:
 
-        if (g_isStartedStack == false)
+        void SetUp()
         {
-            OC::PlatformConfig cfg
-            {
-                OC::ServiceType::InProc,
-                OC::ModeType::Both,
-                "0.0.0.0",
-                0,
-                OC::QualityOfService::LowQos
-            };
-            OC::OCPlatform::Configure(cfg);
+            TestWithMock::SetUp();
 
-            try
+            if (g_isStartedStack == false)
             {
-                OC::OCPlatform::stopPresence();
-            }
-            catch (...)
-            {
-
+                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;
             }
 
-            g_isStartedStack = true;
         }
 
-    }
-
-    void TearDown()
-    {
-        TestWithMock::TearDown();
-    }
+        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);
+    OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallbackEmpty);
 }
 
 TEST_F(NotificationServiceConsumerTest, StopConsumerPositive)
 {
-    OIC::Service::NSConsumerService::getInstance()->Stop();
+    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);
+        [this]( OIC::Service::NSProvider * provider)
+    {
+        std::cout << "Call Discovered" << std::endl;
+        std::cout << provider->getProviderId() << std::endl;
+        responseCon.notify_all();
+    });
+
+    OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallbackEmpty);
 
     g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_CONSUMER);
     g_providerSimul.createNotificationResource();
 
-    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    std::unique_lock< std::mutex > lock { mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 
-     OIC::Service::NSConsumerService::getInstance()->Stop();
+    OIC::Service::NSConsumerService::getInstance()->stop();
     g_providerSimul.deleteNotificationResource();
 }
 
@@ -197,26 +188,22 @@ TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithNonAccepterWhenStart
     g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_CONSUMER);
     g_providerSimul.createNotificationResource();
     {
-        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        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 };
+        [this]( OIC::Service::NSProvider * provider)
+    {
+        std::cout << "Call Discovered" << std::endl;
+        g_provider = provider;
+        std::cout << g_provider->getProviderId() << std::endl;
+        responseCon.notify_all();
+    });
+
+    OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallbackEmpty);
+
+    std::unique_lock< std::mutex > lock { mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 
 }
@@ -224,37 +211,41 @@ TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithNonAccepterWhenStart
 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);
+    mocks.OnCallFunc(ProviderDiscoveredCallbackEmpty).Do(
+        [this]( OIC::Service::NSProvider * provider)
+    {
+        std::cout << "Call Discovered" << std::endl;
+        g_provider = provider;
+        std::cout << g_provider->getProviderId() << std::endl;
+        responseCon.notify_all();
+    });
+
+    OIC::Service::NSConsumerService::getInstance()->rescanProvider();
 
-//     OIC::Service::NSConsumerService::getInstance()->Stop();
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
 }
 
 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 };
+    OIC::Service::NSProviderState revState = OIC::Service::NSProviderState::DENY;
+    mocks.OnCallFunc(ProviderChangedCallbackEmpty).Do(
+        [this, & revState](OIC::Service::NSProviderState state)
+    {
+        std::cout << "Income Accepted subscription : " << std::endl;
+        revState = state;
+        responseCon.notify_all();
+    });
+
+    g_provider->setListener( (OIC::Service::NSProvider::ProviderStateCallback)
+                             ProviderChangedCallbackEmpty,
+                             (OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallbackEmpty,
+                             (OIC::Service::NSProvider::SyncInfoReceivedCallback)SyncCallbackEmpty);
+    if (!g_provider->isSubscribed())
+        g_provider->subscribe();
+    std::unique_lock< std::mutex > lock { mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
+    EXPECT_EQ(OIC::Service::NSProviderState::ALLOW, revState);
 }
 
 TEST_F(NotificationServiceConsumerTest, ExpectReceiveNotification)
@@ -264,17 +255,43 @@ TEST_F(NotificationServiceConsumerTest, ExpectReceiveNotification)
     std::string msg = "msg";
 
     mocks.ExpectCallFunc(NotificationReceivedCallbackEmpty).Do(
-            []( OIC::Service::NSMessage * message)
-            {
-                std::cout << "Income Notification : " << message->getMessageId() << std::endl;
-            });
+        [this]( OIC::Service::NSMessage * message)
+    {
+        std::cout << "Income Notification : " << message->getMessageId() << std::endl;
+        responseCon.notify_all();
+    });
 
     g_providerSimul.notifyMessage(id, title, msg);
 
-    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    std::unique_lock< std::mutex > lock { mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 
-     OIC::Service::NSConsumerService::getInstance()->Stop();
+    OIC::Service::NSConsumerService::getInstance()->stop();
+}
+
+TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithAccepterisProvider)
+{
+    g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_PROVIDER);
+
+    mocks.ExpectCallFunc(ProviderDiscoveredCallbackEmpty).Do(
+        [this]( OIC::Service::NSProvider * provider)
+    {
+        std::cout << "Call Discovered" << std::endl;
+        g_provider = provider;
+        g_provider->setListener( (OIC::Service::NSProvider::ProviderStateCallback)
+                                 ProviderChangedCallbackEmpty,
+                                 (OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallbackEmpty,
+                                 (OIC::Service::NSProvider::SyncInfoReceivedCallback)SyncCallbackEmpty);
+        if (!g_provider->isSubscribed())
+            g_provider->subscribe();
+        std::cout << g_provider->getProviderId() << std::endl;
+        responseCon.notify_all();
+    });
+
+
+    OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallbackEmpty);
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
 }
 
 TEST_F(NotificationServiceConsumerTest, ExpectReceiveNotificationWithAccepterisProvider)
@@ -282,31 +299,22 @@ TEST_F(NotificationServiceConsumerTest, ExpectReceiveNotificationWithAccepterisP
     uint64_t id = 11;
     std::string title = "title";
     std::string msg = "msg";
+    uint64_t revId = 1;
 
-    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);
+    mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
+        [this, & id, & revId](OIC::Service::NSMessage * message)
     {
-        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;
-            });
+        std::cout << "Income Notification : " << message->getMessageId() << std::endl;
+        revId =  message->getMessageId();
+        responseCon.notify_all();
+    });
 
     g_providerSimul.notifyMessage(id, title, msg);
 
-    std::unique_lock< std::mutex > lock{ mutexForCondition };
+    std::unique_lock< std::mutex > lock { mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 
-//    g_providerSimul.deleteNotificationResource();
-//     OIC::Service::NSConsumerService::getInstance()->Stop();
+    EXPECT_EQ(id, revId);
 }
 
 TEST_F(NotificationServiceConsumerTest, ExpectCallbackReadCheckWhenProviderNotifySync)
@@ -314,39 +322,35 @@ TEST_F(NotificationServiceConsumerTest, ExpectCallbackReadCheckWhenProviderNotif
     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();
+        [this]( OIC::Service::NSMessage * message)
+    {
+        std::cout << "Income Notification : " << message->getMessageId() << std::endl;
+    });
 
-            });
+    mocks.OnCallFunc(SyncCallbackEmpty).Do(
+        [& type, this](OIC::Service::NSSyncInfo * sync)
+    {
+        std::cout << "Income SyncInfo : " << sync->getMessageId()
+                  << ", State : " << (int) sync->getState() << std::endl;
+        type = sync->getState();
+        responseCon.notify_all();
+    });
 
     g_providerSimul.notifyMessage(id, title, msg);
     {
-        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        std::unique_lock< std::mutex > lock { mutexForCondition };
         responseCon.wait_for(lock, g_waitForResponse);
     }
 
     g_providerSimul.sendRead(id);
     {
-        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        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);
 }
 
@@ -355,39 +359,35 @@ TEST_F(NotificationServiceConsumerTest, ExpectCallbackDismissCheckWhenProviderNo
     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();
+        [this]( OIC::Service::NSMessage * message)
+    {
+        std::cout << "Income Notification : " << message->getMessageId() << std::endl;
+    });
 
-            });
+    mocks.OnCallFunc(SyncCallbackEmpty).Do(
+        [& type, this](OIC::Service::NSSyncInfo * sync)
+    {
+        std::cout << "Income Notification : " << sync->getMessageId()
+                  << ", State : " << (int) sync->getState() << std::endl;
+        type = sync->getState();
+        responseCon.notify_all();
+    });
 
     g_providerSimul.notifyMessage(id, title, msg);
     {
-        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        std::unique_lock< std::mutex > lock { mutexForCondition };
         responseCon.wait_for(lock, g_waitForResponse);
     }
 
     g_providerSimul.sendDismiss(id);
     {
-        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        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);
 }
 
@@ -396,36 +396,33 @@ TEST_F(NotificationServiceConsumerTest, ExpectCallbackReadCheckWhenConsumerPostS
     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();
+        [this]( 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.OnCallFunc(SyncCallbackEmpty).Do(
+        [& type, this](OIC::Service::NSSyncInfo * sync)
+    {
+        std::cout << "Income Notification : " << sync->getMessageId()
+                  << ", State : " << (int) sync->getState() << std::endl;
+        type = sync->getState();
+        responseCon.notify_all();
+    });
 
     g_providerSimul.notifyMessage(id, title, msg);
     {
-        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        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);
 }
 
@@ -434,43 +431,64 @@ TEST_F(NotificationServiceConsumerTest, ExpectCallbackDismissCheckWhenConsumerPo
     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();
+        [this]( 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.OnCallFunc(SyncCallbackEmpty).Do(
+        [& type, this](OIC::Service::NSSyncInfo * sync)
+    {
+        std::cout << "Income Notification : " << sync->getMessageId()
+                  << ", State : " << (int) sync->getState() << std::endl;
+        type = sync->getState();
+        responseCon.notify_all();
+    });
 
     g_providerSimul.notifyMessage(id, title, msg);
     {
-        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        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)
+TEST_F(NotificationServiceConsumerTest, ExpectCallbackDeletedProvider)
 {
-    g_provider->unSubscribe();
-    std::unique_lock< std::mutex > lock{ mutexForCondition };
-    responseCon.wait_for(lock, g_waitForResponse);
+    OIC::Service::NSProviderState type = OIC::Service::NSProviderState::ALLOW;
+    mocks.OnCallFunc(ProviderChangedCallbackEmpty).Do(
+        [& type, this](OIC::Service::NSProviderState state)
+    {
+        std::cout << "Income Changed Callback : " << std::endl;
+        type = state;
+        responseCon.notify_all();
+    });
 
     g_providerSimul.deleteNotificationResource();
-     OIC::Service::NSConsumerService::getInstance()->Stop();
 
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+    EXPECT_EQ(type, OIC::Service::NSProviderState::STOPPED);
+    OIC::Service::NSConsumerService::getInstance()->stop();
 }
+
+//TO add when unsubscibe API is added back
+//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();
+//
+//}
index 1371e89..ebed3fa 100644 (file)
@@ -98,7 +98,7 @@ private:
                     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("ACCEPTER", (bool) m_accepter);
                     rep.setValue("MESSAGE_URI", msgUri);
                     rep.setValue("SYNC_URI", syncUri);
                     rep.setValue("PROVIDER_ID", providerId);
index 5e9fd0e..b5e76af 100644 (file)
@@ -37,99 +37,100 @@ namespace
 {
     std::atomic_bool g_isStartedStack(false);
 
-    std::chrono::milliseconds g_waitForResponse(3000);
+    std::chrono::milliseconds g_waitForResponse(500);
 
     std::condition_variable responseCon;
     std::mutex mutexForCondition;
 
     NSConsumerSimulator g_consumerSimul;
-     OIC::Service::NSConsumer * g_consumer;
+    OIC::Service::NSConsumer *g_consumer;
 }
 
 class TestWithMock: public testing::Test
 {
-public:
-    MockRepository mocks;
+    public:
+        MockRepository mocks;
 
-protected:
-    virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test())) {}
+    protected:
+        virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test())) {}
 
-    virtual void TearDown() {
-        try
+        virtual void TearDown()
         {
-            mocks.VerifyAll();
-        }
-        catch (...)
-        {
-            mocks.reset();
-            throw;
+            try
+            {
+                mocks.VerifyAll();
+            }
+            catch (...)
+            {
+                mocks.reset();
+                throw;
+            }
         }
-    }
 };
 
 class NotificationProviderServiceTest : public TestWithMock
 {
-public:
-    NotificationProviderServiceTest() = default;
-    ~NotificationProviderServiceTest() = default;
+    public:
+        NotificationProviderServiceTest() = default;
+        ~NotificationProviderServiceTest() = default;
 
-    static void ConsumerSubscribedCallbackEmpty(OIC::Service::NSConsumer *)
-    {
-        std::cout << __func__ << std::endl;
-    }
+        static void ConsumerSubscribedCallbackEmpty(OIC::Service::NSConsumer *)
+        {
+            std::cout << __func__ << std::endl;
+        }
 
-    static void MessageSynchronizedCallbackEmpty(OIC::Service::NSSyncInfo *)
-    {
-        std::cout << __func__ << std::endl;
-    }
+        static void MessageSynchronizedCallbackEmpty(OIC::Service::NSSyncInfo *)
+        {
+            std::cout << __func__ << std::endl;
+        }
 
-    static void MessageCallbackFromConsumerEmpty(
+        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;
-    }
+        {
+            std::cout << __func__ << std::endl;
+        }
 
-protected:
+        static void SyncCallbackFromConsumerEmpty(int, int)
+        {
+            std::cout << __func__ << std::endl;
+        }
 
-    void SetUp()
-    {
-        TestWithMock::SetUp();
+    protected:
 
-        if (g_isStartedStack == false)
+        void SetUp()
         {
-            OC::PlatformConfig cfg
-            {
-                OC::ServiceType::InProc,
-                OC::ModeType::Both,
-                "0.0.0.0",
-                0,
-                OC::QualityOfService::HighQos
-            };
-            OC::OCPlatform::Configure(cfg);
+            TestWithMock::SetUp();
 
-            try
-            {
-                OC::OCPlatform::stopPresence();
-            }
-            catch (...)
+            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;
             }
 
-            g_isStartedStack = true;
         }
 
-    }
-
-    void TearDown()
-    {
-        TestWithMock::TearDown();
-    }
+        void TearDown()
+        {
+            TestWithMock::TearDown();
+        }
 
 };
 
@@ -138,22 +139,16 @@ 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);
+    config.subControllability = true;
 
-    std::unique_lock< std::mutex > lock{ mutexForCondition };
-    responseCon.wait_for(lock, g_waitForResponse);
+    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();
-
-    std::unique_lock< std::mutex > lock{ mutexForCondition };
-    responseCon.wait_for(lock, g_waitForResponse);
+    OIC::Service::NSResult ret =  OIC::Service::NSProviderService::getInstance()->stop();
 
     EXPECT_EQ(ret,  OIC::Service::NSResult::OK);
 }
@@ -163,47 +158,46 @@ TEST_F(NotificationProviderServiceTest, StartProviderPositiveWithPolicyFalse)
     OIC::Service::NSProviderService::ProviderConfig  config;
     config.m_subscribeRequestCb = ConsumerSubscribedCallbackEmpty;
     config.m_syncInfoCb = MessageSynchronizedCallbackEmpty;
-    config.policy = false;
+    config.subControllability = false;
 
-     OIC::Service::NSResult ret =  OIC::Service::NSProviderService::getInstance()->Start(config);
+    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);
+    OIC::Service::NSProviderService::getInstance()->stop();
 }
 
-TEST_F(NotificationProviderServiceTest, ExpectCallbackWhenReceiveSubscribeRequestWithAccepterProvider)
+TEST_F(NotificationProviderServiceTest,
+       ExpectCallbackWhenReceiveSubscribeRequestWithAccepterProvider)
 {
+    g_consumer = NULL;
     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::NSConsumer * consumer)
+    {
+        std::cout << "ConsumerSubscribedCallbackEmpty" << std::endl;
+        g_consumer = consumer;
+        responseCon.notify_all();
+    });
 
     OIC::Service::NSProviderService::ProviderConfig  config;
     config.m_subscribeRequestCb = ConsumerSubscribedCallbackEmpty;
     config.m_syncInfoCb = MessageSynchronizedCallbackEmpty;
-    config.policy = true;
+    config.subControllability = true;
 
-     OIC::Service::NSProviderService::getInstance()->Start(config);
+    OIC::Service::NSProviderService::getInstance()->start(config);
 
     {
-        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        std::unique_lock< std::mutex > lock { mutexForCondition };
         responseCon.wait_for(lock, g_waitForResponse);
     }
 
     g_consumerSimul.setCallback(MessageCallbackFromConsumerEmpty,
-            SyncCallbackFromConsumerEmpty);
+                                SyncCallbackFromConsumerEmpty);
     g_consumerSimul.findProvider();
 
-    std::unique_lock< std::mutex > lock{ mutexForCondition };
-    responseCon.wait_for(lock, std::chrono::milliseconds(1000));
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+    EXPECT_NE((void*)g_consumer, (void*)NULL);
 }
 
 TEST_F(NotificationProviderServiceTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
@@ -212,31 +206,33 @@ TEST_F(NotificationProviderServiceTest, NeverCallNotifyOnConsumerByAcceptIsFalse
     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;
-                }
-            });
+        [& 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;
+        }
+        responseCon.notify_all();
+    });
 
-    g_consumer->acceptSubscription(g_consumer, false);
+    g_consumer->acceptSubscription(false);
 
-     OIC::Service::NSMessage * msg =  OIC::Service::NSProviderService::getInstance()->CreateMessage();
+    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);
+    OIC::Service::NSProviderService::getInstance()->sendMessage(msg);
     {
-        std::unique_lock< std::mutex > lock{ mutexForCondition };
+        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));
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
 
     EXPECT_EQ(expectTrue, true);
 }
@@ -246,30 +242,27 @@ 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();
-                }
-            });
+        [&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);
+    g_consumer->acceptSubscription(true);
 
-     OIC::Service::NSMessage * msg =  OIC::Service::NSProviderService::getInstance()->CreateMessage();
+    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 };
+    OIC::Service::NSProviderService::getInstance()->registerTopic("OCF_TOPIC1");
+    g_consumer->setTopic("OCF_TOPIC1");
+    OIC::Service::NSProviderService::getInstance()->sendMessage(msg);
+    OIC::Service::NSProviderService::getInstance()->unregisterTopic("OCF_TOPIC1");
+    std::unique_lock< std::mutex > lock { mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 }
 
@@ -278,26 +271,27 @@ TEST_F(NotificationProviderServiceTest, ExpectCallbackSyncOnReadToConsumer)
     int id;
 
     mocks.ExpectCallFunc(SyncCallbackFromConsumerEmpty).Do(
-            [& id](int & type, int &syncId)
-            {
+        [& 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();
-                }
-            });
+        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();
+    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));
+    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, g_waitForResponse);
 }
 
 TEST_F(NotificationProviderServiceTest, ExpectCallbackSyncOnReadFromConsumer)
@@ -305,33 +299,194 @@ 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();
-                }
-            });
+        [& 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();
+    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));
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait(lock);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectEqualAddedTopicsAndRegisteredTopics)
+{
+    std::string str1("TEST1");
+    std::string str2("TEST2");
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str2);
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+    bool isSame = false;
+    OIC::Service::NSTopicsList *topicList =
+        OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList();
+    if (!topicList)
+    {
+        printf("topic is NULL\n");
+        isSame = false;
+    }
+    else
+    {
+        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);
+
+    OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
+    OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
+    responseCon.wait_for(lock, g_waitForResponse);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectEqualUnregisteredTopicsAndRegisteredTopics)
+{
+    std::string str1("TEST1");
+    std::string str2("TEST2");
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str2);
+    OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+    bool isSame = false;
+    OIC::Service::NSTopicsList *topicList =
+        OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList();
+    if (!topicList)
+    {
+        printf("topic is NULL\n");
+        isSame = false;
+    }
+    else
+    {
+        std::list<OIC::Service::NSTopic *>::iterator it = topicList->getTopicsList().begin();
+        std::string compStr = (*it)->getTopicName() ;
+        std::cout << compStr << std::endl;
+        if (str1.compare(compStr) == 0 )
+        {
+            isSame = true;
+        }
+    }
+    EXPECT_EQ(isSame, true);
+
+    OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
+    responseCon.wait_for(lock, g_waitForResponse);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectEqualSetConsumerTopicsAndGetConsumerTopics)
+{
+    std::string str1("TEST1");
+    std::string str2("TEST2");
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str2);
+    g_consumer->setTopic(str1);
+
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+    bool isSame = false;
+    OIC::Service::NSTopicsList *topicList =  g_consumer->getConsumerTopicList();
+
+    if (!topicList)
+    {
+        printf("topic is NULL\n");
+        isSame = false;
+    }
+    else
+    {
+        std::string compString[10];
+        int i = 0, state[10];
+        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);
+    responseCon.wait_for(lock, g_waitForResponse);
+}
+
+TEST_F(NotificationProviderServiceTest, ExpectEqualUnSetConsumerTopicsAndGetConsumerTopics)
+{
+    std::string str1("TEST1");
+    std::string str2("TEST2");
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
+    OIC::Service::NSProviderService::getInstance()->registerTopic(str2);
+    g_consumer->setTopic(str1);
+    g_consumer->setTopic(str2);
+    g_consumer->unsetTopic(str1);
+
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
+
+    bool isSame = false;
+    OIC::Service::NSTopicsList *topicList =  g_consumer->getConsumerTopicList();
+
+    if (!topicList)
+    {
+        printf("topic is NULL\n");
+        isSame = false;
+    }
+    else
+    {
+        std::string compString[10];
+        int i = 0, state[10];
+        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] == 0 &&  state[1] == 1)
+        {
+            isSame = true;
+        }
+    }
+
+    EXPECT_EQ(isSame, true);
+
+    OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
+    OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
+    responseCon.wait_for(lock, g_waitForResponse);
 }
 
 TEST_F(NotificationProviderServiceTest, CancelObserves)
 {
     bool ret = g_consumerSimul.cancelObserves();
 
-    std::unique_lock< std::mutex > lock{ mutexForCondition };
-    responseCon.wait_for(lock, std::chrono::milliseconds(5000));
+    std::unique_lock< std::mutex > lock { mutexForCondition };
+    responseCon.wait_for(lock, g_waitForResponse);
 
     EXPECT_EQ(ret, true);
 }
index b9230db..90ef7f5 100644 (file)
@@ -53,7 +53,7 @@ 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' ,
+    'connectivity_abstraction', 'oc', 'octbstack', 'oc_logger', 'coap', 
     GTest_Main, GTest])
 
 if env.get('WITH_TCP') == True:
@@ -82,10 +82,10 @@ notification_wrapper_test_env.AppendUnique(CPPPATH = ['../../src/consumer'])
 ######################################################################
 
 notification_consumer_wrapper_test_env = notification_wrapper_test_env.Clone()
-notification_consumer_wrapper_test_env.AppendUnique(LIBS = ['notification_consumer_wrapper'])
+notification_consumer_wrapper_test_env.AppendUnique(LIBS = ['notification_consumer_wrapper','notification_consumer'])
 
 notification_provider_wrapper_test_env = notification_wrapper_test_env.Clone()
-notification_provider_wrapper_test_env.AppendUnique(LIBS = ['notification_provider_wrapper'])
+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 = notification_consumer_wrapper_test_env.Program('notification_consumer_wrapper_test', notification_consumer_wrapper_test_src)