Fix unittest segfault caused by discovery failure.
It is because external consumers or providers on the same network
interupt discovery or subscription precedure.
The test will be terminated once this situation happens,
even though precondition of the unittest is guided
to prevent this issue.
Change-Id: I0f763db760d8d2af0a185b9e7c3c6e71dfc5e5bf
Signed-off-by: cc <ch79.cho@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14851
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: JungYong KIM <jyong2.kim@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
}
TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithNonAccepterWhenRescan)
responseCon.notify_all();
});
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
g_provider->setListener( (OIC::Service::NSProvider::ProviderStateCallback)
ProviderChangedCallbackEmpty,
(OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallbackEmpty,
std::string msg = "msg";
OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
[this]( OIC::Service::NSMessage * message)
{
std::string msg = "msg";
OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
[this]( OIC::Service::NSMessage * message)
{
TEST_F(NotificationServiceConsumerTest, ExpectGetProviderSuccessWithValidProviderId)
{
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
OIC::Service::NSProvider *provider =
OIC::Service::NSConsumerService::getInstance()->getProvider(g_provider->getProviderId());
int ret = strcmp(provider->getProviderId().c_str(), g_provider->getProviderId().c_str());
topics.push_back("2");
topics.push_back("3");
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
std::list<OIC::Service::NSTopic *> retTopic = g_provider->getTopicList()->getTopicsList();
auto it1 = retTopic.begin();
auto it2 = topics.begin();
TEST_F(NotificationServiceConsumerTest, ExpectFailUpdateTopicOnConsumer)
{
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
OIC::Service::NSTopicsList *retTopic = g_provider->getTopicList();
for (auto it : retTopic->getTopicsList())
{
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
- EXPECT_NE((void *)g_consumer, (void *)NULL);
+ ASSERT_NE(nullptr, g_consumer) << "error: discovery failure";
}
TEST_F(NotificationProviderServiceTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
responseCon.notify_all();
});
+ ASSERT_NE(nullptr, g_consumer) << "error: discovery failure";
+
g_consumer->acceptSubscription(false);
OIC::Service::NSMessage *msg = OIC::Service::NSProviderService::getInstance()->createMessage();
{
int msgID = 0;
+ ASSERT_NE(nullptr, g_consumer) << "error: discovery failure";
+
mocks.ExpectCallFunc(MessageCallbackFromConsumerEmpty).Do(
[&msgID](const int &id, const std::string &, const std::string &, const std::string &)
{
std::string str2("TEST2");
OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
OIC::Service::NSProviderService::getInstance()->registerTopic(str2);
+
+ ASSERT_NE(nullptr, g_consumer) << "error: discovery failure";
+
g_consumer->setTopic(str1);
std::unique_lock< std::mutex > lock { mutexForCondition };
std::string str2("TEST2");
OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
OIC::Service::NSProviderService::getInstance()->registerTopic(str2);
+
+ ASSERT_NE(nullptr, g_consumer) << "error: discovery failure";
+
g_consumer->setTopic(str1);
g_consumer->setTopic(str2);
g_consumer->unsetTopic(str1);
responseCon.wait_for(lock, g_waitForResponse);
EXPECT_EQ(NS_DISCOVERED, revState);
+
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
}
TEST_F(NotificationConsumerTest, DiscoverProviderWithNonAccepterWhenRescan)
TEST_F(NotificationConsumerTest, ExpectSubscribeSuccess)
{
NSProviderState revState = NS_DENY;
+
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
mocks.OnCallFunc(NSProviderChangedCallback).Do(
[this, & revState](NSProvider * , NSProviderState state)
{
uint64_t id = 10;
std::string title = "title";
std::string msg = "msg";
-
uint64_t revId = 0;
mocks.OnCallFunc(NSNotificationReceivedCallbackEmpty).Do(
TEST_F(NotificationConsumerTest, ExpectGetProviderSuccessWithValidProviderId)
{
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
NSProvider * provider = NSConsumerGetProvider(g_provider->providerId);
int ret = strcmp(provider->providerId, g_provider->providerId);
EXPECT_EQ(0, ret);
TEST_F(NotificationConsumerTest, ExpectGetTopicListIsNULL)
{
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
NSTopicLL * currentTopics = NSConsumerGetTopicList(g_provider->providerId);
EXPECT_EQ(NULL, currentTopics);
}
topics.push_back("2");
topics.push_back("3");
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
NSTopicLL * retTopic = NSConsumerGetTopicList(g_provider->providerId);
std::for_each (topics.begin(), topics.end(),
[this, & retTopic, & isSame](const std::string & str)
TEST_F(NotificationConsumerTest, ExpectFailUpdateTopicOnConsumer)
{
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+
NSTopicLL * retTopic = NSConsumerGetTopicList(g_provider->providerId);
for (; retTopic; retTopic = retTopic->next)
{
std::unique_lock< std::mutex > lock{ mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
- EXPECT_NE((void*)g_consumerID, (void*)NULL);
+ ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure";
}
TEST_F(NotificationProviderTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
bool expectTrue = true;
int msgID;
+ ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure";
+
mocks.OnCallFunc(NSMessageCallbackFromConsumerEmpty).Do(
[& expectTrue, &msgID](const int &id, const std::string&, const std::string&, const std::string&)
{
{
int msgID;
+ ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure";
+
mocks.ExpectCallFunc(NSMessageCallbackFromConsumerEmpty).Do(
[&msgID](const int &id, const std::string&, const std::string&, const std::string&)
{
{
int id;
+ ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure";
+
mocks.ExpectCallFunc(NSSyncCallbackFromConsumerEmpty).Do(
[& id](int & type, int &syncId)
{
{
int type = NS_SYNC_READ;
int id;
+
+ ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure";
+
mocks.ExpectCallFunc(NSSyncCallbackEmpty).Do(
[& id](NSSyncInfo * sync)
{
responseCon.wait_for(lock, g_waitForResponse);
bool isSame = false;
+
+ ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure";
+
NSTopicLL * topics = NSProviderGetConsumerTopics(g_consumerID);
if(!topics)