From 38b2f40a9abc6e73d33b9cb0440900b8c3e46d6f Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Wed, 10 May 2017 01:17:36 +0200 Subject: [PATCH 01/23] Add warning -Wunused-macro --- CMakeLists.txt | 1 + cJSON.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3f6f6b..8944894 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ if (ENABLE_CUSTOM_COMPILER_FLAGS) -Wdouble-promotion -Wparentheses -Wformat-overflow + -Wunused-macros ) endif() diff --git a/cJSON.c b/cJSON.c index 314560b..6e8255a 100644 --- a/cJSON.c +++ b/cJSON.c @@ -208,7 +208,6 @@ typedef struct /* check if the given size is left to read in a given parse buffer (starting with 1) */ #define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) -#define cannot_read(buffer, size) (!can_read(buffer, size)) /* check if the buffer can be accessed at the given index (starting with 0) */ #define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) #define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) From 4e0c119391ae952dd1ba02c8c3a7279ef31d6329 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Wed, 10 May 2017 01:19:52 +0200 Subject: [PATCH 02/23] Add warning -Wmissing-variable-declarations --- CMakeLists.txt | 1 + tests/json_patch_tests.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8944894..7dbb289 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ if (ENABLE_CUSTOM_COMPILER_FLAGS) -Wparentheses -Wformat-overflow -Wunused-macros + -Wmissing-variable-declarations ) endif() diff --git a/tests/json_patch_tests.c b/tests/json_patch_tests.c index 3d4df41..c2c88a4 100644 --- a/tests/json_patch_tests.c +++ b/tests/json_patch_tests.c @@ -119,7 +119,7 @@ static cJSON_bool test_apply_patch(const cJSON * const test) return successful; } -static cJSON_bool test_generate_test(cJSON *test __attribute__((unused))) +static cJSON_bool test_generate_test(cJSON *test) { cJSON *doc = NULL; cJSON *patch = NULL; From eb8c0baa3b3e35ce83cc063041935c07ec778fff Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Wed, 10 May 2017 01:20:58 +0200 Subject: [PATCH 03/23] Add warning -Wused-but-marked-unused --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7dbb289..1c3f69e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ if (ENABLE_CUSTOM_COMPILER_FLAGS) -Wformat-overflow -Wunused-macros -Wmissing-variable-declarations + -Wused-but-marked-unused ) endif() From a9ce4e6bbc44048ae8f8786008d6ee9b316c65fb Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Wed, 10 May 2017 01:21:13 +0200 Subject: [PATCH 04/23] Add warning -Wswitch-enum --- CMakeLists.txt | 1 + tests/CMakeLists.txt | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c3f69e..151eb29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ if (ENABLE_CUSTOM_COMPILER_FLAGS) -Wunused-macros -Wmissing-variable-declarations -Wused-but-marked-unused + -Wswitch-enum ) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 47d7c1a..d69f3f8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,6 +25,14 @@ if(ENABLE_CJSON_TEST) target_compile_options(unity PRIVATE "-fno-sanitize=float-divide-by-zero") endif() endif() + # Disable -Wswitch-enum for Unity + if (FLAG_SUPPORTED_Wswitchenum) + if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch-enum") + else() + target_compile_options(unity PRIVATE "-Wno-switch-enum") + endif() + endif() #copy test files file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inputs") From 21733eb02e8458181a5f2d06acb4a5cfc6e71b3f Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sun, 14 May 2017 14:49:27 +0200 Subject: [PATCH 05/23] tests/print_number: Use proper double literals --- tests/print_number.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/print_number.c b/tests/print_number.c index 299cefc..bda455c 100644 --- a/tests/print_number.c +++ b/tests/print_number.c @@ -49,16 +49,16 @@ static void print_number_should_print_zero(void) static void print_number_should_print_negative_integers(void) { - assert_print_number("-1", -1); - assert_print_number("-32768", -32768); + assert_print_number("-1", -1.0); + assert_print_number("-32768", -32768.0); assert_print_number("-2147483648", -2147483648.0); } static void print_number_should_print_positive_integers(void) { - assert_print_number("1", 1); - assert_print_number("32767", 32767); - assert_print_number("2147483647", 2147483647); + assert_print_number("1", 1.0); + assert_print_number("32767", 32767.0); + assert_print_number("2147483647", 2147483647.0); } static void print_number_should_print_positive_reals(void) From e872d402235f1e5aecb99a32960fc0bbb478b9c9 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sat, 17 Jun 2017 14:21:08 +0200 Subject: [PATCH 06/23] MSVC: Disable deprecation warnings for C89 functions C89 sadly doesn't provide safe alternatives for strcpy, sprintf and the like. --- cJSON.c | 5 +++++ cJSON_Utils.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/cJSON.c b/cJSON.c index 6e8255a..9c86128 100644 --- a/cJSON.c +++ b/cJSON.c @@ -23,6 +23,11 @@ /* cJSON */ /* 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__ #pragma GCC visibility push(default) #endif diff --git a/cJSON_Utils.c b/cJSON_Utils.c index 84319cc..e7bf802 100644 --- a/cJSON_Utils.c +++ b/cJSON_Utils.c @@ -20,6 +20,10 @@ 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 #pragma GCC visibility push(default) #include #include From 217ab0261248a0b698f8201987169266f71a8373 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sat, 17 Jun 2017 14:23:12 +0200 Subject: [PATCH 07/23] cJSON_Utils: Guard gcc pragmas with a check for __GCC__ --- cJSON_Utils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cJSON_Utils.c b/cJSON_Utils.c index e7bf802..2baa492 100644 --- a/cJSON_Utils.c +++ b/cJSON_Utils.c @@ -24,13 +24,18 @@ #if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) #define _CRT_SECURE_NO_DEPRECATE #endif + +#ifdef __GNUCC__ #pragma GCC visibility push(default) +#endif #include #include #include #include #include +#ifdef __GNUCC__ #pragma GCC visibility pop +#endif #include "cJSON_Utils.h" From 45e1278acbf789b1a855b2cc81112b4768a27b3b Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sun, 14 May 2017 14:49:55 +0200 Subject: [PATCH 08/23] tests/print_number: Add test with 17 digits of precision --- tests/print_number.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/print_number.c b/tests/print_number.c index bda455c..5ebb348 100644 --- a/tests/print_number.c +++ b/tests/print_number.c @@ -68,6 +68,7 @@ static void print_number_should_print_positive_reals(void) assert_print_number("1000000000000", 10e11); assert_print_number("1.23e+129", 123e+127); assert_print_number("1.23e-126", 123e-128); + assert_print_number("3.1415926535897931", 3.1415926535897931); } static void print_number_should_print_negative_reals(void) From 0d675cb048b9fd4ad5365e6df336b33ae3374275 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sat, 17 Jun 2017 14:26:25 +0200 Subject: [PATCH 09/23] MSVC: Disable warning about single line comments in system headers --- cJSON.c | 8 ++++++++ cJSON_Utils.c | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/cJSON.c b/cJSON.c index 9c86128..e816cde 100644 --- a/cJSON.c +++ b/cJSON.c @@ -31,6 +31,11 @@ #ifdef __GNUC__ #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 #include @@ -41,6 +46,9 @@ #include #include +#if defined(_MSC_VER) +#pragma warning (pop) +#endif #ifdef __GNUC__ #pragma GCC visibility pop #endif diff --git a/cJSON_Utils.c b/cJSON_Utils.c index 2baa492..b83cfcd 100644 --- a/cJSON_Utils.c +++ b/cJSON_Utils.c @@ -28,11 +28,21 @@ #ifdef __GNUCC__ #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 #include #include #include #include + +#if defined(_MSC_VER) +#pragma warning (pop) +#endif #ifdef __GNUCC__ #pragma GCC visibility pop #endif From 04e27dc8c51afce0fe9fccc628eeb29661c6684a Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Wed, 7 Jun 2017 00:15:23 +0200 Subject: [PATCH 10/23] CMake: New option BUILD_SHARED_AND_STATIC_LIBS --- CMakeLists.txt | 31 ++++++++++++++++++++++++++++--- README.md | 1 + 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 151eb29..f012f95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,17 @@ set(CJSON_LIB cjson) file(GLOB HEADERS cJSON.h) set(SOURCES cJSON.c) -add_library("${CJSON_LIB}" "${HEADERS}" "${SOURCES}") +option(BUILD_SHARED_AND_STATIC_LIBS "Build both shared and static libraries" Off) + +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) target_link_libraries("${CJSON_LIB}" m) endif() @@ -114,6 +124,9 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson.pc.in" install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson") install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 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) # export library information for CMake projects install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON") @@ -132,13 +145,25 @@ if(ENABLE_CJSON_UTILS) file(GLOB HEADERS_UTILS cJSON_Utils.h) set(SOURCES_UTILS cJSON_Utils.c) - add_library("${CJSON_UTILS_LIB}" "${HEADERS_UTILS}" "${SOURCES_UTILS}") - target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}") + if (NOT BUILD_SHARED_AND_STATIC_LIBS) + add_library("${CJSON_UTILS_LIB}" "${HEADERS_UTILS}" "${SOURCES_UTILS}") + target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}") + else() + add_library("${CJSON_UTILS_LIB}" SHARED "${HEADERS_UTILS}" "${SOURCES_UTILS}") + target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}") + add_library("${CJSON_UTILS_LIB}-static" STATIC "${HEADERS_UTILS}" "${SOURCES_UTILS}") + target_link_libraries("${CJSON_UTILS_LIB}-static" "${CJSON_LIB}-static") + set_target_properties("${CJSON_UTILS_LIB}-static" PROPERTIES OUTPUT_NAME "${CJSON_UTILS_LIB}") + set_target_properties("${CJSON_UTILS_LIB}-static" PROPERTIES PREFIX "lib") + endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson_utils.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY) 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 "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") if(ENABLE_TARGET_EXPORT) diff --git a/README.md b/README.md index 4dba514..b22025a 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ You can change the build process with a list of different options that you can p * `-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) * `-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. If you are packaging cJSON for a distribution of Linux, you would probably take these steps for example: From d1c2e2df4a7cddaae621d2d9c973fa8b8f6b672d Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sat, 17 Jun 2017 14:33:04 +0200 Subject: [PATCH 11/23] MSVC: workaround for C2322 --- cJSON.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index e816cde..f6ee1ad 100644 --- a/cJSON.c +++ b/cJSON.c @@ -114,7 +114,27 @@ typedef struct internal_hooks void *(*reallocate)(void *pointer, size_t size); } internal_hooks; -static internal_hooks global_hooks = { malloc, free, realloc }; +#if defined(_MSC_VER) +/* 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) { From ac368e9dfb3bc5ab23e2495fbb8234f090424b8b Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sat, 17 Jun 2017 14:33:55 +0200 Subject: [PATCH 12/23] MSVC: Fix warning about assignment in condition --- cJSON.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index f6ee1ad..81b9197 100644 --- a/cJSON.c +++ b/cJSON.c @@ -147,7 +147,8 @@ static unsigned char* cJSON_strdup(const unsigned char* string, const internal_h } length = strlen((const char*)string) + sizeof(""); - if (!(copy = (unsigned char*)hooks->allocate(length))) + copy = (unsigned char*)hooks->allocate(length); + if (copy == NULL) { return NULL; } From e174831819e46afc5797974efd92c92cb13bc9bd Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sat, 17 Jun 2017 14:42:52 +0200 Subject: [PATCH 13/23] CMake: Add custom compiler flags for MSVC --- CMakeLists.txt | 67 ++++++++++++++++++++++++++++---------------------- README.md | 2 +- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f012f95..a55acac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,37 +16,46 @@ set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT set(custom_compiler_flags) include(CheckCCompilerFlag) -option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags for Clang and GCC" ON) +option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags" ON) if (ENABLE_CUSTOM_COMPILER_FLAGS) - list(APPEND custom_compiler_flags - -std=c89 - -pedantic - -Wall - -Wextra - -Werror - -Wstrict-prototypes - -Wwrite-strings - -Wshadow - -Winit-self - -Wcast-align - -Wformat=2 - -Wmissing-prototypes - -Wstrict-overflow=2 - -Wcast-qual - -Wundef - -Wswitch-default - -Wconversion - -Wc++-compat - -fstack-protector-strong - -Wcomma - -Wdouble-promotion - -Wparentheses - -Wformat-overflow - -Wunused-macros - -Wmissing-variable-declarations - -Wused-but-marked-unused - -Wswitch-enum + if (("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")) + list(APPEND custom_compiler_flags + -std=c89 + -pedantic + -Wall + -Wextra + -Werror + -Wstrict-prototypes + -Wwrite-strings + -Wshadow + -Winit-self + -Wcast-align + -Wformat=2 + -Wmissing-prototypes + -Wstrict-overflow=2 + -Wcast-qual + -Wundef + -Wswitch-default + -Wconversion + -Wc++-compat + -fstack-protector-strong + -Wcomma + -Wdouble-promotion + -Wparentheses + -Wformat-overflow + -Wunused-macros + -Wmissing-variable-declarations + -Wused-but-marked-unused + -Wswitch-enum ) + elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") + list(APPEND custom_compiler_flags + /GS + /Za + /sdl + /W4 + ) + endif() endif() option(ENABLE_SANITIZERS "Enables AddressSanitizer and UndefinedBehaviorSanitizer." OFF) diff --git a/README.md b/README.md index b22025a..a363f52 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ 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_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_CUSTOM_COMPILER_FLAGS=On`: Enable custom compiler flags (currently for Clang and GCC). 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_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) * `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default) From 7a2615c2315713ca1a96d37e8a2015b371e6258d Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sat, 17 Jun 2017 15:04:29 +0200 Subject: [PATCH 14/23] Fix: Check if __GNUCC__ is defined This has been detected via MSVC's Warning C4668 --- cJSON.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cJSON.c b/cJSON.c index 81b9197..b689361 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1849,7 +1849,7 @@ CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSO item->type &= ~cJSON_StringIsConst; } -#if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) #pragma GCC diagnostic push #endif #ifdef __GNUC__ @@ -1871,7 +1871,7 @@ CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJ item->type |= cJSON_StringIsConst; cJSON_AddItemToArray(object, item); } -#if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) #pragma GCC diagnostic pop #endif From 5baa77f86cb9dffe20b5f9ab85e00baa8fe70a0b Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Mon, 3 Jul 2017 21:43:14 +0200 Subject: [PATCH 15/23] cJSON_Parse{,WithOpts}: Skip UTF-8 (Byte Order Marks) --- cJSON.c | 19 +++++++++++++++++-- tests/misc_tests.c | 26 ++++++++++++++++++++++++++ tests/parse_with_opts.c | 17 +++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/cJSON.c b/cJSON.c index b689361..9c567ff 100644 --- a/cJSON.c +++ b/cJSON.c @@ -958,6 +958,22 @@ static parse_buffer *buffer_skip_whitespace(parse_buffer * const 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. */ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) { @@ -984,7 +1000,7 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return goto fail; } - if (!parse_value(item, buffer_skip_whitespace(&buffer))) + if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) { /* parse failure. ep is set. */ goto fail; @@ -1222,7 +1238,6 @@ static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buf return parse_object(item, input_buffer); } - return false; } diff --git a/tests/misc_tests.c b/tests/misc_tests.c index 7d51179..2f1efe4 100644 --- a/tests/misc_tests.c +++ b/tests/misc_tests.c @@ -410,6 +410,30 @@ static void cjson_functions_shouldnt_crash_with_null_pointers(void) cJSON_Delete(item); } +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) { UNITY_BEGIN(); @@ -425,6 +449,8 @@ int main(void) RUN_TEST(cjson_replace_item_via_pointer_should_replace_items); RUN_TEST(cjson_replace_item_in_object_should_preserve_name); RUN_TEST(cjson_functions_shouldnt_crash_with_null_pointers); + RUN_TEST(skip_utf8_bom_should_skip_bom); + RUN_TEST(skip_utf8_bom_should_not_skip_bom_if_not_at_beginning); return UNITY_END(); } diff --git a/tests/parse_with_opts.c b/tests/parse_with_opts.c index 0557467..066d2cd 100644 --- a/tests/parse_with_opts.c +++ b/tests/parse_with_opts.c @@ -69,6 +69,22 @@ static void parse_with_opts_should_return_parse_end(void) 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) { UNITY_BEGIN(); @@ -77,6 +93,7 @@ int main(void) RUN_TEST(parse_with_opts_should_handle_empty_strings); 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_parse_utf8_bom); return UNITY_END(); } From bf0bc22a1186a3dad2e1d7d1abdf64b64291b512 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Wed, 5 Jul 2017 10:31:00 +0200 Subject: [PATCH 16/23] CMake: Add ENABLE_SAFE_STACK option --- .travis.yml | 2 +- CMakeLists.txt | 10 ++++++++++ README.md | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d722664..e7ff744 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,6 @@ addons: script: - mkdir build - cd build - - cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_VALGRIND="${VALGRIND}" -DENABLE_SANITIZERS="${SANITIZERS}" + - cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_VALGRIND="${VALGRIND}" -DENABLE_SAFE_STACK="${VALGRIND}" -DENABLE_SANITIZERS="${SANITIZERS}" - make - make test CTEST_OUTPUT_ON_FAILURE=On diff --git a/CMakeLists.txt b/CMakeLists.txt index a55acac..ec5196b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,16 @@ if (ENABLE_SANITIZERS) ) 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) if (ENABLE_PUBLIC_SYMBOLS) list(APPEND custom_compiler_flags -fvisibility=hidden) diff --git a/README.md b/README.md index a363f52..6ff4e95 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ You can change the build process with a list of different options that you can p * `-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_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_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_AND_STATIC_LIBS=On`: Build both shared and static libraries. (off by default) * `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation. From dd980008f712ce5b46b95afc6068a0b2121581e5 Mon Sep 17 00:00:00 2001 From: simon-p-r Date: Sun, 9 Jul 2017 22:20:35 +0100 Subject: [PATCH 17/23] add appveyor --- appveyor.yml | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..db5f2a4 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,82 @@ +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 + +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 } \ No newline at end of file From 824e1b2a99793341f97195209896169b8b33b0a7 Mon Sep 17 00:00:00 2001 From: simon-p-r Date: Mon, 10 Jul 2017 10:38:21 +0100 Subject: [PATCH 18/23] patch for Visual Studio 9 2008 x64 failed builds --- appveyor-patch.ps1 | 11 +++++++++++ appveyor.yml | 1 + 2 files changed, 12 insertions(+) create mode 100644 appveyor-patch.ps1 diff --git a/appveyor-patch.ps1 b/appveyor-patch.ps1 new file mode 100644 index 0000000..34d2163 --- /dev/null +++ b/appveyor-patch.ps1 @@ -0,0 +1,11 @@ +# Script to patch Appveyor build environment for Visual Studio 2008 64bit + +$url = "https://github.com/menpo/condaci/raw/master/vs2008_patch.zip" +$output = "$pwd\build\vs2008_patch.zip" + +(New-Object System.Net.WebClient).DownloadFile($url, $output) + +7z -e "$pwd\build\vs2008_patch.zip" +cmd.exe /c "$pwd\build\vs2008_patch\setup_x64.bat" + + diff --git a/appveyor.yml b/appveyor.yml index db5f2a4..f9c586a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -72,6 +72,7 @@ configuration: build_script: + - ps: if($env:PLATFORM -eq "x64" -And $GENERATOR -eq 'Visual Studio 9 2008') { .\appveyor-patch.ps1 } - 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%" From c6f7f78cbbf8d549d833bd5f261e74303829cb7f Mon Sep 17 00:00:00 2001 From: simon-p-r Date: Mon, 10 Jul 2017 10:50:55 +0100 Subject: [PATCH 19/23] added copy to powershell script --- appveyor-patch.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor-patch.ps1 b/appveyor-patch.ps1 index 34d2163..b380d53 100644 --- a/appveyor-patch.ps1 +++ b/appveyor-patch.ps1 @@ -8,4 +8,6 @@ $output = "$pwd\build\vs2008_patch.zip" 7z -e "$pwd\build\vs2008_patch.zip" cmd.exe /c "$pwd\build\vs2008_patch\setup_x64.bat" +copy C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat + From 2caa884f6a786c900754c25a19083e21db756b68 Mon Sep 17 00:00:00 2001 From: simon-p-r Date: Sat, 15 Jul 2017 09:03:13 +0100 Subject: [PATCH 20/23] removed x64 Visual Studio 9 2008 build --- .gitignore | 1 + appveyor-patch.ps1 | 13 ------------- appveyor.yml | 4 +++- 3 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 appveyor-patch.ps1 diff --git a/.gitignore b/.gitignore index 33424d9..e2e312b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ cJSON_test_utils libcjson.so.* libcjson_utils.so.* *.orig +.vscode diff --git a/appveyor-patch.ps1 b/appveyor-patch.ps1 deleted file mode 100644 index b380d53..0000000 --- a/appveyor-patch.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -# Script to patch Appveyor build environment for Visual Studio 2008 64bit - -$url = "https://github.com/menpo/condaci/raw/master/vs2008_patch.zip" -$output = "$pwd\build\vs2008_patch.zip" - -(New-Object System.Net.WebClient).DownloadFile($url, $output) - -7z -e "$pwd\build\vs2008_patch.zip" -cmd.exe /c "$pwd\build\vs2008_patch\setup_x64.bat" - -copy C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat - - diff --git a/appveyor.yml b/appveyor.yml index f9c586a..e23eb64 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -66,13 +66,15 @@ environment: platform: - x86 - x64 + exclude: + - platform: x64 + GENERATOR: "Visual Studio 9 2008" configuration: - Release build_script: - - ps: if($env:PLATFORM -eq "x64" -And $GENERATOR -eq 'Visual Studio 9 2008') { .\appveyor-patch.ps1 } - 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%" From f0f3e55d485ece89153f947a5f57f3dbd8877958 Mon Sep 17 00:00:00 2001 From: simon-p-r Date: Sat, 15 Jul 2017 09:06:10 +0100 Subject: [PATCH 21/23] fixed appveyor script --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index e23eb64..464bf03 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -66,6 +66,7 @@ environment: platform: - x86 - x64 +matrix: exclude: - platform: x64 GENERATOR: "Visual Studio 9 2008" From 469a437e2af3b965cafa038bdf17e5fbaa4d3a9e Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sat, 15 Jul 2017 11:59:47 +0200 Subject: [PATCH 22/23] Add valgrind suppressions for ARVMv7 ArchlinuxARM --- tests/CMakeLists.txt | 2 +- valgrind.suppressions | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 valgrind.suppressions diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d69f3f8..b0b867b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -66,7 +66,7 @@ if(ENABLE_CJSON_TEST) message(WARNING "Valgrind couldn't be found.") unset(MEMORYCHECK_COMMAND) else() - set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1) + set(MEMORYCHECK_COMMAND_OPTIONS --suppressions=${CMAKE_SOURCE_DIR}/valgrind.suppressions --trace-children=yes --leak-check=full --error-exitcode=1) endif() endif() diff --git a/valgrind.suppressions b/valgrind.suppressions new file mode 100644 index 0000000..7e5ac8c --- /dev/null +++ b/valgrind.suppressions @@ -0,0 +1,11 @@ +{ + + Memcheck:Cond + fun:index + fun:expand_dynamic_string_token +} +{ + + Memcheck:Cond + fun:expand_dynamic_string_token +} From b7bfe1e91a0b55d72f849944d5a33b7962d7bf51 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Tue, 12 Sep 2017 18:30:07 +0200 Subject: [PATCH 23/23] Squashed 'tests/unity/' changes from 3b69bea..60b13f0 60b13f0 Bump version in preparation of release. f278c18 Fix bug #288 - invalid line numbers on partial name matches bdd4cb1 Merge pull request #294 from jlindgren90/master fcd4883 Fix compiler warning due to reusing symbol 'exp'. 05daf95 Update to match Ruby style guide 7b2ad10 Merge pull request #285 from dpostorivo/gt_lt_asserts 0547aab Merge pull request #291 from jlindgren90/master 2ae2bdb Make code C89-compliant. dbdd168 Fix test link error. 0e7eb54 Rewrite UnityPrintFloat to match printf("%.6g"). a868b2e Merge pull request #286 from palaviv/fix-UNITY_OUTPUT_FLUSH e56378e Add UNITY_OUTPUT_CHAR_HEADER_DECLARATION to fixture tests rakefile_helper.rb ad37302 Add UNITY_OUTPUT_CHAR_HEADER_DECLARATION to tests rakefile_helper.rb b3de931 Add UNITY_OUTPUT_CHAR_HEADER_DECLARATION to fixture tests Makefile defines 59182c4 Add UNITY_OUTPUT_CHAR_HEADER_DECLARATION to tests Makefile defines a07d07c Allow specifying custom header declaration c1bc32d - Generator will not change names by default - Fixed some style issues. f2fdf1a Added Greater than and Less than asserts from other PR git-subtree-dir: tests/unity git-subtree-split: 60b13f0685246b009810aecbffafe17fb665d970 --- README.md | 11 + auto/generate_module.rb | 6 +- auto/generate_test_runner.rb | 2 +- auto/stylize_as_junit.rb | 0 docs/UnityAssertionsReference.md | 54 +++ examples/unity_config.h | 10 +- extras/fixture/rakefile_helper.rb | 2 +- extras/fixture/test/Makefile | 1 + release/build.info | 2 +- release/version.info | 2 +- src/unity.c | 216 ++++++---- src/unity.h | 60 +++ src/unity_internals.h | 54 ++- test/Makefile | 1 + test/rakefile_helper.rb | 2 +- test/tests/testunity.c | 676 ++++++++++++++++++++++-------- 16 files changed, 830 insertions(+), 269 deletions(-) mode change 100644 => 100755 auto/stylize_as_junit.rb diff --git a/README.md b/README.md index 17ab574..ec73b4a 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,17 @@ 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 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 ------ diff --git a/auto/generate_module.rb b/auto/generate_module.rb index ade4f1a..13b4cc7 100644 --- a/auto/generate_module.rb +++ b/auto/generate_module.rb @@ -172,7 +172,7 @@ class UnityModuleGenerator when 'camel' then part1 when 'snake' then part1.downcase when 'caps' then part1.upcase - else part1.downcase + else part1 end else case (@options[:naming]) @@ -180,7 +180,7 @@ class UnityModuleGenerator when 'camel' then part1 + part2 when 'snake' then part1.downcase + '_' + part2.downcase when 'caps' then part1.upcase + '_' + part2.upcase - else part1.downcase + '_' + part2.downcase + else part1 + '_' + part2 end end end @@ -290,7 +290,7 @@ if $0 == __FILE__ ' -n"camel" sets the file naming convention.', ' bumpy - BumpyCaseFilenames.', ' camel - camelCaseFilenames.', - ' snake - snake_case_filenames. (DEFAULT)', + ' snake - snake_case_filenames.', ' caps - CAPS_CASE_FILENAMES.', ' -u update subversion too (requires subversion command line)', ' -y"my.yml" selects a different yaml config file for module generation', diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 2c5e56a..07bde81 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -119,7 +119,7 @@ class UnityTestRunnerGenerator source_index = 0 tests_and_line_numbers.size.times do |i| source_lines[source_index..-1].each_with_index do |line, index| - next unless line =~ /#{tests_and_line_numbers[i][:test]}/ + next unless line =~ /\s+#{tests_and_line_numbers[i][:test]}(?:\s|\()/ source_index += index tests_and_line_numbers[i][:line_number] = source_index + 1 break diff --git a/auto/stylize_as_junit.rb b/auto/stylize_as_junit.rb old mode 100644 new mode 100755 diff --git a/docs/UnityAssertionsReference.md b/docs/UnityAssertionsReference.md index 558f6db..2dcf5e3 100644 --- a/docs/UnityAssertionsReference.md +++ b/docs/UnityAssertionsReference.md @@ -290,6 +290,60 @@ Asserts the specified bit of the `actual` parameter is high. 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) diff --git a/examples/unity_config.h b/examples/unity_config.h index 355d9bf..da3c2af 100644 --- a/examples/unity_config.h +++ b/examples/unity_config.h @@ -201,10 +201,12 @@ * `stdout` option. You decide to route your test result output to a custom * serial `RS232_putc()` function you wrote like thus: */ -/* #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) */ -/* #define UNITY_OUTPUT_FLUSH() RS232_flush() */ -/* #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) */ -/* #define UNITY_OUTPUT_COMPLETE() RS232_close() */ +/* #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_HEADER_DECLARATION RS232_flush(void) */ +/* #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) */ +/* #define UNITY_OUTPUT_COMPLETE() RS232_close() */ /* For some targets, Unity can make the otherwise required `setUp()` and * `tearDown()` functions optional. This is a nice convenience for test writers diff --git a/extras/fixture/rakefile_helper.rb b/extras/fixture/rakefile_helper.rb index 5aa8e56..c45b239 100644 --- a/extras/fixture/rakefile_helper.rb +++ b/extras/fixture/rakefile_helper.rb @@ -53,7 +53,7 @@ module RakefileHelpers defines = if $cfg['compiler']['defines']['items'].nil? '' else - squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar']) + squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar'] + ['UNITY_OUTPUT_CHAR_HEADER_DECLARATION=UnityOutputCharSpy_OutputChar\(int\)']) end options = squash('', $cfg['compiler']['options']) includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items']) diff --git a/extras/fixture/test/Makefile b/extras/fixture/test/Makefile index 80e124f..e6c6255 100644 --- a/extras/fixture/test/Makefile +++ b/extras/fixture/test/Makefile @@ -6,6 +6,7 @@ endif CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror CFLAGS += $(DEBUG) DEFINES = -D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar +DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=UnityOutputCharSpy_OutputChar\(int\) SRC = ../src/unity_fixture.c \ ../../../src/unity.c \ unity_fixture_Test.c \ diff --git a/release/build.info b/release/build.info index 207634b..50fb6ea 100644 --- a/release/build.info +++ b/release/build.info @@ -1,2 +1,2 @@ -120 +121 diff --git a/release/version.info b/release/version.info index 3b904b6..b674b92 100644 --- a/release/version.info +++ b/release/version.info @@ -1,2 +1,2 @@ -2.4.1 +2.4.2 diff --git a/src/unity.c b/src/unity.c index 177af0f..9783efa 100644 --- a/src/unity.c +++ b/src/unity.c @@ -27,6 +27,8 @@ static const char UnityStrNull[] = "NULL"; static const char UnityStrSpacer[] = ". "; static const char UnityStrExpected[] = " Expected "; 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 UnityStrByte[] = " Byte "; static const char UnityStrMemory[] = " Memory Mismatch."; @@ -235,95 +237,97 @@ void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number) /*-----------------------------------------------*/ #ifndef UNITY_EXCLUDE_FLOAT_PRINT -static void UnityPrintDecimalAndNumberWithLeadingZeros(UNITY_INT32 fraction_part, UNITY_INT32 divisor) -{ - UNITY_OUTPUT_CHAR('.'); - while (divisor > 0) - { - 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); - */ +/* This function prints a floating-point value in a format similar to + * printf("%.6g"). It can work with either single- or double-precision, + * but for simplicity, it prints only 6 significant digits in either case. + * Printing more than 6 digits accurately is hard (at least in the single- + * precision case) and isn't attempted here. */ void UnityPrintFloat(const UNITY_DOUBLE input_number) { - UNITY_DOUBLE number; + UNITY_DOUBLE number = input_number; - if (input_number < 0) + /* print minus sign (including for negative zero) */ + if (number < 0.0f || (number == 0.0f && 1.0f / number < 0.0f)) { UNITY_OUTPUT_CHAR('-'); - number = -input_number; - } else - { - number = input_number; + number = -number; } - if (isnan(number)) UnityPrint(UnityStrNaN); - else if (isinf(number)) UnityPrintLen(UnityStrInf, 3); - else if (number <= 0.0000005 && number > 0) UnityPrint("0.000000..."); /* Small number */ - else if (number < 4294967295.9999995) /* Rounded result fits in 32 bits, "%.6f" format */ + /* handle zero, NaN, and +/- infinity */ + if (number == 0.0f) UnityPrint("0"); + else if (isnan(number)) UnityPrint("nan"); + else if (isinf(number)) UnityPrint("inf"); + else { - const UNITY_INT32 divisor = 1000000/10; - UNITY_UINT32 integer_part = (UNITY_UINT32)number; - UNITY_INT32 fraction_part = (UNITY_INT32)((number - (UNITY_DOUBLE)integer_part)*1000000.0 + 0.5); - /* 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); + int exponent = 0; + int decimals, digits; + UNITY_INT32 n; + char buf[16]; - if (fraction_part == 1000000) /* Carry across the decimal point */ + /* scale up or down by powers of 10 */ + 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) { - 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; + n = 100000; 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); - UNITY_OUTPUT_CHAR('0' + integer_part / divisor); - UnityPrintDecimalAndNumberWithLeadingZeros(integer_part % divisor, divisor / 10); - UNITY_OUTPUT_CHAR('e'); - UNITY_OUTPUT_CHAR('+'); - if (exponent < 10) UNITY_OUTPUT_CHAR('0'); - UnityPrintNumber(exponent); + /* determine where to place decimal point */ + decimals = (exponent <= 0 && exponent >= -9) ? -exponent : 5; + 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'); + + if(exponent < 0) + { + UNITY_OUTPUT_CHAR('-'); + exponent = -exponent; + } + else + { + UNITY_OUTPUT_CHAR('+'); + } + + 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 */ @@ -526,6 +530,50 @@ 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() \ { \ UnityTestResultsFailBegin(lineNumber); \ @@ -1025,7 +1073,7 @@ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected, { UNITY_UINT32 i = 0; UNITY_UINT32 j = 0; - const char* exp = NULL; + const char* expd = NULL; const char* act = NULL; RETURN_IF_FAIL_OR_IGNORE; @@ -1048,7 +1096,7 @@ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected, if (flags != UNITY_ARRAY_TO_ARRAY) { - exp = (const char*)expected; + expd = (const char*)expected; } do @@ -1056,15 +1104,15 @@ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected, act = actual[j]; if (flags == UNITY_ARRAY_TO_ARRAY) { - exp = ((const char* const*)expected)[j]; + expd = ((const char* const*)expected)[j]; } /* if both pointers not null compare the strings */ - if (exp && act) + if (expd && act) { - for (i = 0; exp[i] || act[i]; i++) + for (i = 0; expd[i] || act[i]; i++) { - if (exp[i] != act[i]) + if (expd[i] != act[i]) { Unity.CurrentTestFailed = 1; break; @@ -1073,7 +1121,7 @@ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected, } else { /* handle case of one pointers being null (if both null, test should pass) */ - if (exp != act) + if (expd != act) { Unity.CurrentTestFailed = 1; } @@ -1087,7 +1135,7 @@ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected, UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(j); } - UnityPrintExpectedAndActualStrings(exp, act); + UnityPrintExpectedAndActualStrings(expd, act); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } diff --git a/src/unity.h b/src/unity.h index 6434238..258e21c 100644 --- a/src/unity.h +++ b/src/unity.h @@ -114,6 +114,35 @@ 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_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) */ #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) @@ -157,6 +186,8 @@ 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_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 */ #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) @@ -241,6 +272,35 @@ 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_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) */ #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)) diff --git a/src/unity_internals.h b/src/unity_internals.h index c08db95..1b57cd0 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -246,8 +246,8 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT; #define UNITY_OUTPUT_CHAR(a) (void)putchar(a) #else /* If defined as something else, make sure we declare it here so it's ready for use */ - #ifndef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION -extern void UNITY_OUTPUT_CHAR(int); + #ifdef UNITY_OUTPUT_CHAR_HEADER_DECLARATION +extern void UNITY_OUTPUT_CHAR_HEADER_DECLARATION; #endif #endif @@ -255,22 +255,22 @@ extern void UNITY_OUTPUT_CHAR(int); #ifdef UNITY_USE_FLUSH_STDOUT /* We want to use the stdout flush utility */ #include -#define UNITY_OUTPUT_FLUSH (void)fflush(stdout) +#define UNITY_OUTPUT_FLUSH() (void)fflush(stdout) #else /* We've specified nothing, therefore flush should just be ignored */ -#define UNITY_OUTPUT_FLUSH +#define UNITY_OUTPUT_FLUSH() #endif #else /* We've defined flush as something else, so make sure we declare it here so it's ready for use */ -#ifndef UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION -extern void UNITY_OUTPUT_FLUSH(void); +#ifdef UNITY_OUTPUT_FLUSH_HEADER_DECLARATION +extern void UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION; #endif #endif #ifndef UNITY_OUTPUT_FLUSH #define UNITY_FLUSH_CALL() #else -#define UNITY_FLUSH_CALL() UNITY_OUTPUT_FLUSH +#define UNITY_FLUSH_CALL() UNITY_OUTPUT_FLUSH() #endif #ifndef UNITY_PRINT_EOL @@ -455,6 +455,18 @@ void UnityAssertEqualNumber(const UNITY_INT expected, const UNITY_LINE_TYPE lineNumber, 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, UNITY_INTERNAL_PTR actual, const UNITY_UINT32 num_elements, @@ -652,6 +664,34 @@ 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_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_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) diff --git a/test/Makefile b/test/Makefile index 03b59bc..9de7a49 100644 --- a/test/Makefile +++ b/test/Makefile @@ -14,6 +14,7 @@ CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstri #DEBUG = -O0 -g CFLAGS += $(DEBUG) DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy +DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\) DEFINES += -D UNITY_SUPPORT_64 -D UNITY_INCLUDE_DOUBLE SRC = ../src/unity.c tests/testunity.c build/testunityRunner.c INC_DIR = -I ../src diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index be5bf3e..1fd60c5 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -91,7 +91,7 @@ module RakefileHelpers defines = if $cfg['compiler']['defines']['items'].nil? '' else - squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=putcharSpy'] + inject_defines) + squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=putcharSpy'] + ['UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\)'] + inject_defines) end options = squash('', $cfg['compiler']['options']) includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items']) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 3555fb2..af06647 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -764,8 +764,9 @@ void testNotEqualBitsLow(void) EXPECT_ABORT_BEGIN TEST_ASSERT_BITS_LOW(v0, v1); VERIFY_FAILS_END - } + + void testEqualShorts(void) { short v0, v1; @@ -1305,6 +1306,415 @@ void testINT8sNotWithinDeltaAndCustomMessage(void) 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) { const char *testString = "foo"; @@ -4056,61 +4466,46 @@ void testFloatPrinting(void) #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY) TEST_IGNORE(); #else - TEST_ASSERT_EQUAL_PRINT_FLOATING("0.0", 0.0f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("0.000000...", 0.000000499f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("0.000001", 0.00000050000005f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.100469499f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0", 0.9999995f); /*Rounding to int place*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0", 1.0f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("1.25", 1.25f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("7.999999", 7.999999f); /*Not rounding*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("16.000002", 16.000002f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("16.000004", 16.000004f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("16.000006", 16.000006f); - 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("4.99e-07", 0.000000499f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("5e-07", 0.00000050000005f); + 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", 1.0f); + 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("16.0002", 16.0002f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0004", 16.0004f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0006", 16.0006f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("999999", 999999.0f); /*Last full print integer*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("0.0", -0.0f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.000000...",-0.000000499f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.000001", -0.00000050000005f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.100469499f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.0", -0.9999995f); /*Rounding to int place*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.0", -1.0f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.25", -1.25f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.999999", -7.999999f); /*Not rounding*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.000002", -16.000002f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.000004", -16.000004f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.000006", -16.000006f); - 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("-4.99e-07", -0.000000499f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-5e-07", -0.00000050000005f); + 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", -1.0f); + 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("-16.0002", -16.0002f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0004", -16.0004f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0006", -16.0006f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-999999", -999999.0f); /*Last full print integer*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967296.0f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("5.0e+09", 5000000000.0f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("8.0e+09", 8.0e+09f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("8.3099991e+09", 8309999104.0f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 1.0e+10f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 10000000000.0f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967296.0f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("5e+09", 5000000000.0f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("8e+09", 8.0e+09f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("8.31e+09", 8309999104.0f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 1.0e+10f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 10000000000.0f); /* Some compilers have trouble with inexact float constants, a float cast works generally */ - TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00005499e+10", (float)1.000055e+10f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("1.10000006e+38", (float)1.10000005e+38f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("1.63529943e+10", 1.63529943e+10f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("3.40282347e+38", 3.40282346638e38f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00005e+10", (float)1.000054e+10f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1.1e+38", (float)1.10000005e+38f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1.6353e+10", 1.63529943e+10f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("3.40282e+38", 3.40282346638e38f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.0e+10", -1.0e+10f); - 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 + TEST_ASSERT_EQUAL_PRINT_FLOATING("-1e+10", -1.0e+10f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-3.40282e+38", -3.40282346638e38f); #endif } @@ -4119,105 +4514,69 @@ void testFloatPrintingInfinityAndNaN(void) #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY) TEST_IGNORE(); #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 } #if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY) -static void AllFloatPrinting_LessThan32Bits(void) +static void printFloatValue(float f) { char expected[18]; - union { float f_value; int32_t int_value; } u; - /* 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) + char expected_lower[18]; + char expected_higher[18]; + + startPutcharSpy(); + + UnityPrintFloat(f); + + sprintf(expected, "%.6g", f); + + /* We print all NaN's as "nan", not "-nan" */ + if(strcmp(expected, "-nan") == 0) strcpy(expected, "nan"); + + /* Allow for rounding differences in last digit */ + double lower = (double)f * 0.9999995; + 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) { - startPutcharSpy(); - - 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); - - while (expected[len - 1] == '0' && expected[len - 2] != '.') { len--; } - expected[len] = '\0'; /* delete trailing 0's */ - - if (strcmp(expected, getBufferPutcharSpy()) != 0) - { - double six_digits = ((double)u.f_value - (uint32_t)u.f_value)*1000000.0; - /* Not a tie (remainder != 0.5) => Can't explain the different strings */ - if (six_digits - (uint32_t)six_digits != 0.5) - { - /* Fail with diagnostic printing */ - 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 */ - } + /* Fail with diagnostic printing */ + TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, f); } } #endif -/* 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) +void testFloatPrintingRandomSamples(void) { -#if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY) - AllFloatPrinting_LessThan32Bits(); +#if !defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) || !defined(USING_OUTPUT_SPY) + TEST_IGNORE(); #else - TEST_IGNORE(); /* Ignore one of three */ -#endif -} + union { float f_value; uint32_t int_value; } u; -/* Test takes a long time, around 3.5 minutes compiled with -O2, try ~500 million values */ -void testAllFloatPrintingPart2_Larger(void) -{ -#if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY) - AllFloatPrinting_Larger(4294967296.0f, 1e25f); -#endif -} + /* These values are not covered by the MINSTD generator */ + u.int_value = 0x00000000; printFloatValue(u.f_value); + u.int_value = 0x80000000; printFloatValue(u.f_value); + u.int_value = 0x7fffffff; printFloatValue(u.f_value); + u.int_value = 0xffffffff; printFloatValue(u.f_value); -/* Test takes a long time, around 3.5 minutes compiled with -O2, try ~500 million values */ -void testAllFloatPrintingPart3_LargerStill(void) -{ -#if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY) - AllFloatPrinting_Larger(1e25f, 3.40282347e+38f); + uint32_t a = 1; + for(int num_tested = 0; num_tested < 1000000; num_tested++) + { + /* MINSTD pseudo-random number generator */ + a = (uint32_t)(((uint64_t)a * 48271u) % 2147483647u); + + /* 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 } @@ -4893,35 +5252,20 @@ void testDoublePrinting(void) #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY) TEST_IGNORE(); #else - TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.10046949999999999); - TEST_ASSERT_EQUAL_PRINT_FLOATING("4294967295.999999", 4294967295.999999); - TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967295.9999995); - TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967296.0); - TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 9999999995.0); - TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199254740990.0); - TEST_ASSERT_EQUAL_PRINT_FLOATING("7.0e+100", 7.0e+100); - TEST_ASSERT_EQUAL_PRINT_FLOATING("3.0e+200", 3.0e+200); - 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("4.29497e+09", 4294967295.999999); + TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967295.9999995); + TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967296.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 9999999995.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("9.0072e+15", 9007199254740990.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("7e+100", 7.0e+100); + TEST_ASSERT_EQUAL_PRINT_FLOATING("3e+200", 3.0e+200); + TEST_ASSERT_EQUAL_PRINT_FLOATING("9.23457e+300", 9.23456789e+300); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.10046949999999999); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-4294967295.999999", -4294967295.999999); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.2949673e+09", -4294967295.9999995); - 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 + TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.10046949999999999); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.29497e+09", -4294967295.999999); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.29497e+09", -4294967295.9999995); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-7e+100", -7.0e+100); #endif } @@ -4930,10 +5274,10 @@ void testDoublePrintingInfinityAndNaN(void) #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY) TEST_IGNORE(); #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 }