Add unittest for negative case.
authorjaesick.shin <jaesick.shin@samsung.com>
Wed, 21 Sep 2016 06:38:21 +0000 (15:38 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 21 Sep 2016 11:06:20 +0000 (11:06 +0000)
Add unittest for negative case in provider side.
and remove printf, cout.

Change-Id: I6fd7119e4cade3da6d87e85f0c8e1957f3bf0ce4
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12025
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/unittest/NSConsumerSimulator.h
service/notification/unittest/NSProviderTest.cpp

index 1c87c07..d6e5d69 100644 (file)
@@ -61,7 +61,6 @@ public:
     {
         if (m_syncResource == nullptr)
         {
-            std::cout << "m_syncResource is null" << std::endl;
             return;
         }
 
@@ -91,15 +90,11 @@ public:
 
 private:
     static void onPost(const OC::HeaderOptions &/*headerOption*/,
-                const OC::OCRepresentation & /*rep*/ , const int eCode)
+                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(),
@@ -109,26 +104,15 @@ private:
         }
     }
     void onGet(const OC::HeaderOptions &/*headerOption*/,
-            const OC::OCRepresentation & rep , const int eCode,
+            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
@@ -166,18 +150,12 @@ private:
 
     }
     void onObserve(const OC::HeaderOptions &/*headerOption*/,
-            const OC::OCRepresentation &rep , const int &eCode, const int &,
+            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")),
@@ -193,20 +171,14 @@ private:
         }
         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")));
         }
     }
 
     void onTopicGet(const OC::HeaderOptions &/*headerOption*/,
-            const OC::OCRepresentation & rep , const int eCode,
-            std::shared_ptr<OC::OCResource> resource)
+            const OC::OCRepresentation & /*rep*/ , const int /*eCode*/,
+            std::shared_ptr<OC::OCResource> /*resource*/)
     {
-        //TO-DO using this function.
-        (void) rep;
-        (void) eCode;
-        (void) resource;
-        std::cout << "onTopicGet()" << std::endl;
     }
 
     OCStackResult msgResourceCancelObserve(OC::QualityOfService qos)
index 55505be..c868273 100755 (executable)
@@ -75,23 +75,19 @@ public:
 
     static void NSRequestedSubscribeCallbackEmpty(NSConsumer *)
     {
-        std::cout << __func__ << std::endl;
     }
 
     static void NSSyncCallbackEmpty(NSSyncInfo *)
     {
-        std::cout << __func__ << std::endl;
     }
 
     static void NSMessageCallbackFromConsumerEmpty(
             const int &, const std::string &, const std::string &, const std::string &)
     {
-        std::cout << __func__ << std::endl;
     }
 
     static void NSSyncCallbackFromConsumerEmpty(int, int)
     {
-        std::cout << __func__ << std::endl;
     }
 
 protected:
