mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-28 10:44:26 +01:00
- happier with const (and more optimized on some compilers)
- better helper examples - general purpose memory compare git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@16 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
@@ -40,8 +40,6 @@ void AssertFloatArrayWithin(const float tolerance, const float* expected, const
|
||||
|
||||
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);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.x, actual.x, "Example Struct Failed For Field x");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.y, actual.y, "Example Struct Failed For Field y");
|
||||
}
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
#ifndef _TESTHELPER_H
|
||||
#define _TESTHELPER_H
|
||||
|
||||
typedef struct _EXAMPLE_STRUCT_T
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} EXAMPLE_STRUCT_T;
|
||||
#include "Types.h"
|
||||
|
||||
void AssertEqualUintArray(const unsigned int* expected, const unsigned int* actual, const unsigned int length);
|
||||
void AssertEqualIntArray(const int* expected, const int* actual, const unsigned int length);
|
||||
void AssertEqualCharArray(const char[] expected, const char actual[], const int 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);}
|
||||
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) {AssertEqualExampleStruct(expected, actual);}
|
||||
|
||||
#endif // _TESTHELPER_H
|
||||
|
||||
45
src/unity.c
45
src/unity.c
@@ -316,6 +316,51 @@ void UnityAssertEqualString(const char *expected,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UnityAssertEqualMemory(void *expected,
|
||||
void *actual,
|
||||
unsigned int length,
|
||||
const char *msg,
|
||||
unsigned short lineNumber)
|
||||
{
|
||||
unsigned int i;
|
||||
if (length == 0)
|
||||
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)
|
||||
{
|
||||
UnityTestResultsBegin(lineNumber);
|
||||
UnityPrint("Expected '");
|
||||
UnityPrint(expected);
|
||||
UnityPrint("' was '");
|
||||
UnityPrint(actual);
|
||||
UnityPrintChar('\'');
|
||||
UnityPrintChar('.');
|
||||
if (msg)
|
||||
{
|
||||
UnityPrintChar(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UnityPrintChar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void UnityFail(const char *message, const int line)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
|
||||
12
src/unity.h
12
src/unity.h
@@ -64,6 +64,12 @@ void UnityAssertEqualString(const char *expected,
|
||||
const char *msg,
|
||||
const unsigned short lineNumber );
|
||||
|
||||
void UnityAssertEqualMemory(void *expected,
|
||||
void *actual,
|
||||
unsigned int length,
|
||||
const char *msg,
|
||||
const unsigned short lineNumber );
|
||||
|
||||
void UnityAssertFloatsWithin(const float delta,
|
||||
const float expected,
|
||||
const float actual,
|
||||
@@ -193,6 +199,12 @@ void UnityIgnore(const char *message, const int 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.TestFile=__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_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)
|
||||
|
||||
Reference in New Issue
Block a user