提交 b4ab81bb 编写于 作者: F Fabian Zahn

Added first working implementation.

上级 7d2bf62b
...@@ -67,14 +67,10 @@ static const char UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " "; ...@@ -67,14 +67,10 @@ static const char UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " ";
* Pretty Printers & Test Result Output Handlers * Pretty Printers & Test Result Output Handlers
*-----------------------------------------------*/ *-----------------------------------------------*/
void UnityPrint(const char* string) /*-----------------------------------------------*/
/* Local helper function to print characters. */
static void UnityPrintChar(const char* pch)
{ {
const char* pch = string;
if (pch != NULL)
{
while (*pch)
{
/* printable characters plus CR & LF are printed */ /* printable characters plus CR & LF are printed */
if ((*pch <= 126) && (*pch >= 32)) if ((*pch <= 126) && (*pch >= 32))
{ {
...@@ -92,30 +88,146 @@ void UnityPrint(const char* string) ...@@ -92,30 +88,146 @@ void UnityPrint(const char* string)
UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('n'); UNITY_OUTPUT_CHAR('n');
} }
#ifdef UNITY_OUTPUT_COLOR /* unprintable characters are shown as codes */
/* print ANSI escape code */ else
else if (*pch == 27 && *(pch + 1) == '[')
{ {
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('x');
UnityPrintNumberHex((UNITY_UINT)*pch, 2);
}
}
/*-----------------------------------------------*/
#ifdef UNITY_OUTPUT_COLOR
static UNITY_UINT UnityPrintAnsiEscapeString(const char* string)
{
const char* pch = string;
UNITY_UINT count = 0;
while (*pch && *pch != 'm') while (*pch && *pch != 'm')
{ {
UNITY_OUTPUT_CHAR(*pch); UNITY_OUTPUT_CHAR(*pch);
pch++; pch++;
count++;
} }
UNITY_OUTPUT_CHAR('m'); UNITY_OUTPUT_CHAR('m');
count++;
return count;
}
#endif
/*-----------------------------------------------*/
void UnityPrint(const char* string)
{
const char* pch = string;
if (pch != NULL)
{
while (*pch)
{
#ifdef UNITY_OUTPUT_COLOR
/* print ANSI escape code */
if (*pch == 27 && *(pch + 1) == '[')
{
pch += UnityPrintAnsiEscapeString(pch);
continue;
} }
#endif #endif
/* unprintable characters are shown as codes */ UnityPrintChar(pch);
else pch++;
}
}
}
/*-----------------------------------------------*/
#ifndef UNITY_EXCLUDE_PRINT_FORMATTED
void UnityPrintFormatted(const char* format, ... )
{
const char* pch = format;
va_list va;
va_start(va, format);
if (pch != NULL)
{ {
UNITY_OUTPUT_CHAR('\\'); while (*pch)
{
/* format identification character */
if (*pch == '%')
{
pch++;
if (pch != NULL)
{
switch (*pch)
{
case 'd':
case 'i':
{
const UNITY_INT number = va_arg(va, UNITY_INT);
UnityPrintNumber(number);
break;
}
case 'u':
{
const UNITY_UINT number = va_arg(va, UNITY_UINT);
UnityPrintNumberUnsigned(number);
break;
}
case 'x':
case 'X':
case 'p':
{
const UNITY_UINT number = va_arg(va, UNITY_UINT);
UNITY_OUTPUT_CHAR('0');
UNITY_OUTPUT_CHAR('x'); UNITY_OUTPUT_CHAR('x');
UnityPrintNumberHex((UNITY_UINT)*pch, 2); UnityPrintNumberHex(number, 8);
break;
}
case 'c':
{
const UNITY_INT ch = va_arg(va, UNITY_INT);
UnityPrintChar((const char *)&ch);
break;
}
case 's':
{ const char * string = va_arg(va, const char *);
UnityPrint(string);
break;
}
case '%':
default:
UnityPrintChar(pch);
break;
}
}
}
#ifdef UNITY_OUTPUT_COLOR
/* print ANSI escape code */
else if (*pch == 27 && *(pch + 1) == '[')
{
pch += UnityPrintAnsiEscapeString(pch);
continue;
}
#endif
else if (*pch == '\n')
{
UNITY_PRINT_EOL();
} }
else
{
UnityPrintChar(pch);
}
pch++; pch++;
} }
} }
va_end(va);
} }
#endif /* ! UNITY_EXCLUDE_PRINT_FORMATTED */
/*-----------------------------------------------*/
void UnityPrintLen(const char* string, const UNITY_UINT32 length) void UnityPrintLen(const char* string, const UNITY_UINT32 length)
{ {
const char* pch = string; const char* pch = string;
......
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
#include <stddef.h> #include <stddef.h>
#endif #endif
#ifndef UNITY_EXCLUDE_PRINT_FORMATTED
#include <stdarg.h>
#endif
/* Unity Attempts to Auto-Detect Integer Types /* Unity Attempts to Auto-Detect Integer Types
* Attempt 1: UINT_MAX, ULONG_MAX in <limits.h>, or default to 32 bits * Attempt 1: UINT_MAX, ULONG_MAX in <limits.h>, or default to 32 bits
* Attempt 2: UINTPTR_MAX in <stdint.h>, or default to same size as long * Attempt 2: UINTPTR_MAX in <stdint.h>, or default to same size as long
...@@ -489,6 +493,11 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int ...@@ -489,6 +493,11 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int
*-------------------------------------------------------*/ *-------------------------------------------------------*/
void UnityPrint(const char* string); void UnityPrint(const char* string);
#ifndef UNITY_EXCLUDE_PRINT_FORMATTED
void UnityPrintFormatted(const char* format, ... );
#endif
void UnityPrintLen(const char* string, const UNITY_UINT32 length); void UnityPrintLen(const char* string, const UNITY_UINT32 length);
void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number); void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number);
void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style); void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册