EXPECT_NE((void *)NULL, payload);
bool getResult = OCRepPayloadSetPropString(payload,
NS_ATTRIBUTE_CONSUMER_ID, testProviderID.c_str());
- getResult &= OCRepPayloadSetPropObjectArray(payload,
- NS_ATTRIBUTE_TOPIC_LIST, (const OCRepPayload **)topicList, dimensions);
+ getResult &= OCRepPayloadSetPropObjectArrayAsOwner(payload,
+ NS_ATTRIBUTE_TOPIC_LIST, topicList, dimensions);
if (getResult == false)
{
OCRepPayloadDestroy(payload);
return payload;
}
- OCClientResponse * getResponse()
+ OCClientResponse * createResponse()
{
OCClientResponse * testResponse =
(OCClientResponse *)malloc(sizeof(OCClientResponse));
NSRemoveProvider(g_provider);
g_provider = NULL;
}
+ }
+
+ void removeGlobalResponse()
+ {
if (g_testResponse)
{
free((void*)(g_testResponse->resourceUri));
revState = NS_STOPPED;
expectedState = NS_DISCOVERED;
- g_testResponse = getResponse();
+ g_testResponse = createResponse();
g_testResponse->payload = (OCPayload *)getDiscoverPayload();
NSIntrospectProvider(NULL, NULL, g_testResponse);
OCRepPayloadDestroy((OCRepPayload *)g_testResponse->payload);
g_testResponse->payload = NULL;
+ removeGlobalResponse();
EXPECT_EQ(NS_DISCOVERED, revState);
}
revState = NS_STOPPED;
expectedState = NS_ALLOW;
+ g_testResponse = createResponse();
g_testResponse->payload = (OCPayload *)getMsgPayload(NS_ALLOW);
NSConsumerMessageListener(NULL,NULL, g_testResponse);
OCRepPayloadDestroy((OCRepPayload *)g_testResponse->payload);
g_testResponse->payload = NULL;
+ removeGlobalResponse();
EXPECT_EQ(NS_ALLOW, revState);
}
{
uint64_t id = 100;
+ g_testResponse = createResponse();
g_testResponse->payload = (OCPayload *)getMsgPayload(id);
NSConsumerMessageListener(NULL,NULL, g_testResponse);
OCRepPayloadDestroy((OCRepPayload *)g_testResponse->payload);
g_testResponse->payload = NULL;
+ removeGlobalResponse();
EXPECT_EQ(id, revId);
}
uint64_t id = 100;
type = NS_SYNC_DELETED;
+ g_testResponse = createResponse();
g_testResponse->payload = (OCPayload *)getSyncPayload(id, NS_SYNC_READ);
NSConsumerSyncInfoListener(NULL,NULL, g_testResponse);
OCRepPayloadDestroy((OCRepPayload *)g_testResponse->payload);
g_testResponse->payload = NULL;
+ removeGlobalResponse();
EXPECT_EQ(NS_SYNC_READ, type);
}
{
revState = NS_STOPPED;
+ g_testResponse = createResponse();
g_testResponse->payload = (OCPayload *)getTopicPayload();
g_provider_internal = getProvider(testAddr);
NSIntrospectTopic((void *)g_provider_internal, NULL, g_testResponse);
OCRepPayloadDestroy((OCRepPayload *)g_testResponse->payload);
g_testResponse->payload = NULL;
+ removeGlobalResponse();
expectedState = NS_STOPPED;
}
topics.push_back("3");
NSTopicLL * retTopic = NSConsumerGetTopicList(g_provider_internal->providerId);
- EXPECT_NE((void *)NULL, retTopic);
+ EXPECT_NE((void *)NULL, (void *)retTopic);
NSTopicLL * iter = retTopic;
std::for_each (topics.begin(), topics.end(),
TEST(NotificationConsumerTest, ExpectUnsubscribeWithPresenceStart)
{
+ g_testResponse = createResponse();
OCPresencePayload * payload = OCPresencePayloadCreate(1, 2, OC_PRESENCE_TRIGGER_CREATE, NULL);
EXPECT_NE((void *)NULL, payload);
g_testResponse->payload = (OCPayload *)payload;
EXPECT_EQ(OC_STACK_KEEP_TRANSACTION, ret);
OCPresencePayloadDestroy(payload);
+ removeGlobalResponse();
}
TEST(NotificationConsumerTest, ExpectUnsubscribeWithPresenceStop)
{
+ g_testResponse = createResponse();
OCPresencePayload * payload = OCPresencePayloadCreate(2, 2, OC_PRESENCE_TRIGGER_DELETE, NULL);
EXPECT_NE((void *)NULL, payload);
g_testResponse->payload = (OCPayload *)payload;
OCEntityHandlerRequest * request =
(OCEntityHandlerRequest *)malloc(sizeof(OCEntityHandlerRequest));
EXPECT_NE((void *)NULL, request);
+ request->requestHandle = NULL;
+ request->resource = NULL;
if (OC_REST_OBSERVE == method)
{
std::string query = std::string(NS_QUERY_CONSUMER_ID)
+ "=" + testConsumerId;
- request->query = (char *)malloc(sizeof(char) * query.size() + 1);
+ request->query = (char *)malloc(query.size() + 1);
+ EXPECT_NE((void *)NULL, request->query);
strncpy(request->query, query.c_str(), query.size() + 1);
}
request->method = method;
request->numRcvdVendorSpecificHeaderOptions = 0;
+ request->payload = NULL;
return request;
}
OCEntityHandlerRequest * request =
(OCEntityHandlerRequest *)malloc(sizeof(OCEntityHandlerRequest));
EXPECT_NE((void *)NULL, request);
+ request->requestHandle = NULL;
+ request->resource = NULL;
request->method = OC_REST_POST;
request->numRcvdVendorSpecificHeaderOptions = 0;
OCEntityHandlerRequest * syncRequest = getEntityRequest(OC_REST_OBSERVE, OC_OBSERVE_REGISTER);
NSEntityHandlerSyncCb(flag, syncRequest, NULL);
+ {
+ std::unique_lock< std::mutex > lock{ responseProviderSubLock };
+ responseProviderSub.wait_for(lock, g_waitForResponse);
+ }
free(syncRequest->query);
free(syncRequest);
OCEntityHandlerRequest * msgRequest =
getEntityRequest(OC_REST_OBSERVE, OC_OBSERVE_DEREGISTER);
NSEntityHandlerMessageCb(flag, msgRequest, NULL);
+ {
+ std::unique_lock< std::mutex > lock{ responseProviderSubLock };
+ responseProviderSub.wait_for(lock, g_waitForResponse);
+ }
free(msgRequest->query);
free(msgRequest);
OCEntityHandlerRequest * syncRequest =
getEntityRequest(OC_REST_OBSERVE, OC_OBSERVE_DEREGISTER);
NSEntityHandlerSyncCb(flag, syncRequest, NULL);
+ {
+ std::unique_lock< std::mutex > lock{ responseProviderSubLock };
+ responseProviderSub.wait_for(lock, g_waitForResponse);
+ }
free(syncRequest->query);
free(syncRequest);