mirror of
https://github.com/json-c/json-c.git
synced 2026-03-26 08:29:06 +08:00
The function _json_c_strerror does not properly format unknown errnos. The int to ascii loop ignores the leading digit if the number can be divided by 10 and if an errno has been formatted, shorter errnos would not properly terminate the newly created string, showing the ending numbers of the previous output. A test case has been added to show these effects. Since this function has been introduced for tests, the effect of this on real life code is basically non-existing. First an environment variable has to be set to activate this strerror code and second an unknown errno would have to be encountered.
60 lines
1.5 KiB
CMake
60 lines
1.5 KiB
CMake
|
|
add_executable(test1Formatted test1.c parse_flags.c parse_flags.h)
|
|
target_compile_definitions(test1Formatted PRIVATE TEST_FORMATTED=1)
|
|
target_link_libraries(test1Formatted PRIVATE ${PROJECT_NAME})
|
|
|
|
add_executable(test2Formatted test2.c parse_flags.c parse_flags.h)
|
|
target_compile_definitions(test2Formatted PRIVATE TEST_FORMATTED=1)
|
|
target_link_libraries(test2Formatted PRIVATE ${PROJECT_NAME})
|
|
|
|
# https://cmake.org/cmake/help/v3.0/command/add_test.html
|
|
# https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
|
|
|
|
include_directories(PUBLIC ${CMAKE_SOURCE_DIR})
|
|
|
|
foreach(TESTNAME
|
|
test1
|
|
test2
|
|
test4
|
|
testReplaceExisting
|
|
test_cast
|
|
test_charcase
|
|
test_compare
|
|
test_deep_copy
|
|
test_double_serializer
|
|
test_float
|
|
test_int_add
|
|
test_json_pointer
|
|
test_locale
|
|
test_null
|
|
test_parse
|
|
test_parse_int64
|
|
test_printbuf
|
|
test_set_serializer
|
|
test_set_value
|
|
test_strerror
|
|
test_util_file
|
|
test_visit
|
|
test_object_iterator)
|
|
|
|
add_executable(${TESTNAME} ${TESTNAME}.c)
|
|
if(${TESTNAME} STREQUAL test_strerror OR ${TESTNAME} STREQUAL test_util_file)
|
|
# For output consistency, we need _json_c_strerror() in some tests:
|
|
target_sources(${TESTNAME} PRIVATE ../strerror_override.c)
|
|
endif()
|
|
add_test(NAME ${TESTNAME} COMMAND ${PROJECT_SOURCE_DIR}/tests/${TESTNAME}.test)
|
|
|
|
# XXX using the non-target_ versions of these doesn't work :(
|
|
target_include_directories(
|
|
${TESTNAME}
|
|
PUBLIC
|
|
${CMAKE_CURRENT_LIST_DIR}
|
|
)
|
|
target_link_libraries(
|
|
${TESTNAME}
|
|
PRIVATE
|
|
${PROJECT_NAME}
|
|
)
|
|
|
|
endforeach(TESTNAME)
|