135375f98Sopenharmony_ci#ifdef TEST_INSTANCES
235375f98Sopenharmony_ci
335375f98Sopenharmony_ci#include <string.h>
435375f98Sopenharmony_ci#include <stdint.h>
535375f98Sopenharmony_ci
635375f98Sopenharmony_ci/* Dividing by these constants produces +/- infinity.
735375f98Sopenharmony_ci * The rationale is given in UnityAssertFloatIsInf's body.
835375f98Sopenharmony_ci */
935375f98Sopenharmony_ci#ifndef UNITY_EXCLUDE_FLOAT
1035375f98Sopenharmony_cistatic const UNITY_FLOAT f_zero = 0.0f;
1135375f98Sopenharmony_ci#endif
1235375f98Sopenharmony_ci
1335375f98Sopenharmony_ci#ifndef UNITY_EXCLUDE_DOUBLE
1435375f98Sopenharmony_cistatic const UNITY_DOUBLE d_zero = 0.0;
1535375f98Sopenharmony_ci#endif
1635375f98Sopenharmony_ci
1735375f98Sopenharmony_ci/* Macros for Catching An Expected Failure or Ignore */
1835375f98Sopenharmony_ci#define EXPECT_ABORT_BEGIN \
1935375f98Sopenharmony_ci    startPutcharSpy();     \
2035375f98Sopenharmony_ci    if (TEST_PROTECT())    \
2135375f98Sopenharmony_ci    {
2235375f98Sopenharmony_ci
2335375f98Sopenharmony_ci#define VERIFY_FAILS_END                                                       \
2435375f98Sopenharmony_ci    }                                                                          \
2535375f98Sopenharmony_ci    endPutcharSpy(); /* start/end Spy to suppress output of failure message */ \
2635375f98Sopenharmony_ci    Unity.CurrentTestFailed = (Unity.CurrentTestFailed == 1) ? 0 : 1;          \
2735375f98Sopenharmony_ci    if (Unity.CurrentTestFailed == 1) {                                        \
2835375f98Sopenharmony_ci      SetToOneMeanWeAlreadyCheckedThisGuy = 1;                                 \
2935375f98Sopenharmony_ci      UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber);                   \
3035375f98Sopenharmony_ci      UNITY_OUTPUT_CHAR(':');                                                  \
3135375f98Sopenharmony_ci      UnityPrint(Unity.CurrentTestName);                                       \
3235375f98Sopenharmony_ci      UnityPrint(":FAIL: [[[[ Test Should Have Failed But Did Not ]]]]");      \
3335375f98Sopenharmony_ci      UNITY_OUTPUT_CHAR('\n');                                                 \
3435375f98Sopenharmony_ci    }
3535375f98Sopenharmony_ci
3635375f98Sopenharmony_ci#define VERIFY_IGNORES_END                                                     \
3735375f98Sopenharmony_ci    }                                                                          \
3835375f98Sopenharmony_ci    endPutcharSpy(); /* start/end Spy to suppress output of ignore message */  \
3935375f98Sopenharmony_ci    Unity.CurrentTestFailed = (Unity.CurrentTestIgnored == 1) ? 0 : 1;         \
4035375f98Sopenharmony_ci    Unity.CurrentTestIgnored = 0;                                              \
4135375f98Sopenharmony_ci    if (Unity.CurrentTestFailed == 1) {                                        \
4235375f98Sopenharmony_ci      SetToOneMeanWeAlreadyCheckedThisGuy = 1;                                 \
4335375f98Sopenharmony_ci      UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber);                   \
4435375f98Sopenharmony_ci      UNITY_OUTPUT_CHAR(':');                                                  \
4535375f98Sopenharmony_ci      UnityPrint(Unity.CurrentTestName);                                       \
4635375f98Sopenharmony_ci      UnityPrint(":FAIL: [[[[ Test Should Have Ignored But Did Not ]]]]");     \
4735375f98Sopenharmony_ci      UNITY_OUTPUT_CHAR('\n');                                                 \
4835375f98Sopenharmony_ci    }
4935375f98Sopenharmony_ci
5035375f98Sopenharmony_ci/* Tricky series of macros to set USING_OUTPUT_SPY */
5135375f98Sopenharmony_ci#define USING_SPY_AS(a)           EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0)
5235375f98Sopenharmony_ci#define ASSIGN_VALUE(a)           VAL_##a
5335375f98Sopenharmony_ci#define VAL_putcharSpy            0, 1
5435375f98Sopenharmony_ci#define EXPAND_AND_USE_2ND(a, b)  SECOND_PARAM(a, b, throwaway)
5535375f98Sopenharmony_ci#define SECOND_PARAM(a, b, ...)   b
5635375f98Sopenharmony_ci#if USING_SPY_AS(UNITY_OUTPUT_CHAR)
5735375f98Sopenharmony_ci  #define USING_OUTPUT_SPY /* true only if UNITY_OUTPUT_CHAR = putcharSpy */
5835375f98Sopenharmony_ci#endif
5935375f98Sopenharmony_ci
6035375f98Sopenharmony_ci#ifdef USING_OUTPUT_SPY
6135375f98Sopenharmony_ci#include <stdio.h>
6235375f98Sopenharmony_ci#define SPY_BUFFER_MAX 40
6335375f98Sopenharmony_cistatic char putcharSpyBuffer[SPY_BUFFER_MAX];
6435375f98Sopenharmony_ci#endif
6535375f98Sopenharmony_cistatic int indexSpyBuffer;
6635375f98Sopenharmony_cistatic int putcharSpyEnabled;
6735375f98Sopenharmony_ci
6835375f98Sopenharmony_civoid startPutcharSpy(void)
6935375f98Sopenharmony_ci{
7035375f98Sopenharmony_ci    indexSpyBuffer = 0;
7135375f98Sopenharmony_ci    putcharSpyEnabled = 1;
7235375f98Sopenharmony_ci}
7335375f98Sopenharmony_ci
7435375f98Sopenharmony_civoid endPutcharSpy(void)
7535375f98Sopenharmony_ci{
7635375f98Sopenharmony_ci    putcharSpyEnabled = 0;
7735375f98Sopenharmony_ci}
7835375f98Sopenharmony_ci
7935375f98Sopenharmony_cichar* getBufferPutcharSpy(void)
8035375f98Sopenharmony_ci{
8135375f98Sopenharmony_ci#ifdef USING_OUTPUT_SPY
8235375f98Sopenharmony_ci    putcharSpyBuffer[indexSpyBuffer] = '\0';
8335375f98Sopenharmony_ci    return putcharSpyBuffer;
8435375f98Sopenharmony_ci#else
8535375f98Sopenharmony_ci    return NULL;
8635375f98Sopenharmony_ci#endif
8735375f98Sopenharmony_ci}
8835375f98Sopenharmony_ci
8935375f98Sopenharmony_civoid putcharSpy(int c)
9035375f98Sopenharmony_ci{
9135375f98Sopenharmony_ci#ifdef USING_OUTPUT_SPY
9235375f98Sopenharmony_ci    if (putcharSpyEnabled)
9335375f98Sopenharmony_ci    {
9435375f98Sopenharmony_ci        if (indexSpyBuffer < SPY_BUFFER_MAX - 1)
9535375f98Sopenharmony_ci            putcharSpyBuffer[indexSpyBuffer++] = (char)c;
9635375f98Sopenharmony_ci    } else
9735375f98Sopenharmony_ci        putchar((char)c);
9835375f98Sopenharmony_ci#else
9935375f98Sopenharmony_ci    (void)c;
10035375f98Sopenharmony_ci#endif
10135375f98Sopenharmony_ci}
10235375f98Sopenharmony_ci
10335375f98Sopenharmony_ci/* This is for counting the calls to the flushSpy */
10435375f98Sopenharmony_cistatic int flushSpyEnabled;
10535375f98Sopenharmony_cistatic int flushSpyCalls = 0;
10635375f98Sopenharmony_ci
10735375f98Sopenharmony_civoid startFlushSpy(void)
10835375f98Sopenharmony_ci{
10935375f98Sopenharmony_ci    flushSpyCalls = 0;
11035375f98Sopenharmony_ci    flushSpyEnabled = 1;
11135375f98Sopenharmony_ci}
11235375f98Sopenharmony_ci
11335375f98Sopenharmony_civoid endFlushSpy(void)
11435375f98Sopenharmony_ci{
11535375f98Sopenharmony_ci    flushSpyCalls = 0;
11635375f98Sopenharmony_ci    flushSpyEnabled = 0;
11735375f98Sopenharmony_ci}
11835375f98Sopenharmony_ci
11935375f98Sopenharmony_ciint getFlushSpyCalls(void)
12035375f98Sopenharmony_ci{
12135375f98Sopenharmony_ci    return flushSpyCalls;
12235375f98Sopenharmony_ci}
12335375f98Sopenharmony_ci
12435375f98Sopenharmony_civoid flushSpy(void)
12535375f98Sopenharmony_ci{
12635375f98Sopenharmony_ci    if (flushSpyEnabled){ flushSpyCalls++; }
12735375f98Sopenharmony_ci}
12835375f98Sopenharmony_ci
12935375f98Sopenharmony_ci#define TEST_ASSERT_EQUAL_PRINT_NUMBERS(expected, actual) {             \
13035375f98Sopenharmony_ci        startPutcharSpy(); UnityPrintNumber((actual)); endPutcharSpy(); \
13135375f98Sopenharmony_ci        TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy());    \
13235375f98Sopenharmony_ci        }
13335375f98Sopenharmony_ci
13435375f98Sopenharmony_ci#define TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS(expected, actual) {            \
13535375f98Sopenharmony_ci        startPutcharSpy(); UnityPrintNumberUnsigned((actual)); endPutcharSpy(); \
13635375f98Sopenharmony_ci        TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy());            \
13735375f98Sopenharmony_ci        }
13835375f98Sopenharmony_ci
13935375f98Sopenharmony_ci#define TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, actual) {            \
14035375f98Sopenharmony_ci        startPutcharSpy(); UnityPrintFloat((actual)); endPutcharSpy();  \
14135375f98Sopenharmony_ci        TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy());    \
14235375f98Sopenharmony_ci        }
14335375f98Sopenharmony_ci
14435375f98Sopenharmony_ci#endif
145