From 53471a5ab2be641a3254e33e8dd0fe4930cbb111 Mon Sep 17 00:00:00 2001 From: "abitha.s" Date: Thu, 13 Oct 2016 16:32:01 +0530 Subject: [PATCH] Added SVACE Fixes for C++ wrapper Unit TCs Change-Id: I09224a2bcd6e38c0d8cbb80caf5a0009161113d2 Signed-off-by: abitha.s Reviewed-on: https://gerrit.iotivity.org/gerrit/13231 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi (cherry picked from commit 82f4898421586624bb7e0576ad48948e05032fff) Reviewed-on: https://gerrit.iotivity.org/gerrit/13239 --- .../cpp-wrapper/provider/inc/NSConsumer.h | 4 ++- .../unittest/NSConsumerServiceSimulator.h | 10 +++++-- .../cpp-wrapper/unittest/NSConsumerServiceTest.cpp | 8 ++++-- .../cpp-wrapper/unittest/NSProviderServiceTest.cpp | 33 +++++++++++++++++----- 4 files changed, 42 insertions(+), 13 deletions(-) mode change 100644 => 100755 service/notification/cpp-wrapper/unittest/NSConsumerServiceSimulator.h mode change 100644 => 100755 service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp mode change 100644 => 100755 service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp diff --git a/service/notification/cpp-wrapper/provider/inc/NSConsumer.h b/service/notification/cpp-wrapper/provider/inc/NSConsumer.h index 17ef502..203ab9e 100755 --- a/service/notification/cpp-wrapper/provider/inc/NSConsumer.h +++ b/service/notification/cpp-wrapper/provider/inc/NSConsumer.h @@ -55,7 +55,9 @@ namespace OIC * @param consumerId -consumerId of the Notification service Consumer. */ NSConsumer(const std::string &consumerId) - : m_consumerId(consumerId) {} + : m_consumerId(consumerId) + { + } /** * Constructor of NSConsumer. diff --git a/service/notification/cpp-wrapper/unittest/NSConsumerServiceSimulator.h b/service/notification/cpp-wrapper/unittest/NSConsumerServiceSimulator.h old mode 100644 new mode 100755 index 64bdac9..4d3f51d --- a/service/notification/cpp-wrapper/unittest/NSConsumerServiceSimulator.h +++ b/service/notification/cpp-wrapper/unittest/NSConsumerServiceSimulator.h @@ -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; } diff --git a/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp b/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp old mode 100644 new mode 100755 index 3f1deaf..56b500a --- a/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp +++ b/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp @@ -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); diff --git a/service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp b/service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp old mode 100644 new mode 100755 index a9acd13..e1b9f02 --- a/service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp +++ b/service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp @@ -52,7 +52,9 @@ class TestWithMock: public testing::Test MockRepository mocks; protected: - virtual ~TestWithMock() noexcept(noexcept(std::declval().~Test())) {} + virtual ~TestWithMock() noexcept(noexcept(std::declval().~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); } -- 2.7.4