提交 9909bfe2 编写于 作者: M mkarlesky

robustified null pointer handling for array handling

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@78 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
上级 2b881e22
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
struct _Unity Unity = { 0 }; struct _Unity Unity = { 0 };
const char* UnityStrNull = "NULL"; const char* UnityStrNull = "NULL";
const char* UnityStrSpacer = ". ";
const char* UnityStrExpected = " Expected "; const char* UnityStrExpected = " Expected ";
const char* UnityStrWas = " Was "; const char* UnityStrWas = " Was ";
const char* UnityStrTo = " To "; const char* UnityStrTo = " To ";
...@@ -21,7 +22,8 @@ const char* UnityStrElement = " Element "; ...@@ -21,7 +22,8 @@ const char* UnityStrElement = " Element ";
const char* UnityStrMemory = " Memory Mismatch"; const char* UnityStrMemory = " Memory Mismatch";
const char* UnityStrDelta = " Values Not Within Delta "; const char* UnityStrDelta = " Values Not Within Delta ";
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless."; const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
const char* UnityStrSpacer = ". "; const char* UnityStrNullPointerForExpected= " Expected value pointer dereferenced NULL";
const char* UnityStrNullPointerForActual = " Actual value pointer dereferenced NULL";
//----------------------------------------------- //-----------------------------------------------
// Pretty Printers // Pretty Printers
...@@ -36,7 +38,7 @@ void UnityPrint(const char* string) ...@@ -36,7 +38,7 @@ void UnityPrint(const char* string)
while (*pch) while (*pch)
{ {
// printable characters plus CR & LF are printed // printable characters plus CR & LF are printed
if ( (*pch <= 126) && (*pch >= 32) || (*pch == 13) || (*pch == 10) ) if ( ((*pch <= 126) && (*pch >= 32)) || (*pch == 13) || (*pch == 10) )
{ {
UNITY_OUTPUT_CHAR(*pch); UNITY_OUTPUT_CHAR(*pch);
} }
...@@ -332,6 +334,22 @@ void UnityAssertEqualIntArray(const int* expected, ...@@ -332,6 +334,22 @@ void UnityAssertEqualIntArray(const int* expected,
case UNITY_DISPLAY_STYLE_UINT8: case UNITY_DISPLAY_STYLE_UINT8:
while (elements--) while (elements--)
{ {
if (ptr_exp8 == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForExpected);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (ptr_act8 == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForActual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (*ptr_exp8++ != *ptr_act8++) if (*ptr_exp8++ != *ptr_act8++)
{ {
UnityTestResultsFailBegin(lineNumber); UnityTestResultsFailBegin(lineNumber);
...@@ -351,6 +369,22 @@ void UnityAssertEqualIntArray(const int* expected, ...@@ -351,6 +369,22 @@ void UnityAssertEqualIntArray(const int* expected,
case UNITY_DISPLAY_STYLE_UINT16: case UNITY_DISPLAY_STYLE_UINT16:
while (elements--) while (elements--)
{ {
if (ptr_exp16 == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForExpected);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (ptr_act16 == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForActual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (*ptr_exp16++ != *ptr_act16++) if (*ptr_exp16++ != *ptr_act16++)
{ {
UnityTestResultsFailBegin(lineNumber); UnityTestResultsFailBegin(lineNumber);
...@@ -368,6 +402,22 @@ void UnityAssertEqualIntArray(const int* expected, ...@@ -368,6 +402,22 @@ void UnityAssertEqualIntArray(const int* expected,
default: default:
while (elements--) while (elements--)
{ {
if (ptr_exp32 == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForExpected);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (ptr_act32 == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForActual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (*ptr_exp32++ != *ptr_act32++) if (*ptr_exp32++ != *ptr_act32++)
{ {
UnityTestResultsFailBegin(lineNumber); UnityTestResultsFailBegin(lineNumber);
...@@ -408,6 +458,22 @@ void UnityAssertEqualFloatArray(const _UF* expected, ...@@ -408,6 +458,22 @@ void UnityAssertEqualFloatArray(const _UF* expected,
while (elements--) while (elements--)
{ {
if (ptr_expected == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForExpected);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (ptr_actual == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForActual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
diff = *ptr_expected - *ptr_actual; diff = *ptr_expected - *ptr_actual;
if (diff < 0.0) if (diff < 0.0)
diff = 0.0 - diff; diff = 0.0 - diff;
...@@ -680,6 +746,10 @@ void UnityFail(const char* msg, const UNITY_LINE_TYPE line) ...@@ -680,6 +746,10 @@ void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
if (msg != NULL) if (msg != NULL)
{ {
UNITY_OUTPUT_CHAR(':'); UNITY_OUTPUT_CHAR(':');
if (msg[0] != ' ')
{
UNITY_OUTPUT_CHAR(' ');
}
UnityPrint(msg); UnityPrint(msg);
} }
UNITY_FAIL_AND_BAIL; UNITY_FAIL_AND_BAIL;
...@@ -693,6 +763,7 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) ...@@ -693,6 +763,7 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
if (msg != NULL) if (msg != NULL)
{ {
UNITY_OUTPUT_CHAR(':'); UNITY_OUTPUT_CHAR(':');
UNITY_OUTPUT_CHAR(' ');
UnityPrint(msg); UnityPrint(msg);
} }
UNITY_IGNORE_AND_BAIL; UNITY_IGNORE_AND_BAIL;
......
...@@ -68,8 +68,8 @@ ...@@ -68,8 +68,8 @@
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE") #define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE")
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE") #define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE")
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE") #define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected Null") #define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL")
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-Null") #define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL")
//Integers (of all sizes) //Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册