Compare commits

..
7 Commits
56 changed files with 549 additions and 1612 deletions

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@ Coding Style
------------ ------------
The coding style has been discussed in [#24](https://github.com/DaveGamble/cJSON/issues/24). The basics are: The coding style has been discussed in [#24](https://github.com/DaveGamble/cJSON/issues/24). The basics are:
* Use 4 spaces for indentation * Use 4 tabs for indentation
* No oneliners (conditions, loops, variable declarations ...) * No oneliners (conditions, loops, variable declarations ...)
* Always use parenthesis for control structures * Always use parenthesis for control structures
* Don't implicitly rely on operator precedence, use round brackets in expressions. e.g. `(a > b) && (c < d)` instead of `a>b && c<d` * Don't implicitly rely on operator precedence, use round brackets in expressions. e.g. `(a > b) && (c < d)` instead of `a>b && c<d`
-1
View File
@@ -13,4 +13,3 @@ cJSON_test_utils
libcjson.so.* libcjson.so.*
libcjson_utils.so.* libcjson_utils.so.*
*.orig *.orig
.vscode
+1 -1
View File
@@ -23,6 +23,6 @@ addons:
script: script:
- mkdir build - mkdir build
- cd build - cd build
- cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_VALGRIND="${VALGRIND}" -DENABLE_SAFE_STACK="${VALGRIND}" -DENABLE_SANITIZERS="${SANITIZERS}" - cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_VALGRIND="${VALGRIND}" -DENABLE_SANITIZERS="${SANITIZERS}"
- make - make
- make test CTEST_OUTPUT_ON_FAILURE=On - make test CTEST_OUTPUT_ON_FAILURE=On
-44
View File
@@ -1,47 +1,3 @@
1.6.0
=====
Features:
---------
* You can now build cJSON as both shared and static library at once with CMake using `-DBUILD_SHARED_AND_STATIC_LIBS=On`, see #178
* UTF-8 byte order marks are now ignored, see #184
* Locales can now be disabled with the option `-DENABLE_LOCALES=Off`, see #202, thanks @Casperinous
* Better support for MSVC and Visual Studio
Other Changes:
--------------
* Add the new warnings `-Wswitch-enum`, `-Wused-but-makred-unused`, `-Wmissing-variable-declarations`, `-Wunused-macro`
* More number printing tests.
* Continuous integration testing with AppVeyor (semi automatic at this point), thanks @simon-p-r
1.5.9
=====
* Set the global error pointer even if `return_parse_end` is passed to `cJSON_ParseWithOpts`. See #200, thanks @rmallins
1.5.8
=====
* Fix `make test` in the Makefile, thanks @YanhaoMo for reporting this (#195)
1.5.7
=====
Fixes:
------
* Fix a bug where realloc failing would return a pointer to an invalid memory address. This is a security issue as it could potentially be used by an attacker to write to arbitrary memory addresses. (see #189), fixed in (954d61e5e7cb9dc6c480fc28ac1cdceca07dd5bd), big thanks @timothyjohncarney for reporting this issue
* Fix a spelling mistake in the AFL fuzzer dictionary (#185), thanks @jwilk
1.5.6
=====
Fixes:
------
* Make cJSON a lot more tolerant about passing NULL pointers to its functions, it should now fail safely instead of dereferencing the pointer. (#183) Thanks @msichal for reporting #182
1.5.5
=====
Fixes:
------
* Fix pointers to nested arrays in cJSON_Utils (9abe75e072050f34732a7169740989a082b65134)
* Fix an error with case sensitivity handling in cJSON_Utils (b9cc911831b0b3e1bb72f142389428e59f882b38)
* Fix cJSON_Compare for arrays that are prefixes of the other and objects that are a subset of the other (03ba72faec115160d1f3aea5582d9b6af5d3e473) See #180, thanks @zhengqb for reporting
1.5.4 1.5.4
===== =====
Fixes: Fixes:
+4 -54
View File
@@ -6,8 +6,8 @@ include(GNUInstallDirs)
project(cJSON C) project(cJSON C)
set(PROJECT_VERSION_MAJOR 1) set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 6) set(PROJECT_VERSION_MINOR 5)
set(PROJECT_VERSION_PATCH 0) set(PROJECT_VERSION_PATCH 4)
set(CJSON_VERSION_SO 1) set(CJSON_VERSION_SO 1)
set(CJSON_UTILS_VERSION_SO 1) set(CJSON_UTILS_VERSION_SO 1)
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
@@ -16,9 +16,8 @@ set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT
set(custom_compiler_flags) set(custom_compiler_flags)
include(CheckCCompilerFlag) include(CheckCCompilerFlag)
option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags" ON) option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags for Clang and GCC" ON)
if (ENABLE_CUSTOM_COMPILER_FLAGS) if (ENABLE_CUSTOM_COMPILER_FLAGS)
if (("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU"))
list(APPEND custom_compiler_flags list(APPEND custom_compiler_flags
-std=c89 -std=c89
-pedantic -pedantic
@@ -48,14 +47,6 @@ if (ENABLE_CUSTOM_COMPILER_FLAGS)
-Wused-but-marked-unused -Wused-but-marked-unused
-Wswitch-enum -Wswitch-enum
) )
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
list(APPEND custom_compiler_flags
/GS
/Za
/sdl
/W4
)
endif()
endif() endif()
option(ENABLE_SANITIZERS "Enables AddressSanitizer and UndefinedBehaviorSanitizer." OFF) option(ENABLE_SANITIZERS "Enables AddressSanitizer and UndefinedBehaviorSanitizer." OFF)
@@ -73,16 +64,6 @@ if (ENABLE_SANITIZERS)
) )
endif() endif()
option(ENABLE_SAFE_STACK "Enables the SafeStack instrumentation pass by the Code Pointer Integrity Project" OFF)
if (ENABLE_SAFE_STACK)
if (ENABLE_SANITIZERS)
message(FATAL_ERROR "ENABLE_SAFE_STACK cannot be used in combination with ENABLE_SANITIZERS")
endif()
list(APPEND custom_compiler_flags
-fsanitize=safe-stack
)
endif()
option(ENABLE_PUBLIC_SYMBOLS "Export library symbols." On) option(ENABLE_PUBLIC_SYMBOLS "Export library symbols." On)
if (ENABLE_PUBLIC_SYMBOLS) if (ENABLE_PUBLIC_SYMBOLS)
list(APPEND custom_compiler_flags -fvisibility=hidden) list(APPEND custom_compiler_flags -fvisibility=hidden)
@@ -122,17 +103,7 @@ set(CJSON_LIB cjson)
file(GLOB HEADERS cJSON.h) file(GLOB HEADERS cJSON.h)
set(SOURCES cJSON.c) set(SOURCES cJSON.c)
option(BUILD_SHARED_AND_STATIC_LIBS "Build both shared and static libraries" Off) add_library("${CJSON_LIB}" "${HEADERS}" "${SOURCES}")
if (NOT BUILD_SHARED_AND_STATIC_LIBS)
add_library("${CJSON_LIB}" "${HEADERS}" "${SOURCES}")
else()
# See https://cmake.org/Wiki/CMake_FAQ#How_do_I_make_my_shared_and_static_libraries_have_the_same_root_name.2C_but_different_suffixes.3F
add_library("${CJSON_LIB}" SHARED "${HEADERS}" "${SOURCES}")
add_library("${CJSON_LIB}-static" STATIC "${HEADERS}" "${SOURCES}")
set_target_properties("${CJSON_LIB}-static" PROPERTIES OUTPUT_NAME "${CJSON_LIB}")
set_target_properties("${CJSON_LIB}-static" PROPERTIES PREFIX "lib")
endif()
if (NOT WIN32) if (NOT WIN32)
target_link_libraries("${CJSON_LIB}" m) target_link_libraries("${CJSON_LIB}" m)
endif() endif()
@@ -143,9 +114,6 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson.pc.in"
install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson") install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(TARGETS "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_LIB}") install(TARGETS "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_LIB}")
if (BUILD_SHARED_AND_STATIC_LIBS)
install(TARGETS "${CJSON_LIB}-static" DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif()
if(ENABLE_TARGET_EXPORT) if(ENABLE_TARGET_EXPORT)
# export library information for CMake projects # export library information for CMake projects
install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON") install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
@@ -164,25 +132,13 @@ if(ENABLE_CJSON_UTILS)
file(GLOB HEADERS_UTILS cJSON_Utils.h) file(GLOB HEADERS_UTILS cJSON_Utils.h)
set(SOURCES_UTILS cJSON_Utils.c) set(SOURCES_UTILS cJSON_Utils.c)
if (NOT BUILD_SHARED_AND_STATIC_LIBS)
add_library("${CJSON_UTILS_LIB}" "${HEADERS_UTILS}" "${SOURCES_UTILS}") add_library("${CJSON_UTILS_LIB}" "${HEADERS_UTILS}" "${SOURCES_UTILS}")
target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}") 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" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson_utils.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY) "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY)
install(TARGETS "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_UTILS_LIB}") install(TARGETS "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_UTILS_LIB}")
if (BUILD_SHARED_AND_STATIC_LIBS)
install(TARGETS "${CJSON_UTILS_LIB}-static" DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif()
install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson") install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
if(ENABLE_TARGET_EXPORT) if(ENABLE_TARGET_EXPORT)
@@ -234,11 +190,5 @@ if(ENABLE_CJSON_TEST)
DEPENDS ${TEST_CJSON}) DEPENDS ${TEST_CJSON})
endif() endif()
# Enable the use of locales
option(ENABLE_LOCALES "Enable the use of locales" ON)
if(ENABLE_LOCALES)
add_definitions(-DENABLE_LOCALES)
endif()
add_subdirectory(tests) add_subdirectory(tests)
add_subdirectory(fuzzing) add_subdirectory(fuzzing)
+2 -7
View File
@@ -1,14 +1,11 @@
Contributors Contributors
============ ============
Original Author: [Dave Gamble](https://github.com/DaveGamble)
Current Maintainer: [Max Bruckner](https://github.com/FSMaxB)
* [Ajay Bhargav](https://github.com/ajaybhargav) * [Ajay Bhargav](https://github.com/ajaybhargav)
* [Alper Akcan](https://github.com/alperakcan) * [Alper Akcan](https://github.com/alperakcan)
* [Anton Sergeev](https://github.com/anton-sergeev) * [Anton Sergeev](https://github.com/anton-sergeev)
* [Christian Schulze](https://github.com/ChristianSch) * [Christian Schulze](https://github.com/ChristianSch)
* [Casperinous](https://github.com/Casperinous) * [Dave Gamble](https://github.com/DaveGamble)
* [Debora Grosse](https://github.com/DeboraG) * [Debora Grosse](https://github.com/DeboraG)
* [dieyushi](https://github.com/dieyushi) * [dieyushi](https://github.com/dieyushi)
* [Dōngwén Huáng (黄东文)](https://github.com/DongwenHuang) * [Dōngwén Huáng (黄东文)](https://github.com/DongwenHuang)
@@ -18,13 +15,13 @@ Current Maintainer: [Max Bruckner](https://github.com/FSMaxB)
* Ian Mobley * Ian Mobley
* Irwan Djadjadi * Irwan Djadjadi
* [IvanVoid](https://github.com/npi3pak) * [IvanVoid](https://github.com/npi3pak)
* [Jakub Wilk](https://github.com/jwilk)
* [Jiri Zouhar](https://github.com/loigu) * [Jiri Zouhar](https://github.com/loigu)
* [Jonathan Fether](https://github.com/jfether) * [Jonathan Fether](https://github.com/jfether)
* [Julián Vásquez](https://github.com/juvasquezg) * [Julián Vásquez](https://github.com/juvasquezg)
* [Kevin Branigan](https://github.com/kbranigan) * [Kevin Branigan](https://github.com/kbranigan)
* [Kyle Chisholm](https://github.com/ChisholmKyle) * [Kyle Chisholm](https://github.com/ChisholmKyle)
* [Linus Wallgren](https://github.com/ecksun) * [Linus Wallgren](https://github.com/ecksun)
* [Max Bruckner](https://github.com/FSMaxB)
* Mike Pontillo * Mike Pontillo
* [Mike Jerris](https://github.com/mjerris) * [Mike Jerris](https://github.com/mjerris)
* [Mike Robinson](https://github.com/mhrobinson) * [Mike Robinson](https://github.com/mhrobinson)
@@ -32,11 +29,9 @@ Current Maintainer: [Max Bruckner](https://github.com/FSMaxB)
* [Pawel Winogrodzki](https://github.com/PawelWMS) * [Pawel Winogrodzki](https://github.com/PawelWMS)
* [prefetchnta](https://github.com/prefetchnta) * [prefetchnta](https://github.com/prefetchnta)
* [Rafael Leal Dias](https://github.com/rafaeldias) * [Rafael Leal Dias](https://github.com/rafaeldias)
* [Robin Mallinson](https://github.com/rmallins)
* [Rod Vagg](https://github.com/rvagg) * [Rod Vagg](https://github.com/rvagg)
* [Roland Meertens](https://github.com/rmeertens) * [Roland Meertens](https://github.com/rmeertens)
* [Romain Porte](https://github.com/MicroJoe) * [Romain Porte](https://github.com/MicroJoe)
* [Simon Ricaldone](https://github.com/simon-p-r)
* [Stephan Gatzka](https://github.com/gatzka) * [Stephan Gatzka](https://github.com/gatzka)
* [Weston Schmidt](https://github.com/schmidtw) * [Weston Schmidt](https://github.com/schmidtw)
+4 -3
View File
@@ -8,7 +8,7 @@ CJSON_TEST_SRC = cJSON.c test.c
LDLIBS = -lm LDLIBS = -lm
LIBVERSION = 1.6.0 LIBVERSION = 1.5.4
CJSON_SOVERSION = 1 CJSON_SOVERSION = 1
UTILS_SOVERSION = 1 UTILS_SOVERSION = 1
@@ -66,10 +66,11 @@ shared: $(CJSON_SHARED) $(UTILS_SHARED)
static: $(CJSON_STATIC) $(UTILS_STATIC) static: $(CJSON_STATIC) $(UTILS_STATIC)
tests: $(CJSON_TEST) tests: $(CJSON_TEST) $(UTILS_TEST)
test: tests test: tests
./$(CJSON_TEST) ./$(CJSON_TEST)
./$(UTILS_TEST)
.c.o: .c.o:
$(CC) -c $(R_CFLAGS) $< $(CC) -c $(R_CFLAGS) $<
@@ -149,4 +150,4 @@ clean:
$(RM) $(CJSON_OBJ) $(UTILS_OBJ) #delete object files $(RM) $(CJSON_OBJ) $(UTILS_OBJ) #delete object files
$(RM) $(CJSON_SHARED) $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO) $(CJSON_STATIC) #delete cJSON $(RM) $(CJSON_SHARED) $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO) $(CJSON_STATIC) #delete cJSON
$(RM) $(UTILS_SHARED) $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO) $(UTILS_STATIC) #delete cJSON_Utils $(RM) $(UTILS_SHARED) $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO) $(UTILS_STATIC) #delete cJSON_Utils
$(RM) $(CJSON_TEST) #delete test $(RM) $(CJSON_TEST) $(UTILS_TEST) #delete tests
+1 -4
View File
@@ -85,14 +85,11 @@ You can change the build process with a list of different options that you can p
* `-DENABLE_CJSON_TEST=On`: Enable building the tests. (on by default) * `-DENABLE_CJSON_TEST=On`: Enable building the tests. (on by default)
* `-DENABLE_CJSON_UTILS=On`: Enable building cJSON_Utils. (off by default) * `-DENABLE_CJSON_UTILS=On`: Enable building cJSON_Utils. (off by default)
* `-DENABLE_TARGET_EXPORT=On`: Enable the export of CMake targets. Turn off if it makes problems. (on by default) * `-DENABLE_TARGET_EXPORT=On`: Enable the export of CMake targets. Turn off if it makes problems. (on by default)
* `-DENABLE_CUSTOM_COMPILER_FLAGS=On`: Enable custom compiler flags (currently for Clang, GCC and MSVC). Turn off if it makes problems. (on by default) * `-DENABLE_CUSTOM_COMPILER_FLAGS=On`: Enable custom compiler flags (currently for Clang and GCC). Turn off if it makes problems. (on by default)
* `-DENABLE_VALGRIND=On`: Run tests with [valgrind](http://valgrind.org). (off by default) * `-DENABLE_VALGRIND=On`: Run tests with [valgrind](http://valgrind.org). (off by default)
* `-DENABLE_SANITIZERS=On`: Compile cJSON with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) enabled (if possible). (off by default) * `-DENABLE_SANITIZERS=On`: Compile cJSON with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) enabled (if possible). (off by default)
* `-DENABLE_SAFE_STACK`: Enable the [SafeStack](https://clang.llvm.org/docs/SafeStack.html) instrumentation pass. Currently only works with the Clang compiler. (off by default)
* `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default) * `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default)
* `-DBUILD_SHARED_AND_STATIC_LIBS=On`: Build both shared and static libraries. (off by default)
* `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation. * `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation.
* `-DENABLE_LOCALES=On`: Enable the usage of localeconv method. ( on by default )
If you are packaging cJSON for a distribution of Linux, you would probably take these steps for example: If you are packaging cJSON for a distribution of Linux, you would probably take these steps for example:
``` ```
-86
View File
@@ -1,86 +0,0 @@
os: Visual Studio 2015
# ENABLE_CUSTOM_COMPILER_FLAGS - on by default
# ENABLE_SANITIZERS - off by default
# ENABLE_PUBLIC_SYMBOLS - on by default
# BUILD_SHARED_LIBS - on by default
# ENABLE_TARGET_EXPORT - on by default
# ENABLE_CJSON_UTILS - off by default
# ENABLE_CJSON_TEST -on by default
# ENABLE_VALGRIND - off by default
# ENABLE_FUZZING - off by default
environment:
matrix:
- GENERATOR: "Visual Studio 14 2015"
BUILD_SHARED_LIBS: ON
ENABLE_CJSON_TEST: OFF
ENABLE_CJSON_UTILS: ON
- GENERATOR: "Visual Studio 14 2015"
BUILD_SHARED_LIBS: OFF
ENABLE_CJSON_TEST: OFF
ENABLE_CJSON_UTILS: ON
- GENERATOR: "Visual Studio 12 2013"
BUILD_SHARED_LIBS: ON
ENABLE_CJSON_TEST: OFF
ENABLE_CJSON_UTILS: ON
- GENERATOR: "Visual Studio 12 2013"
BUILD_SHARED_LIBS: OFF
ENABLE_CJSON_TEST: OFF
ENABLE_CJSON_UTILS: ON
- GENERATOR: "Visual Studio 11 2012"
BUILD_SHARED_LIBS: ON
ENABLE_CJSON_TEST: OFF
ENABLE_CJSON_UTILS: ON
- GENERATOR: "Visual Studio 11 2012"
BUILD_SHARED_LIBS: OFF
ENABLE_CJSON_TEST: OFF
ENABLE_CJSON_UTILS: ON
- GENERATOR: "Visual Studio 10 2010"
BUILD_SHARED_LIBS: ON
ENABLE_CJSON_TEST: OFF
ENABLE_CJSON_UTILS: ON
- GENERATOR: "Visual Studio 10 2010"
BUILD_SHARED_LIBS: OFF
ENABLE_CJSON_TEST: OFF
ENABLE_CJSON_UTILS: ON
- GENERATOR: "Visual Studio 9 2008"
BUILD_SHARED_LIBS: ON
ENABLE_CJSON_TEST: OFF
ENABLE_CJSON_UTILS: ON
- GENERATOR: "Visual Studio 9 2008"
BUILD_SHARED_LIBS: OFF
ENABLE_CJSON_TEST: OFF
ENABLE_CJSON_UTILS: ON
platform:
- x86
- x64
matrix:
exclude:
- platform: x64
GENERATOR: "Visual Studio 9 2008"
configuration:
- Release
build_script:
- ps: if($env:PLATFORM -eq "x64") { $env:CMAKE_GEN_SUFFIX=" Win64" }
- cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DENABLE_CJSON_TEST=%ENABLE_CJSON_TEST% -H. -Bbuild
- cmake --build build --config "%CONFIGURATION%"
on_failure:
- ps: if(Test-Path builds/CMakeFiles/CMakeOutput.log) { cat builds/CMakeFiles/CMakeOutput.log }
- ps: if(Test-Path builds/CMakeFiles/CMakeError.log) { cat builds/CMakeFiles/CMakeError.log }
+32 -153
View File
@@ -23,19 +23,9 @@
/* cJSON */ /* cJSON */
/* JSON parser in C. */ /* JSON parser in C. */
/* disable warnings about old C89 functions in MSVC */
#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
#define _CRT_SECURE_NO_DEPRECATE
#endif
#ifdef __GNUC__ #ifdef __GNUC__
#pragma GCC visibility push(default) #pragma GCC visibility push(default)
#endif #endif
#if defined(_MSC_VER)
#pragma warning (push)
/* disable warning about single line comments in system headers */
#pragma warning (disable : 4001)
#endif
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@@ -44,14 +34,8 @@
#include <float.h> #include <float.h>
#include <limits.h> #include <limits.h>
#include <ctype.h> #include <ctype.h>
#ifdef ENABLE_LOCALES
#include <locale.h> #include <locale.h>
#endif
#if defined(_MSC_VER)
#pragma warning (pop)
#endif
#ifdef __GNUC__ #ifdef __GNUC__
#pragma GCC visibility pop #pragma GCC visibility pop
#endif #endif
@@ -74,7 +58,7 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
} }
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ /* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 6) || (CJSON_VERSION_PATCH != 0) #if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 5) || (CJSON_VERSION_PATCH != 4)
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. #error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
#endif #endif
@@ -117,27 +101,7 @@ typedef struct internal_hooks
void *(*reallocate)(void *pointer, size_t size); void *(*reallocate)(void *pointer, size_t size);
} internal_hooks; } internal_hooks;
#if defined(_MSC_VER) static internal_hooks global_hooks = { malloc, free, realloc };
/* work around MSVC error C2322: '...' address of dillimport '...' is not static */
static void *internal_malloc(size_t size)
{
return malloc(size);
}
static void internal_free(void *pointer)
{
free(pointer);
}
static void *internal_realloc(void *pointer, size_t size)
{
return realloc(pointer, size);
}
#else
#define internal_malloc malloc
#define internal_free free
#define internal_realloc realloc
#endif
static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc };
static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks)
{ {
@@ -150,8 +114,7 @@ static unsigned char* cJSON_strdup(const unsigned char* string, const internal_h
} }
length = strlen((const char*)string) + sizeof(""); length = strlen((const char*)string) + sizeof("");
copy = (unsigned char*)hooks->allocate(length); if (!(copy = (unsigned char*)hooks->allocate(length)))
if (copy == NULL)
{ {
return NULL; return NULL;
} }
@@ -230,12 +193,8 @@ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item)
/* get the decimal point character of the current locale */ /* get the decimal point character of the current locale */
static unsigned char get_decimal_point(void) static unsigned char get_decimal_point(void)
{ {
#ifdef ENABLE_LOCALES
struct lconv *lconv = localeconv(); struct lconv *lconv = localeconv();
return (unsigned char) lconv->decimal_point[0]; return (unsigned char) lconv->decimal_point[0];
#else
return '.';
#endif
} }
typedef struct typedef struct
@@ -417,14 +376,6 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
{ {
/* reallocate with realloc if available */ /* reallocate with realloc if available */
newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize);
if (newbuffer == NULL)
{
p->hooks.deallocate(p->buffer);
p->length = 0;
p->buffer = NULL;
return NULL;
}
} }
else else
{ {
@@ -973,22 +924,6 @@ static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer)
return buffer; return buffer;
} }
/* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */
static parse_buffer *skip_utf8_bom(parse_buffer * const buffer)
{
if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0))
{
return NULL;
}
if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0))
{
buffer->offset += 3;
}
return buffer;
}
/* Parse an object - create a new root, and populate. */ /* Parse an object - create a new root, and populate. */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)
{ {
@@ -1015,7 +950,7 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return
goto fail; goto fail;
} }
if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) if (!parse_value(item, buffer_skip_whitespace(&buffer)))
{ {
/* parse failure. ep is set. */ /* parse failure. ep is set. */
goto fail; goto fail;
@@ -1062,9 +997,11 @@ fail:
{ {
*return_parse_end = (const char*)local_error.json + local_error.position; *return_parse_end = (const char*)local_error.json + local_error.position;
} }
else
{
global_error = local_error; global_error = local_error;
} }
}
return NULL; return NULL;
} }
@@ -1173,7 +1110,6 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON
if (!print_value(item, &p)) if (!print_value(item, &p))
{ {
global_hooks.deallocate(p.buffer);
return NULL; return NULL;
} }
@@ -1184,7 +1120,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buf, const i
{ {
printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
if ((len < 0) || (buf == NULL)) if (len < 0)
{ {
return false; return false;
} }
@@ -1251,6 +1187,7 @@ static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buf
return parse_object(item, input_buffer); return parse_object(item, input_buffer);
} }
return false; return false;
} }
@@ -1714,25 +1651,17 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
/* Get Array size/item / object item. */ /* Get Array size/item / object item. */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array)
{ {
cJSON *child = NULL; cJSON *c = array->child;
size_t size = 0; size_t i = 0;
while(c)
if (array == NULL)
{ {
return 0; i++;
} c = c->next;
child = array->child;
while(child != NULL)
{
size++;
child = child->next;
} }
/* FIXME: Can overflow here. Cannot be fixed without breaking the API */ /* FIXME: Can overflow here. Cannot be fixed without breaking the API */
return (int)size; return (int)i;
} }
static cJSON* get_array_item(const cJSON *array, size_t index) static cJSON* get_array_item(const cJSON *array, size_t index)
@@ -1817,23 +1746,16 @@ static void suffix_object(cJSON *prev, cJSON *item)
/* Utility for handling references. */ /* Utility for handling references. */
static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks)
{ {
cJSON *reference = NULL; cJSON *ref = cJSON_New_Item(hooks);
if (item == NULL) if (!ref)
{ {
return NULL; return NULL;
} }
memcpy(ref, item, sizeof(cJSON));
reference = cJSON_New_Item(hooks); ref->string = NULL;
if (reference == NULL) ref->type |= cJSON_IsReference;
{ ref->next = ref->prev = NULL;
return NULL; return ref;
}
memcpy(reference, item, sizeof(cJSON));
reference->string = NULL;
reference->type |= cJSON_IsReference;
reference->next = reference->prev = NULL;
return reference;
} }
/* Add item to array/object. */ /* Add item to array/object. */
@@ -1866,18 +1788,13 @@ CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item)
CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
{ {
if (item == NULL)
{
return;
}
/* call cJSON_AddItemToObjectCS for code reuse */ /* call cJSON_AddItemToObjectCS for code reuse */
cJSON_AddItemToObjectCS(object, (char*)cJSON_strdup((const unsigned char*)string, &global_hooks), item); cJSON_AddItemToObjectCS(object, (char*)cJSON_strdup((const unsigned char*)string, &global_hooks), item);
/* remove cJSON_StringIsConst flag */ /* remove cJSON_StringIsConst flag */
item->type &= ~cJSON_StringIsConst; item->type &= ~cJSON_StringIsConst;
} }
#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) #if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
#pragma GCC diagnostic push #pragma GCC diagnostic push
#endif #endif
#ifdef __GNUC__ #ifdef __GNUC__
@@ -1887,7 +1804,7 @@ CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSO
/* Add an item to an object with constant string as key */ /* Add an item to an object with constant string as key */
CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item)
{ {
if ((item == NULL) || (string == NULL)) if (!item)
{ {
return; return;
} }
@@ -1899,27 +1816,17 @@ CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJ
item->type |= cJSON_StringIsConst; item->type |= cJSON_StringIsConst;
cJSON_AddItemToArray(object, item); cJSON_AddItemToArray(object, item);
} }
#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) #if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item)
{ {
if (array == NULL)
{
return;
}
cJSON_AddItemToArray(array, create_reference(item, &global_hooks)); cJSON_AddItemToArray(array, create_reference(item, &global_hooks));
} }
CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item)
{ {
if ((object == NULL) || (string == NULL))
{
return;
}
cJSON_AddItemToObject(object, string, create_reference(item, &global_hooks)); cJSON_AddItemToObject(object, string, create_reference(item, &global_hooks));
} }
@@ -2024,7 +1931,7 @@ CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newit
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
{ {
if ((parent == NULL) || (replacement == NULL) || (item == NULL)) if ((parent == NULL) || (replacement == NULL))
{ {
return false; return false;
} }
@@ -2069,7 +1976,7 @@ CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newi
static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive)
{ {
if ((replacement == NULL) || (string == NULL)) if (replacement == NULL)
{ {
return false; return false;
} }
@@ -2232,7 +2139,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
cJSON *p = NULL; cJSON *p = NULL;
cJSON *a = NULL; cJSON *a = NULL;
if ((count < 0) || (numbers == NULL)) if (count < 0)
{ {
return NULL; return NULL;
} }
@@ -2267,7 +2174,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count)
cJSON *p = NULL; cJSON *p = NULL;
cJSON *a = NULL; cJSON *a = NULL;
if ((count < 0) || (numbers == NULL)) if (count < 0)
{ {
return NULL; return NULL;
} }
@@ -2303,7 +2210,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
cJSON *p = NULL; cJSON *p = NULL;
cJSON *a = NULL; cJSON *a = NULL;
if ((count < 0) || (numbers == NULL)) if (count < 0)
{ {
return NULL; return NULL;
} }
@@ -2339,7 +2246,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count)
cJSON *p = NULL; cJSON *p = NULL;
cJSON *a = NULL; cJSON *a = NULL;
if ((count < 0) || (strings == NULL)) if (count < 0)
{ {
return NULL; return NULL;
} }
@@ -2451,12 +2358,6 @@ fail:
CJSON_PUBLIC(void) cJSON_Minify(char *json) CJSON_PUBLIC(void) cJSON_Minify(char *json)
{ {
unsigned char *into = (unsigned char*)json; unsigned char *into = (unsigned char*)json;
if (json == NULL)
{
return;
}
while (*json) while (*json)
{ {
if (*json == ' ') if (*json == ' ')
@@ -2692,22 +2593,16 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons
b_element = b_element->next; b_element = b_element->next;
} }
/* one of the arrays is longer than the other */
if (a_element != b_element) {
return false;
}
return true; return true;
} }
case cJSON_Object: case cJSON_Object:
{ {
cJSON *a_element = NULL; cJSON *a_element = NULL;
cJSON *b_element = NULL;
cJSON_ArrayForEach(a_element, a) cJSON_ArrayForEach(a_element, a)
{ {
/* TODO This has O(n^2) runtime, which is horrible! */ /* TODO This has O(n^2) runtime, which is horrible! */
b_element = get_object_item(b, a_element->string, case_sensitive); cJSON *b_element = get_object_item(b, a_element->string, case_sensitive);
if (b_element == NULL) if (b_element == NULL)
{ {
return false; return false;
@@ -2719,22 +2614,6 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons
} }
} }
/* doing this twice, once on a and b to prevent true comparison if a subset of b
* TODO: Do this the proper way, this is just a fix for now */
cJSON_ArrayForEach(b_element, b)
{
a_element = get_object_item(a, b_element->string, case_sensitive);
if (a_element == NULL)
{
return false;
}
if (!cJSON_Compare(b_element, a_element, case_sensitive))
{
return false;
}
}
return true; return true;
} }
+6 -6
View File
@@ -30,8 +30,8 @@ extern "C"
/* project version */ /* project version */
#define CJSON_VERSION_MAJOR 1 #define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 6 #define CJSON_VERSION_MINOR 5
#define CJSON_VERSION_PATCH 0 #define CJSON_VERSION_PATCH 4
#include <stddef.h> #include <stddef.h>
@@ -138,10 +138,6 @@ CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ /* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ /* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */ /* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */ /* Render a cJSON entity to text for transfer/storage without any formatting. */
@@ -232,6 +228,10 @@ The item->next and ->prev pointers are always zero on return from Duplicate. */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error. If not, then cJSON_GetErrorPtr() does the job. */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(void) cJSON_Minify(char *json); CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Macros for creating things quickly. */ /* Macros for creating things quickly. */
+8 -71
View File
@@ -20,32 +20,13 @@
THE SOFTWARE. THE SOFTWARE.
*/ */
/* disable warnings about old C89 functions in MSVC */
#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
#define _CRT_SECURE_NO_DEPRECATE
#endif
#ifdef __GNUCC__
#pragma GCC visibility push(default) #pragma GCC visibility push(default)
#endif
#if defined(_MSC_VER)
#pragma warning (push)
/* disable warning about single line comments in system headers */
#pragma warning (disable : 4001)
#endif
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
#if defined(_MSC_VER)
#pragma warning (pop)
#endif
#ifdef __GNUCC__
#pragma GCC visibility pop #pragma GCC visibility pop
#endif
#include "cJSON_Utils.h" #include "cJSON_Utils.h"
@@ -181,11 +162,6 @@ CJSON_PUBLIC(char *) cJSONUtils_FindPointerFromObjectTo(const cJSON * const obje
size_t child_index = 0; size_t child_index = 0;
cJSON *current_child = 0; cJSON *current_child = 0;
if ((object == NULL) || (target == NULL))
{
return NULL;
}
if (object == target) if (object == target)
{ {
/* found */ /* found */
@@ -281,12 +257,6 @@ static cJSON_bool decode_array_index_from_pointer(const unsigned char * const po
static cJSON *get_item_from_pointer(cJSON * const object, const char * pointer, const cJSON_bool case_sensitive) static cJSON *get_item_from_pointer(cJSON * const object, const char * pointer, const cJSON_bool case_sensitive)
{ {
cJSON *current_element = object; cJSON *current_element = object;
if (pointer == NULL)
{
return NULL;
}
/* follow path of the pointer */ /* follow path of the pointer */
while ((pointer[0] == '/') && (current_element != NULL)) while ((pointer[0] == '/') && (current_element != NULL))
{ {
@@ -309,18 +279,17 @@ static cJSON *get_item_from_pointer(cJSON * const object, const char * pointer,
{ {
current_element = current_element->next; current_element = current_element->next;
} }
}
else
{
return NULL;
}
/* skip to the next path token or end of string */ /* skip to the next path token or end of string */
while ((pointer[0] != '\0') && (pointer[0] != '/')) while ((pointer[0] != '\0') && (pointer[0] != '/'))
{ {
pointer++; pointer++;
} }
} }
else
{
return NULL;
}
}
return current_element; return current_element;
} }
@@ -569,10 +538,6 @@ static cJSON *sort_list(cJSON *list, const cJSON_bool case_sensitive)
static void sort_object(cJSON * const object, const cJSON_bool case_sensitive) static void sort_object(cJSON * const object, const cJSON_bool case_sensitive)
{ {
if (object == NULL)
{
return;
}
object->child = sort_list(object->child, case_sensitive); object->child = sort_list(object->child, case_sensitive);
} }
@@ -976,15 +941,8 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
} }
} }
else if (cJSON_IsObject(parent)) else if (cJSON_IsObject(parent))
{
if (case_sensitive)
{
cJSON_DeleteItemFromObjectCaseSensitive(parent, (char*)child_pointer);
}
else
{ {
cJSON_DeleteItemFromObject(parent, (char*)child_pointer); cJSON_DeleteItemFromObject(parent, (char*)child_pointer);
}
cJSON_AddItemToObject(parent, (char*)child_pointer, value); cJSON_AddItemToObject(parent, (char*)child_pointer, value);
value = NULL; value = NULL;
} }
@@ -1062,14 +1020,7 @@ CJSON_PUBLIC(int) cJSONUtils_ApplyPatchesCaseSensitive(cJSON * const object, con
static void compose_patch(cJSON * const patches, const unsigned char * const operation, const unsigned char * const path, const unsigned char *suffix, const cJSON * const value) static void compose_patch(cJSON * const patches, const unsigned char * const operation, const unsigned char * const path, const unsigned char *suffix, const cJSON * const value)
{ {
cJSON *patch = NULL; cJSON *patch = cJSON_CreateObject();
if ((patches == NULL) || (operation == NULL) || (path == NULL))
{
return;
}
patch = cJSON_CreateObject();
if (patch == NULL) if (patch == NULL)
{ {
return; return;
@@ -1247,14 +1198,7 @@ static void create_patches(cJSON * const patches, const unsigned char * const pa
CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON * const from, cJSON * const to) CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON * const from, cJSON * const to)
{ {
cJSON *patches = NULL; cJSON *patches = cJSON_CreateArray();
if ((from == NULL) || (to == NULL))
{
return NULL;
}
patches = cJSON_CreateArray();
create_patches(patches, (const unsigned char*)"", from, to, false); create_patches(patches, (const unsigned char*)"", from, to, false);
return patches; return patches;
@@ -1262,14 +1206,7 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON * const from, cJSON * con
CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatchesCaseSensitive(cJSON * const from, cJSON * const to) CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatchesCaseSensitive(cJSON * const from, cJSON * const to)
{ {
cJSON *patches = NULL; cJSON *patches = cJSON_CreateArray();
if ((from == NULL) || (to == NULL))
{
return NULL;
}
patches = cJSON_CreateArray();
create_patches(patches, (const unsigned char*)"", from, to, true); create_patches(patches, (const unsigned char*)"", from, to, true);
return patches; return patches;
+1
View File
@@ -1 +1,2 @@
afl-build afl-build
libfuzzer-build
+10 -7
View File
@@ -5,23 +5,26 @@ if (ENABLE_FUZZING)
message(FATAL_ERROR "Couldn't find afl-fuzz.") message(FATAL_ERROR "Couldn't find afl-fuzz.")
endif() endif()
option(ENABLE_LIBFUZZER "Enable fuzzing with libfuzzer (only works with llvm 5 which hasn't been release at this point)" Off)
if (ENABLE_LIBFUZZER)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=fuzzer")
endif()
add_library(fuzz-target fuzz-target.c)
target_link_libraries(fuzz-target "${CJSON_LIB}")
add_executable(afl-main afl.c) add_executable(afl-main afl.c)
target_link_libraries(afl-main "${CJSON_LIB}") target_link_libraries(afl-main fuzz-target)
if (NOT ENABLE_SANITIZERS) if (NOT ENABLE_SANITIZERS)
message(FATAL_ERROR "Enable sanitizers with -DENABLE_SANITIZERS=On to do fuzzing.") message(FATAL_ERROR "Enable sanitizers with -DENABLE_SANITIZERS=On to do fuzzing.")
endif() 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") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
add_custom_target(afl 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}" 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" "@@"
DEPENDS afl-main) DEPENDS afl-main)
+36 -61
View File
@@ -24,54 +24,71 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../cJSON.h" #include "fuzz-target.h"
static char *read_file(const char *filename) static char *read_file(const char *filename, size_t *size)
{ {
FILE *file = NULL; FILE *file = NULL;
long length = 0; long length = 0;
char *content = NULL; char *content = NULL;
size_t read_chars = 0; size_t read_chars = 0;
if (size == NULL)
{
goto fail;
}
/* open in read binary mode */ /* open in read binary mode */
file = fopen(filename, "rb"); file = fopen(filename, "rb");
if (file == NULL) if (file == NULL)
{ {
goto cleanup; goto fail;
} }
/* get the length */ /* get the length */
if (fseek(file, 0, SEEK_END) != 0) if (fseek(file, 0, SEEK_END) != 0)
{ {
goto cleanup; goto fail;
} }
length = ftell(file); length = ftell(file);
if (length < 0) if (length < 0)
{ {
goto cleanup; goto fail;
} }
if (fseek(file, 0, SEEK_SET) != 0) if (fseek(file, 0, SEEK_SET) != 0)
{ {
goto cleanup; goto fail;
} }
/* allocate content buffer */ /* allocate content buffer */
content = (char*)malloc((size_t)length + sizeof("")); content = (char*)malloc((size_t)length + sizeof(""));
if (content == NULL) if (content == NULL)
{ {
goto cleanup; goto fail;
} }
/* read the file into memory */ /* read the file into memory */
read_chars = fread(content, sizeof(char), (size_t)length, file); read_chars = fread(content, sizeof(char), (size_t)length, file);
if ((long)read_chars != length) if ((long)read_chars != length)
{ {
free(content); goto fail;
content = NULL;
goto cleanup;
} }
content[read_chars] = '\0'; content[read_chars] = '\0';
*size = read_chars + sizeof("");
goto cleanup;
fail:
if (size != NULL)
{
*size = 0;
}
if (content != NULL)
{
free(content);
content = NULL;
}
cleanup: cleanup:
if (file != NULL) if (file != NULL)
@@ -85,79 +102,39 @@ cleanup:
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
const char *filename = NULL; const char *filename = NULL;
cJSON *item = NULL;
char *json = NULL; char *json = NULL;
int status = EXIT_FAILURE; int status = EXIT_FAILURE;
char *printed_json = NULL; char *printed_json = NULL;
if ((argc < 2) || (argc > 3)) if (argc != 2)
{ {
printf("Usage:\n"); printf("Usage:\n");
printf("%s input_file [enable_printing]\n", argv[0]); printf("%s input_file\n", argv[0]);
printf("\t input_file: file containing the test data\n"); printf("\t input_file: file containing the test data\n");
printf("\t enable_printing: print after parsing, 'yes' or 'no', defaults to 'no'\n");
goto cleanup; goto cleanup;
} }
filename = argv[1]; filename = argv[1];
#if __AFL_HAVE_MANUAL_CONTROL #if defined(__AFL_HAVE_MANUAL_CONTROL) && __AFL_HAVE_MANUAL_CONTROL
while (__AFL_LOOP(1000)) while (__AFL_LOOP(1000))
{ {
#else
{
#endif #endif
size_t size = 0;
status = EXIT_SUCCESS; status = EXIT_SUCCESS;
json = read_file(filename); json = read_file(filename, &size);
if ((json == NULL) || (json[0] == '\0') || (json[1] == '\0')) if ((json == NULL) || (json[0] == '\0') || (json[1] == '\0'))
{ {
status = EXIT_FAILURE; status = EXIT_FAILURE;
goto cleanup; goto cleanup;
} }
item = cJSON_Parse(json + 2);
if (item == NULL)
{
goto cleanup;
}
if ((argc == 3) && (strncmp(argv[2], "yes", 3) == 0)) LLVMFuzzerTestOneInput(json, size);
{
int do_format = 0;
if (json[1] == 'f')
{
do_format = 1;
}
if (json[0] == 'b') cleanup:
{
/* buffered printing */
printed_json = cJSON_PrintBuffered(item, 1, do_format);
}
else
{
/* unbuffered printing */
if (do_format)
{
printed_json = cJSON_Print(item);
}
else
{
printed_json = cJSON_PrintUnformatted(item);
}
}
if (printed_json == NULL)
{
status = EXIT_FAILURE;
goto cleanup;
}
printf("%s\n", printed_json);
}
cleanup:
if (item != NULL)
{
cJSON_Delete(item);
item = NULL;
}
if (json != NULL) if (json != NULL)
{ {
free(json); free(json);
@@ -168,9 +145,7 @@ cleanup:
free(printed_json); free(printed_json);
printed_json = NULL; printed_json = NULL;
} }
#if __AFL_HAVE_MANUAL_CONTROL
} }
#endif
return status; return status;
} }
+129
View File
@@ -0,0 +1,129 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <string.h>
#include <stdio.h>
#include "fuzz-target.h"
#include "../cJSON.h"
static void minify(const unsigned char *data, size_t size)
{
unsigned char *copied_data = (unsigned char*)malloc(size);
if (copied_data == NULL)
{
return;
}
memcpy(copied_data, data, size);
cJSON_Minify((char*)copied_data);
free(copied_data);
return;
}
static void printing(cJSON *json, unsigned char format_setting, unsigned char buffered_setting)
{
unsigned char *printed = NULL;
if (buffered_setting == '1')
{
printed = (unsigned char*)cJSON_PrintBuffered(json, 1, (format_setting == '1'));
}
else
{
if (format_setting == '1')
{
printed = (unsigned char*)cJSON_Print(json);
}
else
{
printed = (unsigned char*)cJSON_PrintUnformatted(json);
}
}
if (printed != NULL)
{
free(printed);
}
}
extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
{
unsigned char minify_setting = '\0'; /* minify instead of parsing */
unsigned char require_zero_setting = '\0'; /* zero termination required */
unsigned char format_setting = '\0'; /* formatted printing */
unsigned char buffered_setting = '\0'; /* buffered printing */
const size_t data_offset = 4;
cJSON *json = NULL;
/* don't work with NULL or without mode selector */
if ((data == NULL) || (size < data_offset))
{
return 0;
}
/* get configuration from the beginning of the test case */
minify_setting = data[0];
require_zero_setting = data[1];
format_setting = data[2];
buffered_setting = data[3];
/* check if settings are valid */
if ((minify_setting != '0') && (minify_setting != '1'))
{
return 0;
}
if ((require_zero_setting != '0') && (require_zero_setting != '1'))
{
return 0;
}
if ((format_setting != '0') && (format_setting != '1'))
{
return 0;
}
if ((buffered_setting != '0') && (buffered_setting != '1'))
{
return 0;
}
if (minify_setting == '1')
{
minify(data + data_offset, size);
return 0;
}
json = cJSON_ParseWithOpts((const char*)data + data_offset, NULL, (require_zero_setting == '1'));
if (json == NULL)
{
return 0;
}
printing(json, format_setting, buffered_setting);
free(json);
return 0;
}
+30
View File
@@ -0,0 +1,30 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdlib.h>
#ifndef CJSON_FUZZ_TARGET
#define CJSON_FUZZ_TARGET
extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
#endif /* CJSON_FUZZ_TARGET */
+1 -1
View File
@@ -1,4 +1,4 @@
bf{ 0111{
"glossary": { "glossary": {
"title": "example glossary", "title": "example glossary",
"GlossDiv": { "GlossDiv": {
+1 -1
View File
@@ -1 +1 @@
bf["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] 0111["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
+1 -1
View File
@@ -1,4 +1,4 @@
bf{ 0111{
"name": "Jack (\"Bee\") Nimble", "name": "Jack (\"Bee\") Nimble",
"format": {"type": "rect", "format": {"type": "rect",
"width": 1920, "width": 1920,
+1 -1
View File
@@ -1,4 +1,4 @@
bf{"menu": { 0111{"menu": {
"id": "file", "id": "file",
"value": "File", "value": "File",
"popup": { "popup": {
+1 -1
View File
@@ -1,4 +1,4 @@
bf{"widget": { 0111{"widget": {
"debug": "on", "debug": "on",
"window": { "window": {
"title": "Sample Konfabulator Widget", "title": "Sample Konfabulator Widget",
+1 -1
View File
@@ -1,4 +1,4 @@
bu{"widget": { 0101{"widget": {
"debug": "on", "debug": "on",
"window": { "window": {
"title": "Sample Konfabulator Widget", "title": "Sample Konfabulator Widget",
+1 -1
View File
@@ -1,4 +1,4 @@
uf{"widget": { 0110{"widget": {
"debug": "on", "debug": "on",
"window": { "window": {
"title": "Sample Konfabulator Widget", "title": "Sample Konfabulator Widget",
+1 -1
View File
@@ -1,4 +1,4 @@
uu{"widget": { 0100{"widget": {
"debug": "on", "debug": "on",
"window": { "window": {
"title": "Sample Konfabulator Widget", "title": "Sample Konfabulator Widget",
+1 -1
View File
@@ -1,4 +1,4 @@
bf{"web-app": { 0111{"web-app": {
"servlet": [ "servlet": [
{ {
"servlet-name": "cofaxCDS", "servlet-name": "cofaxCDS",
+1 -1
View File
@@ -1,4 +1,4 @@
bf{"menu": { 0111{"menu": {
"header": "SVG Viewer", "header": "SVG Viewer",
"items": [ "items": [
{"id": "Open"}, {"id": "Open"},
+1 -1
View File
@@ -1,4 +1,4 @@
bf<!DOCTYPE html> 0111<!DOCTYPE html>
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
+1 -1
View File
@@ -1,4 +1,4 @@
bf[ 0111[
{ {
"precision": "zip", "precision": "zip",
"Latitude": 37.7668, "Latitude": 37.7668,
+1 -1
View File
@@ -1,4 +1,4 @@
bf{ 0111{
"Image": { "Image": {
"Width": 800, "Width": 800,
"Height": 600, "Height": 600,
+1 -1
View File
@@ -1,4 +1,4 @@
bf[ 0111[
[0, -1, 0], [0, -1, 0],
[1, 0, 0], [1, 0, 0],
[0, 0, 1] [0, 0, 1]
+2 -2
View File
@@ -25,8 +25,8 @@ escape_sequence_r="\\r"
escape_sequence_t="\\t" escape_sequence_t="\\t"
escape_sequence_quote="\\\"" escape_sequence_quote="\\\""
escape_sequence_backslash="\\\\" escape_sequence_backslash="\\\\"
escape_sequence_slash="\\/" escapce_sequence_slash="\\/"
escape_sequence_utf16_base="\\u" escpae_sequence_utf16_base="\\u"
escape_sequence_utf16="\\u12ab" escape_sequence_utf16="\\u12ab"
number_integer="1" number_integer="1"
+9
View File
@@ -0,0 +1,9 @@
#!/bin/bash
mkdir -p libfuzzer-build || exit 1
cd libfuzzer-build || exit 1
#cleanup
rm -r -- *
CC=clang cmake ../.. -DENABLE_FUZZING=On -DENABLE_SANITIZERS=On -DBUILD_SHARED_LIBS=Off -DCMAKE_BUILD_TYPE=Debug -DENABLE_LIBFUZZER=On
make fuzz-target
+2 -3
View File
@@ -66,7 +66,7 @@ if(ENABLE_CJSON_TEST)
message(WARNING "Valgrind couldn't be found.") message(WARNING "Valgrind couldn't be found.")
unset(MEMORYCHECK_COMMAND) unset(MEMORYCHECK_COMMAND)
else() else()
set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1 --suppressions=${CMAKE_CURRENT_SOURCE_DIR}/../valgrind.supp) set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1)
endif() endif()
endif() endif()
@@ -92,8 +92,7 @@ if(ENABLE_CJSON_TEST)
set (cjson_utils_tests set (cjson_utils_tests
json_patch_tests json_patch_tests
old_utils_tests old_utils_tests)
misc_utils_tests)
foreach (cjson_utils_test ${cjson_utils_tests}) foreach (cjson_utils_test ${cjson_utils_tests})
add_executable("${cjson_utils_test}" "${cjson_utils_test}.c") add_executable("${cjson_utils_test}" "${cjson_utils_test}.c")
-13
View File
@@ -148,10 +148,6 @@ static void cjson_compare_should_compare_arrays(void)
TEST_ASSERT_FALSE(compare_from_string("[true,null,42,\"string\",[],{}]", "[false, true, null, 42, \"string\", [], {}]", true)); TEST_ASSERT_FALSE(compare_from_string("[true,null,42,\"string\",[],{}]", "[false, true, null, 42, \"string\", [], {}]", true));
TEST_ASSERT_FALSE(compare_from_string("[true,null,42,\"string\",[],{}]", "[false, true, null, 42, \"string\", [], {}]", false)); TEST_ASSERT_FALSE(compare_from_string("[true,null,42,\"string\",[],{}]", "[false, true, null, 42, \"string\", [], {}]", false));
/* Arrays that are a prefix of another array */
TEST_ASSERT_FALSE(compare_from_string("[1,2,3]", "[1,2]", true));
TEST_ASSERT_FALSE(compare_from_string("[1,2,3]", "[1,2]", false));
} }
static void cjson_compare_should_compare_objects(void) static void cjson_compare_should_compare_objects(void)
@@ -175,15 +171,6 @@ static void cjson_compare_should_compare_objects(void)
"{\"Flse\": false, \"true\": true, \"null\": null, \"number\": 42, \"string\": \"string\", \"array\": [], \"object\": {}}", "{\"Flse\": false, \"true\": true, \"null\": null, \"number\": 42, \"string\": \"string\", \"array\": [], \"object\": {}}",
"{\"true\": true, \"false\": false, \"null\": null, \"number\": 42, \"string\": \"string\", \"array\": [], \"object\": {}}", "{\"true\": true, \"false\": false, \"null\": null, \"number\": 42, \"string\": \"string\", \"array\": [], \"object\": {}}",
false)); false));
/* test objects that are a subset of each other */
TEST_ASSERT_FALSE(compare_from_string(
"{\"one\": 1, \"two\": 2}",
"{\"one\": 1, \"two\": 2, \"three\": 3}",
true))
TEST_ASSERT_FALSE(compare_from_string(
"{\"one\": 1, \"two\": 2}",
"{\"one\": 1, \"two\": 2, \"three\": 3}",
false))
} }
int main(void) int main(void)
-130
View File
@@ -324,132 +324,6 @@ static void cjson_replace_item_in_object_should_preserve_name(void)
cJSON_Delete(replacement); cJSON_Delete(replacement);
} }
static void cjson_functions_shouldnt_crash_with_null_pointers(void)
{
char buffer[10];
cJSON *item = cJSON_CreateString("item");
cJSON_InitHooks(NULL);
TEST_ASSERT_NULL(cJSON_Parse(NULL));
TEST_ASSERT_NULL(cJSON_ParseWithOpts(NULL, NULL, true));
TEST_ASSERT_NULL(cJSON_Print(NULL));
TEST_ASSERT_NULL(cJSON_PrintUnformatted(NULL));
TEST_ASSERT_NULL(cJSON_PrintBuffered(NULL, 10, true));
TEST_ASSERT_FALSE(cJSON_PrintPreallocated(NULL, buffer, sizeof(buffer), true));
TEST_ASSERT_FALSE(cJSON_PrintPreallocated(item, NULL, 1, true));
cJSON_Delete(NULL);
cJSON_GetArraySize(NULL);
TEST_ASSERT_NULL(cJSON_GetArrayItem(NULL, 0));
TEST_ASSERT_NULL(cJSON_GetObjectItem(NULL, "item"));
TEST_ASSERT_NULL(cJSON_GetObjectItem(item, NULL));
TEST_ASSERT_NULL(cJSON_GetObjectItemCaseSensitive(NULL, "item"));
TEST_ASSERT_NULL(cJSON_GetObjectItemCaseSensitive(item, NULL));
TEST_ASSERT_FALSE(cJSON_HasObjectItem(NULL, "item"));
TEST_ASSERT_FALSE(cJSON_HasObjectItem(item, NULL));
TEST_ASSERT_FALSE(cJSON_IsInvalid(NULL));
TEST_ASSERT_FALSE(cJSON_IsFalse(NULL));
TEST_ASSERT_FALSE(cJSON_IsTrue(NULL));
TEST_ASSERT_FALSE(cJSON_IsBool(NULL));
TEST_ASSERT_FALSE(cJSON_IsNull(NULL));
TEST_ASSERT_FALSE(cJSON_IsNumber(NULL));
TEST_ASSERT_FALSE(cJSON_IsString(NULL));
TEST_ASSERT_FALSE(cJSON_IsArray(NULL));
TEST_ASSERT_FALSE(cJSON_IsObject(NULL));
TEST_ASSERT_FALSE(cJSON_IsRaw(NULL));
TEST_ASSERT_NULL(cJSON_CreateString(NULL));
TEST_ASSERT_NULL(cJSON_CreateRaw(NULL));
TEST_ASSERT_NULL(cJSON_CreateIntArray(NULL, 10));
TEST_ASSERT_NULL(cJSON_CreateFloatArray(NULL, 10));
TEST_ASSERT_NULL(cJSON_CreateDoubleArray(NULL, 10));
TEST_ASSERT_NULL(cJSON_CreateStringArray(NULL, 10));
cJSON_AddItemToArray(NULL, item);
cJSON_AddItemToArray(item, NULL);
cJSON_AddItemToObject(item, "item", NULL);
cJSON_AddItemToObject(item, NULL, item);
cJSON_AddItemToObject(NULL, "item", item);
cJSON_AddItemToObjectCS(item, "item", NULL);
cJSON_AddItemToObjectCS(item, NULL, item);
cJSON_AddItemToObjectCS(NULL, "item", item);
cJSON_AddItemReferenceToArray(NULL, item);
cJSON_AddItemReferenceToArray(item, NULL);
cJSON_AddItemReferenceToObject(item, "item", NULL);
cJSON_AddItemReferenceToObject(item, NULL, item);
cJSON_AddItemReferenceToObject(NULL, "item", item);
TEST_ASSERT_NULL(cJSON_DetachItemViaPointer(NULL, item));
TEST_ASSERT_NULL(cJSON_DetachItemViaPointer(item, NULL));
TEST_ASSERT_NULL(cJSON_DetachItemFromArray(NULL, 0));
cJSON_DeleteItemFromArray(NULL, 0);
TEST_ASSERT_NULL(cJSON_DetachItemFromObject(NULL, "item"));
TEST_ASSERT_NULL(cJSON_DetachItemFromObject(item, NULL));
TEST_ASSERT_NULL(cJSON_DetachItemFromObjectCaseSensitive(NULL, "item"));
TEST_ASSERT_NULL(cJSON_DetachItemFromObjectCaseSensitive(item, NULL));
cJSON_DeleteItemFromObject(NULL, "item");
cJSON_DeleteItemFromObject(item, NULL);
cJSON_DeleteItemFromObjectCaseSensitive(NULL, "item");
cJSON_DeleteItemFromObjectCaseSensitive(item, NULL);
cJSON_InsertItemInArray(NULL, 0, item);
cJSON_InsertItemInArray(item, 0, NULL);
TEST_ASSERT_FALSE(cJSON_ReplaceItemViaPointer(NULL, item, item));
TEST_ASSERT_FALSE(cJSON_ReplaceItemViaPointer(item, NULL, item));
TEST_ASSERT_FALSE(cJSON_ReplaceItemViaPointer(item, item, NULL));
cJSON_ReplaceItemInArray(item, 0, NULL);
cJSON_ReplaceItemInArray(NULL, 0, item);
cJSON_ReplaceItemInObject(NULL, "item", item);
cJSON_ReplaceItemInObject(item, NULL, item);
cJSON_ReplaceItemInObject(item, "item", NULL);
cJSON_ReplaceItemInObjectCaseSensitive(NULL, "item", item);
cJSON_ReplaceItemInObjectCaseSensitive(item, NULL, item);
cJSON_ReplaceItemInObjectCaseSensitive(item, "item", NULL);
TEST_ASSERT_NULL(cJSON_Duplicate(NULL, true));
TEST_ASSERT_FALSE(cJSON_Compare(item, NULL, false));
TEST_ASSERT_FALSE(cJSON_Compare(NULL, item, false));
cJSON_Minify(NULL);
/* skipped because it is only used via a macro that checks for NULL */
/* cJSON_SetNumberHelper(NULL, 0); */
cJSON_Delete(item);
}
static void *failing_realloc(void *pointer, size_t size)
{
(void)size;
(void)pointer;
return NULL;
}
static void ensure_should_fail_on_failed_realloc(void)
{
printbuffer buffer = {NULL, 10, 0, 0, false, false, {&malloc, &free, &failing_realloc}};
buffer.buffer = (unsigned char*)malloc(100);
TEST_ASSERT_NOT_NULL(buffer.buffer);
TEST_ASSERT_NULL_MESSAGE(ensure(&buffer, 200), "Ensure didn't fail with failing realloc.");
}
static void skip_utf8_bom_should_skip_bom(void)
{
const unsigned char string[] = "\xEF\xBB\xBF{}";
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
buffer.content = string;
buffer.length = sizeof(string);
buffer.hooks = global_hooks;
TEST_ASSERT_TRUE(skip_utf8_bom(&buffer) == &buffer);
TEST_ASSERT_EQUAL_UINT(3U, (unsigned int)buffer.offset);
}
static void skip_utf8_bom_should_not_skip_bom_if_not_at_beginning(void)
{
const unsigned char string[] = " \xEF\xBB\xBF{}";
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
buffer.content = string;
buffer.length = sizeof(string);
buffer.hooks = global_hooks;
buffer.offset = 1;
TEST_ASSERT_NULL(skip_utf8_bom(&buffer));
}
int main(void) int main(void)
{ {
UNITY_BEGIN(); UNITY_BEGIN();
@@ -464,10 +338,6 @@ int main(void)
RUN_TEST(cjson_detach_item_via_pointer_should_detach_items); RUN_TEST(cjson_detach_item_via_pointer_should_detach_items);
RUN_TEST(cjson_replace_item_via_pointer_should_replace_items); RUN_TEST(cjson_replace_item_via_pointer_should_replace_items);
RUN_TEST(cjson_replace_item_in_object_should_preserve_name); RUN_TEST(cjson_replace_item_in_object_should_preserve_name);
RUN_TEST(cjson_functions_shouldnt_crash_with_null_pointers);
RUN_TEST(ensure_should_fail_on_failed_realloc);
RUN_TEST(skip_utf8_bom_should_skip_bom);
RUN_TEST(skip_utf8_bom_should_not_skip_bom_if_not_at_beginning);
return UNITY_END(); return UNITY_END();
} }
-80
View File
@@ -1,80 +0,0 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "unity/examples/unity_config.h"
#include "unity/src/unity.h"
#include "common.h"
#include "../cJSON_Utils.h"
static void cjson_utils_functions_shouldnt_crash_with_null_pointers(void)
{
cJSON *item = cJSON_CreateString("item");
TEST_ASSERT_NOT_NULL(item);
TEST_ASSERT_NULL(cJSONUtils_GetPointer(item, NULL));
TEST_ASSERT_NULL(cJSONUtils_GetPointer(NULL, "pointer"));
TEST_ASSERT_NULL(cJSONUtils_GetPointerCaseSensitive(NULL, "pointer"));
TEST_ASSERT_NULL(cJSONUtils_GetPointerCaseSensitive(item, NULL));
TEST_ASSERT_NULL(cJSONUtils_GeneratePatches(item, NULL));
TEST_ASSERT_NULL(cJSONUtils_GeneratePatches(NULL, item));
TEST_ASSERT_NULL(cJSONUtils_GeneratePatchesCaseSensitive(item, NULL));
TEST_ASSERT_NULL(cJSONUtils_GeneratePatchesCaseSensitive(NULL, item));
cJSONUtils_AddPatchToArray(item, "path", "add", NULL);
cJSONUtils_AddPatchToArray(item, "path", NULL, item);
cJSONUtils_AddPatchToArray(item, NULL, "add", item);
cJSONUtils_AddPatchToArray(NULL, "path", "add", item);
cJSONUtils_ApplyPatches(item, NULL);
cJSONUtils_ApplyPatches(NULL, item);
cJSONUtils_ApplyPatchesCaseSensitive(item, NULL);
cJSONUtils_ApplyPatchesCaseSensitive(NULL, item);
TEST_ASSERT_NULL(cJSONUtils_MergePatch(item, NULL));
item = cJSON_CreateString("item");
TEST_ASSERT_NULL(cJSONUtils_MergePatchCaseSensitive(item, NULL));
item = cJSON_CreateString("item");
/* these calls are actually valid */
/* cJSONUtils_MergePatch(NULL, item); */
/* cJSONUtils_MergePatchCaseSensitive(NULL, item);*/
/* cJSONUtils_GenerateMergePatch(item, NULL); */
/* cJSONUtils_GenerateMergePatch(NULL, item); */
/* cJSONUtils_GenerateMergePatchCaseSensitive(item, NULL); */
/* cJSONUtils_GenerateMergePatchCaseSensitive(NULL, item); */
TEST_ASSERT_NULL(cJSONUtils_FindPointerFromObjectTo(item, NULL));
TEST_ASSERT_NULL(cJSONUtils_FindPointerFromObjectTo(NULL, item));
cJSONUtils_SortObject(NULL);
cJSONUtils_SortObjectCaseSensitive(NULL);
cJSON_Delete(item);
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(cjson_utils_functions_shouldnt_crash_with_null_pointers);
return UNITY_END();
}
+1 -18
View File
@@ -142,7 +142,7 @@ static void file_test6_should_not_be_parsed(void)
tree = cJSON_Parse(test6); tree = cJSON_Parse(test6);
TEST_ASSERT_NULL_MESSAGE(tree, "Should fail to parse what is not JSON."); TEST_ASSERT_NULL_MESSAGE(tree, "Should fail to parse what is not JSON.");
TEST_ASSERT_EQUAL_PTR_MESSAGE(test6, cJSON_GetErrorPtr(), "Error pointer is incorrect."); TEST_ASSERT_EQUAL_STRING_MESSAGE(test6, cJSON_GetErrorPtr(), "Error pointer is incorrect.");
if (test6 != NULL) if (test6 != NULL)
{ {
@@ -179,22 +179,6 @@ static void file_test11_should_be_parsed_and_printed(void)
do_test("test11"); do_test("test11");
} }
static void test12_should_not_be_parsed(void)
{
const char *test12 = "{ \"name\": ";
cJSON *tree = NULL;
tree = cJSON_Parse(test12);
TEST_ASSERT_NULL_MESSAGE(tree, "Should fail to parse incomplete JSON.");
TEST_ASSERT_EQUAL_PTR_MESSAGE(test12 + strlen(test12), cJSON_GetErrorPtr(), "Error pointer is incorrect.");
if (tree != NULL)
{
cJSON_Delete(tree);
}
}
int main(void) int main(void)
{ {
UNITY_BEGIN(); UNITY_BEGIN();
@@ -209,6 +193,5 @@ int main(void)
RUN_TEST(file_test9_should_be_parsed_and_printed); RUN_TEST(file_test9_should_be_parsed_and_printed);
RUN_TEST(file_test10_should_be_parsed_and_printed); RUN_TEST(file_test10_should_be_parsed_and_printed);
RUN_TEST(file_test11_should_be_parsed_and_printed); RUN_TEST(file_test11_should_be_parsed_and_printed);
RUN_TEST(test12_should_not_be_parsed);
return UNITY_END(); return UNITY_END();
} }
+4 -34
View File
@@ -40,23 +40,11 @@ static void parse_with_opts_should_handle_empty_strings(void)
{ {
const char empty_string[] = ""; const char empty_string[] = "";
const char *error_pointer = NULL; const char *error_pointer = NULL;
TEST_ASSERT_NULL(cJSON_ParseWithOpts(empty_string, NULL, false)); TEST_ASSERT_NULL(cJSON_ParseWithOpts(empty_string, NULL, false));
TEST_ASSERT_EQUAL_PTR(empty_string, cJSON_GetErrorPtr()); error_pointer = cJSON_GetErrorPtr();
TEST_ASSERT_EQUAL_INT(0, error_pointer - empty_string);
TEST_ASSERT_NULL(cJSON_ParseWithOpts(empty_string, &error_pointer, false)); TEST_ASSERT_NULL(cJSON_ParseWithOpts(empty_string, &error_pointer, false));
TEST_ASSERT_EQUAL_PTR(empty_string, error_pointer); TEST_ASSERT_EQUAL_INT(0, error_pointer - empty_string);
TEST_ASSERT_EQUAL_PTR(empty_string, cJSON_GetErrorPtr());
}
static void parse_with_opts_should_handle_incomplete_json(void)
{
const char json[] = "{ \"name\": ";
const char *parse_end = NULL;
TEST_ASSERT_NULL(cJSON_ParseWithOpts(json, &parse_end, false));
TEST_ASSERT_EQUAL_PTR(json + strlen(json), parse_end);
TEST_ASSERT_EQUAL_PTR(json + strlen(json), cJSON_GetErrorPtr());
} }
static void parse_with_opts_should_require_null_if_requested(void) static void parse_with_opts_should_require_null_if_requested(void)
@@ -77,36 +65,18 @@ static void parse_with_opts_should_return_parse_end(void)
cJSON *item = cJSON_ParseWithOpts(json, &parse_end, false); cJSON *item = cJSON_ParseWithOpts(json, &parse_end, false);
TEST_ASSERT_NOT_NULL(item); TEST_ASSERT_NOT_NULL(item);
TEST_ASSERT_EQUAL_PTR(json + 2, parse_end); TEST_ASSERT_EQUAL_INT(2, parse_end - json);
cJSON_Delete(item); cJSON_Delete(item);
} }
static void parse_with_opts_should_parse_utf8_bom(void)
{
cJSON *with_bom = NULL;
cJSON *without_bom = NULL;
with_bom = cJSON_ParseWithOpts("\xEF\xBB\xBF{}", NULL, true);
TEST_ASSERT_NOT_NULL(with_bom);
without_bom = cJSON_ParseWithOpts("{}", NULL, true);
TEST_ASSERT_NOT_NULL(with_bom);
TEST_ASSERT_TRUE(cJSON_Compare(with_bom, without_bom, true));
cJSON_Delete(with_bom);
cJSON_Delete(without_bom);
}
int main(void) int main(void)
{ {
UNITY_BEGIN(); UNITY_BEGIN();
RUN_TEST(parse_with_opts_should_handle_null); RUN_TEST(parse_with_opts_should_handle_null);
RUN_TEST(parse_with_opts_should_handle_empty_strings); RUN_TEST(parse_with_opts_should_handle_empty_strings);
RUN_TEST(parse_with_opts_should_handle_incomplete_json);
RUN_TEST(parse_with_opts_should_require_null_if_requested); RUN_TEST(parse_with_opts_should_require_null_if_requested);
RUN_TEST(parse_with_opts_should_return_parse_end); RUN_TEST(parse_with_opts_should_return_parse_end);
RUN_TEST(parse_with_opts_should_parse_utf8_bom);
return UNITY_END(); return UNITY_END();
} }
-11
View File
@@ -118,17 +118,6 @@ Another way of calling TEST_ASSERT_EQUAL_INT
Asserts that the actual value is within plus or minus delta of the expected value. This also comes in Asserts that the actual value is within plus or minus delta of the expected value. This also comes in
size specific variants. size specific variants.
TEST_ASSERT_GREATER_THAN(threshold, actual)
Asserts that the actual value is greater than the threshold. This also comes in size specific variants.
TEST_ASSERT_LESS_THAN(threshold, actual)
Asserts that the actual value is less than the threshold. This also comes in size specific variants.
Arrays Arrays
------ ------
+3 -3
View File
@@ -172,7 +172,7 @@ class UnityModuleGenerator
when 'camel' then part1 when 'camel' then part1
when 'snake' then part1.downcase when 'snake' then part1.downcase
when 'caps' then part1.upcase when 'caps' then part1.upcase
else part1 else part1.downcase
end end
else else
case (@options[:naming]) case (@options[:naming])
@@ -180,7 +180,7 @@ class UnityModuleGenerator
when 'camel' then part1 + part2 when 'camel' then part1 + part2
when 'snake' then part1.downcase + '_' + part2.downcase when 'snake' then part1.downcase + '_' + part2.downcase
when 'caps' then part1.upcase + '_' + part2.upcase when 'caps' then part1.upcase + '_' + part2.upcase
else part1 + '_' + part2 else part1.downcase + '_' + part2.downcase
end end
end end
end end
@@ -290,7 +290,7 @@ if $0 == __FILE__
' -n"camel" sets the file naming convention.', ' -n"camel" sets the file naming convention.',
' bumpy - BumpyCaseFilenames.', ' bumpy - BumpyCaseFilenames.',
' camel - camelCaseFilenames.', ' camel - camelCaseFilenames.',
' snake - snake_case_filenames.', ' snake - snake_case_filenames. (DEFAULT)',
' caps - CAPS_CASE_FILENAMES.', ' caps - CAPS_CASE_FILENAMES.',
' -u update subversion too (requires subversion command line)', ' -u update subversion too (requires subversion command line)',
' -y"my.yml" selects a different yaml config file for module generation', ' -y"my.yml" selects a different yaml config file for module generation',
+1 -1
View File
@@ -119,7 +119,7 @@ class UnityTestRunnerGenerator
source_index = 0 source_index = 0
tests_and_line_numbers.size.times do |i| tests_and_line_numbers.size.times do |i|
source_lines[source_index..-1].each_with_index do |line, index| source_lines[source_index..-1].each_with_index do |line, index|
next unless line =~ /\s+#{tests_and_line_numbers[i][:test]}(?:\s|\()/ next unless line =~ /#{tests_and_line_numbers[i][:test]}/
source_index += index source_index += index
tests_and_line_numbers[i][:line_number] = source_index + 1 tests_and_line_numbers[i][:line_number] = source_index + 1
break break
View File
File mode changed.
@@ -290,60 +290,6 @@ Asserts the specified bit of the `actual` parameter is high.
Asserts the specified bit of the `actual` parameter is low. Asserts the specified bit of the `actual` parameter is low.
### Integer Less Than / Greater Than
These assertions verify that the `actual` parameter is less than or greater
than `threshold` (exclusive). For example, if the threshold value is 0 for the
greater than assertion will fail if it is 0 or less.
##### `TEST_ASSERT_GREATER_THAN (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_INT (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_INT8 (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_INT16 (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_INT32 (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_UINT (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_UINT8 (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_UINT16 (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_UINT32 (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_HEX8 (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_HEX16 (threshold, actual)`
##### `TEST_ASSERT_GREATER_THAN_HEX32 (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_INT (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_INT8 (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_INT16 (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_INT32 (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_UINT (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_UINT8 (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_UINT16 (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_UINT32 (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_HEX8 (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_HEX16 (threshold, actual)`
##### `TEST_ASSERT_LESS_THAN_HEX32 (threshold, actual)`
### Integer Ranges (of all sizes) ### Integer Ranges (of all sizes)
-2
View File
@@ -202,9 +202,7 @@
* serial `RS232_putc()` function you wrote like thus: * serial `RS232_putc()` function you wrote like thus:
*/ */
/* #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) */ /* #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) */
/* #define UNITY_OUTPUT_CHAR_HEADER_DECLARATION RS232_putc(int) */
/* #define UNITY_OUTPUT_FLUSH() RS232_flush() */ /* #define UNITY_OUTPUT_FLUSH() RS232_flush() */
/* #define UNITY_OUTPUT_FLUSH_HEADER_DECLARATION RS232_flush(void) */
/* #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) */ /* #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) */
/* #define UNITY_OUTPUT_COMPLETE() RS232_close() */ /* #define UNITY_OUTPUT_COMPLETE() RS232_close() */
@@ -53,7 +53,7 @@ module RakefileHelpers
defines = if $cfg['compiler']['defines']['items'].nil? defines = if $cfg['compiler']['defines']['items'].nil?
'' ''
else else
squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar'] + ['UNITY_OUTPUT_CHAR_HEADER_DECLARATION=UnityOutputCharSpy_OutputChar\(int\)']) squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar'])
end end
options = squash('', $cfg['compiler']['options']) options = squash('', $cfg['compiler']['options'])
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items']) includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
-1
View File
@@ -6,7 +6,6 @@ endif
CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror
CFLAGS += $(DEBUG) CFLAGS += $(DEBUG)
DEFINES = -D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar DEFINES = -D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar
DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=UnityOutputCharSpy_OutputChar\(int\)
SRC = ../src/unity_fixture.c \ SRC = ../src/unity_fixture.c \
../../../src/unity.c \ ../../../src/unity.c \
unity_fixture_Test.c \ unity_fixture_Test.c \
+1 -1
View File
@@ -1,2 +1,2 @@
121 120
+1 -1
View File
@@ -1,2 +1,2 @@
2.4.2 2.4.1
+82 -130
View File
@@ -27,8 +27,6 @@ static const char UnityStrNull[] = "NULL";
static const char UnityStrSpacer[] = ". "; static const char UnityStrSpacer[] = ". ";
static const char UnityStrExpected[] = " Expected "; static const char UnityStrExpected[] = " Expected ";
static const char UnityStrWas[] = " Was "; static const char UnityStrWas[] = " Was ";
static const char UnityStrGt[] = " to be greater than ";
static const char UnityStrLt[] = " to be less than ";
static const char UnityStrElement[] = " Element "; static const char UnityStrElement[] = " Element ";
static const char UnityStrByte[] = " Byte "; static const char UnityStrByte[] = " Byte ";
static const char UnityStrMemory[] = " Memory Mismatch."; static const char UnityStrMemory[] = " Memory Mismatch.";
@@ -237,97 +235,95 @@ void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number)
/*-----------------------------------------------*/ /*-----------------------------------------------*/
#ifndef UNITY_EXCLUDE_FLOAT_PRINT #ifndef UNITY_EXCLUDE_FLOAT_PRINT
/* This function prints a floating-point value in a format similar to static void UnityPrintDecimalAndNumberWithLeadingZeros(UNITY_INT32 fraction_part, UNITY_INT32 divisor)
* printf("%.6g"). It can work with either single- or double-precision, {
* but for simplicity, it prints only 6 significant digits in either case. UNITY_OUTPUT_CHAR('.');
* Printing more than 6 digits accurately is hard (at least in the single- while (divisor > 0)
* precision case) and isn't attempted here. */ {
UNITY_OUTPUT_CHAR('0' + fraction_part / divisor);
fraction_part %= divisor;
divisor /= 10;
if (fraction_part == 0) break; /* Truncate trailing 0's */
}
}
#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO
/* If rounds up && remainder 0.5 && result odd && below cutoff for double precision issues */
#define ROUND_TIES_TO_EVEN(orig, num_int, num) \
if (num_int > (num) && (num) - (num_int-1) <= 0.5 && (num_int & 1) == 1 && orig < 1e22) \
num_int -= 1 /* => a tie to round down to even */
#else
#define ROUND_TIES_TO_EVEN(orig, num_int, num) /* Remove macro */
#endif
/* Printing floating point numbers is hard. Some goals of this implementation: works for embedded
* systems, floats or doubles, and has a reasonable format. The key paper in this area,
* 'How to Print Floating-Point Numbers Accurately' by Steele & White, shows an approximation by
* scaling called Dragon 2. This code uses a similar idea. The other core algorithm uses casts and
* floating subtraction to give exact remainders after the decimal, to be scaled into an integer.
* Extra trailing 0's are excluded. The output defaults to rounding to nearest, ties to even. You
* can enable rounding ties away from zero. Note: UNITY_DOUBLE param can typedef to float or double
* The old version required compiling in snprintf. For reference, with a similar format as now:
* char buf[19];
* if (number > 4294967296.0 || -number > 4294967296.0) snprintf(buf, sizeof buf, "%.8e", number);
* else snprintf(buf, sizeof buf, "%.6f", number);
* UnityPrint(buf);
*/
void UnityPrintFloat(const UNITY_DOUBLE input_number) void UnityPrintFloat(const UNITY_DOUBLE input_number)
{ {
UNITY_DOUBLE number = input_number; UNITY_DOUBLE number;
/* print minus sign (including for negative zero) */ if (input_number < 0)
if (number < 0.0f || (number == 0.0f && 1.0f / number < 0.0f))
{ {
UNITY_OUTPUT_CHAR('-'); UNITY_OUTPUT_CHAR('-');
number = -number; number = -input_number;
} else
{
number = input_number;
} }
/* handle zero, NaN, and +/- infinity */ if (isnan(number)) UnityPrint(UnityStrNaN);
if (number == 0.0f) UnityPrint("0"); else if (isinf(number)) UnityPrintLen(UnityStrInf, 3);
else if (isnan(number)) UnityPrint("nan"); else if (number <= 0.0000005 && number > 0) UnityPrint("0.000000..."); /* Small number */
else if (isinf(number)) UnityPrint("inf"); else if (number < 4294967295.9999995) /* Rounded result fits in 32 bits, "%.6f" format */
else
{ {
int exponent = 0; const UNITY_INT32 divisor = 1000000/10;
int decimals, digits; UNITY_UINT32 integer_part = (UNITY_UINT32)number;
UNITY_INT32 n; UNITY_INT32 fraction_part = (UNITY_INT32)((number - (UNITY_DOUBLE)integer_part)*1000000.0 + 0.5);
char buf[16]; /* Double precision calculation gives best performance for six rounded decimal places */
ROUND_TIES_TO_EVEN(number, fraction_part, (number - (UNITY_DOUBLE)integer_part)*1000000.0);
/* scale up or down by powers of 10 */ if (fraction_part == 1000000) /* Carry across the decimal point */
while (number < 100000.0f / 1e6f) { number *= 1e6f; exponent -= 6; }
while (number < 100000.0f) { number *= 10.0f; exponent--; }
while (number > 1000000.0f * 1e6f) { number /= 1e6f; exponent += 6; }
while (number > 1000000.0f) { number /= 10.0f; exponent++; }
/* round to nearest integer */
n = ((UNITY_INT32)(number + number) + 1) / 2;
if (n > 999999)
{ {
n = 100000; fraction_part = 0;
integer_part += 1;
}
UnityPrintNumberUnsigned(integer_part);
UnityPrintDecimalAndNumberWithLeadingZeros(fraction_part, divisor);
}
else /* Number is larger, use exponential format of 9 digits, "%.8e" */
{
const UNITY_INT32 divisor = 1000000000/10;
UNITY_INT32 integer_part;
UNITY_DOUBLE_TYPE divide = 10.0;
int exponent = 9;
while (number / divide >= 1000000000.0 - 0.5)
{
divide *= 10;
exponent++; exponent++;
} }
integer_part = (UNITY_INT32)(number / divide + 0.5);
/* Double precision calculation required for float, to produce 9 rounded digits */
ROUND_TIES_TO_EVEN(number, integer_part, number / divide);
/* determine where to place decimal point */ UNITY_OUTPUT_CHAR('0' + integer_part / divisor);
decimals = (exponent <= 0 && exponent >= -9) ? -exponent : 5; UnityPrintDecimalAndNumberWithLeadingZeros(integer_part % divisor, divisor / 10);
exponent += decimals;
/* truncate trailing zeroes after decimal point */
while (decimals > 0 && n % 10 == 0)
{
n /= 10;
decimals--;
}
/* build up buffer in reverse order */
digits = 0;
while (n != 0 || digits < decimals + 1)
{
buf[digits++] = (char)('0' + n % 10);
n /= 10;
}
while (digits > 0)
{
if(digits == decimals) UNITY_OUTPUT_CHAR('.');
UNITY_OUTPUT_CHAR(buf[--digits]);
}
/* print exponent if needed */
if (exponent != 0)
{
UNITY_OUTPUT_CHAR('e'); UNITY_OUTPUT_CHAR('e');
if(exponent < 0)
{
UNITY_OUTPUT_CHAR('-');
exponent = -exponent;
}
else
{
UNITY_OUTPUT_CHAR('+'); UNITY_OUTPUT_CHAR('+');
} if (exponent < 10) UNITY_OUTPUT_CHAR('0');
UnityPrintNumber(exponent);
digits = 0;
while (exponent != 0 || digits < 2)
{
buf[digits++] = (char)('0' + exponent % 10);
exponent /= 10;
}
while (digits > 0)
{
UNITY_OUTPUT_CHAR(buf[--digits]);
}
}
} }
} }
#endif /* ! UNITY_EXCLUDE_FLOAT_PRINT */ #endif /* ! UNITY_EXCLUDE_FLOAT_PRINT */
@@ -530,50 +526,6 @@ void UnityAssertEqualNumber(const UNITY_INT expected,
} }
} }
/*-----------------------------------------------*/
void UnityAssertGreaterNumber(const UNITY_INT threshold,
const UNITY_INT actual,
const char *msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
RETURN_IF_FAIL_OR_IGNORE;
if (!(actual > threshold))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(actual, style);
UnityPrint(UnityStrGt);
UnityPrintNumberByStyle(threshold, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
/*-----------------------------------------------*/
void UnityAssertSmallerNumber(const UNITY_INT threshold,
const UNITY_INT actual,
const char *msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
RETURN_IF_FAIL_OR_IGNORE;
if (!(actual < threshold))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(actual, style);
UnityPrint(UnityStrLt);
UnityPrintNumberByStyle(threshold, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
#define UnityPrintPointlessAndBail() \ #define UnityPrintPointlessAndBail() \
{ \ { \
UnityTestResultsFailBegin(lineNumber); \ UnityTestResultsFailBegin(lineNumber); \
@@ -1073,7 +1025,7 @@ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected,
{ {
UNITY_UINT32 i = 0; UNITY_UINT32 i = 0;
UNITY_UINT32 j = 0; UNITY_UINT32 j = 0;
const char* expd = NULL; const char* exp = NULL;
const char* act = NULL; const char* act = NULL;
RETURN_IF_FAIL_OR_IGNORE; RETURN_IF_FAIL_OR_IGNORE;
@@ -1096,7 +1048,7 @@ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected,
if (flags != UNITY_ARRAY_TO_ARRAY) if (flags != UNITY_ARRAY_TO_ARRAY)
{ {
expd = (const char*)expected; exp = (const char*)expected;
} }
do do
@@ -1104,15 +1056,15 @@ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected,
act = actual[j]; act = actual[j];
if (flags == UNITY_ARRAY_TO_ARRAY) if (flags == UNITY_ARRAY_TO_ARRAY)
{ {
expd = ((const char* const*)expected)[j]; exp = ((const char* const*)expected)[j];
} }
/* if both pointers not null compare the strings */ /* if both pointers not null compare the strings */
if (expd && act) if (exp && act)
{ {
for (i = 0; expd[i] || act[i]; i++) for (i = 0; exp[i] || act[i]; i++)
{ {
if (expd[i] != act[i]) if (exp[i] != act[i])
{ {
Unity.CurrentTestFailed = 1; Unity.CurrentTestFailed = 1;
break; break;
@@ -1121,7 +1073,7 @@ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected,
} }
else else
{ /* handle case of one pointers being null (if both null, test should pass) */ { /* handle case of one pointers being null (if both null, test should pass) */
if (expd != act) if (exp != act)
{ {
Unity.CurrentTestFailed = 1; Unity.CurrentTestFailed = 1;
} }
@@ -1135,7 +1087,7 @@ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected,
UnityPrint(UnityStrElement); UnityPrint(UnityStrElement);
UnityPrintNumberUnsigned(j); UnityPrintNumberUnsigned(j);
} }
UnityPrintExpectedAndActualStrings(expd, act); UnityPrintExpectedAndActualStrings(exp, act);
UnityAddMsgIfSpecified(msg); UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL; UNITY_FAIL_AND_BAIL;
} }
-60
View File
@@ -114,35 +114,6 @@ void tearDown(void);
#define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(-1), (actual), __LINE__, NULL) #define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(0), (actual), __LINE__, NULL) #define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(0), (actual), __LINE__, NULL)
/* Integer Greater Than/ Less Than (of all sizes) */
#define TEST_ASSERT_GREATER_THAN(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_INT(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_INT8(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT8((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_INT16(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT16((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_INT32(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT32((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_UINT(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_UINT8(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT8((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_UINT16(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT16((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_UINT32(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT32((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_HEX8(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX8((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_HEX16(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX16((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_GREATER_THAN_HEX32(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX32((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_INT(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_INT8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT8((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_INT16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT16((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_INT32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT32((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_UINT(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_UINT8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT8((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_UINT16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT16((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_UINT32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT32((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_HEX8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX8((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_HEX16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX16((threshold), (actual), __LINE__, NULL)
#define TEST_ASSERT_LESS_THAN_HEX32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX32((threshold), (actual), __LINE__, NULL)
/* Integer Ranges (of all sizes) */ /* Integer Ranges (of all sizes) */
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_INT8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT8_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_INT8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT8_WITHIN((delta), (expected), (actual), __LINE__, NULL)
@@ -186,8 +157,6 @@ void tearDown(void);
#define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY((expected), (actual), (num_elements), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((expected), (actual), (len), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((expected), (actual), (len), (num_elements), __LINE__, NULL)
/* Arrays Compared To Single Value */ /* Arrays Compared To Single Value */
#define TEST_ASSERT_EACH_EQUAL_INT(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_INT(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT((expected), (actual), (num_elements), __LINE__, NULL)
#define TEST_ASSERT_EACH_EQUAL_INT8(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT8((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_INT8(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT8((expected), (actual), (num_elements), __LINE__, NULL)
@@ -272,35 +241,6 @@ void tearDown(void);
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(-1), (actual), __LINE__, (message)) #define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(-1), (actual), __LINE__, (message))
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(0), (actual), __LINE__, (message)) #define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(0), (actual), __LINE__, (message))
/* Integer Greater Than/ Less Than (of all sizes) */
#define TEST_ASSERT_GREATER_THAN_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT8((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT16((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT32((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT8((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT16((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT32((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX8((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX16((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX32((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT8((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT16((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT32((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT8((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT16((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT32((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX8((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX16((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_LESS_THAN_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX32((threshold), (actual), __LINE__, (message))
/* Integer Ranges (of all sizes) */ /* Integer Ranges (of all sizes) */
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_INT8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT8_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_INT8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT8_WITHIN((delta), (expected), (actual), __LINE__, (message))
+7 -47
View File
@@ -244,8 +244,8 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
#define UNITY_OUTPUT_CHAR(a) (void)putchar(a) #define UNITY_OUTPUT_CHAR(a) (void)putchar(a)
#else #else
/* If defined as something else, make sure we declare it here so it's ready for use */ /* If defined as something else, make sure we declare it here so it's ready for use */
#ifdef UNITY_OUTPUT_CHAR_HEADER_DECLARATION #ifndef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION
extern void UNITY_OUTPUT_CHAR_HEADER_DECLARATION; extern void UNITY_OUTPUT_CHAR(int);
#endif #endif
#endif #endif
@@ -253,22 +253,22 @@ extern void UNITY_OUTPUT_CHAR_HEADER_DECLARATION;
#ifdef UNITY_USE_FLUSH_STDOUT #ifdef UNITY_USE_FLUSH_STDOUT
/* We want to use the stdout flush utility */ /* We want to use the stdout flush utility */
#include <stdio.h> #include <stdio.h>
#define UNITY_OUTPUT_FLUSH() (void)fflush(stdout) #define UNITY_OUTPUT_FLUSH (void)fflush(stdout)
#else #else
/* We've specified nothing, therefore flush should just be ignored */ /* We've specified nothing, therefore flush should just be ignored */
#define UNITY_OUTPUT_FLUSH() #define UNITY_OUTPUT_FLUSH
#endif #endif
#else #else
/* We've defined flush as something else, so make sure we declare it here so it's ready for use */ /* We've defined flush as something else, so make sure we declare it here so it's ready for use */
#ifdef UNITY_OUTPUT_FLUSH_HEADER_DECLARATION #ifndef UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION
extern void UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION; extern void UNITY_OUTPUT_FLUSH(void);
#endif #endif
#endif #endif
#ifndef UNITY_OUTPUT_FLUSH #ifndef UNITY_OUTPUT_FLUSH
#define UNITY_FLUSH_CALL() #define UNITY_FLUSH_CALL()
#else #else
#define UNITY_FLUSH_CALL() UNITY_OUTPUT_FLUSH() #define UNITY_FLUSH_CALL() UNITY_OUTPUT_FLUSH
#endif #endif
#ifndef UNITY_PRINT_EOL #ifndef UNITY_PRINT_EOL
@@ -453,18 +453,6 @@ void UnityAssertEqualNumber(const UNITY_INT expected,
const UNITY_LINE_TYPE lineNumber, const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style); const UNITY_DISPLAY_STYLE_T style);
void UnityAssertGreaterNumber(const UNITY_INT threshold,
const UNITY_INT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertSmallerNumber(const UNITY_INT threshold,
const UNITY_INT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
UNITY_INTERNAL_PTR actual, UNITY_INTERNAL_PTR actual,
const UNITY_UINT32 num_elements, const UNITY_UINT32 num_elements,
@@ -662,34 +650,6 @@ int UnityTestMatches(void);
#define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT32)(expected), (UNITY_INT)(UNITY_INT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT32)(expected), (UNITY_INT)(UNITY_INT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((UNITY_INT)(mask), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line)) #define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((UNITY_INT)(mask), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line))
#define UNITY_TEST_ASSERT_GREATER_THAN_INT(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_GREATER_THAN_INT8(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8)
#define UNITY_TEST_ASSERT_GREATER_THAN_INT16(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(UNITY_INT16)(threshold), (UNITY_INT)(UNITY_INT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16)
#define UNITY_TEST_ASSERT_GREATER_THAN_INT32(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(UNITY_INT32)(threshold), (UNITY_INT)(UNITY_INT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32)
#define UNITY_TEST_ASSERT_GREATER_THAN_UINT(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_GREATER_THAN_UINT8(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8)
#define UNITY_TEST_ASSERT_GREATER_THAN_UINT16(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16)
#define UNITY_TEST_ASSERT_GREATER_THAN_UINT32(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32)
#define UNITY_TEST_ASSERT_GREATER_THAN_HEX8(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_GREATER_THAN_HEX16(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_GREATER_THAN_HEX32(threshold, actual, line, message) UnityAssertGreaterNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_SMALLER_THAN_INT(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_SMALLER_THAN_INT8(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8)
#define UNITY_TEST_ASSERT_SMALLER_THAN_INT16(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(UNITY_INT16)(threshold), (UNITY_INT)(UNITY_INT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16)
#define UNITY_TEST_ASSERT_SMALLER_THAN_INT32(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(UNITY_INT32)(threshold), (UNITY_INT)(UNITY_INT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32)
#define UNITY_TEST_ASSERT_SMALLER_THAN_UINT(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_SMALLER_THAN_UINT8(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8)
#define UNITY_TEST_ASSERT_SMALLER_THAN_UINT16(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16)
#define UNITY_TEST_ASSERT_SMALLER_THAN_UINT32(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32)
#define UNITY_TEST_ASSERT_SMALLER_THAN_HEX8(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_SMALLER_THAN_HEX16(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_SMALLER_THAN_HEX32(threshold, actual, line, message) UnityAssertSmallerNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_INT8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT8 )(delta), (UNITY_INT)(UNITY_INT8 )(expected), (UNITY_INT)(UNITY_INT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) #define UNITY_TEST_ASSERT_INT8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT8 )(delta), (UNITY_INT)(UNITY_INT8 )(expected), (UNITY_INT)(UNITY_INT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8)
#define UNITY_TEST_ASSERT_INT16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT16)(delta), (UNITY_INT)(UNITY_INT16)(expected), (UNITY_INT)(UNITY_INT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) #define UNITY_TEST_ASSERT_INT16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT16)(delta), (UNITY_INT)(UNITY_INT16)(expected), (UNITY_INT)(UNITY_INT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16)
-1
View File
@@ -14,7 +14,6 @@ CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstri
#DEBUG = -O0 -g #DEBUG = -O0 -g
CFLAGS += $(DEBUG) CFLAGS += $(DEBUG)
DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy
DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\)
DEFINES += -D UNITY_SUPPORT_64 -D UNITY_INCLUDE_DOUBLE DEFINES += -D UNITY_SUPPORT_64 -D UNITY_INCLUDE_DOUBLE
SRC = ../src/unity.c tests/testunity.c build/testunityRunner.c SRC = ../src/unity.c tests/testunity.c build/testunityRunner.c
INC_DIR = -I ../src INC_DIR = -I ../src
+1 -1
View File
@@ -91,7 +91,7 @@ module RakefileHelpers
defines = if $cfg['compiler']['defines']['items'].nil? defines = if $cfg['compiler']['defines']['items'].nil?
'' ''
else else
squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=putcharSpy'] + ['UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\)'] + inject_defines) squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=putcharSpy'] + inject_defines)
end end
options = squash('', $cfg['compiler']['options']) options = squash('', $cfg['compiler']['options'])
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items']) includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
+155 -499
View File
@@ -764,9 +764,8 @@ void testNotEqualBitsLow(void)
EXPECT_ABORT_BEGIN EXPECT_ABORT_BEGIN
TEST_ASSERT_BITS_LOW(v0, v1); TEST_ASSERT_BITS_LOW(v0, v1);
VERIFY_FAILS_END VERIFY_FAILS_END
} }
void testEqualShorts(void) void testEqualShorts(void)
{ {
short v0, v1; short v0, v1;
@@ -1306,415 +1305,6 @@ void testINT8sNotWithinDeltaAndCustomMessage(void)
VERIFY_FAILS_END VERIFY_FAILS_END
} }
//-----------------
void testGreaterThan(void)
{
UNITY_INT v0, v1;
UNITY_INT *p0, *p1;
v0 = 0;
v1 = 1;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN(v0, v1);
TEST_ASSERT_GREATER_THAN(*p0, v1);
TEST_ASSERT_GREATER_THAN(v0, *p1);
TEST_ASSERT_GREATER_THAN(*p0, *p1);
}
void testGreaterThanINT(void)
{
UNITY_INT v0, v1;
UNITY_INT *p0, *p1;
v0 = 302;
v1 = 3334;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_INT(v0, v1);
TEST_ASSERT_GREATER_THAN_INT(*p0, v1);
TEST_ASSERT_GREATER_THAN_INT(v0, *p1);
TEST_ASSERT_GREATER_THAN_INT(*p0, *p1);
}
void testGreaterThanINT8(void)
{
UNITY_INT8 v0, v1;
UNITY_INT8 *p0, *p1;
v0 = -128;
v1 = 127;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_INT8(v0, v1);
TEST_ASSERT_GREATER_THAN_INT8(*p0, v1);
TEST_ASSERT_GREATER_THAN_INT8(v0, *p1);
TEST_ASSERT_GREATER_THAN_INT8(*p0, *p1);
}
void testGreaterThanINT16(void)
{
UNITY_INT16 v0, v1;
UNITY_INT16 *p0, *p1;
v0 = -32768;
v1 = 32767;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_INT16(v0, v1);
TEST_ASSERT_GREATER_THAN_INT16(*p0, v1);
TEST_ASSERT_GREATER_THAN_INT16(v0, *p1);
TEST_ASSERT_GREATER_THAN_INT16(*p0, *p1);
}
void testGreaterThanINT32(void)
{
UNITY_INT32 v0, v1;
UNITY_INT32 *p0, *p1;
v0 = -214783648;
v1 = 214783647;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_INT32(v0, v1);
TEST_ASSERT_GREATER_THAN_INT32(*p0, v1);
TEST_ASSERT_GREATER_THAN_INT32(v0, *p1);
TEST_ASSERT_GREATER_THAN_INT32(*p0, *p1);
}
void testGreaterThanUINT(void)
{
UNITY_UINT v0, v1;
UNITY_UINT *p0, *p1;
v0 = 0;
v1 = 1;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_UINT(v0, v1);
TEST_ASSERT_GREATER_THAN_UINT(*p0, v1);
TEST_ASSERT_GREATER_THAN_UINT(v0, *p1);
TEST_ASSERT_GREATER_THAN_UINT(*p0, *p1);
}
void testGreaterThanUINT8(void)
{
UNITY_UINT8 v0, v1;
UNITY_UINT8 *p0, *p1;
v0 = 0;
v1 = 255;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_UINT8(v0, v1);
TEST_ASSERT_GREATER_THAN_UINT8(*p0, v1);
TEST_ASSERT_GREATER_THAN_UINT8(v0, *p1);
TEST_ASSERT_GREATER_THAN_UINT8(*p0, *p1);
}
void testGreaterThanUINT16(void)
{
UNITY_UINT16 v0, v1;
UNITY_UINT16 *p0, *p1;
v0 = 0;
v1 = 65535;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_UINT16(v0, v1);
TEST_ASSERT_GREATER_THAN_UINT16(*p0, v1);
TEST_ASSERT_GREATER_THAN_UINT16(v0, *p1);
TEST_ASSERT_GREATER_THAN_UINT16(*p0, *p1);
}
void testGreaterThanUINT32(void)
{
UNITY_UINT32 v0, v1;
UNITY_UINT32 *p0, *p1;
v0 = 0;
v1 = 4294967295;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_UINT32(v0, v1);
TEST_ASSERT_GREATER_THAN_UINT32(*p0, v1);
TEST_ASSERT_GREATER_THAN_UINT32(v0, *p1);
TEST_ASSERT_GREATER_THAN_UINT32(*p0, *p1);
}
void testGreaterThanHEX8(void)
{
UNITY_UINT8 v0, v1;
UNITY_UINT8 *p0, *p1;
v0 = 0x00;
v1 = 0xFF;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_HEX8(v0, v1);
TEST_ASSERT_GREATER_THAN_HEX8(*p0, v1);
TEST_ASSERT_GREATER_THAN_HEX8(v0, *p1);
TEST_ASSERT_GREATER_THAN_HEX8(*p0, *p1);
}
void testGreaterThanHEX16(void)
{
UNITY_UINT16 v0, v1;
UNITY_UINT16 *p0, *p1;
v0 = 0x0000;
v1 = 0xFFFF;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_HEX16(v0, v1);
TEST_ASSERT_GREATER_THAN_HEX16(*p0, v1);
TEST_ASSERT_GREATER_THAN_HEX16(v0, *p1);
TEST_ASSERT_GREATER_THAN_HEX16(*p0, *p1);
}
void testGreaterThanHEX32(void)
{
UNITY_UINT32 v0, v1;
UNITY_UINT32 *p0, *p1;
v0 = 0x00000000;
v1 = 0xFFFFFFFF;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_GREATER_THAN_HEX32(v0, v1);
TEST_ASSERT_GREATER_THAN_HEX32(*p0, v1);
TEST_ASSERT_GREATER_THAN_HEX32(v0, *p1);
TEST_ASSERT_GREATER_THAN_HEX32(*p0, *p1);
}
void testNotGreaterThan(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_GREATER_THAN(0, -1);
VERIFY_FAILS_END
}
void testLessThan(void)
{
UNITY_INT v0, v1;
UNITY_INT *p0, *p1;
v0 = 0;
v1 = -1;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN(v0, v1);
TEST_ASSERT_LESS_THAN(*p0, v1);
TEST_ASSERT_LESS_THAN(v0, *p1);
TEST_ASSERT_LESS_THAN(*p0, *p1);
}
void testLessThanINT(void)
{
UNITY_INT v0, v1;
UNITY_INT *p0, *p1;
v0 = 3334;
v1 = 302;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_INT(v0, v1);
TEST_ASSERT_LESS_THAN_INT(*p0, v1);
TEST_ASSERT_LESS_THAN_INT(v0, *p1);
TEST_ASSERT_LESS_THAN_INT(*p0, *p1);
}
void testLessThanINT8(void)
{
UNITY_INT8 v0, v1;
UNITY_INT8 *p0, *p1;
v0 = 127;
v1 = -128;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_INT8(v0, v1);
TEST_ASSERT_LESS_THAN_INT8(*p0, v1);
TEST_ASSERT_LESS_THAN_INT8(v0, *p1);
TEST_ASSERT_LESS_THAN_INT8(*p0, *p1);
}
void testLessThanINT16(void)
{
UNITY_INT16 v0, v1;
UNITY_INT16 *p0, *p1;
v0 = 32767;
v1 = -32768;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_INT16(v0, v1);
TEST_ASSERT_LESS_THAN_INT16(*p0, v1);
TEST_ASSERT_LESS_THAN_INT16(v0, *p1);
TEST_ASSERT_LESS_THAN_INT16(*p0, *p1);
}
void testLessThanINT32(void)
{
UNITY_INT32 v0, v1;
UNITY_INT32 *p0, *p1;
v0 = 214783647;
v1 = -214783648;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_INT32(v0, v1);
TEST_ASSERT_LESS_THAN_INT32(*p0, v1);
TEST_ASSERT_LESS_THAN_INT32(v0, *p1);
TEST_ASSERT_LESS_THAN_INT32(*p0, *p1);
}
void testLessThanUINT(void)
{
UNITY_UINT v0, v1;
UNITY_UINT *p0, *p1;
v0 = 1;
v1 = 0;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_UINT(v0, v1);
TEST_ASSERT_LESS_THAN_UINT(*p0, v1);
TEST_ASSERT_LESS_THAN_UINT(v0, *p1);
TEST_ASSERT_LESS_THAN_UINT(*p0, *p1);
}
void testLessThanUINT8(void)
{
UNITY_UINT8 v0, v1;
UNITY_UINT8 *p0, *p1;
v0 = 255;
v1 = 0;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_UINT8(v0, v1);
TEST_ASSERT_LESS_THAN_UINT8(*p0, v1);
TEST_ASSERT_LESS_THAN_UINT8(v0, *p1);
TEST_ASSERT_LESS_THAN_UINT8(*p0, *p1);
}
void testLessThanUINT16(void)
{
UNITY_UINT16 v0, v1;
UNITY_UINT16 *p0, *p1;
v0 = 65535;
v1 = 0;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_UINT16(v0, v1);
TEST_ASSERT_LESS_THAN_UINT16(*p0, v1);
TEST_ASSERT_LESS_THAN_UINT16(v0, *p1);
TEST_ASSERT_LESS_THAN_UINT16(*p0, *p1);
}
void testLessThanUINT32(void)
{
UNITY_UINT32 v0, v1;
UNITY_UINT32 *p0, *p1;
v0 = 4294967295;
v1 = 0;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_UINT32(v0, v1);
TEST_ASSERT_LESS_THAN_UINT32(*p0, v1);
TEST_ASSERT_LESS_THAN_UINT32(v0, *p1);
TEST_ASSERT_LESS_THAN_UINT32(*p0, *p1);
}
void testLessThanHEX8(void)
{
UNITY_UINT8 v0, v1;
UNITY_UINT8 *p0, *p1;
v0 = 0xFF;
v1 = 0x00;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_HEX8(v0, v1);
TEST_ASSERT_LESS_THAN_HEX8(*p0, v1);
TEST_ASSERT_LESS_THAN_HEX8(v0, *p1);
TEST_ASSERT_LESS_THAN_HEX8(*p0, *p1);
}
void testLessThanHEX16(void)
{
UNITY_UINT16 v0, v1;
UNITY_UINT16 *p0, *p1;
v0 = 0xFFFF;
v1 = 0x0000;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_HEX16(v0, v1);
TEST_ASSERT_LESS_THAN_HEX16(*p0, v1);
TEST_ASSERT_LESS_THAN_HEX16(v0, *p1);
TEST_ASSERT_LESS_THAN_HEX16(*p0, *p1);
}
void testLessThanHEX32(void)
{
UNITY_UINT32 v0, v1;
UNITY_UINT32 *p0, *p1;
v0 = 0xFFFFFFFF;
v1 = 0x00000000;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_LESS_THAN_HEX32(v0, v1);
TEST_ASSERT_LESS_THAN_HEX32(*p0, v1);
TEST_ASSERT_LESS_THAN_HEX32(v0, *p1);
TEST_ASSERT_LESS_THAN_HEX32(*p0, *p1);
}
void testNotLessThan(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_LESS_THAN(0, 1);
VERIFY_FAILS_END
}
//-----------------
void testEqualStrings(void) void testEqualStrings(void)
{ {
const char *testString = "foo"; const char *testString = "foo";
@@ -4466,46 +4056,61 @@ void testFloatPrinting(void)
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY) #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE(); TEST_IGNORE();
#else #else
TEST_ASSERT_EQUAL_PRINT_FLOATING("0", 0.0f); TEST_ASSERT_EQUAL_PRINT_FLOATING("0.0", 0.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.99e-07", 0.000000499f); TEST_ASSERT_EQUAL_PRINT_FLOATING("0.000000...", 0.000000499f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("5e-07", 0.00000050000005f); TEST_ASSERT_EQUAL_PRINT_FLOATING("0.000001", 0.00000050000005f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.100469499f); TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.100469499f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 0.9999995f); /*Rounding to int place*/ TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0", 0.9999995f); /*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 1.0f); TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0", 1.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.25", 1.25f); TEST_ASSERT_EQUAL_PRINT_FLOATING("1.25", 1.25f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("7.99999", 7.99999f); /*Not rounding*/ TEST_ASSERT_EQUAL_PRINT_FLOATING("7.999999", 7.999999f); /*Not rounding*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0002", 16.0002f); TEST_ASSERT_EQUAL_PRINT_FLOATING("16.000002", 16.000002f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0004", 16.0004f); TEST_ASSERT_EQUAL_PRINT_FLOATING("16.000004", 16.000004f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0006", 16.0006f); TEST_ASSERT_EQUAL_PRINT_FLOATING("16.000006", 16.000006f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("999999", 999999.0f); /*Last full print integer*/ TEST_ASSERT_EQUAL_PRINT_FLOATING("4294967040.0", 4294967040.0f); /*Last full print integer*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0", -0.0f); TEST_ASSERT_EQUAL_PRINT_FLOATING("0.0", -0.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.99e-07", -0.000000499f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.000000...",-0.000000499f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-5e-07", -0.00000050000005f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.000001", -0.00000050000005f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.100469499f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.100469499f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -0.9999995f); /*Rounding to int place*/ TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.0", -0.9999995f); /*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -1.0f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.0", -1.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.25", -1.25f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.25", -1.25f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.99999", -7.99999f); /*Not rounding*/ TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.999999", -7.999999f); /*Not rounding*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0002", -16.0002f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.000002", -16.000002f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0004", -16.0004f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.000004", -16.000004f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0006", -16.0006f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.000006", -16.000006f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-999999", -999999.0f); /*Last full print integer*/ TEST_ASSERT_EQUAL_PRINT_FLOATING("-4294967040.0",-4294967040.0f); /*Last full print integer*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967296.0f); TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967296.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("5e+09", 5000000000.0f); TEST_ASSERT_EQUAL_PRINT_FLOATING("5.0e+09", 5000000000.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("8e+09", 8.0e+09f); TEST_ASSERT_EQUAL_PRINT_FLOATING("8.0e+09", 8.0e+09f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("8.31e+09", 8309999104.0f); TEST_ASSERT_EQUAL_PRINT_FLOATING("8.3099991e+09", 8309999104.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 1.0e+10f); TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 1.0e+10f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 10000000000.0f); TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 10000000000.0f);
/* Some compilers have trouble with inexact float constants, a float cast works generally */ /* Some compilers have trouble with inexact float constants, a float cast works generally */
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00005e+10", (float)1.000054e+10f); TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00005499e+10", (float)1.000055e+10f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.1e+38", (float)1.10000005e+38f); TEST_ASSERT_EQUAL_PRINT_FLOATING("1.10000006e+38", (float)1.10000005e+38f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.6353e+10", 1.63529943e+10f); TEST_ASSERT_EQUAL_PRINT_FLOATING("1.63529943e+10", 1.63529943e+10f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("3.40282e+38", 3.40282346638e38f); TEST_ASSERT_EQUAL_PRINT_FLOATING("3.40282347e+38", 3.40282346638e38f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1e+10", -1.0e+10f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.0e+10", -1.0e+10f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-3.40282e+38", -3.40282346638e38f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-3.40282347e+38",-3.40282346638e38f);
#endif
}
void testFloatPrintingRoundTiesToEven(void)
{
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE();
#else
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.007813", 0.0078125f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.976563", 0.9765625f);
#else /* Default to Round ties to even */
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.007182", 0.0071825f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.976562", 0.9765625f);
#endif
#endif #endif
} }
@@ -4514,69 +4119,105 @@ void testFloatPrintingInfinityAndNaN(void)
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY) #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE(); TEST_IGNORE();
#else #else
TEST_ASSERT_EQUAL_PRINT_FLOATING("inf", 1.0f / f_zero); TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.0f / f_zero);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-inf", -1.0f / f_zero); TEST_ASSERT_EQUAL_PRINT_FLOATING("-Inf", -1.0f / f_zero);
TEST_ASSERT_EQUAL_PRINT_FLOATING("nan", 0.0f / f_zero); TEST_ASSERT_EQUAL_PRINT_FLOATING("NaN", 0.0f / f_zero);
#endif #endif
} }
#if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY) #if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY)
static void printFloatValue(float f) static void AllFloatPrinting_LessThan32Bits(void)
{ {
char expected[18]; char expected[18];
char expected_lower[18]; union { float f_value; int32_t int_value; } u;
char expected_higher[18]; /* Float representations are laid out in integer order, walk up the list */
for (u.f_value = 0.00000050000005f; u.f_value <= 4294967040.0f; u.int_value += 1)
{
startPutcharSpy(); startPutcharSpy();
UnityPrintFloat(f); UnityPrintFloat(u.f_value); /*1.5x as fast as sprintf 5e-7f - 0.01f, 20s vs 30s*/
int len = sprintf(expected, "%.6f", u.f_value);
sprintf(expected, "%.6g", f); while (expected[len - 1] == '0' && expected[len - 2] != '.') { len--; }
expected[len] = '\0'; /* delete trailing 0's */
/* We print all NaN's as "nan", not "-nan" */ if (strcmp(expected, getBufferPutcharSpy()) != 0)
if(strcmp(expected, "-nan") == 0) strcpy(expected, "nan"); {
double six_digits = ((double)u.f_value - (uint32_t)u.f_value)*1000000.0;
/* Allow for rounding differences in last digit */ /* Not a tie (remainder != 0.5) => Can't explain the different strings */
double lower = (double)f * 0.9999995; if (six_digits - (uint32_t)six_digits != 0.5)
double higher = (double)f * 1.0000005;
if (isfinite(lower)) sprintf(expected_lower, "%.6g", lower); else strcpy(expected_lower, expected);
if (isfinite(higher)) sprintf(expected_higher, "%.6g", higher); else strcpy(expected_higher, expected);
if (strcmp(expected, getBufferPutcharSpy()) != 0 &&
strcmp(expected_lower, getBufferPutcharSpy()) != 0 &&
strcmp(expected_higher, getBufferPutcharSpy()) != 0)
{ {
/* Fail with diagnostic printing */ /* Fail with diagnostic printing */
TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, f); TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, u.f_value);
}
}
}
}
/* Compared to perfect, floats are occasionally rounded wrong. It doesn't affect
* correctness, though. Two examples (of 13 total found during testing):
* Printed: 6.19256349e+20, Exact: 619256348499999981568.0f <= Eliminated by ROUND_TIES_TO_EVEN
* Printed: 2.19012272e+35, Exact: 219012271499999993621766990196637696.0f */
static void AllFloatPrinting_Larger(const float start, const float end)
{
unsigned int wrong = 0;
char expected[18];
union { float f_value; int32_t int_value; } u;
for (u.f_value = start; u.f_value <= end; u.int_value += 1)
{
startPutcharSpy();
UnityPrintFloat(u.f_value); /*Twice as fast as sprintf 2**32-1e12, 10s vs 21s*/
sprintf(expected, "%.8e", u.f_value);
int len = 11 - 1; /* 11th char is 'e' in exponential format */
while (expected[len - 1] == '0' && expected[len - 2] != '.') { len --; }
if (expected[14] != '\0') memmove(&expected[12], &expected[13], 3); /* Two char exponent */
memmove(&expected[len], &expected[11 - 1], sizeof "e+09"); /* 5 char length */
if (strcmp(expected, getBufferPutcharSpy()) != 0)
{
wrong++;
/* endPutcharSpy(); UnityPrint("Expected "); UnityPrint(expected);
UnityPrint(" Was "); UnityPrint(getBufferPutcharSpy()); UNITY_OUTPUT_CHAR('\n'); */
if (wrong > 10 || (wrong > 3 && end <= 1e25f))
TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, u.f_value);
/* Empirical values from the current routine, don't be worse when making changes */
}
} }
} }
#endif #endif
void testFloatPrintingRandomSamples(void) /* Exhaustive testing of all float values we differentiate when printing. Doubles
* are not explored here -- too many. These tests confirm that the routine works
* for all floats > 5e-7, positives only. Off by default due to test time.
* Compares Unity's routine to your sprintf() C lib, tested to pass on 3 platforms.
* Part1 takes a long time, around 3 minutes compiled with -O2
* Runs through all floats from 0.000001 - 2**32, ~300 million values */
void testAllFloatPrintingPart1_LessThan32Bits(void)
{ {
#if !defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) || !defined(USING_OUTPUT_SPY) #if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY)
TEST_IGNORE(); AllFloatPrinting_LessThan32Bits();
#else #else
union { float f_value; uint32_t int_value; } u; TEST_IGNORE(); /* Ignore one of three */
#endif
}
/* These values are not covered by the MINSTD generator */ /* Test takes a long time, around 3.5 minutes compiled with -O2, try ~500 million values */
u.int_value = 0x00000000; printFloatValue(u.f_value); void testAllFloatPrintingPart2_Larger(void)
u.int_value = 0x80000000; printFloatValue(u.f_value); {
u.int_value = 0x7fffffff; printFloatValue(u.f_value); #if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY)
u.int_value = 0xffffffff; printFloatValue(u.f_value); AllFloatPrinting_Larger(4294967296.0f, 1e25f);
#endif
}
uint32_t a = 1; /* Test takes a long time, around 3.5 minutes compiled with -O2, try ~500 million values */
for(int num_tested = 0; num_tested < 1000000; num_tested++) void testAllFloatPrintingPart3_LargerStill(void)
{ {
/* MINSTD pseudo-random number generator */ #if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY)
a = (uint32_t)(((uint64_t)a * 48271u) % 2147483647u); AllFloatPrinting_Larger(1e25f, 3.40282347e+38f);
/* MINSTD does not set the highest bit; test both possibilities */
u.int_value = a; printFloatValue(u.f_value);
u.int_value = a | 0x80000000; printFloatValue(u.f_value);
}
#endif #endif
} }
@@ -5253,19 +4894,34 @@ void testDoublePrinting(void)
TEST_IGNORE(); TEST_IGNORE();
#else #else
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.10046949999999999); TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.10046949999999999);
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967295.999999); TEST_ASSERT_EQUAL_PRINT_FLOATING("4294967295.999999", 4294967295.999999);
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967295.9999995); TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967295.9999995);
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967296.0); TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967296.0);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 9999999995.0); TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 9999999995.0);
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.0072e+15", 9007199254740990.0); TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199254740990.0);
TEST_ASSERT_EQUAL_PRINT_FLOATING("7e+100", 7.0e+100); TEST_ASSERT_EQUAL_PRINT_FLOATING("7.0e+100", 7.0e+100);
TEST_ASSERT_EQUAL_PRINT_FLOATING("3e+200", 3.0e+200); TEST_ASSERT_EQUAL_PRINT_FLOATING("3.0e+200", 3.0e+200);
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.23457e+300", 9.23456789e+300); TEST_ASSERT_EQUAL_PRINT_FLOATING("9.23456789e+300", 9.23456789e+300);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.10046949999999999); TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.10046949999999999);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.29497e+09", -4294967295.999999); TEST_ASSERT_EQUAL_PRINT_FLOATING("-4294967295.999999", -4294967295.999999);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.29497e+09", -4294967295.9999995); TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.2949673e+09", -4294967295.9999995);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-7e+100", -7.0e+100); TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.0e+100", -7.0e+100);
#endif
}
void testDoublePrintingRoundTiesToEven(void)
{
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE();
#else
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00000001e+10", 10000000050.0);
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199245000000.0);
#else /* Default to Round ties to even */
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 10000000050.0);
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719924e+15", 9007199245000000.0);
#endif
#endif #endif
} }
@@ -5274,10 +4930,10 @@ void testDoublePrintingInfinityAndNaN(void)
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY) #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE(); TEST_IGNORE();
#else #else
TEST_ASSERT_EQUAL_PRINT_FLOATING("inf", 1.0 / d_zero); TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.0 / d_zero);
TEST_ASSERT_EQUAL_PRINT_FLOATING("-inf", -1.0 / d_zero); TEST_ASSERT_EQUAL_PRINT_FLOATING("-Inf", -1.0 / d_zero);
TEST_ASSERT_EQUAL_PRINT_FLOATING("nan", 0.0 / d_zero); TEST_ASSERT_EQUAL_PRINT_FLOATING("NaN", 0.0 / d_zero);
#endif #endif
} }
-6
View File
@@ -1,6 +0,0 @@
{
suppress_ld_on_armv7
Memcheck:Cond
...
obj:*/ld-*.so
}