std::shared_ptr<OC::OCResource> m_syncResource;
std::shared_ptr<OC::OCResource> m_msgResource;
+ std::shared_ptr<OC::OCResource> m_topicResource;
public:
NSConsumerSimulator()
{
resource->get(OC::QueryParamsMap(),
std::bind(&NSConsumerSimulator::onGet, this,
- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, resource),
- OC::QualityOfService::LowQos);
+ std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+ resource), OC::QualityOfService::LowQos);
}
}
void onGet(const OC::HeaderOptions &/*headerOption*/,
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")));
+ 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::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"};
std::placeholders::_3, std::placeholders::_4, resource),
OC::QualityOfService::LowQos);
+
+ m_topicResource
+ = OC::OCPlatform::constructResourceObject(resource->host(), resource->uri() + "/topic",
+ resource->connectivityType(), true, resource->getResourceTypes(),
+ resource->getResourceInterfaces());
+
}
void onObserve(const OC::HeaderOptions &/*headerOption*/,
const OC::OCRepresentation &rep , const int &eCode, const int &,
std::string(rep.getValueToString("TITLE")),
std::string(rep.getValueToString("CONTENT")),
std::string(rep.getValueToString("SOURCE")));
+
+ if(rep.getValue<int>("MESSAGE_ID") == 3)
+ {
+ m_topicResource->get(OC::QueryParamsMap(),
+ std::bind(&NSConsumerSimulator::onTopicGet, this, std::placeholders::_1,
+ std::placeholders::_2, std::placeholders::_3, m_topicResource),
+ OC::QualityOfService::LowQos);
+ }
}
else if (rep.getUri() == "/notification/sync")
{
}
}
+ void onTopicGet(const OC::HeaderOptions &/*headerOption*/,
+ 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)
{
return m_msgResource->cancelObserve(qos);
g_consumerSimul.syncToProvider(type, id, msg->providerId);
std::unique_lock< std::mutex > lock{ mutexForCondition };
- responseCon.wait_for(lock, std::chrono::milliseconds(5000));
+
+ responseCon.wait(lock);
+ //responseCon.wait_for(lock, std::chrono::milliseconds(3000));
}
TEST_F(NotificationProviderTest, ExpectEqualAddedTopicsAndRegisteredTopics)
NSProviderRegisterTopic(str.c_str());
NSProviderRegisterTopic(str2.c_str());
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, std::chrono::milliseconds(500));
+
bool isSame = true;
NSTopicLL * topics = NSProviderGetTopics();
}
EXPECT_EQ(isSame, true);
+
+ NSProviderUnregisterTopic(str.c_str());
+ NSProviderUnregisterTopic(str2.c_str());
+
+ responseCon.wait_for(lock, std::chrono::milliseconds(500));
}
TEST_F(NotificationProviderTest, ExpectEqualUnregisteredTopicsAndRegisteredTopics)
NSProviderRegisterTopic(str2.c_str());
NSProviderUnregisterTopic(str2.c_str());
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, std::chrono::milliseconds(500));
+
bool isSame = true;
NSTopicLL * topics = NSProviderGetTopics();
}
EXPECT_EQ(isSame, true);
+
+ NSProviderUnregisterTopic(str.c_str());
+
+ responseCon.wait_for(lock, std::chrono::milliseconds(500));
+}
+
+TEST_F(NotificationProviderTest, ExpectEqualSetConsumerTopicsAndGetConsumerTopics)
+{
+ std::string str("TEST1");
+ std::string str2("TEST2");
+ NSProviderRegisterTopic(str.c_str());
+ NSProviderRegisterTopic(str2.c_str());
+ NSProviderSetConsumerTopic(g_consumerID, str.c_str());
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, std::chrono::milliseconds(500));
+
+ bool isSame = false;
+ NSTopicLL * topics = NSProviderGetConsumerTopics(g_consumerID);
+
+ if(!topics)
+ {
+ printf("topic is NULL\n");
+ isSame = false;
+ }
+ else
+ {
+ 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)
+ {
+ isSame = true;
+ }
+ }
+
+ EXPECT_EQ(isSame, true);
+
+ NSProviderUnregisterTopic(str.c_str());
+ NSProviderUnregisterTopic(str2.c_str());
+
+ responseCon.wait_for(lock, std::chrono::milliseconds(500));
+}
+
+TEST_F(NotificationProviderTest, ExpectEqualUnSetConsumerTopicsAndGetConsumerTopics)
+{
+ std::string str("TEST1");
+ std::string str2("TEST2");
+ NSProviderRegisterTopic(str.c_str());
+ NSProviderRegisterTopic(str2.c_str());
+ NSProviderSetConsumerTopic(g_consumerID, str.c_str());
+ NSProviderSetConsumerTopic(g_consumerID, str2.c_str());
+ NSProviderUnsetConsumerTopic(g_consumerID, str.c_str());
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, std::chrono::milliseconds(500));
+
+ bool isSame = false;
+ NSTopicLL * topics = NSProviderGetConsumerTopics(g_consumerID);
+
+ if(!topics)
+ {
+ printf("topic is NULL\n");
+ isSame = false;
+ }
+ else
+ {
+ 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)
+ {
+ isSame = true;
+ }
+ }
+
+ EXPECT_EQ(isSame, true);
+
+ NSProviderUnregisterTopic(str.c_str());
+ NSProviderUnregisterTopic(str2.c_str());
+
+ responseCon.wait_for(lock, std::chrono::milliseconds(500));
}
TEST_F(NotificationProviderTest, CancelObserves)