提交 e189a1b3 编写于 作者: M mvandervoord

- 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
上级 2051e500
......@@ -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)
{
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');
}
}
void UnityAssertEqualNumberUnsigned(const unsigned long expected,
const unsigned 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');
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);
}
if (delta < diff)
else
{
Unity.CurrentTestFailed = 1;
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Values not within delta.");
if (msg)
{
UNITY_OUTPUT_CHAR(' ');
UnityPrint(msg);
}
UNITY_OUTPUT_CHAR('\n');
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);
}
}
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)
if (Unity.CurrentTestFailed)
{
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');
}
}
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');
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
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);
......
此差异已折叠。
#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
......@@ -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};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册