chore: migrate project into clean repository

This commit is contained in:
yuuux
2026-08-13 16:50:52 +08:00
commit d1d25a09e7
27405 changed files with 9422808 additions and 0 deletions

View File

@@ -0,0 +1,151 @@
/* =========================================================================
Unity - A Test Framework for C
ThrowTheSwitch.org
Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifdef TEST_INSTANCES
#include <string.h>
#include <stdint.h>
/* Dividing by these constants produces +/- infinity.
* The rationale is given in UnityAssertFloatIsInf's body.
*/
#ifndef UNITY_EXCLUDE_FLOAT
static const UNITY_FLOAT f_zero = 0.0f;
#endif
#ifndef UNITY_EXCLUDE_DOUBLE
static const UNITY_DOUBLE d_zero = 0.0;
#endif
/* Macros for Catching An Expected Failure or Ignore */
#define EXPECT_ABORT_BEGIN \
startPutcharSpy(); \
if (TEST_PROTECT()) \
{
#define VERIFY_FAILS_END \
} \
endPutcharSpy(); /* start/end Spy to suppress output of failure message */ \
Unity.CurrentTestFailed = (Unity.CurrentTestFailed == 1) ? 0 : 1; \
if (Unity.CurrentTestFailed == 1) { \
SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \
UNITY_OUTPUT_CHAR(':'); \
UnityPrint(Unity.CurrentTestName); \
UnityPrint(":FAIL: [[[[ Test Should Have Failed But Did Not ]]]]"); \
UNITY_OUTPUT_CHAR('\n'); \
}
#define VERIFY_IGNORES_END \
} \
endPutcharSpy(); /* start/end Spy to suppress output of ignore message */ \
Unity.CurrentTestFailed = (Unity.CurrentTestIgnored == 1) ? 0 : 1; \
Unity.CurrentTestIgnored = 0; \
if (Unity.CurrentTestFailed == 1) { \
SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \
UNITY_OUTPUT_CHAR(':'); \
UnityPrint(Unity.CurrentTestName); \
UnityPrint(":FAIL: [[[[ Test Should Have Ignored But Did Not ]]]]"); \
UNITY_OUTPUT_CHAR('\n'); \
}
/* Tricky series of macros to set USING_OUTPUT_SPY */
#define USING_SPY_AS(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0)
#define ASSIGN_VALUE(a) VAL_##a
#define VAL_putcharSpy 0, 1
#define EXPAND_AND_USE_2ND(a, b) SECOND_PARAM(a, b, throwaway)
#define SECOND_PARAM(a, b, ...) b
#if USING_SPY_AS(UNITY_OUTPUT_CHAR)
#define USING_OUTPUT_SPY /* true only if UNITY_OUTPUT_CHAR = putcharSpy */
#endif
#ifdef USING_OUTPUT_SPY
#include <stdio.h>
#define SPY_BUFFER_MAX 40
static char putcharSpyBuffer[SPY_BUFFER_MAX];
#endif
static UNITY_COUNTER_TYPE indexSpyBuffer;
static UNITY_COUNTER_TYPE putcharSpyEnabled;
void startPutcharSpy(void)
{
indexSpyBuffer = 0;
putcharSpyEnabled = 1;
}
void endPutcharSpy(void)
{
putcharSpyEnabled = 0;
}
char* getBufferPutcharSpy(void)
{
#ifdef USING_OUTPUT_SPY
putcharSpyBuffer[indexSpyBuffer] = '\0';
return putcharSpyBuffer;
#else
return NULL;
#endif
}
void putcharSpy(int c)
{
#ifdef USING_OUTPUT_SPY
if (putcharSpyEnabled)
{
if (indexSpyBuffer < SPY_BUFFER_MAX - 1)
putcharSpyBuffer[indexSpyBuffer++] = (char)c;
} else
putchar((char)c);
#else
(void)c;
#endif
}
/* This is for counting the calls to the flushSpy */
static UNITY_COUNTER_TYPE flushSpyEnabled;
static UNITY_COUNTER_TYPE flushSpyCalls = 0;
void startFlushSpy(void)
{
flushSpyCalls = 0;
flushSpyEnabled = 1;
}
void endFlushSpy(void)
{
flushSpyCalls = 0;
flushSpyEnabled = 0;
}
UNITY_COUNTER_TYPE getFlushSpyCalls(void)
{
return flushSpyCalls;
}
void flushSpy(void)
{
if (flushSpyEnabled){ flushSpyCalls++; }
}
#define TEST_ASSERT_EQUAL_PRINT_NUMBERS(expected, actual) { \
startPutcharSpy(); UnityPrintNumber((actual)); endPutcharSpy(); \
TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \
}
#define TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS(expected, actual) { \
startPutcharSpy(); UnityPrintNumberUnsigned((actual)); endPutcharSpy(); \
TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \
}
#define TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, actual) { \
startPutcharSpy(); UnityPrintFloat((actual)); endPutcharSpy(); \
TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,375 @@
/* =========================================================================
Unity - A Test Framework for C
ThrowTheSwitch.org
Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#define TEST_INSTANCES
#include "self_assessment_utils.h"
static int SetToOneToFailInTearDown;
static int SetToOneMeanWeAlreadyCheckedThisGuy;
void setUp(void)
{
SetToOneToFailInTearDown = 0;
SetToOneMeanWeAlreadyCheckedThisGuy = 0;
}
void tearDown(void)
{
endPutcharSpy(); /* Stop suppressing test output */
if (SetToOneToFailInTearDown == 1)
{
/* These will be skipped internally if already failed/ignored */
TEST_FAIL_MESSAGE("<= Failed in tearDown");
TEST_IGNORE_MESSAGE("<= Ignored in tearDown");
}
if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0))
{
UnityPrint(": [[[[ Test Should Have Passed But Did Not ]]]]");
UNITY_OUTPUT_CHAR('\n');
}
}
void testUnitySizeInitializationReminder(void)
{
/* This test ensures that sizeof(struct UNITY_STORAGE_T) doesn't change. If this
* test breaks, go look at the initialization of the Unity global variable
* in unity.c and make sure we're filling in the proper fields. */
const char* message = "Unexpected size for UNITY_STORAGE_T struct. Please check that "
"the initialization of the Unity symbol in unity.c is "
"still correct.";
/* Define a structure with all the same fields as `struct UNITY_STORAGE_T`. */
#ifdef UNITY_EXCLUDE_DETAILS
struct {
const char* TestFile;
const char* CurrentTestName;
UNITY_LINE_TYPE CurrentTestLineNumber;
UNITY_COUNTER_TYPE NumberOfTests;
UNITY_COUNTER_TYPE TestFailures;
UNITY_COUNTER_TYPE TestIgnores;
UNITY_COUNTER_TYPE CurrentTestFailed;
UNITY_COUNTER_TYPE CurrentTestIgnored;
#ifdef UNITY_INCLUDE_EXEC_TIME
UNITY_TIME_TYPE CurrentTestStartTime;
UNITY_TIME_TYPE CurrentTestStopTime;
#endif
#ifndef UNITY_EXCLUDE_SETJMP_H
jmp_buf AbortFrame;
#endif
} _Expected_Unity;
#else
struct {
const char* TestFile;
const char* CurrentTestName;
const char* CurrentDetails1;
const char* CurrentDetails2;
UNITY_LINE_TYPE CurrentTestLineNumber;
UNITY_COUNTER_TYPE NumberOfTests;
UNITY_COUNTER_TYPE TestFailures;
UNITY_COUNTER_TYPE TestIgnores;
UNITY_COUNTER_TYPE CurrentTestFailed;
UNITY_COUNTER_TYPE CurrentTestIgnored;
#ifdef UNITY_INCLUDE_EXEC_TIME
UNITY_COUNTER_TYPE CurrentTestStartTime;
UNITY_COUNTER_TYPE CurrentTestStopTime;
#endif
#ifndef UNITY_EXCLUDE_SETJMP_H
jmp_buf AbortFrame;
#endif
} _Expected_Unity;
#endif
/* Compare our fake structure's size to the actual structure's size. They
* should be the same.
*
* This accounts for alignment, padding, and packing issues that might come
* up between different architectures. */
TEST_ASSERT_EQUAL_MESSAGE(sizeof(_Expected_Unity), sizeof(Unity), message);
}
void testPassShouldEndImmediatelyWithPass(void)
{
TEST_PASS();
TEST_FAIL_MESSAGE("We should have passed already and finished this test");
}
void testPassShouldEndImmediatelyWithPassAndMessage(void)
{
TEST_PASS_MESSAGE("Woohoo! This Automatically Passes!");
TEST_FAIL_MESSAGE("We should have passed already and finished this test");
}
void testMessageShouldDisplayMessageWithoutEndingAndGoOnToPass(void)
{
TEST_MESSAGE("This is just a message");
TEST_MESSAGE("This is another message");
TEST_PASS();
}
void testMessageShouldDisplayMessageWithoutEndingAndGoOnToFail(void)
{
TEST_MESSAGE("This is yet another message");
EXPECT_ABORT_BEGIN
TEST_FAIL();
VERIFY_FAILS_END
}
void testTrue(void)
{
TEST_ASSERT(1);
TEST_ASSERT_TRUE(1);
}
void testFalse(void)
{
TEST_ASSERT_FALSE(0);
TEST_ASSERT_UNLESS(0);
}
void testSingleStatement(void)
{
for(int i = 0; i < 2; i++)
{
/* TEST_ASSERT_TRUE should expand to a single C statement, minus
* the semicolon. This if-else will fail to compile otherwise. */
if(i > 0)
TEST_ASSERT_TRUE(i);
else
TEST_ASSERT_FALSE(i);
}
}
void testPreviousPass(void)
{
TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures);
}
void testNotVanilla(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT(0);
VERIFY_FAILS_END
}
void testNotTrue(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_TRUE(0);
VERIFY_FAILS_END
}
void testNotFalse(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_FALSE(1);
VERIFY_FAILS_END
}
void testNotUnless(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_UNLESS(1);
VERIFY_FAILS_END
}
void testNotNotEqual(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_NOT_EQUAL(10, 10);
VERIFY_FAILS_END
}
void testFail(void)
{
EXPECT_ABORT_BEGIN
TEST_FAIL_MESSAGE("Expected for testing");
VERIFY_FAILS_END
}
void testIsNull(void)
{
char* ptr1 = NULL;
const char* ptr2 = "hello";
TEST_ASSERT_NULL(ptr1);
TEST_ASSERT_NOT_NULL(ptr2);
}
void testIsNullShouldFailIfNot(void)
{
const char* ptr1 = "hello";
EXPECT_ABORT_BEGIN
TEST_ASSERT_NULL(ptr1);
VERIFY_FAILS_END
}
void testNotNullShouldFailIfNULL(void)
{
char* ptr1 = NULL;
EXPECT_ABORT_BEGIN
TEST_ASSERT_NOT_NULL(ptr1);
VERIFY_FAILS_END
}
void testIsEmpty(void)
{
const char* ptr1 = "\0";
const char* ptr2 = "hello";
TEST_ASSERT_EMPTY(ptr1);
TEST_ASSERT_NOT_EMPTY(ptr2);
}
void testIsEmptyShouldFailIfNot(void)
{
const char* ptr1 = "hello";
EXPECT_ABORT_BEGIN
TEST_ASSERT_EMPTY(ptr1);
VERIFY_FAILS_END
}
void testNotEmptyShouldFailIfEmpty(void)
{
const char* ptr1 = "\0";
EXPECT_ABORT_BEGIN
TEST_ASSERT_NOT_EMPTY(ptr1);
VERIFY_FAILS_END
}
void testIgnore(void)
{
EXPECT_ABORT_BEGIN
TEST_IGNORE();
TEST_FAIL_MESSAGE("This should not be reached");
VERIFY_IGNORES_END
}
void testIgnoreMessage(void)
{
EXPECT_ABORT_BEGIN
TEST_IGNORE_MESSAGE("This is an expected TEST_IGNORE_MESSAGE string!");
TEST_FAIL_MESSAGE("This should not be reached");
VERIFY_IGNORES_END
}
void testProtection(void)
{
volatile int mask = 0;
if (TEST_PROTECT())
{
mask |= 1;
TEST_ABORT();
}
else
{
Unity.CurrentTestFailed = 0;
mask |= 2;
}
TEST_ASSERT_EQUAL(3, mask);
}
void testIgnoredAndThenFailInTearDown(void)
{
SetToOneToFailInTearDown = 1;
TEST_IGNORE();
}
void testFailureCountIncrementsAndIsReturnedAtEnd(void)
{
#ifndef USING_OUTPUT_SPY
TEST_IGNORE();
#else
int failures = 0;
UNITY_COUNTER_TYPE savedGetFlushSpyCalls = 0;
UNITY_COUNTER_TYPE savedFailures = Unity.TestFailures;
Unity.CurrentTestFailed = 1;
startPutcharSpy(); /* Suppress output */
startFlushSpy();
savedGetFlushSpyCalls = getFlushSpyCalls();
UnityConcludeTest();
endPutcharSpy();
TEST_ASSERT_EQUAL(0, savedGetFlushSpyCalls);
TEST_ASSERT_EQUAL(savedFailures + 1, Unity.TestFailures);
#if defined(UNITY_OUTPUT_FLUSH) && defined(UNITY_OUTPUT_FLUSH_HEADER_DECLARATION)
TEST_ASSERT_EQUAL(1, getFlushSpyCalls());
#else
TEST_ASSERT_EQUAL(0, getFlushSpyCalls());
#endif
endFlushSpy();
startPutcharSpy(); /* Suppress output */
failures = UnityEnd();
Unity.TestFailures--;
endPutcharSpy();
TEST_ASSERT_EQUAL(savedFailures + 1, failures);
#endif
}
/* ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DETAIL SUPPORT ================== */
void testThatDetailsCanBeHandleOneDetail(void)
{
#ifdef UNITY_EXCLUDE_DETAILS
TEST_IGNORE();
#else
UNITY_SET_DETAIL("Detail1");
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_INT_MESSAGE(5, 6, "Should Fail And Say Detail1");
VERIFY_FAILS_END
#endif
}
void testThatDetailsCanHandleTestFail(void)
{
#ifdef UNITY_EXCLUDE_DETAILS
TEST_IGNORE();
#else
UNITY_SET_DETAILS("Detail1","Detail2");
EXPECT_ABORT_BEGIN
TEST_FAIL_MESSAGE("Should Fail And Say Detail1 and Detail2");
VERIFY_FAILS_END
#endif
}
void testThatDetailsCanBeHandleTwoDetails(void)
{
#ifdef UNITY_EXCLUDE_DETAILS
TEST_IGNORE();
#else
UNITY_SET_DETAILS("Detail1","Detail2");
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_HEX8_MESSAGE(7, 8, "Should Fail And Say Detail1 and Detail2");
VERIFY_FAILS_END
#endif
}
void testThatDetailsCanBeHandleSingleDetailClearingTwoDetails(void)
{
#ifdef UNITY_EXCLUDE_DETAILS
TEST_IGNORE();
#else
UNITY_SET_DETAILS("Detail1","Detail2");
UNITY_SET_DETAIL("DetailNew");
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_MESSAGE("MEH", "GUH", "Should Fail And Say DetailNew");
VERIFY_FAILS_END
#endif
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,783 @@
/* =========================================================================
Unity - A Test Framework for C
ThrowTheSwitch.org
Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#define TEST_INSTANCES
#include "self_assessment_utils.h"
static int SetToOneToFailInTearDown;
static int SetToOneMeanWeAlreadyCheckedThisGuy;
void setUp(void)
{
SetToOneToFailInTearDown = 0;
SetToOneMeanWeAlreadyCheckedThisGuy = 0;
}
void tearDown(void)
{
endPutcharSpy(); /* Stop suppressing test output */
if (SetToOneToFailInTearDown == 1)
{
/* These will be skipped internally if already failed/ignored */
TEST_FAIL_MESSAGE("<= Failed in tearDown");
TEST_IGNORE_MESSAGE("<= Ignored in tearDown");
}
if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0))
{
UnityPrint(": [[[[ Test Should Have Passed But Did Not ]]]]");
UNITY_OUTPUT_CHAR('\n');
}
}
void testInt64ArrayWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 expected[] = {12345000, -12344995, 12345005};
UNITY_INT64 actualSmallDelta[] = {12345001, -12344996, 12345005};
UNITY_INT64 actualBigDelta[] = {12345101, -12344896, 12345055};
TEST_ASSERT_INT64_ARRAY_WITHIN(1, expected, actualSmallDelta, 3);
TEST_ASSERT_INT64_ARRAY_WITHIN(110, expected, actualBigDelta, 3);
#endif
}
void testInt64ArrayWithinDeltaAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 expected[] = {12345000, -12344995, 12345005};
UNITY_INT64 actualSmallDelta[] = {12345001, -12344996, 12345005};
UNITY_INT64 actualBigDelta[] = {12345101, -12344896, 12345055};
TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(1, expected, actualSmallDelta, 3, "Custom Message.");
TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(110, expected, actualBigDelta, 3, "Custom Message.");
#endif
}
void testInt64ArrayNotWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 expected[] = {12345000, -12344995, 12345005};
UNITY_INT64 actualBigDelta[] = {12345101, -12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_ARRAY_WITHIN(1, expected, actualBigDelta, 3);
VERIFY_FAILS_END
#endif
}
void testInt64ArrayNotWithinDeltaAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 expected[] = {12345000, -12344995, 12345005};
UNITY_INT64 actualBigDelta[] = {12345101, -12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(1, expected, actualBigDelta, 3, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testInt64ArrayWithinDeltaPointless(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 expected[] = {12345000, -12344995, 12345005};
UNITY_INT64 actualBigDelta[] = {12345101, -12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_INT64_ARRAY_WITHIN(110, expected, actualBigDelta, 0);
VERIFY_FAILS_END
#endif
}
void testInt64ArrayWithinDeltaPointlessAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 expected[] = {12345000, -12344995, 12345005};
UNITY_INT64 actualBigDelta[] = {12345101, -12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(110, expected, actualBigDelta, 0, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testInt64ArrayWithinDeltaExpectedNull(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 actualBigDelta[] = {12345101, -12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_INT64_ARRAY_WITHIN(110, NULL, actualBigDelta, 3);
VERIFY_FAILS_END
#endif
}
void testInt64ArrayWithinDeltaExpectedNullAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 actualBigDelta[] = {12345101, -12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(110, NULL, actualBigDelta, 3, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testInt64ArrayWithinDeltaActualNull(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 expected[] = {12345000, -12344995, 12345005};
EXPECT_ABORT_BEGIN
TEST_ASSERT_INT64_ARRAY_WITHIN(110, expected, NULL, 3);
VERIFY_FAILS_END
#endif
}
void testInt64ArrayWithinDeltaActualNullAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 expected[] = {12345000, -12344995, 12345005};
EXPECT_ABORT_BEGIN
TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testInt64ArrayWithinDeltaSamePointer(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 expected[] = {12345000, -12344995, 12345005};
TEST_ASSERT_UINT64_ARRAY_WITHIN(110, expected, expected, 3);
#endif
}
void testInt64ArrayWithinDeltaSamePointerAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 expected[] = {12345000, -12344995, 12345005};
TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message.");
#endif
}
void testUInt64ArrayWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {12345000, 12344995, 12345005};
UNITY_UINT64 actualSmallDelta[] = {12345001, 12344996, 12345005};
UNITY_UINT64 actualBigDelta[] = {12345101, 12344896, 12345055};
TEST_ASSERT_UINT64_ARRAY_WITHIN(1, expected, actualSmallDelta, 3);
TEST_ASSERT_UINT64_ARRAY_WITHIN(110, expected, actualBigDelta, 3);
#endif
}
void testUInt64ArrayWithinDeltaAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {12345000, 12344995, 12345005};
UNITY_UINT64 actualSmallDelta[] = {12345001, 12344996, 12345005};
UNITY_UINT64 actualBigDelta[] = {12345101, 12344896, 12345055};
TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(1, expected, actualSmallDelta, 3, "Custom Message.");
TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(110, expected, actualBigDelta, 3, "Custom Message.");
#endif
}
void testUInt64ArrayNotWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {12345000, 12344995, 12345005};
UNITY_UINT64 actualBigDelta[] = {12345101, 12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_ARRAY_WITHIN(1, expected, actualBigDelta, 3);
VERIFY_FAILS_END
#endif
}
void testUInt64ArrayNotWithinDeltaAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {12345000, 12344995, 12345005};
UNITY_UINT64 actualBigDelta[] = {12345101, 12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(1, expected, actualBigDelta, 3, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testUInt64ArrayWithinDeltaPointless(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {12345000, 12344995, 12345005};
UNITY_UINT64 actualBigDelta[] = {12345101, 12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_ARRAY_WITHIN(110, expected, actualBigDelta, 0);
VERIFY_FAILS_END
#endif
}
void testUInt64ArrayWithinDeltaPointlessAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {12345000, 12344995, 12345005};
UNITY_UINT64 actualBigDelta[] = {12345101, 12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(110, expected, actualBigDelta, 0, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testUInt64ArrayWithinDeltaExpectedNull(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 actualBigDelta[] = {12345101, 12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_ARRAY_WITHIN(110, NULL, actualBigDelta, 3);
VERIFY_FAILS_END
#endif
}
void testUInt64ArrayWithinDeltaExpectedNullAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 actualBigDelta[] = {12345101, 12344896, 12345055};
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(110, NULL, actualBigDelta, 3, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testUInt64ArrayWithinDeltaActualNull(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {12345000, 12344995, 12345005};
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_ARRAY_WITHIN(110, expected, NULL, 3);
VERIFY_FAILS_END
#endif
}
void testUInt64ArrayWithinDeltaActualNullAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {12345000, 12344995, 12345005};
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(110, expected, NULL, 3, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testUInt64ArrayWithinDeltaSamePointer(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {12345000, 12344995, 12345005};
TEST_ASSERT_UINT64_ARRAY_WITHIN(110, expected, expected, 3);
#endif
}
void testUInt64ArrayWithinDeltaSamePointerAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {12345000, 12344995, 12345005};
TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(110, expected, expected, 3, "Custom Message.");
#endif
}
void testHEX64ArrayWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {0xABCD123400000000, 0xABCD112200000000, 0xABCD127700000000};
UNITY_UINT64 actualSmallDelta[] = {0xABCD123500000000, 0xABCD112100000000, 0xABCD127700000000};
UNITY_UINT64 actualBigDelta[] = {0xABCD126700000000, 0xABCD118800000000, 0xABCD12AC00000000};
TEST_ASSERT_HEX64_ARRAY_WITHIN(0x100000000, expected, actualSmallDelta, 3);
TEST_ASSERT_HEX64_ARRAY_WITHIN(0x6E00000000, expected, actualBigDelta, 3);
#endif
}
void testHEX64ArrayWithinDeltaAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {0xABCD123400000000, 0xABCD112200000000, 0xABCD127700000000};
UNITY_UINT64 actualSmallDelta[] = {0xABCD123500000000, 0xABCD112100000000, 0xABCD127700000000};
UNITY_UINT64 actualBigDelta[] = {0xABCD126700000000, 0xABCD118800000000, 0xABCD12AC00000000};
TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(0x100000000, expected, actualSmallDelta, 3, "Custom Message.");
TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(0x6E00000000, expected, actualBigDelta, 3, "Custom Message.");
#endif
}
void testHEX64ArrayNotWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {0xABCD123400000000, 0xABCD112200000000, 0xABCD127700000000};
UNITY_UINT64 actualBigDelta[] = {0xABCD126700000000, 0xABCD118800000000, 0xABCD12AC00000000};
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX64_ARRAY_WITHIN(0x100000000, expected, actualBigDelta, 3);
VERIFY_FAILS_END
#endif
}
void testHEX64ArrayNotWithinDeltaAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {0xABCD123400000000, 0xABCD112200000000, 0xABCD127700000000};
UNITY_UINT64 actualBigDelta[] = {0xABCD126700000000, 0xABCD118800000000, 0xABCD12AC00000000};
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(0x100000000, expected, actualBigDelta, 3, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testHEX64ArrayWithinDeltaPointless(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {0xABCD123400000000, 0xABCD112200000000, 0xABCD127700000000};
UNITY_UINT64 actualBigDelta[] = {0xABCD126700000000, 0xABCD118800000000, 0xABCD12AC00000000};
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX64_ARRAY_WITHIN(0x6E00000000, expected, actualBigDelta, 0);
VERIFY_FAILS_END
#endif
}
void testHEX64ArrayWithinDeltaPointlessAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {0xABCD123400000000, 0xABCD112200000000, 0xABCD127700000000};
UNITY_UINT64 actualBigDelta[] = {0xABCD126700000000, 0xABCD118800000000, 0xABCD12AC00000000};
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(0x6E00000000, expected, actualBigDelta, 0, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testHEX64ArrayWithinDeltaExpectedNull(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 actualBigDelta[] = {0xABCD126700000000, 0xABCD118800000000, 0xABCD12AC00000000};
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX64_ARRAY_WITHIN(0x6E00000000, NULL, actualBigDelta, 3);
VERIFY_FAILS_END
#endif
}
void testHEX64ArrayWithinDeltaExpectedNullAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 actualBigDelta[] = {0xABCD126700000000, 0xABCD118800000000, 0xABCD12AC00000000};
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(0x6E00000000, NULL, actualBigDelta, 3, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testHEX64ArrayWithinDeltaActualNull(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {0xABCD123400000000, 0xABCD112200000000, 0xABCD127700000000};
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX64_ARRAY_WITHIN(0x6E00000000, expected, NULL, 3);
VERIFY_FAILS_END
#endif
}
void testHEX64ArrayWithinDeltaActualNullAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {0xABCD123400000000, 0xABCD112200000000, 0xABCD127700000000};
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(0x6E00000000, expected, NULL, 3, "Custom Message.");
VERIFY_FAILS_END
#endif
}
void testHEX64ArrayWithinDeltaSamePointer(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {0xABCD123400000000, 0xABCD112200000000, 0xABCD127700000000};
TEST_ASSERT_HEX64_ARRAY_WITHIN(0x6E00000000, expected, expected, 3);
#endif
}
void testHEX64ArrayWithinDeltaSamePointerAndMessage(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 expected[] = {0xABCD123400000000, 0xABCD112200000000, 0xABCD127700000000};
TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(0x6E00000000, expected, expected, 3, "Custom Message.");
#endif
}
void testEqualHex64s(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 v0, v1;
UNITY_UINT64 *p0, *p1;
v0 = 0x9876543201234567;
v1 = 0x9876543201234567;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_EQUAL_HEX64(0x9876543201234567, 0x9876543201234567);
TEST_ASSERT_EQUAL_HEX64(v0, v1);
TEST_ASSERT_EQUAL_HEX64(0x9876543201234567, v1);
TEST_ASSERT_EQUAL_HEX64(v0, 0x9876543201234567);
TEST_ASSERT_EQUAL_HEX64(*p0, v1);
TEST_ASSERT_EQUAL_HEX64(*p0, *p1);
TEST_ASSERT_EQUAL_HEX64(*p0, 0x9876543201234567);
#endif
}
void testEqualUint64s(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 v0, v1;
UNITY_UINT64 *p0, *p1;
v0 = 0x9876543201234567;
v1 = 0x9876543201234567;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_EQUAL_UINT64(0x9876543201234567, 0x9876543201234567);
TEST_ASSERT_EQUAL_UINT64(v0, v1);
TEST_ASSERT_EQUAL_UINT64(0x9876543201234567, v1);
TEST_ASSERT_EQUAL_UINT64(v0, 0x9876543201234567);
TEST_ASSERT_EQUAL_UINT64(*p0, v1);
TEST_ASSERT_EQUAL_UINT64(*p0, *p1);
TEST_ASSERT_EQUAL_UINT64(*p0, 0x9876543201234567);
#endif
}
void testEqualInt64s(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 v0, v1;
UNITY_INT64 *p0, *p1;
v0 = (UNITY_INT64)0x9876543201234567;
v1 = (UNITY_INT64)0x9876543201234567;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_EQUAL_INT64(0x9876543201234567, 0x9876543201234567);
TEST_ASSERT_EQUAL_INT64(v0, v1);
TEST_ASSERT_EQUAL_INT64(0x9876543201234567, v1);
TEST_ASSERT_EQUAL_INT64(v0, 0x9876543201234567);
TEST_ASSERT_EQUAL_INT64(*p0, v1);
TEST_ASSERT_EQUAL_INT64(*p0, *p1);
TEST_ASSERT_EQUAL_INT64(*p0, 0x9876543201234567);
#endif
}
void testNotEqualHex64s(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 v0, v1;
v0 = 9000000000;
v1 = 9100000000;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_HEX64(v0, v1);
VERIFY_FAILS_END
#endif
}
void testNotEqualUint64s(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_UINT64 v0, v1;
v0 = 9000000000;
v1 = 9100000000;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_UINT64(v0, v1);
VERIFY_FAILS_END
#endif
}
void testNotEqualInt64s(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 v0, v1;
v0 = -9000000000;
v1 = 9100000000;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_INT64(v0, v1);
VERIFY_FAILS_END
#endif
}
void testNotEqualHex64sIfSigned(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
UNITY_INT64 v0, v1;
v0 = -9000000000;
v1 = 9000000000;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_HEX64(v0, v1);
VERIFY_FAILS_END
#endif
}
void testHEX64sWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
TEST_ASSERT_HEX64_WITHIN(1, 0x7FFFFFFFFFFFFFFF,0x7FFFFFFFFFFFFFFE);
TEST_ASSERT_HEX64_WITHIN(5, 5000, 4996);
TEST_ASSERT_HEX64_WITHIN(5, 5000, 5005);
#endif
}
void testHEX32sWithinDeltaShouldIgnoreSign(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
TEST_ASSERT_HEX64_WITHIN(1, 0x7FFFFFFFFFFFFFFF,0x8000000000000000);
#endif
}
void testHEX64sNotWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX64_WITHIN(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFC);
VERIFY_FAILS_END
#endif
}
void testHEX64sNotWithinDeltaEvenThoughASignedIntWouldPass(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX64_WITHIN(5, 1, -1);
VERIFY_FAILS_END
#endif
}
void testUINT64sWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
TEST_ASSERT_UINT64_WITHIN(1, 0x7FFFFFFFFFFFFFFF,0x7FFFFFFFFFFFFFFE);
TEST_ASSERT_UINT64_WITHIN(5, 5000, 4996);
TEST_ASSERT_UINT64_WITHIN(5, 5000, 5005);
#endif
}
void testUINT64sNotWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_WITHIN(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFC);
VERIFY_FAILS_END
#endif
}
void testUINT64sNotWithinDeltaEvenThoughASignedIntWouldPass(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT64_WITHIN(5, 1, -1);
VERIFY_FAILS_END
#endif
}
void testINT64sWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
TEST_ASSERT_INT64_WITHIN(1, 0x7FFFFFFFFFFFFFFF,0x7FFFFFFFFFFFFFFE);
TEST_ASSERT_INT64_WITHIN(5, 5000, 4996);
TEST_ASSERT_INT64_WITHIN(5, 5000, 5005);
#endif
}
void testINT64sNotWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_INT64_WITHIN(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFC);
VERIFY_FAILS_END
#endif
}
void testINT64sNotWithinDeltaAndDifferenceOverflows(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_INT64_WITHIN(1, 0x8000000000000000, 0x7FFFFFFFFFFFFFFF);
VERIFY_FAILS_END
#endif
}
void testPrintNumbersInt64(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
#ifndef USING_OUTPUT_SPY
TEST_IGNORE();
#else
TEST_ASSERT_EQUAL_PRINT_NUMBERS("0", 0);
TEST_ASSERT_EQUAL_PRINT_NUMBERS("10000000000", 10000000000);
TEST_ASSERT_EQUAL_PRINT_NUMBERS("-9223372036854775808", (UNITY_INT)0x8000000000000000);
TEST_ASSERT_EQUAL_PRINT_NUMBERS("-1", (UNITY_INT)0xFFFFFFFFFFFFFFFF);
#endif
#endif
}
void testPrintNumbersUInt64(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();
#else
#ifndef USING_OUTPUT_SPY
TEST_IGNORE();
#else
TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("0", 0);
TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("70000000000", 70000000000);
TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("9223372036854775808", (UNITY_UINT)0x8000000000000000);
TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("18446744073709551615", (UNITY_UINT)0xFFFFFFFFFFFFFFFF);
#endif
#endif
}

View File

@@ -0,0 +1,82 @@
/* =========================================================================
Unity - A Test Framework for C
ThrowTheSwitch.org
Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#define TEST_INSTANCES
#include "self_assessment_utils.h"
static int SetToOneToFailInTearDown;
static int SetToOneMeanWeAlreadyCheckedThisGuy;
void setUp(void)
{
SetToOneToFailInTearDown = 0;
SetToOneMeanWeAlreadyCheckedThisGuy = 0;
}
void tearDown(void)
{
endPutcharSpy(); /* Stop suppressing test output */
if (SetToOneToFailInTearDown == 1)
{
/* These will be skipped internally if already failed/ignored */
TEST_FAIL_MESSAGE("<= Failed in tearDown");
TEST_IGNORE_MESSAGE("<= Ignored in tearDown");
}
if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0))
{
UnityPrint(": [[[[ Test Should Have Passed But Did Not ]]]]");
UNITY_OUTPUT_CHAR('\n');
}
}
void testEqualMemory(void)
{
const char *testString = "whatever";
TEST_ASSERT_EQUAL_MEMORY(testString, testString, 8);
TEST_ASSERT_EQUAL_MEMORY("whatever", "whatever", 8);
TEST_ASSERT_EQUAL_MEMORY("whatever", testString, 8);
TEST_ASSERT_EQUAL_MEMORY(testString, "whatever", 8);
TEST_ASSERT_EQUAL_MEMORY(testString, "whatever", 2);
TEST_ASSERT_EQUAL_MEMORY(NULL, NULL, 1);
}
void testNotEqualMemory1(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_MEMORY("foo", "bar", 3);
VERIFY_FAILS_END
}
void testNotEqualMemory2(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_MEMORY("fool", "food", 4);
VERIFY_FAILS_END
}
void testNotEqualMemory3(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_MEMORY(NULL, "food", 4);
VERIFY_FAILS_END
}
void testNotEqualMemory4(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_MEMORY("fool", NULL, 4);
VERIFY_FAILS_END
}
void testNotEqualMemoryLengthZero(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_MEMORY(NULL, NULL, 0);
VERIFY_FAILS_END
}

View File

@@ -0,0 +1,309 @@
/* =========================================================================
Unity - A Test Framework for C
ThrowTheSwitch.org
Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include <setjmp.h>
#include <stdio.h>
#include "unity.h"
#include "types_for_test.h"
/* Include Passthroughs for Linking Tests */
void putcharSpy(int c) { (void)putchar(c);}
void flushSpy(void) {}
#define EXPECT_ABORT_BEGIN \
if (TEST_PROTECT()) \
{
#define VERIFY_FAILS_END \
} \
Unity.CurrentTestFailed = (Unity.CurrentTestFailed != 0) ? 0 : 1; \
if (Unity.CurrentTestFailed == 1) { \
SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \
UNITY_OUTPUT_CHAR(':'); \
UnityPrint(Unity.CurrentTestName); \
UnityPrint(":FAIL: [[[[ Test Should Have Failed But Did Not ]]]]"); \
UNITY_OUTPUT_CHAR('\n'); \
}
#define VERIFY_IGNORES_END \
} \
Unity.CurrentTestFailed = (Unity.CurrentTestIgnored != 0) ? 0 : 1; \
Unity.CurrentTestIgnored = 0; \
if (Unity.CurrentTestFailed == 1) { \
SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \
UNITY_OUTPUT_CHAR(':'); \
UnityPrint(Unity.CurrentTestName); \
UnityPrint(":FAIL: [[[[ Test Should Have Ignored But Did Not ]]]]"); \
UNITY_OUTPUT_CHAR('\n'); \
}
static int SetToOneToFailInTearDown;
static int SetToOneMeanWeAlreadyCheckedThisGuy;
static unsigned NextExpectedStringIndex;
static unsigned NextExpectedCharIndex;
static unsigned NextExpectedSpaceIndex;
void suiteSetUp(void)
{
NextExpectedStringIndex = 0;
NextExpectedCharIndex = 0;
NextExpectedSpaceIndex = 0;
}
void setUp(void)
{
SetToOneToFailInTearDown = 0;
SetToOneMeanWeAlreadyCheckedThisGuy = 0;
}
void tearDown(void)
{
if (SetToOneToFailInTearDown == 1)
TEST_FAIL_MESSAGE("<= Failed in tearDown");
if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0))
{
UnityPrint(": [[[[ Test Should Have Passed But Did Not ]]]]");
UNITY_OUTPUT_CHAR('\n');
}
}
TEST_CASE(0)
TEST_CASE(44)
TEST_CASE((90)+9)
void test_TheseShouldAllPass(int Num)
{
TEST_ASSERT_TRUE(Num < 100);
}
TEST_CASE(3)
TEST_CASE(77)
TEST_CASE( (99) + 1 - (1))
void test_TheseShouldAllFail(int Num)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_TRUE(Num > 100);
VERIFY_FAILS_END
}
TEST_CASE(1)
TEST_CASE(44)
TEST_CASE(99)
TEST_CASE(98)
void test_TheseAreEveryOther(int Num)
{
if (Num & 1)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_TRUE(Num > 100);
VERIFY_FAILS_END
}
else
{
TEST_ASSERT_TRUE(Num < 100);
}
}
void test_NormalPassesStillWork(void)
{
TEST_ASSERT_TRUE(1);
}
void test_NormalFailsStillWork(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_TRUE(0);
VERIFY_FAILS_END
}
TEST_CASE(0, "abc")
TEST_CASE(1, "{")
TEST_CASE(2, "}")
TEST_CASE(3, ";")
TEST_CASE(4, "\"quoted\"")
void test_StringsArePreserved(unsigned index, const char * str)
{
static const char * const expected[] =
{
"abc",
"{",
"}",
";",
"\"quoted\""
};
/* Ensure that no test cases are skipped by tracking the next expected index */
TEST_ASSERT_EQUAL_UINT32(NextExpectedStringIndex, index);
TEST_ASSERT_LESS_THAN(sizeof(expected) / sizeof(expected[0]), index);
TEST_ASSERT_EQUAL_STRING(expected[index], str);
NextExpectedStringIndex++;
}
TEST_CASE(0, 'x')
TEST_CASE(1, '{')
TEST_CASE(2, '}')
TEST_CASE(3, ';')
TEST_CASE(4, '\'')
TEST_CASE(5, '"')
void test_CharsArePreserved(unsigned index, char c)
{
static const char expected[] =
{
'x',
'{',
'}',
';',
'\'',
'"'
};
/* Ensure that no test cases are skipped by tracking the next expected index */
TEST_ASSERT_EQUAL_UINT32(NextExpectedCharIndex, index);
TEST_ASSERT_LESS_THAN(sizeof(expected) / sizeof(expected[0]), index);
TEST_ASSERT_EQUAL(expected[index], c);
NextExpectedCharIndex++;
}
TEST_RANGE([0, 10, 2])
void test_SingleRange(unsigned value)
{
TEST_ASSERT_EQUAL(0, value % 2);
TEST_ASSERT_LESS_OR_EQUAL(10, value);
}
TEST_RANGE([1, 2, 1], [2, 1, -1])
void test_TwoRanges(unsigned first, unsigned second)
{
TEST_ASSERT_LESS_OR_EQUAL(4, first * second);
}
TEST_RANGE(<0, 10, 2>)
void test_SingleExclusiveRange(unsigned value)
{
TEST_ASSERT_EQUAL(0, value % 2);
TEST_ASSERT_LESS_THAN(10, value);
}
TEST_RANGE([2, 4, 1], <1, 2, 1>)
void test_BothInclusiveAndExclusiveRange(unsigned first, unsigned second)
{
TEST_ASSERT_LESS_THAN(first, second);
}
TEST_CASE(0,
1)
TEST_CASE(1,
2
)
TEST_RANGE([2,
5 ,
1], [6, 6, 1])
TEST_CASE(
6 , 7)
TEST_MATRIX([7,
8 ,
9, 10],
[
11]
)
void test_SpaceInTestCase(unsigned index, unsigned bigger)
{
TEST_ASSERT_EQUAL_UINT32(NextExpectedSpaceIndex, index);
TEST_ASSERT_LESS_THAN(bigger, index);
NextExpectedSpaceIndex++;
}
TEST_MATRIX([1, 5, (2*2)+1, 4])
void test_SingleMatix(unsigned value)
{
TEST_ASSERT_LESS_OR_EQUAL(10, value);
}
TEST_MATRIX([2, 5l, 4u+3, 4ul], [-2, 3])
void test_TwoMatrices(unsigned first, signed second)
{
static unsigned idx = 0;
static const unsigned expected[] =
{
// -2 3
-4, 6, // 2
-10, 15, // 5
-14, 21, // 7
-8, 12, // 4
};
TEST_ASSERT_EQUAL_INT(expected[idx++], first * second);
}
TEST_MATRIX(["String1", "String,2", "Stri" "ng3", "String[4]", "String\"5\""], [-5, 12.5f])
void test_StringsAndNumbersMatrices(const char* str, float number)
{
static unsigned idx = 0;
static const char* expected[] =
{
"String1_-05.00",
"String1_+12.50",
"String,2_-05.00",
"String,2_+12.50",
"String3_-05.00",
"String3_+12.50",
"String[4]_-05.00",
"String[4]_+12.50",
"String\"5\"_-05.00",
"String\"5\"_+12.50",
};
char buf[200] = {0};
snprintf(buf, sizeof(buf), "%s_%+06.2f", str, number);
TEST_ASSERT_EQUAL_STRING(expected[idx++], buf);
}
TEST_MATRIX(
[ENUM_A, ENUM_4, ENUM_C],
[test_arr[0], 7.8f, test_arr[2]],
['a', 'f', '[', ']', '\'', '"'],
)
void test_EnumCharAndArrayMatrices(test_enum_t e, float n, char c)
{
static unsigned enum_idx = 0;
static const test_enum_t exp_enum[3] = {
ENUM_A, ENUM_4, ENUM_C,
};
static unsigned float_idx = 0;
float exp_float[3] = {0};
exp_float[0] = test_arr[0];
exp_float[1] = 7.8f;
exp_float[2] = test_arr[2];
static unsigned char_idx = 0;
static const test_enum_t exp_char[] = {
'a', 'f', '[', ']', '\'', '"'
};
TEST_ASSERT_EQUAL_INT(exp_enum[enum_idx], e);
TEST_ASSERT_EQUAL_FLOAT(exp_float[float_idx], n);
TEST_ASSERT_EQUAL_CHAR(exp_char[char_idx], c);
char_idx = (char_idx + 1) % 6;
if (char_idx == 0.0f)
{
float_idx = (float_idx + 1) % 3;
if (float_idx == 0.0f)
{
enum_idx = (enum_idx + 1) % 3;
}
}
}

