mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-12-16 20:51:17 +08:00
Added support for 16-bit processors via BUS_WIDTH=16 preprocessor define. Defaults to 32-bit if unspecified.
Updated iar_msp430.yml to use full IAR MSP430 edition and use new BUS-WIDTH define. git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@40 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
119
src/unity.c
119
src/unity.c
@@ -204,7 +204,7 @@ void UnityAssertBits(const long mask,
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertEqualInt(const long expected,
|
||||
void UnityAssertEqualNumber(const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber,
|
||||
@@ -229,16 +229,92 @@ void UnityAssertEqualInt(const long expected,
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertEqualIntArray(const long* expected,
|
||||
const long* actual,
|
||||
void UnityAssertEqualNumberUnsigned(const unsigned long expected,
|
||||
const unsigned long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
if (expected != actual)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsBegin(lineNumber);
|
||||
UnityPrint("Expected ");
|
||||
UnityPrintNumberByStyle(expected, style);
|
||||
UnityPrint(" was ");
|
||||
UnityPrintNumberByStyle(actual, style);
|
||||
UnityPrintChar('.');
|
||||
if (msg)
|
||||
{
|
||||
UnityPrintChar(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UnityPrintChar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertEqualIntArray(const int* expected,
|
||||
const int* 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;
|
||||
const int* ptr_expected = expected;
|
||||
const int* 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 UnityAssertEqualUnsignedIntArray(const unsigned int* expected,
|
||||
const unsigned int* 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 unsigned int* ptr_expected = expected;
|
||||
const unsigned int* ptr_actual = actual;
|
||||
|
||||
if (elements == 0)
|
||||
{
|
||||
@@ -307,13 +383,13 @@ void UnityAssertFloatsWithin(const float delta,
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertIntsWithin(const long delta,
|
||||
void UnityAssertNumbersWithin(const long delta,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
{
|
||||
long diff = actual - expected;
|
||||
int diff = actual - expected;
|
||||
|
||||
if (diff < 0)
|
||||
{
|
||||
@@ -324,7 +400,29 @@ void UnityAssertIntsWithin(const long delta,
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
UnityTestResultsBegin(lineNumber);
|
||||
UnityPrint("Ints not within delta.");
|
||||
UnityPrint("Values not within delta.");
|
||||
if (msg)
|
||||
{
|
||||
UnityPrintChar(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UnityPrintChar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertNumbersUnsignedWithin(const unsigned long delta,
|
||||
const unsigned long expected,
|
||||
const unsigned long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
{
|
||||
unsigned int diff = actual - expected;
|
||||
|
||||
if (delta < diff)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
UnityTestResultsBegin(lineNumber);
|
||||
UnityPrint("Values not within delta.");
|
||||
if (msg)
|
||||
{
|
||||
UnityPrintChar(' ');
|
||||
@@ -455,8 +553,3 @@ void UnityEnd(void)
|
||||
UnityPrint("FAIL\n");
|
||||
}
|
||||
}
|
||||
|
||||
long UnityGetNumFailures(void)
|
||||
{
|
||||
return Unity.TestFailures;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user