mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-25 09:21:36 +01:00
- added 64 bit support
- organized targets into a subdirectory - cleaned up testing so floats and 64-bit ints are only tested if enabled git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@85 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
160
src/unity.c
160
src/unity.c
@@ -12,6 +12,7 @@
|
||||
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
|
||||
/// return prematurely if we are already in failure or ignore state
|
||||
#define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
|
||||
#define UNITY_PRINT_CR_LF { UNITY_OUTPUT_CHAR('\r'); UNITY_OUTPUT_CHAR('\n'); }
|
||||
|
||||
struct _Unity Unity = { 0 };
|
||||
|
||||
@@ -40,17 +41,27 @@ void UnityPrint(const char* string)
|
||||
while (*pch)
|
||||
{
|
||||
// printable characters plus CR & LF are printed
|
||||
if ( ((*pch <= 126) && (*pch >= 32)) || (*pch == 13) || (*pch == 10) )
|
||||
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('\\');
|
||||
UnityPrintNumber((_US32)*pch);
|
||||
UNITY_OUTPUT_CHAR('}');
|
||||
UnityPrintNumberHex((_U_SINT)*pch, 2);
|
||||
}
|
||||
pch++;
|
||||
}
|
||||
@@ -58,25 +69,29 @@ void UnityPrint(const char* string)
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintNumberByStyle(const _US32 number, const UNITY_DISPLAY_STYLE_T style)
|
||||
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
switch (style)
|
||||
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
|
||||
{
|
||||
case UNITY_DISPLAY_STYLE_HEX8: UnityPrintNumberHex((_UU32)number, 2); break;
|
||||
case UNITY_DISPLAY_STYLE_HEX16: UnityPrintNumberHex((_UU32)number, 4); break;
|
||||
case UNITY_DISPLAY_STYLE_HEX32: UnityPrintNumberHex((_UU32)number, 8); break;
|
||||
case UNITY_DISPLAY_STYLE_UINT: UnityPrintNumberUnsigned((_UU32)number); break;
|
||||
default: UnityPrintNumber(number); break;
|
||||
UnityPrintNumber(number);
|
||||
}
|
||||
else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
|
||||
{
|
||||
UnityPrintNumberUnsigned((_U_UINT)number);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityPrintNumberHex((_U_UINT)number, (style & 0x000F) << 1);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
/// basically do an itoa using as little ram as possible
|
||||
void UnityPrintNumber(const _US32 number_to_print)
|
||||
void UnityPrintNumber(const _U_SINT number_to_print)
|
||||
{
|
||||
_US32 divisor = 1;
|
||||
_US32 next_divisor;
|
||||
_US32 number = number_to_print;
|
||||
_U_SINT divisor = 1;
|
||||
_U_SINT next_divisor;
|
||||
_U_SINT number = number_to_print;
|
||||
|
||||
if (number < 0)
|
||||
{
|
||||
@@ -105,10 +120,10 @@ void UnityPrintNumber(const _US32 number_to_print)
|
||||
|
||||
//-----------------------------------------------
|
||||
/// basically do an itoa using as little ram as possible
|
||||
void UnityPrintNumberUnsigned(const _UU32 number)
|
||||
void UnityPrintNumberUnsigned(const _U_UINT number)
|
||||
{
|
||||
_UU32 divisor = 1;
|
||||
_UU32 next_divisor;
|
||||
_U_UINT divisor = 1;
|
||||
_U_UINT next_divisor;
|
||||
|
||||
// figure out initial divisor
|
||||
while (number / divisor > 9)
|
||||
@@ -130,9 +145,9 @@ void UnityPrintNumberUnsigned(const _UU32 number)
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintNumberHex(const _UU32 number, const char nibbles_to_print)
|
||||
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
|
||||
{
|
||||
_UU32 nibble;
|
||||
_U_UINT nibble;
|
||||
char nibbles = nibbles_to_print;
|
||||
UnityPrint("0x");
|
||||
|
||||
@@ -151,12 +166,12 @@ void UnityPrintNumberHex(const _UU32 number, const char nibbles_to_print)
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintMask(const _UU32 mask, const _UU32 number)
|
||||
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
|
||||
{
|
||||
_UU32 bit = 0x80000000;
|
||||
_U_UINT bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
|
||||
_US32 i;
|
||||
|
||||
for (i = 0; i < 32; i++)
|
||||
for (i = 0; i < UNITY_INT_WIDTH; i++)
|
||||
{
|
||||
if (bit & mask)
|
||||
{
|
||||
@@ -215,7 +230,8 @@ void UnityConcludeTest(void)
|
||||
else if (!Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
|
||||
UnityPrint("PASS\n");
|
||||
UnityPrint("PASS");
|
||||
UNITY_PRINT_CR_LF;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -299,9 +315,9 @@ int UnityCheckArraysForNull(const void* expected, const void* actual, const UNIT
|
||||
// Assertion Functions
|
||||
//-----------------------------------------------
|
||||
|
||||
void UnityAssertBits(const _US32 mask,
|
||||
const _US32 expected,
|
||||
const _US32 actual,
|
||||
void UnityAssertBits(const _U_SINT mask,
|
||||
const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
@@ -320,8 +336,8 @@ void UnityAssertBits(const _US32 mask,
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualNumber(const _US32 expected,
|
||||
const _US32 actual,
|
||||
void UnityAssertEqualNumber(const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
@@ -341,20 +357,16 @@ void UnityAssertEqualNumber(const _US32 expected,
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualIntArray(const int* expected,
|
||||
const int* actual,
|
||||
void UnityAssertEqualIntArray(const _U_SINT* expected,
|
||||
const _U_SINT* actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
_UU32 elements = num_elements;
|
||||
const _US32* ptr_exp32 = (_US32*)expected;
|
||||
const _US16* ptr_exp16 = (_US16*)expected;
|
||||
const _US8* ptr_exp8 = (_US8*)expected;
|
||||
const _US32* ptr_act32 = (_US32*)actual;
|
||||
const _US16* ptr_act16 = (_US16*)actual;
|
||||
const _US8* ptr_act8 = (_US8*)actual;
|
||||
const _US8* ptr_exp = (_US8*)expected;
|
||||
const _US8* ptr_act = (_US8*)actual;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
@@ -376,18 +388,20 @@ void UnityAssertEqualIntArray(const int* expected,
|
||||
case UNITY_DISPLAY_STYLE_UINT8:
|
||||
while (elements--)
|
||||
{
|
||||
if (*ptr_exp8++ != *ptr_act8++)
|
||||
if (*ptr_exp != *ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*--ptr_exp8, style);
|
||||
UnityPrintNumberByStyle(*ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*--ptr_act8, style);
|
||||
UnityPrintNumberByStyle(*ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 1;
|
||||
ptr_act += 1;
|
||||
}
|
||||
break;
|
||||
case UNITY_DISPLAY_STYLE_HEX16:
|
||||
@@ -395,35 +409,62 @@ void UnityAssertEqualIntArray(const int* expected,
|
||||
case UNITY_DISPLAY_STYLE_UINT16:
|
||||
while (elements--)
|
||||
{
|
||||
if (*ptr_exp16++ != *ptr_act16++)
|
||||
if (*(_US16*)ptr_exp != *(_US16*)ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*--ptr_exp16, style);
|
||||
UnityPrintNumberByStyle(*(_US16*)ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*--ptr_act16, style);
|
||||
UnityPrintNumberByStyle(*(_US16*)ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 2;
|
||||
ptr_act += 2;
|
||||
}
|
||||
break;
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
case UNITY_DISPLAY_STYLE_HEX64:
|
||||
case UNITY_DISPLAY_STYLE_INT64:
|
||||
case UNITY_DISPLAY_STYLE_UINT64:
|
||||
while (elements--)
|
||||
{
|
||||
if (*(_US64*)ptr_exp != *(_US64*)ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*(_US64*)ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*(_US64*)ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 8;
|
||||
ptr_act += 8;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
while (elements--)
|
||||
{
|
||||
if (*ptr_exp32++ != *ptr_act32++)
|
||||
if (*(_US32*)ptr_exp != *(_US32*)ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*--ptr_exp32, style);
|
||||
UnityPrintNumberByStyle(*(_US32*)ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*--ptr_act32, style);
|
||||
UnityPrintNumberByStyle(*(_US32*)ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 4;
|
||||
ptr_act += 4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -523,16 +564,16 @@ void UnityAssertFloatsWithin(const _UF delta,
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertNumbersWithin( const _US32 delta,
|
||||
const _US32 expected,
|
||||
const _US32 actual,
|
||||
void UnityAssertNumbersWithin( const _U_SINT delta,
|
||||
const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if (style == UNITY_DISPLAY_STYLE_INT)
|
||||
|
||||
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
|
||||
{
|
||||
if (actual > expected)
|
||||
Unity.CurrentTestFailed = ((actual - expected) > delta);
|
||||
@@ -541,10 +582,10 @@ void UnityAssertNumbersWithin( const _US32 delta,
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((_UU32)actual > (_UU32)expected)
|
||||
Unity.CurrentTestFailed = ((_UU32)(actual - expected) > (_UU32)delta);
|
||||
if ((_U_UINT)actual > (_U_UINT)expected)
|
||||
Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
|
||||
else
|
||||
Unity.CurrentTestFailed = ((_UU32)(expected - actual) > (_UU32)delta);
|
||||
Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
|
||||
}
|
||||
|
||||
if (Unity.CurrentTestFailed)
|
||||
@@ -757,19 +798,22 @@ void UnityBegin(void)
|
||||
//-----------------------------------------------
|
||||
void UnityEnd(void)
|
||||
{
|
||||
UnityPrint("-----------------------\n");
|
||||
UnityPrint("-----------------------");
|
||||
UNITY_PRINT_CR_LF;
|
||||
UnityPrintNumber(Unity.NumberOfTests);
|
||||
UnityPrint(" Tests ");
|
||||
UnityPrintNumber(Unity.TestFailures);
|
||||
UnityPrint(" Failures ");
|
||||
UnityPrintNumber(Unity.TestIgnores);
|
||||
UnityPrint(" Ignored\n");
|
||||
UnityPrint(" Ignored");
|
||||
UNITY_PRINT_CR_LF;
|
||||
if (Unity.TestFailures == 0U)
|
||||
{
|
||||
UnityPrint("OK\n");
|
||||
UnityPrint("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityPrint("FAIL\n");
|
||||
UnityPrint("FAIL");
|
||||
}
|
||||
UNITY_PRINT_CR_LF;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user