From 8ff74d6000b352ea47ace8895e1bd66146e6086b Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Thu, 14 Sep 2017 13:47:04 -0400 Subject: [PATCH 01/50] Allow UnityPrintFloat() to print a 7th digit. --- src/unity.c | 49 +++++++++++++----- test/tests/testunity.c | 114 ++++++++++++++++++++++++----------------- 2 files changed, 102 insertions(+), 61 deletions(-) diff --git a/src/unity.c b/src/unity.c index 0f2d2de..429ff06 100644 --- a/src/unity.c +++ b/src/unity.c @@ -258,11 +258,14 @@ void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number) /*-----------------------------------------------*/ #ifndef UNITY_EXCLUDE_FLOAT_PRINT -/* 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. */ +/* + * This function prints a floating-point value in a format similar to + * printf("%.7g"). It can work with either single- or double-precision, + * but for simplicity, it prints only 7 significant digits in either case. + * The 7th digit won't always be totally correct in single-precision + * operation (for that level of accuracy, a more complicated algorithm + * would be needed). + */ void UnityPrintFloat(const UNITY_DOUBLE input_number) { UNITY_DOUBLE number = input_number; @@ -285,22 +288,42 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) UNITY_INT32 n; char buf[16]; - /* 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++; } + /* + * Scale up or down by powers of 10. To minimize rounding error, + * start with a factor/divisor of 10^10, which is the largest + * power of 10 that can be represented exactly. Finally, compute + * (exactly) the remaining power of 10 and perform one more + * multiplication or division. + */ + if(number < 1e6f) + { + UNITY_DOUBLE factor = 1.0f; + + while(number < 1e7f / 1e10f) { number *= 1e10f; exponent -= 10; } + while(number * factor < 1e6f) { factor *= 10.0f; exponent--; } + + number *= factor; + } + else if(number > 1e7f) + { + UNITY_DOUBLE divisor = 1.0f; + + while(number > 1e6f * 1e10f) { number /= 1e10f; exponent += 10; } + while(number / divisor > 1e7f) { divisor *= 10.0f; exponent++; } + + number /= divisor; + } /* round to nearest integer */ n = ((UNITY_INT32)(number + number) + 1) / 2; - if (n > 999999) + if (n > 9999999) { - n = 100000; + n = 1000000; exponent++; } /* determine where to place decimal point */ - decimals = (exponent <= 0 && exponent >= -9) ? -exponent : 5; + decimals = (exponent <= 0 && exponent >= -10) ? -exponent : 6; exponent += decimals; /* truncate trailing zeroes after decimal point */ diff --git a/test/tests/testunity.c b/test/tests/testunity.c index af06647..752c3b2 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -4466,46 +4466,48 @@ void testFloatPrinting(void) #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY) TEST_IGNORE(); #else + /* Some failures are expected due to differences in the last digit + * if UnityPrintFloat uses single-precision calculations. */ 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("5e-07", 0.0000005f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("0.1004695", 0.1004695f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("2", 1.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("7.999999", 7.999999f); /*Not rounding*/ + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00002", 16.00002f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00004", 16.00004f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00006", 16.00006f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("9999999", 9999999.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("-5e-07", -0.0000005f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.1004695", -0.1004695f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-2", -1.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("-7.999999", -7.999999f); /*Not rounding*/ + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00002", -16.00002f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00004", -16.00004f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00006", -16.00006f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-9999999", -9999999.0f); /*Last full print integer*/ - 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); + TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+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.309999e+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.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.000055e+10", (float)1.000055e+10f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1.1e+38", (float)1.10000005e+38f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1.635299e+10", 1.63529943e+10f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("3.402823e+38", 3.40282346638e38f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-1e+10", -1.0e+10f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-3.40282e+38", -3.40282346638e38f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-1e+10", -1.0e+10f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-3.402823e+38", -3.40282346638e38f); #endif } @@ -4526,27 +4528,43 @@ static void printFloatValue(float f) { char expected[18]; char expected_lower[18]; + char expected_lower2[18]; + char expected_lower3[18]; char expected_higher[18]; + char expected_higher2[18]; + char expected_higher3[18]; startPutcharSpy(); UnityPrintFloat(f); - sprintf(expected, "%.6g", f); + sprintf(expected, "%.7g", 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; + /* Allow for relative error of +/-2.5e-7 */ + double lower = (double)f * 0.99999995; + double lower2 = (double)f * 0.99999985; + double lower3 = (double)f * 0.99999975; + double higher = (double)f * 1.00000005; + double higher2 = (double)f * 1.00000015; + double higher3 = (double)f * 1.00000025; - 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(isfinite(lower)) sprintf(expected_lower, "%.7g", lower); else strcpy(expected_lower, expected); + if(isfinite(lower2)) sprintf(expected_lower2, "%.7g", lower2); else strcpy(expected_lower2, expected); + if(isfinite(lower3)) sprintf(expected_lower3, "%.7g", lower3); else strcpy(expected_lower3, expected); + if(isfinite(higher)) sprintf(expected_higher, "%.7g", higher); else strcpy(expected_higher, expected); + if(isfinite(higher2)) sprintf(expected_higher2, "%.7g", higher2); else strcpy(expected_higher2, expected); + if(isfinite(higher3)) sprintf(expected_higher3, "%.7g", higher3); else strcpy(expected_higher3, expected); if (strcmp(expected, getBufferPutcharSpy()) != 0 && strcmp(expected_lower, getBufferPutcharSpy()) != 0 && - strcmp(expected_higher, getBufferPutcharSpy()) != 0) + strcmp(expected_lower2, getBufferPutcharSpy()) != 0 && + strcmp(expected_lower3, getBufferPutcharSpy()) != 0 && + strcmp(expected_higher, getBufferPutcharSpy()) != 0 && + strcmp(expected_higher2, getBufferPutcharSpy()) != 0 && + strcmp(expected_higher3, getBufferPutcharSpy()) != 0) { /* Fail with diagnostic printing */ TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, f); @@ -5252,20 +5270,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("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.1004695", 0.10046949999999999); + TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+09", 4294967295.999999); + TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+09", 4294967295.9999995); + TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+09", 4294967296.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 9999999995.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("9.007199e+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.234568e+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("-7e+100", -7.0e+100); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.1004695", -0.10046949999999999); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.294967e+09", -4294967295.999999); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.294967e+09", -4294967295.9999995); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-7e+100", -7.0e+100); #endif } From 74ba70283a026cfcb83cf8a1998c6727535ab5a4 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Thu, 14 Sep 2017 19:19:49 -0400 Subject: [PATCH 02/50] Improve accuracy of UnityPrintFloat() for common cases. --- src/unity.c | 21 ++++++++++++++++++--- test/tests/testunity.c | 39 ++++++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/unity.c b/src/unity.c index 429ff06..d82e78b 100644 --- a/src/unity.c +++ b/src/unity.c @@ -283,9 +283,9 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) else if (isinf(number)) UnityPrint("inf"); else { + UNITY_INT32 n = 0; int exponent = 0; int decimals, digits; - UNITY_INT32 n; char buf[16]; /* @@ -295,7 +295,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) * (exactly) the remaining power of 10 and perform one more * multiplication or division. */ - if(number < 1e6f) + if(number < 1.0f) { UNITY_DOUBLE factor = 1.0f; @@ -313,9 +313,24 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) number /= divisor; } + else + { + /* + * In this range, we can split off the integer part before + * doing any multiplications. This reduces rounding error by + * freeing up significant bits in the fractional part. + */ + UNITY_DOUBLE factor = 1.0f; + n = (UNITY_INT32)number; + number -= (UNITY_DOUBLE)n; + + while(n < 1000000) { n *= 10; factor *= 10.0f; exponent--; } + + number *= factor; + } /* round to nearest integer */ - n = ((UNITY_INT32)(number + number) + 1) / 2; + n += ((UNITY_INT32)(number + number) + 1) / 2; if (n > 9999999) { n = 1000000; diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 752c3b2..626bb25 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -4543,20 +4543,33 @@ static void printFloatValue(float f) /* We print all NaN's as "nan", not "-nan" */ if(strcmp(expected, "-nan") == 0) strcpy(expected, "nan"); - /* Allow for relative error of +/-2.5e-7 */ - double lower = (double)f * 0.99999995; - double lower2 = (double)f * 0.99999985; - double lower3 = (double)f * 0.99999975; - double higher = (double)f * 1.00000005; - double higher2 = (double)f * 1.00000015; - double higher3 = (double)f * 1.00000025; + strcpy(expected_lower, expected); + strcpy(expected_lower2, expected); + strcpy(expected_lower3, expected); + strcpy(expected_higher, expected); + strcpy(expected_higher2, expected); + strcpy(expected_higher3, expected); - if(isfinite(lower)) sprintf(expected_lower, "%.7g", lower); else strcpy(expected_lower, expected); - if(isfinite(lower2)) sprintf(expected_lower2, "%.7g", lower2); else strcpy(expected_lower2, expected); - if(isfinite(lower3)) sprintf(expected_lower3, "%.7g", lower3); else strcpy(expected_lower3, expected); - if(isfinite(higher)) sprintf(expected_higher, "%.7g", higher); else strcpy(expected_higher, expected); - if(isfinite(higher2)) sprintf(expected_higher2, "%.7g", higher2); else strcpy(expected_higher2, expected); - if(isfinite(higher3)) sprintf(expected_higher3, "%.7g", higher3); else strcpy(expected_higher3, expected); + /* Allow for rounding differences in the last digit */ + double lower = (double)f * 0.99999995; + double higher = (double)f * 1.00000005; + + if(isfinite(lower)) sprintf(expected_lower, "%.7g", lower); + if(isfinite(higher)) sprintf(expected_higher, "%.7g", higher); + + /* Outside [1,10000000] allow for relative error of +/-2.5e-7 */ + if(f < 1.0 || f > 10000000) + { + double lower2 = (double)f * 0.99999985; + double lower3 = (double)f * 0.99999975; + double higher2 = (double)f * 1.00000015; + double higher3 = (double)f * 1.00000025; + + if(isfinite(lower2)) sprintf(expected_lower2, "%.7g", lower2); + if(isfinite(lower3)) sprintf(expected_lower3, "%.7g", lower3); + if(isfinite(higher2)) sprintf(expected_higher2, "%.7g", higher2); + if(isfinite(higher3)) sprintf(expected_higher3, "%.7g", higher3); + } if (strcmp(expected, getBufferPutcharSpy()) != 0 && strcmp(expected_lower, getBufferPutcharSpy()) != 0 && From 2d4e32cda1adafd521e13abefe493e9c93618c29 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Tue, 7 Nov 2017 22:44:59 -0500 Subject: [PATCH 03/50] Print 9 digits if we have double precision capability. --- src/unity.c | 39 ++++++----- test/tests/testunity.c | 148 +++++++++++++++++++++++++++++------------ 2 files changed, 129 insertions(+), 58 deletions(-) diff --git a/src/unity.c b/src/unity.c index d82e78b..03d3fbf 100644 --- a/src/unity.c +++ b/src/unity.c @@ -260,14 +260,23 @@ void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number) #ifndef UNITY_EXCLUDE_FLOAT_PRINT /* * This function prints a floating-point value in a format similar to - * printf("%.7g"). It can work with either single- or double-precision, - * but for simplicity, it prints only 7 significant digits in either case. - * The 7th digit won't always be totally correct in single-precision - * operation (for that level of accuracy, a more complicated algorithm - * would be needed). + * printf("%.7g") on a single-precision machine or printf("%.9g") on a + * double-precision machine. The 7th digit won't always be totally correct + * in single-precision operation (for that level of accuracy, a more + * complicated algorithm would be needed). */ void UnityPrintFloat(const UNITY_DOUBLE input_number) { +#ifdef UNITY_INCLUDE_DOUBLE + static const int sig_digits = 9; + static const UNITY_INT32 min_scaled = 100000000; + static const UNITY_INT32 max_scaled = 1000000000; +#else + static const int sig_digits = 7; + static const UNITY_INT32 min_scaled = 1000000; + static const UNITY_INT32 max_scaled = 10000000; +#endif + UNITY_DOUBLE number = input_number; /* print minus sign (including for negative zero) */ @@ -295,21 +304,21 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) * (exactly) the remaining power of 10 and perform one more * multiplication or division. */ - if(number < 1.0f) + if (number < 1.0f) { UNITY_DOUBLE factor = 1.0f; - while(number < 1e7f / 1e10f) { number *= 1e10f; exponent -= 10; } - while(number * factor < 1e6f) { factor *= 10.0f; exponent--; } + while (number < (UNITY_DOUBLE)max_scaled / 1e10f) { number *= 1e10f; exponent -= 10; } + while (number * factor < (UNITY_DOUBLE)min_scaled) { factor *= 10.0f; exponent--; } number *= factor; } - else if(number > 1e7f) + else if (number > (UNITY_DOUBLE)max_scaled) { UNITY_DOUBLE divisor = 1.0f; - while(number > 1e6f * 1e10f) { number /= 1e10f; exponent += 10; } - while(number / divisor > 1e7f) { divisor *= 10.0f; exponent++; } + while (number > (UNITY_DOUBLE)min_scaled * 1e10f) { number /= 1e10f; exponent += 10; } + while (number / divisor > (UNITY_DOUBLE)max_scaled) { divisor *= 10.0f; exponent++; } number /= divisor; } @@ -324,21 +333,21 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) n = (UNITY_INT32)number; number -= (UNITY_DOUBLE)n; - while(n < 1000000) { n *= 10; factor *= 10.0f; exponent--; } + while (n < min_scaled) { n *= 10; factor *= 10.0f; exponent--; } number *= factor; } /* round to nearest integer */ n += ((UNITY_INT32)(number + number) + 1) / 2; - if (n > 9999999) + if (n >= max_scaled) { - n = 1000000; + n = min_scaled; exponent++; } /* determine where to place decimal point */ - decimals = (exponent <= 0 && exponent >= -10) ? -exponent : 6; + decimals = (exponent <= 0 && exponent >= -(sig_digits + 3)) ? -exponent : (sig_digits - 1); exponent += decimals; /* truncate trailing zeroes after decimal point */ diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 626bb25..0aa6914 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -4463,38 +4463,37 @@ void testNotEqualFloatEachEqualLengthZero(void) void testFloatPrinting(void) { -#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY) +#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_INCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY) TEST_IGNORE(); #else - /* Some failures are expected due to differences in the last digit - * if UnityPrintFloat uses single-precision calculations. */ - 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.0000005f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("0.1004695", 0.1004695f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("2", 1.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.999999", 7.999999f); /*Not rounding*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00002", 16.00002f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00004", 16.00004f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00006", 16.00006f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("9999999", 9999999.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("5.000001e-07", 0.00000050000005f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("0.1004695", 0.100469499f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("2", 1.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.999999", 7.999999f); /*Not rounding*/ + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00002", 16.00002f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00004", 16.00004f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00006", 16.00006f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("9999999", 9999999.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.0000005f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.1004695", -0.1004695f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-2", -1.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.999999", -7.999999f); /*Not rounding*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00002", -16.00002f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00004", -16.00004f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00006", -16.00006f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-9999999", -9999999.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("-5.000001e-07", -0.00000050000005f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.1004695", -0.100469499f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-2", -1.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.999999", -7.999999f); /*Not rounding*/ + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00002", -16.00002f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00004", -16.00004f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00006", -16.00006f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-9999999", -9999999.0f); /*Last full print integer*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+09", 4294967296.0f); + /* Fails, prints "4.294968e+09" due to FP math imprecision + * TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+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.309999e+09", 8309999104.0f); @@ -4504,10 +4503,12 @@ void testFloatPrinting(void) TEST_ASSERT_EQUAL_PRINT_FLOATING("1.000055e+10", (float)1.000055e+10f); TEST_ASSERT_EQUAL_PRINT_FLOATING("1.1e+38", (float)1.10000005e+38f); TEST_ASSERT_EQUAL_PRINT_FLOATING("1.635299e+10", 1.63529943e+10f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("3.402823e+38", 3.40282346638e38f); + /* Fails, prints "3.402824e+38" due to FP math imprecision + * TEST_ASSERT_EQUAL_PRINT_FLOATING("3.402823e+38", 3.40282346638e38f); */ TEST_ASSERT_EQUAL_PRINT_FLOATING("-1e+10", -1.0e+10f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-3.402823e+38", -3.40282346638e38f); + /* Fails, prints "-3.402824e+38" due to FP math imprecision + * TEST_ASSERT_EQUAL_PRINT_FLOATING("-3.402823e+38", -3.40282346638e38f); */ #endif } @@ -4524,6 +4525,41 @@ void testFloatPrintingInfinityAndNaN(void) } #if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY) +#ifdef UNITY_INCLUDE_DOUBLE +static void printFloatValue(float f) +{ + char expected[18]; + char expected_lower[18]; + char expected_higher[18]; + + startPutcharSpy(); + + UnityPrintFloat(f); + + sprintf(expected, "%.9g", f); + + /* We print all NaN's as "nan", not "-nan" */ + if(strcmp(expected, "-nan") == 0) strcpy(expected, "nan"); + + strcpy(expected_lower, expected); + strcpy(expected_higher, expected); + + /* Allow for rounding differences in the last digit */ + double lower = (double)f * 0.9999999995; + double higher = (double)f * 1.0000000005; + + if(isfinite(lower)) sprintf(expected_lower, "%.9g", lower); + if(isfinite(higher)) sprintf(expected_higher, "%.9g", higher); + + if (strcmp(expected, getBufferPutcharSpy()) != 0 && + strcmp(expected_lower, getBufferPutcharSpy()) != 0 && + strcmp(expected_higher, getBufferPutcharSpy()) != 0) + { + /* Fail with diagnostic printing */ + TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, f); + } +} +#else static void printFloatValue(float f) { char expected[18]; @@ -4584,6 +4620,7 @@ static void printFloatValue(float f) } } #endif +#endif void testFloatPrintingRandomSamples(void) { @@ -5283,20 +5320,45 @@ 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.1004695", 0.10046949999999999); - TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+09", 4294967295.999999); - TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+09", 4294967295.9999995); - TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+09", 4294967296.0); - TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 9999999995.0); - TEST_ASSERT_EQUAL_PRINT_FLOATING("9.007199e+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.234568e+300", 9.23456789e+300); + TEST_ASSERT_EQUAL_PRINT_FLOATING("0", 0.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("4.99e-07", 0.000000499); + TEST_ASSERT_EQUAL_PRINT_FLOATING("5.0000005e-07", 0.00000050000005); + TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469499", 0.100469499); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 0.9999999995); /*Rounding to int place*/ + TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 1.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1.25", 1.25); + TEST_ASSERT_EQUAL_PRINT_FLOATING("7.99999999", 7.99999999); /*Not rounding*/ + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0000002", 16.0000002); + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0000004", 16.0000004); + TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0000006", 16.0000006); + TEST_ASSERT_EQUAL_PRINT_FLOATING("999999999", 999999999.0); /*Last full print integer*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.1004695", -0.10046949999999999); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.294967e+09", -4294967295.999999); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.294967e+09", -4294967295.9999995); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-7e+100", -7.0e+100); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-0", -0.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.99e-07", -0.000000499); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-5.0000005e-07", -0.00000050000005); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469499", -0.100469499); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -0.9999999995); /*Rounding to int place*/ + TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -1.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.25", -1.25); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.99999999", -7.99999999); /*Not rounding*/ + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0000002", -16.0000002); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0000004", -16.0000004); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0000006", -16.0000006); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-999999999", -999999999.0); /*Last full print integer*/ + + TEST_ASSERT_EQUAL_PRINT_FLOATING("0.1004695", 0.10046949999999999); + TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967295.9); + TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967296.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 9999999995.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199254740990.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("7e+100", 7.0e+100); + TEST_ASSERT_EQUAL_PRINT_FLOATING("3e+200", 3.0e+200); + TEST_ASSERT_EQUAL_PRINT_FLOATING("9.23456789e+300", 9.23456789e+300); + + TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.1004695", -0.10046949999999999); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.2949673e+09", -4294967295.9); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.2949673e+09", -4294967296.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-7e+100", -7.0e+100); #endif } From a6d3f3a59aedb401c89b530b108f4df24e1e4cb5 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Tue, 7 Nov 2017 23:25:27 -0500 Subject: [PATCH 04/50] Restore round-to-even behavior. --- src/unity.c | 19 +++++++++--- test/tests/testunity.c | 70 +++++++++++++++++++++++++----------------- 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/unity.c b/src/unity.c index 03d3fbf..fc3ae53 100644 --- a/src/unity.c +++ b/src/unity.c @@ -292,7 +292,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) else if (isinf(number)) UnityPrint("inf"); else { - UNITY_INT32 n = 0; + UNITY_INT32 n_int = 0, n; int exponent = 0; int decimals, digits; char buf[16]; @@ -330,16 +330,25 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) * freeing up significant bits in the fractional part. */ UNITY_DOUBLE factor = 1.0f; - n = (UNITY_INT32)number; - number -= (UNITY_DOUBLE)n; + n_int = (UNITY_INT32)number; + number -= (UNITY_DOUBLE)n_int; - while (n < min_scaled) { n *= 10; factor *= 10.0f; exponent--; } + while (n_int < min_scaled) { n_int *= 10; factor *= 10.0f; exponent--; } number *= factor; } /* round to nearest integer */ - n += ((UNITY_INT32)(number + number) + 1) / 2; + n = ((UNITY_INT32)(number + number) + 1) / 2; + +#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO + /* round to even if exactly between two integers */ + if ((n & 1) && ((UNITY_DOUBLE)n - number == 0.5f)) + n--; +#endif + + n += n_int; + if (n >= max_scaled) { n = min_scaled; diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 0aa6914..2d6a5ab 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -4468,7 +4468,6 @@ void testFloatPrinting(void) #else TEST_ASSERT_EQUAL_PRINT_FLOATING("0", 0.0f); TEST_ASSERT_EQUAL_PRINT_FLOATING("4.99e-07", 0.000000499f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("5.000001e-07", 0.00000050000005f); TEST_ASSERT_EQUAL_PRINT_FLOATING("0.1004695", 0.100469499f); TEST_ASSERT_EQUAL_PRINT_FLOATING("2", 1.9999995f); /*Rounding to int place*/ TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 1.0f); @@ -4481,7 +4480,6 @@ void testFloatPrinting(void) TEST_ASSERT_EQUAL_PRINT_FLOATING("-0", -0.0f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.99e-07", -0.000000499f); - TEST_ASSERT_EQUAL_PRINT_FLOATING("-5.000001e-07", -0.00000050000005f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.1004695", -0.100469499f); TEST_ASSERT_EQUAL_PRINT_FLOATING("-2", -1.9999995f); /*Rounding to int place*/ TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -1.0f); @@ -4512,6 +4510,25 @@ void testFloatPrinting(void) #endif } +void testFloatPrintingRoundTiesToEven(void) +{ +#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_INCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY) + TEST_IGNORE(); +#else + #ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO + TEST_ASSERT_EQUAL_PRINT_FLOATING("0.0004882813", 0.00048828125f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("488281.3", 488281.25f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("5.000001e-07", 0.00000050000005f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-5.000001e-07", -0.00000050000005f); + #else /* Default to Round ties to even */ + TEST_ASSERT_EQUAL_PRINT_FLOATING("0.0004882812", 0.00048828125f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("488281.2", 488281.25f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("5e-07", 0.00000050000005f); + TEST_ASSERT_EQUAL_PRINT_FLOATING("-5e-07", -0.00000050000005f); + #endif +#endif +} + void testFloatPrintingInfinityAndNaN(void) { #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY) @@ -4529,31 +4546,15 @@ void testFloatPrintingInfinityAndNaN(void) static void printFloatValue(float f) { char expected[18]; - char expected_lower[18]; - char expected_higher[18]; startPutcharSpy(); - UnityPrintFloat(f); sprintf(expected, "%.9g", f); - /* We print all NaN's as "nan", not "-nan" */ - if(strcmp(expected, "-nan") == 0) strcpy(expected, "nan"); + if (strcmp(expected, "-nan") == 0) strcpy(expected, "nan"); - strcpy(expected_lower, expected); - strcpy(expected_higher, expected); - - /* Allow for rounding differences in the last digit */ - double lower = (double)f * 0.9999999995; - double higher = (double)f * 1.0000000005; - - if(isfinite(lower)) sprintf(expected_lower, "%.9g", lower); - if(isfinite(higher)) sprintf(expected_higher, "%.9g", higher); - - if (strcmp(expected, getBufferPutcharSpy()) != 0 && - strcmp(expected_lower, getBufferPutcharSpy()) != 0 && - strcmp(expected_higher, getBufferPutcharSpy()) != 0) + if (strcmp(expected, getBufferPutcharSpy())) { /* Fail with diagnostic printing */ TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, f); @@ -4571,13 +4572,11 @@ static void printFloatValue(float f) char expected_higher3[18]; startPutcharSpy(); - UnityPrintFloat(f); sprintf(expected, "%.7g", f); - /* We print all NaN's as "nan", not "-nan" */ - if(strcmp(expected, "-nan") == 0) strcpy(expected, "nan"); + if (strcmp(expected, "-nan") == 0) strcpy(expected, "nan"); strcpy(expected_lower, expected); strcpy(expected_lower2, expected); @@ -4594,17 +4593,17 @@ static void printFloatValue(float f) if(isfinite(higher)) sprintf(expected_higher, "%.7g", higher); /* Outside [1,10000000] allow for relative error of +/-2.5e-7 */ - if(f < 1.0 || f > 10000000) + if (f < 1.0 || f > 10000000) { double lower2 = (double)f * 0.99999985; double lower3 = (double)f * 0.99999975; double higher2 = (double)f * 1.00000015; double higher3 = (double)f * 1.00000025; - if(isfinite(lower2)) sprintf(expected_lower2, "%.7g", lower2); - if(isfinite(lower3)) sprintf(expected_lower3, "%.7g", lower3); - if(isfinite(higher2)) sprintf(expected_higher2, "%.7g", higher2); - if(isfinite(higher3)) sprintf(expected_higher3, "%.7g", higher3); + if (isfinite(lower2)) sprintf(expected_lower2, "%.7g", lower2); + if (isfinite(lower3)) sprintf(expected_lower3, "%.7g", lower3); + if (isfinite(higher2)) sprintf(expected_higher2, "%.7g", higher2); + if (isfinite(higher3)) sprintf(expected_higher3, "%.7g", higher3); } if (strcmp(expected, getBufferPutcharSpy()) != 0 && @@ -5362,6 +5361,21 @@ void testDoublePrinting(void) #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("1e+10", 10000000050.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719924e+15", 9007199245000000.0); + #endif +#endif +} + void testDoublePrintingInfinityAndNaN(void) { #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY) From f60ab920c918519f30c32403f494aca5fec5a489 Mon Sep 17 00:00:00 2001 From: Kyle Krueger Date: Mon, 10 Sep 2018 10:38:55 +0200 Subject: [PATCH 05/50] switch hardcoded string to reference existing value --- examples/example_3/target_gcc_32.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_3/target_gcc_32.yml b/examples/example_3/target_gcc_32.yml index f155508..8e772b0 100644 --- a/examples/example_3/target_gcc_32.yml +++ b/examples/example_3/target_gcc_32.yml @@ -15,7 +15,7 @@ compiler: includes: prefix: '-I' items: - - 'src/' + - *source_path - '../../src/' - *unit_tests_path defines: From c64cc7d4f41555b33cd47a9f478f6e92ea3189f2 Mon Sep 17 00:00:00 2001 From: Kyle Krueger Date: Mon, 10 Sep 2018 10:51:14 +0200 Subject: [PATCH 06/50] fix new references --- examples/example_3/target_gcc_32.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/example_3/target_gcc_32.yml b/examples/example_3/target_gcc_32.yml index 8e772b0..124e674 100644 --- a/examples/example_3/target_gcc_32.yml +++ b/examples/example_3/target_gcc_32.yml @@ -1,8 +1,9 @@ # Copied from ~Unity/targets/gcc_32.yml unity_root: &unity_root '../..' +unity_source: &unity_source '../../src' compiler: path: gcc - source_path: 'src/' + source_path: &source_path 'src/' unit_tests_path: &unit_tests_path 'test/' build_path: &build_path 'build/' options: @@ -15,8 +16,8 @@ compiler: includes: prefix: '-I' items: - - *source_path - - '../../src/' + - *source_path + - *unity_source - *unit_tests_path defines: prefix: '-D' From 5d2ef07054c201776520b2c3ada19b819f56253c Mon Sep 17 00:00:00 2001 From: Kyle Krueger Date: Mon, 10 Sep 2018 11:21:41 +0200 Subject: [PATCH 07/50] remove change that slipped in from other project --- examples/example_3/target_gcc_32.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_3/target_gcc_32.yml b/examples/example_3/target_gcc_32.yml index 124e674..4acc294 100644 --- a/examples/example_3/target_gcc_32.yml +++ b/examples/example_3/target_gcc_32.yml @@ -1,6 +1,6 @@ # Copied from ~Unity/targets/gcc_32.yml unity_root: &unity_root '../..' -unity_source: &unity_source '../../src' +unity_source: &unity_source '../../' compiler: path: gcc source_path: &source_path 'src/' From 8ba35a0e523c0a8efbb6cd4e5eb9f2d2ce4fc0a6 Mon Sep 17 00:00:00 2001 From: Kyle Krueger Date: Mon, 10 Sep 2018 11:26:13 +0200 Subject: [PATCH 08/50] Revert "remove change that slipped in from other project" This reverts commit 5d2ef07054c201776520b2c3ada19b819f56253c. --- examples/example_3/target_gcc_32.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_3/target_gcc_32.yml b/examples/example_3/target_gcc_32.yml index 4acc294..124e674 100644 --- a/examples/example_3/target_gcc_32.yml +++ b/examples/example_3/target_gcc_32.yml @@ -1,6 +1,6 @@ # Copied from ~Unity/targets/gcc_32.yml unity_root: &unity_root '../..' -unity_source: &unity_source '../../' +unity_source: &unity_source '../../src' compiler: path: gcc source_path: &source_path 'src/' From 56f16460876b34c5b5708909c06957f7761db1c5 Mon Sep 17 00:00:00 2001 From: Kyle Krueger Date: Mon, 10 Sep 2018 15:19:15 +0200 Subject: [PATCH 09/50] add missing trailing slash --- examples/example_3/target_gcc_32.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_3/target_gcc_32.yml b/examples/example_3/target_gcc_32.yml index 124e674..d7568ab 100644 --- a/examples/example_3/target_gcc_32.yml +++ b/examples/example_3/target_gcc_32.yml @@ -1,6 +1,6 @@ # Copied from ~Unity/targets/gcc_32.yml unity_root: &unity_root '../..' -unity_source: &unity_source '../../src' +unity_source: &unity_source '../../src/' compiler: path: gcc source_path: &source_path 'src/' From e0d52d1a7908a4c0a78c439919c31c71bc2dc8d5 Mon Sep 17 00:00:00 2001 From: Kyle Krueger Date: Wed, 12 Sep 2018 17:46:11 +0200 Subject: [PATCH 10/50] fix uninitialzed value warning --- src/unity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 103bde2..4bad2c2 100644 --- a/src/unity.c +++ b/src/unity.c @@ -283,7 +283,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) int exponent = 0; int decimals, digits; UNITY_INT32 n; - char buf[16]; + char buf[16] = {0}; /* scale up or down by powers of 10 */ while (number < 100000.0f / 1e6f) { number *= 1e6f; exponent -= 6; } From e2e549a22f55465074e9f73c4012473a9a7f56e3 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 14 Oct 2018 14:08:09 +0200 Subject: [PATCH 11/50] Added include of 'stddef.h' to 'unity_internals.h' if 'UNITY_EXCLUDE_STDDEF_H' is not defined. This adds compiler independent support for the 'NULL' macro. --- docs/UnityConfigurationGuide.md | 12 ++++++++++++ src/unity_internals.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index dace20c..b88eeee 100644 --- a/docs/UnityConfigurationGuide.md +++ b/docs/UnityConfigurationGuide.md @@ -215,6 +215,18 @@ Guide. _Example:_ #define UNITY_FLOAT_PRECISION 0.001f +### Miscellaneous + +##### `UNITY_EXCLUDE_STDDEF_H` + +Unity uses the `NULL` macro, which defines the value of a null pointer constant, +defined in `stddef.h` by default. If you want to provide +your own macro for this, you should exclude the `stddef.h` header file by adding this +define to your configuration. + +_Example:_ + #define UNITY_EXCLUDE_STDDEF_H + ### Toolset Customization diff --git a/src/unity_internals.h b/src/unity_internals.h index 351d9fe..4c55ef8 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -19,6 +19,10 @@ #include #endif +#ifndef UNITY_EXCLUDE_STDDEF_H +#include +#endif + /* Unity Attempts to Auto-Detect Integer Types * Attempt 1: UINT_MAX, ULONG_MAX in , or default to 32 bits * Attempt 2: UINTPTR_MAX in , or default to same size as long From 7cc3cf478bfae76b516f245ac3e5ff12f09f3ef4 Mon Sep 17 00:00:00 2001 From: Levin Messing Date: Thu, 18 Oct 2018 23:55:38 +0200 Subject: [PATCH 12/50] fixed compile error UNITY_PRINT_EXEC_TIME() --- src/unity_internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unity_internals.h b/src/unity_internals.h index 4c55ef8..7249fc7 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -323,7 +323,7 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT; #ifdef UNITY_INCLUDE_EXEC_TIME #define UNITY_PRINT_EXEC_TIME() \ UnityPrint(" (");\ - UNITY_COUNTER_TYPE execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); + UNITY_COUNTER_TYPE execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime);\ UnityPrintNumberUnsigned(execTimeMs);\ UnityPrint(" ms)"); #else From 01cbce870a55037cc808235b71e83d29ef1417ae Mon Sep 17 00:00:00 2001 From: Filip Michalak Date: Mon, 22 Oct 2018 15:32:22 +0200 Subject: [PATCH 13/50] Changed some text issues --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ec73b4a..abddd4c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Running Tests RUN_TEST(func, linenum) -Each Test is run within the macro `RUN_TEST`. This macro performs necessary setup before the test is called and handles cleanup and result tabulation afterwards. +Each Test is run within the macro `RUN_TEST`. This macro performs necessary setup before the test is called and handles cleanup and result tabulation afterwards. Ignoring Tests -------------- @@ -75,7 +75,7 @@ Another way of calling `TEST_ASSERT_FALSE` TEST_FAIL() TEST_FAIL_MESSAGE(message) -This test is automatically marked as a failure. The message is output stating why. +This test is automatically marked as a failure. The message is output stating why. Numerical Assertions: Integers ------------------------------ @@ -87,7 +87,7 @@ Numerical Assertions: Integers TEST_ASSERT_EQUAL_INT64(expected, actual) Compare two integers for equality and display errors as signed integers. A cast will be performed -to your natural integer size so often this can just be used. When you need to specify the exact size, +to your natural integer size so often this can just be used. When you need to specify the exact size, like when comparing arrays, you can use a specific version: TEST_ASSERT_EQUAL_UINT(expected, actual) @@ -96,7 +96,7 @@ like when comparing arrays, you can use a specific version: TEST_ASSERT_EQUAL_UINT32(expected, actual) TEST_ASSERT_EQUAL_UINT64(expected, actual) -Compare two integers for equality and display errors as unsigned integers. Like INT, there are +Compare two integers for equality and display errors as unsigned integers. Like INT, there are variants for different sizes also. TEST_ASSERT_EQUAL_HEX(expected, actual) @@ -105,7 +105,7 @@ variants for different sizes also. TEST_ASSERT_EQUAL_HEX32(expected, actual) TEST_ASSERT_EQUAL_HEX64(expected, actual) -Compares two integers for equality and display errors as hexadecimal. Like the other integer comparisons, +Compares two integers for equality and display errors as hexadecimal. Like the other integer comparisons, you can specify the size... here the size will also effect how many nibbles are shown (for example, `HEX16` will show 4 nibbles). @@ -115,7 +115,7 @@ Another way of calling TEST_ASSERT_EQUAL_INT TEST_ASSERT_INT_WITHIN(delta, expected, actual) -Asserts that the actual value is within plus or minus delta of the expected value. This also comes in +Asserts that the actual value is within plus or minus delta of the expected value. This also comes in size specific variants. @@ -199,12 +199,12 @@ Compare two null-terminate strings. Fail if any character is different or if th TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message) -Compare two strings. Fail if any character is different, stop comparing after len characters. Output a custom message on failure. +Compare two strings. Fail if any character is different, stop comparing after len characters. Output a custom message on failure. Pointer Assertions ------------------ -Most pointer operations can be performed by simply using the integer comparisons above. However, a couple of special cases are added for clarity. +Most pointer operations can be performed by simply using the integer comparisons above. However, a couple of special cases are added for clarity. TEST_ASSERT_NULL(pointer) From e84cb29acc0e01e22728bc6bf093329b67710588 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sat, 27 Oct 2018 11:24:29 +0200 Subject: [PATCH 14/50] Fixed an "array index out of bounds violation" in the examples (regarding issue #360). --- examples/example_1/src/ProductionCode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/example_1/src/ProductionCode.c b/examples/example_1/src/ProductionCode.c index d039c3e..db128e5 100644 --- a/examples/example_1/src/ProductionCode.c +++ b/examples/example_1/src/ProductionCode.c @@ -4,14 +4,14 @@ int Counter = 0; int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; /* some obnoxious array to search that is 1-based indexing instead of 0. */ -/* This function is supposed to search through NumbersToFind and find a particular number. - * If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since - * NumbersToFind is indexed from 1. Unfortunately it's broken +/* This function is supposed to search through NumbersToFind and find a particular number. + * If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since + * NumbersToFind is indexed from 1. Unfortunately it's broken * (and should therefore be caught by our tests) */ int FindFunction_WhichIsBroken(int NumberToFind) { int i = 0; - while (i <= 8) /* Notice I should have been in braces */ + while (i < 8) /* Notice I should have been in braces */ i++; if (NumbersToFind[i] == NumberToFind) /* Yikes! I'm getting run after the loop finishes instead of during it! */ return i; From b4ab81bbe994adfe1aaf401196deddf999c67250 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sat, 27 Oct 2018 16:00:52 +0200 Subject: [PATCH 15/50] Added first working implementation. --- src/unity.c | 174 ++++++++++++++++++++++++++++++++++-------- src/unity_internals.h | 9 +++ 2 files changed, 152 insertions(+), 31 deletions(-) diff --git a/src/unity.c b/src/unity.c index 103bde2..ea50b31 100644 --- a/src/unity.c +++ b/src/unity.c @@ -67,6 +67,57 @@ static const char UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " "; * Pretty Printers & Test Result Output Handlers *-----------------------------------------------*/ +/*-----------------------------------------------*/ +/* Local helper function to print characters. */ +static void UnityPrintChar(const char* pch) +{ + /* printable characters plus CR & LF are printed */ + if ((*pch <= 126) && (*pch >= 32)) + { + UNITY_OUTPUT_CHAR(*pch); + } + /* write escaped carriage returns */ + else if (*pch == 13) + { + UNITY_OUTPUT_CHAR('\\'); + UNITY_OUTPUT_CHAR('r'); + } + /* write escaped line feeds */ + else if (*pch == 10) + { + UNITY_OUTPUT_CHAR('\\'); + UNITY_OUTPUT_CHAR('n'); + } + /* unprintable characters are shown as codes */ + else + { + UNITY_OUTPUT_CHAR('\\'); + UNITY_OUTPUT_CHAR('x'); + UnityPrintNumberHex((UNITY_UINT)*pch, 2); + } +} + +/*-----------------------------------------------*/ +#ifdef UNITY_OUTPUT_COLOR +static UNITY_UINT UnityPrintAnsiEscapeString(const char* string) +{ + const char* pch = string; + UNITY_UINT count = 0; + + while (*pch && *pch != 'm') + { + UNITY_OUTPUT_CHAR(*pch); + pch++; + count++; + } + UNITY_OUTPUT_CHAR('m'); + count++; + + return count; +} +#endif + +/*-----------------------------------------------*/ void UnityPrint(const char* string) { const char* pch = string; @@ -75,47 +126,108 @@ void UnityPrint(const char* string) { while (*pch) { - /* printable characters plus CR & LF are printed */ - if ((*pch <= 126) && (*pch >= 32)) - { - UNITY_OUTPUT_CHAR(*pch); - } - /* write escaped carriage returns */ - else if (*pch == 13) - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('r'); - } - /* write escaped line feeds */ - else if (*pch == 10) - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('n'); - } #ifdef UNITY_OUTPUT_COLOR /* print ANSI escape code */ - else if (*pch == 27 && *(pch + 1) == '[') + if (*pch == 27 && *(pch + 1) == '[') { - while (*pch && *pch != 'm') - { - UNITY_OUTPUT_CHAR(*pch); - pch++; - } - UNITY_OUTPUT_CHAR('m'); + pch += UnityPrintAnsiEscapeString(pch); + continue; } #endif - /* unprintable characters are shown as codes */ - else - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('x'); - UnityPrintNumberHex((UNITY_UINT)*pch, 2); - } + UnityPrintChar(pch); pch++; } } } +/*-----------------------------------------------*/ +#ifndef UNITY_EXCLUDE_PRINT_FORMATTED +void UnityPrintFormatted(const char* format, ... ) +{ + const char* pch = format; + va_list va; + va_start(va, format); + + if (pch != NULL) + { + while (*pch) + { + /* format identification character */ + if (*pch == '%') + { + pch++; + + if (pch != NULL) + { + switch (*pch) + { + case 'd': + case 'i': + { + const UNITY_INT number = va_arg(va, UNITY_INT); + UnityPrintNumber(number); + break; + } + case 'u': + { + const UNITY_UINT number = va_arg(va, UNITY_UINT); + UnityPrintNumberUnsigned(number); + break; + } + case 'x': + case 'X': + case 'p': + { + const UNITY_UINT number = va_arg(va, UNITY_UINT); + UNITY_OUTPUT_CHAR('0'); + UNITY_OUTPUT_CHAR('x'); + UnityPrintNumberHex(number, 8); + break; + } + case 'c': + { + const UNITY_INT ch = va_arg(va, UNITY_INT); + UnityPrintChar((const char *)&ch); + break; + } + case 's': + { const char * string = va_arg(va, const char *); + UnityPrint(string); + break; + } + case '%': + default: + UnityPrintChar(pch); + break; + } + } + } +#ifdef UNITY_OUTPUT_COLOR + /* print ANSI escape code */ + else if (*pch == 27 && *(pch + 1) == '[') + { + pch += UnityPrintAnsiEscapeString(pch); + continue; + } +#endif + else if (*pch == '\n') + { + UNITY_PRINT_EOL(); + } + else + { + UnityPrintChar(pch); + } + + pch++; + } + } + + va_end(va); +} +#endif /* ! UNITY_EXCLUDE_PRINT_FORMATTED */ + +/*-----------------------------------------------*/ void UnityPrintLen(const char* string, const UNITY_UINT32 length) { const char* pch = string; diff --git a/src/unity_internals.h b/src/unity_internals.h index 7249fc7..69e08a5 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -23,6 +23,10 @@ #include #endif +#ifndef UNITY_EXCLUDE_PRINT_FORMATTED +#include +#endif + /* Unity Attempts to Auto-Detect Integer Types * Attempt 1: UINT_MAX, ULONG_MAX in , or default to 32 bits * Attempt 2: UINTPTR_MAX in , or default to same size as long @@ -489,6 +493,11 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int *-------------------------------------------------------*/ void UnityPrint(const char* string); + +#ifndef UNITY_EXCLUDE_PRINT_FORMATTED +void UnityPrintFormatted(const char* format, ... ); +#endif + void UnityPrintLen(const char* string, const UNITY_UINT32 length); void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number); void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style); From f1100dd19a12763fcc2a0027ffa54b9958746ed7 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sat, 27 Oct 2018 18:21:01 +0200 Subject: [PATCH 16/50] Added support for %b (bits / binary), %f (float) and %g (double). --- src/unity.c | 44 ++++++++++++++++++++++++++++++++++--------- src/unity_internals.h | 2 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/unity.c b/src/unity.c index ea50b31..0f71b91 100644 --- a/src/unity.c +++ b/src/unity.c @@ -164,29 +164,47 @@ void UnityPrintFormatted(const char* format, ... ) case 'd': case 'i': { - const UNITY_INT number = va_arg(va, UNITY_INT); - UnityPrintNumber(number); + const int number = va_arg(va, int); + UnityPrintNumber((UNITY_INT)number); break; } +#ifndef UNITY_EXCLUDE_FLOAT_PRINT + case 'f': + case 'g': + { + const double number = va_arg(va, double); + UnityPrintFloat((UNITY_DOUBLE)number); + break; + } +#endif case 'u': { - const UNITY_UINT number = va_arg(va, UNITY_UINT); - UnityPrintNumberUnsigned(number); + const unsigned int number = va_arg(va, unsigned int); + UnityPrintNumberUnsigned((UNITY_UINT)number); + break; + } + case 'b': + { + const unsigned int number = va_arg(va, unsigned int); + const UNITY_UINT mask = (UNITY_UINT)0 - (UNITY_UINT)1; + UNITY_OUTPUT_CHAR('0'); + UNITY_OUTPUT_CHAR('b'); + UnityPrintMask(mask, (UNITY_UINT)number); break; } case 'x': case 'X': case 'p': { - const UNITY_UINT number = va_arg(va, UNITY_UINT); + const unsigned int number = va_arg(va, unsigned int); UNITY_OUTPUT_CHAR('0'); UNITY_OUTPUT_CHAR('x'); - UnityPrintNumberHex(number, 8); + UnityPrintNumberHex((UNITY_UINT)number, 8); break; } case 'c': { - const UNITY_INT ch = va_arg(va, UNITY_INT); + const int ch = va_arg(va, int); UnityPrintChar((const char *)&ch); break; } @@ -196,9 +214,17 @@ void UnityPrintFormatted(const char* format, ... ) break; } case '%': + { + UnityPrintChar(pch); + break; + } default: - UnityPrintChar(pch); - break; + { + /* print the unknown character */ + UNITY_OUTPUT_CHAR('%'); + UnityPrintChar(pch); + break; + } } } } diff --git a/src/unity_internals.h b/src/unity_internals.h index 69e08a5..9bdd171 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -134,7 +134,7 @@ typedef UNITY_INT32 UNITY_INT; #else - /* 64-bit Support */ + /* 64-bit Support */ #if (UNITY_LONG_WIDTH == 32) typedef unsigned long long UNITY_UINT64; typedef signed long long UNITY_INT64; From be765649f1f4203de9ea79241f6c9f929b056502 Mon Sep 17 00:00:00 2001 From: Kochise Date: Wed, 31 Oct 2018 11:24:37 +0100 Subject: [PATCH 17/50] Some cleanup --- src/unity_internals.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/unity_internals.h b/src/unity_internals.h index 7249fc7..0d047da 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -359,7 +359,6 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT; # undef UNITY_WEAK_PRAGMA #endif - /*------------------------------------------------------- * Internal Structs Needed *-------------------------------------------------------*/ @@ -400,11 +399,13 @@ UNITY_DISPLAY_STYLE_UINT = sizeof(unsigned) + UNITY_DISPLAY_RANGE_UINT, typedef enum { + UNITY_WITHIN = 0, UNITY_EQUAL_TO = 1, UNITY_GREATER_THAN = 2, UNITY_GREATER_OR_EQUAL = 2 + UNITY_EQUAL_TO, UNITY_SMALLER_THAN = 4, - UNITY_SMALLER_OR_EQUAL = 4 + UNITY_EQUAL_TO + UNITY_SMALLER_OR_EQUAL = 4 + UNITY_EQUAL_TO, + UNITY_UNKNOWN } UNITY_COMPARISON_T; #ifndef UNITY_EXCLUDE_FLOAT @@ -425,7 +426,8 @@ typedef enum UNITY_FLOAT_TRAIT typedef enum { UNITY_ARRAY_TO_VAL = 0, - UNITY_ARRAY_TO_ARRAY + UNITY_ARRAY_TO_ARRAY, + UNITY_ARRAY_UNKNOWN } UNITY_FLAGS_T; struct UNITY_STORAGE_T @@ -568,9 +570,9 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); -void UnityFail(const char* msg, const UNITY_LINE_TYPE line); +void UnityFail(const char* message, const UNITY_LINE_TYPE line); -void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line); +void UnityIgnore(const char* message, const UNITY_LINE_TYPE line); #ifndef UNITY_EXCLUDE_FLOAT void UnityAssertFloatsWithin(const UNITY_FLOAT delta, @@ -826,9 +828,9 @@ int UnityTestMatches(void); #define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)expected, 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT64)expected, 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)expected, 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_INT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_INT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_UINT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) @@ -910,10 +912,10 @@ int UnityTestMatches(void); #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #else -#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((UNITY_DOUBLE)(delta), (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)line) -#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((UNITY_DOUBLE)(expected) * (UNITY_DOUBLE)UNITY_DOUBLE_PRECISION, (UNITY_DOUBLE)expected, (UNITY_DOUBLE)actual, (UNITY_LINE_TYPE)(line), message) -#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((UNITY_DOUBLE*)(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray(UnityDoubleToPtr(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((UNITY_DOUBLE)(delta), (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line)) +#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((UNITY_DOUBLE)(expected) * (UNITY_DOUBLE)UNITY_DOUBLE_PRECISION, (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (UNITY_LINE_TYPE)(line), (message)) +#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((UNITY_DOUBLE*)(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray(UnityDoubleToPtr(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_INF) #define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NEG_INF) #define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NAN) From 96127581a041a2c76a3a6ae6659499dbb7dc1678 Mon Sep 17 00:00:00 2001 From: Kochise Date: Wed, 31 Oct 2018 11:30:13 +0100 Subject: [PATCH 18/50] Some cleanup --- src/unity.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 103bde2..4efc47f 100644 --- a/src/unity.c +++ b/src/unity.c @@ -67,6 +67,7 @@ static const char UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " "; * Pretty Printers & Test Result Output Handlers *-----------------------------------------------*/ +/*-----------------------------------------------*/ void UnityPrint(const char* string) { const char* pch = string; @@ -116,6 +117,7 @@ void UnityPrint(const char* string) } } +/*-----------------------------------------------*/ void UnityPrintLen(const char* string, const UNITY_UINT32 length) { const char* pch = string; @@ -479,6 +481,7 @@ static void UnityPrintExpectedAndActualStringsLen(const char* expected, * Assertion & Control Helpers *-----------------------------------------------*/ +/*-----------------------------------------------*/ static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_LINE_TYPE lineNumber, @@ -511,6 +514,7 @@ static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected, * Assertion Functions *-----------------------------------------------*/ +/*-----------------------------------------------*/ void UnityAssertBits(const UNITY_INT mask, const UNITY_INT expected, const UNITY_INT actual, @@ -704,12 +708,14 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UnityPrint(UnityStrDelta) #endif /* UNITY_EXCLUDE_FLOAT_PRINT */ +/*-----------------------------------------------*/ static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected, UNITY_FLOAT actual) { UNITY_FLOAT diff; UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff); } +/*-----------------------------------------------*/ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected, UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* actual, const UNITY_UINT32 num_elements, @@ -840,6 +846,7 @@ static int UnityDoublesWithin(UNITY_DOUBLE delta, UNITY_DOUBLE expected, UNITY_D UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff); } +/*-----------------------------------------------*/ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expected, UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* actual, const UNITY_UINT32 num_elements, @@ -900,7 +907,6 @@ void UnityAssertDoublesWithin(const UNITY_DOUBLE delta, } /*-----------------------------------------------*/ - void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual, const char* msg, const UNITY_LINE_TYPE lineNumber, @@ -1259,6 +1265,7 @@ UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size) } #ifndef UNITY_EXCLUDE_FLOAT +/*-----------------------------------------------*/ UNITY_INTERNAL_PTR UnityFloatToPtr(const float num) { UnityQuickCompare.f = num; @@ -1267,6 +1274,7 @@ UNITY_INTERNAL_PTR UnityFloatToPtr(const float num) #endif #ifndef UNITY_EXCLUDE_DOUBLE +/*-----------------------------------------------*/ UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num) { UnityQuickCompare.d = num; @@ -1278,6 +1286,7 @@ UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num) * Control Functions *-----------------------------------------------*/ +/*-----------------------------------------------*/ void UnityFail(const char* msg, const UNITY_LINE_TYPE line) { RETURN_IF_FAIL_OR_IGNORE; @@ -1402,6 +1411,7 @@ char* UnityOptionIncludeNamed = NULL; char* UnityOptionExcludeNamed = NULL; int UnityVerbosity = 1; +/*-----------------------------------------------*/ int UnityParseOptions(int argc, char** argv) { UnityOptionIncludeNamed = NULL; @@ -1458,6 +1468,7 @@ int UnityParseOptions(int argc, char** argv) return 0; } +/*-----------------------------------------------*/ int IsStringInBiggerString(const char* longstring, const char* shortstring) { const char* lptr = longstring; @@ -1496,9 +1507,11 @@ int IsStringInBiggerString(const char* longstring, const char* shortstring) lptr = lnext; sptr = shortstring; } + return 0; } +/*-----------------------------------------------*/ int UnityStringArgumentMatches(const char* str) { int retval; @@ -1522,24 +1535,33 @@ int UnityStringArgumentMatches(const char* str) if ((ptr2[0] == ':') && (ptr2[1] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')) ptrf = &ptr2[1]; } while ((ptr2[0] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')); + while ((ptr2[0] != 0) && ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ','))) + { ptr2++; + } /* done if complete filename match */ retval = IsStringInBiggerString(Unity.TestFile, ptr1); if (retval == 1) + { return retval; + } /* done if testname match after filename partial match */ if ((retval == 2) && (ptrf != 0)) { if (IsStringInBiggerString(Unity.CurrentTestName, ptrf)) + { return 1; + } } /* done if complete testname match */ if (IsStringInBiggerString(Unity.CurrentTestName, ptr1) == 1) + { return 1; + } ptr1 = ptr2; } @@ -1548,6 +1570,7 @@ int UnityStringArgumentMatches(const char* str) return 0; } +/*-----------------------------------------------*/ int UnityTestMatches(void) { /* Check if this test name matches the included test pattern */ From 50ce8a880af6d27dabab5d3655bbd26a3a16d295 Mon Sep 17 00:00:00 2001 From: Kochise Date: Wed, 31 Oct 2018 11:41:44 +0100 Subject: [PATCH 19/50] Some cleanup --- src/unity.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/src/unity.c b/src/unity.c index 4efc47f..732db55 100644 --- a/src/unity.c +++ b/src/unity.c @@ -214,7 +214,9 @@ void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print) int nibble; char nibbles = nibbles_to_print; if ((unsigned)nibbles > (2 * sizeof(number))) + { nibbles = 2 * sizeof(number); + } while (nibbles > 0) { @@ -277,9 +279,18 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) } /* handle zero, NaN, and +/- infinity */ - if (number == 0.0f) UnityPrint("0"); - else if (isnan(number)) UnityPrint("nan"); - else if (isinf(number)) UnityPrint("inf"); + if (number == 0.0f) + { + UnityPrint("0"); + } + else if (isnan(number)) + { + UnityPrint("nan"); + } + else if (isinf(number)) + { + UnityPrint("inf"); + } else { int exponent = 0; @@ -621,9 +632,15 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UnityPrintPointlessAndBail(); } - if (expected == actual) return; /* Both are NULL or same pointer */ + if (expected == actual) + { + return; /* Both are NULL or same pointer */ + } + if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) + { UNITY_FAIL_AND_BAIL; + } while ((elements > 0) && elements--) { @@ -734,9 +751,15 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected, UnityPrintPointlessAndBail(); } - if (expected == actual) return; /* Both are NULL or same pointer */ + if (expected == actual) + { + return; /* Both are NULL or same pointer */ + } + if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) + { UNITY_FAIL_AND_BAIL; + } while (elements--) { @@ -821,14 +844,18 @@ void UnityAssertFloatSpecial(const UNITY_FLOAT actual, UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); if (!should_be_trait) + { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); UnityPrint(UnityStrWas); #ifndef UNITY_EXCLUDE_FLOAT_PRINT UnityPrintFloat((UNITY_DOUBLE)actual); #else if (should_be_trait) + { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); #endif UnityAddMsgIfSpecified(msg); @@ -865,9 +892,15 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expecte UnityPrintPointlessAndBail(); } - if (expected == actual) return; /* Both are NULL or same pointer */ + if (expected == actual) + { + return; /* Both are NULL or same pointer */ + } + if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) + { UNITY_FAIL_AND_BAIL; + } while (elements--) { @@ -951,14 +984,18 @@ void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual, UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); if (!should_be_trait) + { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); UnityPrint(UnityStrWas); #ifndef UNITY_EXCLUDE_FLOAT_PRINT UnityPrintFloat(actual); #else if (should_be_trait) + { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); #endif UnityAddMsgIfSpecified(msg); @@ -981,16 +1018,24 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta, if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { if (actual > expected) + { Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); + } else + { Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); + } } else { if ((UNITY_UINT)actual > (UNITY_UINT)expected) + { Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); + } else + { Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); + } } if (Unity.CurrentTestFailed) @@ -1186,9 +1231,15 @@ void UnityAssertEqualMemory(UNITY_INTERNAL_PTR expected, UnityPrintPointlessAndBail(); } - if (expected == actual) return; /* Both are NULL or same pointer */ + if (expected == actual) + { + return; /* Both are NULL or same pointer */ + } + if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) + { UNITY_FAIL_AND_BAIL; + } while (elements--) { @@ -1428,9 +1479,13 @@ int UnityParseOptions(int argc, char** argv) case 'n': /* include tests with name including this string */ case 'f': /* an alias for -n */ if (argv[i][2] == '=') + { UnityOptionIncludeNamed = &argv[i][3]; + } else if (++i < argc) + { UnityOptionIncludeNamed = argv[i]; + } else { UnityPrint("ERROR: No Test String to Include Matches For"); @@ -1446,9 +1501,13 @@ int UnityParseOptions(int argc, char** argv) break; case 'x': /* exclude tests with name including this string */ if (argv[i][2] == '=') + { UnityOptionExcludeNamed = &argv[i][3]; + } else if (++i < argc) + { UnityOptionExcludeNamed = argv[i]; + } else { UnityPrint("ERROR: No Test String to Exclude Matches For"); @@ -1476,7 +1535,9 @@ int IsStringInBiggerString(const char* longstring, const char* shortstring) const char* lnext = lptr; if (*sptr == '*') + { return 1; + } while (*lptr) { @@ -1524,7 +1585,9 @@ int UnityStringArgumentMatches(const char* str) while (ptr1[0] != 0) { if ((ptr1[0] == '"') || (ptr1[0] == '\'')) + { ptr1++; + } /* look for the start of the next partial */ ptr2 = ptr1; @@ -1533,7 +1596,9 @@ int UnityStringArgumentMatches(const char* str) { ptr2++; if ((ptr2[0] == ':') && (ptr2[1] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')) + { ptrf = &ptr2[1]; + } } while ((ptr2[0] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')); while ((ptr2[0] != 0) && ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ','))) @@ -1580,14 +1645,19 @@ int UnityTestMatches(void) retval = UnityStringArgumentMatches(UnityOptionIncludeNamed); } else + { retval = 1; + } /* Check if this test name matches the excluded test pattern */ if (UnityOptionExcludeNamed) { if (UnityStringArgumentMatches(UnityOptionExcludeNamed)) + { retval = 0; + } } + return retval; } From 7dd21c333e56098b2e047a6fedd1c7ddfc4a88ab Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Fri, 2 Nov 2018 07:42:47 -0400 Subject: [PATCH 20/50] Fix unintended array overrun in example (#360. Thanks @quantum-leaps) --- examples/example_1/src/ProductionCode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/example_1/src/ProductionCode.c b/examples/example_1/src/ProductionCode.c index d039c3e..db128e5 100644 --- a/examples/example_1/src/ProductionCode.c +++ b/examples/example_1/src/ProductionCode.c @@ -4,14 +4,14 @@ int Counter = 0; int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; /* some obnoxious array to search that is 1-based indexing instead of 0. */ -/* This function is supposed to search through NumbersToFind and find a particular number. - * If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since - * NumbersToFind is indexed from 1. Unfortunately it's broken +/* This function is supposed to search through NumbersToFind and find a particular number. + * If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since + * NumbersToFind is indexed from 1. Unfortunately it's broken * (and should therefore be caught by our tests) */ int FindFunction_WhichIsBroken(int NumberToFind) { int i = 0; - while (i <= 8) /* Notice I should have been in braces */ + while (i < 8) /* Notice I should have been in braces */ i++; if (NumbersToFind[i] == NumberToFind) /* Yikes! I'm getting run after the loop finishes instead of during it! */ return i; From 100c73d37feef84c63530535793c739b30b23c0f Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Tue, 13 Nov 2018 21:07:05 -0500 Subject: [PATCH 21/50] Move license for GitHub detection --- docs/license.txt => LICENSE.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/license.txt => LICENSE.txt (100%) diff --git a/docs/license.txt b/LICENSE.txt similarity index 100% rename from docs/license.txt rename to LICENSE.txt From 6b657c6f17ca45c240dd7ad74e8096dd17ab3ad1 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 28 Nov 2018 13:27:00 -0500 Subject: [PATCH 22/50] Fix (most) Rubocop warnings. --- auto/colour_prompt.rb | 4 +- auto/colour_reporter.rb | 2 +- auto/generate_module.rb | 8 ++-- auto/generate_test_runner.rb | 8 ++-- auto/parse_output.rb | 55 +++++++++++++-------------- auto/stylize_as_junit.rb | 12 ++---- auto/test_file_filter.rb | 4 +- auto/unity_test_summary.rb | 4 -- examples/example_3/rakefile.rb | 11 ++---- examples/example_3/rakefile_helper.rb | 8 ++-- extras/fixture/rakefile.rb | 14 +++---- test/.rubocop.yml | 2 +- test/rakefile | 7 ++-- test/rakefile_helper.rb | 8 ++-- 14 files changed, 64 insertions(+), 83 deletions(-) diff --git a/auto/colour_prompt.rb b/auto/colour_prompt.rb index 0f1dc4e..bf09d02 100644 --- a/auto/colour_prompt.rb +++ b/auto/colour_prompt.rb @@ -24,7 +24,7 @@ class ColourCommandLine return unless RUBY_PLATFORM =~ /(win|w)32$/ get_std_handle = Win32API.new('kernel32', 'GetStdHandle', ['L'], 'L') @set_console_txt_attrb = - Win32API.new('kernel32', 'SetConsoleTextAttribute', %w(L N), 'I') + Win32API.new('kernel32', 'SetConsoleTextAttribute', %w[L N], 'I') @hout = get_std_handle.call(-11) end @@ -107,7 +107,7 @@ class ColourCommandLine $stdout.print("#{change_to(colour)}#{str}\033[0m") if mode == :print end end -end # ColourCommandLine +end def colour_puts(role, str) ColourCommandLine.new.out_c(:puts, role, str) diff --git a/auto/colour_reporter.rb b/auto/colour_reporter.rb index bb1fbfc..1c3bc21 100644 --- a/auto/colour_reporter.rb +++ b/auto/colour_reporter.rb @@ -4,7 +4,7 @@ # [Released under MIT License. Please refer to license.txt for details] # ========================================== -require "#{File.expand_path(File.dirname(__FILE__))}/colour_prompt" +require_relative 'colour_prompt' $colour_output = true diff --git a/auto/generate_module.rb b/auto/generate_module.rb index 13b4cc7..fb8c7ac 100644 --- a/auto/generate_module.rb +++ b/auto/generate_module.rb @@ -45,8 +45,6 @@ TEMPLATE_INC ||= '#ifndef _%3$s_H class UnityModuleGenerator ############################ def initialize(options = nil) - here = File.expand_path(File.dirname(__FILE__)) + '/' - @options = UnityModuleGenerator.default_options case options when NilClass then @options @@ -56,9 +54,9 @@ class UnityModuleGenerator end # Create default file paths if none were provided - @options[:path_src] = here + '../src/' if @options[:path_src].nil? - @options[:path_inc] = @options[:path_src] if @options[:path_inc].nil? - @options[:path_tst] = here + '../test/' if @options[:path_tst].nil? + @options[:path_src] = "#{__dir__}/../src/" if @options[:path_src].nil? + @options[:path_inc] = @options[:path_src] if @options[:path_inc].nil? + @options[:path_tst] = "#{__dir__}/../test/" if @options[:path_tst].nil? @options[:path_src] += '/' unless @options[:path_src][-1] == 47 @options[:path_inc] += '/' unless @options[:path_inc][-1] == 47 @options[:path_tst] += '/' unless @options[:path_tst][-1] == 47 diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 2f14966..377db6f 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -4,8 +4,6 @@ # [Released under MIT License. Please refer to license.txt for details] # ========================================== -File.expand_path(File.join(File.dirname(__FILE__), 'colour_prompt')) - class UnityTestRunnerGenerator def initialize(options = nil) @options = UnityTestRunnerGenerator.default_options @@ -15,7 +13,7 @@ class UnityTestRunnerGenerator when Hash then @options.merge!(options) else raise 'If you specify arguments, it should be a filename or a hash of options' end - require "#{File.expand_path(File.dirname(__FILE__))}/type_sanitizer" + require_relative 'type_sanitizer' end def self.default_options @@ -165,7 +163,7 @@ class UnityTestRunnerGenerator output.puts('#include "cmock.h"') unless mocks.empty? output.puts('#ifndef UNITY_EXCLUDE_SETJMP_H') output.puts('#include ') - output.puts("#endif") + output.puts('#endif') output.puts('#include ') if @options[:defines] && !@options[:defines].empty? @options[:defines].each { |d| output.puts("#define #{d}") } @@ -379,7 +377,7 @@ class UnityTestRunnerGenerator end output.puts output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty? - output.puts(" return suite_teardown(UnityEnd());") + output.puts(' return suite_teardown(UnityEnd());') output.puts('}') end diff --git a/auto/parse_output.rb b/auto/parse_output.rb index f04508f..fa07b7d 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -210,7 +210,7 @@ class ParseOutput # Adjusts the os specific members according to the current path style # (Windows or Unix based) - def set_os_specifics(line) + def detect_os_specifics(line) if line.include? '\\' # Windows X:\Y\Z @class_name_idx = 1 @@ -254,43 +254,42 @@ class ParseOutput # TEST() PASS # # Note: Where path is different on Unix vs Windows devices (Windows leads with a drive letter)! - set_os_specifics(line) + detect_os_specifics(line) line_array = line.split(':') # If we were able to split the line then we can look to see if any of our target words # were found. Case is important. - if (line_array.size >= 4) || (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') + next unless (line_array.size >= 4) || (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') - # check if the output is fixture output (with verbose flag "-v") - if (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') - line_array = prepare_fixture_line(line) - if line.include? ' PASS' - test_passed_unity_fixture(line_array) - @test_passed += 1 - elsif line.include? 'FAIL' - test_failed_unity_fixture(line_array) - @test_failed += 1 - elsif line.include? 'IGNORE' - test_ignored_unity_fixture(line_array) - @test_ignored += 1 - end - # normal output / fixture output (without verbose "-v") - elsif line.include? ':PASS' - test_passed(line_array) + # check if the output is fixture output (with verbose flag "-v") + if (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') + line_array = prepare_fixture_line(line) + if line.include? ' PASS' + test_passed_unity_fixture(line_array) @test_passed += 1 - elsif line.include? ':FAIL' - test_failed(line_array) + elsif line.include? 'FAIL' + test_failed_unity_fixture(line_array) @test_failed += 1 - elsif line.include? ':IGNORE:' - test_ignored(line_array) - @test_ignored += 1 - elsif line.include? ':IGNORE' - line_array.push('No reason given') - test_ignored(line_array) + elsif line.include? 'IGNORE' + test_ignored_unity_fixture(line_array) @test_ignored += 1 end - @total_tests = @test_passed + @test_failed + @test_ignored + # normal output / fixture output (without verbose "-v") + elsif line.include? ':PASS' + test_passed(line_array) + @test_passed += 1 + elsif line.include? ':FAIL' + test_failed(line_array) + @test_failed += 1 + elsif line.include? ':IGNORE:' + test_ignored(line_array) + @test_ignored += 1 + elsif line.include? ':IGNORE' + line_array.push('No reason given') + test_ignored(line_array) + @test_ignored += 1 end + @total_tests = @test_passed + @test_failed + @test_ignored end puts '' puts '=================== SUMMARY =====================' diff --git a/auto/stylize_as_junit.rb b/auto/stylize_as_junit.rb index b3d8f40..a53f85f 100755 --- a/auto/stylize_as_junit.rb +++ b/auto/stylize_as_junit.rb @@ -61,8 +61,8 @@ class ArgvParser opts.parse!(args) options - end # parse() -end # class OptparseExample + end +end class UnityToJUnit include FileUtils::Verbose @@ -155,10 +155,6 @@ class UnityToJUnit [Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i] end - def here - File.expand_path(File.dirname(__FILE__)) - end - private def results_structure @@ -221,9 +217,9 @@ class UnityToJUnit def write_suites_footer(stream) stream.puts '' end -end # UnityToJUnit +end -if __FILE__ == $0 +if $0 == __FILE__ # parse out the command options options = ArgvParser.parse(ARGV) diff --git a/auto/test_file_filter.rb b/auto/test_file_filter.rb index aad28e3..5c3a79f 100644 --- a/auto/test_file_filter.rb +++ b/auto/test_file_filter.rb @@ -11,8 +11,8 @@ module RakefileHelpers def initialize(all_files = false) @all_files = all_files - return false unless @all_files - return false unless File.exist?('test_file_filter.yml') + return unless @all_files + return unless File.exist?('test_file_filter.yml') filters = YAML.load_file('test_file_filter.yml') @all_files = filters[:all_files] diff --git a/auto/unity_test_summary.rb b/auto/unity_test_summary.rb index b37dc5f..810fdbd 100644 --- a/auto/unity_test_summary.rb +++ b/auto/unity_test_summary.rb @@ -101,10 +101,6 @@ class UnityTestSummary raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ } [Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i] end - - def here - File.expand_path(File.dirname(__FILE__)) - end end if $0 == __FILE__ diff --git a/examples/example_3/rakefile.rb b/examples/example_3/rakefile.rb index bf9f42b..d014929 100644 --- a/examples/example_3/rakefile.rb +++ b/examples/example_3/rakefile.rb @@ -1,12 +1,9 @@ -HERE = File.expand_path(File.dirname(__FILE__)) + '/' -UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/../..' - require 'rake' require 'rake/clean' -require HERE + 'rakefile_helper' +require_relative 'rakefile_helper' TEMP_DIRS = [ - File.join(HERE, 'build') + File.join(__dir__, 'build') ].freeze TEMP_DIRS.each do |dir| @@ -32,8 +29,8 @@ task :summary do end desc 'Build and test Unity' -task all: %i(clean unit summary) -task default: %i(clobber all) +task all: %i[clean unit summary] +task default: %i[clobber all] task ci: [:default] task cruise: [:default] diff --git a/examples/example_3/rakefile_helper.rb b/examples/example_3/rakefile_helper.rb index a186cf0..f1f51d4 100644 --- a/examples/example_3/rakefile_helper.rb +++ b/examples/example_3/rakefile_helper.rb @@ -1,8 +1,8 @@ require 'yaml' require 'fileutils' -require UNITY_ROOT + '/auto/unity_test_summary' -require UNITY_ROOT + '/auto/generate_test_runner' -require UNITY_ROOT + '/auto/colour_reporter' +require_relative '../../auto/unity_test_summary' +require_relative '../../auto/generate_test_runner' +require_relative '../../auto/colour_reporter' module RakefileHelpers C_EXTENSION = '.c'.freeze @@ -149,7 +149,7 @@ module RakefileHelpers def report_summary summary = UnityTestSummary.new - summary.root = HERE + summary.root = __dir__ results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob.tr!('\\', '/') results = Dir[results_glob] diff --git a/extras/fixture/rakefile.rb b/extras/fixture/rakefile.rb index 7603e57..8b5319c 100644 --- a/extras/fixture/rakefile.rb +++ b/extras/fixture/rakefile.rb @@ -4,15 +4,13 @@ # [Released under MIT License. Please refer to license.txt for details] # ========================================== -HERE = File.expand_path(File.dirname(__FILE__)) + '/' - require 'rake' require 'rake/clean' require 'rake/testtask' -require HERE + 'rakefile_helper' +require_relative 'rakefile_helper' TEMP_DIRS = [ - File.join(HERE, 'build') + File.join(__dir__, 'build') ].freeze TEMP_DIRS.each do |dir| @@ -33,10 +31,10 @@ task unit: [:prepare_for_tests] do end desc 'Build and test Unity Framework' -task all: %i(clean unit) -task default: %i(clobber all) -task ci: %i(no_color default) -task cruise: %i(no_color default) +task all: %i[clean unit] +task default: %i[clobber all] +task ci: %i[no_color default] +task cruise: %i[no_color default] desc 'Load configuration' task :config, :config_file do |_t, args| diff --git a/test/.rubocop.yml b/test/.rubocop.yml index c074ca9..3bfe31a 100644 --- a/test/.rubocop.yml +++ b/test/.rubocop.yml @@ -18,7 +18,7 @@ Style/HashSyntax: EnforcedStyle: no_mixed_keys # This is disabled because it seems to get confused over nested hashes -Style/AlignHash: +Layout/AlignHash: Enabled: false EnforcedHashRocketStyle: table EnforcedColonStyle: table diff --git a/test/rakefile b/test/rakefile index 4a2f3d2..770fead 100644 --- a/test/rakefile +++ b/test/rakefile @@ -4,17 +4,16 @@ # [Released under MIT License. Please refer to license.txt for details] # ========================================== -UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/' $verbose = false require 'rake' require 'rake/clean' -require UNITY_ROOT + 'rakefile_helper' +require_relative 'rakefile_helper' require 'rspec/core/rake_task' TEMP_DIRS = [ - File.join(UNITY_ROOT, 'build'), - File.join(UNITY_ROOT, 'sandbox') + File.join(__dir__, 'build'), + File.join(__dir__, 'sandbox') ] TEMP_DIRS.each do |dir| diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index 1fd60c5..d4335ec 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -6,9 +6,9 @@ require 'yaml' require 'fileutils' -require UNITY_ROOT + '../auto/unity_test_summary' -require UNITY_ROOT + '../auto/generate_test_runner' -require UNITY_ROOT + '../auto/colour_reporter' +require_relative '../auto/unity_test_summary' +require_relative '../auto/generate_test_runner' +require_relative '../auto/colour_reporter' module RakefileHelpers C_EXTENSION = '.c'.freeze @@ -179,7 +179,7 @@ module RakefileHelpers def report_summary summary = UnityTestSummary.new - summary.root = UNITY_ROOT + summary.root = __dir__ results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob.tr!('\\', '/') results = Dir[results_glob] From 5cd1c33b0e99bfaa1c1c1a2c950854286e6c5eb3 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 28 Nov 2018 13:36:27 -0500 Subject: [PATCH 23/50] Fix uninitialized constant --- extras/fixture/rakefile_helper.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extras/fixture/rakefile_helper.rb b/extras/fixture/rakefile_helper.rb index c45b239..71e752b 100644 --- a/extras/fixture/rakefile_helper.rb +++ b/extras/fixture/rakefile_helper.rb @@ -6,9 +6,9 @@ require 'yaml' require 'fileutils' -require HERE + '../../auto/unity_test_summary' -require HERE + '../../auto/generate_test_runner' -require HERE + '../../auto/colour_reporter' +require_relative '../../auto/unity_test_summary' +require_relative '../../auto/generate_test_runner' +require_relative '../../auto/colour_reporter' module RakefileHelpers C_EXTENSION = '.c'.freeze @@ -16,7 +16,7 @@ module RakefileHelpers def load_configuration(config_file) return if $configured - $cfg_file = HERE + "../../test/targets/#{config_file}" unless config_file =~ /[\\|\/]/ + $cfg_file = "#{__dir__}/../../test/targets/#{config_file}" unless config_file =~ /[\\|\/]/ $cfg = YAML.load(File.read($cfg_file)) $colour_output = false unless $cfg['colour'] $configured = true if config_file != DEFAULT_CONFIG_FILE @@ -128,7 +128,7 @@ module RakefileHelpers def report_summary summary = UnityTestSummary.new - summary.root = HERE + summary.root = __dir__ results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob.tr!('\\', '/') results = Dir[results_glob] @@ -145,9 +145,9 @@ module RakefileHelpers $cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil? # Get a list of all source files needed - src_files = Dir[HERE + 'src/*.c'] - src_files += Dir[HERE + 'test/*.c'] - src_files += Dir[HERE + 'test/main/*.c'] + src_files = Dir["#{__dir__}/src/*.c"] + src_files += Dir["#{__dir__}/test/*.c"] + src_files += Dir["#{__dir__}/test/main/*.c"] src_files << '../../src/unity.c' # Build object files From 8a77f48634a055a11edf1583babd1b7a86e7d3a6 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 28 Nov 2018 14:40:40 -0500 Subject: [PATCH 24/50] Fix undefined behavior when printing INT_MIN/INT64_MIN. Negating the most-negative signed integer results in overflow, which is undefined behavior. Fix this by casting to an unsigned type first (unsigned overflow is well-defined as it uses modular arithmetic). --- src/unity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index d1dda41..00c9412 100644 --- a/src/unity.c +++ b/src/unity.c @@ -183,7 +183,7 @@ void UnityPrintNumber(const UNITY_INT number_to_print) { /* A negative number, including MIN negative */ UNITY_OUTPUT_CHAR('-'); - number = (UNITY_UINT)(-number_to_print); + number = -number; } UnityPrintNumberUnsigned(number); } From d09f4953ffd67bcaf774d3f0e6476a9ec33265f4 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 28 Nov 2018 15:17:25 -0500 Subject: [PATCH 25/50] Fix another signed integer overflow. --- src/unity.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unity.c b/src/unity.c index 00c9412..70c6b26 100644 --- a/src/unity.c +++ b/src/unity.c @@ -1019,22 +1019,22 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta, { if (actual > expected) { - Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); + Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta); } else { - Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); + Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta); } } else { if ((UNITY_UINT)actual > (UNITY_UINT)expected) { - Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); + Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta); } else { - Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); + Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta); } } From 5db2a3dbd9b72070c236eda6549520a38ca0ada1 Mon Sep 17 00:00:00 2001 From: Elliot Gawthrop Date: Sun, 9 Dec 2018 21:21:46 +0000 Subject: [PATCH 26/50] Add support for strings in TEST_CASE() --- auto/generate_test_runner.rb | 15 ++++++++- test/tests/testparameterized.c | 61 ++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 377db6f..9f64b44 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -90,12 +90,25 @@ class UnityTestRunnerGenerator def find_tests(source) tests_and_line_numbers = [] + # contains characters which will be substituted from within strings, doing + # this prevents these characters from interferring with scrubbers + # @ is not a valid C character, so there should be no clashes with files genuinely containing these markers + substring_subs = { '{' => '@co@', '}' => '@cc@', ';' => '@ss@', '/' => '@fs@' } + substring_re = Regexp.union(substring_subs.keys) + substring_unsubs = substring_subs.invert # the inverse map will be used to fix the strings afterwords + substring_unsubs['@quote@'] = '\\"' + substring_unsubs['@apos@'] = '\\\'' + substring_unre = Regexp.union(substring_unsubs.keys) source_scrubbed = source.clone - source_scrubbed = source_scrubbed.gsub(/"[^"\n]*"/, '') # remove things in strings + source_scrubbed = source_scrubbed.gsub(/\\"/, '@quote@') # hide escaped quotes to allow capture of the full string/char + source_scrubbed = source_scrubbed.gsub(/\\'/, '@apos@') # hide escaped apostrophes to allow capture of the full string/char + source_scrubbed = source_scrubbed.gsub(/("[^"\n]*")|('[^'\n]*')/) { |s| s.gsub(substring_re, substring_subs) } # temporarily hide problematic + # characters within strings source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line | (;|\{|\}) /x) # Match ;, {, and } as end of lines + .map { |line| line.gsub(substring_unre, substring_unsubs) } # unhide the problematic characters previously removed lines.each_with_index do |line, _index| # find tests diff --git a/test/tests/testparameterized.c b/test/tests/testparameterized.c index 136cd2f..6100834 100644 --- a/test/tests/testparameterized.c +++ b/test/tests/testparameterized.c @@ -46,6 +46,14 @@ void flushSpy(void) {} int SetToOneToFailInTearDown; int SetToOneMeanWeAlreadyCheckedThisGuy; +static unsigned NextExpectedStringIndex; +static unsigned NextExpectedCharIndex; + +void suiteSetUp(void) +{ + NextExpectedStringIndex = 0; + NextExpectedCharIndex = 0; +} void setUp(void) { @@ -111,3 +119,56 @@ void test_NormalFailsStillWork(void) TEST_ASSERT_TRUE(0); VERIFY_FAILS_END } + +TEST_CASE(0, "abc") +TEST_CASE(1, "{") +TEST_CASE(2, "}") +TEST_CASE(3, ";") +TEST_CASE(4, "\"quoted\"") +void test_StringsArePreserved(unsigned index, const char * str) +{ + static const char * const expected[] = + { + "abc", + "{", + "}", + ";", + "\"quoted\"" + }; + + /* Ensure that no test cases are skipped by tracking the next expected index */ + TEST_ASSERT_EQUAL_UINT32(NextExpectedStringIndex, index); + TEST_ASSERT_LESS_THAN(sizeof(expected) / sizeof(expected[0]), index); + TEST_ASSERT_EQUAL_STRING(expected[index], str); + + NextExpectedStringIndex++; +} + +TEST_CASE(0, 'x') +TEST_CASE(1, '{') +TEST_CASE(2, '}') +TEST_CASE(3, ';') +TEST_CASE(4, '\'') +TEST_CASE(5, '"') +void test_CharsArePreserved(unsigned index, char c) +{ + static const char expected[] = + { + 'x', + '{', + '}', + ';', + '\'', + '"' + }; + + /* Ensure that no test cases are skipped by tracking the next expected index */ + TEST_ASSERT_EQUAL_UINT32(NextExpectedCharIndex, index); + TEST_ASSERT_LESS_THAN(sizeof(expected) / sizeof(expected[0]), index); + TEST_ASSERT_EQUAL(expected[index], c); + + NextExpectedCharIndex++; +} + + + From 516f7be04526b4573e0a5bc37fad2917e9e189aa Mon Sep 17 00:00:00 2001 From: Dom Postorivo Date: Wed, 13 Jun 2018 23:44:58 -0400 Subject: [PATCH 27/50] generate runner defines with #ifndef guards --- auto/generate_test_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 9f64b44..2acda0f 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -179,7 +179,7 @@ class UnityTestRunnerGenerator output.puts('#endif') output.puts('#include ') if @options[:defines] && !@options[:defines].empty? - @options[:defines].each { |d| output.puts("#define #{d}") } + @options[:defines].each { |d| output.puts("#ifndef #{d}\n#define #{d}\n#endif /* #{d} */") } end if @options[:header_file] && !@options[:header_file].empty? output.puts("#include \"#{File.basename(@options[:header_file])}\"") From 95ccc6edc11814052552c4d306d3e3adb10ece89 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Thu, 24 Jan 2019 18:42:51 +0100 Subject: [PATCH 28/50] Changed the compiler switch behaviour for printf (default: disabled). Macro UNITY_EXCLUDE_PRINT_FORMATTED changed to UNITY_INCLUDE_PRINT_FORMATTED. Enable printf via "-DUNITY_INCLUDE_PRINT_FORMATTED" compiler option. --- src/unity.c | 6 +++--- src/unity_internals.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/unity.c b/src/unity.c index fa1847b..9874108 100644 --- a/src/unity.c +++ b/src/unity.c @@ -141,8 +141,8 @@ void UnityPrint(const char* string) } /*-----------------------------------------------*/ -#ifndef UNITY_EXCLUDE_PRINT_FORMATTED -void UnityPrintFormatted(const char* format, ... ) +#ifdef UNITY_INCLUDE_PRINT_FORMATTED +void UnityPrintFormatted(const char* format, ...) { const char* pch = format; va_list va; @@ -251,7 +251,7 @@ void UnityPrintFormatted(const char* format, ... ) va_end(va); } -#endif /* ! UNITY_EXCLUDE_PRINT_FORMATTED */ +#endif /* ! UNITY_INCLUDE_PRINT_FORMATTED */ /*-----------------------------------------------*/ void UnityPrintLen(const char* string, const UNITY_UINT32 length) diff --git a/src/unity_internals.h b/src/unity_internals.h index 2a30682..e91d9bc 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -23,7 +23,7 @@ #include #endif -#ifndef UNITY_EXCLUDE_PRINT_FORMATTED +#ifdef UNITY_INCLUDE_PRINT_FORMATTED #include #endif @@ -496,8 +496,8 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int void UnityPrint(const char* string); -#ifndef UNITY_EXCLUDE_PRINT_FORMATTED -void UnityPrintFormatted(const char* format, ... ); +#ifdef UNITY_INCLUDE_PRINT_FORMATTED +void UnityPrintFormatted(const char* format, ...); #endif void UnityPrintLen(const char* string, const UNITY_UINT32 length); From 4f8656f65845bfc2d6aa2e9561cb2c77e767161e Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Thu, 24 Jan 2019 19:21:08 +0100 Subject: [PATCH 29/50] Added some documentation for the helper function. --- src/unity.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/unity.c b/src/unity.c index 9874108..5cb0365 100644 --- a/src/unity.c +++ b/src/unity.c @@ -98,6 +98,7 @@ static void UnityPrintChar(const char* pch) } /*-----------------------------------------------*/ +/* Local helper function to print ANSI escape strings e.g. "\033[42m". */ #ifdef UNITY_OUTPUT_COLOR static UNITY_UINT UnityPrintAnsiEscapeString(const char* string) { @@ -209,7 +210,8 @@ void UnityPrintFormatted(const char* format, ...) break; } case 's': - { const char * string = va_arg(va, const char *); + { + const char * string = va_arg(va, const char *); UnityPrint(string); break; } @@ -220,7 +222,7 @@ void UnityPrintFormatted(const char* format, ...) } default: { - /* print the unknown character */ + /* print the unknown format character */ UNITY_OUTPUT_CHAR('%'); UnityPrintChar(pch); break; From 92a345b2644d9f0838b7c252f7e4f9cc12a9c958 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Thu, 24 Jan 2019 20:12:16 +0100 Subject: [PATCH 30/50] Added documentation and changed all the code examples to backtick (code) blocks. --- docs/UnityConfigurationGuide.md | 179 ++++++++++++++++++++++---------- 1 file changed, 127 insertions(+), 52 deletions(-) diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index b88eeee..1275ca7 100644 --- a/docs/UnityConfigurationGuide.md +++ b/docs/UnityConfigurationGuide.md @@ -66,7 +66,9 @@ That way, Unity will know to skip the inclusion of this file and you won't be left with a compiler error. _Example:_ - #define UNITY_EXCLUDE_STDINT_H +```C +#define UNITY_EXCLUDE_STDINT_H +``` ##### `UNITY_EXCLUDE_LIMITS_H` @@ -76,8 +78,9 @@ that don't support `stdint.h` could include `limits.h` instead. If you don't want Unity to check this file either, define this to make it skip the inclusion. _Example:_ - #define UNITY_EXCLUDE_LIMITS_H - +```C +#define UNITY_EXCLUDE_LIMITS_H +``` If you've disabled both of the automatic options above, you're going to have to do the configuration yourself. Don't worry. Even this isn't too bad... there are @@ -91,7 +94,9 @@ Define this to be the number of bits an `int` takes up on your system. The default, if not autodetected, is 32 bits. _Example:_ - #define UNITY_INT_WIDTH 16 +```C +#define UNITY_INT_WIDTH 16 +``` ##### `UNITY_LONG_WIDTH` @@ -103,7 +108,9 @@ of 64-bit support your system can handle. Does it need to specify a `long` or a ignored. _Example:_ - #define UNITY_LONG_WIDTH 16 +```C +#define UNITY_LONG_WIDTH 16 +``` ##### `UNITY_POINTER_WIDTH` @@ -113,7 +120,9 @@ default, if not autodetected, is 32-bits. If you're getting ugly compiler warnings about casting from pointers, this is the one to look at. _Example:_ - #define UNITY_POINTER_WIDTH 64 +```C +#define UNITY_POINTER_WIDTH 64 +``` ##### `UNITY_SUPPORT_64` @@ -125,7 +134,9 @@ can be a significant size and speed impact to enabling 64-bit support on small targets, so don't define it if you don't need it. _Example:_ - #define UNITY_SUPPORT_64 +```C +#define UNITY_SUPPORT_64 +``` ### Floating Point Types @@ -153,10 +164,11 @@ suits your needs. For features that are enabled, the following floating point options also become available. _Example:_ - - //what manner of strange processor is this? - #define UNITY_EXCLUDE_FLOAT - #define UNITY_INCLUDE_DOUBLE +```C +//what manner of strange processor is this? +#define UNITY_EXCLUDE_FLOAT +#define UNITY_INCLUDE_DOUBLE +``` ##### `UNITY_EXCLUDE_FLOAT_PRINT` @@ -172,7 +184,9 @@ can use this define to instead respond to a failed assertion with a message like point assertions, use these options to give more explicit failure messages. _Example:_ - #define UNITY_EXCLUDE_FLOAT_PRINT +```C +#define UNITY_EXCLUDE_FLOAT_PRINT +``` ##### `UNITY_FLOAT_TYPE` @@ -182,7 +196,9 @@ floats. If your compiler supports a specialty floating point type, you can always override this behavior by using this definition. _Example:_ - #define UNITY_FLOAT_TYPE float16_t +```C +#define UNITY_FLOAT_TYPE float16_t +``` ##### `UNITY_DOUBLE_TYPE` @@ -194,7 +210,9 @@ could enable gargantuan floating point types on your 64-bit processor instead of the standard `double`. _Example:_ - #define UNITY_DOUBLE_TYPE long double +```C +#define UNITY_DOUBLE_TYPE long double +``` ##### `UNITY_FLOAT_PRECISION` @@ -213,7 +231,10 @@ For further details on how this works, see the appendix of the Unity Assertion Guide. _Example:_ - #define UNITY_FLOAT_PRECISION 0.001f +```C +#define UNITY_FLOAT_PRECISION 0.001f +``` + ### Miscellaneous @@ -225,7 +246,47 @@ your own macro for this, you should exclude the `stddef.h` header file by adding define to your configuration. _Example:_ - #define UNITY_EXCLUDE_STDDEF_H +```C +#define UNITY_EXCLUDE_STDDEF_H +``` + + +#### `UNITY_INCLUDE_PRINT_FORMATTED` + +Unity provides a simple (and very basic) printf-like string output implementation, +which is able to print a string modified by the following format string modifiers: + +- __%d__ - signed value (decimal) +- __%i__ - same as __%i__ +- __%u__ - unsigned value (decimal) +- __%f__ - float/Double (if float support is activated) +- __%g__ - same as __%f__ +- __%b__ - binary prefixed with "0b" +- __%x__ - hexadecimal (upper case) prefixed with "0x" +- __%X__ - same as __%x__ +- __%p__ - pointer (same as __%x__ or __%X__) +- __%c__ - a single character +- __%s__ - a string (e.g. "string") +- __%%__ - The "%" symbol (escaped) + +_Example:_ +```C +#define UNITY_INCLUDE_PRINT_FORMATTED + +int a = 0xfab1; +UnityPrintFormatted("Decimal %d\n", -7); +UnityPrintFormatted("Unsigned %u\n", 987); +UnityPrintFormatted("Float %f\n", 3.1415926535897932384); +UnityPrintFormatted("Binary %b\n", 0xA); +UnityPrintFormatted("Hex %X\n", 0xFAB); +UnityPrintFormatted("Pointer %p\n", &a); +UnityPrintFormatted("Character %c\n", 'F'); +UnityPrintFormatted("String %s\n", "My string"); +UnityPrintFormatted("Percent %%\n"); +UnityPrintFormatted("Color Red \033[41mFAIL\033[00m\n"); +UnityPrintFormatted("\n"); +UnityPrintFormatted("Multiple (%d) (%i) (%u) (%x)\n", -100, 0, 200, 0x12345); +``` ### Toolset Customization @@ -260,12 +321,14 @@ _Example:_ Say you are forced to run your test suite on an embedded processor with no `stdout` option. You decide to route your test result output to a custom serial `RS232_putc()` function you wrote like thus: - #include "RS232_header.h" - ... - #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) - #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) - #define UNITY_OUTPUT_FLUSH() RS232_flush() - #define UNITY_OUTPUT_COMPLETE() RS232_close() +```C +#include "RS232_header.h" +... +#define UNITY_OUTPUT_CHAR(a) RS232_putc(a) +#define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) +#define UNITY_OUTPUT_FLUSH() RS232_flush() +#define UNITY_OUTPUT_COMPLETE() RS232_close() +``` _Note:_ `UNITY_OUTPUT_FLUSH()` can be set to the standard out flush function simply by @@ -294,10 +357,12 @@ empty). You can also force Unity to NOT use weak functions by defining UNITY_NO_WEAK. The most common options for this feature are: _Example:_ - #define UNITY_WEAK_ATTRIBUTE weak - #define UNITY_WEAK_ATTRIBUTE __attribute__((weak)) - #define UNITY_WEAK_PRAGMA - #define UNITY_NO_WEAK +```C +#define UNITY_WEAK_ATTRIBUTE weak +#define UNITY_WEAK_ATTRIBUTE __attribute__((weak)) +#define UNITY_WEAK_PRAGMA +#define UNITY_NO_WEAK +``` ##### `UNITY_PTR_ATTRIBUTE` @@ -307,9 +372,10 @@ Some compilers require a custom attribute to be assigned to pointers, like defining this option with the attribute you would like. _Example:_ - #define UNITY_PTR_ATTRIBUTE __attribute__((far)) - #define UNITY_PTR_ATTRIBUTE near - +```C +#define UNITY_PTR_ATTRIBUTE __attribute__((far)) +#define UNITY_PTR_ATTRIBUTE near +``` ##### `UNITY_PRINT_EOL` @@ -318,8 +384,9 @@ to parse by the scripts, by Ceedling, etc, but it might not be ideal for YOUR system. Feel free to override this and to make it whatever you wish. _Example:_ - #define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\r'); UNITY_OUTPUT_CHAR('\n') } - +```C +#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\r'); UNITY_OUTPUT_CHAR('\n') } +``` ##### `UNITY_EXCLUDE_DETAILS` @@ -331,8 +398,9 @@ report which function or argument flagged an error. If you're not using CMock an you're not using these details for other things, then you can exclude them. _Example:_ - #define UNITY_EXCLUDE_DETAILS - +```C +#define UNITY_EXCLUDE_DETAILS +``` ##### `UNITY_EXCLUDE_SETJMP` @@ -345,15 +413,18 @@ compiler doesn't support setjmp, you wouldn't have had the memory space for thos things anyway, though... so this option exists for those situations. _Example:_ - #define UNITY_EXCLUDE_SETJMP +```C +#define UNITY_EXCLUDE_SETJMP +``` ##### `UNITY_OUTPUT_COLOR` If you want to add color using ANSI escape codes you can use this define. t _Example:_ - #define UNITY_OUTPUT_COLOR - +```C +#define UNITY_OUTPUT_COLOR +``` ## Getting Into The Guts @@ -380,13 +451,15 @@ output of your test results. A simple main function looks something like this: - int main(void) { - UNITY_BEGIN(); - RUN_TEST(test_TheFirst); - RUN_TEST(test_TheSecond); - RUN_TEST(test_TheThird); - return UNITY_END(); - } +```C +int main(void) { + UNITY_BEGIN(); + RUN_TEST(test_TheFirst); + RUN_TEST(test_TheSecond); + RUN_TEST(test_TheThird); + return UNITY_END(); +} +``` You can see that our main function doesn't bother taking any arguments. For our most barebones case, we'll never have arguments because we just run all the @@ -409,15 +482,17 @@ case function. This includes catching failures, calling the test module's using CMock or test coverage, there will be additional stubs in use here. A simple minimalist RUN_TEST macro looks something like this: - #define RUN_TEST(testfunc) \ - UNITY_NEW_TEST(#testfunc) \ - if (TEST_PROTECT()) { \ - setUp(); \ - testfunc(); \ - } \ - if (TEST_PROTECT() && (!TEST_IS_IGNORED)) \ - tearDown(); \ - UnityConcludeTest(); +```C +#define RUN_TEST(testfunc) \ + UNITY_NEW_TEST(#testfunc) \ + if (TEST_PROTECT()) { \ + setUp(); \ + testfunc(); \ + } \ + if (TEST_PROTECT() && (!TEST_IS_IGNORED)) \ + tearDown(); \ + UnityConcludeTest(); +``` So that's quite a macro, huh? It gives you a glimpse of what kind of stuff Unity has to deal with for every single test case. For each test case, we declare that From 5074a3d8b29978636c4f88670da7b64a44f37546 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Thu, 24 Jan 2019 21:44:34 +0000 Subject: [PATCH 31/50] Make unity.c compatible with c90 Avoid declaring the loop variable inside the for statement to keep compatibility with c90: unity.c:1408: error: for' loop initial declaration used outside C99 mode --- src/unity.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 38e7d68..be8dbc8 100644 --- a/src/unity.c +++ b/src/unity.c @@ -1523,8 +1523,9 @@ int UnityParseOptions(int argc, char** argv) { UnityOptionIncludeNamed = NULL; UnityOptionExcludeNamed = NULL; + int i; - for (int i = 1; i < argc; i++) + for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { From a6e9f85f71a621ffa94d6277dcc13cc318c73c3d Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Fri, 25 Jan 2019 07:00:32 +0100 Subject: [PATCH 32/50] Added examples for the configuration of UnityPrintFormatted and exclusion of --- examples/unity_config.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/examples/unity_config.h b/examples/unity_config.h index d586448..bc66e7f 100644 --- a/examples/unity_config.h +++ b/examples/unity_config.h @@ -176,6 +176,22 @@ /* #define UNITY_DOUBLE_PRECISION 0.001f */ +/* *************************** MISCELLANEOUS *********************************** + * Miscellaneous configuration options for Unity + **************************************************************************** */ + +/* Unity uses the stddef.h header included in the C standard library for the + * "NULL" macro. Define this in order to disable the include of stddef.h. If you + * do this, you have to make sure to provide your own "NULL" definition. + */ +/* #define UNITY_EXCLUDE_STDDEF_H */ + +/* Define this to enable the unity formatted print function: + * "UnityPrintFormatted" + */ +/* #define UNITY_INCLUDE_PRINT_FORMATTED */ + + /* *************************** TOOLSET CUSTOMIZATION *************************** * In addition to the options listed above, there are a number of other options * which will come in handy to customize Unity's behavior for your specific From 9d1ffe26d60f19b1ef1bc895996b2cb72ae7caea Mon Sep 17 00:00:00 2001 From: teaguecl Date: Fri, 25 Jan 2019 21:22:55 -0800 Subject: [PATCH 33/50] Fix error in example_1 This test case had an error: test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode It was supposed to be a list of values that are NOT in the list, and none of them should be found. It incorrectly included '1' which is a value in the list. The compile option -Wno-misleading-indentation was also added to remove a compiler warning produced by gcc 7.3.0 --- examples/example_1/makefile | 1 + examples/example_1/test/TestProductionCode.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/example_1/makefile b/examples/example_1/makefile index cca79b4..ee0cf73 100644 --- a/examples/example_1/makefile +++ b/examples/example_1/makefile @@ -41,6 +41,7 @@ CFLAGS += -Wno-unknown-pragmas CFLAGS += -Wstrict-prototypes CFLAGS += -Wundef CFLAGS += -Wold-style-definition +CFLAGS += -Wno-misleading-indentation TARGET_BASE1=test1 TARGET_BASE2=test2 diff --git a/examples/example_1/test/TestProductionCode.c b/examples/example_1/test/TestProductionCode.c index 8060886..404c371 100644 --- a/examples/example_1/test/TestProductionCode.c +++ b/examples/example_1/test/TestProductionCode.c @@ -5,7 +5,7 @@ /* sometimes you may want to get at local data in a module. * for example: If you plan to pass by reference, this could be useful * however, it should often be avoided */ -extern int Counter; +extern int Counter; void setUp(void) { @@ -21,7 +21,7 @@ void test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWork { /* All of these should pass */ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(78)); - TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(1)); + TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(2)); TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(33)); TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(999)); TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(-1)); @@ -31,9 +31,9 @@ void test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWil { /* You should see this line fail in your test summary */ TEST_ASSERT_EQUAL(1, FindFunction_WhichIsBroken(34)); - - /* Notice the rest of these didn't get a chance to run because the line above failed. - * Unit tests abort each test function on the first sign of trouble. + + /* Notice the rest of these didn't get a chance to run because the line above failed. + * Unit tests abort each test function on the first sign of trouble. * Then NEXT test function runs as normal. */ TEST_ASSERT_EQUAL(8, FindFunction_WhichIsBroken(8888)); } @@ -42,7 +42,7 @@ void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue(v { /* This should be true because setUp set this up for us before this test */ TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable()); - + /* This should be true because we can still change our answer */ Counter = 0x1234; TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable()); From bc2ab233eeb6d316f6a27a4d9e7e59357c03d93b Mon Sep 17 00:00:00 2001 From: teaguecl Date: Fri, 25 Jan 2019 21:51:25 -0800 Subject: [PATCH 34/50] Fix error in example_1 and example_2 This test case had an error in both examples: test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode It was supposed to be a list of values that are NOT in the list, and none of them should be found. It incorrectly included '1' --- examples/example_1/makefile | 1 - examples/example_2/test/TestProductionCode.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/example_1/makefile b/examples/example_1/makefile index ee0cf73..cca79b4 100644 --- a/examples/example_1/makefile +++ b/examples/example_1/makefile @@ -41,7 +41,6 @@ CFLAGS += -Wno-unknown-pragmas CFLAGS += -Wstrict-prototypes CFLAGS += -Wundef CFLAGS += -Wold-style-definition -CFLAGS += -Wno-misleading-indentation TARGET_BASE1=test1 TARGET_BASE2=test2 diff --git a/examples/example_2/test/TestProductionCode.c b/examples/example_2/test/TestProductionCode.c index ff318ab..b8fb95c 100644 --- a/examples/example_2/test/TestProductionCode.c +++ b/examples/example_2/test/TestProductionCode.c @@ -23,7 +23,7 @@ TEST(ProductionCode, FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInLis { //All of these should pass TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(78)); - TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(1)); + TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(2)); TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(33)); TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(999)); TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(-1)); From b723c9f25012155b34d698094155164f465a0412 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Wed, 30 Jan 2019 21:10:23 +0100 Subject: [PATCH 35/50] Added braces to avoid implementation solely based on operator precedence. --- src/unity.c | 51 ++++++++++++++++++++++--------------------- src/unity_internals.h | 12 +++++----- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/unity.c b/src/unity.c index f4d8ed2..42bc47a 100644 --- a/src/unity.c +++ b/src/unity.c @@ -105,7 +105,7 @@ static UNITY_UINT UnityPrintAnsiEscapeString(const char* string) const char* pch = string; UNITY_UINT count = 0; - while (*pch && *pch != 'm') + while (*pch && (*pch != 'm')) { UNITY_OUTPUT_CHAR(*pch); pch++; @@ -129,7 +129,7 @@ void UnityPrint(const char* string) { #ifdef UNITY_OUTPUT_COLOR /* print ANSI escape code */ - if (*pch == 27 && *(pch + 1) == '[') + if ((*pch == 27) && (*(pch + 1) == '[')) { pch += UnityPrintAnsiEscapeString(pch); continue; @@ -232,7 +232,7 @@ void UnityPrintFormatted(const char* format, ...) } #ifdef UNITY_OUTPUT_COLOR /* print ANSI escape code */ - else if (*pch == 27 && *(pch + 1) == '[') + else if ((*pch == 27) && (*(pch + 1) == '[')) { pch += UnityPrintAnsiEscapeString(pch); continue; @@ -262,7 +262,7 @@ void UnityPrintLen(const char* string, const UNITY_UINT32 length) if (pch != NULL) { - while (*pch && (UNITY_UINT32)(pch - string) < length) + while (*pch && ((UNITY_UINT32)(pch - string) < length)) { /* printable characters plus CR & LF are printed */ if ((*pch <= 126) && (*pch >= 32)) @@ -351,6 +351,7 @@ void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print) { int nibble; char nibbles = nibbles_to_print; + if ((unsigned)nibbles > (2 * sizeof(number))) { nibbles = 2 * sizeof(number); @@ -422,7 +423,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) UNITY_DOUBLE number = input_number; /* print minus sign (including for negative zero) */ - if (number < 0.0f || (number == 0.0f && 1.0f / number < 0.0f)) + if ((number < 0.0f) || ((number == 0.0f) && ((1.0f / number) < 0.0f))) { UNITY_OUTPUT_CHAR('-'); number = -number; @@ -459,7 +460,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) { UNITY_DOUBLE factor = 1.0f; - while (number < (UNITY_DOUBLE)max_scaled / 1e10f) { number *= 1e10f; exponent -= 10; } + while (number < (UNITY_DOUBLE)max_scaled / 1e10f) { number *= 1e10f; exponent -= 10; } while (number * factor < (UNITY_DOUBLE)min_scaled) { factor *= 10.0f; exponent--; } number *= factor; @@ -468,7 +469,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) { UNITY_DOUBLE divisor = 1.0f; - while (number > (UNITY_DOUBLE)min_scaled * 1e10f) { number /= 1e10f; exponent += 10; } + while (number > (UNITY_DOUBLE)min_scaled * 1e10f) { number /= 1e10f; exponent += 10; } while (number / divisor > (UNITY_DOUBLE)max_scaled) { divisor *= 10.0f; exponent++; } number /= divisor; @@ -494,7 +495,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) #ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO /* round to even if exactly between two integers */ - if ((n & 1) && ((UNITY_DOUBLE)n - number == 0.5f)) + if ((n & 1) && (((UNITY_DOUBLE)n - number) == 0.5f)) n--; #endif @@ -507,11 +508,11 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) } /* determine where to place decimal point */ - decimals = (exponent <= 0 && exponent >= -(sig_digits + 3)) ? -exponent : (sig_digits - 1); + decimals = ((exponent <= 0) && (exponent >= -(sig_digits + 3))) ? (-exponent) : (sig_digits - 1); exponent += decimals; /* truncate trailing zeroes after decimal point */ - while (decimals > 0 && n % 10 == 0) + while ((decimals > 0) && ((n % 10) == 0)) { n /= 10; decimals--; @@ -519,14 +520,14 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) /* build up buffer in reverse order */ digits = 0; - while (n != 0 || digits < decimals + 1) + while ((n != 0) || (digits < (decimals + 1))) { buf[digits++] = (char)('0' + n % 10); n /= 10; } while (digits > 0) { - if(digits == decimals) UNITY_OUTPUT_CHAR('.'); + if (digits == decimals) { UNITY_OUTPUT_CHAR('.'); } UNITY_OUTPUT_CHAR(buf[--digits]); } @@ -535,7 +536,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) { UNITY_OUTPUT_CHAR('e'); - if(exponent < 0) + if (exponent < 0) { UNITY_OUTPUT_CHAR('-'); exponent = -exponent; @@ -546,7 +547,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) } digits = 0; - while (exponent != 0 || digits < 2) + while ((exponent != 0) || (digits < 2)) { buf[digits++] = (char)('0' + exponent % 10); exponent /= 10; @@ -772,18 +773,18 @@ void UnityAssertGreaterOrLessOrEqualNumber(const UNITY_INT threshold, int failed = 0; RETURN_IF_FAIL_OR_IGNORE; - if (threshold == actual && compare & UNITY_EQUAL_TO) return; - if (threshold == actual) failed = 1; + if ((threshold == actual) && (compare & UNITY_EQUAL_TO)) { return; } + if ((threshold == actual)) { failed = 1; } if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { - if (actual > threshold && compare & UNITY_SMALLER_THAN) failed = 1; - if (actual < threshold && compare & UNITY_GREATER_THAN) failed = 1; + if ((actual > threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; } + if ((actual < threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; } } else /* UINT or HEX */ { - if ((UNITY_UINT)actual > (UNITY_UINT)threshold && compare & UNITY_SMALLER_THAN) failed = 1; - if ((UNITY_UINT)actual < (UNITY_UINT)threshold && compare & UNITY_GREATER_THAN) failed = 1; + if (((UNITY_UINT)actual > (UNITY_UINT)threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; } + if (((UNITY_UINT)actual < (UNITY_UINT)threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; } } if (failed) @@ -791,9 +792,9 @@ void UnityAssertGreaterOrLessOrEqualNumber(const UNITY_INT threshold, UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(actual, style); - if (compare & UNITY_GREATER_THAN) UnityPrint(UnityStrGt); - if (compare & UNITY_SMALLER_THAN) UnityPrint(UnityStrLt); - if (compare & UNITY_EQUAL_TO) UnityPrint(UnityStrOrEqual); + if (compare & UNITY_GREATER_THAN) { UnityPrint(UnityStrGt); } + if (compare & UNITY_SMALLER_THAN) { UnityPrint(UnityStrLt); } + if (compare & UNITY_EQUAL_TO) { UnityPrint(UnityStrOrEqual); } UnityPrintNumberByStyle(threshold, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; @@ -836,7 +837,7 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UNITY_FAIL_AND_BAIL; } - while ((elements > 0) && elements--) + while ((elements > 0) && (elements--)) { UNITY_INT expect_val; UNITY_INT actual_val; @@ -865,7 +866,7 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, if (expect_val != actual_val) { - if (style & UNITY_DISPLAY_RANGE_UINT && length < sizeof(expect_val)) + if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < sizeof(expect_val))) { /* For UINT, remove sign extension (padding 1's) from signed type casts above */ UNITY_INT mask = 1; mask = (mask << 8 * length) - 1; diff --git a/src/unity_internals.h b/src/unity_internals.h index e91d9bc..0024d91 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -403,12 +403,12 @@ UNITY_DISPLAY_STYLE_UINT = sizeof(unsigned) + UNITY_DISPLAY_RANGE_UINT, typedef enum { - UNITY_WITHIN = 0, - UNITY_EQUAL_TO = 1, - UNITY_GREATER_THAN = 2, - UNITY_GREATER_OR_EQUAL = 2 + UNITY_EQUAL_TO, - UNITY_SMALLER_THAN = 4, - UNITY_SMALLER_OR_EQUAL = 4 + UNITY_EQUAL_TO, + UNITY_WITHIN = 0x0, + UNITY_EQUAL_TO = 0x1, + UNITY_GREATER_THAN = 0x2, + UNITY_GREATER_OR_EQUAL = 0x2 + UNITY_EQUAL_TO, + UNITY_SMALLER_THAN = 0x4, + UNITY_SMALLER_OR_EQUAL = 0x4 + UNITY_EQUAL_TO, UNITY_UNKNOWN } UNITY_COMPARISON_T; From 145691519b8865f5275d7e0ca2e1e06fe8942830 Mon Sep 17 00:00:00 2001 From: elliot Date: Wed, 5 Dec 2018 21:14:25 +0000 Subject: [PATCH 36/50] Add ability to override name of the 'resetTest' function This allows multiple groups to be compiled into the same executable by naming each function uniquely. --- auto/generate_test_runner.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 2acda0f..51e004b 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -27,6 +27,7 @@ class UnityTestRunnerGenerator mock_suffix: '', setup_name: 'setUp', teardown_name: 'tearDown', + test_reset_name: 'resetTest', main_name: 'main', # set to :auto to automatically generate each time main_export_decl: '', cmdline_args: false, @@ -322,8 +323,8 @@ class UnityTestRunnerGenerator def create_reset(output, used_mocks) output.puts("\n/*=======Test Reset Option=====*/") - output.puts('void resetTest(void);') - output.puts('void resetTest(void)') + output.puts("void #{@options[:test_reset_name]}(void);") + output.puts("void #{@options[:test_reset_name]}(void)") output.puts('{') output.puts(' CMock_Verify();') unless used_mocks.empty? output.puts(' CMock_Destroy();') unless used_mocks.empty? @@ -457,6 +458,7 @@ if $0 == __FILE__ ' --teardown_name="" - redefine tearDown func name to something else', ' --main_name="" - redefine main func name to something else', ' --test_prefix="" - redefine test prefix from default test|spec|should', + ' --test_reset_name="" - redefine resetTest func name to something else', ' --suite_setup="" - code to execute for setup of entire suite', ' --suite_teardown="" - code to execute for teardown of entire suite', ' --use_param_tests=1 - enable parameterized tests (disabled by default)', @@ -468,4 +470,4 @@ if $0 == __FILE__ ARGV[1] = ARGV[0].gsub('.c', '_Runner.c') unless ARGV[1] UnityTestRunnerGenerator.new(options).run(ARGV[0], ARGV[1]) -end +end \ No newline at end of file From 076f0fff5625ec7f7592fd702abd24b0442a2151 Mon Sep 17 00:00:00 2001 From: elliot Date: Sat, 1 Dec 2018 21:43:49 +0000 Subject: [PATCH 37/50] Improvements to the execution time feature - Running time macros have been made more portable, previously it was not possible to override all macros - Running time macros will be executed by default test runner, and auto test runners - Adds a default execution time implementation for unix. (Previous default implementation only worked on Windows) - For embedded platforms there is a simple method of getting a default implementation by defining a single macro UNITY_CLOCK_MS() - Removed need for UNITY_EXEC_TIME_RESET. This was not being used for the default implementations, if anything ever did need reset-like functionality it could simply be wrapped up with the start or stop macros for that platform --- auto/generate_test_runner.rb | 2 + src/unity.c | 5 +- src/unity_internals.h | 89 +++++++++++++++++++++--------------- test/tests/testunity.c | 4 +- 4 files changed, 59 insertions(+), 41 deletions(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 2acda0f..c83cbb4 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -299,6 +299,7 @@ class UnityTestRunnerGenerator output.puts(' Unity.CurrentTestLineNumber = TestLineNum; \\') output.puts(' if (UnityTestMatches()) { \\') if @options[:cmdline_args] output.puts(' Unity.NumberOfTests++; \\') + output.puts(' UNITY_EXEC_TIME_START(); \\') output.puts(' CMock_Init(); \\') unless used_mocks.empty? output.puts(' UNITY_CLR_DETAILS(); \\') unless used_mocks.empty? output.puts(' if (TEST_PROTECT()) \\') @@ -315,6 +316,7 @@ class UnityTestRunnerGenerator output.puts(' CMock_Verify(); \\') unless used_mocks.empty? output.puts(' } \\') output.puts(' CMock_Destroy(); \\') unless used_mocks.empty? + output.puts(' UNITY_EXEC_TIME_STOP(); \\') output.puts(' UnityConcludeTest(); \\') output.puts(' } \\') if @options[:cmdline_args] output.puts("}\n") diff --git a/src/unity.c b/src/unity.c index 42bc47a..c797649 100644 --- a/src/unity.c +++ b/src/unity.c @@ -599,7 +599,7 @@ void UnityConcludeTest(void) Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; - UNITY_EXEC_TIME_RESET(); + UNITY_PRINT_EXEC_TIME(); UNITY_PRINT_EOL(); UNITY_FLUSH_CALL(); } @@ -1589,6 +1589,7 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum; Unity.NumberOfTests++; UNITY_CLR_DETAILS(); + UNITY_EXEC_TIME_START(); if (TEST_PROTECT()) { setUp(); @@ -1598,6 +1599,7 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int { tearDown(); } + UNITY_EXEC_TIME_STOP(); UnityConcludeTest(); } @@ -1612,7 +1614,6 @@ void UnityBegin(const char* filename) Unity.TestIgnores = 0; Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; - UNITY_EXEC_TIME_RESET(); UNITY_CLR_DETAILS(); UNITY_OUTPUT_START(); diff --git a/src/unity_internals.h b/src/unity_internals.h index 0024d91..7539bc9 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -40,10 +40,6 @@ #include #endif -#ifndef UNITY_EXCLUDE_TIME_H -#include -#endif - /*------------------------------------------------------- * Guess Widths If Not Specified *-------------------------------------------------------*/ @@ -297,42 +293,67 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT; #define UNITY_OUTPUT_COMPLETE() #endif -#ifndef UNITY_EXEC_TIME_RESET #ifdef UNITY_INCLUDE_EXEC_TIME -#define UNITY_EXEC_TIME_RESET()\ - Unity.CurrentTestStartTime = 0;\ - Unity.CurrentTestStopTime = 0; -#else -#define UNITY_EXEC_TIME_RESET() -#endif + #if !defined(UNITY_EXEC_TIME_START) && \ + !defined(UNITY_EXEC_TIME_STOP) && \ + !defined(UNITY_PRINT_EXEC_TIME) && \ + !defined(UNITY_TIME_TYPE) + /* If none any of these macros are defined then try to provide a default implementation */ + + #if defined(UNITY_CLOCK_MS) + /* This is a simple way to get a default implementation on platforms that support getting a millisecond counter */ + #define UNITY_TIME_TYPE UNITY_UINT + #define UNITY_EXEC_TIME_START() Unity.CurrentTestStartTime = UNITY_CLOCK_MS() + #define UNITY_EXEC_TIME_STOP() Unity.CurrentTestStopTime = UNITY_CLOCK_MS() + #define UNITY_PRINT_EXEC_TIME() { \ + UNITY_UINT execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); \ + UnityPrint(" ("); \ + UnityPrintNumberUnsigned(execTimeMs); \ + UnityPrint(" ms)"); \ + } + #elif defined(_WIN32) + #include + #define UNITY_TIME_TYPE clock_t + #define UNITY_GET_TIME(t) t = (clock_t)((clock() * 1000) / CLOCKS_PER_SEC) + #define UNITY_EXEC_TIME_START() UNITY_GET_TIME(Unity.CurrentTestStartTime) + #define UNITY_EXEC_TIME_STOP() UNITY_GET_TIME(Unity.CurrentTestStopTime) + #define UNITY_PRINT_EXEC_TIME() { \ + UNITY_UINT execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); \ + UnityPrint(" ("); \ + UnityPrintNumberUnsigned(execTimeMs); \ + UnityPrint(" ms)"); \ + } + #elif defined(__unix__) + #include + #define UNITY_TIME_TYPE struct timespec + #define UNITY_GET_TIME(t) clock_gettime(CLOCK_MONOTONIC, &t) + #define UNITY_EXEC_TIME_START() UNITY_GET_TIME(Unity.CurrentTestStartTime) + #define UNITY_EXEC_TIME_STOP() UNITY_GET_TIME(Unity.CurrentTestStopTime) + #define UNITY_PRINT_EXEC_TIME() { \ + UNITY_UINT execTimeMs = ((Unity.CurrentTestStopTime.tv_sec - Unity.CurrentTestStartTime.tv_sec) * 1000L); \ + execTimeMs += ((Unity.CurrentTestStopTime.tv_nsec - Unity.CurrentTestStartTime.tv_nsec) / 1000000L); \ + UnityPrint(" ("); \ + UnityPrintNumberUnsigned(execTimeMs); \ + UnityPrint(" ms)"); \ + } + #endif + #endif #endif #ifndef UNITY_EXEC_TIME_START -#ifdef UNITY_INCLUDE_EXEC_TIME -#define UNITY_EXEC_TIME_START() Unity.CurrentTestStartTime = UNITY_CLOCK_MS(); -#else -#define UNITY_EXEC_TIME_START() -#endif +#define UNITY_EXEC_TIME_START() do{}while(0) #endif #ifndef UNITY_EXEC_TIME_STOP -#ifdef UNITY_INCLUDE_EXEC_TIME -#define UNITY_EXEC_TIME_STOP() Unity.CurrentTestStopTime = UNITY_CLOCK_MS(); -#else -#define UNITY_EXEC_TIME_STOP() +#define UNITY_EXEC_TIME_STOP() do{}while(0) #endif + +#ifndef UNITY_TIME_TYPE +#define UNITY_TIME_TYPE UNITY_UINT #endif #ifndef UNITY_PRINT_EXEC_TIME -#ifdef UNITY_INCLUDE_EXEC_TIME -#define UNITY_PRINT_EXEC_TIME() \ - UnityPrint(" (");\ - UNITY_COUNTER_TYPE execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime);\ - UnityPrintNumberUnsigned(execTimeMs);\ - UnityPrint(" ms)"); -#else -#define UNITY_PRINT_EXEC_TIME() -#endif +#define UNITY_PRINT_EXEC_TIME() do{}while(0) #endif /*------------------------------------------------------- @@ -449,8 +470,8 @@ struct UNITY_STORAGE_T UNITY_COUNTER_TYPE CurrentTestFailed; UNITY_COUNTER_TYPE CurrentTestIgnored; #ifdef UNITY_INCLUDE_EXEC_TIME - UNITY_COUNTER_TYPE CurrentTestStartTime; - UNITY_COUNTER_TYPE CurrentTestStopTime; + UNITY_TIME_TYPE CurrentTestStartTime; + UNITY_TIME_TYPE CurrentTestStopTime; #endif #ifndef UNITY_EXCLUDE_SETJMP_H jmp_buf AbortFrame; @@ -655,12 +676,6 @@ extern const char UnityStrErr64[]; #define TEST_ABORT() return #endif -#ifndef UNITY_EXCLUDE_TIME_H -#define UNITY_CLOCK_MS() (UNITY_COUNTER_TYPE)((clock() * 1000) / CLOCKS_PER_SEC) -#else -#define UNITY_CLOCK_MS() -#endif - /* This tricky series of macros gives us an optional line argument to treat it as RUN_TEST(func, num=__LINE__) */ #ifndef RUN_TEST #ifdef __STDC_VERSION__ diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 366deba..aecd272 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -104,8 +104,8 @@ void testUnitySizeInitializationReminder(void) UNITY_COUNTER_TYPE CurrentTestFailed; UNITY_COUNTER_TYPE CurrentTestIgnored; #ifdef UNITY_INCLUDE_EXEC_TIME - UNITY_COUNTER_TYPE CurrentTestStartTime; - UNITY_COUNTER_TYPE CurrentTestStopTime; + UNITY_TIME_TYPE CurrentTestStartTime; + UNITY_TIME_TYPE CurrentTestStopTime; #endif #ifndef UNITY_EXCLUDE_SETJMP_H jmp_buf AbortFrame; From 9dc7cb1b5cf9d0cbfc3227b7acbde446190054b0 Mon Sep 17 00:00:00 2001 From: Michael Brockus Date: Mon, 18 Feb 2019 12:35:53 -0800 Subject: [PATCH 38/50] Adding CMake script to unity test framework. --- CMakeLists.txt | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..282ea4c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,68 @@ +##################################################### +# FILE NAME CMakeLists.txt # +# # +# PURPOSE contains CMake statements. # +# # +##################################################### +cmake_minimum_required(VERSION 3.13.2.0 FATAL_ERROR) + + + +# +# CMake: Declare project +# +project(unity LANGUAGES C DESCRIPTION "C Unit testing framework.") + + + +# +# CMake: Creation of library +# +add_library("unity" STATIC) + + + +# +# CMake: Adding source to target +# +target_sources("unity" PRIVATE "src/unity.c") + + + +# +# CMake: Including directories to target +# +target_include_directories("unity" + PUBLIC + "$" + "$" + + PRIVATE "src" +) + + + +# +# CMake: Give target an alias +# +add_library("unity::framework" ALIAS "unity") + + + +# +# CMake: export project +# +install(TARGETS "unity" EXPORT "unityConfig" + ARCHIVE DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_INSTALL_BINDIR}" + + INCLUDES DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) + +install(DIRECTORY src/ DESTINATION src) + +install(EXPORT unityConfig DESTINATION share/unityConfig/cmake) + +# This makes the project importable from the build directory +export(TARGETS unity FILE unityConfig.cmake) \ No newline at end of file From 3e4d064c42cf8db428b96d72c463b7dd71b5cc71 Mon Sep 17 00:00:00 2001 From: Michael Brockus Date: Tue, 19 Feb 2019 09:45:50 -0800 Subject: [PATCH 39/50] Singing my name on the script. --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 282ea4c..0eddcd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ ##################################################### # FILE NAME CMakeLists.txt # # # +# WRITTEN BY Michael Brockus. # +# # # PURPOSE contains CMake statements. # # # ##################################################### @@ -65,4 +67,4 @@ install(DIRECTORY src/ DESTINATION src) install(EXPORT unityConfig DESTINATION share/unityConfig/cmake) # This makes the project importable from the build directory -export(TARGETS unity FILE unityConfig.cmake) \ No newline at end of file +export(TARGETS unity FILE unityConfig.cmake) From ead95b3ab8ebed0c5d51f6a20b939b942899144f Mon Sep 17 00:00:00 2001 From: Jason Heeris Date: Fri, 22 Feb 2019 08:38:29 +1100 Subject: [PATCH 40/50] Removed leading underscore from module generator header guards. --- auto/generate_module.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/auto/generate_module.rb b/auto/generate_module.rb index fb8c7ac..92aa514 100644 --- a/auto/generate_module.rb +++ b/auto/generate_module.rb @@ -35,11 +35,11 @@ TEMPLATE_SRC ||= '%2$s#include "%1$s.h" '.freeze # TEMPLATE_INC -TEMPLATE_INC ||= '#ifndef _%3$s_H -#define _%3$s_H +TEMPLATE_INC ||= '#ifndef %3$s_H +#define %3$s_H %2$s -#endif // _%3$s_H +#endif // %3$s_H '.freeze class UnityModuleGenerator From 0dafa0b306154697ff91a505153354cc7946f600 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Tue, 12 Mar 2019 00:17:37 +0100 Subject: [PATCH 41/50] use unary minus on the incoming int instead of the casted uint --- src/unity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 42bc47a..4888962 100644 --- a/src/unity.c +++ b/src/unity.c @@ -321,7 +321,7 @@ void UnityPrintNumber(const UNITY_INT number_to_print) { /* A negative number, including MIN negative */ UNITY_OUTPUT_CHAR('-'); - number = -number; + number = (UNITY_UINT)-number_to_print; } UnityPrintNumberUnsigned(number); } From 6315c4c4c345afda673c72fd1339e94394fc060b Mon Sep 17 00:00:00 2001 From: Dom Postorivo Date: Sat, 23 Mar 2019 19:58:15 -0400 Subject: [PATCH 42/50] Fix travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5a15f03..8d32264 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ matrix: compiler: gcc before_install: - - if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.1 && rvm use 2.1 && ruby -v; fi + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.3 && rvm use 2.3 && ruby -v; fi - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi install: - gem install rspec From aecc642594245cdd069d547e83256ad92dbfcde2 Mon Sep 17 00:00:00 2001 From: Tomer Yogev Date: Tue, 26 Mar 2019 17:32:30 +0200 Subject: [PATCH 43/50] recursive search for target test files in test summary python script --- auto/unity_test_summary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto/unity_test_summary.py b/auto/unity_test_summary.py index 4c20e52..00c0da8 100644 --- a/auto/unity_test_summary.py +++ b/auto/unity_test_summary.py @@ -121,7 +121,7 @@ if __name__ == '__main__': targets_dir = sys.argv[1] else: targets_dir = './' - targets = list(map(lambda x: x.replace('\\', '/'), glob(targets_dir + '*.test*'))) + targets = list(map(lambda x: x.replace('\\', '/'), glob(targets_dir + '**/*.test*', recursive=True))) if len(targets) == 0: raise Exception("No *.testpass or *.testfail files found in '%s'" % targets_dir) uts.set_targets(targets) From 2191b2ba8ef4b22de43a2707a31d92322475be29 Mon Sep 17 00:00:00 2001 From: Fredrik Rothamel Date: Wed, 13 Mar 2019 13:41:29 +0100 Subject: [PATCH 44/50] Allow multi line test-function definitions. --- auto/generate_test_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 2acda0f..e7ca698 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -112,7 +112,7 @@ class UnityTestRunnerGenerator lines.each_with_index do |line, _index| # find tests - next unless line =~ /^((?:\s*TEST_CASE\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]}).*)\s*\(\s*(.*)\s*\)/ + next unless line =~ /^((?:\s*TEST_CASE\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]}).*)\s*\(\s*(.*)\s*\)/m arguments = Regexp.last_match(1) name = Regexp.last_match(2) call = Regexp.last_match(3) From 52ff8613a234248df3ab8d0ea794d54bd646e699 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 7 Apr 2019 11:56:34 +0200 Subject: [PATCH 45/50] Fixed maximum number of nibbles for processor where sizeof() operator doesn't return the size of a type in 8-bit bytes (e.g. the TI C2000 series). --- src/unity.c | 4 ++-- src/unity_internals.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/unity.c b/src/unity.c index 4888962..8022e24 100644 --- a/src/unity.c +++ b/src/unity.c @@ -352,9 +352,9 @@ void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print) int nibble; char nibbles = nibbles_to_print; - if ((unsigned)nibbles > (2 * sizeof(number))) + if ((unsigned)nibbles > UNITY_MAX_NIBBLES) { - nibbles = 2 * sizeof(number); + nibbles = UNITY_MAX_NIBBLES; } while (nibbles > 0) diff --git a/src/unity_internals.h b/src/unity_internals.h index 0024d91..88b8baa 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -122,18 +122,20 @@ * 64-bit Support *-------------------------------------------------------*/ +/* Auto-detect 64 Bit Support */ #ifndef UNITY_SUPPORT_64 #if UNITY_LONG_WIDTH == 64 || UNITY_POINTER_WIDTH == 64 #define UNITY_SUPPORT_64 #endif #endif +/* 64-Bit Support Dependent Configuration */ #ifndef UNITY_SUPPORT_64 /* No 64-bit Support */ typedef UNITY_UINT32 UNITY_UINT; typedef UNITY_INT32 UNITY_INT; + #define UNITY_MAX_NIBBLES (8) /* Maximum number of nibbles in a UNITY_(U)INT */ #else - /* 64-bit Support */ #if (UNITY_LONG_WIDTH == 32) typedef unsigned long long UNITY_UINT64; @@ -146,7 +148,7 @@ #endif typedef UNITY_UINT64 UNITY_UINT; typedef UNITY_INT64 UNITY_INT; - + #define UNITY_MAX_NIBBLES (16) /* Maximum number of nibbles in a UNITY_(U)INT */ #endif /*------------------------------------------------------- From d01e32299ee792aa72e35e91682c8b6d8696d9ec Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sat, 6 Apr 2019 11:55:24 +0200 Subject: [PATCH 46/50] Used sizeof() operator for pointer increments and substituted sizeof() operator for the unsigned int mask calculation to "UNITY_INT_WIDTH / 8" in function "UnityAssertEqualIntArray". --- src/unity.c | 45 ++++++++++++++++++++++++++++--------------- src/unity.h | 2 +- src/unity_internals.h | 6 +++--- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/unity.c b/src/unity.c index 4888962..38dc801 100644 --- a/src/unity.c +++ b/src/unity.c @@ -1,6 +1,6 @@ /* ========================================================================= Unity Project - A Test Framework for C - Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams + Copyright (c) 2007-19 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ============================================================================ */ @@ -693,7 +693,8 @@ static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected, const UNITY_LINE_TYPE lineNumber, const char* msg) { - if (expected == actual) return 0; /* Both are NULL or same pointer */ + /* Both are NULL or same pointer */ + if (expected == actual) { return 0; } /* print and return true if just expected is NULL */ if (expected == NULL) @@ -817,8 +818,9 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, const UNITY_DISPLAY_STYLE_T style, const UNITY_FLAGS_T flags) { - UNITY_UINT32 elements = num_elements; - unsigned int length = style & 0xF; + UNITY_UINT32 elements = num_elements; + unsigned int length = style & 0xF; + unsigned int increment = 0; RETURN_IF_FAIL_OR_IGNORE; @@ -841,32 +843,41 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, { UNITY_INT expect_val; UNITY_INT actual_val; + switch (length) { case 1: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual; + increment = sizeof(UNITY_INT8); break; + case 2: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual; + increment = sizeof(UNITY_INT16); break; + #ifdef UNITY_SUPPORT_64 case 8: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual; + increment = sizeof(UNITY_INT64); break; #endif - default: /* length 4 bytes */ + + default: /* default is length 4 bytes */ + case 4: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual; + increment = sizeof(UNITY_INT32); length = 4; break; } if (expect_val != actual_val) { - if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < sizeof(expect_val))) + if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < (UNITY_INT_WIDTH / 8))) { /* For UINT, remove sign extension (padding 1's) from signed type casts above */ UNITY_INT mask = 1; mask = (mask << 8 * length) - 1; @@ -883,11 +894,12 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } + /* Walk through array by incrementing the pointers */ if (flags == UNITY_ARRAY_TO_ARRAY) { - expected = (UNITY_INTERNAL_PTR)(length + (const char*)expected); + expected = (UNITY_INTERNAL_PTR)((const char*)expected + increment); } - actual = (UNITY_INTERNAL_PTR)(length + (const char*)actual); + actual = (UNITY_INTERNAL_PTR)((const char*)actual + increment); } } @@ -1492,21 +1504,22 @@ UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size) switch(size) { case 1: - UnityQuickCompare.i8 = (UNITY_INT8)num; - return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i8); + UnityQuickCompare.i8 = (UNITY_INT8)num; + return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i8); case 2: - UnityQuickCompare.i16 = (UNITY_INT16)num; - return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i16); + UnityQuickCompare.i16 = (UNITY_INT16)num; + return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i16); #ifdef UNITY_SUPPORT_64 case 8: - UnityQuickCompare.i64 = (UNITY_INT64)num; - return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i64); + UnityQuickCompare.i64 = (UNITY_INT64)num; + return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i64); #endif + default: /* 4 bytes */ - UnityQuickCompare.i32 = (UNITY_INT32)num; - return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i32); + UnityQuickCompare.i32 = (UNITY_INT32)num; + return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i32); } } diff --git a/src/unity.h b/src/unity.h index a0c301d..c51267c 100644 --- a/src/unity.h +++ b/src/unity.h @@ -1,6 +1,6 @@ /* ========================================== Unity Project - A Test Framework for C - Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams + Copyright (c) 2007-19 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ diff --git a/src/unity_internals.h b/src/unity_internals.h index 0024d91..70edadc 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -1,6 +1,6 @@ /* ========================================== Unity Project - A Test Framework for C - Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams + Copyright (c) 2007-19 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ @@ -375,7 +375,7 @@ typedef void (*UnityTestFunction)(void); typedef enum { -UNITY_DISPLAY_STYLE_INT = sizeof(int)+ UNITY_DISPLAY_RANGE_INT, + UNITY_DISPLAY_STYLE_INT = sizeof(int) + UNITY_DISPLAY_RANGE_INT, UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT, UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT, UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT, @@ -383,7 +383,7 @@ UNITY_DISPLAY_STYLE_INT = sizeof(int)+ UNITY_DISPLAY_RANGE_INT, UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT, #endif -UNITY_DISPLAY_STYLE_UINT = sizeof(unsigned) + UNITY_DISPLAY_RANGE_UINT, + UNITY_DISPLAY_STYLE_UINT = sizeof(unsigned) + UNITY_DISPLAY_RANGE_UINT, UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT, UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT, UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT, From f69fbe8a95c24935fa62cb04e72fb348f962296f Mon Sep 17 00:00:00 2001 From: Dom Postorivo Date: Sat, 13 Apr 2019 11:45:27 -0400 Subject: [PATCH 47/50] expliticly show test failures of unequal strings --- test/tests/testunity.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 366deba..bba555a 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -1852,6 +1852,20 @@ void testNotEqualStringLen_ActualStringIsNull(void) VERIFY_FAILS_END } +void testNotEqualString_ExpectedStringIsLonger(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_STRING("foo2", "foo"); + VERIFY_FAILS_END +} + +void testNotEqualString_ActualStringIsLonger(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_STRING("foo", "foo2"); + VERIFY_FAILS_END +} + void testEqualStringArrays(void) { const char *testStrings[] = { "foo", "boo", "woo", "moo" }; From 0bd6bf7b2b9665959ceae793ae03103c15e36a54 Mon Sep 17 00:00:00 2001 From: Dom Postorivo Date: Sat, 13 Apr 2019 14:08:45 -0400 Subject: [PATCH 48/50] Use Pass string from unity.c in unity_fixture.c to garuntee colour behavior --- extras/fixture/src/unity_fixture.c | 3 ++- src/unity.c | 16 ++++++++-------- src/unity_internals.h | 5 +++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 36c1fb1..2771198 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -419,7 +419,8 @@ void UnityConcludeFixtureTest(void) { if (UnityFixture.Verbose) { - UnityPrint(" PASS"); + UnityPrint(" "); + UnityPrint(UnityStrPass); UNITY_EXEC_TIME_STOP(); UNITY_PRINT_EXEC_TIME(); UNITY_PRINT_EOL(); diff --git a/src/unity.c b/src/unity.c index 4888962..7ed85e0 100644 --- a/src/unity.c +++ b/src/unity.c @@ -21,15 +21,15 @@ void UNITY_OUTPUT_CHAR(int); struct UNITY_STORAGE_T Unity; #ifdef UNITY_OUTPUT_COLOR -static const char UnityStrOk[] = "\033[42mOK\033[00m"; -static const char UnityStrPass[] = "\033[42mPASS\033[00m"; -static const char UnityStrFail[] = "\033[41mFAIL\033[00m"; -static const char UnityStrIgnore[] = "\033[43mIGNORE\033[00m"; +const char UnityStrOk[] = "\033[42mOK\033[00m"; +const char UnityStrPass[] = "\033[42mPASS\033[00m"; +const char UnityStrFail[] = "\033[41mFAIL\033[00m"; +const char UnityStrIgnore[] = "\033[43mIGNORE\033[00m"; #else -static const char UnityStrOk[] = "OK"; -static const char UnityStrPass[] = "PASS"; -static const char UnityStrFail[] = "FAIL"; -static const char UnityStrIgnore[] = "IGNORE"; +const char UnityStrOk[] = "OK"; +const char UnityStrPass[] = "PASS"; +const char UnityStrFail[] = "FAIL"; +const char UnityStrIgnore[] = "IGNORE"; #endif static const char UnityStrNull[] = "NULL"; static const char UnityStrSpacer[] = ". "; diff --git a/src/unity_internals.h b/src/unity_internals.h index 0024d91..ad12fde 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -639,6 +639,11 @@ UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num); * Error Strings We Might Need *-------------------------------------------------------*/ +extern const char UnityStrOk[]; +extern const char UnityStrPass[]; +extern const char UnityStrFail[]; +extern const char UnityStrIgnore[]; + extern const char UnityStrErrFloat[]; extern const char UnityStrErrDouble[]; extern const char UnityStrErr64[]; From 89465c88b03ac7b3cfef846fbf5ad6270aa52b57 Mon Sep 17 00:00:00 2001 From: Dom Postorivo Date: Sun, 14 Apr 2019 15:59:40 -0400 Subject: [PATCH 49/50] Add tests for GREATER_OR_EQUAL, LESS_OR_EQUAL, LESS_THAN, and GREATER_THAN --- test/tests/testunity.c | 859 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 852 insertions(+), 7 deletions(-) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index bba555a..65a746f 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -1318,8 +1318,8 @@ void testINT8sNotWithinDeltaAndCustomMessage(void) VERIFY_FAILS_END } - //----------------- + void testGreaterThan(void) { UNITY_INT v0, v1; @@ -1336,6 +1336,13 @@ void testGreaterThan(void) TEST_ASSERT_GREATER_THAN(*p0, *p1); } +void testNotGreaterThan(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN(0, -1); + VERIFY_FAILS_END +} + void testGreaterThanINT(void) { UNITY_INT v0, v1; @@ -1352,6 +1359,12 @@ void testGreaterThanINT(void) TEST_ASSERT_GREATER_THAN_INT(*p0, *p1); } +void testNotGreaterThanINT(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN_INT(3334, 302); + VERIFY_FAILS_END +} void testGreaterThanINT8(void) { @@ -1369,6 +1382,13 @@ void testGreaterThanINT8(void) TEST_ASSERT_GREATER_THAN_INT8(*p0, *p1); } +void testNotGreaterThanINT8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN_INT8(127, -128); + VERIFY_FAILS_END +} + void testGreaterThanINT16(void) { UNITY_INT16 v0, v1; @@ -1385,6 +1405,13 @@ void testGreaterThanINT16(void) TEST_ASSERT_GREATER_THAN_INT16(*p0, *p1); } +void testNotGreaterThanINT16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN_INT16(32768, -32768); + VERIFY_FAILS_END +} + void testGreaterThanINT32(void) { UNITY_INT32 v0, v1; @@ -1401,6 +1428,13 @@ void testGreaterThanINT32(void) TEST_ASSERT_GREATER_THAN_INT32(*p0, *p1); } +void testNotGreaterThanINT32(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN_INT32(214783647, -214783648); + VERIFY_FAILS_END +} + void testGreaterThanUINT(void) { UNITY_UINT v0, v1; @@ -1417,6 +1451,12 @@ void testGreaterThanUINT(void) TEST_ASSERT_GREATER_THAN_UINT(*p0, *p1); } +void testNotGreaterThanUINT(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN_UINT(1, 0); + VERIFY_FAILS_END +} void testGreaterThanUINT8(void) { @@ -1434,6 +1474,13 @@ void testGreaterThanUINT8(void) TEST_ASSERT_GREATER_THAN_UINT8(*p0, *p1); } +void testNotGreaterThanUINT8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN_UINT8(255, 0); + VERIFY_FAILS_END +} + void testGreaterThanUINT16(void) { UNITY_UINT16 v0, v1; @@ -1450,6 +1497,13 @@ void testGreaterThanUINT16(void) TEST_ASSERT_GREATER_THAN_UINT16(*p0, *p1); } +void testNotGreaterThanUINT16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN_UINT16(65535, 0); + VERIFY_FAILS_END +} + void testGreaterThanUINT32(void) { UNITY_UINT32 v0, v1; @@ -1466,6 +1520,13 @@ void testGreaterThanUINT32(void) TEST_ASSERT_GREATER_THAN_UINT32(*p0, *p1); } +void testNotGreaterThanUINT32(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN_UINT32(4294967295, 0); + VERIFY_FAILS_END +} + void testGreaterThanHEX8(void) { UNITY_UINT8 v0, v1; @@ -1482,6 +1543,13 @@ void testGreaterThanHEX8(void) TEST_ASSERT_GREATER_THAN_HEX8(*p0, *p1); } +void testNotGreaterThanHEX8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN_HEX8(0xFF, 0x00); + VERIFY_FAILS_END +} + void testGreaterThanHEX16(void) { UNITY_UINT16 v0, v1; @@ -1498,6 +1566,13 @@ void testGreaterThanHEX16(void) TEST_ASSERT_GREATER_THAN_HEX16(*p0, *p1); } +void testNotGreaterThanHEX16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_THAN_HEX16(0xFFFF, 0x00); + VERIFY_FAILS_END +} + void testGreaterThanHEX32(void) { UNITY_UINT32 v0, v1; @@ -1514,14 +1589,364 @@ void testGreaterThanHEX32(void) TEST_ASSERT_GREATER_THAN_HEX32(*p0, *p1); } - -void testNotGreaterThan(void) +void testNotGreaterThanHEX32(void) { EXPECT_ABORT_BEGIN - TEST_ASSERT_GREATER_THAN(0, -1); + TEST_ASSERT_GREATER_THAN_HEX32(0xFFFFFFFF, 0x00); VERIFY_FAILS_END } +void testGreaterOrEqual(void) +{ + UNITY_INT v0, v1, v2; + UNITY_INT *p0, *p1, *p2; + + v0 = 0; + v1 = 1; + v2 = 0; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL(*p0, *p2); +} + +void testNotGreaterOrEqual(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL(0, -1); + VERIFY_FAILS_END +} + +void testGreaterOrEqualINT(void) +{ + UNITY_INT v0, v1, v2; + UNITY_INT *p0, *p1, *p2; + + v0 = 302; + v1 = 3334; + v2 = 302; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_INT(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_INT(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_INT(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_INT(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_INT(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_INT(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_INT(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_INT(*p0, *p2); +} + +void testNotGreaterOrEqualINT(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_INT(3334, 302); + VERIFY_FAILS_END +} + +void testGreaterOrEqualINT8(void) +{ + UNITY_INT8 v0, v1, v2; + UNITY_INT8 *p0, *p1, *p2; + + v0 = -128; + v1 = 127; + v2 = -128; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_INT8(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_INT8(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_INT8(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_INT8(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_INT8(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_INT8(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_INT8(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_INT8(*p0, *p2); +} + +void testNotGreaterOrEqualINT8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_INT8(127, -128); + VERIFY_FAILS_END +} + +void testGreaterOrEqualINT16(void) +{ + UNITY_INT16 v0, v1, v2; + UNITY_INT16 *p0, *p1, *p2; + + v0 = -32768; + v1 = 32767; + v2 = -32768; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_INT16(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_INT16(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_INT16(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_INT16(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_INT16(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_INT16(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_INT16(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_INT16(*p0, *p2); +} + +void testNotGreaterOrEqualINT16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_INT16(32767, -32768); + VERIFY_FAILS_END +} + +void testGreaterOrEqualINT32(void) +{ + UNITY_INT32 v0, v1, v2; + UNITY_INT32 *p0, *p1, *p2; + + v0 = -214783648; + v1 = 214783647; + v2 = -214783648; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_INT32(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_INT32(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_INT32(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_INT32(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_INT32(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_INT32(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_INT32(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_INT32(*p0, *p2); +} + +void testNotGreaterOrEqualINT32(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_INT32(214783647, -214783648); + VERIFY_FAILS_END +} + +void testGreaterOrEqualUINT(void) +{ + UNITY_UINT v0, v1, v2; + UNITY_UINT *p0, *p1, *p2; + + v0 = 0; + v1 = 1; + v2 = 0; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_UINT(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT(*p0, *p2); +} + +void testNotGreaterOrEqualUINT(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_UINT(1, 0); + VERIFY_FAILS_END +} + +void testGreaterOrEqualUINT8(void) +{ + UNITY_UINT8 v0, v1, v2; + UNITY_UINT8 *p0, *p1, *p2; + + v0 = 0; + v1 = 255; + v2 = 0; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_UINT8(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT8(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT8(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT8(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT8(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT8(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT8(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT8(*p0, *p2); +} + +void testNotGreaterOrEqualUINT8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_UINT8(255, 0); + VERIFY_FAILS_END +} + +void testGreaterOrEqualUINT16(void) +{ + UNITY_UINT16 v0, v1, v2; + UNITY_UINT16 *p0, *p1, *p2; + + v0 = 0; + v1 = 65535; + v2 = 0; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_UINT16(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT16(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT16(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT16(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT16(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT16(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT16(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT16(*p0, *p2); +} + +void testNotGreaterOrEqualUINT16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_UINT16(65535, 0); + VERIFY_FAILS_END +} + +void testGreaterOrEqualUINT32(void) +{ + UNITY_UINT32 v0, v1, v2; + UNITY_UINT32 *p0, *p1, *p2; + + v0 = 0; + v1 = 4294967295; + v2 = 0; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(*p0, *p2); +} + +void testNotGreaterOrEqualUINT32(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(4294967295, 0); + VERIFY_FAILS_END +} + +void testGreaterOrEqualHEX8(void) +{ + UNITY_UINT8 v0, v1, v2; + UNITY_UINT8 *p0, *p1, *p2; + + v0 = 0x00; + v1 = 0xFF; + v2 = 0x00; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_HEX8(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX8(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX8(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX8(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX8(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_HEX8(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_HEX8(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_HEX8(*p0, *p2); +} + +void testNotGreaterOrEqualHEX8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_HEX8(0xFF, 0x00); + VERIFY_FAILS_END +} + +void testGreaterOrEqualHEX16(void) +{ + UNITY_UINT16 v0, v1, v2; + UNITY_UINT16 *p0, *p1, *p2; + + v0 = 0x0000; + v1 = 0xFFFF; + v2 = 0x0000; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_HEX16(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX16(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX16(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX16(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX16(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_HEX16(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_HEX16(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_HEX16(*p0, *p2); +} + +void testNotGreaterOrEqualHEX16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_HEX16(0xFFFF, 0x00); + VERIFY_FAILS_END +} + +void testGreaterOrEqualHEX32(void) +{ + UNITY_UINT32 v0, v1, v2; + UNITY_UINT32 *p0, *p1, *p2; + + v0 = 0x00000000; + v1 = 0xFFFFFFFF; + v2 = 0x00000000; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_GREATER_OR_EQUAL_HEX32(v0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX32(*p0, v1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX32(v0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX32(*p0, *p1); + TEST_ASSERT_GREATER_OR_EQUAL_HEX32(v0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_HEX32(*p0, v2); + TEST_ASSERT_GREATER_OR_EQUAL_HEX32(v0, *p2); + TEST_ASSERT_GREATER_OR_EQUAL_HEX32(*p0, *p2); +} + +void testNotGreaterOrEqualHEX32(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_GREATER_OR_EQUAL_HEX32(0xFFFFFFFF, 0x00); + VERIFY_FAILS_END +} + +//----------------- + + void testLessThan(void) { UNITY_INT v0, v1; @@ -1538,6 +1963,13 @@ void testLessThan(void) TEST_ASSERT_LESS_THAN(*p0, *p1); } +void testNotLessThan(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN(0, 1); + VERIFY_FAILS_END +} + void testLessThanINT(void) { UNITY_INT v0, v1; @@ -1554,6 +1986,12 @@ void testLessThanINT(void) TEST_ASSERT_LESS_THAN_INT(*p0, *p1); } +void testNotLessThanINT(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN_INT(302, 3334); + VERIFY_FAILS_END +} void testLessThanINT8(void) { @@ -1571,6 +2009,13 @@ void testLessThanINT8(void) TEST_ASSERT_LESS_THAN_INT8(*p0, *p1); } +void testNotLessThanINT8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN_INT8(-128, 127); + VERIFY_FAILS_END +} + void testLessThanINT16(void) { UNITY_INT16 v0, v1; @@ -1587,6 +2032,13 @@ void testLessThanINT16(void) TEST_ASSERT_LESS_THAN_INT16(*p0, *p1); } +void testNotLessThanINT16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN_INT16(-32768, 32767); + VERIFY_FAILS_END +} + void testLessThanINT32(void) { UNITY_INT32 v0, v1; @@ -1603,6 +2055,13 @@ void testLessThanINT32(void) TEST_ASSERT_LESS_THAN_INT32(*p0, *p1); } +void testNotLessThanINT32(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN_INT32(-214783648, 214783647); + VERIFY_FAILS_END +} + void testLessThanUINT(void) { UNITY_UINT v0, v1; @@ -1619,6 +2078,12 @@ void testLessThanUINT(void) TEST_ASSERT_LESS_THAN_UINT(*p0, *p1); } +void testNotLessThanUINT(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN_UINT(0, 1); + VERIFY_FAILS_END +} void testLessThanUINT8(void) { @@ -1636,6 +2101,13 @@ void testLessThanUINT8(void) TEST_ASSERT_LESS_THAN_UINT8(*p0, *p1); } +void testNotLessThanUINT8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN_UINT8(0, 255); + VERIFY_FAILS_END +} + void testLessThanUINT16(void) { UNITY_UINT16 v0, v1; @@ -1652,6 +2124,13 @@ void testLessThanUINT16(void) TEST_ASSERT_LESS_THAN_UINT16(*p0, *p1); } +void testNotLessThanUINT16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN_UINT16(0, 65535); + VERIFY_FAILS_END +} + void testLessThanUINT32(void) { UNITY_UINT32 v0, v1; @@ -1668,6 +2147,13 @@ void testLessThanUINT32(void) TEST_ASSERT_LESS_THAN_UINT32(*p0, *p1); } +void testNotLessThanUINT32(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN_UINT32(0, 4294967295); + VERIFY_FAILS_END +} + void testLessThanHEX8(void) { UNITY_UINT8 v0, v1; @@ -1684,6 +2170,13 @@ void testLessThanHEX8(void) TEST_ASSERT_LESS_THAN_HEX8(*p0, *p1); } +void testNotLessThanHEX8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN_HEX8(0x00, 0xFF); + VERIFY_FAILS_END +} + void testLessThanHEX16(void) { UNITY_UINT16 v0, v1; @@ -1700,6 +2193,13 @@ void testLessThanHEX16(void) TEST_ASSERT_LESS_THAN_HEX16(*p0, *p1); } +void testNotLessThanHEX16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_THAN_HEX16(0x0000, 0xFFFF); + VERIFY_FAILS_END +} + void testLessThanHEX32(void) { UNITY_UINT32 v0, v1; @@ -1716,15 +2216,360 @@ void testLessThanHEX32(void) TEST_ASSERT_LESS_THAN_HEX32(*p0, *p1); } - -void testNotLessThan(void) +void testNotLessThanHEX32(void) { EXPECT_ABORT_BEGIN - TEST_ASSERT_LESS_THAN(0, 1); + TEST_ASSERT_LESS_THAN_HEX32(0x00000000, 0xFFFFFFFF); VERIFY_FAILS_END } +void testLessOrEqual(void) +{ + UNITY_INT v0, v1, v2; + UNITY_INT *p0, *p1, *p2; + v0 = 0; + v1 = -1; + v2 = 0; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL(*p0, *p2); +} + +void testNotLessOrEqual(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL(0, 1); + VERIFY_FAILS_END +} + +void testLessOrEqualINT(void) +{ + UNITY_INT v0, v1, v2; + UNITY_INT *p0, *p1, *p2; + + v0 = 3334; + v1 = 302; + v2 = 3334; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_INT(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_INT(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_INT(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_INT(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_INT(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_INT(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_INT(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_INT(*p0, *p2); +} + +void testNotLessOrEqualINT(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_INT(302, 3334); + VERIFY_FAILS_END +} + +void testLessOrEqualINT8(void) +{ + UNITY_INT8 v0, v1, v2; + UNITY_INT8 *p0, *p1, *p2; + + v0 = 127; + v1 = -128; + v2 = 127; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_INT8(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_INT8(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_INT8(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_INT8(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_INT8(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_INT8(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_INT8(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_INT8(*p0, *p2); +} + +void testNotLessOrEqualINT8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_INT8(-128, 127); + VERIFY_FAILS_END +} + +void testLessOrEqualINT16(void) +{ + UNITY_INT16 v0, v1, v2; + UNITY_INT16 *p0, *p1, *p2; + + v0 = 32767; + v1 = -32768; + v2 = 32767; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_INT16(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_INT16(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_INT16(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_INT16(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_INT16(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_INT16(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_INT16(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_INT16(*p0, *p2); +} + +void testNotLessOrEqualINT16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_INT16(-32768, 32767); + VERIFY_FAILS_END +} + +void testLessOrEqualINT32(void) +{ + UNITY_INT32 v0, v1, v2; + UNITY_INT32 *p0, *p1, *p2; + + v0 = 214783647; + v1 = -214783648; + v2 = 214783647; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_INT32(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_INT32(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_INT32(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_INT32(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_INT32(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_INT32(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_INT32(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_INT32(*p0, *p2); +} + +void testNotLessOrEqualINT32(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_INT32(-214783648, 214783647); + VERIFY_FAILS_END +} + +void testLessOrEqualUINT(void) +{ + UNITY_UINT v0, v1, v2; + UNITY_UINT *p0, *p1, *p2; + + v0 = 1; + v1 = 0; + v2 = 1; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_UINT(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_UINT(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_UINT(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_UINT(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_UINT(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_UINT(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_UINT(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_UINT(*p0, *p2); +} + +void testNotLessOrEqualUINT(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_UINT(0, 1); + VERIFY_FAILS_END +} + +void testLessOrEqualUINT8(void) +{ + UNITY_UINT8 v0, v1, v2; + UNITY_UINT8 *p0, *p1, *p2; + + v0 = 255; + v1 = 0; + v2 = 255; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_UINT8(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_UINT8(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_UINT8(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_UINT8(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_UINT8(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_UINT8(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_UINT8(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_UINT8(*p0, *p2); +} + +void testNotLessOrEqualUINT8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_UINT8(0, 255); + VERIFY_FAILS_END +} + +void testLessOrEqualUINT16(void) +{ + UNITY_UINT16 v0, v1, v2; + UNITY_UINT16 *p0, *p1, *p2; + + v0 = 65535; + v1 = 0; + v2 = 65535; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_UINT16(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_UINT16(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_UINT16(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_UINT16(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_UINT16(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_UINT16(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_UINT16(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_UINT16(*p0, *p2); +} + +void testNotLessOrEqualUINT16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_UINT16(0, 65535); + VERIFY_FAILS_END +} + +void testLessOrEqualUINT32(void) +{ + UNITY_UINT32 v0, v1, v2; + UNITY_UINT32 *p0, *p1, *p2; + + v0 = 4294967295; + v1 = 0; + v2 = 4294967295; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_UINT32(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_UINT32(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_UINT32(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_UINT32(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_UINT32(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_UINT32(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_UINT32(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_UINT32(*p0, *p2); +} + +void testNotLessOrEqualUINT32(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_UINT32(0, 4294967295); + VERIFY_FAILS_END +} + +void testLessOrEqualHEX8(void) +{ + UNITY_UINT8 v0, v1, v2; + UNITY_UINT8 *p0, *p1, *p2; + + v0 = 0xFF; + v1 = 0x00; + v2 = 0xFF; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_HEX8(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_HEX8(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_HEX8(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_HEX8(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_HEX8(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_HEX8(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_HEX8(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_HEX8(*p0, *p2); +} + +void testNotLessOrEqualHEX8(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_HEX8(0x00, 0xFF); + VERIFY_FAILS_END +} + +void testLessOrEqualHEX16(void) +{ + UNITY_UINT16 v0, v1, v2; + UNITY_UINT16 *p0, *p1, *p2; + + v0 = 0xFFFF; + v1 = 0x0000; + v2 = 0xFFFF; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_HEX16(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_HEX16(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_HEX16(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_HEX16(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_HEX16(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_HEX16(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_HEX16(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_HEX16(*p0, *p2); +} + +void testNotLessOrEqualHEX16(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_HEX16(0x0000, 0xFFFF); + VERIFY_FAILS_END +} + +void testLessOrEqualHEX32(void) +{ + UNITY_UINT32 v0, v1, v2; + UNITY_UINT32 *p0, *p1, *p2; + + v0 = 0xFFFFFFFF; + v1 = 0x00000000; + v2 = 0xFFFFFFFF; + p0 = &v0; + p1 = &v1; + p2 = &v2; + + TEST_ASSERT_LESS_OR_EQUAL_HEX32(v0, v1); + TEST_ASSERT_LESS_OR_EQUAL_HEX32(*p0, v1); + TEST_ASSERT_LESS_OR_EQUAL_HEX32(v0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_HEX32(*p0, *p1); + TEST_ASSERT_LESS_OR_EQUAL_HEX32(v0, v2); + TEST_ASSERT_LESS_OR_EQUAL_HEX32(*p0, v2); + TEST_ASSERT_LESS_OR_EQUAL_HEX32(v0, *p2); + TEST_ASSERT_LESS_OR_EQUAL_HEX32(*p0, *p2); +} + +void testNotLessOrEqualHEX32(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_LESS_OR_EQUAL_HEX32(0x00000000, 0xFFFFFFFF); + VERIFY_FAILS_END +} //----------------- void testEqualStrings(void) From 93405827974740ac5be4b3fa02b3b6fb7aa8ccdc Mon Sep 17 00:00:00 2001 From: Dom Postorivo Date: Mon, 15 Apr 2019 21:33:56 -0400 Subject: [PATCH 50/50] ARRAY_WITHIN in unity --- docs/UnityAssertionsReference.md | 37 +- src/unity.c | 110 +++ src/unity.h | 36 + src/unity_internals.h | 29 + test/tests/testunity.c | 1469 ++++++++++++++++++++++++++++++ 5 files changed, 1680 insertions(+), 1 deletion(-) diff --git a/docs/UnityAssertionsReference.md b/docs/UnityAssertionsReference.md index eb855f3..0f1aaa2 100644 --- a/docs/UnityAssertionsReference.md +++ b/docs/UnityAssertionsReference.md @@ -391,7 +391,6 @@ of 7 - 13. ##### `TEST_ASSERT_HEX64_WITHIN (delta, expected, actual)` - ### Structs and Strings ##### `TEST_ASSERT_EQUAL_PTR (expected, actual)` @@ -466,6 +465,42 @@ match. Failure messages specify the array index of the failed comparison. `len` is the memory in bytes to be compared at each array element. +### Integer Array Ranges (of all sizes) + +These assertions verify that the `expected` array parameter is within +/- `delta` +(inclusive) of the `actual` array parameter. For example, if the expected value is +\[10, 12\] and the delta is 3 then the assertion will fail for any value +outside the range of \[7 - 13, 9 - 15\]. + +##### `TEST_ASSERT_INT_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_INT8_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_INT16_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_INT32_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_INT64_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_UINT_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_UINT8_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_UINT16_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_UINT32_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_UINT64_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_HEX_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_HEX8_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_HEX16_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_HEX32_ARRAY_WITHIN (delta, expected, actual)` + +##### `TEST_ASSERT_HEX64_ARRAY_WITHIN (delta, expected, actual)` ### Each Equal (Arrays to Single Value) diff --git a/src/unity.c b/src/unity.c index 7ed85e0..3d090ee 100644 --- a/src/unity.c +++ b/src/unity.c @@ -1247,6 +1247,116 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta, } } +/*-----------------------------------------------*/ +void UnityAssertNumbersArrayWithin(const UNITY_UINT delta, + UNITY_INTERNAL_PTR expected, + UNITY_INTERNAL_PTR actual, + const UNITY_UINT32 num_elements, + const char* msg, + const UNITY_LINE_TYPE lineNumber, + const UNITY_DISPLAY_STYLE_T style, + const UNITY_FLAGS_T flags) +{ + UNITY_UINT32 elements = num_elements; + unsigned int length = style & 0xF; + + RETURN_IF_FAIL_OR_IGNORE; + if (num_elements == 0) + { + UnityPrintPointlessAndBail(); + } + + if (expected == actual) + { + return; /* Both are NULL or same pointer */ + } + + if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) + { + UNITY_FAIL_AND_BAIL; + } + + while ((elements > 0) && (elements--)) + { + UNITY_INT expect_val; + UNITY_INT actual_val; + + switch (length) + { + case 1: + expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected; + actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual; + break; + case 2: + expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected; + actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual; + break; +#ifdef UNITY_SUPPORT_64 + case 8: + expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected; + actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual; + break; +#endif + default: /* length 4 bytes */ + expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected; + actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual; + length = 4; + break; + } + + if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) + { + if (actual_val > expect_val) + { + Unity.CurrentTestFailed = (((UNITY_UINT)actual_val - (UNITY_UINT)expect_val) > delta); + } + else + { + Unity.CurrentTestFailed = (((UNITY_UINT)expect_val - (UNITY_UINT)actual_val) > delta); + } + } + else + { + if ((UNITY_UINT)actual_val > (UNITY_UINT)expect_val) + { + Unity.CurrentTestFailed = (((UNITY_UINT)actual_val - (UNITY_UINT)expect_val) > delta); + } + else + { + Unity.CurrentTestFailed = (((UNITY_UINT)expect_val - (UNITY_UINT)actual_val) > delta); + } + } + + if (Unity.CurrentTestFailed) + { + if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < sizeof(expect_val))) + { /* For UINT, remove sign extension (padding 1's) from signed type casts above */ + UNITY_INT mask = 1; + mask = (mask << 8 * length) - 1; + expect_val &= mask; + actual_val &= mask; + } + UnityTestResultsFailBegin(lineNumber); + UnityPrint(UnityStrDelta); + UnityPrintNumberByStyle((UNITY_INT)delta, style); + UnityPrint(UnityStrElement); + UnityPrintNumberUnsigned(num_elements - elements - 1); + UnityPrint(UnityStrExpected); + UnityPrintNumberByStyle(expect_val, style); + UnityPrint(UnityStrWas); + UnityPrintNumberByStyle(actual_val, style); + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } + if (flags == UNITY_ARRAY_TO_ARRAY) + { + expected = (UNITY_INTERNAL_PTR)(length + (const char*)expected); + } + actual = (UNITY_INTERNAL_PTR)(length + (const char*)actual); + } + +} + /*-----------------------------------------------*/ void UnityAssertEqualString(const char* expected, const char* actual, diff --git a/src/unity.h b/src/unity.h index a0c301d..f7f31a6 100644 --- a/src/unity.h +++ b/src/unity.h @@ -230,6 +230,24 @@ int suiteTearDown(int num_failures); #define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN((delta), (expected), (actual), __LINE__, NULL) +/* Integer Array Ranges (of all sizes) */ +#define TEST_ASSERT_INT_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_INT8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_INT16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_INT32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_INT64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_UINT_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_UINT8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_UINT16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_UINT32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_UINT64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_HEX_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_HEX8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_HEX16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_HEX32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) +#define TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) + + /* Structs and Strings */ #define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, NULL) @@ -422,6 +440,24 @@ int suiteTearDown(int num_failures); #define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN((delta), (expected), (actual), __LINE__, (message)) +/* Integer Array Ranges (of all sizes) */ +#define TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_INT32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_UINT32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_HEX_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) +#define TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) + + /* Structs and Strings */ #define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, (message)) diff --git a/src/unity_internals.h b/src/unity_internals.h index ad12fde..45cdd3f 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -579,6 +579,15 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); +void UnityAssertNumbersArrayWithin(const UNITY_UINT delta, + UNITY_INTERNAL_PTR expected, + UNITY_INTERNAL_PTR actual, + const UNITY_UINT32 num_elements, + const char* msg, + const UNITY_LINE_TYPE lineNumber, + const UNITY_DISPLAY_STYLE_T style, + const UNITY_FLAGS_T flags); + void UnityFail(const char* message, const UNITY_LINE_TYPE line); void UnityIgnore(const char* message, const UNITY_LINE_TYPE line); @@ -800,6 +809,20 @@ int UnityTestMatches(void); #define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT16)(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT16)(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT32)(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT32)(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) + +#define UNITY_TEST_ASSERT_INT_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT8 )(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT8 )(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_ARRAY) + + #define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((UNITY_PTR_TO_INT)(expected), (UNITY_PTR_TO_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER) #define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)(line)) #define UNITY_TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len, line, message) UnityAssertEqualStringLen((const char*)(expected), (const char*)(actual), (UNITY_UINT32)(len), (message), (UNITY_LINE_TYPE)(line)) @@ -860,6 +883,9 @@ int UnityTestMatches(void); #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) +#define UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_ARRAY) #else #define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) @@ -882,6 +908,9 @@ int UnityTestMatches(void); #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) +#define UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) +#define UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) +#define UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #endif #ifdef UNITY_EXCLUDE_FLOAT diff --git a/test/tests/testunity.c b/test/tests/testunity.c index bba555a..6675201 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -1318,8 +1318,1477 @@ void testINT8sNotWithinDeltaAndCustomMessage(void) VERIFY_FAILS_END } +//------------------------ + +void testInt64ArrayWithinDelta(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 expected[] = {12345000, -12344995, 12345005}; + UNITY_INT64 acutalSmallDelta[] = {12345001, -12344996, 12345005}; + UNITY_INT64 acutalBigDelta[] = {12345101, -12344896, 12345055}; + + TEST_ASSERT_INT64_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_INT64_ARRAY_WITHIN(110, expected, acutalBigDelta, 3); +#endif +} + +void testInt64ArrayWithinDeltaAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 expected[] = {12345000, -12344995, 12345005}; + UNITY_INT64 acutalSmallDelta[] = {12345001, -12344996, 12345005}; + UNITY_INT64 acutalBigDelta[] = {12345101, -12344896, 12345055}; + + TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 3, "Custom Message."); +#endif +} + +void tesUInt64ArrayNotWithinDelta(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 expected[] = {12345000, -12344995, 12345005}; + UNITY_INT64 acutalBigDelta[] = {12345101, -12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT64_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +#endif +} + +void testInt64ArrayNotWithinDeltaAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 expected[] = {12345000, -12344995, 12345005}; + UNITY_INT64 acutalBigDelta[] = {12345101, -12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testInt64ArrayWithinDeltaPointless(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 expected[] = {12345000, -12344995, 12345005}; + UNITY_INT64 acutalBigDelta[] = {12345101, -12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT64_ARRAY_WITHIN(110, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +#endif +} + +void testInt64ArrayWithinDeltaPointlessAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 expected[] = {12345000, -12344995, 12345005}; + UNITY_INT64 acutalBigDelta[] = {12345101, -12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testInt64ArrayWithinDeltaExpectedNull(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 acutalBigDelta[] = {12345101, -12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT64_ARRAY_WITHIN(110, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +#endif +} + +void testInt64ArrayWithinDeltaExpectedNullAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 acutalBigDelta[] = {12345101, -12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(110, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testInt64ArrayWithinDeltaActualNull(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 expected[] = {12345000, -12344995, 12345005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT64_ARRAY_WITHIN(110, expected, NULL, 3); + VERIFY_FAILS_END +#endif +} + +void testInt64ArrayWithinDeltaActualNullAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 expected[] = {12345000, -12344995, 12345005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testInt64ArrayWithinDeltaSamePointer(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 expected[] = {12345000, -12344995, 12345005}; + + TEST_ASSERT_UINT64_ARRAY_WITHIN(110, expected, expected, 3); +#endif +} + +void testInt64ArrayWithinDeltaSamePointerAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_INT64 expected[] = {12345000, -12344995, 12345005}; + + TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message."); +#endif +} + +void testIntArrayWithinDelta(void) +{ + UNITY_INT expected[] = {5000, -4995, 5005}; + UNITY_INT acutalSmallDelta[] = {5001, -4996, 5005}; + UNITY_INT acutalBigDelta[] = {5101, -4896, 5055}; + + TEST_ASSERT_INT_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_INT_ARRAY_WITHIN(110, expected, acutalBigDelta, 3); +} + +void testIntArrayWithinDeltaAndMessage(void) +{ + UNITY_INT expected[] = {5000, -4995, 5005}; + UNITY_INT acutalSmallDelta[] = {5001, -4996, 5005}; + UNITY_INT acutalBigDelta[] = {5101, -4896, 5055}; + + TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 3, "Custom Message."); +} + +void testIntArrayNotWithinDelta(void) +{ + UNITY_INT expected[] = {5000, -4995, 5005}; + UNITY_INT acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testIntArrayNotWithinDeltaAndMessage(void) +{ + UNITY_INT expected[] = {5000, -4995, 5005}; + UNITY_INT acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testIntArrayWithinDeltaPointless(void) +{ + UNITY_INT expected[] = {5000, -4995, 5005}; + UNITY_INT acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT_ARRAY_WITHIN(110, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +} + +void testIntArrayWithinDeltaPointlessAndMessage(void) +{ + UNITY_INT expected[] = {5000, -4995, 5005}; + UNITY_INT acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +} + +void testIntArrayWithinDeltaExpectedNull(void) +{ + UNITY_INT acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT_ARRAY_WITHIN(110, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testIntArrayWithinDeltaExpectedNullAndMessage(void) +{ + UNITY_INT acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(110, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testIntArrayWithinDeltaActualNull(void) +{ + UNITY_INT expected[] = {5000, -4995, 5005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT_ARRAY_WITHIN(110, expected, NULL, 3); + VERIFY_FAILS_END +} + +void testIntArrayWithinDeltaActualNullAndMessage(void) +{ + UNITY_INT expected[] = {5000, -4995, 5005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testIntArrayWithinDeltaSamePointer(void) +{ + UNITY_INT expected[] = {5000, -4995, 5005}; + + TEST_ASSERT_INT_ARRAY_WITHIN(110, expected, expected, 3); +} + +void testIntArrayWithinDeltaSamePointerAndMessage(void) +{ + UNITY_INT expected[] = {5000, -4995, 5005}; + + TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message."); +} + +void testInt16ArrayWithinDelta(void) +{ + UNITY_INT16 expected[] = {5000, -4995, 5005}; + UNITY_INT16 acutalSmallDelta[] = {5001, -4996, 5005}; + UNITY_INT16 acutalBigDelta[] = {5101, -4896, 5055}; + + TEST_ASSERT_INT16_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_INT16_ARRAY_WITHIN(110, expected, acutalBigDelta, 3); +} + +void testInt16ArrayWithinDeltaAndMessage(void) +{ + UNITY_INT16 expected[] = {5000, -4995, 5005}; + UNITY_INT16 acutalSmallDelta[] = {5001, -4996, 5005}; + UNITY_INT16 acutalBigDelta[] = {5101, -4896, 5055}; + + TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 3, "Custom Message."); +} + +void testInt16ArrayNotWithinDelta(void) +{ + UNITY_INT16 expected[] = {5000, -4995, 5005}; + UNITY_INT16 acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT16_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testInt16ArrayNotWithinDeltaAndMessage(void) +{ + UNITY_INT16 expected[] = {5000, -4995, 5005}; + UNITY_INT16 acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testInt16ArrayWithinDeltaPointless(void) +{ + UNITY_INT16 expected[] = {5000, -4995, 5005}; + UNITY_INT16 acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT16_ARRAY_WITHIN(110, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +} + +void testInt16ArrayWithinDeltaPointlessAndMessage(void) +{ + UNITY_INT16 expected[] = {5000, -4995, 5005}; + UNITY_INT16 acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +} + +void testInt16ArrayWithinDeltaExpectedNull(void) +{ + UNITY_INT16 acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT16_ARRAY_WITHIN(110, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testInt16ArrayWithinDeltaExpectedNullAndMessage(void) +{ + UNITY_INT16 acutalBigDelta[] = {5101, -4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(110, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testInt16ArrayWithinDeltaActualNull(void) +{ + UNITY_INT16 expected[] = {5000, -4995, 5005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT16_ARRAY_WITHIN(110, expected, NULL, 3); + VERIFY_FAILS_END +} + +void testInt16ArrayWithinDeltaActualNullAndMessage(void) +{ + UNITY_INT16 expected[] = {5000, -4995, 5005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testInt16ArrayWithinDeltaSamePointer(void) +{ + UNITY_INT16 expected[] = {5000, -4995, 5005}; + + TEST_ASSERT_INT16_ARRAY_WITHIN(110, expected, expected, 3); +} + +void testInt16ArrayWithinDeltaSamePointerAndMessage(void) +{ + UNITY_INT16 expected[] = {5000, -4995, 5005}; + + TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message."); +} + +void testInt8ArrayWithinDelta(void) +{ + UNITY_INT8 expected[] = {20, -95, 55}; + UNITY_INT8 acutalSmallDelta[] = {21, -94, 55}; + UNITY_INT8 acutalBigDelta[] = {11, -86, 45}; + + TEST_ASSERT_INT8_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_INT8_ARRAY_WITHIN(11, expected, acutalBigDelta, 3); +} + +void testInt8ArrayWithinDeltaAndMessage(void) +{ + UNITY_INT8 expected[] = {20, -95, 55}; + UNITY_INT8 acutalSmallDelta[] = {21, -94, 55}; + UNITY_INT8 acutalBigDelta[] = {11, -86, 45}; + + TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(11, expected, acutalBigDelta, 3, "Custom Message."); +} + +void testInt8ArrayNotWithinDelta(void) +{ + UNITY_INT8 expected[] = {20, -95, 55}; + UNITY_INT8 acutalBigDelta[] = {11, -86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT8_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testInt8ArrayNotWithinDeltaAndMessage(void) +{ + UNITY_INT8 expected[] = {20, -95, 55}; + UNITY_INT8 acutalBigDelta[] = {11, -86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testInt8ArrayWithinDeltaPointless(void) +{ + UNITY_INT8 expected[] = {20, -95, 55}; + UNITY_INT8 acutalBigDelta[] = {11, -86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT8_ARRAY_WITHIN(11, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +} + +void testInt8ArrayWithinDeltaPointlessAndMessage(void) +{ + UNITY_INT8 expected[] = {20, -95, 55}; + UNITY_INT8 acutalBigDelta[] = {11, -86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(11, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +} + +void testInt8ArrayWithinDeltaExpectedNull(void) +{ + UNITY_INT8 acutalBigDelta[] = {11, -86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT8_ARRAY_WITHIN(11, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testInt8ArrayWithinDeltaExpectedNullAndMessage(void) +{ + UNITY_INT8 acutalBigDelta[] = {11, -86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(11, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testInt8ArrayWithinDeltaActualNull(void) +{ + UNITY_INT8 expected[] = {20, -95, 55}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT8_ARRAY_WITHIN(11, expected, NULL, 3); + VERIFY_FAILS_END +} + +void testInt8ArrayWithinDeltaActualNullAndMessage(void) +{ + UNITY_INT8 expected[] = {20, -95, 55}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(11, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testInt8ArrayWithinDeltaSamePointer(void) +{ + UNITY_INT8 expected[] = {20, -95, 55}; + + TEST_ASSERT_INT8_ARRAY_WITHIN(11, expected, expected, 3); +} + +void testInt8ArrayWithinDeltaSamePointerAndMessage(void) +{ + UNITY_INT8 expected[] = {20, -95, 55}; + + TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(11, expected, expected, 3, "Custom Message."); +} + +void testUInt64ArrayWithinDelta(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {12345000, 12344995, 12345005}; + UNITY_UINT64 acutalSmallDelta[] = {12345001, 12344996, 12345005}; + UNITY_UINT64 acutalBigDelta[] = {12345101, 12344896, 12345055}; + + TEST_ASSERT_UINT64_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_UINT64_ARRAY_WITHIN(110, expected, acutalBigDelta, 3); +#endif +} + +void testUInt64ArrayWithinDeltaAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {12345000, 12344995, 12345005}; + UNITY_UINT64 acutalSmallDelta[] = {12345001, 12344996, 12345005}; + UNITY_UINT64 acutalBigDelta[] = {12345101, 12344896, 12345055}; + + TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 3, "Custom Message."); +#endif +} + +void testUInt64ArrayNotWithinDelta(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {12345000, 12344995, 12345005}; + UNITY_UINT64 acutalBigDelta[] = {12345101, 12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT64_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +#endif +} + +void testUInt64ArrayNotWithinDeltaAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {12345000, 12344995, 12345005}; + UNITY_UINT64 acutalBigDelta[] = {12345101, 12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testUInt64ArrayWithinDeltaPointless(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {12345000, 12344995, 12345005}; + UNITY_UINT64 acutalBigDelta[] = {12345101, 12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT64_ARRAY_WITHIN(110, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +#endif +} + +void testUInt64ArrayWithinDeltaPointlessAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {12345000, 12344995, 12345005}; + UNITY_UINT64 acutalBigDelta[] = {12345101, 12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testUInt64ArrayWithinDeltaExpectedNull(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 acutalBigDelta[] = {12345101, 12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT64_ARRAY_WITHIN(110, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +#endif +} + +void testUInt64ArrayWithinDeltaExpectedNullAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 acutalBigDelta[] = {12345101, 12344896, 12345055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(110, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testUInt64ArrayWithinDeltaActualNull(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {12345000, 12344995, 12345005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT64_ARRAY_WITHIN(110, expected, NULL, 3); + VERIFY_FAILS_END +#endif +} + +void testUInt64ArrayWithinDeltaActualNullAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {12345000, 12344995, 12345005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testUInt64ArrayWithinDeltaSamePointer(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {12345000, 12344995, 12345005}; + + TEST_ASSERT_UINT64_ARRAY_WITHIN(110, expected, expected, 3); +#endif +} + +void testUInt64ArrayWithinDeltaSamePointerAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {12345000, 12344995, 12345005}; + + TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message."); +#endif +} + +void testUIntArrayWithinDelta(void) +{ + UNITY_UINT expected[] = {125000, 124995, 125005}; + UNITY_UINT acutalSmallDelta[] = {125001, 124996, 125005}; + UNITY_UINT acutalBigDelta[] = {125101, 124896, 125055}; + + TEST_ASSERT_UINT_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_UINT_ARRAY_WITHIN(110, expected, acutalBigDelta, 3); +} + +void testUIntArrayWithinDeltaAndMessage(void) +{ + UNITY_UINT expected[] = {125000, 124995, 125005}; + UNITY_UINT acutalSmallDelta[] = {125001, 124996, 125005}; + UNITY_UINT acutalBigDelta[] = {125101, 124896, 125055}; + + TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 3, "Custom Message."); +} + +void testUIntArrayNotWithinDelta(void) +{ + UNITY_UINT expected[] = {125000, 124995, 125005}; + UNITY_UINT acutalBigDelta[] = {125101, 124896, 125055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testUIntArrayNotWithinDeltaAndMessage(void) +{ + UNITY_UINT expected[] = {125000, 124995, 125005}; + UNITY_UINT acutalBigDelta[] = {125101, 124896, 125055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testUIntArrayWithinDeltaPointless(void) +{ + UNITY_UINT expected[] = {125000, 124995, 125005}; + UNITY_UINT acutalBigDelta[] = {125101, 124896, 125055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT_ARRAY_WITHIN(110, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +} + +void testUIntArrayWithinDeltaPointlessAndMessage(void) +{ + UNITY_UINT expected[] = {125000, 124995, 125005}; + UNITY_UINT acutalBigDelta[] = {125101, 124896, 125055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +} + +void testUIntArrayWithinDeltaExpectedNull(void) +{ + UNITY_UINT acutalBigDelta[] = {125101, 124896, 125055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT_ARRAY_WITHIN(110, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testUIntArrayWithinDeltaExpectedNullAndMessage(void) +{ + UNITY_UINT acutalBigDelta[] = {125101, 124896, 125055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(110, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testUIntArrayWithinDeltaActualNull(void) +{ + UNITY_UINT expected[] = {125000, 124995, 125005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT_ARRAY_WITHIN(110, expected, NULL, 3); + VERIFY_FAILS_END +} + +void testUIntArrayWithinDeltaActualNullAndMessage(void) +{ + UNITY_UINT expected[] = {125000, 124995, 125005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testUIntArrayWithinDeltaSamePointer(void) +{ + UNITY_UINT expected[] = {125000, 124995, 125005}; + + TEST_ASSERT_UINT_ARRAY_WITHIN(110, expected, expected, 3); +} + +void testUIntArrayWithinDeltaSamePointerAndMessage(void) +{ + UNITY_UINT expected[] = {125000, 124995, 125005}; + + TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message."); +} + +void testUInt16ArrayWithinDelta(void) +{ + UNITY_UINT16 expected[] = {5000, 4995, 5005}; + UNITY_UINT16 acutalSmallDelta[] = {5001, 4996, 5005}; + UNITY_UINT16 acutalBigDelta[] = {5101, 4896, 5055}; + + TEST_ASSERT_UINT16_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_UINT16_ARRAY_WITHIN(110, expected, acutalBigDelta, 3); +} + +void testUInt16ArrayWithinDeltaAndMessage(void) +{ + UNITY_UINT16 expected[] = {5000, 4995, 5005}; + UNITY_UINT16 acutalSmallDelta[] = {5001, 4996, 5005}; + UNITY_UINT16 acutalBigDelta[] = {5101, 4896, 5055}; + + TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 3, "Custom Message."); +} + +void testUInt16ArrayNotWithinDelta(void) +{ + UNITY_UINT16 expected[] = {5000, 4995, 5005}; + UNITY_UINT16 acutalBigDelta[] = {5101, 4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT16_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testUInt16ArrayNotWithinDeltaAndMessage(void) +{ + UNITY_UINT16 expected[] = {5000, 4995, 5005}; + UNITY_UINT16 acutalBigDelta[] = {5101, 4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testUInt16ArrayWithinDeltaPointless(void) +{ + UNITY_UINT16 expected[] = {5000, 4995, 5005}; + UNITY_UINT16 acutalBigDelta[] = {5101, 4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT16_ARRAY_WITHIN(110, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +} + +void testUInt16ArrayWithinDeltaPointlessAndMessage(void) +{ + UNITY_UINT16 expected[] = {5000, 4995, 5005}; + UNITY_UINT16 acutalBigDelta[] = {5101, 4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +} + +void testUInt16ArrayWithinDeltaExpectedNull(void) +{ + UNITY_UINT16 acutalBigDelta[] = {5101, 4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT16_ARRAY_WITHIN(110, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testUInt16ArrayWithinDeltaExpectedNullAndMessage(void) +{ + UNITY_UINT16 acutalBigDelta[] = {5101, 4896, 5055}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(110, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testUInt16ArrayWithinDeltaActualNull(void) +{ + UNITY_UINT16 expected[] = {5000, 4995, 5005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT16_ARRAY_WITHIN(110, expected, NULL, 3); + VERIFY_FAILS_END +} + +void testUInt16ArrayWithinDeltaActualNullAndMessage(void) +{ + UNITY_UINT16 expected[] = {5000, 4995, 5005}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testUInt16ArrayWithinDeltaSamePointer(void) +{ + UNITY_UINT16 expected[] = {5000, 4995, 5005}; + + TEST_ASSERT_UINT16_ARRAY_WITHIN(110, expected, expected, 3); +} + +void testUInt16ArrayWithinDeltaSamePointerAndMessage(void) +{ + UNITY_UINT16 expected[] = {5000, 4995, 5005}; + + TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message."); +} + +void testUInt8ArrayWithinDelta(void) +{ + UNITY_UINT8 expected[] = {20, 95, 55}; + UNITY_UINT8 acutalSmallDelta[] = {21, 94, 55}; + UNITY_UINT8 acutalBigDelta[] = {11, 86, 45}; + + TEST_ASSERT_UINT8_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_UINT8_ARRAY_WITHIN(11, expected, acutalBigDelta, 3); +} + +void testUInt8ArrayWithinDeltaAndMessage(void) +{ + UNITY_UINT8 expected[] = {20, 95, 55}; + UNITY_UINT8 acutalSmallDelta[] = {21, 94, 55}; + UNITY_UINT8 acutalBigDelta[] = {11, 86, 45}; + + TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(11, expected, acutalBigDelta, 3, "Custom Message."); +} + +void testUInt8ArrayNotWithinDelta(void) +{ + UNITY_UINT8 expected[] = {20, 95, 55}; + UNITY_UINT8 acutalBigDelta[] = {11, 86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT8_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testUInt8ArrayNotWithinDeltaAndMessage(void) +{ + UNITY_UINT8 expected[] = {20, 95, 55}; + UNITY_UINT8 acutalBigDelta[] = {11, 86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testUInt8ArrayWithinDeltaPointless(void) +{ + UNITY_UINT8 expected[] = {20, 95, 55}; + UNITY_UINT8 acutalBigDelta[] = {11, 86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT8_ARRAY_WITHIN(11, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +} + +void testUInt8ArrayWithinDeltaPointlessAndMessage(void) +{ + UNITY_UINT8 expected[] = {20, 95, 55}; + UNITY_UINT8 acutalBigDelta[] = {11, 86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(11, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +} + +void testUInt8ArrayWithinDeltaExpectedNull(void) +{ + UNITY_UINT8 acutalBigDelta[] = {11, 86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT8_ARRAY_WITHIN(11, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testUInt8ArrayWithinDeltaExpectedNullAndMessage(void) +{ + UNITY_UINT8 acutalBigDelta[] = {11, 86, 45}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(11, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testUInt8ArrayWithinDeltaActualNull(void) +{ + UNITY_UINT8 expected[] = {20, 95, 55}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT8_ARRAY_WITHIN(11, expected, NULL, 3); + VERIFY_FAILS_END +} + +void testUInt8ArrayWithinDeltaActualNullAndMessage(void) +{ + UNITY_UINT8 expected[] = {20, 95, 55}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(11, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testUInt8ArrayWithinDeltaSamePointer(void) +{ + UNITY_UINT8 expected[] = {20, 95, 55}; + + TEST_ASSERT_UINT8_ARRAY_WITHIN(11, expected, expected, 3); +} + +void testUInt8ArrayWithinDeltaSamePointerAndMessage(void) +{ + UNITY_UINT8 expected[] = {20, 95, 55}; + + TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(11, expected, expected, 3, "Custom Message."); +} + + +void testHEX64ArrayWithinDelta(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT64 acutalSmallDelta[] = {0xABCD1235, 0xABCD1121, 0xABCD1277}; + UNITY_UINT64 acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + TEST_ASSERT_HEX64_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_HEX64_ARRAY_WITHIN(110, expected, acutalBigDelta, 3); +#endif +} + +void testHEX64ArrayWithinDeltaAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT64 acutalSmallDelta[] = {0xABCD1235, 0xABCD1121, 0xABCD1277}; + UNITY_UINT64 acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 3, "Custom Message."); +#endif +} + +void testHEX64ArrayNotWithinDelta(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT64 acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX64_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +#endif +} + +void testHEX64ArrayNotWithinDeltaAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT64 acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testHEX64ArrayWithinDeltaPointless(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT64 acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX64_ARRAY_WITHIN(110, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +#endif +} + +void testHEX64ArrayWithinDeltaPointlessAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT64 acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testHEX64ArrayWithinDeltaExpectedNull(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX64_ARRAY_WITHIN(110, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +#endif +} + +void testHEX64ArrayWithinDeltaExpectedNullAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(110, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testHEX64ArrayWithinDeltaActualNull(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX64_ARRAY_WITHIN(110, expected, NULL, 3); + VERIFY_FAILS_END +#endif +} + +void testHEX64ArrayWithinDeltaActualNullAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +#endif +} + +void testHEX64ArrayWithinDeltaSamePointer(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + + TEST_ASSERT_HEX64_ARRAY_WITHIN(110, expected, expected, 3); +#endif +} + +void testHEX64ArrayWithinDeltaSamePointerAndMessage(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + UNITY_UINT64 expected[] = {0xABCD11234, 0xABCD1122, 0xABCD1277}; + + TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message."); +#endif +} + + +void testHEX32ArrayWithinDelta(void) +{ + UNITY_UINT expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT acutalSmallDelta[] = {0xABCD1235, 0xABCD1121, 0xABCD1277}; + UNITY_UINT acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + TEST_ASSERT_HEX32_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_HEX32_ARRAY_WITHIN(110, expected, acutalBigDelta, 3); +} + +void testHEX32ArrayWithinDeltaAndMessage(void) +{ + UNITY_UINT expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT acutalSmallDelta[] = {0xABCD1235, 0xABCD1121, 0xABCD1277}; + UNITY_UINT acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 3, "Custom Message."); +} + +void testHEX32ArrayNotWithinDelta(void) +{ + UNITY_UINT expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX32_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testHEX32ArrayNotWithinDeltaAndMessage(void) +{ + UNITY_UINT expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX32ArrayWithinDeltaPointless(void) +{ + UNITY_UINT expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX32_ARRAY_WITHIN(110, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +} + +void testHEX32ArrayWithinDeltaPointlessAndMessage(void) +{ + UNITY_UINT expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + UNITY_UINT acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX32ArrayWithinDeltaExpectedNull(void) +{ + UNITY_UINT acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX32_ARRAY_WITHIN(110, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testHEX32ArrayWithinDeltaExpectedNullAndMessage(void) +{ + UNITY_UINT acutalBigDelta[] = {0xABCD1267, 0xABCD1188, 0xABCD12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(110, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX32ArrayWithinDeltaActualNull(void) +{ + UNITY_UINT expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX32_ARRAY_WITHIN(110, expected, NULL, 3); + VERIFY_FAILS_END +} + +void testHEX32ArrayWithinDeltaActualNullAndMessage(void) +{ + UNITY_UINT expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX32ArrayWithinDeltaSamePointer(void) +{ + UNITY_UINT expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + + TEST_ASSERT_HEX32_ARRAY_WITHIN(110, expected, expected, 3); +} + +void testHEX32ArrayWithinDeltaSamePointerAndMessage(void) +{ + UNITY_UINT expected[] = {0xABCD1234, 0xABCD1122, 0xABCD1277}; + + TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message."); +} + + +void testHEX16ArrayWithinDelta(void) +{ + UNITY_UINT16 expected[] = {0x1234, 0x1122, 0x1277}; + UNITY_UINT16 acutalSmallDelta[] = {0x1235, 0x1121, 0x1277}; + UNITY_UINT16 acutalBigDelta[] = {0x1267, 0x1188, 0x12AC}; + + TEST_ASSERT_HEX16_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_HEX16_ARRAY_WITHIN(110, expected, acutalBigDelta, 3); +} + +void testHEX16ArrayWithinDeltaAndMessage(void) +{ + UNITY_UINT16 expected[] = {0x1234, 0x1122, 0x1277}; + UNITY_UINT16 acutalSmallDelta[] = {0x1235, 0x1121, 0x1277}; + UNITY_UINT16 acutalBigDelta[] = {0x1267, 0x1188, 0x12AC}; + + TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 3, "Custom Message."); +} + +void testHEX16ArrayNotWithinDelta(void) +{ + UNITY_UINT16 expected[] = {0x1234, 0x1122, 0x1277}; + UNITY_UINT16 acutalBigDelta[] = {0x1267, 0x1188, 0x12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX16_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testHEX16ArrayNotWithinDeltaAndMessage(void) +{ + UNITY_UINT16 expected[] = {0x1234, 0x1122, 0x1277}; + UNITY_UINT16 acutalBigDelta[] = {0x1267, 0x1188, 0x12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX16ArrayWithinDeltaPointless(void) +{ + UNITY_UINT16 expected[] = {0x1234, 0x1122, 0x1277}; + UNITY_UINT16 acutalBigDelta[] = {0x1267, 0x1188, 0x12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX16_ARRAY_WITHIN(110, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +} + +void testHEX16ArrayWithinDeltaPointlessAndMessage(void) +{ + UNITY_UINT16 expected[] = {0x1234, 0x1122, 0x1277}; + UNITY_UINT16 acutalBigDelta[] = {0x1267, 0x1188, 0x12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(110, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX16ArrayWithinDeltaExpectedNull(void) +{ + UNITY_UINT16 acutalBigDelta[] = {0x1267, 0x1188, 0x12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX16_ARRAY_WITHIN(110, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testHEX16ArrayWithinDeltaExpectedNullAndMessage(void) +{ + UNITY_UINT16 acutalBigDelta[] = {0x1267, 0x1188, 0x12AC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(110, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX16ArrayWithinDeltaActualNull(void) +{ + UNITY_UINT16 expected[] = {0x1234, 0x1122, 0x1277}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX16_ARRAY_WITHIN(110, expected, NULL, 3); + VERIFY_FAILS_END +} + +void testHEX16ArrayWithinDeltaActualNullAndMessage(void) +{ + UNITY_UINT16 expected[] = {0x1234, 0x1122, 0x1277}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX16ArrayWithinDeltaSamePointer(void) +{ + UNITY_UINT16 expected[] = {0x1234, 0x1122, 0x1277}; + + TEST_ASSERT_HEX16_ARRAY_WITHIN(110, expected, expected, 3); +} + +void testHEX16ArrayWithinDeltaSamePointerAndMessage(void) +{ + UNITY_UINT16 expected[] = {0x1234, 0x1122, 0x1277}; + + TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message."); +} + +void testHEX8ArrayWithinDelta(void) +{ + UNITY_UINT8 expected[] = {0x34, 0x22, 0x77}; + UNITY_UINT8 acutalSmallDelta[] = {0x35, 0x21, 0x77}; + UNITY_UINT8 acutalBigDelta[] = {0x47, 0x48, 0x4C}; + + TEST_ASSERT_HEX8_ARRAY_WITHIN(1, expected, acutalSmallDelta, 3); + TEST_ASSERT_HEX8_ARRAY_WITHIN(60, expected, acutalBigDelta, 3); +} + +void testHEX8ArrayWithinDeltaAndMessage(void) +{ + UNITY_UINT8 expected[] = {0x34, 0x22, 0x77}; + UNITY_UINT8 acutalSmallDelta[] = {0x35, 0x21, 0x77}; + UNITY_UINT8 acutalBigDelta[] = {0x47, 0x48, 0x4C}; + + TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(1, expected, acutalSmallDelta, 3, "Custom Message."); + TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(60, expected, acutalBigDelta, 3, "Custom Message."); +} + +void testHEX8ArrayNotWithinDelta(void) +{ + UNITY_UINT8 expected[] = {0x34, 0x22, 0x77}; + UNITY_UINT8 acutalBigDelta[] = {0x67, 0x88, 0xAC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX8_ARRAY_WITHIN(1, expected, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testHEX8ArrayNotWithinDeltaAndMessage(void) +{ + UNITY_UINT8 expected[] = {0x34, 0x22, 0x77}; + UNITY_UINT8 acutalBigDelta[] = {0x67, 0x88, 0xAC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(1, expected, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX8ArrayWithinDeltaPointless(void) +{ + UNITY_UINT8 expected[] = {0x34, 0x22, 0x77}; + UNITY_UINT8 acutalBigDelta[] = {0x67, 0x88, 0xAC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX8_ARRAY_WITHIN(60, expected, acutalBigDelta, 0); + VERIFY_FAILS_END +} + +void testHEX8ArrayWithinDeltaPointlessAndMessage(void) +{ + UNITY_UINT8 expected[] = {0x34, 0x22, 0x77}; + UNITY_UINT8 acutalBigDelta[] = {0x67, 0x88, 0xAC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(60, expected, acutalBigDelta, 0, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX8ArrayWithinDeltaExpectedNull(void) +{ + UNITY_UINT8 acutalBigDelta[] = {0x67, 0x88, 0xAC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX8_ARRAY_WITHIN(60, NULL, acutalBigDelta, 3); + VERIFY_FAILS_END +} + +void testHEX8ArrayWithinDeltaExpectedNullAndMessage(void) +{ + UNITY_UINT8 acutalBigDelta[] = {0x67, 0x88, 0xAC}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(60, NULL, acutalBigDelta, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX8ArrayWithinDeltaActualNull(void) +{ + UNITY_UINT8 expected[] = {0x34, 0x22, 0x77}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX8_ARRAY_WITHIN(60, expected, NULL, 3); + VERIFY_FAILS_END +} + +void testHEX8ArrayWithinDeltaActualNullAndMessage(void) +{ + UNITY_UINT8 expected[] = {0x34, 0x22, 0x77}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(60, expected, NULL, 3, "Custom Message."); + VERIFY_FAILS_END +} + +void testHEX8ArrayWithinDeltaSamePointer(void) +{ + UNITY_UINT8 expected[] = {0x34, 0x22, 0x77}; + + TEST_ASSERT_HEX8_ARRAY_WITHIN(60, expected, expected, 3); +} + +void testHEX8ArrayWithinDeltaSamePointerAndMessage(void) +{ + UNITY_UINT8 expected[] = {0x34, 0x22, 0x77}; + + TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(60, expected, expected, 3, "Custom Message."); +} //----------------- + void testGreaterThan(void) { UNITY_INT v0, v1;