Added SVACE Fixes for C++ wrapper Unit TCs
authorabitha.s <abitha.s@samsung.com>
Thu, 13 Oct 2016 11:02:01 +0000 (16:32 +0530)
committerUze Choi <uzchoi@samsung.com>
Fri, 14 Oct 2016 01:16:17 +0000 (01:16 +0000)
Change-Id: I09224a2bcd6e38c0d8cbb80caf5a0009161113d2
Signed-off-by: abitha.s <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13231
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit 82f4898421586624bb7e0576ad48948e05032fff)
Reviewed-on: https://gerrit.iotivity.org/gerrit/13239

service/notification/cpp-wrapper/provider/inc/NSConsumer.h
service/notification/cpp-wrapper/unittest/NSConsumerServiceSimulator.h [changed mode: 0644->0755]
service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp [changed mode: 0644->0755]
service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp [changed mode: 0644->0755]

index 17ef502..203ab9e 100755 (executable)
@@ -55,7 +55,9 @@ namespace OIC
                       * @param consumerId -consumerId of the Notification service Consumer.\r
                       */\r
                 NSConsumer(const std::string &consumerId)\r
-                    : m_consumerId(consumerId) {}\r
+                    : m_consumerId(consumerId)\r
+                {\r
+                }\r
 \r
                 /**\r
                       * Constructor of NSConsumer.\r
old mode 100644 (file)
new mode 100755 (executable)
index 64bdac9..4d3f51d
@@ -40,7 +40,9 @@ private:
 public:
     NSConsumerSimulator()
     : m_messageFunc(), m_syncFunc(),
-      m_syncResource() { };
+      m_syncResource()
+    {
+    }
     ~NSConsumerSimulator() = default;
 
     NSConsumerSimulator(const NSConsumerSimulator &) = delete;
@@ -74,9 +76,11 @@ public:
 
     bool cancelObserves()
     {
-        if(!msgResourceCancelObserve(OC::QualityOfService::HighQos) &&
-                !syncResourceCancelObserve(OC::QualityOfService::HighQos))
+        if((msgResourceCancelObserve(OC::QualityOfService::HighQos) == OC_STACK_OK) &&
+                (syncResourceCancelObserve(OC::QualityOfService::HighQos) == OC_STACK_OK))
+        {
             return true;
+        }
         return false;
     }
 
old mode 100644 (file)
new mode 100755 (executable)
index 3f1deaf..56b500a
@@ -242,7 +242,9 @@ TEST_F(NotificationServiceConsumerTest, ExpectSubscribeSuccess)
                              (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);
@@ -283,7 +285,9 @@ TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithAccepterisProvider)
                                  (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();
     });
@@ -518,8 +522,8 @@ TEST_F(NotificationServiceConsumerTest, ExpectEQTopicList)
         {
             isSame = false; break;
         }
-            it1++;it2++;
-     }
+        it1++;it2++;
+    }
 
 
     EXPECT_EQ(true, isSame);
old mode 100644 (file)
new mode 100755 (executable)
index a9acd13..e1b9f02
@@ -52,7 +52,9 @@ class TestWithMock: public testing::Test
         MockRepository mocks;
 
     protected:
-        virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test())) {}
+        virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
+        {
+        }
 
         virtual void TearDown()
         {
@@ -203,7 +205,7 @@ TEST_F(NotificationProviderServiceTest,
 TEST_F(NotificationProviderServiceTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
 {
     bool expectTrue = true;
-    int msgID;
+    int msgID = 0;
 
     mocks.OnCallFunc(MessageCallbackFromConsumerEmpty).Do(
         [& expectTrue, &msgID](const int & id, const std::string &, const std::string &,
@@ -239,7 +241,7 @@ TEST_F(NotificationProviderServiceTest, NeverCallNotifyOnConsumerByAcceptIsFalse
 
 TEST_F(NotificationProviderServiceTest, ExpectCallNotifyOnConsumerByAcceptIsTrue)
 {
-    int msgID;
+    int msgID = 0;
 
     mocks.ExpectCallFunc(MessageCallbackFromConsumerEmpty).Do(
         [&msgID](const int & id, const std::string &, const std::string &, const std::string &)
@@ -266,7 +268,7 @@ TEST_F(NotificationProviderServiceTest, ExpectCallNotifyOnConsumerByAcceptIsTrue
 
 TEST_F(NotificationProviderServiceTest, ExpectCallbackSyncOnReadToConsumer)
 {
-    int id;
+    int id = 0;
 
     mocks.ExpectCallFunc(SyncCallbackFromConsumerEmpty).Do(
         [& id](int & type, int & syncId)
@@ -295,7 +297,7 @@ TEST_F(NotificationProviderServiceTest, ExpectCallbackSyncOnReadToConsumer)
 TEST_F(NotificationProviderServiceTest, ExpectCallbackSyncOnReadFromConsumer)
 {
     int type = (int)OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
-    int id;
+    int id = 0;
     mocks.ExpectCallFunc(MessageSynchronizedCallbackEmpty).Do(
         [& id](OIC::Service::NSSyncInfo * sync)
     {
@@ -353,6 +355,10 @@ TEST_F(NotificationProviderServiceTest, ExpectEqualAddedTopicsAndRegisteredTopic
 
     OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
     OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
+    if(topicList != nullptr)
+    {
+        delete topicList;
+    }
     responseCon.wait_for(lock, g_waitForResponse);
 }
 
@@ -386,6 +392,10 @@ TEST_F(NotificationProviderServiceTest, ExpectEqualUnregisteredTopicsAndRegister
     EXPECT_EQ(isSame, true);
 
     OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
+    if(topicList != nullptr)
+    {
+        delete topicList;
+    }
     responseCon.wait_for(lock, g_waitForResponse);
 }
 
@@ -411,7 +421,7 @@ TEST_F(NotificationProviderServiceTest, ExpectEqualSetConsumerTopicsAndGetConsum
     else
     {
         std::string compString[10];
-        int i = 0, state[10];
+        int i = 0, state[10] = {0};
         for (auto itr : topicList->getTopicsList())
         {
             compString[i] = itr->getTopicName();
@@ -430,6 +440,10 @@ TEST_F(NotificationProviderServiceTest, ExpectEqualSetConsumerTopicsAndGetConsum
 
     OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
     OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
+    if(topicList != nullptr)
+    {
+        delete topicList;
+    }
     responseCon.wait_for(lock, g_waitForResponse);
 }
 
@@ -457,7 +471,7 @@ TEST_F(NotificationProviderServiceTest, ExpectEqualUnSetConsumerTopicsAndGetCons
     else
     {
         std::string compString[10];
-        int i = 0, state[10];
+        int i = 0, state[10] = {0};
         for (auto itr : topicList->getTopicsList())
         {
             compString[i] = itr->getTopicName();
@@ -476,6 +490,11 @@ TEST_F(NotificationProviderServiceTest, ExpectEqualUnSetConsumerTopicsAndGetCons
 
     OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
     OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
+    
+    if(topicList != nullptr)
+    {
+        delete topicList;
+    }
     responseCon.wait_for(lock, g_waitForResponse);
 }