diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index a3158cb..b7d37ac 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -176,21 +176,24 @@ class UnityTestRunnerGenerator output.puts(" GlobalOrderError = NULL;") end mocks.each do |mock| - output.puts(" #{mock}_Init();") + mock_clean = mock.gsub(/(?:-|\s+)/, "_") + output.puts(" #{mock_clean}_Init();") end output.puts("}\n") output.puts("static void CMock_Verify(void)") output.puts("{") mocks.each do |mock| - output.puts(" #{mock}_Verify();") + mock_clean = mock.gsub(/(?:-|\s+)/, "_") + output.puts(" #{mock_clean}_Verify();") end output.puts("}\n") output.puts("static void CMock_Destroy(void)") output.puts("{") mocks.each do |mock| - output.puts(" #{mock}_Destroy();") + mock_clean = mock.gsub(/(?:-|\s+)/, "_") + output.puts(" #{mock_clean}_Destroy();") end output.puts("}\n") end diff --git a/examples/rakefile.rb b/examples/rakefile.rb index 198fe91..0a64118 100644 --- a/examples/rakefile.rb +++ b/examples/rakefile.rb @@ -8,7 +8,7 @@ require HERE+'rakefile_helper' include RakefileHelpers # Load default configuration, for now -DEFAULT_CONFIG_FILE = 'gcc.yml' +DEFAULT_CONFIG_FILE = 'gcc_32.yml' configure_toolchain(DEFAULT_CONFIG_FILE) task :unit do diff --git a/extras/fixture/rakefile.rb b/extras/fixture/rakefile.rb index fbff3bd..5d81e72 100644 --- a/extras/fixture/rakefile.rb +++ b/extras/fixture/rakefile.rb @@ -14,7 +14,7 @@ require HERE + 'rakefile_helper' include RakefileHelpers # Load default configuration, for now -DEFAULT_CONFIG_FILE = 'gcc.yml' +DEFAULT_CONFIG_FILE = 'gcc_32.yml' configure_toolchain(DEFAULT_CONFIG_FILE) task :unit do diff --git a/extras/fixture/rakefile_helper.rb b/extras/fixture/rakefile_helper.rb index 01a5d66..09730ef 100644 --- a/extras/fixture/rakefile_helper.rb +++ b/extras/fixture/rakefile_helper.rb @@ -87,7 +87,7 @@ module RakefileHelpers return {:command => command, :options => options, :includes => includes} end - def link(exe_name, obj_list) + def link_it(exe_name, obj_list) linker = build_linker_fields cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " + (obj_list.map{|obj|"#{$cfg['linker']['object_files']['path']}#{obj} "}).join + @@ -148,7 +148,8 @@ module RakefileHelpers # Get a list of all source files needed src_files = Dir[HERE+'src/*.c'] src_files += Dir[HERE+'test/*.c'] - src_files << '../../src/Unity.c' + src_files += Dir[HERE+'test/main/*.c'] + src_files << '../../src/unity.c' # Build object files src_files.each { |f| compile(f, test_defines) } @@ -156,7 +157,7 @@ module RakefileHelpers # Link the test executable test_base = "framework_test" - link(test_base, obj_list) + link_it(test_base, obj_list) # Execute unit test and generate results file simulator = build_simulator_fields diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index ec0b4c5..5dc099c 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -5,9 +5,9 @@ [Released under MIT License. Please refer to license.txt for details] ========================================== */ +#include #include "unity_fixture.h" #include "unity_internals.h" -#include UNITY_FIXTURE_T UnityFixture; @@ -107,20 +107,20 @@ void UnityTestRunner(unityfunction* setup, UnityPointer_UndoAllSets(); if (!Unity.CurrentTestFailed) UnityMalloc_EndTest(); - UnityConcludeFixtureTest(); - } - else - { - //aborting - jwg - di i need these for the other TEST_PROTECTS? } + UnityConcludeFixtureTest(); } } -void UnityIgnoreTest() +void UnityIgnoreTest(const char * printableName) { Unity.NumberOfTests++; Unity.CurrentTestIgnored = 1; - UNITY_OUTPUT_CHAR('!'); + if (!UnityFixture.Verbose) + UNITY_OUTPUT_CHAR('!'); + else + UnityPrint(printableName); + UnityConcludeFixtureTest(); } @@ -164,8 +164,8 @@ void UnityMalloc_MakeMallocFailAfterCount(int countdown) typedef struct GuardBytes { - int size; - char guard[sizeof(int)]; + size_t size; + char guard[sizeof(size_t)]; } Guard; @@ -254,7 +254,7 @@ void* unity_realloc(void * oldMem, size_t size) return oldMem; newMem = unity_malloc(size); - memcpy(newMem, oldMem, size); + memcpy(newMem, oldMem, guard->size); unity_free(oldMem); return newMem; } @@ -360,6 +360,10 @@ void UnityConcludeFixtureTest() { if (Unity.CurrentTestIgnored) { + if (UnityFixture.Verbose) + { + UNITY_OUTPUT_CHAR('\n'); + } Unity.TestIgnores++; } else if (!Unity.CurrentTestFailed) @@ -378,4 +382,3 @@ void UnityConcludeFixtureTest() Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; } - diff --git a/extras/fixture/src/unity_fixture.h b/extras/fixture/src/unity_fixture.h index da1f871..9d5cd12 100644 --- a/extras/fixture/src/unity_fixture.h +++ b/extras/fixture/src/unity_fixture.h @@ -41,7 +41,7 @@ int UnityMain(int argc, char* argv[], void (*runAllTests)()); void TEST_##group##_##name##_();\ void TEST_##group##_##name##_run()\ {\ - UnityIgnoreTest();\ + UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")");\ }\ void TEST_##group##_##name##_() @@ -49,8 +49,8 @@ int UnityMain(int argc, char* argv[], void (*runAllTests)()); void TEST_##group##_##name##_run() #define RUN_TEST_CASE(group, name) \ - DECLARE_TEST_CASE(group, name);\ - TEST_##group##_##name##_run(); + { DECLARE_TEST_CASE(group, name);\ + TEST_##group##_##name##_run(); } //This goes at the bottom of each test file or in a separate c file #define TEST_GROUP_RUNNER(group)\ @@ -63,8 +63,8 @@ int UnityMain(int argc, char* argv[], void (*runAllTests)()); //Call this from main #define RUN_TEST_GROUP(group)\ - void TEST_##group##_GROUP_RUNNER();\ - TEST_##group##_GROUP_RUNNER(); + { void TEST_##group##_GROUP_RUNNER();\ + TEST_##group##_GROUP_RUNNER(); } //CppUTest Compatibility Macros #define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&ptr, (void*)newPointerValue) diff --git a/extras/fixture/src/unity_fixture_internals.h b/extras/fixture/src/unity_fixture_internals.h index db23f67..46cbbcb 100644 --- a/extras/fixture/src/unity_fixture_internals.h +++ b/extras/fixture/src/unity_fixture_internals.h @@ -25,7 +25,7 @@ void UnityTestRunner(unityfunction * setup, const char * name, const char * file, int line); -void UnityIgnoreTest(); +void UnityIgnoreTest(const char * printableName); void UnityMalloc_StartTest(); void UnityMalloc_EndTest(); int UnityFailureCount(); diff --git a/extras/fixture/test/unity_fixture_Test.c b/extras/fixture/test/unity_fixture_Test.c index b8b4524..f5803b8 100644 --- a/extras/fixture/test/unity_fixture_Test.c +++ b/extras/fixture/test/unity_fixture_Test.c @@ -49,10 +49,12 @@ TEST(UnityFixture, PointerSetting) TEST(UnityFixture, ForceMallocFail) { + void* m; + void* mfails; UnityMalloc_MakeMallocFailAfterCount(1); - void* m = malloc(10); + m = malloc(10); CHECK(m); - void* mfails = malloc(10); + mfails = malloc(10); TEST_ASSERT_POINTERS_EQUAL(0, mfails); free(m); } @@ -76,8 +78,9 @@ TEST(UnityFixture, ReallocSameIsUnchanged) TEST(UnityFixture, ReallocLargerNeeded) { void* m1 = malloc(10); + void* m2; strcpy((char*)m1, "123456789"); - void* m2 = realloc(m1, 15); + m2 = realloc(m1, 15); CHECK(m1 != m2); STRCMP_EQUAL("123456789", m2); free(m2); diff --git a/makefile b/makefile index 58ead54..753bbae 100644 --- a/makefile +++ b/makefile @@ -28,7 +28,7 @@ all: clean default default: ruby auto/generate_test_runner.rb test/testunity.c build/testunity_Runner.c $(C_COMPILER) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) $(OUT_FILE) - $(TARGET) + ./$(TARGET) clean: $(CLEANUP) diff --git a/src/unity.c b/src/unity.c index 0219b37..bd9aa14 100644 --- a/src/unity.c +++ b/src/unity.c @@ -28,6 +28,16 @@ const char* UnityStrDelta = " Values Not Within Delta "; const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless."; const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL"; const char* UnityStrNullPointerForActual = " Actual pointer was NULL"; +const char* UnityStrInf = "Infinity"; +const char* UnityStrNegInf = "Negative Infinity"; +const char* UnityStrNaN = "NaN"; + +// Dividing by these constants produces +/- infinity. +// The rationale is given in UnityAssertFloatIsInf's body. +static const _UF f_zero = 0.0f; +#ifndef UNITY_EXCLUDE_DOUBLE +static const _UD d_zero = 0.0; +#endif // compiler-generic print formatting masks const _U_UINT UnitySizeMask[] = @@ -531,12 +541,14 @@ void UnityAssertEqualFloatArray(const _UF* expected, while (elements--) { diff = *ptr_expected - *ptr_actual; - if (diff < 0.0) - diff = 0.0 - diff; + if (diff < 0.0f) + diff = 0.0f - diff; tol = UNITY_FLOAT_PRECISION * *ptr_expected; - if (tol < 0.0) - tol = 0.0 - tol; - if (diff > tol) + if (tol < 0.0f) + tol = 0.0f - tol; + + //This first part of this condition will catch any NaN or Infinite values + if ((diff * 0.0f != 0.0f) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); @@ -569,16 +581,17 @@ void UnityAssertFloatsWithin(const _UF delta, UNITY_SKIP_EXECUTION; - if (diff < 0) + if (diff < 0.0f) { diff = 0.0f - diff; } - if (pos_delta < 0) + if (pos_delta < 0.0f) { pos_delta = 0.0f - pos_delta; } - if (pos_delta < diff) + //This first part of this condition will catch any NaN or Infinite values + if ((diff * 0.0f != 0.0f) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE @@ -594,6 +607,81 @@ void UnityAssertFloatsWithin(const _UF delta, } } +//----------------------------------------------- +void UnityAssertFloatIsInf(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + // In Microsoft Visual C++ Express Edition 2008, + // if ((1.0f / f_zero) != actual) + // produces + // error C2124: divide or mod by zero + // As a workaround, place 0 into a variable. + if ((1.0f / f_zero) != actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_FLOAT_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrInf); + UnityPrint(UnityStrWas); + UnityPrintFloat(actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + +//----------------------------------------------- +void UnityAssertFloatIsNegInf(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + // The rationale for not using 1.0f/0.0f is given in UnityAssertFloatIsInf's body. + if ((-1.0f / f_zero) != actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_FLOAT_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrNegInf); + UnityPrint(UnityStrWas); + UnityPrintFloat(actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + +//----------------------------------------------- +void UnityAssertFloatIsNaN(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + if (actual == actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_FLOAT_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrNaN); + UnityPrint(UnityStrWas); + UnityPrintFloat(actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + #endif //not UNITY_EXCLUDE_FLOAT //----------------------------------------------- @@ -630,7 +718,9 @@ void UnityAssertEqualDoubleArray(const _UD* expected, tol = UNITY_DOUBLE_PRECISION * *ptr_expected; if (tol < 0.0) tol = 0.0 - tol; - if (diff > tol) + + //This first part of this condition will catch any NaN or Infinite values + if ((diff * 0.0 != 0.0) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); @@ -663,16 +753,17 @@ void UnityAssertDoublesWithin(const _UD delta, UNITY_SKIP_EXECUTION; - if (diff < 0) + if (diff < 0.0) { - diff = 0.0f - diff; + diff = 0.0 - diff; } - if (pos_delta < 0) + if (pos_delta < 0.0) { - pos_delta = 0.0f - pos_delta; + pos_delta = 0.0 - pos_delta; } - if (pos_delta < diff) + //This first part of this condition will catch any NaN or Infinite values + if ((diff * 0.0 != 0.0) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE @@ -688,6 +779,77 @@ void UnityAssertDoublesWithin(const _UD delta, } } +//----------------------------------------------- +void UnityAssertDoubleIsInf(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + // The rationale for not using 1.0/0.0 is given in UnityAssertFloatIsInf's body. + if ((1.0 / d_zero) != actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_DOUBLE_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrInf); + UnityPrint(UnityStrWas); + UnityPrintFloat((float)actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + +//----------------------------------------------- +void UnityAssertDoubleIsNegInf(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + // The rationale for not using 1.0/0.0 is given in UnityAssertFloatIsInf's body. + if ((-1.0 / d_zero) != actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_DOUBLE_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrNegInf); + UnityPrint(UnityStrWas); + UnityPrintFloat((float)actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + +//----------------------------------------------- +void UnityAssertDoubleIsNaN(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + if (actual == actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_DOUBLE_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrNaN); + UnityPrint(UnityStrWas); + UnityPrintFloat((float)actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + #endif // not UNITY_EXCLUDE_DOUBLE //----------------------------------------------- diff --git a/src/unity.h b/src/unity.h index 6c635bd..f0c6abe 100644 --- a/src/unity.h +++ b/src/unity.h @@ -14,10 +14,13 @@ //------------------------------------------------------- // Configuration Options //------------------------------------------------------- +// All options described below should be passed as a compiler flag to all files using Unity. If you must add #defines, place them BEFORE the #include above. -// Integers -// - Unity assumes 32 bit integers by default -// - If your compiler treats ints of a different size, define UNITY_INT_WIDTH +// Integers/longs/pointers +// - Unity assumes 32 bit integers, longs, and pointers by default +// - If your compiler treats ints of a different size, options are: +// - define UNITY_USE_LIMITS_H to use limits.h to determine sizes +// - define UNITY_INT_WIDTH, UNITY_LONG_WIDTH, nand UNITY_POINTER_WIDTH // Floats // - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons @@ -142,12 +145,17 @@ #define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL) +#define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, NULL) +#define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, NULL) +#define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, NULL) //Double (If Enabled) #define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_DOUBLE(expected, actual) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, NULL) - +#define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, NULL) +#define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, NULL) +#define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, NULL) //------------------------------------------------------- // Test Asserts (with additional messages) @@ -223,10 +231,15 @@ #define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message) +#define TEST_ASSERT_FLOAT_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, message) +#define TEST_ASSERT_FLOAT_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, message) +#define TEST_ASSERT_FLOAT_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, message) //Double (If Enabled) #define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_DOUBLE_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_DOUBLE_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, message) - +#define TEST_ASSERT_DOUBLE_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, message) +#define TEST_ASSERT_DOUBLE_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, message) +#define TEST_ASSERT_DOUBLE_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, message) #endif diff --git a/src/unity_internals.h b/src/unity_internals.h index 253c5b9..7020756 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -10,11 +10,14 @@ #include #include -//stdint.h is often automatically included. -//Unity uses it to guess at the sizes of integer types, etc. +// Unity attempts to determine sizeof(various types) +// based on UINT_MAX, ULONG_MAX, etc. These are typically +// defined in limits.h. #ifdef UNITY_USE_LIMITS_H #include #endif +// As a fallback, hope that including stdint.h will +// provide this information. #ifndef UNITY_EXCLUDE_STDINT_H #include #endif @@ -23,9 +26,10 @@ // Guess Widths If Not Specified //------------------------------------------------------- -// If the INT Width hasn't been specified, -// We first try to guess based on UINT_MAX (if it exists) -// Otherwise we fall back on assuming 32-bit +// Determine the size of an int, if not already specificied. +// We cannot use sizeof(int), because it is not yet defined +// at this stage in the trnslation of the C program. +// Therefore, infer it from UINT_MAX if possible. #ifndef UNITY_INT_WIDTH #ifdef UINT_MAX #if (UINT_MAX == 0xFFFF) @@ -37,17 +41,16 @@ #ifndef UNITY_SUPPORT_64 #define UNITY_SUPPORT_64 #endif - #else - #define UNITY_INT_WIDTH (32) #endif - #else - #define UNITY_INT_WIDTH (32) #endif #endif +#ifndef UNITY_INT_WIDTH + #define UNITY_INT_WIDTH (32) +#endif -// If the Long Width hasn't been specified, -// We first try to guess based on ULONG_MAX (if it exists) -// Otherwise we fall back on assuming 32-bit +// Determine the size of a long, if not already specified, +// by following the process used above to define +// UNITY_INT_WIDTH. #ifndef UNITY_LONG_WIDTH #ifdef ULONG_MAX #if (ULONG_MAX == 0xFFFF) @@ -56,20 +59,19 @@ #define UNITY_LONG_WIDTH (32) #elif (ULONG_MAX == 0xFFFFFFFFFFFFFFFF) #define UNITY_LONG_WIDTH (64) - #else - #define UNITY_LONG_WIDTH (32) #ifndef UNITY_SUPPORT_64 #define UNITY_SUPPORT_64 #endif #endif - #else - #define UNITY_LONG_WIDTH (32) #endif #endif +#ifndef UNITY_LONG_WIDTH + #define UNITY_LONG_WIDTH (32) +#endif -// If the Pointer Width hasn't been specified, -// We first try to guess based on INTPTR_MAX (if it exists) -// Otherwise we fall back on assuming 32-bit +// Determine the size of a pointer, if not already specified, +// by following the process used above to define +// UNITY_INT_WIDTH. #ifndef UNITY_POINTER_WIDTH #ifdef UINTPTR_MAX #if (UINTPTR_MAX <= 0xFFFF) @@ -155,10 +157,6 @@ typedef _US64 _U_SINT; // Pointer Support //------------------------------------------------------- -#ifndef UNITY_POINTER_WIDTH -#define UNITY_POINTER_WIDTH (32) -#endif /* UNITY_POINTER_WIDTH */ - #if (UNITY_POINTER_WIDTH == 32) typedef _UU32 _UP; #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32 @@ -410,6 +408,18 @@ void UnityAssertEqualFloatArray(const _UF* expected, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber); + +void UnityAssertFloatIsInf(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); + +void UnityAssertFloatIsNegInf(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); + +void UnityAssertFloatIsNaN(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); #endif #ifndef UNITY_EXCLUDE_DOUBLE @@ -424,6 +434,18 @@ void UnityAssertEqualDoubleArray(const _UD* expected, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber); + +void UnityAssertDoubleIsInf(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); + +void UnityAssertDoubleIsNegInf(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); + +void UnityAssertDoubleIsNaN(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); #endif //------------------------------------------------------- @@ -493,20 +515,32 @@ void UnityAssertEqualDoubleArray(const _UD* expected, #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") +#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") +#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") +#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #else #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #endif #ifdef UNITY_EXCLUDE_DOUBLE #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") +#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") +#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") +#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #else #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UF)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((_UD*)(expected), (_UD*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #endif #endif diff --git a/test/testunity.c b/test/testunity.c index e98ca8f..2a10894 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -7,6 +7,13 @@ #include #include "unity.h" +// Dividing by these constants produces +/- infinity. +// The rationale is given in UnityAssertFloatIsInf's body. +static const _UF f_zero = 0.0f; +#ifndef UNITY_EXCLUDE_DOUBLE +static const _UD d_zero = 0.0; +#endif + #define EXPECT_ABORT_BEGIN \ if (TEST_PROTECT()) \ { @@ -2226,15 +2233,188 @@ void testFloatsNotEqualNegative2(void) #endif } +void testFloatsNotEqualActualNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(85.963f, 0.0f / f_zero); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualExpectedNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(0.0f / f_zero, 85.963f); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualBothNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(0.0f / f_zero, 0.0f / f_zero); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualInfNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(1.0f / f_zero, 0.0f / f_zero); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualNaNInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(0.0f / f_zero, 1.0f / f_zero); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualActualInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(321.642f, 1.0f / f_zero); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualExpectedInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(1.0f / f_zero, 321.642f); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualBothInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(1.0f / f_zero, 1.0f / f_zero); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualPlusMinusInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(1.0f / f_zero, -1.0f / f_zero); + VERIFY_FAILS_END +#endif +} + +void testFloatIsInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + TEST_ASSERT_FLOAT_IS_INF(2.0f / f_zero); + TEST_ASSERT_FLOAT_IS_NEG_INF(-3.0f / f_zero); +#endif +} + +void testFloatIsNotInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_IS_INF(2.0f); + VERIFY_FAILS_END +#endif +} + +void testFloatIsNotNegInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_IS_NEG_INF(-999.876f); + VERIFY_FAILS_END +#endif +} + +void testFloatIsNan(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + TEST_ASSERT_FLOAT_IS_NAN(0.0f / f_zero); +#endif +} + +void testFloatIsNotNan(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_IS_NAN(234.9f); + VERIFY_FAILS_END +#endif +} + +void testFloatInfIsNotNan(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_IS_NAN(1.0f / f_zero); + VERIFY_FAILS_END +#endif +} + +void testFloatNanIsNotInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_IS_INF(0.0f / f_zero); + VERIFY_FAILS_END +#endif +} + void testEqualFloatArrays(void) { #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, -8.0, 25.4, -0.123}; - float p1[] = {1.0, -8.0, 25.4, -0.123}; - float p2[] = {1.0, -8.0, 25.4, -0.2}; - float p3[] = {1.0, -23.0, 25.0, -0.26}; + float p0[] = {1.0f, -8.0f, 25.4f, -0.123f}; + float p1[] = {1.0f, -8.0f, 25.4f, -0.123f}; + float p2[] = {1.0f, -8.0f, 25.4f, -0.2f}; + float p3[] = {1.0f, -23.0f, 25.0f, -0.26f}; TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p0, 1); TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p0, 4); @@ -2250,7 +2430,7 @@ void testNotEqualFloatArraysExpectedNull(void) TEST_IGNORE(); #else float* p0 = NULL; - float p1[] = {1.0, 8.0, 25.4, 0.252}; + float p1[] = {1.0f, 8.0f, 25.4f, 0.252f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2263,7 +2443,7 @@ void testNotEqualFloatArraysActualNull(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, 8.0, 25.4, 0.253}; + float p0[] = {1.0f, 8.0f, 25.4f, 0.253f}; float* p1 = NULL; EXPECT_ABORT_BEGIN @@ -2277,8 +2457,8 @@ void testNotEqualFloatArrays1(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, 8.0, 25.4, 0.253}; - float p1[] = {1.0, 8.0, 25.4, 0.252}; + float p0[] = {1.0f, 8.0f, 25.4f, 0.253f}; + float p1[] = {1.0f, 8.0f, 25.4f, 0.252f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2291,8 +2471,8 @@ void testNotEqualFloatArrays2(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, 8.0, 25.4, 0.253}; - float p1[] = {2.0, 8.0, 25.4, 0.253}; + float p0[] = {1.0f, 8.0f, 25.4f, 0.253f}; + float p1[] = {2.0f, 8.0f, 25.4f, 0.253f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2305,8 +2485,8 @@ void testNotEqualFloatArrays3(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, 8.0, 25.4, 0.253}; - float p1[] = {1.0, 8.0, 25.5, 0.253}; + float p0[] = {1.0f, 8.0f, 25.4f, 0.253f}; + float p1[] = {1.0f, 8.0f, 25.5f, 0.253f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2319,8 +2499,8 @@ void testNotEqualFloatArraysNegative1(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {-1.0, -8.0, -25.4, -0.253}; - float p1[] = {-1.0, -8.0, -25.4, -0.252}; + float p0[] = {-1.0f, -8.0f, -25.4f, -0.253f}; + float p1[] = {-1.0f, -8.0f, -25.4f, -0.252f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2333,8 +2513,8 @@ void testNotEqualFloatArraysNegative2(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {-1.0, -8.0, -25.4, -0.253}; - float p1[] = {-2.0, -8.0, -25.4, -0.253}; + float p0[] = {-1.0f, -8.0f, -25.4f, -0.253f}; + float p1[] = {-2.0f, -8.0f, -25.4f, -0.253f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2347,8 +2527,36 @@ void testNotEqualFloatArraysNegative3(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {-1.0, -8.0, -25.4, -0.253}; - float p1[] = {-1.0, -8.0, -25.5, -0.253}; + float p0[] = {-1.0f, -8.0f, -25.4f, -0.253f}; + float p1[] = {-1.0f, -8.0f, -25.5f, -0.253f}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); + VERIFY_FAILS_END +#endif +} + +void testNotEqualFloatArraysNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + float p0[] = {1.0f, 0.0f / f_zero, 25.4f, 0.253f}; + float p1[] = {1.0f, 0.0f / f_zero, 25.4f, 0.253f}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); + VERIFY_FAILS_END +#endif +} + +void testNotEqualFloatArraysInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + float p0[] = {1.0f, 1.0f / f_zero, 25.4f, 0.253f}; + float p1[] = {1.0f, 1.0f / f_zero, 25.4f, 0.253f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2427,6 +2635,179 @@ void testDoublesNotEqualNegative2(void) #endif } +void testDoublesNotEqualActualNaN(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(85.963, 0.0 / d_zero); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualExpectedNaN(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 85.963); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualBothNaN(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 0.0 / d_zero); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualInfNaN(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, 0.0 / d_zero); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualNaNInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 1.0 / d_zero); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualActualInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(321.642, 1.0 / d_zero); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualExpectedInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, 321.642); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualBothInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, 1.0 / d_zero); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualPlusMinusInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, -1.0 / d_zero); + VERIFY_FAILS_END +#endif +} + +void testDoubleIsInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + TEST_ASSERT_DOUBLE_IS_INF(2.0 / d_zero); + TEST_ASSERT_DOUBLE_IS_NEG_INF(-3.0 / d_zero); +#endif +} + +void testDoubleIsNotInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_IS_INF(2.0); + VERIFY_FAILS_END +#endif +} + +void testDoubleIsNotNegInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_IS_NEG_INF(-999.876); + VERIFY_FAILS_END +#endif +} + +void testDoubleIsNan(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + TEST_ASSERT_DOUBLE_IS_NAN(0.0 / d_zero); +#endif +} + +void testDoubleIsNotNan(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_IS_NAN(234.9); + VERIFY_FAILS_END +#endif +} + +void testDoubleInfIsNotNan(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_IS_NAN(1.0 / d_zero); + VERIFY_FAILS_END +#endif +} + +void testDoubleNanIsNotInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_IS_INF(0.0 / d_zero); + VERIFY_FAILS_END +#endif +} + void testEqualDoubleArrays(void) { #ifdef UNITY_EXCLUDE_DOUBLE @@ -2557,3 +2938,30 @@ void testNotEqualDoubleArraysNegative3(void) #endif } +void testNotEqualDoubleArraysNaN(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + double p0[] = {1.0, 0.0 / d_zero, 25.4, 0.253}; + double p1[] = {1.0, 0.0 / d_zero, 25.4, 0.253}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4); + VERIFY_FAILS_END +#endif +} + +void testNotEqualDoubleArraysInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + double p0[] = {1.0, 1.0 / d_zero, 25.4, 0.253}; + double p1[] = {1.0, 1.0 / d_zero, 25.4, 0.253}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4); + VERIFY_FAILS_END +#endif +} \ No newline at end of file