View File

@@ -0,0 +1,28 @@
/* =========================================================================
Unity - A Test Framework for C
ThrowTheSwitch.org
Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
/* Support for Meta Test Rig */
#ifndef TEST_CASE
#define TEST_CASE(...)
#endif
#ifndef TEST_RANGE
#define TEST_RANGE(...)
#endif
#ifndef TEST_MATRIX
#define TEST_MATRIX(...)
#endif
TEST_CASE(1, 2, 5)
TEST_CASE(10, 7, 20)
TEST_RANGE([3, 4, 1], [10, 5, -2], <30, 31, 1>)
TEST_MATRIX([3, 4, 7], [10, 8, 2, 1],[30u, 20.0f])
void test_demoParamFunction(int a, int b, int c)
{
TEST_ASSERT_GREATER_THAN_INT(a + b, c);
}

View File

@@ -0,0 +1,330 @@
/* =========================================================================
Unity - A Test Framework for C
ThrowTheSwitch.org
Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#define TEST_INSTANCES
#include "self_assessment_utils.h"
static int SetToOneToFailInTearDown;
static int SetToOneMeanWeAlreadyCheckedThisGuy;
void setUp(void)
{
SetToOneToFailInTearDown = 0;
SetToOneMeanWeAlreadyCheckedThisGuy = 0;
}
void tearDown(void)
{
endPutcharSpy(); /* Stop suppressing test output */
if (SetToOneToFailInTearDown == 1)
{
/* These will be skipped internally if already failed/ignored */
TEST_FAIL_MESSAGE("<= Failed in tearDown");
TEST_IGNORE_MESSAGE("<= Ignored in tearDown");
}
if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0))
{
UnityPrint(": [[[[ Test Should Have Passed But Did Not ]]]]");
UNITY_OUTPUT_CHAR('\n');
}
}
void testEqualStrings(void)
{
const char *testString = "foo";
TEST_ASSERT_EQUAL_STRING(testString, testString);
TEST_ASSERT_EQUAL_STRING_MESSAGE("foo", "foo", "foo isn't foo");
TEST_ASSERT_EQUAL_STRING("foo", testString);
TEST_ASSERT_EQUAL_STRING(testString, "foo");
TEST_ASSERT_EQUAL_STRING("", "");
}
void testEqualStringsLen(void)
{
const char *testString = "foobar";
TEST_ASSERT_EQUAL_STRING_LEN(testString, testString, strlen(testString));
TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE("foobar", "foobaz", 5, "fooba isn't fooba");
TEST_ASSERT_EQUAL_STRING_LEN("foo", testString, 3);
TEST_ASSERT_EQUAL_STRING_LEN(testString, "foo", 3);
TEST_ASSERT_EQUAL_STRING_LEN("", "", 3);
}
void testEqualStringsWithCarriageReturnsAndLineFeeds(void)
{
const char *testString = "foo\r\nbar";
TEST_ASSERT_EQUAL_STRING(testString, testString);
TEST_ASSERT_EQUAL_STRING("foo\r\nbar", "foo\r\nbar");
TEST_ASSERT_EQUAL_STRING("foo\r\nbar", testString);
TEST_ASSERT_EQUAL_STRING(testString, "foo\r\nbar");
TEST_ASSERT_EQUAL_STRING("", "");
}
void testNotEqualString1(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("foo", "bar");
VERIFY_FAILS_END
}
void testNotEqualStringLen1(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN("foobar", "foobaz", 6);
VERIFY_FAILS_END
}
void testNotEqualString2(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("foo", "");
VERIFY_FAILS_END
}
void testNotEqualStringLen2(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN("foo", "", 3);
VERIFY_FAILS_END
}
void testNotEqualString3(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("", "bar");
VERIFY_FAILS_END
}
void testNotEqualStringLen3(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN("", "bar", 3);
VERIFY_FAILS_END
}
void testNotEqualString4(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("bar\r", "bar\n");
VERIFY_FAILS_END
}
void testNotEqualStringLen4(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN("ba\r\x16", "ba\r\n", 4);
VERIFY_FAILS_END
}
void testNotEqualString5(void)
{
const char str1[] = { 0x41, 0x42, 0x03, 0x00 };
const char str2[] = { 0x41, 0x42, 0x04, 0x00 };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING(str1, str2);
VERIFY_FAILS_END
}
void testNotEqualString_ExpectedStringIsNull(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING(NULL, "bar");
VERIFY_FAILS_END
}
void testNotEqualStringLen_ExpectedStringIsNull(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN(NULL, "bar", 1);
VERIFY_FAILS_END
}
void testNotEqualString_ActualStringIsNull(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("foo", NULL);
VERIFY_FAILS_END
}
void testNotEqualStringLen_ActualStringIsNull(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN("foo", NULL, 1);
VERIFY_FAILS_END
}
void testNotEqualString_ExpectedStringIsLonger(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("foo2", "foo");
VERIFY_FAILS_END
}
void testNotEqualString_ActualStringIsLonger(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("foo", "foo2");
VERIFY_FAILS_END
}
void testEqualStringArrays(void)
{
const char *testStrings[] = { "foo", "boo", "woo", "moo" };
const char *expStrings[] = { "foo", "boo", "woo", "zoo" };
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, expStrings, 3);
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 3);
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 2);
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 1);
}
void testNotEqualStringArray1(void)
{
const char *testStrings[] = { "foo", "boo", "woo", "moo" };
const char *expStrings[] = { "foo", "boo", "woo", "zoo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringArray2(void)
{
const char *testStrings[] = { "zoo", "boo", "woo", "moo" };
const char *expStrings[] = { "foo", "boo", "woo", "moo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringArray3(void)
{
const char *testStrings[] = { "foo", "boo", "woo", NULL };
const char *expStrings[] = { "foo", "boo", "woo", "zoo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringArray4(void)
{
const char *testStrings[] = { "foo", "boo", "woo", "moo" };
const char *expStrings[] = { "foo", NULL, "woo", "moo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringArray5(void)
{
const char **testStrings = NULL;
const char *expStrings[] = { "foo", "boo", "woo", "zoo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringArray6(void)
{
const char *testStrings[] = { "foo", "boo", "woo", "zoo" };
const char **expStrings = NULL;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 4);
VERIFY_FAILS_END
}
void testEqualStringArrayIfBothNulls(void)
{
const char **testStrings = NULL;
const char **expStrings = NULL;
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 4);
}
void testNotEqualStringArrayLengthZero(void)
{
const char *testStrings[] = {NULL};
const char **expStrings = NULL;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_ARRAY(expStrings, testStrings, 0);
VERIFY_FAILS_END
}
void testEqualStringEachEqual(void)
{
const char *testStrings1[] = { "foo", "foo", "foo", "foo" };
const char *testStrings2[] = { "boo", "boo", "boo", "zoo" };
const char *testStrings3[] = { "", "", "", "" };
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings1, 4);
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings1, 1);
TEST_ASSERT_EACH_EQUAL_STRING("boo", testStrings2, 3);
TEST_ASSERT_EACH_EQUAL_STRING("", testStrings3, 4);
}
void testNotEqualStringEachEqual1(void)
{
const char *testStrings[] = { "foo", "foo", "foo", "moo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringEachEqual2(void)
{
const char *testStrings[] = { "boo", "foo", "foo", "foo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringEachEqual3(void)
{
const char *testStrings[] = { "foo", "foo", "foo", NULL };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringEachEqual4(void)
{
const char *testStrings[] = { "foo", "foo", "woo", "foo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringEachEqual5(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_STRING("foo", NULL, 1);
VERIFY_FAILS_END
}
void testCstringsEscapeSequence(void)
{
#ifndef USING_OUTPUT_SPY
TEST_IGNORE();
#else
startPutcharSpy();
UnityPrint("\x16\x10");
endPutcharSpy();
TEST_ASSERT_EQUAL_STRING("\\x16\\x10", getBufferPutcharSpy());
#endif
}

View File

@@ -0,0 +1,21 @@
/* =========================================================================
Unity - A Test Framework for C
ThrowTheSwitch.org
Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#pragma once
typedef enum {
ENUM_A,
ENUM_2,
ENUM_C,
ENUM_4,
} test_enum_t;
static const float test_arr[] = {
1.2f,
2.3f,
3.4f,
};