1# Include filepaths for source and include.
2include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
3
4# ====================  Define your project name (edit) ========================
5set( project_name "FreeRTOS_DNS_Callback" )
6message( STATUS "${project_name}" )
7# =====================  Create your mock here  (edit)  ========================
8
9# list the files to mock here
10set (mock_list "")
11list(APPEND mock_list
12            "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
13            "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
14            "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
15
16#"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/portable.h"
17            "${CMAKE_BINARY_DIR}/Annexed_TCP/portable.h"
18            "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
19            "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
20            "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
21            "${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
22            "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
23            "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Cache.h"
24            "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Parser.h"
25            "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
26            "${MODULE_ROOT_DIR}/test/unit-test/FreeRTOS_Sockets/Sockets_list_macros.h"
27        )
28# list the directories your mocks need
29set(mock_include_list "")
30list(APPEND mock_include_list
31            .
32            ${TCP_INCLUDE_DIRS}
33            ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
34            ${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
35        )
36
37#list the definitions of your mocks to control what to be included
38set(mock_define_list "")
39list(APPEND mock_define_list
40       )
41
42# ================= Create the library under test here (edit) ==================
43
44add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3)
45# list the files you would like to test here
46set(real_source_files "")
47list(APPEND real_source_files
48            ${project_name}/FreeRTOS_UDP_IP_stubs.c
49            ${MODULE_ROOT_DIR}/source/FreeRTOS_DNS_Callback.c
50	)
51# list the directories the module under test includes
52set(real_include_directories "")
53list(APPEND real_include_directories
54            .
55            ${TCP_INCLUDE_DIRS}
56            ${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
57            ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
58            ${CMOCK_DIR}/vendor/unity/src
59	)
60
61# =====================  Create UnitTest Code here (edit)  =====================
62
63# list the directories your test needs to include
64set(test_include_directories "")
65list(APPEND test_include_directories
66            .
67            ${CMOCK_DIR}/vendor/unity/src
68            ${TCP_INCLUDE_DIRS}
69            ${MODULE_ROOT_DIR}/test/unit-test/${project_name}
70            ${MODULE_ROOT_DIR}/source/include/
71            ${MODULE_ROOT_DIR}/test/unit-test/FreeRTOS_Sockets
72        )
73# To prevent the file under test from using the list macros and instead use our
74# mocked version
75add_definitions(
76            -I${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
77            -I${MODULE_ROOT_DIR}/test/unit-test/FreeRTOS_Sockets/
78            -I${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
79        )
80
81# =============================  (end edit)  ===================================
82
83set(mock_name "${project_name}_mock")
84set(real_name "${project_name}_real")
85
86create_mock_list(${mock_name}
87                "${mock_list}"
88                "${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
89                "${mock_include_list}"
90                "${mock_define_list}"
91        )
92create_real_library(${real_name}
93                    "${real_source_files}"
94                    "${real_include_directories}"
95                    "${mock_name}"
96        )
97
98set( utest_link_list "")
99list(APPEND utest_link_list
100            -l${mock_name}
101            lib${real_name}.a
102        )
103
104set (utest_dep_list "")
105list(APPEND utest_dep_list
106            ${real_name}
107        )
108
109set(utest_name "${project_name}_utest")
110set(utest_source "${project_name}/${project_name}_utest.c")
111
112create_test(${utest_name}
113            ${utest_source}
114            "${utest_link_list}"
115            "${utest_dep_list}"
116            "${test_include_directories}"
117        )
118
119target_compile_options(${real_name} PUBLIC
120            -include Sockets_list_macros.h
121        )
122