mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-12-19 07:18:10 +08:00
* update unity and helper to make names more consistent and to strictly make const interfaces.
git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@14 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
static char message[1024];
|
static char message[1024];
|
||||||
|
|
||||||
void AssertEqualArrayUint(unsigned int* expected, unsigned int* actual, unsigned int length)
|
void AssertEqualUintArray(const unsigned int* expected, const unsigned int* actual, const unsigned int length)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ void AssertEqualArrayUint(unsigned int* expected, unsigned int* actual, unsigned
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssertEqualArrayInt(int* expected, int* actual, unsigned int length)
|
void AssertEqualIntArray(const int* expected, const int* actual, const unsigned int length)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ void AssertEqualArrayInt(int* expected, int* actual, unsigned int length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssertEqualArrayFloatWithin(float tolerance, float* expected, float* actual, unsigned int length)
|
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
@@ -37,3 +37,11 @@ void AssertEqualArrayFloatWithin(float tolerance, float* expected, float* actual
|
|||||||
TEST_ASSERT_FLOAT_WITHIN_MESSAGE(tolerance, expected[i], actual[i], message);
|
TEST_ASSERT_FLOAT_WITHIN_MESSAGE(tolerance, expected[i], actual[i], message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual)
|
||||||
|
{
|
||||||
|
sprintf(message, "Example Struct Failed For Field x", i);
|
||||||
|
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.x, actual.x, message);
|
||||||
|
sprintf(message, "Example Struct Failed For Field y", i);
|
||||||
|
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.y, actual.y, message);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
#ifndef _TESTHELPER_H
|
#ifndef _TESTHELPER_H
|
||||||
#define _TESTHELPER_H
|
#define _TESTHELPER_H
|
||||||
|
|
||||||
void AssertEqualArrayUint(unsigned int* expected, unsigned int* actual, unsigned int length);
|
typedef struct _EXAMPLE_STRUCT_T
|
||||||
void AssertEqualArrayInt(int* expected, int* actual, unsigned int length);
|
{
|
||||||
void AssertEqualArrayFloatWithin(float tolerance, float* expected, float* actual, unsigned int length);
|
int x;
|
||||||
|
int y;
|
||||||
|
} EXAMPLE_STRUCT_T;
|
||||||
|
|
||||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, length) {AssertEqualArrayUint(expected, actual, length);}
|
void AssertEqualUintArray(const unsigned int* expected, const unsigned int* actual, const unsigned int length);
|
||||||
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, length) {AssertEqualArrayInt(expected, actual, length);}
|
void AssertEqualIntArray(const int* expected, const int* actual, const unsigned int length);
|
||||||
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) {AssertEqualArrayFloatWithin(tolerance, expected, actual, length);}
|
void AssertEqualCharArray(const char[] expected, const char actual[], const int length);
|
||||||
|
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length);
|
||||||
|
void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual);
|
||||||
|
|
||||||
|
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, length) {AssertEqualUintArray(expected, actual, length);}
|
||||||
|
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, length) {AssertEqualIntArray(expected, actual, length);}
|
||||||
|
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) {AssertFloatArrayWithin(tolerance, expected, actual, length);}
|
||||||
|
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT(expected, actual) {AssertEqualExampleStruct(expected, actual);}
|
||||||
#endif // _TESTHELPER_H
|
#endif // _TESTHELPER_H
|
||||||
|
|||||||
49
src/unity.c
49
src/unity.c
@@ -14,7 +14,7 @@ struct _Unity Unity =
|
|||||||
1e-4f,
|
1e-4f,
|
||||||
};
|
};
|
||||||
|
|
||||||
void UnityPrintChar(char ch)
|
void UnityPrintChar(const char ch)
|
||||||
{
|
{
|
||||||
putchar(ch);
|
putchar(ch);
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ void UnityPrint(const char *string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityPrintNumberByStyle(long number, UNITY_DISPLAY_STYLE_T style)
|
void UnityPrintNumberByStyle(const long number, const UNITY_DISPLAY_STYLE_T style)
|
||||||
{
|
{
|
||||||
switch (style)
|
switch (style)
|
||||||
{
|
{
|
||||||
@@ -46,9 +46,10 @@ void UnityPrintNumberByStyle(long number, UNITY_DISPLAY_STYLE_T style)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// basically do an itoa using as little ram as possible
|
/// basically do an itoa using as little ram as possible
|
||||||
void UnityPrintNumber(long number)
|
void UnityPrintNumber(const long number_to_print)
|
||||||
{
|
{
|
||||||
unsigned long divisor = 10;
|
unsigned long divisor = 10;
|
||||||
|
long number = number_to_print;
|
||||||
|
|
||||||
if (number < 0)
|
if (number < 0)
|
||||||
{
|
{
|
||||||
@@ -72,7 +73,7 @@ void UnityPrintNumber(long number)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// basically do an itoa using as little ram as possible
|
/// basically do an itoa using as little ram as possible
|
||||||
void UnityPrintNumberUnsigned(unsigned long number)
|
void UnityPrintNumberUnsigned(const unsigned long number)
|
||||||
{
|
{
|
||||||
unsigned long divisor = 10;
|
unsigned long divisor = 10;
|
||||||
|
|
||||||
@@ -91,9 +92,10 @@ void UnityPrintNumberUnsigned(unsigned long number)
|
|||||||
while (divisor > 1U);
|
while (divisor > 1U);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityPrintNumberHex(unsigned long number, char nibbles)
|
void UnityPrintNumberHex(const unsigned long number, const char nibbles_to_print)
|
||||||
{
|
{
|
||||||
unsigned long nibble;
|
unsigned long nibble;
|
||||||
|
char nibbles;
|
||||||
UnityPrint("0x");
|
UnityPrint("0x");
|
||||||
|
|
||||||
while (nibbles > 0)
|
while (nibbles > 0)
|
||||||
@@ -110,7 +112,7 @@ void UnityPrintNumberHex(unsigned long number, char nibbles)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityPrintMask(unsigned long mask, unsigned long number)
|
void UnityPrintMask(const unsigned long mask, const unsigned long number)
|
||||||
{
|
{
|
||||||
unsigned long bit = 0x00000001;
|
unsigned long bit = 0x00000001;
|
||||||
int i;
|
int i;
|
||||||
@@ -136,7 +138,7 @@ void UnityPrintMask(unsigned long mask, unsigned long number)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityTestResultsBegin(int line)
|
void UnityTestResultsBegin(const int line)
|
||||||
{
|
{
|
||||||
UnityPrint(Unity.TestFile);
|
UnityPrint(Unity.TestFile);
|
||||||
UnityPrintChar(':');
|
UnityPrintChar(':');
|
||||||
@@ -166,7 +168,11 @@ void UnityConcludeTest()
|
|||||||
Unity.CurrentTestIgnored = 0;
|
Unity.CurrentTestIgnored = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityAssertBits(int mask, int expected, int actual, const char *msg, unsigned short lineNumber)
|
void UnityAssertBits(const int mask,
|
||||||
|
const int expected,
|
||||||
|
const int actual,
|
||||||
|
const char *msg,
|
||||||
|
const unsigned short lineNumber)
|
||||||
{
|
{
|
||||||
if ((mask & expected) != (mask & actual))
|
if ((mask & expected) != (mask & actual))
|
||||||
{
|
{
|
||||||
@@ -187,7 +193,11 @@ void UnityAssertBits(int mask, int expected, int actual, const char *msg, unsign
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityAssertEqualInt(int expected, int actual, const char *msg, unsigned short lineNumber, UNITY_DISPLAY_STYLE_T style)
|
void UnityAssertEqualInt(const int expected,
|
||||||
|
const int actual,
|
||||||
|
const char *msg,
|
||||||
|
const unsigned short lineNumber,
|
||||||
|
const UNITY_DISPLAY_STYLE_T style)
|
||||||
{
|
{
|
||||||
if (expected != actual)
|
if (expected != actual)
|
||||||
{
|
{
|
||||||
@@ -208,7 +218,11 @@ void UnityAssertEqualInt(int expected, int actual, const char *msg, unsigned sho
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityAssertFloatsWithin(float delta, float expected, float actual, const char *msg, unsigned short lineNumber)
|
void UnityAssertFloatsWithin(const float delta,
|
||||||
|
const float expected,
|
||||||
|
const float actual,
|
||||||
|
const char *msg,
|
||||||
|
const unsigned short lineNumber)
|
||||||
{
|
{
|
||||||
float diff = actual - expected;
|
float diff = actual - expected;
|
||||||
|
|
||||||
@@ -231,7 +245,11 @@ void UnityAssertFloatsWithin(float delta, float expected, float actual, const ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityAssertIntsWithin(int delta, int expected, int actual, const char *msg, unsigned short lineNumber)
|
void UnityAssertIntsWithin(const int delta,
|
||||||
|
const int expected,
|
||||||
|
const int actual,
|
||||||
|
const char *msg,
|
||||||
|
const unsigned short lineNumber)
|
||||||
{
|
{
|
||||||
int diff = actual - expected;
|
int diff = actual - expected;
|
||||||
|
|
||||||
@@ -254,7 +272,10 @@ void UnityAssertIntsWithin(int delta, int expected, int actual, const char *msg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityAssertEqualString(const char *expected, const char *actual, const char *msg, unsigned short lineNumber)
|
void UnityAssertEqualString(const char *expected,
|
||||||
|
const char *actual,
|
||||||
|
const char *msg,
|
||||||
|
unsigned short lineNumber)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
@@ -295,7 +316,7 @@ void UnityAssertEqualString(const char *expected, const char *actual, const char
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityFail(const char *message, int line)
|
void UnityFail(const char *message, const int line)
|
||||||
{
|
{
|
||||||
Unity.CurrentTestFailed = 1;
|
Unity.CurrentTestFailed = 1;
|
||||||
UnityTestResultsBegin(line);
|
UnityTestResultsBegin(line);
|
||||||
@@ -303,7 +324,7 @@ void UnityFail(const char *message, int line)
|
|||||||
UnityPrintChar('\n');
|
UnityPrintChar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnityIgnore(const char *message, int line)
|
void UnityIgnore(const char *message, const int line)
|
||||||
{
|
{
|
||||||
Unity.CurrentTestIgnored = 1;
|
Unity.CurrentTestIgnored = 1;
|
||||||
UnityTestResultsBegin(line);
|
UnityTestResultsBegin(line);
|
||||||
|
|||||||
50
src/unity.h
50
src/unity.h
@@ -38,33 +38,47 @@ void UnityBegin();
|
|||||||
void UnityEnd(void);
|
void UnityEnd(void);
|
||||||
int UnityGetNumFailures(void);
|
int UnityGetNumFailures(void);
|
||||||
|
|
||||||
void UnityPrintChar(char ch);
|
void UnityPrintChar(const char ch);
|
||||||
void UnityPrint(const char *string);
|
void UnityPrint(const char *string);
|
||||||
void UnityPrintMask(unsigned long mask, unsigned long number);
|
void UnityPrintMask(const unsigned long mask, const unsigned long number);
|
||||||
void UnityPrintNumberByStyle(long number, UNITY_DISPLAY_STYLE_T style);
|
void UnityPrintNumberByStyle(const long number, const UNITY_DISPLAY_STYLE_T style);
|
||||||
void UnityPrintNumber(long number);
|
void UnityPrintNumber(const long number);
|
||||||
void UnityPrintNumberUnsigned(unsigned long number);
|
void UnityPrintNumberUnsigned(const unsigned long number);
|
||||||
void UnityPrintNumberHex(unsigned long number, char nibbles);
|
void UnityPrintNumberHex(const unsigned long number, const char nibbles);
|
||||||
void UnityConcludeTest();
|
void UnityConcludeTest();
|
||||||
|
|
||||||
void UnityAssertEqualInt(int expected, int actual,
|
void UnityAssertEqualInt(const int expected,
|
||||||
const char *msg, unsigned short lineNumber, UNITY_DISPLAY_STYLE_T style);
|
const int actual,
|
||||||
|
const char *msg,
|
||||||
|
const unsigned short lineNumber,
|
||||||
|
const UNITY_DISPLAY_STYLE_T style);
|
||||||
|
|
||||||
void UnityAssertBits(int mask, int expected, int actual,
|
void UnityAssertBits(const int mask,
|
||||||
const char *msg, unsigned short lineNumber);
|
const int expected,
|
||||||
|
const int actual,
|
||||||
|
const char *msg,
|
||||||
|
const unsigned short lineNumber);
|
||||||
|
|
||||||
void UnityAssertEqualString(const char *expected, const char *actual,
|
void UnityAssertEqualString(const char *expected,
|
||||||
const char *msg, unsigned short lineNumber );
|
const char *actual,
|
||||||
|
const char *msg,
|
||||||
|
const unsigned short lineNumber );
|
||||||
|
|
||||||
void UnityAssertFloatsWithin(float delta, float expected, float actual,
|
void UnityAssertFloatsWithin(const float delta,
|
||||||
const char *msg, unsigned short lineNumber);
|
const float expected,
|
||||||
|
const float actual,
|
||||||
|
const char *msg,
|
||||||
|
const unsigned short lineNumber);
|
||||||
|
|
||||||
void UnityAssertIntsWithin(int delta, int expected, int actual,
|
void UnityAssertIntsWithin(const int delta,
|
||||||
const char *msg, unsigned short lineNumber);
|
const int expected,
|
||||||
|
const int actual,
|
||||||
|
const char *msg,
|
||||||
|
const unsigned short lineNumber);
|
||||||
|
|
||||||
void UnityFail(const char *message, int line);
|
void UnityFail(const char *message, const int line);
|
||||||
|
|
||||||
void UnityIgnore(const char *message, int line);
|
void UnityIgnore(const char *message, const int line);
|
||||||
|
|
||||||
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
|
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user