interplane.Get Omega
Read in your language

cJSON

[Ported from github.com/DaveGamble/cJSON] Fix: heap-use-after-free in merge_patch when patch is subtree of target (#1065)

Brought by drakestapleton

branch master Branches Tags History

cJSON / tests / CMakeLists.txt

119 lines · 4530 bytes Raw Blame History
1if(ENABLE_CJSON_TEST)
2 add_library(unity STATIC unity/src/unity.c)
3
4 # Disable -Werror for Unity
5 if (FLAG_SUPPORTED_Werror)
6 if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
7 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
8 else()
9 target_compile_options(unity PRIVATE "-Wno-error")
10 endif()
11 endif()
12 # Disable -fvisibility=hidden for Unity
13 if (FLAG_SUPPORTED_fvisibilityhidden)
14 if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
15 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default")
16 else()
17 target_compile_options(unity PRIVATE "-fvisibility=default")
18 endif()
19 endif()
20 # Disable -fsanitize=float-divide-by-zero for Unity (GCC bug on x86 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80097)
21 if (FLAG_SUPPORTED_fsanitizefloatdividebyzero AND (CMAKE_C_COMPILER_ID STREQUAL "GNU"))
22 if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
23 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize=float-divide-by-zero")
24 else()
25 target_compile_options(unity PRIVATE "-fno-sanitize=float-divide-by-zero")
26 endif()
27 endif()
28 # Disable -Wswitch-enum for Unity
29 if (FLAG_SUPPORTED_Wswitchenum)
30 if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
31 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch-enum")
32 else()
33 target_compile_options(unity PRIVATE "-Wno-switch-enum")
34 endif()
35 endif()
36
37 #copy test files
38 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inputs")
39 file(GLOB test_files "inputs/*")
40 file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/inputs/")
41
42 set(unity_tests
43 parse_examples
44 parse_number
45 parse_hex4
46 parse_string
47 parse_array
48 parse_object
49 parse_value
50 print_string
51 print_number
52 print_array
53 print_object
54 print_value
55 misc_tests
56 parse_with_opts
57 compare_tests
58 cjson_add
59 readme_examples
60 minify_tests
61 )
62
63 option(ENABLE_VALGRIND OFF "Enable the valgrind memory checker for the tests.")
64 if (ENABLE_VALGRIND)
65 find_program(MEMORYCHECK_COMMAND valgrind)
66 if ("${MEMORYCHECK_COMMAND}" MATCHES "MEMORYCHECK_COMMAND-NOTFOUND")
67 message(WARNING "Valgrind couldn't be found.")
68 unset(MEMORYCHECK_COMMAND)
69 else()
70 set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1 --suppressions=${CMAKE_CURRENT_SOURCE_DIR}/../valgrind.supp)
71 endif()
72 endif()
73
74 foreach(unity_test ${unity_tests})
75 add_executable("${unity_test}" "${unity_test}.c")
76 if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
77 target_sources(${unity_test} PRIVATE unity_setup.c)
78 endif()
79 target_link_libraries("${unity_test}" "${CJSON_LIB}" unity)
80 if(MEMORYCHECK_COMMAND)
81 add_test(NAME "${unity_test}"
82 COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "${CMAKE_CURRENT_BINARY_DIR}/${unity_test}")
83 else()
84 add_test(NAME "${unity_test}"
85 COMMAND "./${unity_test}")
86 endif()
87 endforeach()
88
89 add_dependencies(check ${unity_tests})
90
91 if (ENABLE_CJSON_UTILS)
92 #copy test files
93 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/json-patch-tests")
94 file(GLOB test_files "json-patch-tests/*")
95 file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/json-patch-tests/")
96
97 set (cjson_utils_tests
98 json_patch_tests
99 old_utils_tests
100 misc_utils_tests)
101
102 foreach (cjson_utils_test ${cjson_utils_tests})
103 add_executable("${cjson_utils_test}" "${cjson_utils_test}.c")
104 target_link_libraries("${cjson_utils_test}" "${CJSON_LIB}" "${CJSON_UTILS_LIB}" unity)
105 if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
106 target_sources(${cjson_utils_test} PRIVATE unity_setup.c)
107 endif()
108 if(MEMORYCHECK_COMMAND)
109 add_test(NAME "${cjson_utils_test}"
110 COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "${CMAKE_CURRENT_BINARY_DIR}/${cjson_utils_test}")
111 else()
112 add_test(NAME "${cjson_utils_test}"
113 COMMAND "./${cjson_utils_test}")
114 endif()
115 endforeach()
116
117 add_dependencies(check ${cjson_utils_tests})
118 endif()
119endif()