1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-25 17:31:36 +01:00

- added an "equal" check for floating point (where it checks that floats are within a significant digit of eachother)

- added array support for unknown types (memcompares)

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@45 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
mvandervoord
2009-11-03 01:15:54 +00:00
parent f5e2adcfdd
commit 6901c8eb04
3 changed files with 187 additions and 9 deletions

View File

@@ -321,7 +321,7 @@ void UnityAssertEqualUnsignedIntArray(const unsigned int* expected,
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityPrint("You asked me to compare 0 elements of an array, which was pointless.");
UnityPrint("You asked me to compare nothing, which was pointless.");
if (msg)
{
UnityPrintChar(' ');
@@ -363,13 +363,18 @@ void UnityAssertFloatsWithin(const float delta,
const unsigned short lineNumber)
{
float diff = actual - expected;
float pos_delta = delta;
if (diff < 0)
{
diff = -diff;
diff = 0.0f - diff;
}
if (delta < diff)
if (pos_delta < 0)
{
pos_delta = 0.0f - pos_delta;
}
if (pos_delta < diff)
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
@@ -484,7 +489,19 @@ void UnityAssertEqualMemory(const void* expected,
const unsigned short lineNumber)
{
if (length == 0)
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityPrint("You asked me to compare nothing, which was pointless.");
if (msg)
{
UnityPrintChar(' ');
UnityPrint(msg);
}
UnityPrintChar('\n');
return;
}
// if both pointers not null compare the memory
if (expected && actual)
@@ -515,6 +532,66 @@ void UnityAssertEqualMemory(const void* expected,
}
}
void UnityAssertEqualMemoryArray(const void* expected,
const void* actual,
unsigned long length,
unsigned long num_elements,
const char* msg,
const unsigned short lineNumber)
{
unsigned long elements = num_elements;
if ((elements == 0) || (length == 0))
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityPrint("You asked me to compare nothing, which was pointless.");
if (msg)
{
UnityPrintChar(' ');
UnityPrint(msg);
}
UnityPrintChar('\n');
return;
}
// if both pointers not null compare the memory
if (expected && actual)
{
while (elements--)
{
if (memcmp(expected, actual, length) != 0)
{
Unity.CurrentTestFailed = 1;
break;
}
expected += length;
actual += length;
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected != actual)
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsBegin(lineNumber);
UnityPrint("Element ");
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(" Memory Mismatch.");
if (msg)
{
UnityPrintChar(' ');
UnityPrint(msg);
}
UnityPrintChar('\n');
}
}
void UnityFail(const char* message, const long line)
{
Unity.CurrentTestFailed = 1;

View File

@@ -140,6 +140,13 @@ void UnityAssertEqualMemory(const void* expected,
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 UnityAssertFloatsWithin(const float delta,
const float expected,
const float actual,
@@ -306,6 +313,8 @@ void UnityIgnore(const char* message, const long line);
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 / 10000.0f, expected, actual, message)
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) TEST_ASSERT_FLOAT_WITHIN_MESSAGE((expected) / 10000.0f, expected, actual, NULL)
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
@@ -319,6 +328,12 @@ void UnityIgnore(const char* message, const long 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.TestFile=__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.TestFile=__FILE__; UnityFail((message), (unsigned short)__LINE__); TEST_ABORT(); }
#define TEST_IGNORE_MESSAGE(message) { Unity.TestFile=__FILE__; UnityIgnore((message), (unsigned short)__LINE__); TEST_ABORT(); }
#define TEST_IGNORE() TEST_IGNORE_MESSAGE(NULL)