### Package cJSON for Linux with CMake Source: https://github.com/davegamble/cjson/blob/master/README.md Example packaging steps for a Linux distribution: configure with cJSON_Utils enabled, tests disabled, and a custom install prefix, then build and install with DESTDIR. ```bash mkdir build cd build cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_CJSON_TEST=Off -DCMAKE_INSTALL_PREFIX=/usr make make DESTDIR=$pkgdir install ``` -------------------------------- ### Example of TEST_PROTECT and TEST_ABORT usage Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Example showing how to use TEST_PROTECT to catch TEST_ABORT calls. ```c main() { if (TEST_PROTECT()) { MyTest(); } } ``` -------------------------------- ### Unity test summary output example Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md Example of the final summary output showing ignored tests, failed tests, and overall totals. ```Shell -------------------------- UNITY IGNORED TEST SUMMARY -------------------------- blah.c:22:test_sandwiches_should_HaveBreadOnTwoSides:IGNORE ------------------------- UNITY FAILED TEST SUMMARY ------------------------- blah.c:87:test_sandwiches_should_HaveCondiments:FAIL:Expected 1 was 0 meh.c:38:test_soda_should_BeCalledPop:FAIL:Expected "pop" was "coke" -------------------------- OVERALL UNITY TEST SUMMARY -------------------------- 45 TOTAL TESTS 2 TOTAL FAILURES 1 IGNORED ``` -------------------------------- ### Run unity_test_summary.rb with Windows paths Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md Windows-style path example for the script. ```Shell ruby unity_test_summary.rb build\teat\ C:\projects\myproject\ ``` -------------------------------- ### Configure and install cJSON Source: https://github.com/davegamble/cjson/blob/master/CMakeLists.txt Generates libcjson.pc from a template, installs headers, pkg-config file, and library targets. Optionally exports CMake targets and sets SOVERSION when ENABLE_CJSON_VERSION_SO is ON. ```cmake configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" @ONLY) install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson") install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig") install(TARGETS "${CJSON_LIB}" EXPORT "${CJSON_LIB}" ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}" ) if (BUILD_SHARED_AND_STATIC_LIBS) install(TARGETS "${CJSON_LIB}-static" EXPORT "${CJSON_LIB}" ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}" ) endif() if(ENABLE_TARGET_EXPORT) # export library information for CMake projects install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON") endif() if(ENABLE_CJSON_VERSION_SO) set_target_properties("${CJSON_LIB}" PROPERTIES SOVERSION "${CJSON_VERSION_SO}" VERSION "${PROJECT_VERSION}") endif() ``` -------------------------------- ### Configure and install cJSON package config files Source: https://github.com/davegamble/cjson/blob/master/CMakeLists.txt Generates cJSONConfig.cmake and cJSONConfigVersion.cmake from templates and installs them if ENABLE_TARGET_EXPORT is enabled. ```cmake configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfig.cmake.in" ${PROJECT_BINARY_DIR}/cJSONConfig.cmake @ONLY) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfigVersion.cmake.in" ${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake @ONLY) if(ENABLE_TARGET_EXPORT) # Install package config files install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake ${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON") endif() ``` -------------------------------- ### Example JSON for building and parsing Source: https://github.com/davegamble/cjson/blob/master/README.md Example JSON object used to demonstrate building and parsing with cJSON. Contains a name and an array of resolution objects with width and height. ```json { "name": "Awesome 4K", "resolutions": [ { "width": 1280, "height": 720 }, { "width": 1920, "height": 1080 }, { "width": 3840, "height": 2160 } ] } ``` -------------------------------- ### Example YAML configuration file Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md Configuration file format used by Unity and CMock to define test runner behavior. ```YAML :unity: :includes: - stdio.h - microdefs.h :cexception: 1 :suit_setup: "blah = malloc(1024);" :suite_teardown: "free(blah);" ``` -------------------------------- ### Array comparison macro example Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Example of using _ARRAY suffix for array comparisons. ```c TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, elements) ``` -------------------------------- ### Install cJSON Utils library and headers Source: https://github.com/davegamble/cjson/blob/master/CMakeLists.txt Installs the cJSON Utils shared library, optionally the static library when BUILD_SHARED_AND_STATIC_LIBS is enabled, the cJSON_Utils.h header, and the pkg-config file. Also exports the library for CMake projects if ENABLE_TARGET_EXPORT is set. ```cmake install(TARGETS "${CJSON_UTILS_LIB}" EXPORT "${CJSON_UTILS_LIB}" ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}" ) if (BUILD_SHARED_AND_STATIC_LIBS) install(TARGETS "${CJSON_UTILS_LIB}-static" EXPORT "${CJSON_UTILS_LIB}" ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}" ) endif() install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson") install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig") if(ENABLE_TARGET_EXPORT) # export library information for CMake projects install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON") endif() ``` -------------------------------- ### Run generate_test_runner.rb with YAML configuration Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md Pass a YAML file to configure options like includes, setup, and teardown code. ```Shell ruby generate_test_runner.rb TestFile.c my_config.yml ``` -------------------------------- ### Install cJSON with vcpkg Source: https://github.com/davegamble/cjson/blob/master/README.md Installs cJSON via the vcpkg dependency manager. The port is maintained by Microsoft team members and community contributors. ```shell git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install vcpkg install cjson ``` -------------------------------- ### Simple main() function for Unity test module Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityConfigurationGuide.md Each test module has its own main() that initializes the system, calls UNITY_BEGIN(), runs each test, and returns UNITY_END() which is the total number of failures. Add system-wide setup or teardown code before or after the test calls as needed. ```c int main(void) { UNITY_BEGIN(); RUN_TEST(test_TheFirst); RUN_TEST(test_TheSecond); RUN_TEST(test_TheThird); return UNITY_END(); } ``` -------------------------------- ### RUN_TEST(func, linenum) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Macro to run a test function with setup and cleanup. It handles necessary setup before the test is called and handles cleanup and result tabulation afterwards. ```APIDOC ## RUN_TEST(func, linenum) ### Description Each Test is run within the macro `RUN_TEST`. This macro performs necessary setup before the test is called and handles cleanup and result tabulation afterwards. ### Parameters - **func** (function) - Required - The test function to run. - **linenum** (integer) - Required - The line number of the test. ### Example ```c RUN_TEST(MyTest, __LINE__); ``` ``` -------------------------------- ### Example test cases for generate_test_runner.rb Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md The script identifies test cases by searching for void functions starting with 'test' or 'spec'. ```C void testVerifyThatUnityIsAwesomeAndWillMakeYourLifeEasier(void) { ASSERT_TRUE(1); } void test_FunctionName_should_WorkProperlyAndReturn8(void) { ASSERT_EQUAL_INT(8, FunctionName()); } void spec_Function_should_DoWhatItIsSupposedToDo(void) { ASSERT_NOT_NULL(Function(5)); } ``` -------------------------------- ### EACH_EQUAL macro example Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Example of using _EACH_EQUAL to check every element of an array equals a single expected value. ```c TEST_ASSERT_EACH_EQUAL_INT32(expected, actual, elements) ``` -------------------------------- ### TEST_PROTECT() Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Setup and Catch macro. Sets up the feature for aborting tests and handles emergency abort cases. ```APIDOC ## TEST_PROTECT() ### Description Setup and Catch macro. Sets up the feature for aborting tests and handles emergency abort cases. ### Example ```c if (TEST_PROTECT()) { MyTest(); } ``` ``` -------------------------------- ### RUN_TEST macro Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Macro to run a test function with setup, cleanup, and result tabulation. ```c RUN_TEST(func, linenum) ``` -------------------------------- ### Configure Weak Function Support Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityConfigurationGuide.md Define these macros to enable optional setUp and tearDown functions if your compiler supports weak symbols. ```c #define UNITY_WEAK_ATTRIBUTE weak #define UNITY_WEAK_ATTRIBUTE __attribute__((weak)) #define UNITY_WEAK_PRAGMA #define UNITY_NO_WEAK ``` -------------------------------- ### Include cJSON header Source: https://github.com/davegamble/cjson/blob/master/README.md Include the cJSON header after installing via CMake or the Makefile. ```c #include ``` -------------------------------- ### Unity test file template in C Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityGettingStartedGuide.md Complete template for a Unity test file. Includes unity.h and the module header, setUp and tearDown functions, test functions following the test_ prefix convention, and a main function that calls UNITY_BEGIN, RUN_TEST for each test, and UNITY_END. ```C #include "unity.h" #include "file_to_test.h" void setUp(void) { // set stuff up here } void tearDown(void) { // clean stuff up here } void test_function_should_doBlahAndBlah(void) { //test stuff } void test_function_should_doAlsoDoBlah(void) { //more test stuff } int main(void) { UNITY_BEGIN(); RUN_TEST(test_function_should_doBlahAndBlah); RUN_TEST(test_function_should_doAlsoDoBlah); return UNITY_END(); } ``` -------------------------------- ### Configure Floating Point Support Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityConfigurationGuide.md Example of disabling single precision and enabling double precision floating point support. ```c //what manner of strange processor is this? #define UNITY_EXCLUDE_FLOAT #define UNITY_INCLUDE_DOUBLE ``` -------------------------------- ### Whitespace Indentation Example Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/ThrowTheSwitchCodingStandard.md Shows the preferred indentation style using 4 spaces per level, with additional indentation for wrapped lines to align in columns. ```C if (stuff_happened) { do_something(); } ``` -------------------------------- ### Minimalist RUN_TEST macro definition Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityConfigurationGuide.md The RUN_TEST macro performs per-test setup, teardown, and failure handling. It declares a new test, runs setUp() and the test function inside TEST_PROTECT(), runs tearDown() if not ignored, and concludes with UnityConcludeTest(). Modify this macro to add actions before or after every test case, such as flushing output with fsync. ```c #define RUN_TEST(testfunc) \ UNITY_NEW_TEST(#testfunc) \ if (TEST_PROTECT()) { \ setUp(); \ testfunc(); \ } \ if (TEST_PROTECT() && (!TEST_IS_IGNORED)) \ tearDown(); \ UnityConcludeTest(); ``` -------------------------------- ### Braces Placement Example Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/ThrowTheSwitchCodingStandard.md Illustrates the brace style: left brace on the next line after the declaration, right brace directly below, and indented content. Braces are used even for single-line blocks. ```C while (blah) { //Like so. Even if only one line, we use braces. } ``` -------------------------------- ### Example of Non-Standard Integer Sizes on a Target Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Illustrates a target where the natural register size is 12 bits, leading to non-standard integer sizes that violate the C standard's minimum size requirements. ```C char (8 bit) <= short (12 bit) <= int (12 bit) <= long (16 bit) ``` -------------------------------- ### Run unity_test_summary.rb with build path Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md Basic command-line invocation to summarize test results from the specified build directory. ```Shell ruby unity_test_summary.rb build/test/ ``` -------------------------------- ### Run generate_test_runner.rb with YAML and extra headers Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md Include additional header files by passing them as arguments after the YAML configuration. ```Shell ruby generate_test_runner.rb TestFile.c my_config.yml extras.h ``` -------------------------------- ### Override UNITY_DOUBLE_TYPE Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityConfigurationGuide.md Example of overriding the default double type with long double. ```c #define UNITY_DOUBLE_TYPE long double ``` -------------------------------- ### Run unity_test_summary.rb with root path Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md Optional root path argument for use with relative paths in tools, enabling clickable shortcuts in IDEs like Eclipse. ```Shell ruby unity_test_summary.rb build/test/ ~/projects/myproject/ ``` -------------------------------- ### Override UNITY_FLOAT_TYPE Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityConfigurationGuide.md Example of overriding the default float type with a specialty type. ```c #define UNITY_FLOAT_TYPE float16_t ``` -------------------------------- ### Build cJSON with make all Source: https://github.com/davegamble/cjson/blob/master/README.md Builds cJSON static and shared libraries and a small test program using the deprecated Makefile. Run in the source directory. ```makefile make all ``` -------------------------------- ### Run generate_test_runner.rb from command line Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md Basic usage to generate a test runner file from a source test file. ```Shell ruby generate_test_runner.rb TestFile.c NameOfRunner.c ``` -------------------------------- ### Define UNITY_SUPPORT_64 to enable 64-bit support Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityConfigurationGuide.md Define this macro to enable 64-bit support when Unity does not auto-detect it. Enabling 64-bit support can have a significant size and speed impact on small targets. ```c #define UNITY_SUPPORT_64 ``` -------------------------------- ### Create and print JSON with cJSON_Print using helper functions Source: https://github.com/davegamble/cjson/blob/master/README.md Builds the same JSON structure as create_monitor but uses the cJSON_Add...ToObject helper functions (cJSON_AddStringToObject, cJSON_AddArrayToObject, cJSON_AddNumberToObject) to reduce boilerplate. The returned string is heap-allocated and must be freed by the caller. On failure, it prints "Failed to print monitor." to stderr and returns NULL. ```c //NOTE: Returns a heap allocated string, you are required to free it after use. char *create_monitor_with_helpers(void) { const unsigned int resolution_numbers[3][2] = { {1280, 720}, {1920, 1080}, {3840, 2160} }; char *string = NULL; cJSON *resolutions = NULL; size_t index = 0; cJSON *monitor = cJSON_CreateObject(); if (cJSON_AddStringToObject(monitor, "name", "Awesome 4K") == NULL) { goto end; } resolutions = cJSON_AddArrayToObject(monitor, "resolutions"); if (resolutions == NULL) { goto end; } for (index = 0; index < (sizeof(resolution_numbers) / (2 * sizeof(int))); ++index) { cJSON *resolution = cJSON_CreateObject(); if (cJSON_AddNumberToObject(resolution, "width", resolution_numbers[index][0]) == NULL) { goto end; } if (cJSON_AddNumberToObject(resolution, "height", resolution_numbers[index][1]) == NULL) { goto end; } cJSON_AddItemToArray(resolutions, resolution); } string = cJSON_Print(monitor); if (string == NULL) { fprintf(stderr, "Failed to print monitor.\n"); } end: cJSON_Delete(monitor); return string; } ``` -------------------------------- ### Create and print JSON with cJSON_Print using low-level functions Source: https://github.com/davegamble/cjson/blob/master/README.md Builds a JSON object with a name and an array of resolution objects using low-level cJSON functions (cJSON_CreateObject, cJSON_CreateString, cJSON_CreateArray, cJSON_CreateNumber, cJSON_AddItemToObject, cJSON_AddItemToArray) and prints it with cJSON_Print. The returned string is heap-allocated and must be freed by the caller. On failure, it prints "Failed to print monitor." to stderr and returns NULL. ```c //create a monitor with a list of supported resolutions //NOTE: Returns a heap allocated string, you are required to free it after use. char *create_monitor(void) { const unsigned int resolution_numbers[3][2] = { {1280, 720}, {1920, 1080}, {3840, 2160} }; char *string = NULL; cJSON *name = NULL; cJSON *resolutions = NULL; cJSON *resolution = NULL; cJSON *width = NULL; cJSON *height = NULL; size_t index = 0; cJSON *monitor = cJSON_CreateObject(); if (monitor == NULL) { goto end; } name = cJSON_CreateString("Awesome 4K"); if (name == NULL) { goto end; } /* after creation was successful, immediately add it to the monitor, * thereby transferring ownership of the pointer to it */ cJSON_AddItemToObject(monitor, "name", name); resolutions = cJSON_CreateArray(); if (resolutions == NULL) { goto end; } cJSON_AddItemToObject(monitor, "resolutions", resolutions); for (index = 0; index < (sizeof(resolution_numbers) / (2 * sizeof(int))); ++index) { resolution = cJSON_CreateObject(); if (resolution == NULL) { goto end; } cJSON_AddItemToArray(resolutions, resolution); width = cJSON_CreateNumber(resolution_numbers[index][0]); if (width == NULL) { goto end; } cJSON_AddItemToObject(resolution, "width", width); height = cJSON_CreateNumber(resolution_numbers[index][1]); if (height == NULL) { goto end; } cJSON_AddItemToObject(resolution, "height", height); } string = cJSON_Print(monitor); if (string == NULL) { fprintf(stderr, "Failed to print monitor.\n"); } end: cJSON_Delete(monitor); return string; } ``` -------------------------------- ### Meson build file for cJSON dependency Source: https://github.com/davegamble/cjson/blob/master/README.md Meson build file that declares a C project and links against the libcjson dependency. Use this to integrate cJSON into a Meson-based project. ```meson project('c-json-example', 'c') cjson = dependency('libcjson') example = executable( 'example', 'example.c', dependencies: [cjson], ) ``` -------------------------------- ### Create uninstall target Source: https://github.com/davegamble/cjson/blob/master/CMakeLists.txt Adds a custom 'uninstall' target that runs the uninstall.cmake script when ENABLE_CJSON_UNINSTALL is enabled. ```cmake option(ENABLE_CJSON_UNINSTALL "Enable creating uninstall target" ON) if(ENABLE_CJSON_UNINSTALL) add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/library_config/uninstall.cmake") endif() ``` -------------------------------- ### TEST_ASSERT_X parameter convention Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Shows the general parameter order for Unity assertions: modifiers, expected, actual, and size/count. The 'actual' parameter is always present; others are optional depending on the assertion. ```c TEST_ASSERT_X( {modifiers}, {expected}, actual, {size/count} ) ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_UINT64 (expected, actual, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of a uint64_t array equals a single expected uint64_t value. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_UINT64 (expected, actual, num_elements) ### Description Asserts that each element of a uint64_t array equals a single expected uint64_t value. Fails on the first mismatch and reports the index. ### Parameters - **expected** (uint64_t) - Required - The expected value for each element. - **actual** (array of uint64_t) - Required - The array to compare. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected value. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison. ``` -------------------------------- ### Configure Custom Output Macros Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityConfigurationGuide.md Define these macros to route test output to custom functions when standard stdout is unavailable, such as on embedded processors. ```c #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) #define UNITY_OUTPUT_FLUSH() RS232_flush() #define UNITY_OUTPUT_COMPLETE() RS232_close() ``` -------------------------------- ### CMake configuration for cJSON tests Source: https://github.com/davegamble/cjson/blob/master/tests/CMakeLists.txt Configures the test build: adds Unity as a static library, disables -Werror, -fvisibility=hidden, -fsanitize=float-divide-by-zero, and -Wswitch-enum for Unity, copies test input files, defines test executables, and optionally sets up Valgrind memory checking. ```cmake if(ENABLE_CJSON_TEST) add_library(unity STATIC unity/src/unity.c) # Disable -Werror for Unity if (FLAG_SUPPORTED_Werror) if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error") else() target_compile_options(unity PRIVATE "-Wno-error") endif() endif() # Disable -fvisibility=hidden for Unity if (FLAG_SUPPORTED_fvisibilityhidden) if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default") else() target_compile_options(unity PRIVATE "-fvisibility=default") endif() endif() # Disable -fsanitize=float-divide-by-zero for Unity (GCC bug on x86 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80097) if (FLAG_SUPPORTED_fsanitizefloatdividebyzero AND (CMAKE_C_COMPILER_ID STREQUAL "GNU")) if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize=float-divide-by-zero") else() target_compile_options(unity PRIVATE "-fno-sanitize=float-divide-by-zero") endif() endif() # Disable -Wswitch-enum for Unity if (FLAG_SUPPORTED_Wswitchenum) if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch-enum") else() target_compile_options(unity PRIVATE "-Wno-switch-enum") endif() endif() #copy test files file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inputs") file(GLOB test_files "inputs/*") file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/inputs/") set(unity_tests parse_examples parse_number parse_hex4 parse_string parse_array parse_object parse_value print_string print_number print_array print_object print_value misc_tests parse_with_opts compare_tests cjson_add readme_examples minify_tests ) option(ENABLE_VALGRIND OFF "Enable the valgrind memory checker for the tests.") if (ENABLE_VALGRIND) find_program(MEMORYCHECK_COMMAND valgrind) if ("${MEMORYCHECK_COMMAND}" MATCHES "MEMORYCHECK_COMMAND-NOTFOUND") message(WARNING "Valgrind couldn't be found.") unset(MEMORYCHECK_COMMAND) else() set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1 --suppressions=${CMAKE_CURRENT_SOURCE_DIR}/../valgrind.supp) endif() endif() foreach(unity_test ${unity_tests}) add_executable("${unity_test}" "${unity_test}.c") if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") target_sources(${unity_test} PRIVATE unity_setup.c) endif() target_link_libraries("${unity_test}" "${CJSON_LIB}" unity) if(MEMORYCHECK_COMMAND) add_test(NAME "${unity_test}" COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "${CMAKE_CURRENT_BINARY_DIR}/${unity_test}") else() add_test(NAME "${unity_test}" COMMAND "./${unity_test}") endif() endforeach() add_dependencies(check ${unity_tests}) if (ENABLE_CJSON_UTILS) #copy test files file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/json-patch-tests") file(GLOB test_files "json-patch-tests/*") file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/json-patch-tests/") set (cjson_utils_tests json_patch_tests old_utils_tests misc_utils_tests) foreach (cjson_utils_test ${cjson_utils_tests}) add_executable("${cjson_utils_test}" "${cjson_utils_test}.c") target_link_libraries("${cjson_utils_test}" "${CJSON_LIB}" "${CJSON_UTILS_LIB}" unity) if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") target_sources(${cjson_utils_test} PRIVATE unity_setup.c) endif() if(MEMORYCHECK_COMMAND) add_test(NAME "${cjson_utils_test}" COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "${CMAKE_CURRENT_BINARY_DIR}/${cjson_utils_test}") else() add_test(NAME "${cjson_utils_test}" COMMAND "./${cjson_utils_test}") endif() endforeach() add_dependencies(check ${cjson_utils_tests}) endif() endif() ``` -------------------------------- ### Build cJSON_Utils library Source: https://github.com/davegamble/cjson/blob/master/CMakeLists.txt Optionally builds the cJSON_Utils library when ENABLE_CJSON_UTILS is ON. Creates shared/static targets as configured, links against cJSON, and generates libcjson_utils.pc. ```cmake #cJSON_Utils option(ENABLE_CJSON_UTILS "Enable building the cJSON_Utils library." OFF) if(ENABLE_CJSON_UTILS) set(CJSON_UTILS_LIB cjson_utils) file(GLOB HEADERS_UTILS cJSON_Utils.h) set(SOURCES_UTILS cJSON_Utils.c) if (NOT BUILD_SHARED_AND_STATIC_LIBS) add_library("${CJSON_UTILS_LIB}" "${CJSON_LIBRARY_TYPE}" "${HEADERS_UTILS}" "${SOURCES_UTILS}") target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}") else() add_library("${CJSON_UTILS_LIB}" SHARED "${HEADERS_UTILS}" "${SOURCES_UTILS}") target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}") add_library("${CJSON_UTILS_LIB}-static" STATIC "${HEADERS_UTILS}" "${SOURCES_UTILS}") target_link_libraries("${CJSON_UTILS_LIB}-static" "${CJSON_LIB}-static") set_target_properties("${CJSON_UTILS_LIB}-static" PROPERTIES OUTPUT_NAME "${CJSON_UTILS_LIB}") set_target_properties("${CJSON_UTILS_LIB}-static" PROPERTIES PREFIX "lib") endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson_utils.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY) endif() ``` -------------------------------- ### TEST_PROTECT and TEST_ABORT macros Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Macros for setting up emergency abort handling and aborting a test. ```c TEST_PROTECT() ``` ```c TEST_ABORT() ``` -------------------------------- ### TEST_ASSERT_EQUAL macro Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Another way of calling TEST_ASSERT_EQUAL_INT. ```c TEST_ASSERT_EQUAL(expected, actual) ``` -------------------------------- ### Run generate_test_runner.rb with automatic naming Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md If only the test file is provided, the script appends '_Runner' to the filename. ```Shell ruby generate_test_runner.rb TestFile.c ``` -------------------------------- ### Define build options for cJSON Source: https://github.com/davegamble/cjson/blob/master/CMakeLists.txt Sets options for shared/static library builds, target export, and versioning. BUILD_SHARED_LIBS defaults to ON, while BUILD_SHARED_AND_STATIC_LIBS defaults to Off. ```cmake option(BUILD_SHARED_LIBS "Build shared libraries" ON) option(ENABLE_TARGET_EXPORT "Enable exporting of CMake targets. Disable when it causes problems!" ON) ``` ```cmake #cJSON set(CJSON_LIB cjson) file(GLOB HEADERS cJSON.h) set(SOURCES cJSON.c) option(BUILD_SHARED_AND_STATIC_LIBS "Build both shared and static libraries" Off) option(CJSON_OVERRIDE_BUILD_SHARED_LIBS "Override BUILD_SHARED_LIBS with CJSON_BUILD_SHARED_LIBS" OFF) option(CJSON_BUILD_SHARED_LIBS "Overrides BUILD_SHARED_LIBS if CJSON_OVERRIDE_BUILD_SHARED_LIBS is enabled" ON) option(ENABLE_CJSON_VERSION_SO "Enables cJSON so version" ON) ``` -------------------------------- ### Build cJSON with CMake on Unix Source: https://github.com/davegamble/cjson/blob/master/README.md Out-of-tree CMake build on Unix: create a build directory, configure with cmake, then compile with make. Requires CMake 3.5 or higher. ```bash mkdir build cd build cmake .. ``` ```bash make ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_UINT32 (expected, actual, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of a uint32_t array equals a single expected uint32_t value. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_UINT32 (expected, actual, num_elements) ### Description Asserts that each element of a uint32_t array equals a single expected uint32_t value. Fails on the first mismatch and reports the index. ### Parameters - **expected** (uint32_t) - Required - The expected value for each element. - **actual** (array of uint32_t) - Required - The array to compare. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected value. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison. ``` -------------------------------- ### TEST_ASSERT_EQUAL_STRING macro Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Compares two null-terminated strings. Fails if any character is different or if the lengths are different. ```c TEST_ASSERT_EQUAL_STRING(expected, actual) ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_UINT8 (expected, actual, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of a uint8_t array equals a single expected uint8_t value. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_UINT8 (expected, actual, num_elements) ### Description Asserts that each element of a uint8_t array equals a single expected uint8_t value. Fails on the first mismatch and reports the index. ### Parameters - **expected** (uint8_t) - Required - The expected value for each element. - **actual** (array of uint8_t) - Required - The array to compare. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected value. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison. ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_UINT16 (expected, actual, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of a uint16_t array equals a single expected uint16_t value. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_UINT16 (expected, actual, num_elements) ### Description Asserts that each element of a uint16_t array equals a single expected uint16_t value. Fails on the first mismatch and reports the index. ### Parameters - **expected** (uint16_t) - Required - The expected value for each element. - **actual** (array of uint16_t) - Required - The array to compare. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected value. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison. ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_HEX64 (expected, actual, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of a uint64_t array equals a single expected uint64_t value, with failure messages formatted in hexadecimal. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_HEX64 (expected, actual, num_elements) ### Description Asserts that each element of a uint64_t array equals a single expected uint64_t value, with failure messages formatted in hexadecimal. Fails on the first mismatch and reports the index. ### Parameters - **expected** (uint64_t) - Required - The expected value for each element. - **actual** (array of uint64_t) - Required - The array to compare. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected value. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison and displays values in hexadecimal. ``` -------------------------------- ### TEST_ASSERT_EQUAL_STRING_MESSAGE macro Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Compares two null-terminated strings. Fails if any character is different or if the lengths are different. Outputs a custom message on failure. ```c TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) ``` -------------------------------- ### Configure Fuzzing Test Executable Source: https://github.com/davegamble/cjson/blob/master/fuzzing/CMakeLists.txt Adds the fuzz_main executable when ENABLE_CJSON_TEST is enabled. ```cmake if(ENABLE_CJSON_TEST) ADD_EXECUTABLE(fuzz_main fuzz_main.c cjson_read_fuzzer.c) TARGET_LINK_LIBRARIES(fuzz_main cjson) endif() ``` -------------------------------- ### Define UNITY_EXCLUDE_LIMITS_H to skip limits.h Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityConfigurationGuide.md Define this macro to prevent Unity from including limits.h when your system does not support it, avoiding compiler errors. ```c #define UNITY_EXCLUDE_LIMITS_H ``` -------------------------------- ### Basic validity assertion macros Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Macros for asserting true/false conditions and unconditional failure. ```c TEST_ASSERT_TRUE(condition) ``` ```c TEST_ASSERT_FALSE(condition) ``` ```c TEST_ASSERT(condition) ``` ```c TEST_ASSERT_UNLESS(condition) ``` ```c TEST_FAIL() TEST_FAIL_MESSAGE(message) ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_INT64 (expected, actual, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of an int64_t array equals a single expected int64_t value. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_INT64 (expected, actual, num_elements) ### Description Asserts that each element of an int64_t array equals a single expected int64_t value. Fails on the first mismatch and reports the index. ### Parameters - **expected** (int64_t) - Required - The expected value for each element. - **actual** (array of int64_t) - Required - The array to compare. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected value. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison. ``` -------------------------------- ### Generate multiple test runners in a loop Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md Instantiate the generator once and reuse it to process multiple test files in a build script. ```Ruby gen = UnityTestRunnerGenerator.new(options) test_files.each do |f| gen.run(f, File.basename(f,'.c')+"Runner.c" end ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_UINT (expected, actual, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of an unsigned int array equals a single expected unsigned int value. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_UINT (expected, actual, num_elements) ### Description Asserts that each element of an unsigned int array equals a single expected unsigned int value. Fails on the first mismatch and reports the index. ### Parameters - **expected** (unsigned int) - Required - The expected value for each element. - **actual** (array of unsigned int) - Required - The array to compare. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected value. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison. ``` -------------------------------- ### TEST_ASSERT_EQUAL_MEMORY (expected, actual, len) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that the contents of the memory specified by the expected and actual pointers is identical for the given length. ```APIDOC ## TEST_ASSERT_EQUAL_MEMORY (expected, actual, len) ### Description Asserts that the contents of the memory specified by the expected and actual pointers is identical. The size of the memory blocks in bytes is specified by the len parameter. ### Parameters - **expected** - Pointer to the expected memory block. - **actual** - Pointer to the actual memory block. - **len** - The number of bytes to compare. ### Behavior - Passes if the memory blocks are identical for len bytes. - Fails if any byte differs. ``` -------------------------------- ### TEST_ASSERT_NULL macro Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Fails if the pointer is not equal to NULL. ```c TEST_ASSERT_NULL(pointer) ``` -------------------------------- ### Enable CException plugin with YAML syntax Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityHelperScriptsGuide.md Use this YAML configuration to enable CException support in generated test runners. It adds a check for unhandled exceptions in each test, reporting a failure if one is detected. ```YAML :plugins: -:cexception ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_HEX (expected, actual, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of an unsigned int array equals a single expected unsigned int value, with failure messages formatted in hexadecimal. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_HEX (expected, actual, num_elements) ### Description Asserts that each element of an unsigned int array equals a single expected unsigned int value, with failure messages formatted in hexadecimal. Fails on the first mismatch and reports the index. ### Parameters - **expected** (unsigned int) - Required - The expected value for each element. - **actual** (array of unsigned int) - Required - The array to compare. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected value. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison and displays values in hexadecimal. ``` -------------------------------- ### Enable cJSON testing with check target Source: https://github.com/davegamble/cjson/blob/master/CMakeLists.txt Adds a test executable, registers a CTest test, disables float-divide-by-zero sanitizer for the test, and creates a 'check' custom target that runs all tests. ```cmake option(ENABLE_CJSON_TEST "Enable building cJSON test" ON) if(ENABLE_CJSON_TEST) enable_testing() set(TEST_CJSON cJSON_test) add_executable("${TEST_CJSON}" test.c) target_link_libraries("${TEST_CJSON}" "${CJSON_LIB}") add_test(NAME ${TEST_CJSON} COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${TEST_CJSON}") # Disable -fsanitize=float-divide-by-zero for cJSON_test if (FLAG_SUPPORTED_fsanitizefloatdividebyzero) if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize=float-divide-by-zero") else() target_compile_options(${TEST_CJSON} PRIVATE "-fno-sanitize=float-divide-by-zero") endif() endif() #"check" target that automatically builds everything and runs the tests add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure DEPENDS ${TEST_CJSON}) endif() ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_HEX32 (expected, actual, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of a uint32_t array equals a single expected uint32_t value, with failure messages formatted in hexadecimal. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_HEX32 (expected, actual, num_elements) ### Description Asserts that each element of a uint32_t array equals a single expected uint32_t value, with failure messages formatted in hexadecimal. Fails on the first mismatch and reports the index. ### Parameters - **expected** (uint32_t) - Required - The expected value for each element. - **actual** (array of uint32_t) - Required - The array to compare. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected value. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison and displays values in hexadecimal. ``` -------------------------------- ### TEST_ASSERT_EQUAL_FLOAT and TEST_ASSERT_EQUAL_DOUBLE macros Source: https://github.com/davegamble/cjson/blob/master/tests/unity/README.md Asserts that two floating point values are "equal" within a small % delta of the expected value. ```c TEST_ASSERT_EQUAL_FLOAT(expected, actual) TEST_ASSERT_EQUAL_DOUBLE(expected, actual) ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_HEX16 (expected, actual, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of a uint16_t array equals a single expected uint16_t value, with failure messages formatted in hexadecimal. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_HEX16 (expected, actual, num_elements) ### Description Asserts that each element of a uint16_t array equals a single expected uint16_t value, with failure messages formatted in hexadecimal. Fails on the first mismatch and reports the index. ### Parameters - **expected** (uint16_t) - Required - The expected value for each element. - **actual** (array of uint16_t) - Required - The array to compare. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected value. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison and displays values in hexadecimal. ``` -------------------------------- ### Define UNITY_EXCLUDE_STDINT_H to skip stdint.h Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityConfigurationGuide.md Define this macro to prevent Unity from including stdint.h when your system does not support it, avoiding compiler errors. ```c #define UNITY_EXCLUDE_STDINT_H ``` -------------------------------- ### TEST_ASSERT_EACH_EQUAL_MEMORY (expected, actual, len, num_elements) Source: https://github.com/davegamble/cjson/blob/master/tests/unity/docs/UnityAssertionsReference.md Asserts that each element of a memory block array equals a single expected memory block, comparing len bytes at each element. Fails on the first mismatch and reports the index. ```APIDOC ## TEST_ASSERT_EACH_EQUAL_MEMORY (expected, actual, len, num_elements) ### Description Asserts that each element of a memory block array equals a single expected memory block, comparing len bytes at each element. Fails on the first mismatch and reports the index. ### Parameters - **expected** (memory block) - Required - The expected memory block for each element. - **actual** (array of memory blocks) - Required - The array to compare. - **len** (int) - Required - Number of bytes to compare at each array element. - **num_elements** (int) - Required - Number of elements to compare. ### Behavior - Compares the first num_elements elements of actual against the expected memory block. - For each element, compares len bytes. - Fails on the first element that does not match. - Failure message includes the index of the failed comparison. ``` -------------------------------- ### Configure Fuzzing with afl-fuzz Source: https://github.com/davegamble/cjson/blob/master/fuzzing/CMakeLists.txt Defines the ENABLE_FUZZING option and sets up the afl-main executable and custom target if enabled. Requires sanitizers to be active. ```cmake option(ENABLE_FUZZING "Create executables and targets for fuzzing cJSON with afl." Off) if (ENABLE_FUZZING) find_program(AFL_FUZZ afl-fuzz) if ("${AFL_FUZZ}" MATCHES "AFL_FUZZ-NOTFOUND") message(FATAL_ERROR "Couldn't find afl-fuzz.") endif() add_executable(afl-main afl.c) target_link_libraries(afl-main "${CJSON_LIB}") if (NOT ENABLE_SANITIZERS) message(FATAL_ERROR "Enable sanitizers with -DENABLE_SANITIZERS=On to do fuzzing.") endif() option(ENABLE_FUZZING_PRINT "Fuzz printing functions together with parser." On) set(fuzz_print_parameter "no") if (ENABLE_FUZZING_PRINT) set(fuzz_print_parameter "yes") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error") add_custom_target(afl COMMAND "${AFL_FUZZ}" -i "${CMAKE_CURRENT_SOURCE_DIR}/inputs" -o "${CMAKE_CURRENT_BINARY_DIR}/findings" -x "${CMAKE_CURRENT_SOURCE_DIR}/json.dict" -- "${CMAKE_CURRENT_BINARY_DIR}/afl-main" "@@" "${fuzz_print_parameter}" DEPENDS afl-main) endif() ```