#******************************************************************
#
# Copyright 2014 Intel Mobile Communications GmbH 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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

import os
import os.path

# SConscript file for Local PKI google tests
gtest_env = SConscript('#extlibs/gtest/SConscript')
stacktest_env = gtest_env.Clone()
target_os = stacktest_env.get('TARGET_OS')

######################################################################
# Build flags
######################################################################
stacktest_env.PrependUnique(CPPPATH = [
		'../../security/include',
		'../../ocsocket/include',
		'../../logger/include',
		'../../../c_common/ocrandom/include',
		'../../stack/include',
		'../../stack/include/internal',
		'../../connectivity/api',
		'../../connectivity/inc/pkix',
		'../../connectivity/external/inc',
		'../../extlibs/cjson',
		'../../../oc_logger/include',
		])

stacktest_env.AppendUnique(LIBPATH = [stacktest_env.get('BUILD_DIR')])
stacktest_env.PrependUnique(LIBS = ['octbstack',
                                    'ocsrm',
                                    'connectivity_abstraction',
                                    'coap'])
if target_os != 'darwin':
    stacktest_env.PrependUnique(LIBS = ['oc_logger'])

if stacktest_env.get('SECURED') == '1':
	stacktest_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509','mbedcrypto'])

if stacktest_env.get('LOGGING'):
	stacktest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])

if target_os in ['msys_nt', 'windows']:
	stacktest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
	stacktest_env.AppendUnique(LIBS = ['ws2_32', 'iphlpapi', 'kernel32'])
else:
	stacktest_env.PrependUnique(LIBS = ['m'])

######################################################################
# Source files and Targets
######################################################################
stacktests = stacktest_env.Program('stacktests', ['stacktests.cpp'])
cbortests = stacktest_env.Program('cbortests', ['cbortests.cpp'])

Alias("test", [stacktests, cbortests])


stacktest_env.AppendTarget('test')
if stacktest_env.get('TEST') == '1':
	if target_os in ['windows']:
		stacktest_env.AppendENVPath('PATH', [os.path.join(stacktest_env.get('BUILD_DIR'), 'resource', 'csdk')])
	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')
