bug fix for response of topic and modify unittest.
authorjaesick.shin <jaesick.shin@samsung.com>
Thu, 13 Oct 2016 10:24:40 +0000 (19:24 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 13 Oct 2016 14:18:53 +0000 (14:18 +0000)
this patch include,
1. bug fix for response of topic post case.
2. modify unittest about included interface type.

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

index f551541..ae623c6 100644 (file)
@@ -289,7 +289,9 @@ OCEntityHandlerResult NSEntityHandlerTopicCb(OCEntityHandlerFlag flag,
             NS_LOG(DEBUG, "NSEntityHandlerTopicCb - OC_REST_POST");\r
             // Accepter is provider. our service is not support sendtopiclist from OC_REST_POST\r
             // Accepter is consumer. our service is support sendtopiclist from OC_REST_POST\r
-            if(NSGetPolicy() == false)\r
+            if(NSGetPolicy() == false &&\r
+                    NSProviderIsTopicAttributes(OCRepPayloadClone((OCRepPayload *)\r
+                            entityHandlerRequest->payload)))\r
             {\r
                 NSPushQueue(TOPIC_SCHEDULER, TASK_POST_TOPIC,\r
                         NSCopyOCEntityHandlerRequest(entityHandlerRequest));\r
@@ -430,7 +432,7 @@ bool NSProviderIsTopicAttributes(OCRepPayload * payload)
     OCRepPayloadValue * curr = payload->values;\r
     while(curr)\r
     {\r
-        if (!NSProviderCompareSyncAttributes(curr->name))\r
+        if (!NSProviderCompareTopicAttributes(curr->name))\r
         {\r
             return false;\r
         }\r
@@ -517,26 +519,28 @@ OCStackResult NSProviderSendResponse(OCEntityHandlerRequest * entityHandlerReque
         OCResourcePayloadAddStringLL(&payload->types, rtStr);\r
     }\r
 \r
-    if(resourceType != NS_RESOURCE_TOPIC)\r
+    if (resourceType == NS_RESOURCE_TOPIC && entityHandlerRequest->method == OC_REST_GET)\r
     {\r
-        OCEntityHandlerResponse response;\r
-        response.numSendVendorSpecificHeaderOptions = 0;\r
-        memset(response.sendVendorSpecificHeaderOptions, 0,\r
-                sizeof response.sendVendorSpecificHeaderOptions);\r
-        memset(response.resourceUri, 0, sizeof response.resourceUri);\r
-\r
-        response.requestHandle = entityHandlerRequest->requestHandle;\r
-        response.resourceHandle = entityHandlerRequest->resource;\r
-        response.persistentBufferFlag = 0;\r
-        response.ehResult = ehResult;\r
-        response.payload = (OCPayload *) payload;\r
-\r
-        if (OCDoResponse(&response) != OC_STACK_OK)\r
-        {\r
-            NS_LOG(ERROR, "Fail to AccessPolicy send response");\r
-            OCRepPayloadDestroy(payload);\r
-            return ehResult;\r
-        }\r
+        OCRepPayloadDestroy(payload);\r
+        return ehResult;\r
+    }\r
+\r
+    OCEntityHandlerResponse response;\r
+    response.numSendVendorSpecificHeaderOptions = 0;\r
+    memset(response.sendVendorSpecificHeaderOptions, 0,\r
+            sizeof response.sendVendorSpecificHeaderOptions);\r
+    memset(response.resourceUri, 0, sizeof response.resourceUri);\r
+\r
+    response.requestHandle = entityHandlerRequest->requestHandle;\r
+    response.resourceHandle = entityHandlerRequest->resource;\r
+    response.persistentBufferFlag = 0;\r
+    response.ehResult = ehResult;\r
+    response.payload = (OCPayload *) payload;\r
+\r
+    if (OCDoResponse(&response) != OC_STACK_OK)\r
+    {\r
+        NS_LOG(ERROR, "Fail to AccessPolicy send response");\r
+        ehResult = OC_STACK_ERROR;\r
     }\r
 \r
     OCRepPayloadDestroy(payload);\r
index 02cc94a..bd0a6e3 100644 (file)
@@ -37,10 +37,12 @@ private:
     std::shared_ptr<OC::OCResource> m_msgResource;
     std::shared_ptr<OC::OCResource> m_topicResource;
 
+    bool isTopicPost;
+
 public:
     NSConsumerSimulator()
     : m_messageFunc(), m_syncFunc(),
-      m_syncResource() { };
+      m_syncResource(), isTopicPost(false) { };
     ~NSConsumerSimulator() = default;
 
     NSConsumerSimulator(const NSConsumerSimulator &) = delete;
@@ -97,8 +99,8 @@ private:
     {
         if(resource->uri() == "/notification")
         {
-            resource->get(OC::QueryParamsMap(),
-                    std::bind(&NSConsumerSimulator::onGet, this,
+            resource->get(std::string("oic.wk.notification"), std::string("oic.if.baseline"),
+                    OC::QueryParamsMap(), std::bind(&NSConsumerSimulator::onGet, this,
                             std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
                             resource), OC::QualityOfService::LowQos);
         }
@@ -163,7 +165,8 @@ private:
 
             if(rep.getValue<int>("messageId") == 3)
             {
-                m_topicResource->get(OC::QueryParamsMap(),
+                m_topicResource->get(std::string("oic.wk.notification"),
+                        std::string("oic.if.baseline"), OC::QueryParamsMap(),
                         std::bind(&NSConsumerSimulator::onTopicGet, this, std::placeholders::_1,
                                 std::placeholders::_2, std::placeholders::_3, m_topicResource),
                                 OC::QualityOfService::LowQos);
@@ -176,9 +179,43 @@ private:
     }
 
     void onTopicGet(const OC::HeaderOptions &/*headerOption*/,
-            const OC::OCRepresentation & /*rep*/ , const int /*eCode*/,
+            const OC::OCRepresentation & rep , const int /*eCode*/,
             std::shared_ptr<OC::OCResource> /*resource*/)
     {
+
+        if(!isTopicPost)
+        {
+            isTopicPost = true;
+            OC::OCRepresentation postRep;
+
+            std::vector<OC::OCRepresentation> topicArr =
+                            rep.getValue<std::vector<OC::OCRepresentation>>("topicList");
+
+            std::vector<OC::OCRepresentation> postTopicArr;
+
+            for(std::vector<OC::OCRepresentation>::iterator it = topicArr.begin();
+                    it != topicArr.end(); ++it) {
+                /* std::cout << *it; ... */
+                OC::OCRepresentation topic = *it;
+                OC::OCRepresentation postTopic;
+
+                postTopic.setValue("topicName", topic.getValueToString("topicName"));
+                postTopic.setValue("topicState", (int) topic.getValue<int>("topicState"));
+
+                postTopicArr.push_back(topic);
+
+//                std::cout << "tName : " << tName << std::endl;
+//                std::cout << "tState : " << tState << std::endl;
+            }
+
+            postRep.setValue<std::vector<OC::OCRepresentation>>
+                ("topicList", postTopicArr);
+
+            OC::QueryParamsMap map;
+            map.insert(std::pair<std::string,std::string>(std::string("consumerId"),
+                    std::string("123456789012345678901234567890123456")));
+            m_topicResource->post(postRep, map, &onPost, OC::QualityOfService::LowQos);
+        }
     }
 
     OCStackResult msgResourceCancelObserve(OC::QualityOfService qos)
index a4477c6..0349297 100755 (executable)
@@ -139,7 +139,7 @@ TEST_F(NotificationProviderTest, StartProviderPositiveWithNSPolicyTrue)
     config.subRequestCallback = NSRequestedSubscribeCallbackEmpty;
     config.syncInfoCallback = NSSyncCallbackEmpty;
     config.subControllability = true;
-    config.userInfo = NULL;
+    config.userInfo = strdup("user1");
 
     NSResult ret = NSStartProvider(config);