From f1100dd19a12763fcc2a0027ffa54b9958746ed7 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sat, 27 Oct 2018 18:21:01 +0200 Subject: [PATCH] Added support for %b (bits / binary), %f (float) and %g (double). --- src/unity.c | 44 ++++++++++++++++++++++++++++++++++--------- src/unity_internals.h | 2 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/unity.c b/src/unity.c index ea50b31..0f71b91 100644 --- a/src/unity.c +++ b/src/unity.c @@ -164,29 +164,47 @@ void UnityPrintFormatted(const char* format, ... ) case 'd': case 'i': { - const UNITY_INT number = va_arg(va, UNITY_INT); - UnityPrintNumber(number); + const int number = va_arg(va, int); + UnityPrintNumber((UNITY_INT)number); break; } +#ifndef UNITY_EXCLUDE_FLOAT_PRINT + case 'f': + case 'g': + { + const double number = va_arg(va, double); + UnityPrintFloat((UNITY_DOUBLE)number); + break; + } +#endif case 'u': { - const UNITY_UINT number = va_arg(va, UNITY_UINT); - UnityPrintNumberUnsigned(number); + const unsigned int number = va_arg(va, unsigned int); + UnityPrintNumberUnsigned((UNITY_UINT)number); + break; + } + case 'b': + { + const unsigned int number = va_arg(va, unsigned int); + const UNITY_UINT mask = (UNITY_UINT)0 - (UNITY_UINT)1; + UNITY_OUTPUT_CHAR('0'); + UNITY_OUTPUT_CHAR('b'); + UnityPrintMask(mask, (UNITY_UINT)number); break; } case 'x': case 'X': case 'p': { - const UNITY_UINT number = va_arg(va, UNITY_UINT); + const unsigned int number = va_arg(va, unsigned int); UNITY_OUTPUT_CHAR('0'); UNITY_OUTPUT_CHAR('x'); - UnityPrintNumberHex(number, 8); + UnityPrintNumberHex((UNITY_UINT)number, 8); break; } case 'c': { - const UNITY_INT ch = va_arg(va, UNITY_INT); + const int ch = va_arg(va, int); UnityPrintChar((const char *)&ch); break; } @@ -196,9 +214,17 @@ void UnityPrintFormatted(const char* format, ... ) break; } case '%': + { + UnityPrintChar(pch); + break; + } default: - UnityPrintChar(pch); - break; + { + /* print the unknown character */ + UNITY_OUTPUT_CHAR('%'); + UnityPrintChar(pch); + break; + } } } } diff --git a/src/unity_internals.h b/src/unity_internals.h index 69e08a5..9bdd171 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -134,7 +134,7 @@ typedef UNITY_INT32 UNITY_INT; #else - /* 64-bit Support */ + /* 64-bit Support */ #if (UNITY_LONG_WIDTH == 32) typedef unsigned long long UNITY_UINT64; typedef signed long long UNITY_INT64;