mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 /* =========================================================================
elessair 0:f269e3021894 2 Unity Project - A Test Framework for C
elessair 0:f269e3021894 3 Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams
elessair 0:f269e3021894 4 [Released under MIT License. Please refer to license.txt for details]
elessair 0:f269e3021894 5 ============================================================================ */
elessair 0:f269e3021894 6
elessair 0:f269e3021894 7 #include "unity/unity.h"
elessair 0:f269e3021894 8 #include "utest/unity_handler.h"
elessair 0:f269e3021894 9 #include <stddef.h>
elessair 0:f269e3021894 10
elessair 0:f269e3021894 11 /* If omitted from header, declare overrideable prototypes here so they're ready for use */
elessair 0:f269e3021894 12 #ifdef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION
elessair 0:f269e3021894 13 int UNITY_OUTPUT_CHAR(int);
elessair 0:f269e3021894 14 #endif
elessair 0:f269e3021894 15 #ifdef UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION
elessair 0:f269e3021894 16 int UNITY_OUTPUT_FLUSH(void);
elessair 0:f269e3021894 17 #endif
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 /* Helpful macros for us to use here */
elessair 0:f269e3021894 20 #define UNITY_FAIL_AND_BAIL { UNITY_OUTPUT_CHAR('\n'); utest_unity_assert_failure(); }
elessair 0:f269e3021894 21 #define UNITY_IGNORE_AND_BAIL { UNITY_OUTPUT_CHAR('\n'); utest_unity_ignore_failure(); }
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23 /* return prematurely if we are already in failure or ignore state */
elessair 0:f269e3021894 24 #define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
elessair 0:f269e3021894 25
elessair 0:f269e3021894 26 struct _Unity Unity;
elessair 0:f269e3021894 27
elessair 0:f269e3021894 28 static const char UnityStrOk[] = "OK";
elessair 0:f269e3021894 29 static const char UnityStrPass[] = "PASS";
elessair 0:f269e3021894 30 static const char UnityStrFail[] = "FAIL";
elessair 0:f269e3021894 31 static const char UnityStrIgnore[] = "IGNORE";
elessair 0:f269e3021894 32 static const char UnityStrNull[] = "NULL";
elessair 0:f269e3021894 33 static const char UnityStrSpacer[] = ". ";
elessair 0:f269e3021894 34 static const char UnityStrExpected[] = " Expected ";
elessair 0:f269e3021894 35 static const char UnityStrWas[] = " Was ";
elessair 0:f269e3021894 36 static const char UnityStrElement[] = " Element ";
elessair 0:f269e3021894 37 static const char UnityStrByte[] = " Byte ";
elessair 0:f269e3021894 38 static const char UnityStrMemory[] = " Memory Mismatch.";
elessair 0:f269e3021894 39 static const char UnityStrDelta[] = " Values Not Within Delta ";
elessair 0:f269e3021894 40 static const char UnityStrPointless[] = " You Asked Me To Compare Nothing, Which Was Pointless.";
elessair 0:f269e3021894 41 static const char UnityStrNullPointerForExpected[] = " Expected pointer to be NULL";
elessair 0:f269e3021894 42 static const char UnityStrNullPointerForActual[] = " Actual pointer was NULL";
elessair 0:f269e3021894 43 static const char UnityStrNot[] = "Not ";
elessair 0:f269e3021894 44 static const char UnityStrInf[] = "Infinity";
elessair 0:f269e3021894 45 static const char UnityStrNegInf[] = "Negative Infinity";
elessair 0:f269e3021894 46 static const char UnityStrNaN[] = "NaN";
elessair 0:f269e3021894 47 static const char UnityStrDet[] = "Determinate";
elessair 0:f269e3021894 48 static const char UnityStrInvalidFloatTrait[] = "Invalid Float Trait";
elessair 0:f269e3021894 49 const char UnityStrErrFloat[] = "Unity Floating Point Disabled";
elessair 0:f269e3021894 50 const char UnityStrErrDouble[] = "Unity Double Precision Disabled";
elessair 0:f269e3021894 51 const char UnityStrErr64[] = "Unity 64-bit Support Disabled";
elessair 0:f269e3021894 52 static const char UnityStrBreaker[] = "-----------------------";
elessair 0:f269e3021894 53 static const char UnityStrResultsTests[] = " Tests ";
elessair 0:f269e3021894 54 static const char UnityStrResultsFailures[] = " Failures ";
elessair 0:f269e3021894 55 static const char UnityStrResultsIgnored[] = " Ignored ";
elessair 0:f269e3021894 56 static const char UnityStrDetail1Name[] = UNITY_DETAIL1_NAME " ";
elessair 0:f269e3021894 57 static const char UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " ";
elessair 0:f269e3021894 58
elessair 0:f269e3021894 59 #ifdef UNITY_FLOAT_NEEDS_ZERO
elessair 0:f269e3021894 60 /* Dividing by these constants produces +/- infinity.
elessair 0:f269e3021894 61 * The rationale is given in UnityAssertFloatIsInf's body. */
elessair 0:f269e3021894 62 static const _UF f_zero = 0.0f;
elessair 0:f269e3021894 63 #endif
elessair 0:f269e3021894 64
elessair 0:f269e3021894 65 /* compiler-generic print formatting masks */
elessair 0:f269e3021894 66 static const _U_UINT UnitySizeMask[] =
elessair 0:f269e3021894 67 {
elessair 0:f269e3021894 68 255u, /* 0xFF */
elessair 0:f269e3021894 69 65535u, /* 0xFFFF */
elessair 0:f269e3021894 70 65535u,
elessair 0:f269e3021894 71 4294967295u, /* 0xFFFFFFFF */
elessair 0:f269e3021894 72 4294967295u,
elessair 0:f269e3021894 73 4294967295u,
elessair 0:f269e3021894 74 4294967295u
elessair 0:f269e3021894 75 #ifdef UNITY_SUPPORT_64
elessair 0:f269e3021894 76 ,0xFFFFFFFFFFFFFFFFull
elessair 0:f269e3021894 77 #endif
elessair 0:f269e3021894 78 };
elessair 0:f269e3021894 79
elessair 0:f269e3021894 80 /*-----------------------------------------------
elessair 0:f269e3021894 81 * Pretty Printers & Test Result Output Handlers
elessair 0:f269e3021894 82 *-----------------------------------------------*/
elessair 0:f269e3021894 83
elessair 0:f269e3021894 84 void UnityPrint(const char* string)
elessair 0:f269e3021894 85 {
elessair 0:f269e3021894 86 const char* pch = string;
elessair 0:f269e3021894 87
elessair 0:f269e3021894 88 if (pch != NULL)
elessair 0:f269e3021894 89 {
elessair 0:f269e3021894 90 while (*pch)
elessair 0:f269e3021894 91 {
elessair 0:f269e3021894 92 /* printable characters plus CR & LF are printed */
elessair 0:f269e3021894 93 if ((*pch <= 126) && (*pch >= 32))
elessair 0:f269e3021894 94 {
elessair 0:f269e3021894 95 UNITY_OUTPUT_CHAR(*pch);
elessair 0:f269e3021894 96 }
elessair 0:f269e3021894 97 /* write escaped carriage returns */
elessair 0:f269e3021894 98 else if (*pch == 13)
elessair 0:f269e3021894 99 {
elessair 0:f269e3021894 100 UNITY_OUTPUT_CHAR('\\');
elessair 0:f269e3021894 101 UNITY_OUTPUT_CHAR('r');
elessair 0:f269e3021894 102 }
elessair 0:f269e3021894 103 /* write escaped line feeds */
elessair 0:f269e3021894 104 else if (*pch == 10)
elessair 0:f269e3021894 105 {
elessair 0:f269e3021894 106 UNITY_OUTPUT_CHAR('\\');
elessair 0:f269e3021894 107 UNITY_OUTPUT_CHAR('n');
elessair 0:f269e3021894 108 }
elessair 0:f269e3021894 109 /* unprintable characters are shown as codes */
elessair 0:f269e3021894 110 else
elessair 0:f269e3021894 111 {
elessair 0:f269e3021894 112 UNITY_OUTPUT_CHAR('\\');
elessair 0:f269e3021894 113 UnityPrintNumberHex((_U_UINT)*pch, 2);
elessair 0:f269e3021894 114 }
elessair 0:f269e3021894 115 pch++;
elessair 0:f269e3021894 116 }
elessair 0:f269e3021894 117 }
elessair 0:f269e3021894 118 }
elessair 0:f269e3021894 119
elessair 0:f269e3021894 120 void UnityPrintLen(const char* string, const _UU32 length);
elessair 0:f269e3021894 121 void UnityPrintLen(const char* string, const _UU32 length)
elessair 0:f269e3021894 122 {
elessair 0:f269e3021894 123 const char* pch = string;
elessair 0:f269e3021894 124
elessair 0:f269e3021894 125 if (pch != NULL)
elessair 0:f269e3021894 126 {
elessair 0:f269e3021894 127 while (*pch && (_UU32)(pch - string) < length)
elessair 0:f269e3021894 128 {
elessair 0:f269e3021894 129 /* printable characters plus CR & LF are printed */
elessair 0:f269e3021894 130 if ((*pch <= 126) && (*pch >= 32))
elessair 0:f269e3021894 131 {
elessair 0:f269e3021894 132 UNITY_OUTPUT_CHAR(*pch);
elessair 0:f269e3021894 133 }
elessair 0:f269e3021894 134 /* write escaped carriage returns */
elessair 0:f269e3021894 135 else if (*pch == 13)
elessair 0:f269e3021894 136 {
elessair 0:f269e3021894 137 UNITY_OUTPUT_CHAR('\\');
elessair 0:f269e3021894 138 UNITY_OUTPUT_CHAR('r');
elessair 0:f269e3021894 139 }
elessair 0:f269e3021894 140 /* write escaped line feeds */
elessair 0:f269e3021894 141 else if (*pch == 10)
elessair 0:f269e3021894 142 {
elessair 0:f269e3021894 143 UNITY_OUTPUT_CHAR('\\');
elessair 0:f269e3021894 144 UNITY_OUTPUT_CHAR('n');
elessair 0:f269e3021894 145 }
elessair 0:f269e3021894 146 /* unprintable characters are shown as codes */
elessair 0:f269e3021894 147 else
elessair 0:f269e3021894 148 {
elessair 0:f269e3021894 149 UNITY_OUTPUT_CHAR('\\');
elessair 0:f269e3021894 150 UnityPrintNumberHex((_U_UINT)*pch, 2);
elessair 0:f269e3021894 151 }
elessair 0:f269e3021894 152 pch++;
elessair 0:f269e3021894 153 }
elessair 0:f269e3021894 154 }
elessair 0:f269e3021894 155 }
elessair 0:f269e3021894 156
elessair 0:f269e3021894 157 /*-----------------------------------------------*/
elessair 0:f269e3021894 158 void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
elessair 0:f269e3021894 159 {
elessair 0:f269e3021894 160 if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
elessair 0:f269e3021894 161 {
elessair 0:f269e3021894 162 UnityPrintNumber(number);
elessair 0:f269e3021894 163 }
elessair 0:f269e3021894 164 else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
elessair 0:f269e3021894 165 {
elessair 0:f269e3021894 166 UnityPrintNumberUnsigned( (_U_UINT)number & UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1] );
elessair 0:f269e3021894 167 }
elessair 0:f269e3021894 168 else
elessair 0:f269e3021894 169 {
elessair 0:f269e3021894 170 UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1));
elessair 0:f269e3021894 171 }
elessair 0:f269e3021894 172 }
elessair 0:f269e3021894 173
elessair 0:f269e3021894 174 /*-----------------------------------------------*/
elessair 0:f269e3021894 175 void UnityPrintNumber(const _U_SINT number_to_print)
elessair 0:f269e3021894 176 {
elessair 0:f269e3021894 177 _U_UINT number = (_U_UINT)number_to_print;
elessair 0:f269e3021894 178
elessair 0:f269e3021894 179 if (number_to_print < 0)
elessair 0:f269e3021894 180 {
elessair 0:f269e3021894 181 /* A negative number, including MIN negative */
elessair 0:f269e3021894 182 UNITY_OUTPUT_CHAR('-');
elessair 0:f269e3021894 183 number = (_U_UINT)(-number_to_print);
elessair 0:f269e3021894 184 }
elessair 0:f269e3021894 185 UnityPrintNumberUnsigned(number);
elessair 0:f269e3021894 186 }
elessair 0:f269e3021894 187
elessair 0:f269e3021894 188 /*-----------------------------------------------
elessair 0:f269e3021894 189 * basically do an itoa using as little ram as possible */
elessair 0:f269e3021894 190 void UnityPrintNumberUnsigned(const _U_UINT number)
elessair 0:f269e3021894 191 {
elessair 0:f269e3021894 192 _U_UINT divisor = 1;
elessair 0:f269e3021894 193
elessair 0:f269e3021894 194 /* figure out initial divisor */
elessair 0:f269e3021894 195 while (number / divisor > 9)
elessair 0:f269e3021894 196 {
elessair 0:f269e3021894 197 divisor *= 10;
elessair 0:f269e3021894 198 }
elessair 0:f269e3021894 199
elessair 0:f269e3021894 200 /* now mod and print, then divide divisor */
elessair 0:f269e3021894 201 do
elessair 0:f269e3021894 202 {
elessair 0:f269e3021894 203 UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
elessair 0:f269e3021894 204 divisor /= 10;
elessair 0:f269e3021894 205 }
elessair 0:f269e3021894 206 while (divisor > 0);
elessair 0:f269e3021894 207 }
elessair 0:f269e3021894 208
elessair 0:f269e3021894 209 /*-----------------------------------------------*/
elessair 0:f269e3021894 210 void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
elessair 0:f269e3021894 211 {
elessair 0:f269e3021894 212 _U_UINT nibble;
elessair 0:f269e3021894 213 char nibbles = nibbles_to_print;
elessair 0:f269e3021894 214 UNITY_OUTPUT_CHAR('0');
elessair 0:f269e3021894 215 UNITY_OUTPUT_CHAR('x');
elessair 0:f269e3021894 216
elessair 0:f269e3021894 217 while (nibbles > 0)
elessair 0:f269e3021894 218 {
elessair 0:f269e3021894 219 nibble = (number >> (--nibbles << 2)) & 0x0000000F;
elessair 0:f269e3021894 220 if (nibble <= 9)
elessair 0:f269e3021894 221 {
elessair 0:f269e3021894 222 UNITY_OUTPUT_CHAR((char)('0' + nibble));
elessair 0:f269e3021894 223 }
elessair 0:f269e3021894 224 else
elessair 0:f269e3021894 225 {
elessair 0:f269e3021894 226 UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
elessair 0:f269e3021894 227 }
elessair 0:f269e3021894 228 }
elessair 0:f269e3021894 229 }
elessair 0:f269e3021894 230
elessair 0:f269e3021894 231 /*-----------------------------------------------*/
elessair 0:f269e3021894 232 void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
elessair 0:f269e3021894 233 {
elessair 0:f269e3021894 234 _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
elessair 0:f269e3021894 235 _US32 i;
elessair 0:f269e3021894 236
elessair 0:f269e3021894 237 for (i = 0; i < UNITY_INT_WIDTH; i++)
elessair 0:f269e3021894 238 {
elessair 0:f269e3021894 239 if (current_bit & mask)
elessair 0:f269e3021894 240 {
elessair 0:f269e3021894 241 if (current_bit & number)
elessair 0:f269e3021894 242 {
elessair 0:f269e3021894 243 UNITY_OUTPUT_CHAR('1');
elessair 0:f269e3021894 244 }
elessair 0:f269e3021894 245 else
elessair 0:f269e3021894 246 {
elessair 0:f269e3021894 247 UNITY_OUTPUT_CHAR('0');
elessair 0:f269e3021894 248 }
elessair 0:f269e3021894 249 }
elessair 0:f269e3021894 250 else
elessair 0:f269e3021894 251 {
elessair 0:f269e3021894 252 UNITY_OUTPUT_CHAR('.');
elessair 0:f269e3021894 253 }
elessair 0:f269e3021894 254 current_bit = current_bit >> 1;
elessair 0:f269e3021894 255 }
elessair 0:f269e3021894 256 }
elessair 0:f269e3021894 257
elessair 0:f269e3021894 258 /*-----------------------------------------------*/
elessair 0:f269e3021894 259 #ifdef UNITY_FLOAT_VERBOSE
elessair 0:f269e3021894 260 #include <stdio.h>
elessair 0:f269e3021894 261
elessair 0:f269e3021894 262 #ifndef UNITY_VERBOSE_NUMBER_MAX_LENGTH
elessair 0:f269e3021894 263 # ifdef UNITY_DOUBLE_VERBOSE
elessair 0:f269e3021894 264 # define UNITY_VERBOSE_NUMBER_MAX_LENGTH 317
elessair 0:f269e3021894 265 # else
elessair 0:f269e3021894 266 # define UNITY_VERBOSE_NUMBER_MAX_LENGTH 47
elessair 0:f269e3021894 267 # endif
elessair 0:f269e3021894 268 #endif
elessair 0:f269e3021894 269
elessair 0:f269e3021894 270 void UnityPrintFloat(_UF number)
elessair 0:f269e3021894 271 {
elessair 0:f269e3021894 272 char TempBuffer[UNITY_VERBOSE_NUMBER_MAX_LENGTH + 1];
elessair 0:f269e3021894 273 snprintf(TempBuffer, sizeof(TempBuffer), "%.6f", number);
elessair 0:f269e3021894 274 UnityPrint(TempBuffer);
elessair 0:f269e3021894 275 }
elessair 0:f269e3021894 276 #endif
elessair 0:f269e3021894 277
elessair 0:f269e3021894 278 /*-----------------------------------------------*/
elessair 0:f269e3021894 279
elessair 0:f269e3021894 280 void UnityPrintFail(void);
elessair 0:f269e3021894 281 void UnityPrintFail(void)
elessair 0:f269e3021894 282 {
elessair 0:f269e3021894 283 UnityPrint(UnityStrFail);
elessair 0:f269e3021894 284 }
elessair 0:f269e3021894 285
elessair 0:f269e3021894 286 void UnityPrintOk(void);
elessair 0:f269e3021894 287 void UnityPrintOk(void)
elessair 0:f269e3021894 288 {
elessair 0:f269e3021894 289 UnityPrint(UnityStrOk);
elessair 0:f269e3021894 290 }
elessair 0:f269e3021894 291
elessair 0:f269e3021894 292 /*-----------------------------------------------*/
elessair 0:f269e3021894 293 static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line);
elessair 0:f269e3021894 294 static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
elessair 0:f269e3021894 295 {
elessair 0:f269e3021894 296 #ifndef UNITY_FIXTURES
elessair 0:f269e3021894 297 UnityPrint(file);
elessair 0:f269e3021894 298 UNITY_OUTPUT_CHAR(':');
elessair 0:f269e3021894 299 UnityPrintNumber((_U_SINT)line);
elessair 0:f269e3021894 300 UNITY_OUTPUT_CHAR(':');
elessair 0:f269e3021894 301 UnityPrint(Unity.CurrentTestName);
elessair 0:f269e3021894 302 UNITY_OUTPUT_CHAR(':');
elessair 0:f269e3021894 303 #else
elessair 0:f269e3021894 304 UNITY_UNUSED(file);
elessair 0:f269e3021894 305 UNITY_UNUSED(line);
elessair 0:f269e3021894 306 #endif
elessair 0:f269e3021894 307 }
elessair 0:f269e3021894 308
elessair 0:f269e3021894 309 /*-----------------------------------------------*/
elessair 0:f269e3021894 310 static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line);
elessair 0:f269e3021894 311 static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
elessair 0:f269e3021894 312 {
elessair 0:f269e3021894 313 #ifndef UNITY_FIXTURES
elessair 0:f269e3021894 314 UnityTestResultsBegin(Unity.TestFile, line);
elessair 0:f269e3021894 315 #else
elessair 0:f269e3021894 316 UNITY_UNUSED(line);
elessair 0:f269e3021894 317 #endif
elessair 0:f269e3021894 318 UnityPrint(UnityStrFail);
elessair 0:f269e3021894 319 UNITY_OUTPUT_CHAR(':');
elessair 0:f269e3021894 320 }
elessair 0:f269e3021894 321
elessair 0:f269e3021894 322 /*-----------------------------------------------*/
elessair 0:f269e3021894 323 void UnityConcludeTest(void)
elessair 0:f269e3021894 324 {
elessair 0:f269e3021894 325 if (Unity.CurrentTestIgnored)
elessair 0:f269e3021894 326 {
elessair 0:f269e3021894 327 Unity.TestIgnores++;
elessair 0:f269e3021894 328 }
elessair 0:f269e3021894 329 else if (!Unity.CurrentTestFailed)
elessair 0:f269e3021894 330 {
elessair 0:f269e3021894 331 UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
elessair 0:f269e3021894 332 UnityPrint(UnityStrPass);
elessair 0:f269e3021894 333 }
elessair 0:f269e3021894 334 else
elessair 0:f269e3021894 335 {
elessair 0:f269e3021894 336 Unity.TestFailures++;
elessair 0:f269e3021894 337 }
elessair 0:f269e3021894 338
elessair 0:f269e3021894 339 Unity.CurrentTestFailed = 0;
elessair 0:f269e3021894 340 Unity.CurrentTestIgnored = 0;
elessair 0:f269e3021894 341 UNITY_PRINT_EOL();
elessair 0:f269e3021894 342 UNITY_OUTPUT_FLUSH();
elessair 0:f269e3021894 343 }
elessair 0:f269e3021894 344
elessair 0:f269e3021894 345 /*-----------------------------------------------*/
elessair 0:f269e3021894 346 static void UnityAddMsgIfSpecified(const char* msg);
elessair 0:f269e3021894 347 static void UnityAddMsgIfSpecified(const char* msg)
elessair 0:f269e3021894 348 {
elessair 0:f269e3021894 349 if (msg)
elessair 0:f269e3021894 350 {
elessair 0:f269e3021894 351 UnityPrint(UnityStrSpacer);
elessair 0:f269e3021894 352 #ifndef UNITY_EXCLUDE_DETAILS
elessair 0:f269e3021894 353 if (Unity.CurrentDetail1)
elessair 0:f269e3021894 354 {
elessair 0:f269e3021894 355 UnityPrint(UnityStrDetail1Name);
elessair 0:f269e3021894 356 UnityPrint(Unity.CurrentDetail1);
elessair 0:f269e3021894 357 if (Unity.CurrentDetail2)
elessair 0:f269e3021894 358 {
elessair 0:f269e3021894 359 UnityPrint(UnityStrDetail2Name);
elessair 0:f269e3021894 360 UnityPrint(Unity.CurrentDetail2);
elessair 0:f269e3021894 361 }
elessair 0:f269e3021894 362 UnityPrint(UnityStrSpacer);
elessair 0:f269e3021894 363 }
elessair 0:f269e3021894 364 #endif
elessair 0:f269e3021894 365 UnityPrint(msg);
elessair 0:f269e3021894 366 }
elessair 0:f269e3021894 367 }
elessair 0:f269e3021894 368
elessair 0:f269e3021894 369 /*-----------------------------------------------*/
elessair 0:f269e3021894 370 static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual);
elessair 0:f269e3021894 371 static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
elessair 0:f269e3021894 372 {
elessair 0:f269e3021894 373 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 374 if (expected != NULL)
elessair 0:f269e3021894 375 {
elessair 0:f269e3021894 376 UNITY_OUTPUT_CHAR('\'');
elessair 0:f269e3021894 377 UnityPrint(expected);
elessair 0:f269e3021894 378 UNITY_OUTPUT_CHAR('\'');
elessair 0:f269e3021894 379 }
elessair 0:f269e3021894 380 else
elessair 0:f269e3021894 381 {
elessair 0:f269e3021894 382 UnityPrint(UnityStrNull);
elessair 0:f269e3021894 383 }
elessair 0:f269e3021894 384 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 385 if (actual != NULL)
elessair 0:f269e3021894 386 {
elessair 0:f269e3021894 387 UNITY_OUTPUT_CHAR('\'');
elessair 0:f269e3021894 388 UnityPrint(actual);
elessair 0:f269e3021894 389 UNITY_OUTPUT_CHAR('\'');
elessair 0:f269e3021894 390 }
elessair 0:f269e3021894 391 else
elessair 0:f269e3021894 392 {
elessair 0:f269e3021894 393 UnityPrint(UnityStrNull);
elessair 0:f269e3021894 394 }
elessair 0:f269e3021894 395 }
elessair 0:f269e3021894 396
elessair 0:f269e3021894 397 /*-----------------------------------------------*/
elessair 0:f269e3021894 398 static void UnityPrintExpectedAndActualStringsLen(const char* expected, const char* actual, const _UU32 length)
elessair 0:f269e3021894 399 {
elessair 0:f269e3021894 400 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 401 if (expected != NULL)
elessair 0:f269e3021894 402 {
elessair 0:f269e3021894 403 UNITY_OUTPUT_CHAR('\'');
elessair 0:f269e3021894 404 UnityPrintLen(expected, length);
elessair 0:f269e3021894 405 UNITY_OUTPUT_CHAR('\'');
elessair 0:f269e3021894 406 }
elessair 0:f269e3021894 407 else
elessair 0:f269e3021894 408 {
elessair 0:f269e3021894 409 UnityPrint(UnityStrNull);
elessair 0:f269e3021894 410 }
elessair 0:f269e3021894 411 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 412 if (actual != NULL)
elessair 0:f269e3021894 413 {
elessair 0:f269e3021894 414 UNITY_OUTPUT_CHAR('\'');
elessair 0:f269e3021894 415 UnityPrintLen(actual, length);
elessair 0:f269e3021894 416 UNITY_OUTPUT_CHAR('\'');
elessair 0:f269e3021894 417 }
elessair 0:f269e3021894 418 else
elessair 0:f269e3021894 419 {
elessair 0:f269e3021894 420 UnityPrint(UnityStrNull);
elessair 0:f269e3021894 421 }
elessair 0:f269e3021894 422 }
elessair 0:f269e3021894 423
elessair 0:f269e3021894 424
elessair 0:f269e3021894 425
elessair 0:f269e3021894 426 /*-----------------------------------------------
elessair 0:f269e3021894 427 * Assertion & Control Helpers
elessair 0:f269e3021894 428 *-----------------------------------------------*/
elessair 0:f269e3021894 429
elessair 0:f269e3021894 430 static int UnityCheckArraysForNull(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
elessair 0:f269e3021894 431 {
elessair 0:f269e3021894 432 /* return true if they are both NULL */
elessair 0:f269e3021894 433 if ((expected == NULL) && (actual == NULL))
elessair 0:f269e3021894 434 return 1;
elessair 0:f269e3021894 435
elessair 0:f269e3021894 436 /* throw error if just expected is NULL */
elessair 0:f269e3021894 437 if (expected == NULL)
elessair 0:f269e3021894 438 {
elessair 0:f269e3021894 439 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 440 UnityPrint(UnityStrNullPointerForExpected);
elessair 0:f269e3021894 441 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 442 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 443 }
elessair 0:f269e3021894 444
elessair 0:f269e3021894 445 /* throw error if just actual is NULL */
elessair 0:f269e3021894 446 if (actual == NULL)
elessair 0:f269e3021894 447 {
elessair 0:f269e3021894 448 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 449 UnityPrint(UnityStrNullPointerForActual);
elessair 0:f269e3021894 450 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 451 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 452 }
elessair 0:f269e3021894 453
elessair 0:f269e3021894 454 /* return false if neither is NULL */
elessair 0:f269e3021894 455 return 0;
elessair 0:f269e3021894 456 }
elessair 0:f269e3021894 457
elessair 0:f269e3021894 458 /*-----------------------------------------------
elessair 0:f269e3021894 459 * Assertion Functions
elessair 0:f269e3021894 460 *-----------------------------------------------*/
elessair 0:f269e3021894 461
elessair 0:f269e3021894 462 void UnityAssertBits(const _U_SINT mask,
elessair 0:f269e3021894 463 const _U_SINT expected,
elessair 0:f269e3021894 464 const _U_SINT actual,
elessair 0:f269e3021894 465 const char* msg,
elessair 0:f269e3021894 466 const UNITY_LINE_TYPE lineNumber)
elessair 0:f269e3021894 467 {
elessair 0:f269e3021894 468 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 469
elessair 0:f269e3021894 470 if ((mask & expected) != (mask & actual))
elessair 0:f269e3021894 471 {
elessair 0:f269e3021894 472 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 473 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 474 UnityPrintMask((_U_UINT)mask, (_U_UINT)expected);
elessair 0:f269e3021894 475 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 476 UnityPrintMask((_U_UINT)mask, (_U_UINT)actual);
elessair 0:f269e3021894 477 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 478 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 479 }
elessair 0:f269e3021894 480 }
elessair 0:f269e3021894 481
elessair 0:f269e3021894 482 /*-----------------------------------------------*/
elessair 0:f269e3021894 483 void UnityAssertEqualNumber(const _U_SINT expected,
elessair 0:f269e3021894 484 const _U_SINT actual,
elessair 0:f269e3021894 485 const char* msg,
elessair 0:f269e3021894 486 const UNITY_LINE_TYPE lineNumber,
elessair 0:f269e3021894 487 const UNITY_DISPLAY_STYLE_T style)
elessair 0:f269e3021894 488 {
elessair 0:f269e3021894 489 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 490
elessair 0:f269e3021894 491 if (expected != actual)
elessair 0:f269e3021894 492 {
elessair 0:f269e3021894 493 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 494 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 495 UnityPrintNumberByStyle(expected, style);
elessair 0:f269e3021894 496 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 497 UnityPrintNumberByStyle(actual, style);
elessair 0:f269e3021894 498 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 499 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 500 }
elessair 0:f269e3021894 501 }
elessair 0:f269e3021894 502
elessair 0:f269e3021894 503 #define UnityPrintPointlessAndBail() \
elessair 0:f269e3021894 504 { \
elessair 0:f269e3021894 505 UnityTestResultsFailBegin(lineNumber); \
elessair 0:f269e3021894 506 UnityPrint(UnityStrPointless); \
elessair 0:f269e3021894 507 UnityAddMsgIfSpecified(msg); \
elessair 0:f269e3021894 508 UNITY_FAIL_AND_BAIL; }
elessair 0:f269e3021894 509
elessair 0:f269e3021894 510 /*-----------------------------------------------*/
elessair 0:f269e3021894 511 void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
elessair 0:f269e3021894 512 UNITY_INTERNAL_PTR actual,
elessair 0:f269e3021894 513 const _UU32 num_elements,
elessair 0:f269e3021894 514 const char* msg,
elessair 0:f269e3021894 515 const UNITY_LINE_TYPE lineNumber,
elessair 0:f269e3021894 516 const UNITY_DISPLAY_STYLE_T style)
elessair 0:f269e3021894 517 {
elessair 0:f269e3021894 518 _UU32 elements = num_elements;
elessair 0:f269e3021894 519 UNITY_INTERNAL_PTR ptr_exp = (UNITY_INTERNAL_PTR)expected;
elessair 0:f269e3021894 520 UNITY_INTERNAL_PTR ptr_act = (UNITY_INTERNAL_PTR)actual;
elessair 0:f269e3021894 521
elessair 0:f269e3021894 522 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 523
elessair 0:f269e3021894 524 if (elements == 0)
elessair 0:f269e3021894 525 {
elessair 0:f269e3021894 526 UnityPrintPointlessAndBail();
elessair 0:f269e3021894 527 }
elessair 0:f269e3021894 528
elessair 0:f269e3021894 529 if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1)
elessair 0:f269e3021894 530 return;
elessair 0:f269e3021894 531
elessair 0:f269e3021894 532 /* If style is UNITY_DISPLAY_STYLE_INT, we'll fall into the default case rather than the INT16 or INT32 (etc) case
elessair 0:f269e3021894 533 * as UNITY_DISPLAY_STYLE_INT includes a flag for UNITY_DISPLAY_RANGE_AUTO, which the width-specific
elessair 0:f269e3021894 534 * variants do not. Therefore remove this flag. */
elessair 0:f269e3021894 535 switch(style & (UNITY_DISPLAY_STYLE_T)(~UNITY_DISPLAY_RANGE_AUTO))
elessair 0:f269e3021894 536 {
elessair 0:f269e3021894 537 case UNITY_DISPLAY_STYLE_HEX8:
elessair 0:f269e3021894 538 case UNITY_DISPLAY_STYLE_INT8:
elessair 0:f269e3021894 539 case UNITY_DISPLAY_STYLE_UINT8:
elessair 0:f269e3021894 540 while (elements--)
elessair 0:f269e3021894 541 {
elessair 0:f269e3021894 542 if (*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US8*)ptr_act)
elessair 0:f269e3021894 543 {
elessair 0:f269e3021894 544 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 545 UnityPrint(UnityStrElement);
elessair 0:f269e3021894 546 UnityPrintNumberUnsigned(num_elements - elements - 1);
elessair 0:f269e3021894 547 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 548 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_exp, style);
elessair 0:f269e3021894 549 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 550 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_act, style);
elessair 0:f269e3021894 551 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 552 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 553 }
elessair 0:f269e3021894 554 ptr_exp = (UNITY_INTERNAL_PTR)((_UP)ptr_exp + 1);
elessair 0:f269e3021894 555 ptr_act = (UNITY_INTERNAL_PTR)((_UP)ptr_act + 1);
elessair 0:f269e3021894 556 }
elessair 0:f269e3021894 557 break;
elessair 0:f269e3021894 558 case UNITY_DISPLAY_STYLE_HEX16:
elessair 0:f269e3021894 559 case UNITY_DISPLAY_STYLE_INT16:
elessair 0:f269e3021894 560 case UNITY_DISPLAY_STYLE_UINT16:
elessair 0:f269e3021894 561 while (elements--)
elessair 0:f269e3021894 562 {
elessair 0:f269e3021894 563 if (*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US16*)ptr_act)
elessair 0:f269e3021894 564 {
elessair 0:f269e3021894 565 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 566 UnityPrint(UnityStrElement);
elessair 0:f269e3021894 567 UnityPrintNumberUnsigned(num_elements - elements - 1);
elessair 0:f269e3021894 568 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 569 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_exp, style);
elessair 0:f269e3021894 570 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 571 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_act, style);
elessair 0:f269e3021894 572 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 573 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 574 }
elessair 0:f269e3021894 575 ptr_exp = (UNITY_INTERNAL_PTR)((_UP)ptr_exp + 2);
elessair 0:f269e3021894 576 ptr_act = (UNITY_INTERNAL_PTR)((_UP)ptr_act + 2);
elessair 0:f269e3021894 577 }
elessair 0:f269e3021894 578 break;
elessair 0:f269e3021894 579 #ifdef UNITY_SUPPORT_64
elessair 0:f269e3021894 580 case UNITY_DISPLAY_STYLE_HEX64:
elessair 0:f269e3021894 581 case UNITY_DISPLAY_STYLE_INT64:
elessair 0:f269e3021894 582 case UNITY_DISPLAY_STYLE_UINT64:
elessair 0:f269e3021894 583 while (elements--)
elessair 0:f269e3021894 584 {
elessair 0:f269e3021894 585 if (*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US64*)ptr_act)
elessair 0:f269e3021894 586 {
elessair 0:f269e3021894 587 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 588 UnityPrint(UnityStrElement);
elessair 0:f269e3021894 589 UnityPrintNumberUnsigned(num_elements - elements - 1);
elessair 0:f269e3021894 590 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 591 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_exp, style);
elessair 0:f269e3021894 592 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 593 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_act, style);
elessair 0:f269e3021894 594 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 595 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 596 }
elessair 0:f269e3021894 597 ptr_exp = (UNITY_INTERNAL_PTR)((_UP)ptr_exp + 8);
elessair 0:f269e3021894 598 ptr_act = (UNITY_INTERNAL_PTR)((_UP)ptr_act + 8);
elessair 0:f269e3021894 599 }
elessair 0:f269e3021894 600 break;
elessair 0:f269e3021894 601 #endif
elessair 0:f269e3021894 602 default:
elessair 0:f269e3021894 603 while (elements--)
elessair 0:f269e3021894 604 {
elessair 0:f269e3021894 605 if (*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US32*)ptr_act)
elessair 0:f269e3021894 606 {
elessair 0:f269e3021894 607 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 608 UnityPrint(UnityStrElement);
elessair 0:f269e3021894 609 UnityPrintNumberUnsigned(num_elements - elements - 1);
elessair 0:f269e3021894 610 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 611 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_exp, style);
elessair 0:f269e3021894 612 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 613 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_act, style);
elessair 0:f269e3021894 614 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 615 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 616 }
elessair 0:f269e3021894 617 ptr_exp = (UNITY_INTERNAL_PTR)((_UP)ptr_exp + 4);
elessair 0:f269e3021894 618 ptr_act = (UNITY_INTERNAL_PTR)((_UP)ptr_act + 4);
elessair 0:f269e3021894 619 }
elessair 0:f269e3021894 620 break;
elessair 0:f269e3021894 621 }
elessair 0:f269e3021894 622 }
elessair 0:f269e3021894 623
elessair 0:f269e3021894 624 /*-----------------------------------------------*/
elessair 0:f269e3021894 625 #ifndef UNITY_EXCLUDE_FLOAT
elessair 0:f269e3021894 626 void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
elessair 0:f269e3021894 627 UNITY_PTR_ATTRIBUTE const _UF* actual,
elessair 0:f269e3021894 628 const _UU32 num_elements,
elessair 0:f269e3021894 629 const char* msg,
elessair 0:f269e3021894 630 const UNITY_LINE_TYPE lineNumber)
elessair 0:f269e3021894 631 {
elessair 0:f269e3021894 632 _UU32 elements = num_elements;
elessair 0:f269e3021894 633 UNITY_PTR_ATTRIBUTE const _UF* ptr_expected = expected;
elessair 0:f269e3021894 634 UNITY_PTR_ATTRIBUTE const _UF* ptr_actual = actual;
elessair 0:f269e3021894 635 _UF diff, tol;
elessair 0:f269e3021894 636
elessair 0:f269e3021894 637 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 638
elessair 0:f269e3021894 639 if (elements == 0)
elessair 0:f269e3021894 640 {
elessair 0:f269e3021894 641 UnityPrintPointlessAndBail();
elessair 0:f269e3021894 642 }
elessair 0:f269e3021894 643
elessair 0:f269e3021894 644 if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1)
elessair 0:f269e3021894 645 return;
elessair 0:f269e3021894 646
elessair 0:f269e3021894 647 while (elements--)
elessair 0:f269e3021894 648 {
elessair 0:f269e3021894 649 diff = *ptr_expected - *ptr_actual;
elessair 0:f269e3021894 650 if (diff < 0.0f)
elessair 0:f269e3021894 651 diff = 0.0f - diff;
elessair 0:f269e3021894 652 tol = UNITY_FLOAT_PRECISION * *ptr_expected;
elessair 0:f269e3021894 653 if (tol < 0.0f)
elessair 0:f269e3021894 654 tol = 0.0f - tol;
elessair 0:f269e3021894 655
elessair 0:f269e3021894 656 /* This first part of this condition will catch any NaN or Infinite values */
elessair 0:f269e3021894 657 if (isnan(diff) || isinf(diff) || (diff > tol))
elessair 0:f269e3021894 658 {
elessair 0:f269e3021894 659 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 660 UnityPrint(UnityStrElement);
elessair 0:f269e3021894 661 UnityPrintNumberUnsigned(num_elements - elements - 1);
elessair 0:f269e3021894 662 #ifdef UNITY_FLOAT_VERBOSE
elessair 0:f269e3021894 663 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 664 UnityPrintFloat(*ptr_expected);
elessair 0:f269e3021894 665 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 666 UnityPrintFloat(*ptr_actual);
elessair 0:f269e3021894 667 #else
elessair 0:f269e3021894 668 UnityPrint(UnityStrDelta);
elessair 0:f269e3021894 669 #endif
elessair 0:f269e3021894 670 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 671 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 672 }
elessair 0:f269e3021894 673 ptr_expected++;
elessair 0:f269e3021894 674 ptr_actual++;
elessair 0:f269e3021894 675 }
elessair 0:f269e3021894 676 }
elessair 0:f269e3021894 677
elessair 0:f269e3021894 678 /*-----------------------------------------------*/
elessair 0:f269e3021894 679 void UnityAssertFloatsWithin(const _UF delta,
elessair 0:f269e3021894 680 const _UF expected,
elessair 0:f269e3021894 681 const _UF actual,
elessair 0:f269e3021894 682 const char* msg,
elessair 0:f269e3021894 683 const UNITY_LINE_TYPE lineNumber)
elessair 0:f269e3021894 684 {
elessair 0:f269e3021894 685 _UF diff = actual - expected;
elessair 0:f269e3021894 686 _UF pos_delta = delta;
elessair 0:f269e3021894 687
elessair 0:f269e3021894 688 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 689
elessair 0:f269e3021894 690 if (diff < 0.0f)
elessair 0:f269e3021894 691 {
elessair 0:f269e3021894 692 diff = 0.0f - diff;
elessair 0:f269e3021894 693 }
elessair 0:f269e3021894 694 if (pos_delta < 0.0f)
elessair 0:f269e3021894 695 {
elessair 0:f269e3021894 696 pos_delta = 0.0f - pos_delta;
elessair 0:f269e3021894 697 }
elessair 0:f269e3021894 698
elessair 0:f269e3021894 699 /* This first part of this condition will catch any NaN or Infinite values */
elessair 0:f269e3021894 700 if (isnan(diff) || isinf(diff) || (pos_delta < diff))
elessair 0:f269e3021894 701 {
elessair 0:f269e3021894 702 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 703 #ifdef UNITY_FLOAT_VERBOSE
elessair 0:f269e3021894 704 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 705 UnityPrintFloat(expected);
elessair 0:f269e3021894 706 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 707 UnityPrintFloat(actual);
elessair 0:f269e3021894 708 #else
elessair 0:f269e3021894 709 UnityPrint(UnityStrDelta);
elessair 0:f269e3021894 710 #endif
elessair 0:f269e3021894 711 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 712 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 713 }
elessair 0:f269e3021894 714 }
elessair 0:f269e3021894 715
elessair 0:f269e3021894 716 /*-----------------------------------------------*/
elessair 0:f269e3021894 717 void UnityAssertFloatSpecial(const _UF actual,
elessair 0:f269e3021894 718 const char* msg,
elessair 0:f269e3021894 719 const UNITY_LINE_TYPE lineNumber,
elessair 0:f269e3021894 720 const UNITY_FLOAT_TRAIT_T style)
elessair 0:f269e3021894 721 {
elessair 0:f269e3021894 722 const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
elessair 0:f269e3021894 723 _U_SINT should_be_trait = ((_U_SINT)style & 1);
elessair 0:f269e3021894 724 _U_SINT is_trait = !should_be_trait;
elessair 0:f269e3021894 725 _U_SINT trait_index = (_U_SINT)(style >> 1);
elessair 0:f269e3021894 726
elessair 0:f269e3021894 727 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 728
elessair 0:f269e3021894 729 switch(style)
elessair 0:f269e3021894 730 {
elessair 0:f269e3021894 731 /* To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
elessair 0:f269e3021894 732 * We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise */
elessair 0:f269e3021894 733 case UNITY_FLOAT_IS_INF:
elessair 0:f269e3021894 734 case UNITY_FLOAT_IS_NOT_INF:
elessair 0:f269e3021894 735 is_trait = isinf(actual) & ispos(actual);
elessair 0:f269e3021894 736 break;
elessair 0:f269e3021894 737 case UNITY_FLOAT_IS_NEG_INF:
elessair 0:f269e3021894 738 case UNITY_FLOAT_IS_NOT_NEG_INF:
elessair 0:f269e3021894 739 is_trait = isinf(actual) & isneg(actual);
elessair 0:f269e3021894 740 break;
elessair 0:f269e3021894 741
elessair 0:f269e3021894 742 /* NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN. */
elessair 0:f269e3021894 743 case UNITY_FLOAT_IS_NAN:
elessair 0:f269e3021894 744 case UNITY_FLOAT_IS_NOT_NAN:
elessair 0:f269e3021894 745 is_trait = isnan(actual);
elessair 0:f269e3021894 746 break;
elessair 0:f269e3021894 747
elessair 0:f269e3021894 748 /* A determinate number is non infinite and not NaN. (therefore the opposite of the two above) */
elessair 0:f269e3021894 749 case UNITY_FLOAT_IS_DET:
elessair 0:f269e3021894 750 case UNITY_FLOAT_IS_NOT_DET:
elessair 0:f269e3021894 751 if (isinf(actual) | isnan(actual))
elessair 0:f269e3021894 752 is_trait = 0;
elessair 0:f269e3021894 753 else
elessair 0:f269e3021894 754 is_trait = 1;
elessair 0:f269e3021894 755 break;
elessair 0:f269e3021894 756
elessair 0:f269e3021894 757 default:
elessair 0:f269e3021894 758 trait_index = 0;
elessair 0:f269e3021894 759 trait_names[0] = UnityStrInvalidFloatTrait;
elessair 0:f269e3021894 760 break;
elessair 0:f269e3021894 761 }
elessair 0:f269e3021894 762
elessair 0:f269e3021894 763 if (is_trait != should_be_trait)
elessair 0:f269e3021894 764 {
elessair 0:f269e3021894 765 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 766 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 767 if (!should_be_trait)
elessair 0:f269e3021894 768 UnityPrint(UnityStrNot);
elessair 0:f269e3021894 769 UnityPrint(trait_names[trait_index]);
elessair 0:f269e3021894 770 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 771 #ifdef UNITY_FLOAT_VERBOSE
elessair 0:f269e3021894 772 UnityPrintFloat(actual);
elessair 0:f269e3021894 773 #else
elessair 0:f269e3021894 774 if (should_be_trait)
elessair 0:f269e3021894 775 UnityPrint(UnityStrNot);
elessair 0:f269e3021894 776 UnityPrint(trait_names[trait_index]);
elessair 0:f269e3021894 777 #endif
elessair 0:f269e3021894 778 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 779 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 780 }
elessair 0:f269e3021894 781 }
elessair 0:f269e3021894 782
elessair 0:f269e3021894 783 #endif /* not UNITY_EXCLUDE_FLOAT */
elessair 0:f269e3021894 784
elessair 0:f269e3021894 785 /*-----------------------------------------------*/
elessair 0:f269e3021894 786 #ifndef UNITY_EXCLUDE_DOUBLE
elessair 0:f269e3021894 787 void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
elessair 0:f269e3021894 788 UNITY_PTR_ATTRIBUTE const _UD* actual,
elessair 0:f269e3021894 789 const _UU32 num_elements,
elessair 0:f269e3021894 790 const char* msg,
elessair 0:f269e3021894 791 const UNITY_LINE_TYPE lineNumber)
elessair 0:f269e3021894 792 {
elessair 0:f269e3021894 793 _UU32 elements = num_elements;
elessair 0:f269e3021894 794 UNITY_PTR_ATTRIBUTE const _UD* ptr_expected = expected;
elessair 0:f269e3021894 795 UNITY_PTR_ATTRIBUTE const _UD* ptr_actual = actual;
elessair 0:f269e3021894 796 _UD diff, tol;
elessair 0:f269e3021894 797
elessair 0:f269e3021894 798 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 799
elessair 0:f269e3021894 800 if (elements == 0)
elessair 0:f269e3021894 801 {
elessair 0:f269e3021894 802 UnityPrintPointlessAndBail();
elessair 0:f269e3021894 803 }
elessair 0:f269e3021894 804
elessair 0:f269e3021894 805 if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1)
elessair 0:f269e3021894 806 return;
elessair 0:f269e3021894 807
elessair 0:f269e3021894 808 while (elements--)
elessair 0:f269e3021894 809 {
elessair 0:f269e3021894 810 diff = *ptr_expected - *ptr_actual;
elessair 0:f269e3021894 811 if (diff < 0.0)
elessair 0:f269e3021894 812 diff = 0.0 - diff;
elessair 0:f269e3021894 813 tol = UNITY_DOUBLE_PRECISION * *ptr_expected;
elessair 0:f269e3021894 814 if (tol < 0.0)
elessair 0:f269e3021894 815 tol = 0.0 - tol;
elessair 0:f269e3021894 816
elessair 0:f269e3021894 817 /* This first part of this condition will catch any NaN or Infinite values */
elessair 0:f269e3021894 818 if (isnan(diff) || isinf(diff) || (diff > tol))
elessair 0:f269e3021894 819 {
elessair 0:f269e3021894 820 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 821 UnityPrint(UnityStrElement);
elessair 0:f269e3021894 822 UnityPrintNumberUnsigned(num_elements - elements - 1);
elessair 0:f269e3021894 823 #ifdef UNITY_DOUBLE_VERBOSE
elessair 0:f269e3021894 824 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 825 UnityPrintFloat((float)(*ptr_expected));
elessair 0:f269e3021894 826 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 827 UnityPrintFloat((float)(*ptr_actual));
elessair 0:f269e3021894 828 #else
elessair 0:f269e3021894 829 UnityPrint(UnityStrDelta);
elessair 0:f269e3021894 830 #endif
elessair 0:f269e3021894 831 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 832 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 833 }
elessair 0:f269e3021894 834 ptr_expected++;
elessair 0:f269e3021894 835 ptr_actual++;
elessair 0:f269e3021894 836 }
elessair 0:f269e3021894 837 }
elessair 0:f269e3021894 838
elessair 0:f269e3021894 839 /*-----------------------------------------------*/
elessair 0:f269e3021894 840 void UnityAssertDoublesWithin(const _UD delta,
elessair 0:f269e3021894 841 const _UD expected,
elessair 0:f269e3021894 842 const _UD actual,
elessair 0:f269e3021894 843 const char* msg,
elessair 0:f269e3021894 844 const UNITY_LINE_TYPE lineNumber)
elessair 0:f269e3021894 845 {
elessair 0:f269e3021894 846 _UD diff = actual - expected;
elessair 0:f269e3021894 847 _UD pos_delta = delta;
elessair 0:f269e3021894 848
elessair 0:f269e3021894 849 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 850
elessair 0:f269e3021894 851 if (diff < 0.0)
elessair 0:f269e3021894 852 {
elessair 0:f269e3021894 853 diff = 0.0 - diff;
elessair 0:f269e3021894 854 }
elessair 0:f269e3021894 855 if (pos_delta < 0.0)
elessair 0:f269e3021894 856 {
elessair 0:f269e3021894 857 pos_delta = 0.0 - pos_delta;
elessair 0:f269e3021894 858 }
elessair 0:f269e3021894 859
elessair 0:f269e3021894 860 /* This first part of this condition will catch any NaN or Infinite values */
elessair 0:f269e3021894 861 if (isnan(diff) || isinf(diff) || (pos_delta < diff))
elessair 0:f269e3021894 862 {
elessair 0:f269e3021894 863 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 864 #ifdef UNITY_DOUBLE_VERBOSE
elessair 0:f269e3021894 865 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 866 UnityPrintFloat((float)expected);
elessair 0:f269e3021894 867 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 868 UnityPrintFloat((float)actual);
elessair 0:f269e3021894 869 #else
elessair 0:f269e3021894 870 UnityPrint(UnityStrDelta);
elessair 0:f269e3021894 871 #endif
elessair 0:f269e3021894 872 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 873 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 874 }
elessair 0:f269e3021894 875 }
elessair 0:f269e3021894 876
elessair 0:f269e3021894 877 /*-----------------------------------------------*/
elessair 0:f269e3021894 878
elessair 0:f269e3021894 879 void UnityAssertDoubleSpecial(const _UD actual,
elessair 0:f269e3021894 880 const char* msg,
elessair 0:f269e3021894 881 const UNITY_LINE_TYPE lineNumber,
elessair 0:f269e3021894 882 const UNITY_FLOAT_TRAIT_T style)
elessair 0:f269e3021894 883 {
elessair 0:f269e3021894 884 const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
elessair 0:f269e3021894 885 _U_SINT should_be_trait = ((_U_SINT)style & 1);
elessair 0:f269e3021894 886 _U_SINT is_trait = !should_be_trait;
elessair 0:f269e3021894 887 _U_SINT trait_index = (_U_SINT)(style >> 1);
elessair 0:f269e3021894 888
elessair 0:f269e3021894 889 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 890
elessair 0:f269e3021894 891 switch(style)
elessair 0:f269e3021894 892 {
elessair 0:f269e3021894 893 /* To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
elessair 0:f269e3021894 894 * We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise */
elessair 0:f269e3021894 895 case UNITY_FLOAT_IS_INF:
elessair 0:f269e3021894 896 case UNITY_FLOAT_IS_NOT_INF:
elessair 0:f269e3021894 897 is_trait = isinf(actual) & ispos(actual);
elessair 0:f269e3021894 898 break;
elessair 0:f269e3021894 899 case UNITY_FLOAT_IS_NEG_INF:
elessair 0:f269e3021894 900 case UNITY_FLOAT_IS_NOT_NEG_INF:
elessair 0:f269e3021894 901 is_trait = isinf(actual) & isneg(actual);
elessair 0:f269e3021894 902 break;
elessair 0:f269e3021894 903
elessair 0:f269e3021894 904 /* NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN. */
elessair 0:f269e3021894 905 case UNITY_FLOAT_IS_NAN:
elessair 0:f269e3021894 906 case UNITY_FLOAT_IS_NOT_NAN:
elessair 0:f269e3021894 907 is_trait = isnan(actual);
elessair 0:f269e3021894 908 break;
elessair 0:f269e3021894 909
elessair 0:f269e3021894 910 /* A determinate number is non infinite and not NaN. (therefore the opposite of the two above) */
elessair 0:f269e3021894 911 case UNITY_FLOAT_IS_DET:
elessair 0:f269e3021894 912 case UNITY_FLOAT_IS_NOT_DET:
elessair 0:f269e3021894 913 if (isinf(actual) | isnan(actual))
elessair 0:f269e3021894 914 is_trait = 0;
elessair 0:f269e3021894 915 else
elessair 0:f269e3021894 916 is_trait = 1;
elessair 0:f269e3021894 917 break;
elessair 0:f269e3021894 918
elessair 0:f269e3021894 919 default:
elessair 0:f269e3021894 920 trait_index = 0;
elessair 0:f269e3021894 921 trait_names[0] = UnityStrInvalidFloatTrait;
elessair 0:f269e3021894 922 break;
elessair 0:f269e3021894 923 }
elessair 0:f269e3021894 924
elessair 0:f269e3021894 925 if (is_trait != should_be_trait)
elessair 0:f269e3021894 926 {
elessair 0:f269e3021894 927 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 928 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 929 if (!should_be_trait)
elessair 0:f269e3021894 930 UnityPrint(UnityStrNot);
elessair 0:f269e3021894 931 UnityPrint(trait_names[trait_index]);
elessair 0:f269e3021894 932 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 933 #ifdef UNITY_DOUBLE_VERBOSE
elessair 0:f269e3021894 934 UnityPrintFloat(actual);
elessair 0:f269e3021894 935 #else
elessair 0:f269e3021894 936 if (should_be_trait)
elessair 0:f269e3021894 937 UnityPrint(UnityStrNot);
elessair 0:f269e3021894 938 UnityPrint(trait_names[trait_index]);
elessair 0:f269e3021894 939 #endif
elessair 0:f269e3021894 940 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 941 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 942 }
elessair 0:f269e3021894 943 }
elessair 0:f269e3021894 944
elessair 0:f269e3021894 945
elessair 0:f269e3021894 946 #endif /* not UNITY_EXCLUDE_DOUBLE */
elessair 0:f269e3021894 947
elessair 0:f269e3021894 948 /*-----------------------------------------------*/
elessair 0:f269e3021894 949 void UnityAssertNumbersWithin( const _U_UINT delta,
elessair 0:f269e3021894 950 const _U_SINT expected,
elessair 0:f269e3021894 951 const _U_SINT actual,
elessair 0:f269e3021894 952 const char* msg,
elessair 0:f269e3021894 953 const UNITY_LINE_TYPE lineNumber,
elessair 0:f269e3021894 954 const UNITY_DISPLAY_STYLE_T style)
elessair 0:f269e3021894 955 {
elessair 0:f269e3021894 956 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 957
elessair 0:f269e3021894 958 if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
elessair 0:f269e3021894 959 {
elessair 0:f269e3021894 960 if (actual > expected)
elessair 0:f269e3021894 961 Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > delta);
elessair 0:f269e3021894 962 else
elessair 0:f269e3021894 963 Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > delta);
elessair 0:f269e3021894 964 }
elessair 0:f269e3021894 965 else
elessair 0:f269e3021894 966 {
elessair 0:f269e3021894 967 if ((_U_UINT)actual > (_U_UINT)expected)
elessair 0:f269e3021894 968 Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > delta);
elessair 0:f269e3021894 969 else
elessair 0:f269e3021894 970 Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > delta);
elessair 0:f269e3021894 971 }
elessair 0:f269e3021894 972
elessair 0:f269e3021894 973 if (Unity.CurrentTestFailed)
elessair 0:f269e3021894 974 {
elessair 0:f269e3021894 975 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 976 UnityPrint(UnityStrDelta);
elessair 0:f269e3021894 977 UnityPrintNumberByStyle((_U_SINT)delta, style);
elessair 0:f269e3021894 978 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 979 UnityPrintNumberByStyle(expected, style);
elessair 0:f269e3021894 980 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 981 UnityPrintNumberByStyle(actual, style);
elessair 0:f269e3021894 982 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 983 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 984 }
elessair 0:f269e3021894 985 }
elessair 0:f269e3021894 986
elessair 0:f269e3021894 987 /*-----------------------------------------------*/
elessair 0:f269e3021894 988 void UnityAssertEqualString(const char* expected,
elessair 0:f269e3021894 989 const char* actual,
elessair 0:f269e3021894 990 const char* msg,
elessair 0:f269e3021894 991 const UNITY_LINE_TYPE lineNumber)
elessair 0:f269e3021894 992 {
elessair 0:f269e3021894 993 _UU32 i;
elessair 0:f269e3021894 994
elessair 0:f269e3021894 995 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 996
elessair 0:f269e3021894 997 /* if both pointers not null compare the strings */
elessair 0:f269e3021894 998 if (expected && actual)
elessair 0:f269e3021894 999 {
elessair 0:f269e3021894 1000 for (i = 0; expected[i] || actual[i]; i++)
elessair 0:f269e3021894 1001 {
elessair 0:f269e3021894 1002 if (expected[i] != actual[i])
elessair 0:f269e3021894 1003 {
elessair 0:f269e3021894 1004 Unity.CurrentTestFailed = 1;
elessair 0:f269e3021894 1005 break;
elessair 0:f269e3021894 1006 }
elessair 0:f269e3021894 1007 }
elessair 0:f269e3021894 1008 }
elessair 0:f269e3021894 1009 else
elessair 0:f269e3021894 1010 { /* handle case of one pointers being null (if both null, test should pass) */
elessair 0:f269e3021894 1011 if (expected != actual)
elessair 0:f269e3021894 1012 {
elessair 0:f269e3021894 1013 Unity.CurrentTestFailed = 1;
elessair 0:f269e3021894 1014 }
elessair 0:f269e3021894 1015 }
elessair 0:f269e3021894 1016
elessair 0:f269e3021894 1017 if (Unity.CurrentTestFailed)
elessair 0:f269e3021894 1018 {
elessair 0:f269e3021894 1019 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 1020 UnityPrintExpectedAndActualStrings(expected, actual);
elessair 0:f269e3021894 1021 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 1022 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 1023 }
elessair 0:f269e3021894 1024 }
elessair 0:f269e3021894 1025
elessair 0:f269e3021894 1026 /*-----------------------------------------------*/
elessair 0:f269e3021894 1027 void UnityAssertEqualStringLen(const char* expected,
elessair 0:f269e3021894 1028 const char* actual,
elessair 0:f269e3021894 1029 const _UU32 length,
elessair 0:f269e3021894 1030 const char* msg,
elessair 0:f269e3021894 1031 const UNITY_LINE_TYPE lineNumber)
elessair 0:f269e3021894 1032 {
elessair 0:f269e3021894 1033 _UU32 i;
elessair 0:f269e3021894 1034
elessair 0:f269e3021894 1035 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 1036
elessair 0:f269e3021894 1037 /* if both pointers not null compare the strings */
elessair 0:f269e3021894 1038 if (expected && actual)
elessair 0:f269e3021894 1039 {
elessair 0:f269e3021894 1040 for (i = 0; (expected[i] || actual[i]) && i < length; i++)
elessair 0:f269e3021894 1041 {
elessair 0:f269e3021894 1042 if (expected[i] != actual[i])
elessair 0:f269e3021894 1043 {
elessair 0:f269e3021894 1044 Unity.CurrentTestFailed = 1;
elessair 0:f269e3021894 1045 break;
elessair 0:f269e3021894 1046 }
elessair 0:f269e3021894 1047 }
elessair 0:f269e3021894 1048 }
elessair 0:f269e3021894 1049 else
elessair 0:f269e3021894 1050 { /* handle case of one pointers being null (if both null, test should pass) */
elessair 0:f269e3021894 1051 if (expected != actual)
elessair 0:f269e3021894 1052 {
elessair 0:f269e3021894 1053 Unity.CurrentTestFailed = 1;
elessair 0:f269e3021894 1054 }
elessair 0:f269e3021894 1055 }
elessair 0:f269e3021894 1056
elessair 0:f269e3021894 1057 if (Unity.CurrentTestFailed)
elessair 0:f269e3021894 1058 {
elessair 0:f269e3021894 1059 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 1060 UnityPrintExpectedAndActualStringsLen(expected, actual, length);
elessair 0:f269e3021894 1061 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 1062 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 1063 }
elessair 0:f269e3021894 1064 }
elessair 0:f269e3021894 1065
elessair 0:f269e3021894 1066
elessair 0:f269e3021894 1067 /*-----------------------------------------------*/
elessair 0:f269e3021894 1068 void UnityAssertEqualStringArray( const char** expected,
elessair 0:f269e3021894 1069 const char** actual,
elessair 0:f269e3021894 1070 const _UU32 num_elements,
elessair 0:f269e3021894 1071 const char* msg,
elessair 0:f269e3021894 1072 const UNITY_LINE_TYPE lineNumber)
elessair 0:f269e3021894 1073 {
elessair 0:f269e3021894 1074 _UU32 i, j = 0;
elessair 0:f269e3021894 1075
elessair 0:f269e3021894 1076 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 1077
elessair 0:f269e3021894 1078 /* if no elements, it's an error */
elessair 0:f269e3021894 1079 if (num_elements == 0)
elessair 0:f269e3021894 1080 {
elessair 0:f269e3021894 1081 UnityPrintPointlessAndBail();
elessair 0:f269e3021894 1082 }
elessair 0:f269e3021894 1083
elessair 0:f269e3021894 1084 if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1)
elessair 0:f269e3021894 1085 return;
elessair 0:f269e3021894 1086
elessair 0:f269e3021894 1087 do
elessair 0:f269e3021894 1088 {
elessair 0:f269e3021894 1089 /* if both pointers not null compare the strings */
elessair 0:f269e3021894 1090 if (expected[j] && actual[j])
elessair 0:f269e3021894 1091 {
elessair 0:f269e3021894 1092 for (i = 0; expected[j][i] || actual[j][i]; i++)
elessair 0:f269e3021894 1093 {
elessair 0:f269e3021894 1094 if (expected[j][i] != actual[j][i])
elessair 0:f269e3021894 1095 {
elessair 0:f269e3021894 1096 Unity.CurrentTestFailed = 1;
elessair 0:f269e3021894 1097 break;
elessair 0:f269e3021894 1098 }
elessair 0:f269e3021894 1099 }
elessair 0:f269e3021894 1100 }
elessair 0:f269e3021894 1101 else
elessair 0:f269e3021894 1102 { /* handle case of one pointers being null (if both null, test should pass) */
elessair 0:f269e3021894 1103 if (expected[j] != actual[j])
elessair 0:f269e3021894 1104 {
elessair 0:f269e3021894 1105 Unity.CurrentTestFailed = 1;
elessair 0:f269e3021894 1106 }
elessair 0:f269e3021894 1107 }
elessair 0:f269e3021894 1108
elessair 0:f269e3021894 1109 if (Unity.CurrentTestFailed)
elessair 0:f269e3021894 1110 {
elessair 0:f269e3021894 1111 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 1112 if (num_elements > 1)
elessair 0:f269e3021894 1113 {
elessair 0:f269e3021894 1114 UnityPrint(UnityStrElement);
elessair 0:f269e3021894 1115 UnityPrintNumberUnsigned(j);
elessair 0:f269e3021894 1116 }
elessair 0:f269e3021894 1117 UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
elessair 0:f269e3021894 1118 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 1119 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 1120 }
elessair 0:f269e3021894 1121 } while (++j < num_elements);
elessair 0:f269e3021894 1122 }
elessair 0:f269e3021894 1123
elessair 0:f269e3021894 1124 /*-----------------------------------------------*/
elessair 0:f269e3021894 1125 void UnityAssertEqualMemory( UNITY_INTERNAL_PTR expected,
elessair 0:f269e3021894 1126 UNITY_INTERNAL_PTR actual,
elessair 0:f269e3021894 1127 const _UU32 length,
elessair 0:f269e3021894 1128 const _UU32 num_elements,
elessair 0:f269e3021894 1129 const char* msg,
elessair 0:f269e3021894 1130 const UNITY_LINE_TYPE lineNumber)
elessair 0:f269e3021894 1131 {
elessair 0:f269e3021894 1132 UNITY_PTR_ATTRIBUTE const unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected;
elessair 0:f269e3021894 1133 UNITY_PTR_ATTRIBUTE const unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char*)actual;
elessair 0:f269e3021894 1134 _UU32 elements = num_elements;
elessair 0:f269e3021894 1135 _UU32 bytes;
elessair 0:f269e3021894 1136
elessair 0:f269e3021894 1137 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 1138
elessair 0:f269e3021894 1139 if ((elements == 0) || (length == 0))
elessair 0:f269e3021894 1140 {
elessair 0:f269e3021894 1141 UnityPrintPointlessAndBail();
elessair 0:f269e3021894 1142 }
elessair 0:f269e3021894 1143
elessair 0:f269e3021894 1144 if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1)
elessair 0:f269e3021894 1145 return;
elessair 0:f269e3021894 1146
elessair 0:f269e3021894 1147 while (elements--)
elessair 0:f269e3021894 1148 {
elessair 0:f269e3021894 1149 /* /////////////////////////////////// */
elessair 0:f269e3021894 1150 bytes = length;
elessair 0:f269e3021894 1151 while (bytes--)
elessair 0:f269e3021894 1152 {
elessair 0:f269e3021894 1153 if (*ptr_exp != *ptr_act)
elessair 0:f269e3021894 1154 {
elessair 0:f269e3021894 1155 UnityTestResultsFailBegin(lineNumber);
elessair 0:f269e3021894 1156 UnityPrint(UnityStrMemory);
elessair 0:f269e3021894 1157 if (num_elements > 1)
elessair 0:f269e3021894 1158 {
elessair 0:f269e3021894 1159 UnityPrint(UnityStrElement);
elessair 0:f269e3021894 1160 UnityPrintNumberUnsigned(num_elements - elements - 1);
elessair 0:f269e3021894 1161 }
elessair 0:f269e3021894 1162 UnityPrint(UnityStrByte);
elessair 0:f269e3021894 1163 UnityPrintNumberUnsigned(length - bytes - 1);
elessair 0:f269e3021894 1164 UnityPrint(UnityStrExpected);
elessair 0:f269e3021894 1165 UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8);
elessair 0:f269e3021894 1166 UnityPrint(UnityStrWas);
elessair 0:f269e3021894 1167 UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8);
elessair 0:f269e3021894 1168 UnityAddMsgIfSpecified(msg);
elessair 0:f269e3021894 1169 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 1170 }
elessair 0:f269e3021894 1171 ptr_exp = (UNITY_INTERNAL_PTR)((_UP)ptr_exp + 1);
elessair 0:f269e3021894 1172 ptr_act = (UNITY_INTERNAL_PTR)((_UP)ptr_act + 1);
elessair 0:f269e3021894 1173 }
elessair 0:f269e3021894 1174 /* /////////////////////////////////// */
elessair 0:f269e3021894 1175
elessair 0:f269e3021894 1176 }
elessair 0:f269e3021894 1177 }
elessair 0:f269e3021894 1178
elessair 0:f269e3021894 1179 /*-----------------------------------------------
elessair 0:f269e3021894 1180 * Control Functions
elessair 0:f269e3021894 1181 *-----------------------------------------------*/
elessair 0:f269e3021894 1182
elessair 0:f269e3021894 1183 void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
elessair 0:f269e3021894 1184 {
elessair 0:f269e3021894 1185 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 1186
elessair 0:f269e3021894 1187 UnityTestResultsBegin(Unity.TestFile, line);
elessair 0:f269e3021894 1188 UnityPrintFail();
elessair 0:f269e3021894 1189 if (msg != NULL)
elessair 0:f269e3021894 1190 {
elessair 0:f269e3021894 1191 UNITY_OUTPUT_CHAR(':');
elessair 0:f269e3021894 1192
elessair 0:f269e3021894 1193 #ifndef UNITY_EXCLUDE_DETAILS
elessair 0:f269e3021894 1194 if (Unity.CurrentDetail1)
elessair 0:f269e3021894 1195 {
elessair 0:f269e3021894 1196 UnityPrint(UnityStrDetail1Name);
elessair 0:f269e3021894 1197 UnityPrint(Unity.CurrentDetail1);
elessair 0:f269e3021894 1198 if (Unity.CurrentDetail2)
elessair 0:f269e3021894 1199 {
elessair 0:f269e3021894 1200 UnityPrint(UnityStrDetail2Name);
elessair 0:f269e3021894 1201 UnityPrint(Unity.CurrentDetail2);
elessair 0:f269e3021894 1202 }
elessair 0:f269e3021894 1203 UnityPrint(UnityStrSpacer);
elessair 0:f269e3021894 1204 }
elessair 0:f269e3021894 1205 #endif
elessair 0:f269e3021894 1206 if (msg[0] != ' ')
elessair 0:f269e3021894 1207 {
elessair 0:f269e3021894 1208 UNITY_OUTPUT_CHAR(' ');
elessair 0:f269e3021894 1209 }
elessair 0:f269e3021894 1210 UnityPrint(msg);
elessair 0:f269e3021894 1211 }
elessair 0:f269e3021894 1212 UNITY_FAIL_AND_BAIL;
elessair 0:f269e3021894 1213 }
elessair 0:f269e3021894 1214
elessair 0:f269e3021894 1215 /*-----------------------------------------------*/
elessair 0:f269e3021894 1216 void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
elessair 0:f269e3021894 1217 {
elessair 0:f269e3021894 1218 UNITY_SKIP_EXECUTION;
elessair 0:f269e3021894 1219
elessair 0:f269e3021894 1220 UnityTestResultsBegin(Unity.TestFile, line);
elessair 0:f269e3021894 1221 UnityPrint(UnityStrIgnore);
elessair 0:f269e3021894 1222 if (msg != NULL)
elessair 0:f269e3021894 1223 {
elessair 0:f269e3021894 1224 UNITY_OUTPUT_CHAR(':');
elessair 0:f269e3021894 1225 UNITY_OUTPUT_CHAR(' ');
elessair 0:f269e3021894 1226 UnityPrint(msg);
elessair 0:f269e3021894 1227 }
elessair 0:f269e3021894 1228 UNITY_IGNORE_AND_BAIL;
elessair 0:f269e3021894 1229 }
elessair 0:f269e3021894 1230
elessair 0:f269e3021894 1231 /*-----------------------------------------------*/
elessair 0:f269e3021894 1232 #if defined(UNITY_WEAK_ATTRIBUTE)
elessair 0:f269e3021894 1233 UNITY_WEAK_ATTRIBUTE void setUp(void) { }
elessair 0:f269e3021894 1234 UNITY_WEAK_ATTRIBUTE void tearDown(void) { }
elessair 0:f269e3021894 1235 #elif defined(UNITY_WEAK_PRAGMA)
elessair 0:f269e3021894 1236 # pragma weak setUp
elessair 0:f269e3021894 1237 void setUp(void) { }
elessair 0:f269e3021894 1238 # pragma weak tearDown
elessair 0:f269e3021894 1239 void tearDown(void) { }
elessair 0:f269e3021894 1240 #endif
elessair 0:f269e3021894 1241 /*-----------------------------------------------*/
elessair 0:f269e3021894 1242 void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
elessair 0:f269e3021894 1243 {
elessair 0:f269e3021894 1244 Unity.CurrentTestName = FuncName;
elessair 0:f269e3021894 1245 Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
elessair 0:f269e3021894 1246 Unity.NumberOfTests++;
elessair 0:f269e3021894 1247 UNITY_CLR_DETAILS();
elessair 0:f269e3021894 1248 if (TEST_PROTECT())
elessair 0:f269e3021894 1249 {
elessair 0:f269e3021894 1250 setUp();
elessair 0:f269e3021894 1251 Func();
elessair 0:f269e3021894 1252 }
elessair 0:f269e3021894 1253 if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
elessair 0:f269e3021894 1254 {
elessair 0:f269e3021894 1255 tearDown();
elessair 0:f269e3021894 1256 }
elessair 0:f269e3021894 1257 UnityConcludeTest();
elessair 0:f269e3021894 1258 }
elessair 0:f269e3021894 1259
elessair 0:f269e3021894 1260 /*-----------------------------------------------*/
elessair 0:f269e3021894 1261 void UnityBegin(const char* filename)
elessair 0:f269e3021894 1262 {
elessair 0:f269e3021894 1263 Unity.TestFile = filename;
elessair 0:f269e3021894 1264 Unity.CurrentTestName = NULL;
elessair 0:f269e3021894 1265 Unity.CurrentTestLineNumber = 0;
elessair 0:f269e3021894 1266 Unity.NumberOfTests = 0;
elessair 0:f269e3021894 1267 Unity.TestFailures = 0;
elessair 0:f269e3021894 1268 Unity.TestIgnores = 0;
elessair 0:f269e3021894 1269 Unity.CurrentTestFailed = 0;
elessair 0:f269e3021894 1270 Unity.CurrentTestIgnored = 0;
elessair 0:f269e3021894 1271
elessair 0:f269e3021894 1272 UNITY_CLR_DETAILS();
elessair 0:f269e3021894 1273 UNITY_OUTPUT_START();
elessair 0:f269e3021894 1274 }
elessair 0:f269e3021894 1275
elessair 0:f269e3021894 1276 /*-----------------------------------------------*/
elessair 0:f269e3021894 1277 int UnityEnd(void)
elessair 0:f269e3021894 1278 {
elessair 0:f269e3021894 1279 UNITY_PRINT_EOL();
elessair 0:f269e3021894 1280 UnityPrint(UnityStrBreaker);
elessair 0:f269e3021894 1281 UNITY_PRINT_EOL();
elessair 0:f269e3021894 1282 UnityPrintNumber((_U_SINT)(Unity.NumberOfTests));
elessair 0:f269e3021894 1283 UnityPrint(UnityStrResultsTests);
elessair 0:f269e3021894 1284 UnityPrintNumber((_U_SINT)(Unity.TestFailures));
elessair 0:f269e3021894 1285 UnityPrint(UnityStrResultsFailures);
elessair 0:f269e3021894 1286 UnityPrintNumber((_U_SINT)(Unity.TestIgnores));
elessair 0:f269e3021894 1287 UnityPrint(UnityStrResultsIgnored);
elessair 0:f269e3021894 1288 UNITY_PRINT_EOL();
elessair 0:f269e3021894 1289 if (Unity.TestFailures == 0U)
elessair 0:f269e3021894 1290 {
elessair 0:f269e3021894 1291 UnityPrintOk();
elessair 0:f269e3021894 1292 }
elessair 0:f269e3021894 1293 else
elessair 0:f269e3021894 1294 {
elessair 0:f269e3021894 1295 UnityPrintFail();
elessair 0:f269e3021894 1296 #ifdef UNITY_DIFFERENTIATE_FINAL_FAIL
elessair 0:f269e3021894 1297 UNITY_OUTPUT_CHAR('E'); UNITY_OUTPUT_CHAR('D');
elessair 0:f269e3021894 1298 #endif
elessair 0:f269e3021894 1299 }
elessair 0:f269e3021894 1300 UNITY_PRINT_EOL();
elessair 0:f269e3021894 1301 UNITY_OUTPUT_FLUSH();
elessair 0:f269e3021894 1302 UNITY_OUTPUT_COMPLETE();
elessair 0:f269e3021894 1303 return (int)(Unity.TestFailures);
elessair 0:f269e3021894 1304 }
elessair 0:f269e3021894 1305
elessair 0:f269e3021894 1306 /*-----------------------------------------------*/