@@ -188,7 +184,6 @@ TEST_F(NotificationProviderTest, ExpectCallbackWhenReceiveSubscribeRequestWithAc
     mocks.OnCallFunc(NSRequestedSubscribeCallbackEmpty).Do(
             [](NSConsumer * consumer)
             {
-                std::cout << "NSRequestedSubscribeCallback" << std::endl;
                 g_consumerID = strdup(consumer->consumerId);
                 responseCon.notify_all();
             });
@@ -226,7 +221,6 @@ TEST_F(NotificationProviderTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
             {
                 if (id == msgID)
                 {
-                    std::cout << "This function never call" << std::endl;
                     expectTrue = false;
                 }
             });
@@ -260,10 +254,8 @@ TEST_F(NotificationProviderTest, ExpectCallNotifyOnConsumerByAcceptIsTrue)
     mocks.ExpectCallFunc(NSMessageCallbackFromConsumerEmpty).Do(
             [&msgID](const int &id, const std::string&, const std::string&, const std::string&)
             {
-                std::cout << "id : " << id << std::endl;
                 if (id == msgID)
                 {
-                    std::cout << "ExpectCallNotifyOnConsumerByAcceptIsTrue" << std::endl;
                     responseCon.notify_all();
                 }
             });
@@ -288,11 +280,8 @@ TEST_F(NotificationProviderTest, ExpectCallbackSyncOnReadToConsumer)
     mocks.ExpectCallFunc(NSSyncCallbackFromConsumerEmpty).Do(
             [& id](int & type, int &syncId)
             {
-        std::cout << "NSSyncCallbackEmpty" << std::endl;
-                if (syncId == id &&
-                        type == NS_SYNC_READ)
+                if (syncId == id && type == NS_SYNC_READ)
                 {
-                    std::cout << "ExpectCallbackSyncOnReadFromConsumer" << std::endl;
                     responseCon.notify_all();
                 }
             });
@@ -315,10 +304,8 @@ TEST_F(NotificationProviderTest, ExpectCallbackSyncOnReadFromConsumer)
     mocks.ExpectCallFunc(NSSyncCallbackEmpty).Do(
             [& id](NSSyncInfo * sync)
             {
-                std::cout << "NSSyncCallbackEmpty" << std::endl;
                 if ((int)sync->messageId == id && sync->state == NS_SYNC_READ)
                 {
-                    std::cout << "ExpectCallbackSyncOnReadFromConsumer" << std::endl;
                     responseCon.notify_all();
                 }
             });
@@ -351,7 +338,6 @@ TEST_F(NotificationProviderTest, ExpectEqualAddedTopicsAndRegisteredTopics)
 
     if(!topics)
     {
-        printf("topic is NULL\n");
         isSame = false;
     }
     else
@@ -360,9 +346,6 @@ TEST_F(NotificationProviderTest, ExpectEqualAddedTopicsAndRegisteredTopics)
         std::string compStr(iter->topicName);
         std::string compStr2(iter->next->topicName);
 
-        printf("str = %s, compStr = %s\n", str.c_str(), iter->topicName);
-        printf("str2 = %s, compStr2 = %s\n", str2.c_str(), iter->next->topicName);
-
         if(str.compare(compStr) == 0 && str2.compare(compStr2) == 0)
         {
             isSame = true;
@@ -393,7 +376,6 @@ TEST_F(NotificationProviderTest, ExpectEqualUnregisteredTopicsAndRegisteredTopic
 
     if(!topics)
     {
-        printf("topic is NULL\n");
         isSame = false;
     }
     else
@@ -401,8 +383,6 @@ TEST_F(NotificationProviderTest, ExpectEqualUnregisteredTopicsAndRegisteredTopic
         NSTopicLL * iter = topics;
         std::string compStr(iter->topicName);
 
-        printf("str = %s, compStr = %s\n", str.c_str(), iter->topicName);
-
         if(str.compare(compStr) == 0)
         {
             isSame = true;
@@ -432,7 +412,6 @@ TEST_F(NotificationProviderTest, ExpectEqualSetConsumerTopicsAndGetConsumerTopic
 
     if(!topics)
     {
-        printf("topic is NULL\n");
         isSame = false;
     }
     else
@@ -440,12 +419,6 @@ TEST_F(NotificationProviderTest, ExpectEqualSetConsumerTopicsAndGetConsumerTopic
         NSTopicLL * firstData = topics;
         NSTopicLL * secondData = firstData->next;
 
-        printf("str = %s, compStr = %s, state = %d\n", str.c_str(), firstData->topicName,
-                (int)firstData->state);
-
-        printf("str2 = %s, compStr = %s, state = %d\n", str2.c_str(), secondData->topicName,
-                (int)secondData->state);
-
         if(str.compare(firstData->topicName) == 0 && str2.compare(secondData->topicName) == 0
                 && ((int)firstData->state) == 1 && ((int)secondData->state) == 0)
         {
@@ -479,7 +452,6 @@ TEST_F(NotificationProviderTest, ExpectEqualUnSetConsumerTopicsAndGetConsumerTop
 
     if(!topics)
     {
-        printf("topic is NULL\n");
         isSame = false;
     }
     else
@@ -487,12 +459,6 @@ TEST_F(NotificationProviderTest, ExpectEqualUnSetConsumerTopicsAndGetConsumerTop
         NSTopicLL * firstData = topics;
         NSTopicLL * secondData = firstData->next;
 
-        printf("str = %s, compStr = %s, state = %d\n", str.c_str(), firstData->topicName,
-                (int)firstData->state);
-
-        printf("str2 = %s, compStr = %s, state = %d\n", str2.c_str(), secondData->topicName,
-                (int)secondData->state);
-
         if(str.compare(firstData->topicName) == 0 && str2.compare(secondData->topicName) == 0
                 && ((int)firstData->state) == 0 && ((int)secondData->state) == 1)
         {
@@ -508,6 +474,88 @@ TEST_F(NotificationProviderTest, ExpectEqualUnSetConsumerTopicsAndGetConsumerTop
     responseCon.wait_for(lock, std::chrono::milliseconds(500));
 }
 
+TEST_F(NotificationProviderTest, ExpectFailAcceptSubscription)
+{
+    NSResult result;
+    result = NS_SUCCESS;
+    result = NSAcceptSubscription(NULL, true);
+    result = NSAcceptSubscription("\0", true);
+
+    EXPECT_EQ(result, NS_FAIL);
+}
+
+TEST_F(NotificationProviderTest, ExpectFailSendMessage)
+{
+    NSResult result;
+    result = NS_SUCCESS;
+    result = NSSendMessage(NULL);
+
+    EXPECT_EQ(result, NS_FAIL);
+}
+
+TEST_F(NotificationProviderTest, ExpectFailRegisterTopic)
+{
+    NSResult result;
+    result = NS_SUCCESS;
+    result = NSProviderRegisterTopic(NULL);
+    result = NSProviderRegisterTopic("\0");
+
+    EXPECT_EQ(result, NS_FAIL);
+}
+
+TEST_F(NotificationProviderTest, ExpectFailUnregisterTopic)
+{
+    NSResult result;
+    result = NS_SUCCESS;
+    result = NSProviderUnregisterTopic(NULL);
+    result = NSProviderUnregisterTopic("\0");
+
+    EXPECT_EQ(result, NS_FAIL);
+}
+
+TEST_F(NotificationProviderTest, ExpectFailGetConsumerTopics)
+{
+    NSTopicLL topic;
+    NSTopicLL * topicLL = &topic;
+
+    topicLL = NSProviderGetConsumerTopics(NULL);
+    topicLL = NSProviderGetConsumerTopics("\0");
+
+    EXPECT_EQ(topicLL, (NSTopicLL *)NULL);
+}
+
+TEST_F(NotificationProviderTest, ExpectFailSetConsumerTopics)
+{
+    NSResult result;
+    result = NS_SUCCESS;
+    result = NSProviderSetConsumerTopic(NULL, NULL);
+    result = NSProviderSetConsumerTopic(NULL, "\0");
+    result = NSProviderSetConsumerTopic("\0", NULL);
+    result = NSProviderSetConsumerTopic("\0", "\0");
+    result = NSProviderSetConsumerTopic("abc", NULL);
+    result = NSProviderSetConsumerTopic(NULL, "abc");
+    result = NSProviderSetConsumerTopic("abc", "\0");
+    result = NSProviderSetConsumerTopic("\0", "abc");
+
+    EXPECT_EQ(result, NS_FAIL);
+}
+
+TEST_F(NotificationProviderTest, ExpectFailUnsetConsumerTopics)
+{
+    NSResult result;
+    result = NS_SUCCESS;
+    result = NSProviderUnsetConsumerTopic(NULL, NULL);
+    result = NSProviderUnsetConsumerTopic(NULL, "\0");
+    result = NSProviderUnsetConsumerTopic("\0", NULL);
+    result = NSProviderUnsetConsumerTopic("\0", "\0");
+    result = NSProviderUnsetConsumerTopic("abc", NULL);
+    result = NSProviderUnsetConsumerTopic(NULL, "abc");
+    result = NSProviderUnsetConsumerTopic("abc", "\0");
+    result = NSProviderUnsetConsumerTopic("\0", "abc");
+
+    EXPECT_EQ(result, NS_FAIL);
+}
+
 TEST_F(NotificationProviderTest, CancelObserves)
 {
     bool ret = g_consumerSimul.cancelObserves();