#******************************************************************
#
# 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
from tools.scons.RunTest import *

Import('test_env')

# SConscript file for Local PKI google tests
stacktest_env = test_env.Clone()
target_os = stacktest_env.get('TARGET_OS')
rd_mode = stacktest_env.get('RD_MODE')

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

stacktest_env.PrependUnique(LIBS = ['octbstack_internal',
                                    'ocsrm',
                                    'routingmanager',
                                    'connectivity_abstraction_internal',
                                    'coap',
                                    ])

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

# c_common calls into mbedcrypto.
stacktest_env.AppendUnique(LIBS = ['mbedcrypto'])

if 'CLIENT' in rd_mode and target_os not in ['arduino', 'darwin', 'ios', 'windows', 'winrt']:
    stacktest_env.PrependUnique(LIBS = ['oc', 'oc_logger'])
if 'SERVER' in rd_mode:
    if target_os in ['linux', 'tizen']:
        stacktest_env.ParseConfig('pkg-config --cflags --libs sqlite3')
    elif target_os in ['msys_nt', 'windows']:
        stacktest_env.PrependUnique(LIBS = ['sqlite3'])

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

if target_os in ['msys_nt', 'windows']:
    stacktest_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
else:
    stacktest_env.PrependUnique(LIBS = ['m'])
    if target_os in ['tizen', 'linux']:
        stacktest_env.ParseConfig("pkg-config --cflags --libs gobject-2.0 gio-2.0 glib-2.0")

######################################################################
# 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 ['linux', 'windows']:
                run_test(stacktest_env,
                         'resource_csdk_stack_test.memcheck',
                         'resource/csdk/stack/test/stacktests')
                run_test(stacktest_env,
                         'resource_csdk_stack_test.memcheck',
                         'resource/csdk/stack/test/cbortests')
