This is an example of BLE GATT Client, which receives broadcast data from BLE_Server_BME280 ( a GATT server) , then transfers values up to mbed Device Connector (cloud).

Please refer details about BLEClient_mbedDevConn below. https://github.com/soramame21/BLEClient_mbedDevConn

The location of required BLE GATT server, BLE_Server_BME280, is at here. https://developer.mbed.org/users/edamame22/code/BLE_Server_BME280/

Committer:
Ren Boting
Date:
Tue Sep 05 11:56:13 2017 +0900
Revision:
2:b894b3508057
Parent:
0:29983394c6b6
Update all libraries and reform main.cpp

Who changed what in which revision?

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