DiscoveryManagerTest is moved.
ResourceClientTest is modified to conform to the modified discovery manager.
Change-Id: I55b1fcfa00e4a606796f44ee4c84351dfaebc4c7
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2907
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
+++ /dev/null
-#******************************************************************
-#
-# Copyright 2015 Samsung Electronics All Rights Reserved.
-#
-#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-##
-# ResourceClient Unit Test build script
-##
-import os
-Import('env')
-
-if env.get('RELEASE'):
- env.AppendUnique(CCFLAGS = ['-Os'])
- env.AppendUnique(CPPDEFINES = ['NDEBUG'])
-else:
- env.AppendUnique(CCFLAGS = ['-g'])
-
-if env.get('LOGGING'):
- env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-
-# Add third party libraries
-lib_env = env.Clone()
-SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
-
-target_os = env.get('TARGET_OS')
-if target_os == 'linux':
- # Verify that 'google unit test' library is installed. If not,
- # get it and install it
- SConscript(env.get('SRC_DIR') + '/extlibs/gtest/SConscript')
-
- # Verify that 'hippomocks' mocking code is installed. If not,
- # get it and install it
- SConscript(env.get('SRC_DIR') + '/extlibs/hippomocks.scons')
-
-DiscoveryManager_gtest_env = lib_env.Clone()
-
-######################################################################
-#unit test setting
-######################################################################
-src_dir = lib_env.get('SRC_DIR')
-gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0'
-
-######################################################################
-# Build flags
-######################################################################
-gtest = File(gtest_dir + '/lib/.libs/libgtest.a')
-gtest_main = File(gtest_dir + '/lib/.libs/libgtest_main.a')
-
-DiscoveryManager_gtest_env.AppendUnique(
- CPPPATH = [
- src_dir + '/extlibs/hippomocks-master',
- src_dir + '/extlibs/gtest/gtest-1.7.0/include',
- '../../src/common/utils/include',
- '../../src/serverBuilder/include',
- '../../src/common/primitiveResource/include',
- '../../common/utils/include/',
- '../../../include/',
- '../../common/primitiveResource/include',
- '../../../../../resource/include',
- '../../common/expiryTimer/include'
- ])
-
-if target_os not in ['windows', 'winrt']:
- DiscoveryManager_gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
- if target_os != 'android':
- DiscoveryManager_gtest_env.AppendUnique(CXXFLAGS = ['-pthread'])
- DiscoveryManager_gtest_env.AppendUnique(LIBS = ['pthread'])
-
-DiscoveryManager_gtest_env.PrependUnique(LIBS = [
- 'rcs_client',
- 'rcs_server',
- 'rcs_common',
- 'oc',
- 'octbstack',
- 'oc_logger',
- 'oc_logger_core',
- 'connectivity_abstraction',
- gtest,
- gtest_main])
-
-DiscoveryManager_gtest_env.AppendUnique(LIBS = ['dl'])
-
-######################################################################
-# Build Test
-######################################################################
-DiscoveryManager_gtest_src = env.Glob('./*.cpp')
-
-DiscoveryManager_test = DiscoveryManager_gtest_env.Program('DiscoveryManagerTest', DiscoveryManager_gtest_src)
-Alias("DiscoveryManagerTest", DiscoveryManager_test)
-env.AppendTarget('DiscoveryManager_test')
-
-if env.get('TEST') == '1':
- target_os = env.get('TARGET_OS')
- if target_os == 'linux':
- from tools.scons.RunTest import *
- run_test(DiscoveryManager_gtest_env, '',
- 'service/resource-encapsulation/src/resourceClient/DiscoveryManagerTest')
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include <unistd.h>
-#include "OCPlatform.h"
+
#include "UnitTestHelper.h"
+
#include "RCSRemoteResourceObject.h"
#include "RCSDiscoveryManager.h"
#include "RCSResourceObject.h"
-#include "PrimitiveResource.h"
+#include "RCSAddress.h"
+
+#include "OCPlatform.h"
using namespace OIC::Service;
using namespace OC::OCPlatform;
constexpr char RESOURCEURI[]{ "/a/TemperatureSensor" };
-constexpr char RESOURCETYPE[]{ "Resource.Hosting" };
+constexpr char RESOURCETYPE[]{ "resource.type" };
constexpr char RESOURCEINTERFACE[]{ "oic.if.baseline" };
constexpr int DiscoveryTaskDELAYTIME = 7;
void startDiscovery()
{
const std::string uri = "/oic/res";
- const std::string type = "Resource.Hosting";
discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(),
- uri, type, &resourceDiscovered);
+ uri, RESOURCETYPE, &resourceDiscovered);
}
void cancelDiscovery()
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "UnitTestHelper.h"
+
#include "RCSRemoteResourceObject.h"
#include "RCSDiscoveryManager.h"
#include "RCSResourceObject.h"
-#include "PrimitiveResource.h"
-#include <condition_variable>
+#include "RCSAddress.h"
+#include <condition_variable>
#include <mutex>
using namespace OIC::Service;
using namespace OC;
constexpr char RESOURCEURI[]{ "/a/TemperatureSensor" };
-constexpr char RESOURCETYPE[]{ "Resource.Hosting" };
+constexpr char RESOURCETYPE[]{ "resource.type" };
constexpr char RESOURCEINTERFACE[]{ "oic.if.baseline" };
constexpr char ATTR_KEY[]{ "Temperature" };
public:
RCSResourceObject::Ptr server;
RCSRemoteResourceObject::Ptr object;
- std::shared_ptr< bool > finished;
public:
void Proceed()
{
TestWithMock::SetUp();
- finished = std::make_shared< bool >(false);
-
CreateResource();
WaitUntilDiscovered();
// This method is to make sure objects disposed.
WaitForPtrBeingUnique();
-
- *finished = true;
}
private:
server->setAttribute(ATTR_KEY, ATTR_VALUE);
}
- bool checkObject()
- {
- std::lock_guard<std::mutex> lock{ mutexForObject };
- return object == nullptr;
- }
-
void WaitUntilDiscovered()
{
- for (int i=0; i<10 && checkObject(); ++i)
+ for (int i=0; i<10 && !object; ++i)
{
const std::string uri = "/oic/res";
- const std::string type = "Resource.Hosting";
auto discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(
- RCSAddress::multicast(), uri, type, std::bind(resourceDiscovered, this, finished,
- std::placeholders::_1));
+ RCSAddress::multicast(), uri, RESOURCETYPE,
+ std::bind(&RemoteResourceObjectTest::resourceDiscovered, this,
+ std::placeholders::_1));
Wait(1000);
}
}
}
}
- // This callback is to protect crash from crashes caused by delayed callbacks
- static void resourceDiscovered(RemoteResourceObjectTest* test,
- std::shared_ptr< bool > finished, RCSRemoteResourceObject::Ptr resourceObject)
+ void resourceDiscovered(RCSRemoteResourceObject::Ptr resourceObject)
{
- if (*finished) return;
-
- {
- std::lock_guard< std::mutex > lock{ test->mutexForObject };
-
- if (test->object) return;
-
- test->object = resourceObject;
- }
+ object = resourceObject;
- test->Proceed();
+ Proceed();
}
private:
std::condition_variable cond;
std::mutex mutex;
- std::mutex mutexForObject;
};
TEST_F(RemoteResourceObjectTest, GetRemoteAttributesDoesNotAllowEmptyFunction)
Import('env')
if env.get('RELEASE'):
- env.AppendUnique(CCFLAGS = ['-Os'])
- env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+ env.AppendUnique(CCFLAGS = ['-Os'])
+ env.AppendUnique(CPPDEFINES = ['NDEBUG'])
else:
- env.AppendUnique(CCFLAGS = ['-g'])
+ env.AppendUnique(CCFLAGS = ['-g'])
if env.get('LOGGING'):
- env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+ env.AppendUnique(CPPDEFINES = ['TB_LOG'])
# Add third party libraries
lib_env = env.Clone()
target_os = env.get('TARGET_OS')
if target_os == 'linux':
- # Verify that 'google unit test' library is installed. If not,
- # get it and install it
- SConscript(env.get('SRC_DIR') + '/extlibs/gtest/SConscript')
+ # Verify that 'google unit test' library is installed. If not,
+ # get it and install it
+ SConscript(env.get('SRC_DIR') + '/extlibs/gtest/SConscript')
- # Verify that 'hippomocks' mocking code is installed. If not,
- # get it and install it
- SConscript(env.get('SRC_DIR') + '/extlibs/hippomocks.scons')
+ # Verify that 'hippomocks' mocking code is installed. If not,
+ # get it and install it
+ SConscript(env.get('SRC_DIR') + '/extlibs/hippomocks.scons')
-ResourceClient_gtest_env = lib_env.Clone()
+rcs_test_env = lib_env.Clone()
######################################################################
#unit test setting
gtest = File(gtest_dir + '/lib/.libs/libgtest.a')
gtest_main = File(gtest_dir + '/lib/.libs/libgtest_main.a')
-ResourceClient_gtest_env.AppendUnique(
+rcs_test_env.AppendUnique(
CPPPATH = [
src_dir + '/extlibs/hippomocks-master',
src_dir + '/extlibs/gtest/gtest-1.7.0/include',
'../include',
'../src/common/utils/include',
- '../src/serverBuilder/include',
- '../src/common/primitiveResource/include',
- '../src/common/include/expiryTimer'
])
if target_os not in ['windows', 'winrt']:
- ResourceClient_gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
+ rcs_test_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
if target_os != 'android':
- ResourceClient_gtest_env.AppendUnique(CXXFLAGS = ['-pthread'])
- ResourceClient_gtest_env.AppendUnique(LIBS = ['pthread'])
+ rcs_test_env.AppendUnique(CXXFLAGS = ['-pthread'])
+ rcs_test_env.AppendUnique(LIBS = ['pthread'])
-ResourceClient_gtest_env.PrependUnique(LIBS = [
+rcs_test_env.PrependUnique(LIBS = [
'rcs_client',
'rcs_server',
'rcs_common',
gtest,
gtest_main])
-ResourceClient_gtest_env.AppendUnique(LIBS = ['dl'])
+rcs_test_env.AppendUnique(LIBS = ['dl'])
######################################################################
# Build Test
######################################################################
-ResourceClient_gtest_src = env.Glob('./*.cpp')
+rcs_test_src = env.Glob('./*.cpp')
-ResourceClient_test = ResourceClient_gtest_env.Program('ResourceClientTest', ResourceClient_gtest_src)
-Alias("ResourceClientTest", ResourceClient_test)
-env.AppendTarget('ResourceClient_test')
+rcs_client_test = rcs_test_env.Program('rcs_client_test', rcs_test_src)
+Alias("rcs_client_test", rcs_client_test)
+env.AppendTarget('rcs_client_test')
if env.get('TEST') == '1':
target_os = env.get('TARGET_OS')
if target_os == 'linux':
from tools.scons.RunTest import *
- run_test(ResourceClient_gtest_env, '',
- 'service/resource-encapsulation/unittests/ResourceClientTest')
\ No newline at end of file
+ run_test(rcs_test_env, '', 'service/resource-encapsulation/unittests/rcs_client_test')
\ No newline at end of file