First batch of refactoring changes to remove /W4 compiler warnings.
For now I'm starting with resource/c_common and adding
_CRT_SECURE_NO_WARNINGS to disable warnings about issues we cannot
change anyway, because the code has to build for multiple platforms.
Change-Id: I03d088f8a7c3263ea994fe075fbb579a14e31f0c
Signed-off-by: Pawel Winogrodzki <pawelwi@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15725
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+# Add MinGW-specific libraries
+env.AppendUnique(LIBS = ['bcrypt', 'ws2_32', 'advapi32', 'iphlpapi', 'crypt32', 'kernel32'])
+
target_arch = env.get('TARGET_ARCH')
if env['CC'] == 'gcc':
env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
env.AppendUnique(PATH = os.environ['PATH'])
+ # Add Windows-specific libraries
+ env.AppendUnique(LIBS = ['bcrypt', 'ws2_32', 'advapi32', 'iphlpapi', 'crypt32', 'kernel32'])
+
+ # Visual Studio compiler complains that functions like strncpy are unsafe. We
+ # are aware that it's possible to create a non-null terminated string using the
+ # strncpy function. However, the str*_s functions are not standard and thus
+ # will not work on all systems supported by IoTivity. This will prevent Visual
+ # Studio from displaying unwanted warnings.
+ # See https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx for more details.
+ env.AppendUnique(CPPDEFINES=['_CRT_SECURE_NO_WARNINGS', '_CRT_NONSTDC_NO_WARNINGS'])
+
elif env['CC'] == 'gcc':
print "\nError: gcc not supported on Windows. Use Visual Studio!\n"
Exit(1);
samples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
samples_env.PrependUnique(LIBS = ['tinydtls'])
- if target_os in ['windows', 'msys_nt']:
- samples_env.AppendUnique(LIBS = ['ws2_32', 'iphlpapi', 'advapi32', 'bcrypt'])
-
Alias("samples", [dtlsserver, dtlsclient])
samples_env.AppendTarget('samples')
######################################################################
-######################################################################
-# Add platform-specific helper library
-######################################################################
-
-if target_os in ['windows', 'msys_nt']:
- SConscript('windows/SConscript')
-
env.AppendUnique(CPPPATH = [
os.path.join(Dir('.').abspath, 'oic_malloc', 'include'),
os.path.join(Dir('.').abspath, 'oic_string', 'include'),
common_env = env.Clone()
######################################################################
+# Enable treating all warnings as errors
+######################################################################
+
+if target_os in ['windows', 'msys_nt']:
+ common_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
+
+######################################################################
+# Add platform-specific helper library
+######################################################################
+
+if target_os in ['windows', 'msys_nt']:
+ SConscript('windows/SConscript', 'common_env')
+
+######################################################################
# Source files and Targets
######################################################################
common_src = [
import os
import os.path
+from tools.scons.RunTest import *
+
+Import('test_env')
# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-randomtest_env = gtest_env.Clone()
+randomtest_env = test_env.Clone()
target_os = randomtest_env.get('TARGET_OS')
######################################################################
randomtest_env.AppendTarget('test')
if randomtest_env.get('TEST') == '1':
if target_os in ['linux', 'windows']:
- from tools.scons.RunTest import *
run_test(randomtest_env,
'resource_csdk_random_test.memcheck',
'resource/c_common/ocrandom/test/randomtests')
import os
import os.path
+from tools.scons.RunTest import *
+
+Import('test_env')
# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-malloctest_env = gtest_env.Clone()
+malloctest_env = test_env.Clone()
target_os = malloctest_env.get('TARGET_OS')
######################################################################
malloctest_env.AppendTarget('test')
if malloctest_env.get('TEST') == '1':
if target_os in ['linux', 'windows']:
- from tools.scons.RunTest import *
run_test(malloctest_env,
'resource_ccommon_malloc_test.memcheck',
'resource/c_common/oic_malloc/test/malloctests')
#include <unistd.h>
#endif
#include <stdlib.h>
-#include <stdint.h>
//-----------------------------------------------------------------------------
// Includes
using namespace std;
//-----------------------------------------------------------------------------
-// Private variables
-//-----------------------------------------------------------------------------
-static uint8_t *pBuffer;
-
-//-----------------------------------------------------------------------------
// Tests
//-----------------------------------------------------------------------------
-TEST(OICMalloc, MallocPass1)
+struct OICCallocParams
{
- // Try to allocate a small buffer
- pBuffer = (uint8_t *)OICMalloc(1);
- EXPECT_TRUE(pBuffer);
- OICFree(pBuffer);
-}
+ OICCallocParams(size_t elementsCount, size_t allocatedSize) :
+ m_elementsCount(elementsCount),
+ m_allocatedSize(allocatedSize)
+ {}
-TEST(OICMalloc, MallocPass2)
-{
- // Try to allocate a small buffer
- pBuffer = (uint8_t *)OICMalloc(128);
- EXPECT_TRUE(pBuffer);
- OICFree(pBuffer);
-}
-
-TEST(OICMalloc, MallocFail1)
-{
- // Try to allocate a buffer of size 0
- pBuffer = (uint8_t *)OICMalloc(0);
- EXPECT_TRUE(NULL == pBuffer);
- OICFree(pBuffer);
-}
-
-TEST(OICMalloc, MallocFail2)
-{
- // Try to allocate a ridiculous amount of RAM
- pBuffer = (uint8_t *)OICMalloc((size_t)0x7FFFFFFFFFFFFFFF);
- EXPECT_TRUE(NULL == pBuffer);
- OICFree(pBuffer);
-}
+ size_t m_elementsCount;
+ size_t m_allocatedSize;
+};
-TEST(OICCalloc, CallocPass1)
+class OICAllocTestsBase : public testing::Test
{
- // Try to allocate a small buffer
- pBuffer = (uint8_t *)OICCalloc(1, 1);
- EXPECT_TRUE(pBuffer);
- OICFree(pBuffer);
-}
-
-TEST(OICCalloc, CallocPass2)
+public:
+ OICAllocTestsBase() :
+ m_pBuffer(NULL)
+ {}
+
+ virtual void TearDown()
+ {
+ OICFree(m_pBuffer);
+ }
+
+protected:
+ size_t m_allocatedSize;
+ uint8_t* m_pBuffer;
+};
+
+class OICMallocPassTests : public OICAllocTestsBase,
+ public testing::WithParamInterface<size_t>
{
- // Try to allocate a small buffer
- pBuffer = (uint8_t *)OICCalloc(1, 128);
- EXPECT_TRUE(pBuffer);
- OICFree(pBuffer);
-}
-
-TEST(OICCalloc, CallocPass3)
+public:
+ virtual void SetUp()
+ {
+ m_allocatedSize = GetParam();
+ }
+};
+
+class OICMallocFailTests : public OICMallocPassTests
+{};
+
+class OICCallocPassTests : public OICAllocTestsBase,
+ public testing::WithParamInterface<OICCallocParams>
{
- // Try to allocate a buffer for an array
- pBuffer = (uint8_t *)OICCalloc(5, 128);
- EXPECT_TRUE(pBuffer);
- OICFree(pBuffer);
-}
-
-TEST(OICCalloc, CallocFail1)
+public:
+ virtual void SetUp()
+ {
+ m_allocatedSize = GetParam().m_allocatedSize;
+ m_elementsCount = GetParam().m_elementsCount;
+ }
+
+protected:
+ size_t m_elementsCount;
+};
+
+class OICCallocFailTests : public OICCallocPassTests
+{};
+
+INSTANTIATE_TEST_CASE_P(OICMallocPassTests,
+ OICMallocPassTests,
+ ::testing::Values(1,
+ 128));
+TEST_P(OICMallocPassTests, shouldPassOICMalloc)
{
- // Try to allocate a buffer of size 0
- pBuffer = (uint8_t *)OICCalloc(1, 0);
- EXPECT_TRUE(NULL == pBuffer);
- OICFree(pBuffer);
+ m_pBuffer = (uint8_t*)OICMalloc(m_allocatedSize);
+ EXPECT_NE((decltype(m_pBuffer))NULL, m_pBuffer);
}
-TEST(OICCalloc, CallocFail2)
+INSTANTIATE_TEST_CASE_P(OICMallocFailTests,
+ OICMallocFailTests,
+ ::testing::Values(0,
+ SIZE_MAX,
+ SIZE_MAX - 1,
+ SIZE_MAX - 2,
+ SIZE_MAX - 8));
+TEST_P(OICMallocFailTests, shouldFailOICMalloc)
{
- // Try to allocate a buffer with num of 0
- pBuffer = (uint8_t *)OICCalloc(0, 5);
- EXPECT_TRUE(NULL == pBuffer);
- OICFree(pBuffer);
+ m_pBuffer = (uint8_t *)OICMalloc(0);
+ EXPECT_EQ((decltype(m_pBuffer))NULL, m_pBuffer);
}
-TEST(OICCalloc, CallocFail3)
+INSTANTIATE_TEST_CASE_P(OICCallocPassTests,
+ OICCallocPassTests,
+ ::testing::Values(OICCallocParams(1, 1),
+ OICCallocParams(1, 128),
+ OICCallocParams(5, 128)));
+TEST_P(OICCallocPassTests, shouldPassOICCalloc)
{
- // Try to allocate a buffer with size and num 0
- pBuffer = (uint8_t *)OICCalloc(0, 0);
- EXPECT_TRUE(NULL == pBuffer);
- OICFree(pBuffer);
+ m_pBuffer = (uint8_t *)OICCalloc(m_elementsCount, m_allocatedSize);
+ EXPECT_NE((decltype(m_pBuffer))NULL, m_pBuffer);
}
-TEST(OICCalloc, CallocFail4)
+INSTANTIATE_TEST_CASE_P(OICCallocFailTests,
+ OICCallocFailTests,
+ ::testing::Values(OICCallocParams(1, 0),
+ OICCallocParams(0, 5),
+ OICCallocParams(0, 0),
+ OICCallocParams(1, SIZE_MAX),
+ OICCallocParams(1, SIZE_MAX - 1),
+ OICCallocParams(1, SIZE_MAX - 2),
+ OICCallocParams(1, SIZE_MAX - 8),
+ OICCallocParams(SIZE_MAX, 1),
+ OICCallocParams(SIZE_MAX - 1, 1),
+ OICCallocParams(SIZE_MAX - 2, 1),
+ OICCallocParams(SIZE_MAX - 8, 1)));
+TEST_P(OICCallocFailTests, shouldFailOICCalloc)
{
- // Try to allocate a ridiculous amount of RAM
- pBuffer = (uint8_t *)OICCalloc(1, (size_t)0x7FFFFFFFFFFFFFFF);
- EXPECT_TRUE(NULL == pBuffer);
- OICFree(pBuffer);
+ m_pBuffer = (uint8_t *)OICCalloc(m_elementsCount, m_allocatedSize);
+ EXPECT_EQ((decltype(m_pBuffer))NULL, m_pBuffer);
}
TEST(OICFreeAndSetToNull, FreeAndSetToNullPass1)
void OICStringToLower(char* str);
/**
- * Copies a C string into destination buffer. Ensures that the destination
+ * Copies a C string into destination buffer. Ensures that the destination
* is null terminated.
*
* @param dest Destination C buffer.
import os
import os.path
+from tools.scons.RunTest import *
+
+Import('test_env')
# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-stringtest_env = gtest_env.Clone()
+stringtest_env = test_env.Clone()
target_os = stringtest_env.get('TARGET_OS')
######################################################################
stringtest_env.AppendTarget('test')
if stringtest_env.get('TEST') == '1':
if target_os in ['linux', 'windows']:
- from tools.scons.RunTest import *
run_test(stringtest_env,
'resource_ccommon_string_test.memcheck',
'resource/c_common/oic_string/test/stringtests')
#include <oic_malloc.h>
const char SENTINEL_VALUE = 127;
+static const char SENTINEL_CHAR = '?';
+
TEST(StringTests, StrdupNormalDup)
{
char param[] = "This is a normal parameter";
// tests a copy where the destination is of length 0
TEST(StringTests, StrcpyZeroDestination)
{
- char target[1] = { (char)0xde };
+ char target[1] = { SENTINEL_CHAR };
char source[] = "123456789";
char beforeValue = target[0];
// Tests a cat where the Destination is zero length
TEST(StringTests, StrcatZeroDestination)
{
- char target[1] = { (char)0xde };
+ char target[1] = { SENTINEL_CHAR };
char source[] = "12345";
char beforeValue = target[0];
import os
import os.path
+from tools.scons.RunTest import *
+
+Import('test_env')
# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-timetest_env = gtest_env.Clone()
+timetest_env = test_env.Clone()
target_os = timetest_env.get('TARGET_OS')
######################################################################
timetest_env.AppendTarget('test')
if timetest_env.get('TEST') == '1':
if target_os in ['linux', 'windows']:
- from tools.scons.RunTest import *
run_test(timetest_env,
'resource_ccommon_time_test.memcheck',
'resource/c_common/oic_time/test/timetests')
--- /dev/null
+#******************************************************************
+#
+# Copyright 2016 Microsoft
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# Script for building unit tests and libs.
+##
+
+Import('test_env')
+
+common_test_env = test_env.Clone()
+target_os = common_test_env.get('TARGET_OS')
+
+# Enable treating all warnings as errors for Windows.
+if target_os in ['windows', 'msys_nt']:
+ common_test_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
+
+SConscript('../oic_string/test/SConscript', exports = { 'test_env' : common_test_env})
+SConscript('../oic_malloc/test/SConscript', exports = { 'test_env' : common_test_env})
+SConscript('../oic_time/test/SConscript', exports = { 'test_env' : common_test_env})
+SConscript('../ocrandom/test/SConscript', exports = { 'test_env' : common_test_env})
+if target_os == 'windows':
+ SConscript('../windows/test/SConscript', 'test_env')
##
# Builds Windows-specific helper library
##
-Import('env')
+Import('env common_env')
import os.path
# Include any headers that might be missing on Windows
-env.AppendUnique(CPPPATH = [os.path.abspath('./include')])
+header = os.path.abspath('./include')
+env.AppendUnique(CPPPATH = [header])
+common_env.AppendUnique(CPPPATH = [header])
######################################################################
# Source files and Targets
os.path.join(src_dir, 'pthread_create.c')
]
-win_helper_env = env.Clone()
+win_helper_env = common_env.Clone()
win_helper_env.AppendUnique(CPPPATH = ['#resource/csdk/logger/include'])
static_libwinhelper = win_helper_env.StaticLibrary('win_helper', helper_src)
win_helper_env.UserInstallTargetHeader('include/pthread_create.h', 'c_common/windows/include', 'pthread_create.h')
win_helper_env.UserInstallTargetHeader('include/vs12_snprintf.h', 'c_common/windows/include', 'vs12_snprintf.h')
-env.AppendUnique(LIBS = ['win_helper', 'bcrypt'])
-
+helper_lib = ['win_helper']
+env.AppendUnique(LIBS = helper_lib)
+common_env.AppendUnique(LIBS = helper_lib)
void *(*start_routine)(void *),
void *arg)
{
+ UNREFERENCED_PARAMETER(attr);
*thread = CreateThread(NULL, 0, (PTHREAD_START_ROUTINE)start_routine, arg, 0, NULL);
return (*thread == NULL) ? GetLastError() : 0;
}
int vs12_snprintf(char *buffer, size_t count, const char *format, ...)
{
- // These three values are invalid when calling _vsnprintf
- if ((buffer == NULL) || (count == 0) || (format == NULL))
+ // The first three values are invalid when calling _vsnprintf.
+ // Last check is to make sure the buffer is small enough for the
+ // return value to make sense.
+ if ((buffer == NULL) ||
+ (count == 0) ||
+ (format == NULL) ||
+ (count > INT_MAX))
{
return -1;
}
int length = _vsnprintf(buffer, count, format, args);
va_end(args);
- if ((length == -1) || (length == count))
+ if ((length == -1) || (length == (int)count))
{
// Add the missing zero character terminator.
buffer[count - 1] = '\0';
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
import os.path
+from tools.scons.RunTest import *
-######################################################################
-# Build the gtest framework
-######################################################################
-gtest_env = SConscript('#extlibs/gtest/SConscript')
+Import('test_env')
-c_common_windows_test_env = gtest_env.Clone()
+c_common_windows_test_env = test_env.Clone()
######################################################################
# Build flags
c_common_windows_test_env.AppendTarget('test')
-from tools.scons.RunTest import *
-run_test(c_common_windows_test_env,
- 'resource_c_common_windows_test.memcheck',
- 'resource/c_common/windows/test/c_common_windows_tests')
+if c_common_windows_test_env.get('TEST') == '1':
+ run_test(c_common_windows_test_env,
+ 'resource_c_common_windows_test.memcheck',
+ 'resource/c_common/windows/test/c_common_windows_tests')
liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_product.def'), File('octbstack_product_secured.def')])
else:
liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_product.def')])
-
- liboctbstack_env.AppendUnique(LIBS = ['ws2_32', 'advapi32', 'iphlpapi', 'bcrypt', 'crypt32'])
else:
liboctbstack_env.AppendUnique(LIBS = ['m'])
import os
import os.path
+from tools.scons.RunTest import *
+
+Import('test_env')
# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-catest_env = gtest_env.Clone()
+catest_env = test_env.Clone()
target_os = catest_env.get('TARGET_OS')
target_transport = catest_env.get('TARGET_TRANSPORT')
rd_mode = catest_env.get('RD_MODE')
if catest_env.get('LOGGING'):
catest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-if target_os in ['msys_nt', 'windows']:
- catest_env.AppendUnique(LIBS = ['ws2_32',
- 'advapi32',
- 'bcrypt',
- 'iphlpapi'])
-else:
+if target_os not in ['msys_nt', 'windows']:
catest_env.AppendUnique(LIBS = ['m'])
######################################################################
if catest_env.get('TEST') == '1' and catest_env.get('SECURED') != '1':
if target_os in ['linux', 'windows']:
catest_env.AppendENVPath('PATH', catest_env.get('BUILD_DIR'))
- from tools.scons.RunTest import *
run_test(catest_env,
'resource_csdk_connectivity_test.memcheck',
'resource/csdk/connectivity/test/catests')
import os.path
from tools.scons.RunTest import run_test
+Import('test_env')
+
# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-sptest_env = gtest_env.Clone()
+sptest_env = test_env.Clone()
src_dir = sptest_env.get('SRC_DIR')
target_os = sptest_env.get('TARGET_OS')
rd_mode = sptest_env.get('RD_MODE')
sptest_env.AppendUnique(CPPDEFINES=['MULTIPLE_OWNER'])
if target_os in ['msys_nt', 'windows']:
- sptest_env.AppendUnique(LIBS = ['ws2_32',
- 'advapi32',
- 'bcrypt',
- 'crypt32',
- 'octbstack_static',
- 'iphlpapi'])
+ sptest_env.AppendUnique(LIBS = ['octbstack_static'])
else:
sptest_env.AppendUnique(LIBS = ['octbstack'])
if target_os in ['msys_nt', 'windows']:
# octbstack.dll doesn't export all the functions called by this app, so use static LIBs instead.
- tools_env.AppendUnique(LIBS = ['ws2_32', 'bcrypt', 'iphlpapi', 'crypt32',
- 'coap', 'tinydtls', 'mbedtls', 'mbedx509', 'mbedcrypto',
+ tools_env.AppendUnique(LIBS = ['coap', 'tinydtls', 'mbedtls', 'mbedx509', 'mbedcrypto',
'octbstack_static', 'ocsrm', 'connectivity_abstraction'])
elif target_os in ['darwin']:
tools_env.AppendUnique(LIBS = ['coap', 'tinydtls', 'mbedtls', 'mbedx509', 'mbedcrypto',
import os
import os.path
+from tools.scons.RunTest import *
+
+Import('test_env')
# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-srmtest_env = gtest_env.Clone()
+srmtest_env = test_env.Clone()
src_dir = srmtest_env.get('SRC_DIR')
target_os = srmtest_env.get('TARGET_OS')
rd_mode = srmtest_env.get('RD_MODE')
if target_os == 'windows':
srmtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
- srmtest_env.AppendUnique(LIBS = ['advapi32', 'bcrypt', 'crypt32', 'kernel32', 'ws2_32', 'iphlpapi', 'octbstack_static'])
+ srmtest_env.AppendUnique(LIBS = ['octbstack_static'])
else:
# TODO: Implement feature check.
srmtest_env.AppendUnique(CPPDEFINES = ['HAVE_LOCALTIME_R'])
os.makedirs(result_dir)
srmtest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
srmtest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
- from tools.scons.RunTest import *
run_test(srmtest_env,'ut','resource/csdk/security/unittest/unittest')
#include <string.h>
#include "cainterface.h"
- #define VERIFY_NON_NULL(arg) { if (!arg) {OIC_LOG(FATAL, TAG, #arg " is NULL"); goto exit;} }
- #define VERIFY_GT_ZERO(arg) { if (arg < 1) {OIC_LOG(FATAL, TAG, #arg " < 1"); goto exit;} }
- #define TAG "OIC_RI_ENDPOINT"
+#define VERIFY_NON_NULL(arg) { if (!arg) {OIC_LOG(FATAL, TAG, #arg " is NULL"); goto exit;} }
+#define VERIFY_GT_ZERO(arg) { if (arg < 1) {OIC_LOG(FATAL, TAG, #arg " < 1"); goto exit;} }
+#define VERIFY_GT(arg1, arg2) { if (arg1 <= arg2) {OIC_LOG(FATAL, TAG, #arg1 " <= " #arg2); goto exit;} }
+#define TAG "OIC_RI_ENDPOINT"
OCStackResult OCGetSupportedEndpointFlags(const OCTpsSchemeFlags givenFlags, OCTpsSchemeFlags* out)
{
}
char* tmp = NULL;
- char* ret = NULL;
+ void* ret = NULL;
char* tps = NULL;
char* addr = NULL;
char* origin = NULL;
char* tokPos = NULL;
+ size_t tpsCharsToWrite = 0;
+ size_t addrCharsToWrite = 0;
OCStackResult isEnabledAdapter = OC_STACK_ADAPTER_NOT_ENABLED;
OCTransportAdapter parsedAdapter = OC_DEFAULT_ADAPTER;
VERIFY_NON_NULL(tokPos);
// copy tps
- VERIFY_GT_ZERO(tokPos - origin);
- ret = strncpy(tps, origin, tokPos - origin);
+ tpsCharsToWrite = tokPos - origin;
+ VERIFY_GT_ZERO(tpsCharsToWrite);
+ VERIFY_GT((size_t)OC_MAX_TPS_STR_SIZE, tpsCharsToWrite);
+ ret = memcpy(tps, origin, tpsCharsToWrite);
VERIFY_NON_NULL(ret);
OIC_LOG_V(INFO, TAG, "parsed tps is:%s", tps);
out->family = OC_IP_USE_V6;
tokPos = tokPos + 4;
tmp = strrchr(origin, OC_ENDPOINT_BRACKET_END);
- VERIFY_NON_NULL(tmp);
}
else
{
out->family = OC_IP_USE_V4;
tokPos = tokPos + 3;
tmp = strrchr(origin, OC_ENDPOINT_ADDR_TOKEN);
- VERIFY_NON_NULL(tmp);
}
+ VERIFY_NON_NULL(tmp);
// copy addr
- VERIFY_GT_ZERO(tmp - tokPos);
- ret = strncpy(addr, tokPos, tmp - tokPos);
+ addrCharsToWrite = tmp - tokPos;
+ VERIFY_GT_ZERO(addrCharsToWrite);
+ VERIFY_GT((size_t)OC_MAX_ADDR_STR_SIZE, addrCharsToWrite);
+ ret = memcpy(addr, tokPos, addrCharsToWrite);
VERIFY_NON_NULL(ret);
OIC_LOG_V(INFO, TAG, "parsed addr is:%s", addr);
import os
import os.path
+from tools.scons.RunTest import *
+
+Import('test_env')
# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-stacktest_env = gtest_env.Clone()
+stacktest_env = test_env.Clone()
target_os = stacktest_env.get('TARGET_OS')
rd_mode = stacktest_env.get('RD_MODE')
if stacktest_env.get('LOGGING'):
stacktest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-if target_os in ['msys_nt', 'windows']:
- stacktest_env.AppendUnique(LIBS = ['ws2_32', 'iphlpapi', 'kernel32', 'bcrypt', 'advapi32', 'crypt32'])
-else:
+if target_os not in ['msys_nt', 'windows']:
stacktest_env.PrependUnique(LIBS = ['m'])
if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
# TODO: fix test in all supported configurations
if stacktest_env.get('TEST') == '1' and stacktest_env.get('SECURED') != '1':
if target_os in ['linux', 'windows']:
- from tools.scons.RunTest import *
run_test(stacktest_env,
'resource_csdk_stack_test.memcheck',
'resource/csdk/stack/test/stacktests')
--- /dev/null
+#******************************************************************
+#
+# Copyright 2016 Microsoft
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# Script for building unit tests and libs.
+##
+
+Import('test_env')
+
+target_os = test_env.get('TARGET_OS')
+
+SConscript('../stack/test/SConscript', 'test_env')
+SConscript('../connectivity/test/SConscript', 'test_env')
+
+# Build Security Resource Manager and Provisioning API unit test
+if (target_os in ['linux', 'windows']) and (test_env.get('SECURED') == '1'):
+ SConscript('../security/unittest/SConscript', 'test_env')
+ SConscript('../security/provisioning/unittest/SConscript', 'test_env')
import os.path
from tools.scons.RunTest import run_test
+Import('test_env')
+
# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-provisiontests_env = gtest_env.Clone()
+provisiontests_env = test_env.Clone()
src_dir = provisiontests_env.get('SRC_DIR')
target_os = provisiontests_env.get('TARGET_OS')
with_ra = provisiontests_env.get('WITH_RA')
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
##
-# 'unit_test' script for building unit tests and libs
+# 'unit_tests' script for building unit tests and libs
#
##
Import('env')
target_os = env.get('TARGET_OS')
-src_dir = env.get('SRC_DIR')
-build_dir = env.get('BUILD_DIR')
-if target_os in ['linux', 'windows']:
- # Verify that 'google unit test' library is installed. If not,
- # get it and install it
- SConscript('#extlibs/gtest/SConscript')
+if target_os in ['linux', 'windows', 'darwin', 'msys_nt']:
+ # Verify that 'google unit test' library is installed. If not,
+ # get it and install it
+ test_env = SConscript('#extlibs/gtest/SConscript')
- # Verify that 'hippomocks' mocking code is installed. If not,
- # get it and install it
- SConscript('#extlibs/hippomocks.scons')
+ if target_os in ['linux', 'windows']:
+ # Verify that 'hippomocks' mocking code is installed. If not,
+ # get it and install it
+ SConscript('#extlibs/hippomocks.scons')
- # Build Common unit tests
- SConscript('c_common/oic_string/test/SConscript')
- SConscript('c_common/oic_malloc/test/SConscript')
- SConscript('c_common/oic_time/test/SConscript')
- SConscript('c_common/ocrandom/test/SConscript')
- if target_os == 'windows':
- SConscript('c_common/windows/test/SConscript')
+ # Build Common unit tests
+ SConscript('c_common/unittests/SConscript', 'test_env')
- # Build C unit tests
- SConscript('csdk/stack/test/SConscript')
+ # Build C++ unit tests
+ SConscript('unittests/SConscript', 'test_env')
- SConscript('csdk/connectivity/test/SConscript')
+ # Build Security Resource Manager and Provisioning API unit test
+ # TODO: Enable provisioning and associated unit tests for Windows
+ if (env.get('SECURED') == '1') and (target_os != 'windows'):
+ SConscript('provisioning/unittests/SConscript', 'test_env')
- # Build Security Resource Manager unit tests
- if env.get('SECURED') == '1':
- SConscript('csdk/security/unittest/SConscript')
-
- # Build C++ unit tests
- SConscript('unittests/SConscript')
-
- # Build Provisioning API unit test
- if env.get('SECURED') == '1':
- SConscript('csdk/security/provisioning/unittest/SConscript')
- # TODO: Enable provisioning and associated unit tests for Windows
- if target_os != 'windows':
- SConscript('provisioning/unittests/SConscript')
-
-elif target_os in ['darwin', 'msys_nt']:
- # Verify that 'google unit test' library is installed. If not,
- # get it and install it
- SConscript('#extlibs/gtest/SConscript')
-
- # Build C stack's unit tests.
- SConscript('csdk/stack/test/SConscript')
- SConscript('csdk/connectivity/test/SConscript')
+ # Build C unit tests
+ SConscript('csdk/unittests/SConscript', 'test_env')
import os
import os.path
+from tools.scons.RunTest import *
+
+Import('test_env')
# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-unittests_env = gtest_env.Clone()
+unittests_env = test_env.Clone()
src_dir = unittests_env.get('SRC_DIR')
target_os = unittests_env.get('TARGET_OS')
with_mq = unittests_env.get('WITH_MQ')
])
if target_os in ['windows']:
- unittests_env.AppendUnique(LIBS = ['ws2_32', 'advapi32', 'iphlpapi', 'bcrypt', 'crypt32'])
unittests_env.AppendUnique(CPPPATH = ['#extlibs/boost/boost'])
# On Windows, octbstack_test is a static LIB, that makes calls into static LIB ocsrm.
# On other platforms, octbstack_test is a shared LIB, that includes static LIB ocsrm.
if target_os in ['windows']:
unittests_env.AppendENVPath('PATH', unittests_env.get('BUILD_DIR'))
if target_os in ['linux', 'windows']:
- from tools.scons.RunTest import *
run_test(unittests_env,
'resource_unittests_unittests.memcheck',
'resource/unittests/unittests')