mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-09-28 16:53:54 +08:00
- cleaned up Unity header file
- added macros to support more combinations - shrunk code size by reducing functions and macro sizes git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@62 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
412
src/unity.c
412
src/unity.c
@ -2,8 +2,26 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
|
||||
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
|
||||
|
||||
struct _Unity Unity = { 0 };
|
||||
|
||||
const char* UnityStrExpected = " Expected ";
|
||||
const char* UnityStrWas = " Was ";
|
||||
const char* UnityStrTo = " To ";
|
||||
const char* UnityStrElement = " Element ";
|
||||
const char* UnityStrMemory = " Memory Mismatch ";
|
||||
const char* UnityStrDelta = " Values Not Within Delta ";
|
||||
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless";
|
||||
const char* UnityStrSpacer = ". ";
|
||||
|
||||
void UnityAddMsgIfSpecified(const char* msg);
|
||||
|
||||
//-----------------------------------------------
|
||||
// Pretty Printers
|
||||
//-----------------------------------------------
|
||||
|
||||
void UnityPrint(const char* string)
|
||||
{
|
||||
unsigned char* pch = (unsigned char*)string;
|
||||
@ -22,11 +40,11 @@ void UnityPrintNumberByStyle(const long number, const UNITY_DISPLAY_STYLE_T styl
|
||||
{
|
||||
switch (style)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +108,7 @@ void UnityPrintNumberUnsigned(const unsigned long number)
|
||||
void UnityPrintNumberHex(const unsigned long number, const char nibbles_to_print)
|
||||
{
|
||||
unsigned long nibble;
|
||||
char nibbles = nibbles_to_print;
|
||||
char nibbles = nibbles_to_print;
|
||||
UnityPrint("0x");
|
||||
|
||||
while (nibbles > 0)
|
||||
@ -133,7 +151,7 @@ void UnityPrintMask(const unsigned long mask, const unsigned long number)
|
||||
}
|
||||
}
|
||||
|
||||
void UnityTestResultsBegin(const char* file, const long line)
|
||||
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
|
||||
{
|
||||
UnityPrint(file);
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
@ -143,9 +161,9 @@ void UnityTestResultsBegin(const char* file, const long line)
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
}
|
||||
|
||||
void UnityTestResultsFailBegin(const long line)
|
||||
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
|
||||
{
|
||||
UnityTestResultsBegin(Unity.AssertContainerFile, line);
|
||||
UnityTestResultsBegin(Unity.TestFile, line);
|
||||
UnityPrint("FAIL:");
|
||||
}
|
||||
|
||||
@ -169,78 +187,52 @@ void UnityConcludeTest()
|
||||
Unity.CurrentTestIgnored = 0;
|
||||
}
|
||||
|
||||
void UnityAddMsgIfSpecified(const char* msg)
|
||||
{
|
||||
if (msg)
|
||||
{
|
||||
UnityPrint(UnityStrSpacer);
|
||||
UnityPrint(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
// Assertion Functions
|
||||
//-----------------------------------------------
|
||||
|
||||
void UnityAssertBits(const long mask,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
if ((mask & expected) != (mask & actual))
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Expected ");
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintMask(mask, expected);
|
||||
UnityPrint(" was ");
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintMask(mask, actual);
|
||||
UNITY_OUTPUT_CHAR('.');
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertEqualNumber(const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
if (expected != actual)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Expected ");
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(expected, style);
|
||||
UnityPrint(" was ");
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(actual, style);
|
||||
UNITY_OUTPUT_CHAR('.');
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Expected ");
|
||||
UnityPrintNumberByStyle(expected, style);
|
||||
UnityPrint(" was ");
|
||||
UnityPrintNumberByStyle(actual, style);
|
||||
UNITY_OUTPUT_CHAR('.');
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,7 +240,7 @@ void UnityAssertEqualIntArray(const int* expected,
|
||||
const int* actual,
|
||||
const unsigned long num_elements,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
unsigned long elements = num_elements;
|
||||
@ -257,91 +249,25 @@ void UnityAssertEqualIntArray(const int* expected,
|
||||
|
||||
if (elements == 0)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("You asked me to compare 0 elements of an array, which was pointless.");
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
return;
|
||||
UnityPrint(UnityStrPointless);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
while (elements--)
|
||||
{
|
||||
if (*ptr_expected++ != *ptr_actual++)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Element ");
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(" Expected ");
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*--ptr_expected, style);
|
||||
UnityPrint(" was ");
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*--ptr_actual, style);
|
||||
UNITY_OUTPUT_CHAR('.');
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\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)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("You asked me to compare nothing, which was pointless.");
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
return;
|
||||
}
|
||||
|
||||
while (elements--)
|
||||
{
|
||||
if (*ptr_expected++ != *ptr_actual++)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Element ");
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(" Expected ");
|
||||
UnityPrintNumberByStyle(*--ptr_expected, style);
|
||||
UnityPrint(" was ");
|
||||
UnityPrintNumberByStyle(*--ptr_actual, style);
|
||||
UNITY_OUTPUT_CHAR('.');
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
return;
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -351,7 +277,7 @@ void UnityAssertFloatsWithin(const _UF delta,
|
||||
const _UF expected,
|
||||
const _UF actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
_UF diff = actual - expected;
|
||||
_UF pos_delta = delta;
|
||||
@ -367,72 +293,54 @@ void UnityAssertFloatsWithin(const _UF delta,
|
||||
|
||||
if (pos_delta < diff)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Floats not within delta.");
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
UnityPrint(UnityStrDelta);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void UnityAssertNumbersWithin(const long delta,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
void UnityAssertNumbersWithin( const long delta,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
int diff = actual - expected;
|
||||
|
||||
if (diff < 0)
|
||||
if (style == UNITY_DISPLAY_STYLE_INT)
|
||||
{
|
||||
diff = -diff;
|
||||
if (actual > expected)
|
||||
Unity.CurrentTestFailed = ((actual - expected) > delta);
|
||||
else
|
||||
Unity.CurrentTestFailed = ((expected - actual) > delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((unsigned long)actual > (unsigned long)expected)
|
||||
Unity.CurrentTestFailed = ((unsigned long)(actual - expected) > (unsigned long)delta);
|
||||
else
|
||||
Unity.CurrentTestFailed = ((unsigned long)(expected - actual) > (unsigned long)delta);
|
||||
}
|
||||
|
||||
if (delta < diff)
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Values not within delta.");
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\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;
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Values not within delta.");
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
UnityPrint(UnityStrDelta);
|
||||
UnityPrintNumberByStyle(delta, style);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(expected, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(actual, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertEqualString(const char* expected,
|
||||
const char* actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
unsigned long i;
|
||||
|
||||
@ -458,95 +366,35 @@ void UnityAssertEqualString(const char* expected,
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Expected '");
|
||||
UnityPrint(UnityStrExpected);
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
UnityPrint(expected);
|
||||
UnityPrint("' was '");
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
UnityPrint(UnityStrWas);
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
UnityPrint(actual);
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
UNITY_OUTPUT_CHAR('.');
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UnityAssertEqualMemory(const void* expected,
|
||||
const void* actual,
|
||||
unsigned long length,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
{
|
||||
if (length == 0)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("You asked me to compare nothing, which was pointless.");
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
return;
|
||||
}
|
||||
|
||||
// if both pointers not null compare the memory
|
||||
if (expected && actual)
|
||||
{
|
||||
if (memcmp(expected, actual, length) != 0)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // handle case of one pointers being null (if both null, test should pass)
|
||||
if (expected != actual)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Memory Mismatch.");
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void UnityAssertEqualMemoryArray(const void* expected,
|
||||
const void* actual,
|
||||
unsigned long length,
|
||||
unsigned long num_elements,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
void UnityAssertEqualMemory( const void* expected,
|
||||
const void* actual,
|
||||
unsigned long length,
|
||||
unsigned long num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
unsigned char* expected_ptr = (unsigned char*)expected;
|
||||
unsigned char* actual_ptr = (unsigned char*)actual;
|
||||
unsigned long elements = num_elements;
|
||||
if ((elements == 0) || (length == 0))
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("You asked me to compare nothing, which was pointless.");
|
||||
if (msg)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
return;
|
||||
UnityPrint(UnityStrPointless);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
// if both pointers not null compare the memory
|
||||
@ -574,42 +422,43 @@ void UnityAssertEqualMemoryArray(const void* expected,
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint("Element ");
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(" Memory Mismatch.");
|
||||
if (msg)
|
||||
if (num_elements > 1)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
UnityPrint(UnityStrMemory);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
void UnityFail(const char* message, const long line)
|
||||
//-----------------------------------------------
|
||||
// Control Functions
|
||||
//-----------------------------------------------
|
||||
|
||||
void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
UnityTestResultsBegin(Unity.AssertContainerFile, line);
|
||||
UnityTestResultsBegin(Unity.TestFile, line);
|
||||
UnityPrint("FAIL");
|
||||
if (message != NULL)
|
||||
if (msg != NULL)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
UnityPrint(message);
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
void UnityIgnore(const char* message, const long line)
|
||||
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
|
||||
{
|
||||
Unity.CurrentTestIgnored = 1;
|
||||
UnityTestResultsBegin(Unity.AssertContainerFile, line);
|
||||
UnityTestResultsBegin(Unity.TestFile, line);
|
||||
UnityPrint("IGNORE");
|
||||
if (message != NULL)
|
||||
if (msg != NULL)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
UnityPrint(message);
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_OUTPUT_CHAR('\n');
|
||||
UNITY_IGNORE_AND_BAIL;
|
||||
}
|
||||
|
||||
void UnityBegin()
|
||||
@ -619,6 +468,7 @@ void UnityBegin()
|
||||
|
||||
void UnityEnd(void)
|
||||
{
|
||||
UnityPrint("-----------------------\n");
|
||||
UnityPrintNumber(Unity.NumberOfTests);
|
||||
UnityPrint(" Tests ");
|
||||
UnityPrintNumber(Unity.TestFailures);
|
||||
|
433
src/unity.h
433
src/unity.h
@ -3,192 +3,26 @@
|
||||
|
||||
#define UNITY
|
||||
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
#include "unity_internals.h"
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Float Support
|
||||
//-------------------------------------------------------
|
||||
// define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
|
||||
// define UNITY_FLOAT_DELTA to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
|
||||
// define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
|
||||
|
||||
#ifndef UNITY_EXCLUDE_FLOAT
|
||||
#ifndef UNITY_FLOAT_PRECISION
|
||||
#define UNITY_FLOAT_PRECISION (0.00001f)
|
||||
#endif
|
||||
#ifndef UNITY_FLOAT_TYPE
|
||||
#define UNITY_FLOAT_TYPE float
|
||||
#endif
|
||||
typedef UNITY_FLOAT_TYPE _UF;
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Int Support
|
||||
//-------------------------------------------------------
|
||||
// Unity assumes 32 bit integers by default
|
||||
// If your compiler treats ints of a different size, define UNITY_INT_WIDTH
|
||||
|
||||
#ifndef UNITY_INT_WIDTH
|
||||
#define UNITY_INT_WIDTH (32)
|
||||
#endif
|
||||
#if (UNITY_INT_WIDTH == 32)
|
||||
typedef unsigned char _UU8;
|
||||
typedef unsigned short _UU16;
|
||||
typedef unsigned int _UU32;
|
||||
typedef signed char _US8;
|
||||
typedef signed short _US16;
|
||||
typedef signed int _US32;
|
||||
#elif (UNITY_INT_WIDTH == 16)
|
||||
typedef unsigned char _UU8;
|
||||
typedef unsigned int _UU16;
|
||||
typedef unsigned long _UU32;
|
||||
typedef signed char _US8;
|
||||
typedef signed int _US16;
|
||||
typedef signed long _US32;
|
||||
#else
|
||||
#error Invalid UNITY_INT_WIDTH specified! (32 or 16 only are currently supported)
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Output Method
|
||||
// Configuration Options
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_OUTPUT_CHAR
|
||||
#define UNITY_OUTPUT_CHAR(a) putchar(a)
|
||||
#endif
|
||||
// Integers
|
||||
// - Unity assumes 32 bit integers by default
|
||||
// - If your compiler treats ints of a different size, define UNITY_INT_WIDTH
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Internal Structs Needed
|
||||
//-------------------------------------------------------
|
||||
// Floats
|
||||
// - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
|
||||
// - define UNITY_FLOAT_DELTA to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
|
||||
// - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
|
||||
|
||||
typedef void (*UnityTestFunction)(void);
|
||||
// Output
|
||||
// - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UNITY_DISPLAY_STYLE_INT,
|
||||
UNITY_DISPLAY_STYLE_UINT,
|
||||
UNITY_DISPLAY_STYLE_HEX8,
|
||||
UNITY_DISPLAY_STYLE_HEX16,
|
||||
UNITY_DISPLAY_STYLE_HEX32
|
||||
} UNITY_DISPLAY_STYLE_T;
|
||||
|
||||
struct _Unity
|
||||
{
|
||||
const char* TestFile;
|
||||
const char* AssertContainerFile;
|
||||
const char* CurrentTestName;
|
||||
unsigned long CurrentTestLineNumber;
|
||||
unsigned char NumberOfTests;
|
||||
unsigned char TestFailures;
|
||||
unsigned char TestIgnores;
|
||||
unsigned char CurrentTestFailed;
|
||||
unsigned char CurrentTestIgnored;
|
||||
jmp_buf AbortFrame;
|
||||
};
|
||||
|
||||
extern struct _Unity Unity;
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Suite Management
|
||||
//-------------------------------------------------------
|
||||
|
||||
void UnityBegin(void);
|
||||
void UnityEnd(void);
|
||||
void UnityConcludeTest(void);
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Output
|
||||
//-------------------------------------------------------
|
||||
|
||||
void UnityPrint(const char* string);
|
||||
void UnityPrintMask(const unsigned long mask, const unsigned long number);
|
||||
void UnityPrintNumberByStyle(const long number, const UNITY_DISPLAY_STYLE_T style);
|
||||
void UnityPrintNumber(const long number);
|
||||
void UnityPrintNumberUnsigned(const unsigned long number);
|
||||
void UnityPrintNumberHex(const unsigned long number, const char nibbles);
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Assertion Fuctions
|
||||
//-------------------------------------------------------
|
||||
// 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.
|
||||
|
||||
void UnityAssertEqualNumber(const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityAssertEqualNumberUnsigned(const unsigned long expected,
|
||||
const unsigned long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
void UnityAssertBits(const long mask,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber);
|
||||
|
||||
void UnityAssertEqualString(const char* expected,
|
||||
const char* actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber );
|
||||
|
||||
void UnityAssertEqualMemory(const void* expected,
|
||||
const void* actual,
|
||||
unsigned long length,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber );
|
||||
|
||||
void UnityAssertEqualMemoryArray(const void* expected,
|
||||
const void* actual,
|
||||
unsigned long length,
|
||||
unsigned long num_elements,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber );
|
||||
|
||||
void UnityAssertNumbersWithin(const long delta,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber);
|
||||
|
||||
void UnityAssertNumbersUnsignedWithin(const unsigned long delta,
|
||||
const unsigned long expected,
|
||||
const unsigned long actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber);
|
||||
|
||||
void UnityFail(const char* message, const long line);
|
||||
|
||||
void UnityIgnore(const char* message, const long line);
|
||||
|
||||
#ifndef UNITY_EXCLUDE_FLOAT
|
||||
void UnityAssertFloatsWithin(const _UF delta,
|
||||
const _UF expected,
|
||||
const _UF actual,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber);
|
||||
#endif
|
||||
// Optimization
|
||||
// - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Running Macros
|
||||
@ -198,173 +32,120 @@ void UnityAssertFloatsWithin(const _UF delta,
|
||||
|
||||
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
|
||||
|
||||
#define ABORT_IF_NECESSARY() \
|
||||
if( Unity.CurrentTestFailed || Unity.CurrentTestIgnored ) {TEST_ABORT();}
|
||||
|
||||
#define RUN_TEST(func, line_num) \
|
||||
Unity.CurrentTestName = #func; \
|
||||
Unity.CurrentTestLineNumber = line_num; \
|
||||
Unity.NumberOfTests ++; \
|
||||
Unity.CurrentTestLineNumber = line_num; \
|
||||
Unity.NumberOfTests++; \
|
||||
runTest(func); \
|
||||
UnityConcludeTest();
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts
|
||||
// Basic Fail and Ignore
|
||||
//-------------------------------------------------------
|
||||
// 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, "Expectation Failed.")
|
||||
#define TEST_FAIL(message) UNITY_TEST_FAIL(__LINE__, message)
|
||||
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, message)
|
||||
#define TEST_IGNORE(message) UNITY_TEST_IGNORE(__LINE__, NULL)
|
||||
#define TEST_ONLY()
|
||||
|
||||
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) TEST_ASSERT_MESSAGE(condition, message)
|
||||
#define TEST_ASSERT_TRUE(condition) TEST_ASSERT_MESSAGE(condition, "Expected TRUE was FALSE.")
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts (simple)
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) TEST_ASSERT_MESSAGE(!(condition), message)
|
||||
#define TEST_ASSERT_UNLESS(condition) TEST_ASSERT(!(condition))
|
||||
//Boolean
|
||||
#define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE")
|
||||
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE")
|
||||
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE")
|
||||
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
|
||||
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected Null")
|
||||
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-Null")
|
||||
|
||||
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) TEST_ASSERT_MESSAGE(!(condition), message)
|
||||
#define TEST_ASSERT_FALSE(condition) TEST_ASSERT_MESSAGE(!(condition), "Expected FALSE was TRUE.")
|
||||
//Integers (of all sizes)
|
||||
#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Non-Eequal")
|
||||
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, NULL)
|
||||
|
||||
#define TEST_ASSERT_NULL(pointer) TEST_ASSERT_MESSAGE(pointer == NULL, #pointer " was not null.")
|
||||
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) TEST_ASSERT_MESSAGE(pointer == NULL, message)
|
||||
#define TEST_ASSERT_NOT_NULL(pointer) TEST_ASSERT_MESSAGE(pointer != NULL, #pointer " was null.")
|
||||
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) TEST_ASSERT_MESSAGE(pointer != NULL, message)
|
||||
//Integer Ranges (of all sizes)
|
||||
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualNumber((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)
|
||||
//Structs and Strings
|
||||
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualIntArray((const int*)(expected), (const int*)(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)
|
||||
//Arrays
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, 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)
|
||||
//Floating Point (If Enabled)
|
||||
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL)
|
||||
|
||||
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) TEST_ASSERT_FALSE_MESSAGE(((expected) == (actual)), (message))
|
||||
#define TEST_ASSERT_NOT_EQUAL(expected, actual) TEST_ASSERT_FALSE((expected) == (actual))
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts (with additional messages)
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertNumbersWithin((long)(delta), (long)(expected), (long)(actual), NULL, (unsigned short)__LINE__); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, NULL)
|
||||
//Boolean
|
||||
#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
|
||||
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
|
||||
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
|
||||
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
|
||||
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, message)
|
||||
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, message)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualNumberUnsigned((unsigned long)(expected), (unsigned 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)
|
||||
//Integers (of all sizes)
|
||||
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, message)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualUnsignedIntArray((const unsigned int*)(expected), (const unsigned int*)(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)
|
||||
//Integer Ranges (of all sizes)
|
||||
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualNumberUnsigned((unsigned long)(expected), (unsigned 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)
|
||||
//Structs and Strings
|
||||
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, message)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualNumberUnsigned((unsigned long)(expected), (unsigned 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)
|
||||
//Arrays
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, message)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualNumber((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.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualIntArray((const int*)(expected), (const int*)(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.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualIntArray((const int*)(expected), (const int*)(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.AssertContainerFile=__FILE__; \
|
||||
UnityAssertBits((mask), (expected), (actual), (message), (unsigned short)__LINE__); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_BITS(mask, expected, actual) TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertBits((mask), (-1), (actual), (message), (unsigned short)__LINE__); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_BITS_HIGH(mask, actual) TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertBits((mask), (0), (actual), (message), (unsigned short)__LINE__); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_BITS_LOW(mask, actual) TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertBits(((_UU32)1 << bit), (-1), (actual), (message), (unsigned short)__LINE__); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_BIT_HIGH(bit, actual) TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertBits(((_UU32)1 << bit), (0), (actual), (message), (unsigned short)__LINE__); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_BIT_LOW(bit, actual) TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualString((expected), (actual), (message), (unsigned short)__LINE__); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_STRING(expected, actual) TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualMemory((expected), (actual), (len), (message), (unsigned short)__LINE__); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, NULL)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertEqualMemoryArray((expected), (actual), (len), (num_elements), (message), (unsigned short)__LINE__); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, NULL)
|
||||
|
||||
#define TEST_FAIL(message) { Unity.AssertContainerFile=__FILE__; UnityFail((message), (unsigned short)__LINE__); TEST_ABORT(); }
|
||||
#define TEST_IGNORE_MESSAGE(message) { Unity.AssertContainerFile=__FILE__; UnityIgnore((message), (unsigned short)__LINE__); TEST_ABORT(); }
|
||||
#define TEST_IGNORE() TEST_IGNORE_MESSAGE(NULL)
|
||||
#define TEST_ONLY()
|
||||
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) TEST_FAIL("Unity Floating Point Disabled");
|
||||
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) TEST_FAIL("Unity Floating Point Disabled");
|
||||
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) TEST_FAIL("Unity Floating Point Disabled");
|
||||
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) TEST_FAIL("Unity Floating Point Disabled");
|
||||
#else
|
||||
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) \
|
||||
Unity.AssertContainerFile=__FILE__; \
|
||||
UnityAssertFloatsWithin((delta), (expected), (actual), (message), (unsigned short)__LINE__); \
|
||||
ABORT_IF_NECESSARY();
|
||||
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, NULL)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) TEST_ASSERT_FLOAT_WITHIN_MESSAGE((expected) * UNITY_FLOAT_PRECISION, expected, actual, message)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) TEST_ASSERT_FLOAT_WITHIN_MESSAGE((expected) * UNITY_FLOAT_PRECISION, expected, actual, NULL)
|
||||
#endif
|
||||
//Floating Point (If Enabled)
|
||||
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message)
|
||||
|
||||
#endif
|
||||
|
215
src/unity_internals.h
Normal file
215
src/unity_internals.h
Normal file
@ -0,0 +1,215 @@
|
||||
#ifndef UNITY_INTERNALS_H
|
||||
#define UNITY_INTERNALS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Int Support
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_INT_WIDTH
|
||||
#define UNITY_INT_WIDTH (32)
|
||||
#endif
|
||||
|
||||
#if (UNITY_INT_WIDTH == 32)
|
||||
typedef unsigned char _UU8;
|
||||
typedef unsigned short _UU16;
|
||||
typedef unsigned int _UU32;
|
||||
typedef signed char _US8;
|
||||
typedef signed short _US16;
|
||||
typedef signed int _US32;
|
||||
#elif (UNITY_INT_WIDTH == 16)
|
||||
typedef unsigned char _UU8;
|
||||
typedef unsigned int _UU16;
|
||||
typedef unsigned long _UU32;
|
||||
typedef signed char _US8;
|
||||
typedef signed int _US16;
|
||||
typedef signed long _US32;
|
||||
#else
|
||||
#error Invalid UNITY_INT_WIDTH specified! (32 or 16 only are currently supported)
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Float Support
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_EXCLUDE_FLOAT
|
||||
#ifndef UNITY_FLOAT_PRECISION
|
||||
#define UNITY_FLOAT_PRECISION (0.00001f)
|
||||
#endif
|
||||
#ifndef UNITY_FLOAT_TYPE
|
||||
#define UNITY_FLOAT_TYPE float
|
||||
#endif
|
||||
typedef UNITY_FLOAT_TYPE _UF;
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Output Method
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_OUTPUT_CHAR
|
||||
#define UNITY_OUTPUT_CHAR(a) putchar(a)
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Footprint
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_LINE_TYPE
|
||||
#define UNITY_LINE_TYPE unsigned short
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Internal Structs Needed
|
||||
//-------------------------------------------------------
|
||||
|
||||
typedef void (*UnityTestFunction)(void);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UNITY_DISPLAY_STYLE_INT,
|
||||
UNITY_DISPLAY_STYLE_UINT,
|
||||
UNITY_DISPLAY_STYLE_HEX8,
|
||||
UNITY_DISPLAY_STYLE_HEX16,
|
||||
UNITY_DISPLAY_STYLE_HEX32
|
||||
} UNITY_DISPLAY_STYLE_T;
|
||||
|
||||
struct _Unity
|
||||
{
|
||||
const char* TestFile;
|
||||
const char* CurrentTestName;
|
||||
unsigned long CurrentTestLineNumber;
|
||||
unsigned char NumberOfTests;
|
||||
unsigned char TestFailures;
|
||||
unsigned char TestIgnores;
|
||||
unsigned char CurrentTestFailed;
|
||||
unsigned char CurrentTestIgnored;
|
||||
jmp_buf AbortFrame;
|
||||
};
|
||||
|
||||
extern struct _Unity Unity;
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Suite Management
|
||||
//-------------------------------------------------------
|
||||
|
||||
void UnityBegin(void);
|
||||
void UnityEnd(void);
|
||||
void UnityConcludeTest(void);
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Output
|
||||
//-------------------------------------------------------
|
||||
|
||||
void UnityPrint(const char* string);
|
||||
void UnityPrintMask(const unsigned long mask, const unsigned long number);
|
||||
void UnityPrintNumberByStyle(const long number, const UNITY_DISPLAY_STYLE_T style);
|
||||
void UnityPrintNumber(const long number);
|
||||
void UnityPrintNumberUnsigned(const unsigned long number);
|
||||
void UnityPrintNumberHex(const unsigned long number, const char nibbles);
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Assertion Fuctions
|
||||
//-------------------------------------------------------
|
||||
// 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.
|
||||
|
||||
void UnityAssertEqualNumber(const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityAssertEqualIntArray(const int* expected,
|
||||
const int* actual,
|
||||
const unsigned long num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityAssertBits(const long mask,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertEqualString(const char* expected,
|
||||
const char* actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
|
||||
void UnityAssertEqualMemory( const void* expected,
|
||||
const void* actual,
|
||||
const unsigned long length,
|
||||
const unsigned long num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertNumbersWithin(const long delta,
|
||||
const long expected,
|
||||
const long actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
|
||||
|
||||
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
|
||||
|
||||
#ifndef UNITY_EXCLUDE_FLOAT
|
||||
void UnityAssertFloatsWithin(const _UF delta,
|
||||
const _UF expected,
|
||||
const _UF actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Basic Fail and Ignore
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define UNITY_TEST_FAIL(line, message) { UnityFail( (message), (UNITY_LINE_TYPE)line); }
|
||||
#define UNITY_TEST_IGNORE(line, message) { UnityIgnore( (message), (UNITY_LINE_TYPE)line); }
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, message);}
|
||||
#define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), message, (UNITY_LINE_TYPE)line)
|
||||
#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), message, (UNITY_LINE_TYPE)line)
|
||||
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((long)(expected), (long)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((long)(expected), (long)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((long)(expected), (long)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((long)(expected), (long)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((long)(expected), (long)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
|
||||
#define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((long)(mask), (long)(expected), (long)(actual), (message), (UNITY_LINE_TYPE)line)
|
||||
|
||||
#define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((long)(delta), (long)(expected), (long)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((long)(delta), (long)(expected), (long)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((long)(delta), (long)(expected), (long)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
|
||||
#define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((long)(delta), (long)(expected), (long)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
|
||||
#define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((long)(delta), (long)(expected), (long)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
|
||||
|
||||
#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_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (unsigned long)(len), 1, (message), (UNITY_LINE_TYPE)line)
|
||||
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const int*)(expected), (const int*)(actual), (unsigned long)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const int*)(expected), (const int*)(actual), (unsigned long)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const int*)(expected), (const int*)(actual), (unsigned long)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (unsigned long)(len), (unsigned long)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
||||
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
|
||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
|
||||
#else
|
||||
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
|
||||
#endif
|
||||
|
||||
#endif
|
250
test/testunity.c
250
test/testunity.c
@ -229,6 +229,24 @@ void testNotEqualHex8s(void)
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
|
||||
}
|
||||
|
||||
void testNotEqualHex8sIfSigned(void)
|
||||
{
|
||||
int failed;
|
||||
_US8 v0, v1;
|
||||
|
||||
v0 = -2;
|
||||
v1 = 2;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_HEX8(v0, v1);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
|
||||
}
|
||||
|
||||
void testNotEqualHex16s(void)
|
||||
{
|
||||
int failed;
|
||||
@ -247,6 +265,24 @@ void testNotEqualHex16s(void)
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
|
||||
}
|
||||
|
||||
void testNotEqualHex16sIfSigned(void)
|
||||
{
|
||||
int failed;
|
||||
_US16 v0, v1;
|
||||
|
||||
v0 = -1024;
|
||||
v1 = -1028;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_HEX16(v0, v1);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
|
||||
}
|
||||
|
||||
void testNotEqualHex32s(void)
|
||||
{
|
||||
int failed;
|
||||
@ -265,6 +301,24 @@ void testNotEqualHex32s(void)
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
|
||||
}
|
||||
|
||||
void testNotEqualHex32sIfSigned(void)
|
||||
{
|
||||
int failed;
|
||||
_US32 v0, v1;
|
||||
|
||||
v0 = -900000;
|
||||
v1 = 900001;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_HEX32(v0, v1);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
|
||||
}
|
||||
|
||||
void testEqualInts(void)
|
||||
{
|
||||
int v0, v1;
|
||||
@ -535,6 +589,10 @@ void testIntsWithinDelta(void)
|
||||
TEST_ASSERT_INT_WITHIN(5, 5000, 4996);
|
||||
TEST_ASSERT_INT_WITHIN(5, 5000, 5005);
|
||||
TEST_ASSERT_INT_WITHIN(500, 50, -440);
|
||||
|
||||
TEST_ASSERT_INT_WITHIN(2, 2147483647, -1);
|
||||
TEST_ASSERT_INT_WITHIN(5, 1, -1);
|
||||
TEST_ASSERT_INT_WITHIN(5, -1, 1);
|
||||
}
|
||||
|
||||
void testIntsNotWithinDelta(void)
|
||||
@ -551,6 +609,132 @@ void testIntsNotWithinDelta(void)
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testUIntsWithinDelta(void)
|
||||
{
|
||||
TEST_ASSERT_UINT_WITHIN(1, 5000, 5001);
|
||||
TEST_ASSERT_UINT_WITHIN(5, 5000, 4996);
|
||||
TEST_ASSERT_UINT_WITHIN(5, 5000, 5005);
|
||||
}
|
||||
|
||||
void testUIntsNotWithinDelta(void)
|
||||
{
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_UINT_WITHIN(1, 2147483647, 2147483649);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testUIntsNotWithinDeltaEvenThoughASignedIntWouldPassSmallFirst(void)
|
||||
{
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_UINT_WITHIN(5, 1, -1);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testUIntsNotWithinDeltaEvenThoughASignedIntWouldPassBigFirst(void)
|
||||
{
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_UINT_WITHIN(5, -1, 1);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testHEX32sWithinDelta(void)
|
||||
{
|
||||
TEST_ASSERT_HEX32_WITHIN(1, 5000, 5001);
|
||||
TEST_ASSERT_HEX32_WITHIN(5, 5000, 4996);
|
||||
TEST_ASSERT_HEX32_WITHIN(5, 5000, 5005);
|
||||
}
|
||||
|
||||
void testHEX32sNotWithinDelta(void)
|
||||
{
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_HEX32_WITHIN(1, 2147483647, 2147483649);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testHEX32sNotWithinDeltaEvenThoughASignedIntWouldPass(void)
|
||||
{
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_HEX32_WITHIN(5, 1, -1);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testHEX16sWithinDelta(void)
|
||||
{
|
||||
TEST_ASSERT_HEX16_WITHIN(1, 5000, 5001);
|
||||
TEST_ASSERT_HEX16_WITHIN(5, 5000, 4996);
|
||||
TEST_ASSERT_HEX16_WITHIN(5, 5000, 5005);
|
||||
}
|
||||
|
||||
void testHEX16sNotWithinDelta(void)
|
||||
{
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_HEX16_WITHIN(2, 65535, 0);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testHEX8sWithinDelta(void)
|
||||
{
|
||||
TEST_ASSERT_HEX8_WITHIN(1, 254, 255);
|
||||
TEST_ASSERT_HEX8_WITHIN(5, 251, 255);
|
||||
TEST_ASSERT_HEX8_WITHIN(5, 1, 4);
|
||||
}
|
||||
|
||||
void testHEX8sNotWithinDelta(void)
|
||||
{
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_HEX8_WITHIN(2, 255, 0);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testEqualStrings(void)
|
||||
{
|
||||
const char *testString = "foo";
|
||||
@ -831,6 +1015,72 @@ void testNotEqualUIntArrays3(void)
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
|
||||
void testEqualHEXArrays(void)
|
||||
{
|
||||
unsigned int p0[] = {1, 8, 987, 65132u};
|
||||
unsigned int p1[] = {1, 8, 987, 65132u};
|
||||
unsigned int p2[] = {1, 8, 987, 2};
|
||||
unsigned int p3[] = {1, 500, 600, 700};
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX_ARRAY(p0, p0, 1);
|
||||
TEST_ASSERT_EQUAL_HEX_ARRAY(p0, p0, 4);
|
||||
TEST_ASSERT_EQUAL_HEX_ARRAY(p0, p1, 4);
|
||||
TEST_ASSERT_EQUAL_HEX32_ARRAY(p0, p2, 3);
|
||||
TEST_ASSERT_EQUAL_HEX32_ARRAY(p0, p3, 1);
|
||||
}
|
||||
|
||||
void testNotEqualHEXArrays1(void)
|
||||
{
|
||||
unsigned int p0[] = {1, 8, 987, 65132u};
|
||||
unsigned int p1[] = {1, 8, 987, 65131u};
|
||||
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_HEX32_ARRAY(p0, p1, 4);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualHEXArrays2(void)
|
||||
{
|
||||
unsigned int p0[] = {1, 8, 987, 65132u};
|
||||
unsigned int p1[] = {2, 8, 987, 65132u};
|
||||
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_HEX32_ARRAY(p0, p1, 4);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testNotEqualHEXArrays3(void)
|
||||
{
|
||||
unsigned int p0[] = {1, 8, 987, 65132u};
|
||||
unsigned int p1[] = {1, 8, 986, 65132u};
|
||||
|
||||
int failed;
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_HEX_ARRAY(p0, p1, 4);
|
||||
EXPECT_ABORT_END
|
||||
|
||||
failed = Unity.CurrentTestFailed;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
|
||||
VERIFY_FAILURE_WAS_CAUGHT
|
||||
}
|
||||
|
||||
void testEqualMemoryArrays(void)
|
||||
{
|
||||
int p0[] = {1, 8, 987, -2};
|
||||
|
Reference in New Issue
Block a user