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

- support arrays of integers

- fixed bug when reporting problems with large integers
- fixed bug in test suite when checking for expected failures.


git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@22 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
mvandervoord
2009-04-10 18:21:21 +00:00
parent 897d2a3746
commit 54eba93094
7 changed files with 348 additions and 66 deletions

View File

@@ -6,6 +6,15 @@
#include <stdio.h>
#include <setjmp.h>
//-------------------------------------------------------
// Internal Functions and Structs Needed For Unity To Run
//
// (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.)
//-------------------------------------------------------
typedef void (*UnityTestFunction)(void);
typedef enum
@@ -36,7 +45,7 @@ void CreateResults();
void UnityBegin();
void UnityEnd(void);
int UnityGetNumFailures(void);
long UnityGetNumFailures(void);
void UnityPrintChar(const char ch);
void UnityPrint(const char* string);
@@ -47,15 +56,22 @@ void UnityPrintNumberUnsigned(const unsigned long number);
void UnityPrintNumberHex(const unsigned long number, const char nibbles);
void UnityConcludeTest();
void UnityAssertEqualInt(const int expected,
const int actual,
void UnityAssertEqualInt(const long expected,
const long actual,
const char* msg,
const unsigned short lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertBits(const int mask,
const int expected,
const int actual,
void UnityAssertEqualIntArray(const long* expected,
const long* 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);
@@ -64,9 +80,9 @@ void UnityAssertEqualString(const char* expected,
const char* msg,
const unsigned short lineNumber );
void UnityAssertEqualMemory(void* expected,
void* actual,
unsigned int length,
void UnityAssertEqualMemory(const void* expected,
const void* actual,
unsigned long length,
const char* msg,
const unsigned short lineNumber );
@@ -76,15 +92,19 @@ void UnityAssertFloatsWithin(const float delta,
const char* msg,
const unsigned short lineNumber);
void UnityAssertIntsWithin(const int delta,
const int expected,
const int actual,
void UnityAssertIntsWithin(const long delta,
const long expected,
const long actual,
const char* msg,
const unsigned short lineNumber);
void UnityFail(const char* message, const int line);
void UnityFail(const char* message, const long line);
void UnityIgnore(const char* message, const int line);
void UnityIgnore(const char* message, const long line);
//-------------------------------------------------------
// Test Running Macros
//-------------------------------------------------------
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
@@ -99,6 +119,12 @@ void UnityIgnore(const char* message, const int line);
runTest(func); \
UnityConcludeTest();
//-------------------------------------------------------
// Test Asserts
//
// (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, NULL)
@@ -112,15 +138,20 @@ void UnityIgnore(const char* message, const int line);
#define TEST_ASSERT_FALSE(condition) TEST_ASSERT(!(condition))
#define TEST_ASSERT_NULL(pointer) TEST_ASSERT_MESSAGE(pointer == NULL, #pointer " was not null.")
#define TEST_ASSERT_NOT_NULL(pointer) TEST_ASSERT_MESSAGE(pointer != NULL, #pointer " was null.")
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_INT); \
UnityAssertEqualInt((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)
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) \
Unity.TestFile=__FILE__; \
UnityAssertEqualIntArray((long*)(expected), (long*)(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)
#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)
@@ -132,31 +163,49 @@ void UnityIgnore(const char* message, const int line);
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_UINT); \
UnityAssertEqualInt((long)(expected), (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)
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) \
Unity.TestFile=__FILE__; \
UnityAssertEqualIntArray((long*)(expected), (long*)(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)
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX8); \
UnityAssertEqualInt((long)(expected), (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)
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX16); \
UnityAssertEqualInt((long)(expected), (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)
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX32); \
UnityAssertEqualInt((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.TestFile=__FILE__; \
UnityAssertEqualIntArray((long*)(expected), (long*)(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.TestFile=__FILE__; \
UnityAssertEqualIntArray((long*)(expected), (long*)(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.TestFile=__FILE__; \
UnityAssertBits((mask), (expected), (actual), (message), (unsigned short)__LINE__); \