From 2b881e22d875bc5191408e5bbf6022ec9fb7e1c2 Mon Sep 17 00:00:00 2001 From: mkarlesky Date: Thu, 24 Jun 2010 02:23:56 +0000 Subject: [PATCH] (1.) removed errant '.' from memory mismatch string (2.) made string asserts more verbose for NULL string pointers (3.) modified UnityPrint to display unprintable characters as codes git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@77 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e --- src/unity.c | 73 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/src/unity.c b/src/unity.c index fce2cff..dec72ce 100644 --- a/src/unity.c +++ b/src/unity.c @@ -13,17 +13,16 @@ struct _Unity Unity = { 0 }; +const char* UnityStrNull = "NULL"; const char* UnityStrExpected = " Expected "; const char* UnityStrWas = " Was "; const char* UnityStrTo = " To "; const char* UnityStrElement = " Element "; -const char* UnityStrMemory = " Memory Mismatch."; +const char* UnityStrMemory = " Memory Mismatch"; const char* UnityStrDelta = " Values Not Within Delta "; const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless."; const char* UnityStrSpacer = ". "; -void UnityAddMsgIfSpecified(const char* msg); - //----------------------------------------------- // Pretty Printers //----------------------------------------------- @@ -36,7 +35,19 @@ void UnityPrint(const char* string) { while (*pch) { - UNITY_OUTPUT_CHAR(*pch); + // printable characters plus CR & LF are printed + if ( (*pch <= 126) && (*pch >= 32) || (*pch == 13) || (*pch == 10) ) + { + UNITY_OUTPUT_CHAR(*pch); + } + // unprintable characters are shown as codes + else + { + UNITY_OUTPUT_CHAR('{'); + UNITY_OUTPUT_CHAR('\\'); + UnityPrintNumber((const _US32)*pch); + UNITY_OUTPUT_CHAR('}'); + } pch++; } } @@ -51,7 +62,7 @@ void UnityPrintNumberByStyle(const _US32 number, const UNITY_DISPLAY_STYLE_T sty case UNITY_DISPLAY_STYLE_HEX16: UnityPrintNumberHex((_UU32)number, 4); break; case UNITY_DISPLAY_STYLE_HEX32: UnityPrintNumberHex((_UU32)number, 8); break; case UNITY_DISPLAY_STYLE_UINT: UnityPrintNumberUnsigned((_UU32)number); break; - default: UnityPrintNumber(number); break; + default: UnityPrintNumber(number); break; } } @@ -221,6 +232,34 @@ void UnityAddMsgIfSpecified(const char* msg) } } +//----------------------------------------------- +void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual) +{ + UnityPrint(UnityStrExpected); + if (expected != NULL) + { + UNITY_OUTPUT_CHAR('\''); + UnityPrint(expected); + UNITY_OUTPUT_CHAR('\''); + } + else + { + UnityPrint(UnityStrNull); + } + UnityPrint(UnityStrWas); + if (actual != NULL) + { + UNITY_OUTPUT_CHAR('\''); + UnityPrint(actual); + UNITY_OUTPUT_CHAR('\''); + } + else + { + UnityPrint(UnityStrNull); + } +} + + //----------------------------------------------- // Assertion Functions //----------------------------------------------- @@ -499,17 +538,10 @@ void UnityAssertEqualString(const char* expected, if (Unity.CurrentTestFailed) { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrExpected); - UNITY_OUTPUT_CHAR('\''); - UnityPrint(expected); - UNITY_OUTPUT_CHAR('\''); - UnityPrint(UnityStrWas); - UNITY_OUTPUT_CHAR('\''); - UnityPrint(actual); - UNITY_OUTPUT_CHAR('\''); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; + UnityTestResultsFailBegin(lineNumber); + UnityPrintExpectedAndActualStrings(expected, actual); + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; } } @@ -575,14 +607,7 @@ void UnityAssertEqualStringArray( const char** expected, UnityPrint(UnityStrElement); UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT); } - UnityPrint(UnityStrExpected); - UNITY_OUTPUT_CHAR('\''); - UnityPrint(expected[j]); - UNITY_OUTPUT_CHAR('\''); - UnityPrint(UnityStrWas); - UNITY_OUTPUT_CHAR('\''); - UnityPrint(actual[j]); - UNITY_OUTPUT_CHAR('\''); + UnityPrintExpectedAndActualStrings(expected[j], actual[j]); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; }