e6d27be4cc904d0c62ab5a96756b5fa58ec609a3
[platform/upstream/iotivity.git] / resource / unittests / SConscript
1 #******************************************************************
2 #
3 # Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 #
5 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 import os
22 import os.path
23 from tools.scons.RunTest import *
24
25 Import('test_env')
26
27 # SConscript file for Local PKI google tests
28 unittests_env = test_env.Clone()
29 src_dir = unittests_env.get('SRC_DIR')
30 target_os = unittests_env.get('TARGET_OS')
31 with_mq = unittests_env.get('WITH_MQ')
32
33 ######################################################################
34 # Build flags
35 ######################################################################
36 unittests_env.PrependUnique(CPPPATH = [
37                 '../include',
38                 '../oc_logger/include',
39                 '../csdk/include',
40                 '../csdk/stack/include',
41                 '../csdk/security/include',
42                 '../csdk/stack/include/internal',
43                 '../csdk/connectivity/api',
44                 '../csdk/connectivity/external/inc',
45                 '../csdk/ocsocket/include',
46                 '../c_common/ocrandom/include',
47                 '../csdk/logger/include',
48                 '#extlibs/hippomocks-master/HippoMocks',
49                 '#extlibs/hippomocks-master/HippoMocksTest'
50                 ])
51
52 if target_os in ['windows']:
53         unittests_env.AppendUnique(CPPPATH = ['#extlibs/boost/boost'])
54         # On Windows, octbstack_test is a static LIB, that makes calls into static LIB ocsrm.
55         # On other platforms, octbstack_test is a shared LIB, that includes static LIB ocsrm.
56         unittests_env.AppendUnique(LIBS = ['ocsrm'])
57
58 unittests_env.AppendUnique(LIBPATH = [unittests_env.get('BUILD_DIR')])
59 unittests_env.PrependUnique(LIBS = [
60                 'oc',
61                 'octbstack_test',
62                 'oc_logger',
63                 'connectivity_abstraction',
64                 'coap',
65                 'timer'])
66
67 if unittests_env.get('SECURED') == '1':
68         unittests_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509','mbedcrypto'])
69         unittests_env.AppendUnique(LIBS = ['tinydtls'])
70
71 if unittests_env.get('LOGGING'):
72         unittests_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
73
74 if unittests_env.get('WITH_CLOUD'):
75         unittests_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
76
77 ######################################################################
78 # Source files and Targets
79 ######################################################################
80
81 unittests_src = [
82                 'ConstructResourceTest.cpp',
83                 'OCPlatformTest.cpp',
84                 'OCRepresentationTest.cpp',
85                 'OCRepresentationEncodingTest.cpp',
86                 'OCResourceTest.cpp',
87                 'OCExceptionTest.cpp',
88                 'OCResourceResponseTest.cpp',
89                 'OCHeaderOptionTest.cpp'
90         ]
91
92 # TODO: Fix errors in the following Windows tests.
93 if target_os in ['windows']:
94         if '12.0' == unittests_env['MSVC_VERSION']:
95                 unittests_src.remove('OCPlatformTest.cpp')
96                 unittests_src.remove('OCRepresentationEncodingTest.cpp')
97                 unittests_src.remove('OCRepresentationTest.cpp')
98                 unittests_src.remove('OCResourceTest.cpp')
99
100 if (('SUB' in with_mq) or ('PUB' in with_mq) or ('BROKER' in with_mq)):
101         unittests_src = unittests_src + ['OCMQResourceTest.cpp']
102
103 if unittests_env.get('WITH_CLOUD'):
104         unittests_src = unittests_src + ['OCAccountManagerTest.cpp']
105
106 unittests = unittests_env.Program('unittests', unittests_src)
107
108 Alias("unittests", [unittests])
109
110 unittests_env.AppendTarget('unittests')
111 if unittests_env.get('TEST') == '1':
112         if target_os in ['windows']:
113                 unittests_env.AppendENVPath('PATH', unittests_env.get('BUILD_DIR'))
114         if target_os in ['linux', 'windows']:
115                 run_test(unittests_env,
116                          'resource_unittests_unittests.memcheck',
117                          'resource/unittests/unittests',
118                          unittests)
119
120 src_dir = unittests_env.get('SRC_DIR')
121 svr_db_src_dir = os.path.join(src_dir, 'resource/examples/')
122 svr_db_build_dir = os.path.join(unittests_env.get('BUILD_DIR'), 'resource', 'unittests') + os.sep
123 unittests_env.Alias("install",
124                     unittests_env.Install(svr_db_build_dir,
125                                           os.path.join(svr_db_src_dir,
126                                                        'oic_svr_db_client.dat')))