A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

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