//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <gtest/gtest.h>
-#include <HippoMocks/hippomocks.h>
#include <atomic>
#include <functional>
#include <condition_variable>
NS_SELECTION_PROVIDER = 1
};
+ OIC::Service::NSProviderState g_expectedState = OIC::Service::NSProviderState::DENY;
+ OIC::Service::NSProviderState g_revState = OIC::Service::NSProviderState::DENY;
+
+ uint64_t g_messageId = 0;
+
+ OIC::Service::NSSyncInfo::NSSyncType g_expectedSyncType =
+ OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
+ OIC::Service::NSSyncInfo::NSSyncType g_syncType =
+ OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
+
}
class TestWithMock: public testing::Test
{
- public:
- MockRepository mocks;
-
protected:
virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
{
virtual void TearDown()
{
- try
- {
- mocks.VerifyAll();
- }
- catch (...)
- {
- mocks.reset();
- throw;
- }
+
}
};
NotificationServiceConsumerTest() = default;
~NotificationServiceConsumerTest() = default;
- static void ProviderDiscoveredCallbackEmpty( std::shared_ptr<OIC::Service::NSProvider> )
+ static void ProviderDiscoveredCallback( std::shared_ptr<OIC::Service::NSProvider> provider)
{
std::cout << __func__ << std::endl;
+ g_provider = provider;
+ responseCon.notify_all();
}
- static void NotificationReceivedCallbackEmpty( OIC::Service::NSMessage )
+ static void NotificationReceivedCallback( OIC::Service::NSMessage message)
{
- std::cout << __func__ << std::endl;
+ std::cout << "Income Notification : " << message.getMessageId() << std::endl;
+ g_messageId = message.getMessageId();
+ responseCon.notify_all();
}
- static void SyncCallbackEmpty(OIC::Service::NSSyncInfo)
+ static void SyncCallback(OIC::Service::NSSyncInfo sync)
{
std::cout << __func__ << std::endl;
+ g_syncType = sync.getState();
+ if (g_expectedSyncType == sync.getState())
+ {
+ std::cout << "[Expected]" << __func__ << std::endl;
+ responseCon.notify_all();
+ }
}
- static void FoundResourceEmpty(std::shared_ptr< OC::OCResource >)
+ static void FoundResource(std::shared_ptr< OC::OCResource >)
{
std::cout << __func__ << std::endl;
}
- static void ProviderChangedCallbackEmpty( OIC::Service::NSProviderState )
+ static void ProviderChangedCallback( OIC::Service::NSProviderState state)
{
std::cout << __func__ << std::endl;
+
+ if (g_expectedState == state)
+ {
+ g_revState = state;
+ std::cout << "[Expected]" << __func__ << std::endl;
+ responseCon.notify_all();
+ }
}
protected:
TEST_F(NotificationServiceConsumerTest, StartConsumerPositive)
{
- OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallbackEmpty);
+ OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallback);
}
TEST_F(NotificationServiceConsumerTest, StopConsumerPositive)
TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithNonAccepterWhenStartedConsumerFirst)
{
- mocks.ExpectCallFunc(ProviderDiscoveredCallbackEmpty).Do(
- [this]( std::shared_ptr<OIC::Service::NSProvider> provider)
- {
- std::cout << "Call Discovered" << std::endl;
- std::cout << provider->getProviderId() << std::endl;
- responseCon.notify_all();
- });
-
- OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallbackEmpty);
+ OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallback);
g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_CONSUMER);
g_providerSimul.createNotificationResource();
responseCon.wait_for(lock, g_waitForResponse);
}
- mocks.ExpectCallFunc(ProviderDiscoveredCallbackEmpty).Do(
- [this]( std::shared_ptr<OIC::Service::NSProvider> provider)
- {
- std::cout << "Call Discovered" << std::endl;
- g_provider = provider;
- std::cout << g_provider->getProviderId() << std::endl;
- responseCon.notify_all();
- });
-
- OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallbackEmpty);
+ OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallback);
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithNonAccepterWhenRescan)
{
g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_CONSUMER);
- mocks.OnCallFunc(ProviderDiscoveredCallbackEmpty).Do(
- [this]( std::shared_ptr<OIC::Service::NSProvider> provider)
- {
- std::cout << "Call Discovered" << std::endl;
- g_provider = provider;
- std::cout << g_provider->getProviderId() << std::endl;
- responseCon.notify_all();
- });
OIC::Service::NSConsumerService::getInstance()->rescanProvider();
TEST_F(NotificationServiceConsumerTest, ExpectSubscribeSuccess)
{
- OIC::Service::NSProviderState revState = OIC::Service::NSProviderState::DENY;
- mocks.OnCallFunc(ProviderChangedCallbackEmpty).Do(
- [this, & revState](OIC::Service::NSProviderState state)
- {
- std::cout << "Income Accepted subscription : " << std::endl;
- revState = state;
- responseCon.notify_all();
- });
-
ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+ g_expectedState = OIC::Service::NSProviderState::ALLOW;
- g_provider->setListener( (OIC::Service::NSProvider::ProviderStateCallback)
- ProviderChangedCallbackEmpty,
- (OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallbackEmpty,
- (OIC::Service::NSProvider::SyncInfoReceivedCallback)SyncCallbackEmpty);
+ g_provider->setListener( (OIC::Service::NSProvider::ProviderStateCallback)ProviderChangedCallback,
+ (OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallback,
+ (OIC::Service::NSProvider::SyncInfoReceivedCallback)SyncCallback);
if (!g_provider->isSubscribed())
{
g_provider->subscribe();
}
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
- EXPECT_EQ(OIC::Service::NSProviderState::ALLOW, revState);
+ EXPECT_EQ(g_expectedState, g_revState);
}
TEST_F(NotificationServiceConsumerTest, ExpectReceiveNotification)
std::string title = "title";
std::string msg = "msg";
- mocks.ExpectCallFunc(NotificationReceivedCallbackEmpty).Do(
- [this]( OIC::Service::NSMessage message)
- {
- std::cout << "Income Notification : " << message.getMessageId() << std::endl;
- responseCon.notify_all();
- });
-
g_providerSimul.notifyMessage(id, title, msg);
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
-
+ EXPECT_EQ(id, g_messageId);
OIC::Service::NSConsumerService::getInstance()->stop();
}
{
g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_PROVIDER);
- mocks.ExpectCallFunc(ProviderDiscoveredCallbackEmpty).Do(
- [this]( std::shared_ptr<OIC::Service::NSProvider> provider)
- {
- std::cout << "Call Discovered" << std::endl;
- g_provider = provider;
- g_provider->setListener( (OIC::Service::NSProvider::ProviderStateCallback)
- ProviderChangedCallbackEmpty,
- (OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallbackEmpty,
- (OIC::Service::NSProvider::SyncInfoReceivedCallback)SyncCallbackEmpty);
- if (!g_provider->isSubscribed())
- {
- g_provider->subscribe();
- }
- std::cout << g_provider->getProviderId() << std::endl;
- responseCon.notify_all();
- });
+ OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallback);
- OIC::Service::NSConsumerService::getInstance()->start(ProviderDiscoveredCallbackEmpty);
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
+
+ ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
+ g_provider->setListener( (OIC::Service::NSProvider::ProviderStateCallback)
+ ProviderChangedCallback,
+ (OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallback,
+ (OIC::Service::NSProvider::SyncInfoReceivedCallback)SyncCallback);
+ if (!g_provider->isSubscribed())
+ {
+ g_provider->subscribe();
+ }
+
}
TEST_F(NotificationServiceConsumerTest, ExpectReceiveNotificationWithAccepterisProvider)
uint64_t id = 11;
std::string title = "title";
std::string msg = "msg";
- uint64_t revId = 1;
-
- mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
- [this, & id, & revId](OIC::Service::NSMessage message)
- {
- std::cout << "Income Notification : " << message.getMessageId() << std::endl;
- revId = message.getMessageId();
- responseCon.notify_all();
- });
g_providerSimul.notifyMessage(id, title, msg);
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
- EXPECT_EQ(id, revId);
+ EXPECT_EQ(id, g_messageId);
}
TEST_F(NotificationServiceConsumerTest, ExpectCallbackReadCheckWhenProviderNotifySync)
uint64_t id = 12;
std::string title = "title";
std::string msg = "msg";
- OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
-
- mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
- [this]( OIC::Service::NSMessage message)
- {
- std::cout << "Income Notification : " << message.getMessageId() << std::endl;
- });
-
- mocks.OnCallFunc(SyncCallbackEmpty).Do(
- [& type, this](OIC::Service::NSSyncInfo sync)
- {
- std::cout << "Income SyncInfo : " << sync.getMessageId()
- << ", State : " << (int) sync.getState() << std::endl;
- type = sync.getState();
- responseCon.notify_all();
- });
+ g_expectedSyncType = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
g_providerSimul.notifyMessage(id, title, msg);
{
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
}
- EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ, type);
+ EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ, g_syncType);
+ g_expectedSyncType = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
}
TEST_F(NotificationServiceConsumerTest, ExpectCallbackDismissCheckWhenProviderNotifySync)
uint64_t id = 13;
std::string title = "title";
std::string msg = "msg";
- OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
-
- mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
- [this]( OIC::Service::NSMessage message)
- {
- std::cout << "Income Notification : " << message.getMessageId() << std::endl;
- });
-
- mocks.OnCallFunc(SyncCallbackEmpty).Do(
- [& type, this](OIC::Service::NSSyncInfo sync)
- {
- std::cout << "Income Notification : " << sync.getMessageId()
- << ", State : " << (int) sync.getState() << std::endl;
- type = sync.getState();
- responseCon.notify_all();
- });
+ g_syncType = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
+ g_expectedSyncType = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
g_providerSimul.notifyMessage(id, title, msg);
{
responseCon.wait_for(lock, g_waitForResponse);
}
- EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED, type);
+ EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED, g_syncType);
+ g_expectedSyncType = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
}
TEST_F(NotificationServiceConsumerTest, ExpectCallbackReadCheckWhenConsumerPostSync)
uint64_t id = 14;
std::string title = "title";
std::string msg = "msg";
- OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
+ g_syncType = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
+ g_expectedSyncType = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
ASSERT_NE(nullptr, g_provider) << "error: discovery failure";
- mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do(
- [this]( OIC::Service::NSMessage message)
- {
- std::cout << "Income Notification : " << message.getMessageId() << std::endl;
- g_provider->sendSyncInfo(message.getMessageId(),
- OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
- });
-
- mocks.OnCallFunc(SyncCallbackEmpty).Do(
- [& type, this](OIC::Service::NSSyncInfo sync)
- {
- std::cout << "Income Notification : " << sync.getMessageId()
- << ", State : " << (int) sync.getState() << std::endl;
- type = sync.getState();
- responseCon.notify_all();
- });
-
g_providerSimul.notifyMessage(id, title, msg);
{
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
}
- EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ, type);
+ g_provider->sendSyncInfo(g_messageId,
+ OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);
+ std::unique_lock< std::mutex > lock { mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ, g_syncType);
+ g_expectedSyncType = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
}
TEST_F(NotificationServiceConsumerTest, ExpectCallbackDismissCheckWhenConsumerPostSync)
uint64_t id = 15;
std::string title = "title";
std::string msg = "msg";
- OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
+ g_syncType = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
+ g_expectedSyncType = 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::cout << "Income Notification : " << message.getMessageId() << std::endl;
- g_provider->sendSyncInfo(message.getMessageId(),
- OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED);
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
- });
-
- mocks.OnCallFunc(SyncCallbackEmpty).Do(
- [& type, this](OIC::Service::NSSyncInfo sync)
- {
- std::cout << "Income Notification : " << sync.getMessageId()
- << ", State : " << (int) sync.getState() << std::endl;
- type = sync.getState();
- responseCon.notify_all();
- });
-
g_providerSimul.notifyMessage(id, title, msg);
{
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
}
- EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED, type);
+ g_provider->sendSyncInfo(g_messageId,
+ OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED);
+ std::unique_lock< std::mutex > lock { mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED, g_syncType);
+ g_expectedSyncType = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
}
TEST_F(NotificationServiceConsumerTest, ExpectGetProviderSuccessWithValidProviderId)
TEST_F(NotificationServiceConsumerTest, ExpectCallbackTopicUpdated)
{
- OIC::Service::NSProviderState revState = OIC::Service::NSProviderState::STOPPED;
- mocks.OnCallFunc(ProviderChangedCallbackEmpty).Do(
- [this, & revState](OIC::Service::NSProviderState state)
- {
- std::cout << "Income Changed Callback : " << (int)state << std::endl;
- revState = state;
- responseCon.notify_all();
- });
+ g_expectedState = OIC::Service::NSProviderState::TOPIC;
NSProviderSimulator::NS_TopicList topics;
topics.push_back("1");
topics.push_back("3");
g_providerSimul.setTopics(topics);
-
+ std::chrono::milliseconds waitForTopicUdateComplete(1000);
std::unique_lock< std::mutex > lock{ mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
- EXPECT_EQ(OIC::Service::NSProviderState::TOPIC, revState);
+ EXPECT_EQ(OIC::Service::NSProviderState::TOPIC, g_revState);
+ responseCon.wait_for(lock, waitForTopicUdateComplete);
+ g_expectedState = OIC::Service::NSProviderState::STOPPED;
}
TEST_F(NotificationServiceConsumerTest, ExpectEQTopicList)
TEST_F(NotificationServiceConsumerTest, ExpectCallbackDeletedProvider)
{
- OIC::Service::NSProviderState type = OIC::Service::NSProviderState::ALLOW;
- mocks.OnCallFunc(ProviderChangedCallbackEmpty).Do(
- [& type, this](OIC::Service::NSProviderState state)
- {
- std::cout << "Income Changed Callback : " << std::endl;
- type = state;
- });
-
+ g_expectedState = OIC::Service::NSProviderState::STOPPED;
g_providerSimul.deleteNotificationResource();
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
- EXPECT_EQ(type, OIC::Service::NSProviderState::STOPPED);
+ EXPECT_EQ(g_revState, OIC::Service::NSProviderState::STOPPED);
OIC::Service::NSConsumerService::getInstance()->stop();
}
#include <iostream>
#include <memory>
+#include <list>
+
#include "OCPlatform.h"
#include "OCApi.h"
NSProviderSimulator()
: m_notificationHandle(), m_messageHandle(), m_syncHandle(), m_topicHandle(),
m_syncRep(), m_messageRep(), m_accepter(0),
- m_notificationUri(std::string("/notification")),
+ m_notificationUri(std::string("/notificationTest")),
m_messageUri(std::string("/message")),
m_syncUri(std::string("/sync")),
m_topicUri(std::string("/topic")),
m_syncRep = requests->getResourceRepresentation();
std::cout << "Receive POST for Sync" << std::endl;
- std::cout << "provider Id : " << m_syncRep.getValueToString("x.org.iotivity.ns.providerid") << std::endl;
+ std::cout << "provider Id : " << m_syncRep.getValueToString("x.org.iotivity.ns.providerid") <<
+ std::endl;
std::cout << "Sync State : " << m_syncRep.getValueToString("x.org.iotivity.ns.state") << std::endl;
response->setResourceRepresentation(m_syncRep);
{
std::string providerId = "123456789012345678901234567890123456";
m_messageRep.setValue<int>("x.org.iotivity.ns.messageid", id);
- m_messageRep.setValue("x.org.iotivity.ns.title", title);
- m_messageRep.setValue("x.org.iotivity.ns.contenttext", content);
- m_messageRep.setValue("x.org.iotivity.ns.providerid", providerId);
+ m_messageRep.setValue<std::string>("x.org.iotivity.ns.title", title);
+ m_messageRep.setValue<std::string>("x.org.iotivity.ns.contenttext", content);
+ m_messageRep.setValue<std::string>("x.org.iotivity.ns.providerid", providerId);
}
void setTopics(const NS_TopicList &topics)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <gtest/gtest.h>
-#include <HippoMocks/hippomocks.h>
#include <atomic>
#include <functional>
#include <condition_variable>
{
std::atomic_bool g_isStartedStack(false);
- std::chrono::milliseconds g_waitForResponse(500);
+ std::chrono::milliseconds g_waitForResponse(1000);
- std::condition_variable responseCon;
- std::mutex mutexForCondition;
+ std::condition_variable responseProviderSub;
+ std::mutex responseProviderSubLock;
+
+ std::condition_variable responseProviderSync;
+ std::mutex responseProviderSyncLock;
+
+ std::condition_variable responseConsumerMessage;
+ std::mutex responseConsumerMessageLock;
+
+ std::condition_variable responseConsumerSync;
+ std::mutex responseConsumerSyncLock;
NSConsumerSimulator g_consumerSimul;
std::shared_ptr<OIC::Service::NSConsumer> g_consumer;
+
+ int expectedMsgId;
+ int expectedSyncType = NS_SYNC_READ;
}
class TestWithMock: public testing::Test
{
- public:
- MockRepository mocks;
-
protected:
virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
{
virtual void TearDown()
{
- try
- {
- mocks.VerifyAll();
- }
- catch (...)
- {
- mocks.reset();
- throw;
- }
+
}
};
NotificationProviderServiceTest() = default;
~NotificationProviderServiceTest() = default;
- static void ConsumerSubscribedCallbackEmpty(std::shared_ptr<OIC::Service::NSConsumer> )
+ static void ConsumerSubscribedCallback(std::shared_ptr<OIC::Service::NSConsumer> consumer)
{
std::cout << __func__ << std::endl;
+ g_consumer = consumer;
+
+ responseProviderSub.notify_all();
}
- static void MessageSynchronizedCallbackEmpty(OIC::Service::NSSyncInfo)
+ static void MessageSynchronizedCallback(OIC::Service::NSSyncInfo sync)
{
std::cout << __func__ << std::endl;
+ expectedSyncType = (int) sync.getState();
+ expectedMsgId = sync.getMessageId();
+ responseProviderSync.notify_all();
}
- static void MessageCallbackFromConsumerEmpty(
- const int &, const std::string &, const std::string &, const std::string &)
+ static void MessageCallbackFromConsumer(
+ const int &id, const std::string &, const std::string &, const std::string &)
{
std::cout << __func__ << std::endl;
+ expectedMsgId = id;
+ std::cout << expectedMsgId << std::endl;
+ responseConsumerMessage.notify_all();
}
- static void SyncCallbackFromConsumerEmpty(int, int)
+ static void SyncCallbackFromConsumer(const int type, const int syncId)
{
std::cout << __func__ << std::endl;
+ expectedSyncType = type;
+ expectedMsgId = syncId;
+ responseConsumerSync.notify_all();
}
protected:
TEST_F(NotificationProviderServiceTest, StartProviderPositiveWithPolicyTrue)
{
OIC::Service::NSProviderService::ProviderConfig config;
- config.m_subscribeRequestCb = ConsumerSubscribedCallbackEmpty;
- config.m_syncInfoCb = MessageSynchronizedCallbackEmpty;
+ config.m_subscribeRequestCb = ConsumerSubscribedCallback;
+ config.m_syncInfoCb = MessageSynchronizedCallback;
config.subControllability = true;
+ config.userInfo = "user1";
+ config.resourceSecurity = false;
OIC::Service::NSResult ret = OIC::Service::NSProviderService::getInstance()->start(config);
TEST_F(NotificationProviderServiceTest, StartProviderPositiveWithPolicyFalse)
{
OIC::Service::NSProviderService::ProviderConfig config;
- config.m_subscribeRequestCb = ConsumerSubscribedCallbackEmpty;
- config.m_syncInfoCb = MessageSynchronizedCallbackEmpty;
+ config.m_subscribeRequestCb = ConsumerSubscribedCallback;
+ config.m_syncInfoCb = MessageSynchronizedCallback;
config.subControllability = false;
+ config.resourceSecurity = false;
OIC::Service::NSResult ret = OIC::Service::NSProviderService::getInstance()->start(config);
ExpectCallbackWhenReceiveSubscribeRequestWithAccepterProvider)
{
g_consumer = NULL;
- mocks.ExpectCallFunc(ConsumerSubscribedCallbackEmpty).Do(
- []( std::shared_ptr<OIC::Service::NSConsumer> consumer)
- {
- std::cout << "ConsumerSubscribedCallbackEmpty" << std::endl;
- g_consumer = consumer;
- responseCon.notify_all();
- });
OIC::Service::NSProviderService::ProviderConfig config;
- config.m_subscribeRequestCb = ConsumerSubscribedCallbackEmpty;
- config.m_syncInfoCb = MessageSynchronizedCallbackEmpty;
+ config.m_subscribeRequestCb = ConsumerSubscribedCallback;
+ config.m_syncInfoCb = MessageSynchronizedCallback;
config.subControllability = true;
+ config.resourceSecurity = false;
OIC::Service::NSProviderService::getInstance()->start(config);
- {
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
- }
-
- g_consumerSimul.setCallback(MessageCallbackFromConsumerEmpty,
- SyncCallbackFromConsumerEmpty);
+ g_consumerSimul.setCallback(MessageCallbackFromConsumer,
+ SyncCallbackFromConsumer);
g_consumerSimul.findProvider();
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
+ // maximum waiting time for subscription is 1.5 sec.
+ // usually maximum time is 1 sec. (g_waitForResponse = 1 sec.)
+ // but, in the secured case is need to more wait for processing.
+ std::chrono::milliseconds waitForSubscription(1500);
+ std::unique_lock< std::mutex > lock{ responseProviderSubLock };
+ responseProviderSub.wait_for(lock, waitForSubscription);
ASSERT_NE(nullptr, g_consumer) << "error: discovery failure";
}
TEST_F(NotificationProviderServiceTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
{
- bool expectTrue = true;
int msgID = 0;
- mocks.OnCallFunc(MessageCallbackFromConsumerEmpty).Do(
- [& expectTrue, &msgID](const int &id, const std::string &, const std::string &,
- const std::string &)
- {
- if (id == msgID)
- {
- std::cout << "This function never call" << std::endl;
- expectTrue = false;
- }
- responseCon.notify_all();
- });
ASSERT_NE(nullptr, g_consumer) << "error: discovery failure";
msg.setSourceName(std::string("OCF"));
OIC::Service::NSProviderService::getInstance()->sendMessage(msg);
- {
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
- }
+ std::unique_lock< std::mutex > lock{ responseConsumerMessageLock };
+ responseConsumerMessage.wait_for(lock, g_waitForResponse);
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
+ EXPECT_NE(expectedMsgId, msgID);
+ responseConsumerMessage.wait_for(lock, g_waitForResponse);
- EXPECT_EQ(expectTrue, true);
}
TEST_F(NotificationProviderServiceTest, ExpectCallNotifyOnConsumerByAcceptIsTrue)
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 &)
- {
- if (id == msgID)
- {
- std::cout << "ExpectCallNotifyOnConsumerByAcceptIsTrue" << std::endl;
- responseCon.notify_all();
- }
- });
-
g_consumer->acceptSubscription(true);
OIC::Service::NSMessage msg = OIC::Service::NSProviderService::getInstance()->createMessage();
msg.setSourceName(std::string("OCF"));
OIC::Service::NSProviderService::getInstance()->sendMessage(msg);
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
+ std::unique_lock< std::mutex > lock{ responseConsumerMessageLock };
+ responseConsumerMessage.wait_for(lock, g_waitForResponse);
+ EXPECT_EQ(expectedMsgId, msgID);
}
TEST_F(NotificationProviderServiceTest, ExpectCallbackSyncOnReadToConsumer)
{
int id = 0;
+ int type = (int)OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
+ expectedSyncType = (int)OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
- mocks.ExpectCallFunc(SyncCallbackFromConsumerEmpty).Do(
- [& id](int &type, int &syncId)
- {
- std::cout << "MessageSynchronizedCallbackEmpty" << std::endl;
- if (syncId == id &&
- type == (int)OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ)
- {
- std::cout << "ExpectCallbackSyncOnReadFromConsumer" << std::endl;
- responseCon.notify_all();
- }
- });
OIC::Service::NSMessage msg = OIC::Service::NSProviderService::getInstance()->createMessage();
id = (int)msg.getMessageId();
OIC::Service::NSProviderService::getInstance()->sendSyncInfo(msg.getMessageId(),
OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
+ std::unique_lock< std::mutex > lock{ responseConsumerSyncLock };
+ responseConsumerSync.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(expectedMsgId, id);
+ EXPECT_EQ(expectedSyncType, type);
}
TEST_F(NotificationProviderServiceTest, ExpectCallbackSyncOnReadFromConsumer)
{
int type = (int)OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ;
+ expectedSyncType = (int)OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED;
+
int id = 0;
- mocks.ExpectCallFunc(MessageSynchronizedCallbackEmpty).Do(
- [& id](OIC::Service::NSSyncInfo sync)
- {
- std::cout << "MessageSynchronizedCallbackEmpty" << std::endl;
- if ((int)sync.getMessageId() == id
- && sync.getState() == OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ)
- {
- std::cout << "ExpectCallbackSyncOnReadFromConsumer" << std::endl;
- responseCon.notify_all();
- }
- });
OIC::Service::NSMessage msg = OIC::Service::NSProviderService::getInstance()->createMessage();
id = (int)msg.getMessageId();
msg.setContentText(std::string("ContentText"));
msg.setSourceName(std::string("OCF"));
g_consumerSimul.syncToProvider(type, id, msg.getProviderId());
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait(lock);
+ std::unique_lock< std::mutex > lock{ responseProviderSyncLock };
+ responseProviderSync.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(expectedMsgId, id);
+ EXPECT_EQ(expectedSyncType, type);
}
TEST_F(NotificationProviderServiceTest, ExpectEqualAddedTopicsAndRegisteredTopics)
std::string str2("TEST2");
OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
OIC::Service::NSProviderService::getInstance()->registerTopic(str2);
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
+
bool isSame = false;
- auto topicList =
- OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList();
- if (!topicList)
+ auto topicList = OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList();
+
+ std::string compString[10];
+ int i = 0;
+ for (auto itr : topicList->getTopicsList())
{
- printf("topic is NULL\n");
- isSame = false;
+ compString[i] = itr.getTopicName(); i++;
}
- else
+ std::cout << compString[0] << std::endl;
+ std::cout << compString[1] << std::endl;
+ if (str1.compare(compString[0]) == 0 && str2.compare(compString[1]) == 0)
{
- std::string compString[10];
- int i = 0;
- for (auto itr : topicList->getTopicsList())
- {
- compString[i] = itr.getTopicName(); i++;
- }
- std::cout << compString[0] << std::endl;
- std::cout << compString[1] << std::endl;
- if (str1.compare(compString[0]) == 0 && str2.compare(compString[1]) == 0)
- {
- isSame = true;
- }
+ isSame = true;
}
+
EXPECT_EQ(isSame, true);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
- responseCon.wait_for(lock, g_waitForResponse);
+
}
TEST_F(NotificationProviderServiceTest, ExpectEqualUnregisteredTopicsAndRegisteredTopics)
OIC::Service::NSProviderService::getInstance()->registerTopic(str1);
OIC::Service::NSProviderService::getInstance()->registerTopic(str2);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
bool isSame = false;
auto topicList =
OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList();
- if (!topicList)
+
+ std::string compStr[10];
+ int i = 0;
+ for (auto itr : topicList->getTopicsList())
{
- printf("topic is NULL\n");
- isSame = false;
+ compStr[i] = itr.getTopicName(); i++;
}
- else
+ std::cout << compStr << std::endl;
+ if (str1.compare(compStr[0]) == 0)
{
- auto topic = topicList->getTopicsList();
- auto it = topic.begin();
- std::string compStr = (*it).getTopicName() ;
- std::cout << compStr << std::endl;
- if (str1.compare(compStr) == 0 )
- {
- isSame = true;
- }
+ isSame = true;
}
+
EXPECT_EQ(isSame, true);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
- responseCon.wait_for(lock, g_waitForResponse);
}
TEST_F(NotificationProviderServiceTest, ExpectEqualSetConsumerTopicsAndGetConsumerTopics)
g_consumer->setTopic(str1);
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
bool isSame = false;
auto topicList = g_consumer->getConsumerTopicList();
- if (!topicList)
+ std::string compString[10];
+ int i = 0, state[10] = {0};
+ for (auto itr : topicList->getTopicsList())
{
- printf("topic is NULL\n");
- isSame = false;
+ compString[i] = itr.getTopicName();
+ state[i++] = (int) itr.getState();
}
- else
+ std::cout << compString[0] << std::endl;
+ std::cout << compString[1] << std::endl;
+ if (str1.compare(compString[0]) == 0 && str2.compare(compString[1]) == 0
+ && state[0] == 1 && state[1] == 0)
{
- std::string compString[10];
- int i = 0, state[10] = {0};
- for (auto itr : topicList->getTopicsList())
- {
- compString[i] = itr.getTopicName();
- state[i++] = (int) itr.getState();
- }
- std::cout << compString[0] << std::endl;
- std::cout << compString[1] << std::endl;
- if (str1.compare(compString[0]) == 0 && str2.compare(compString[1]) == 0
- && state[0] == 1 && state[1] == 0)
- {
- isSame = true;
- }
+ isSame = true;
}
+
EXPECT_EQ(isSame, true);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
- responseCon.wait_for(lock, g_waitForResponse);
+
}
TEST_F(NotificationProviderServiceTest, ExpectEqualUnSetConsumerTopicsAndGetConsumerTopics)
g_consumer->setTopic(str2);
g_consumer->unsetTopic(str1);
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
-
bool isSame = false;
auto topicList = g_consumer->getConsumerTopicList();
- if (!topicList)
+ std::string compString[10];
+ int i = 0, state[10] = {0};
+ for (auto itr : topicList->getTopicsList())
{
- printf("topic is NULL\n");
- isSame = false;
+ compString[i] = itr.getTopicName();
+ state[i++] = (int) itr.getState();
}
- else
+ std::cout << compString[0] << std::endl;
+ std::cout << compString[1] << std::endl;
+ if (str1.compare(compString[0]) == 0 && str2.compare(compString[1]) == 0
+ && state[0] == 0 && state[1] == 1)
{
- std::string compString[10];
- int i = 0, state[10] = {0};
- for (auto itr : topicList->getTopicsList())
- {
- compString[i] = itr.getTopicName();
- state[i++] = (int) itr.getState();
- }
- std::cout << compString[0] << std::endl;
- std::cout << compString[1] << std::endl;
- if (str1.compare(compString[0]) == 0 && str2.compare(compString[1]) == 0
- && state[0] == 0 && state[1] == 1)
- {
- isSame = true;
- }
+ isSame = true;
}
EXPECT_EQ(isSame, true);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
- responseCon.wait_for(lock, g_waitForResponse);
}
{
bool ret = g_consumerSimul.cancelObserves();
- std::unique_lock< std::mutex > lock { mutexForCondition };
- responseCon.wait_for(lock, g_waitForResponse);
+ std::this_thread::sleep_for(g_waitForResponse);
EXPECT_EQ(ret, true);
}
if env.get('WITH_TCP') == True:
notification_wrapper_test_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
- if env.get('SECURED') == '1':
- notification_wrapper_test_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
+if env.get('SECURED') == '1':
+ notification_wrapper_test_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
if target_os not in ['windows', 'winrt']:
notification_wrapper_test_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
if env.get('TEST') == '1':
if env.get('SECURED') != '1':
-# TODO: fix this test on linux and remove this comment line
- if target_os in []:
+# TODO: fix this test for MLK and remove this comment line
+ if target_os in ['linux'] and env.get('SECURED') != '1':
from tools.scons.RunTest import *
run_test(notification_consumer_wrapper_test_env,
'',