mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-10-16 19:52:34 +08:00
- support arrays of integers
- fixed bug when reporting problems with large integers - fixed bug in test suite when checking for expected failures. git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@22 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
Binary file not shown.
Binary file not shown.
@ -147,6 +147,26 @@ TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message)
|
||||
|
||||
Another way of calling TEST_ASSERT_EQUAL_HEX32_MESSAGE
|
||||
|
||||
------------------------------------
|
||||
Numerical Assertions: Integer Arrays
|
||||
------------------------------------
|
||||
|
||||
TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements)
|
||||
|
||||
Compare two arrays for equality and display errors as signed integers.
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements)
|
||||
|
||||
Compare two arrays for equality and display errors as unsigned integers.
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements)
|
||||
|
||||
Compare two arrays for equality and display errors as 32-bit hex values.
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements)
|
||||
|
||||
Another way of calling TEST_ASSERT_EQUAL_HEX32_ARRAY.
|
||||
|
||||
-----------------------------
|
||||
Numerical Assertions: Bitwise
|
||||
-----------------------------
|
||||
|
131
src/unity.c
131
src/unity.c
@ -38,18 +38,19 @@ void UnityPrintNumberByStyle(const long number, const UNITY_DISPLAY_STYLE_T styl
|
||||
{
|
||||
switch (style)
|
||||
{
|
||||
case UNITY_DISPLAY_STYLE_HEX8: UnityPrintNumberHex(number,2); break;
|
||||
case UNITY_DISPLAY_STYLE_HEX16: UnityPrintNumberHex(number,4); break;
|
||||
case UNITY_DISPLAY_STYLE_HEX32: UnityPrintNumberHex(number,8); break;
|
||||
case UNITY_DISPLAY_STYLE_UINT: UnityPrintNumberUnsigned(number); break;
|
||||
default: UnityPrintNumber(number); break;
|
||||
case UNITY_DISPLAY_STYLE_HEX8: UnityPrintNumberHex((unsigned long)number, 2); break;
|
||||
case UNITY_DISPLAY_STYLE_HEX16: UnityPrintNumberHex((unsigned long)number, 4); break;
|
||||
case UNITY_DISPLAY_STYLE_HEX32: UnityPrintNumberHex((unsigned long)number, 8); break;
|
||||
case UNITY_DISPLAY_STYLE_UINT: UnityPrintNumberUnsigned((unsigned long)number); break;
|
||||
default: UnityPrintNumber(number); break;
|
||||
}
|
||||
}
|
||||
|
||||
/// basically do an itoa using as little ram as possible
|
||||
void UnityPrintNumber(const long number_to_print)
|
||||
{
|
||||
unsigned long divisor = 10;
|
||||
long divisor = 1;
|
||||
long next_divisor;
|
||||
long number = number_to_print;
|
||||
|
||||
if (number < 0)
|
||||
@ -59,38 +60,47 @@ void UnityPrintNumber(const long number_to_print)
|
||||
}
|
||||
|
||||
// figure out initial divisor
|
||||
while (number / divisor)
|
||||
while (number / divisor > 9)
|
||||
{
|
||||
divisor *= 10;
|
||||
next_divisor = divisor * 10;
|
||||
if (next_divisor > divisor)
|
||||
divisor = next_divisor;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// now divide number by divisor, mod and print, then divide divisor
|
||||
// now mod and print, then divide divisor
|
||||
do
|
||||
{
|
||||
divisor /= 10;
|
||||
UnityPrintChar((char)('0' + (number / divisor % 10)));
|
||||
divisor /= 10;
|
||||
}
|
||||
while (divisor > 1U);
|
||||
while (divisor > 0);
|
||||
}
|
||||
|
||||
/// basically do an itoa using as little ram as possible
|
||||
void UnityPrintNumberUnsigned(const unsigned long number)
|
||||
{
|
||||
unsigned long divisor = 10;
|
||||
unsigned long divisor = 1;
|
||||
unsigned long next_divisor;
|
||||
|
||||
// figure out initial divisor
|
||||
while (number / divisor)
|
||||
while (number / divisor > 9)
|
||||
{
|
||||
divisor *= 10;
|
||||
next_divisor = divisor * 10;
|
||||
if (next_divisor > divisor)
|
||||
divisor = next_divisor;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// now divide number by divisor, mod and print, then divide divisor
|
||||
// now mod and print, then divide divisor
|
||||
do
|
||||
{
|
||||
divisor /= 10;
|
||||
UnityPrintChar((char)('0' + (number / divisor % 10)));
|
||||
divisor /= 10;
|
||||
}
|
||||
while (divisor > 1U);
|
||||
while (divisor > 0);
|
||||
}
|
||||
|
||||
void UnityPrintNumberHex(const unsigned long number, const char nibbles_to_print)
|
||||
@ -116,7 +126,7 @@ void UnityPrintNumberHex(const unsigned long number, const char nibbles_to_print
|
||||
void UnityPrintMask(const unsigned long mask, const unsigned long number)
|
||||
{
|
||||
unsigned long bit = 0x00000001;
|
||||
int i;
|
||||
long i;
|
||||
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
@ -139,7 +149,7 @@ void UnityPrintMask(const unsigned long mask, const unsigned long number)
|
||||
}
|
||||
}
|
||||
|
||||
void UnityTestResultsBegin(const int line)
|
||||
void UnityTestResultsBegin(const long line)
|
||||
{
|
||||
UnityPrint(Unity.TestFile);
|
||||
UnityPrintChar(':');
|
||||
@ -169,9 +179,9 @@ void UnityConcludeTest()
|
||||
Unity.CurrentTestIgnored = 0;
|
||||
}
|
||||
|
||||
void UnityAssertBits(const int mask,
|
||||
const int expected,
|
||||
const int actual,
|
||||
void UnityAssertBits(const long mask,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
{
|
||||
@ -194,8 +204,8 @@ void UnityAssertBits(const int mask,
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertEqualInt(const int expected,
|
||||
const int actual,
|
||||
void UnityAssertEqualInt(const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
@ -219,6 +229,57 @@ void UnityAssertEqualInt(const int expected,
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertEqualIntArray(const long* expected,
|
||||
const long* actual,
|
||||
const unsigned long num_elements,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
unsigned long elements = num_elements;
|
||||
const long* ptr_expected = expected;
|
||||
const long* ptr_actual = actual;
|
||||
|
||||
if (elements == 0)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsBegin(lineNumber);
|
||||
UnityPrint("You asked me to compare 0 elements of an array, which was pointless.");
|
||||
if (msg)
|
||||
{
|
||||
UnityPrintChar(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UnityPrintChar('\n');
|
||||
return;
|
||||
}
|
||||
|
||||
while (elements--)
|
||||
{
|
||||
if (*ptr_expected++ != *ptr_actual++)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsBegin(lineNumber);
|
||||
UnityPrint("Element ");
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(" Expected ");
|
||||
UnityPrintNumberByStyle(*--ptr_expected, style);
|
||||
UnityPrint(" was ");
|
||||
UnityPrintNumberByStyle(*--ptr_actual, style);
|
||||
UnityPrintChar('.');
|
||||
if (msg)
|
||||
{
|
||||
UnityPrintChar(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UnityPrintChar('\n');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertFloatsWithin(const float delta,
|
||||
const float expected,
|
||||
const float actual,
|
||||
@ -246,13 +307,13 @@ void UnityAssertFloatsWithin(const float delta,
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertIntsWithin(const int delta,
|
||||
const int expected,
|
||||
const int actual,
|
||||
void UnityAssertIntsWithin(const long delta,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
{
|
||||
int diff = actual - expected;
|
||||
long diff = actual - expected;
|
||||
|
||||
if (diff < 0)
|
||||
{
|
||||
@ -278,7 +339,7 @@ void UnityAssertEqualString(const char* expected,
|
||||
const char* msg,
|
||||
unsigned short lineNumber)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned long i;
|
||||
|
||||
// if both pointers not null compare the strings
|
||||
if (expected && actual)
|
||||
@ -318,9 +379,9 @@ void UnityAssertEqualString(const char* expected,
|
||||
}
|
||||
|
||||
|
||||
void UnityAssertEqualMemory(void* expected,
|
||||
void* actual,
|
||||
unsigned int length,
|
||||
void UnityAssertEqualMemory(const void* expected,
|
||||
const void* actual,
|
||||
unsigned long length,
|
||||
const char* msg,
|
||||
unsigned short lineNumber)
|
||||
{
|
||||
@ -356,7 +417,7 @@ void UnityAssertEqualMemory(void* expected,
|
||||
}
|
||||
}
|
||||
|
||||
void UnityFail(const char* message, const int line)
|
||||
void UnityFail(const char* message, const long line)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
UnityTestResultsBegin(line);
|
||||
@ -364,7 +425,7 @@ void UnityFail(const char* message, const int line)
|
||||
UnityPrintChar('\n');
|
||||
}
|
||||
|
||||
void UnityIgnore(const char* message, const int line)
|
||||
void UnityIgnore(const char* message, const long line)
|
||||
{
|
||||
Unity.CurrentTestIgnored = 1;
|
||||
UnityTestResultsBegin(line);
|
||||
@ -395,7 +456,7 @@ void UnityEnd(void)
|
||||
}
|
||||
}
|
||||
|
||||
int UnityGetNumFailures(void)
|
||||
long UnityGetNumFailures(void)
|
||||
{
|
||||
return Unity.TestFailures;
|
||||
}
|
||||
|
89
src/unity.h
89
src/unity.h
@ -6,6 +6,15 @@
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Internal Functions and Structs Needed For Unity To Run
|
||||
//
|
||||
// (use the macros below this section instead of calling
|
||||
// these directly. The macros have a consistent naming
|
||||
// convention and will pull in file and line information
|
||||
// for you.)
|
||||
//-------------------------------------------------------
|
||||
|
||||
typedef void (*UnityTestFunction)(void);
|
||||
|
||||
typedef enum
|
||||
@ -36,7 +45,7 @@ void CreateResults();
|
||||
|
||||
void UnityBegin();
|
||||
void UnityEnd(void);
|
||||
int UnityGetNumFailures(void);
|
||||
long UnityGetNumFailures(void);
|
||||
|
||||
void UnityPrintChar(const char ch);
|
||||
void UnityPrint(const char* string);
|
||||
@ -47,15 +56,22 @@ void UnityPrintNumberUnsigned(const unsigned long number);
|
||||
void UnityPrintNumberHex(const unsigned long number, const char nibbles);
|
||||
void UnityConcludeTest();
|
||||
|
||||
void UnityAssertEqualInt(const int expected,
|
||||
const int actual,
|
||||
void UnityAssertEqualInt(const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityAssertBits(const int mask,
|
||||
const int expected,
|
||||
const int actual,
|
||||
void UnityAssertEqualIntArray(const long* expected,
|
||||
const long* actual,
|
||||
const unsigned long num_elements,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityAssertBits(const long mask,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber);
|
||||
|
||||
@ -64,9 +80,9 @@ void UnityAssertEqualString(const char* expected,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber );
|
||||
|
||||
void UnityAssertEqualMemory(void* expected,
|
||||
void* actual,
|
||||
unsigned int length,
|
||||
void UnityAssertEqualMemory(const void* expected,
|
||||
const void* actual,
|
||||
unsigned long length,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber );
|
||||
|
||||
@ -76,15 +92,19 @@ void UnityAssertFloatsWithin(const float delta,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber);
|
||||
|
||||
void UnityAssertIntsWithin(const int delta,
|
||||
const int expected,
|
||||
const int actual,
|
||||
void UnityAssertIntsWithin(const long delta,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber);
|
||||
|
||||
void UnityFail(const char* message, const int line);
|
||||
void UnityFail(const char* message, const long line);
|
||||
|
||||
void UnityIgnore(const char* message, const int line);
|
||||
void UnityIgnore(const char* message, const long line);
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Running Macros
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
|
||||
|
||||
@ -99,6 +119,12 @@ void UnityIgnore(const char* message, const int line);
|
||||
runTest(func); \
|
||||
UnityConcludeTest();
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts
|
||||
//
|
||||
// (these are the macros you are looking for)
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define TEST_ASSERT_MESSAGE(condition, message) if (condition) {} else {TEST_FAIL(message);}
|
||||
#define TEST_ASSERT(condition) TEST_ASSERT_MESSAGE(condition, NULL)
|
||||
|
||||
@ -112,15 +138,20 @@ void UnityIgnore(const char* message, const int line);
|
||||
#define TEST_ASSERT_FALSE(condition) TEST_ASSERT(!(condition))
|
||||
|
||||
#define TEST_ASSERT_NULL(pointer) TEST_ASSERT_MESSAGE(pointer == NULL, #pointer " was not null.")
|
||||
|
||||
#define TEST_ASSERT_NOT_NULL(pointer) TEST_ASSERT_MESSAGE(pointer != NULL, #pointer " was null.")
|
||||
|
||||
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) \
|
||||
Unity.TestFile=__FILE__; \
|
||||
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_INT); \
|
||||
UnityAssertEqualInt((long)(expected), (long)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_INT); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_INT(expected, actual) TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) \
|
||||
Unity.TestFile=__FILE__; \
|
||||
UnityAssertEqualIntArray((long*)(expected), (long*)(actual), (unsigned long)(num_elements), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_INT); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) TEST_ASSERT_EQUAL_INT_MESSAGE((expected), (actual), (message))
|
||||
#define TEST_ASSERT_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT(expected, actual)
|
||||
|
||||
@ -132,31 +163,49 @@ void UnityIgnore(const char* message, const int line);
|
||||
|
||||
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) \
|
||||
Unity.TestFile=__FILE__; \
|
||||
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_UINT); \
|
||||
UnityAssertEqualInt((long)(expected), (long)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_UINT); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_UINT(expected, actual) TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) \
|
||||
Unity.TestFile=__FILE__; \
|
||||
UnityAssertEqualIntArray((long*)(expected), (long*)(actual), (unsigned long)(num_elements), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_UINT); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) \
|
||||
Unity.TestFile=__FILE__; \
|
||||
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX8); \
|
||||
UnityAssertEqualInt((long)(expected), (long)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX8); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) \
|
||||
Unity.TestFile=__FILE__; \
|
||||
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX16); \
|
||||
UnityAssertEqualInt((long)(expected), (long)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX16); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) \
|
||||
Unity.TestFile=__FILE__; \
|
||||
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX32); \
|
||||
UnityAssertEqualInt((long)(expected), (long)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX32); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) \
|
||||
Unity.TestFile=__FILE__; \
|
||||
UnityAssertEqualIntArray((long*)(expected), (long*)(actual), (unsigned long)(num_elements), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX32); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX(expected, actual) TEST_ASSERT_EQUAL_HEX32(expected, actual)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) \
|
||||
Unity.TestFile=__FILE__; \
|
||||
UnityAssertEqualIntArray((long*)(expected), (long*)(actual), (unsigned long)(num_elements), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX32); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, NULL)
|
||||
|
||||
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) \
|
||||
Unity.TestFile=__FILE__; \
|
||||
UnityAssertBits((mask), (expected), (actual), (message), (unsigned short)__LINE__); \
|
||||
|
158
test/testunity.c
158
test/testunity.c
@ -12,6 +12,11 @@
|
||||
} \
|
||||
}
|
||||
|
||||
#define VERIFY_FAILURE_WAS_CAUGHT \
|
||||
EXPECT_ABORT_BEGIN \
|
||||
TEST_ASSERT_MESSAGE((1u == failed), "<---- [ This Test Should Have Failed But Did Not ]"); \
|
||||
EXPECT_ABORT_END
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
@ -264,6 +269,7 @@ void testEqualUints(void)
|
||||
TEST_ASSERT_EQUAL_UINT(*p0, v1);
|
||||
TEST_ASSERT_EQUAL_UINT(*p0, *p1);
|
||||
TEST_ASSERT_EQUAL_UINT(*p0, 19467);
|
||||
TEST_ASSERT_EQUAL_UINT(4294967295ul, 4294967295ul);
|
||||
}
|
||||
|
||||
void testEqualHex8s(void)
|
||||
@ -446,7 +452,7 @@ void testFloatsNotWithinDelta(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testIntsWithinDelta(void)
|
||||
@ -468,7 +474,7 @@ void testIntsNotWithinDelta(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testEqualStrings(void)
|
||||
@ -494,7 +500,7 @@ void testNotEqualString1(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualString2(void)
|
||||
@ -508,7 +514,7 @@ void testNotEqualString2(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualString3(void)
|
||||
@ -522,7 +528,7 @@ void testNotEqualString3(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualString_ExpectedStringIsNull(void)
|
||||
@ -536,7 +542,7 @@ void testNotEqualString_ExpectedStringIsNull(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualString_ActualStringIsNull(void)
|
||||
@ -550,7 +556,7 @@ void testNotEqualString_ActualStringIsNull(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testEqualMemory(void)
|
||||
@ -577,7 +583,7 @@ void testNotEqualMemory1(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualMemory2(void)
|
||||
@ -591,7 +597,7 @@ void testNotEqualMemory2(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualMemory3(void)
|
||||
@ -605,7 +611,7 @@ void testNotEqualMemory3(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualMemory4(void)
|
||||
@ -619,7 +625,137 @@ void testNotEqualMemory4(void)
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testEqualIntArrays(void)
|
||||
{
|
||||
int p0[] = {1, 8, 987, -2};
|
||||
int p1[] = {1, 8, 987, -2};
|
||||
int p2[] = {1, 8, 987, 2};
|
||||
int p3[] = {1, 500, 600, 700};
|
||||
|
||||
TEST_ASSERT_EQUAL_INT_ARRAY(p0, p0, 1);
|
||||
TEST_ASSERT_EQUAL_INT_ARRAY(p0, p0, 4);
|
||||
TEST_ASSERT_EQUAL_INT_ARRAY(p0, p1, 4);
|
||||
TEST_ASSERT_EQUAL_INT_ARRAY(p0, p2, 3);
|
||||
TEST_ASSERT_EQUAL_INT_ARRAY(p0, p3, 1);
|
||||
}
|
||||
|
||||
void testNotEqualIntArrays1(void)
|
||||
{
|
||||
int p0[] = {1, 8, 987, -2};
|
||||
int p1[] = {1, 8, 987, 2};
|
||||
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_INT_ARRAY(p0, p1, 4);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualIntArrays2(void)
|
||||
{
|
||||
int p0[] = {1, 8, 987, -2};
|
||||
int p1[] = {2, 8, 987, -2};
|
||||
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_INT_ARRAY(p0, p1, 4);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualIntArrays3(void)
|
||||
{
|
||||
int p0[] = {1, 8, 987, -2};
|
||||
int p1[] = {1, 8, 986, -2};
|
||||
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_INT_ARRAY(p0, p1, 4);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testEqualUIntArrays(void)
|
||||
{
|
||||
unsigned int p0[] = {1, 8, 987, 4294967295ul};
|
||||
unsigned int p1[] = {1, 8, 987, 4294967295ul};
|
||||
unsigned int p2[] = {1, 8, 987, 2};
|
||||
unsigned int p3[] = {1, 500, 600, 700};
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT_ARRAY(p0, p0, 1);
|
||||
TEST_ASSERT_EQUAL_UINT_ARRAY(p0, p0, 4);
|
||||
TEST_ASSERT_EQUAL_UINT_ARRAY(p0, p1, 4);
|
||||
TEST_ASSERT_EQUAL_UINT_ARRAY(p0, p2, 3);
|
||||
TEST_ASSERT_EQUAL_UINT_ARRAY(p0, p3, 1);
|
||||
}
|
||||
|
||||
void testNotEqualUIntArrays1(void)
|
||||
{
|
||||
unsigned int p0[] = {1, 8, 987, 4294967295ul};
|
||||
unsigned int p1[] = {1, 8, 987, 4294967294ul};
|
||||
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_UINT_ARRAY(p0, p1, 4);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualUIntArrays2(void)
|
||||
{
|
||||
unsigned int p0[] = {1, 8, 987, 4294967295ul};
|
||||
unsigned int p1[] = {2, 8, 987, 4294967295ul};
|
||||
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_UINT_ARRAY(p0, p1, 4);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualUIntArrays3(void)
|
||||
{
|
||||
unsigned int p0[] = {1, 8, 987, 4294967295ul};
|
||||
unsigned int p1[] = {1, 8, 986, 4294967295ul};
|
||||
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_UINT_ARRAY(p0, p1, 4);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testProtection(void)
|
||||
|
@ -48,6 +48,14 @@ void testNotEqualMemory1(void);
|
||||
void testNotEqualMemory2(void);
|
||||
void testNotEqualMemory3(void);
|
||||
void testNotEqualMemory4(void);
|
||||
void testEqualIntArrays(void);
|
||||
void testNotEqualIntArrays1(void);
|
||||
void testNotEqualIntArrays2(void);
|
||||
void testNotEqualIntArrays3(void);
|
||||
void testEqualUIntArrays(void);
|
||||
void testNotEqualUIntArrays1(void);
|
||||
void testNotEqualUIntArrays2(void);
|
||||
void testNotEqualUIntArrays3(void);
|
||||
void testProtection(void);
|
||||
|
||||
|
||||
@ -113,6 +121,14 @@ int main(void)
|
||||
RUN_TEST(testNotEqualMemory2);
|
||||
RUN_TEST(testNotEqualMemory3);
|
||||
RUN_TEST(testNotEqualMemory4);
|
||||
RUN_TEST(testEqualIntArrays);
|
||||
RUN_TEST(testNotEqualIntArrays1);
|
||||
RUN_TEST(testNotEqualIntArrays2);
|
||||
RUN_TEST(testNotEqualIntArrays3);
|
||||
RUN_TEST(testEqualUIntArrays);
|
||||
RUN_TEST(testNotEqualUIntArrays1);
|
||||
RUN_TEST(testNotEqualUIntArrays2);
|
||||
RUN_TEST(testNotEqualUIntArrays3);
|
||||
RUN_TEST(testProtection);
|
||||
|
||||
UnityEnd();
|
||||
|
Reference in New Issue
Block a user