aboutsummaryrefslogtreecommitdiff
path: root/external/Unity/extras/fixture/test
diff options
context:
space:
mode:
authorbenj <benj@rse8.com>2017-06-16 01:20:02 -0700
committerbenj <benj@rse8.com>2017-06-16 01:20:02 -0700
commit14adc6a1d769e22958496d570b7f25b68cc86969 (patch)
tree6754de138c6d59bbfce8d5a3b732891d5a5e220b /external/Unity/extras/fixture/test
parentdee453b6473354786871a9b0b123d676ef1eb5cc (diff)
downloadworkbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar.gz
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar.bz2
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar.lz
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar.xz
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar.zst
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.zip
add unity testing fmwk and simple hash fn demonstrationHEADmaster
Diffstat (limited to 'external/Unity/extras/fixture/test')
-rw-r--r--external/Unity/extras/fixture/test/Makefile74
-rw-r--r--external/Unity/extras/fixture/test/main/AllTests.c22
-rw-r--r--external/Unity/extras/fixture/test/template_fixture_tests.c39
-rw-r--r--external/Unity/extras/fixture/test/unity_fixture_Test.c543
-rw-r--r--external/Unity/extras/fixture/test/unity_fixture_TestRunner.c57
-rw-r--r--external/Unity/extras/fixture/test/unity_output_Spy.c57
-rw-r--r--external/Unity/extras/fixture/test/unity_output_Spy.h17
7 files changed, 809 insertions, 0 deletions
diff --git a/external/Unity/extras/fixture/test/Makefile b/external/Unity/extras/fixture/test/Makefile
new file mode 100644
index 0000000..80e124f
--- /dev/null
+++ b/external/Unity/extras/fixture/test/Makefile
@@ -0,0 +1,74 @@
+CC = gcc
+ifeq ($(shell uname -s), Darwin)
+CC = clang
+endif
+#DEBUG = -O0 -g
+CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror
+CFLAGS += $(DEBUG)
+DEFINES = -D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar
+SRC = ../src/unity_fixture.c \
+ ../../../src/unity.c \
+ unity_fixture_Test.c \
+ unity_fixture_TestRunner.c \
+ unity_output_Spy.c \
+ main/AllTests.c
+
+INC_DIR = -I../src -I../../../src/
+BUILD_DIR = ../build
+TARGET = ../build/fixture_tests.exe
+
+all: default noStdlibMalloc 32bits
+
+default: $(BUILD_DIR)
+ $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_SUPPORT_64
+ @ echo "default build"
+ ./$(TARGET)
+
+32bits: $(BUILD_DIR)
+ $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -m32
+ @ echo "32bits build"
+ ./$(TARGET)
+
+noStdlibMalloc: $(BUILD_DIR)
+ $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC
+ @ echo "build with noStdlibMalloc"
+ ./$(TARGET)
+
+C89: CFLAGS += -D UNITY_EXCLUDE_STDINT_H # C89 did not have type 'long long', <stdint.h>
+C89: $(BUILD_DIR)
+ $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -std=c89 && ./$(TARGET)
+ $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC -std=c89
+ ./$(TARGET)
+
+$(BUILD_DIR):
+ mkdir -p $(BUILD_DIR)
+
+clean:
+ rm -f $(TARGET) $(BUILD_DIR)/*.gc*
+
+cov: $(BUILD_DIR)
+ cd $(BUILD_DIR) && \
+ $(CC) $(DEFINES) $(foreach i, $(SRC), ../test/$(i)) $(INC_DIR) -o $(TARGET) -fprofile-arcs -ftest-coverage
+ rm -f $(BUILD_DIR)/*.gcda
+ ./$(TARGET) > /dev/null ; ./$(TARGET) -v > /dev/null
+ cd $(BUILD_DIR) && \
+ gcov unity_fixture.c | head -3
+ grep '###' $(BUILD_DIR)/unity_fixture.c.gcov -C2 || true # Show uncovered lines
+
+# These extended flags DO get included before any target build runs
+CFLAGS += -Wbad-function-cast
+CFLAGS += -Wcast-qual
+CFLAGS += -Wconversion
+CFLAGS += -Wformat=2
+CFLAGS += -Wmissing-prototypes
+CFLAGS += -Wold-style-definition
+CFLAGS += -Wpointer-arith
+CFLAGS += -Wshadow
+CFLAGS += -Wstrict-overflow=5
+CFLAGS += -Wstrict-prototypes
+CFLAGS += -Wswitch-default
+CFLAGS += -Wundef
+CFLAGS += -Wno-error=undef # Warning only, this should not stop the build
+CFLAGS += -Wunreachable-code
+CFLAGS += -Wunused
+CFLAGS += -fstrict-aliasing
diff --git a/external/Unity/extras/fixture/test/main/AllTests.c b/external/Unity/extras/fixture/test/main/AllTests.c
new file mode 100644
index 0000000..e30dd85
--- /dev/null
+++ b/external/Unity/extras/fixture/test/main/AllTests.c
@@ -0,0 +1,22 @@
+/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
+ * ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#include "unity_fixture.h"
+
+static void runAllTests(void)
+{
+ RUN_TEST_GROUP(UnityFixture);
+ RUN_TEST_GROUP(UnityCommandOptions);
+ RUN_TEST_GROUP(LeakDetection);
+ RUN_TEST_GROUP(InternalMalloc);
+}
+
+int main(int argc, const char* argv[])
+{
+ return UnityMain(argc, argv, runAllTests);
+}
+
diff --git a/external/Unity/extras/fixture/test/template_fixture_tests.c b/external/Unity/extras/fixture/test/template_fixture_tests.c
new file mode 100644
index 0000000..18bbb89
--- /dev/null
+++ b/external/Unity/extras/fixture/test/template_fixture_tests.c
@@ -0,0 +1,39 @@
+/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
+ * ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#include "unity_fixture.h"
+
+static int data = -1;
+
+TEST_GROUP(mygroup);
+
+TEST_SETUP(mygroup)
+{
+ data = 0;
+}
+
+TEST_TEAR_DOWN(mygroup)
+{
+ data = -1;
+}
+
+TEST(mygroup, test1)
+{
+ TEST_ASSERT_EQUAL_INT(0, data);
+}
+
+TEST(mygroup, test2)
+{
+ TEST_ASSERT_EQUAL_INT(0, data);
+ data = 5;
+}
+
+TEST(mygroup, test3)
+{
+ data = 7;
+ TEST_ASSERT_EQUAL_INT(7, data);
+}
diff --git a/external/Unity/extras/fixture/test/unity_fixture_Test.c b/external/Unity/extras/fixture/test/unity_fixture_Test.c
new file mode 100644
index 0000000..a842b08
--- /dev/null
+++ b/external/Unity/extras/fixture/test/unity_fixture_Test.c
@@ -0,0 +1,543 @@
+/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
+ * ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#include "unity_fixture.h"
+#include "unity_output_Spy.h"
+#include <stdlib.h>
+#include <string.h>
+
+TEST_GROUP(UnityFixture);
+
+TEST_SETUP(UnityFixture)
+{
+}
+
+TEST_TEAR_DOWN(UnityFixture)
+{
+}
+
+static int* pointer1 = 0;
+static int* pointer2 = (int*)2;
+static int* pointer3 = (int*)3;
+static int int1;
+static int int2;
+static int int3;
+static int int4;
+
+TEST(UnityFixture, PointerSetting)
+{
+ TEST_ASSERT_POINTERS_EQUAL(pointer1, 0);
+ UT_PTR_SET(pointer1, &int1);
+ UT_PTR_SET(pointer2, &int2);
+ UT_PTR_SET(pointer3, &int3);
+ TEST_ASSERT_POINTERS_EQUAL(pointer1, &int1);
+ TEST_ASSERT_POINTERS_EQUAL(pointer2, &int2);
+ TEST_ASSERT_POINTERS_EQUAL(pointer3, &int3);
+ UT_PTR_SET(pointer1, &int4);
+ UnityPointer_UndoAllSets();
+ TEST_ASSERT_POINTERS_EQUAL(pointer1, 0);
+ TEST_ASSERT_POINTERS_EQUAL(pointer2, (int*)2);
+ TEST_ASSERT_POINTERS_EQUAL(pointer3, (int*)3);
+}
+
+TEST(UnityFixture, ForceMallocFail)
+{
+ void* m;
+ void* mfails;
+ UnityMalloc_MakeMallocFailAfterCount(1);
+ m = malloc(10);
+ CHECK(m);
+ mfails = malloc(10);
+ TEST_ASSERT_POINTERS_EQUAL(0, mfails);
+ free(m);
+}
+
+TEST(UnityFixture, ReallocSmallerIsUnchanged)
+{
+ void* m1 = malloc(10);
+ void* m2 = realloc(m1, 5);
+ TEST_ASSERT_POINTERS_EQUAL(m1, m2);
+ free(m2);
+}
+
+TEST(UnityFixture, ReallocSameIsUnchanged)
+{
+ void* m1 = malloc(10);
+ void* m2 = realloc(m1, 10);
+ TEST_ASSERT_POINTERS_EQUAL(m1, m2);
+ free(m2);
+}
+
+TEST(UnityFixture, ReallocLargerNeeded)
+{
+ void* m1 = malloc(10);
+ void* m2;
+ CHECK(m1);
+ strcpy((char*)m1, "123456789");
+ m2 = realloc(m1, 15);
+ /* CHECK(m1 != m2); //Depends on implementation */
+ STRCMP_EQUAL("123456789", m2);
+ free(m2);
+}
+
+TEST(UnityFixture, ReallocNullPointerIsLikeMalloc)
+{
+ void* m = realloc(0, 15);
+ CHECK(m != 0);
+ free(m);
+}
+
+TEST(UnityFixture, ReallocSizeZeroFreesMemAndReturnsNullPointer)
+{
+ void* m1 = malloc(10);
+ void* m2 = realloc(m1, 0);
+ TEST_ASSERT_POINTERS_EQUAL(0, m2);
+}
+
+TEST(UnityFixture, CallocFillsWithZero)
+{
+ void* m = calloc(3, sizeof(char));
+ char* s = (char*)m;
+ CHECK(m);
+ TEST_ASSERT_BYTES_EQUAL(0, s[0]);
+ TEST_ASSERT_BYTES_EQUAL(0, s[1]);
+ TEST_ASSERT_BYTES_EQUAL(0, s[2]);
+ free(m);
+}
+
+static char *p1;
+static char *p2;
+
+TEST(UnityFixture, PointerSet)
+{
+ char c1;
+ char c2;
+ char newC1;
+ char newC2;
+ p1 = &c1;
+ p2 = &c2;
+
+ UnityPointer_Init();
+ UT_PTR_SET(p1, &newC1);
+ UT_PTR_SET(p2, &newC2);
+ TEST_ASSERT_POINTERS_EQUAL(&newC1, p1);
+ TEST_ASSERT_POINTERS_EQUAL(&newC2, p2);
+ UnityPointer_UndoAllSets();
+ TEST_ASSERT_POINTERS_EQUAL(&c1, p1);
+ TEST_ASSERT_POINTERS_EQUAL(&c2, p2);
+}
+
+TEST(UnityFixture, FreeNULLSafety)
+{
+ free(NULL);
+}
+
+TEST(UnityFixture, ConcludeTestIncrementsFailCount)
+{
+ UNITY_UINT savedFails = Unity.TestFailures;
+ UNITY_UINT savedIgnores = Unity.TestIgnores;
+ UnityOutputCharSpy_Enable(1);
+ Unity.CurrentTestFailed = 1;
+ UnityConcludeFixtureTest(); /* Resets TestFailed for this test to pass */
+ Unity.CurrentTestIgnored = 1;
+ UnityConcludeFixtureTest(); /* Resets TestIgnored */
+ UnityOutputCharSpy_Enable(0);
+ TEST_ASSERT_EQUAL(savedFails + 1, Unity.TestFailures);
+ TEST_ASSERT_EQUAL(savedIgnores + 1, Unity.TestIgnores);
+ Unity.TestFailures = savedFails;
+ Unity.TestIgnores = savedIgnores;
+}
+
+/*------------------------------------------------------------ */
+
+TEST_GROUP(UnityCommandOptions);
+
+static int savedVerbose;
+static unsigned int savedRepeat;
+static const char* savedName;
+static const char* savedGroup;
+
+TEST_SETUP(UnityCommandOptions)
+{
+ savedVerbose = UnityFixture.Verbose;
+ savedRepeat = UnityFixture.RepeatCount;
+ savedName = UnityFixture.NameFilter;
+ savedGroup = UnityFixture.GroupFilter;
+}
+
+TEST_TEAR_DOWN(UnityCommandOptions)
+{
+ UnityFixture.Verbose = savedVerbose;
+ UnityFixture.RepeatCount= savedRepeat;
+ UnityFixture.NameFilter = savedName;
+ UnityFixture.GroupFilter = savedGroup;
+}
+
+
+static const char* noOptions[] = {
+ "testrunner.exe"
+};
+
+TEST(UnityCommandOptions, DefaultOptions)
+{
+ UnityGetCommandLineOptions(1, noOptions);
+ TEST_ASSERT_EQUAL(0, UnityFixture.Verbose);
+ TEST_ASSERT_POINTERS_EQUAL(0, UnityFixture.GroupFilter);
+ TEST_ASSERT_POINTERS_EQUAL(0, UnityFixture.NameFilter);
+ TEST_ASSERT_EQUAL(1, UnityFixture.RepeatCount);
+}
+
+static const char* verbose[] = {
+ "testrunner.exe",
+ "-v"
+};
+
+TEST(UnityCommandOptions, OptionVerbose)
+{
+ TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(2, verbose));
+ TEST_ASSERT_EQUAL(1, UnityFixture.Verbose);
+}
+
+static const char* group[] = {
+ "testrunner.exe",
+ "-g", "groupname"
+};
+
+TEST(UnityCommandOptions, OptionSelectTestByGroup)
+{
+ TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, group));
+ STRCMP_EQUAL("groupname", UnityFixture.GroupFilter);
+}
+
+static const char* name[] = {
+ "testrunner.exe",
+ "-n", "testname"
+};
+
+TEST(UnityCommandOptions, OptionSelectTestByName)
+{
+ TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, name));
+ STRCMP_EQUAL("testname", UnityFixture.NameFilter);
+}
+
+static const char* repeat[] = {
+ "testrunner.exe",
+ "-r", "99"
+};
+
+TEST(UnityCommandOptions, OptionSelectRepeatTestsDefaultCount)
+{
+ TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(2, repeat));
+ TEST_ASSERT_EQUAL(2, UnityFixture.RepeatCount);
+}
+
+TEST(UnityCommandOptions, OptionSelectRepeatTestsSpecificCount)
+{
+ TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, repeat));
+ TEST_ASSERT_EQUAL(99, UnityFixture.RepeatCount);
+}
+
+static const char* multiple[] = {
+ "testrunner.exe",
+ "-v",
+ "-g", "groupname",
+ "-n", "testname",
+ "-r", "98"
+};
+
+TEST(UnityCommandOptions, MultipleOptions)
+{
+ TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(8, multiple));
+ TEST_ASSERT_EQUAL(1, UnityFixture.Verbose);
+ STRCMP_EQUAL("groupname", UnityFixture.GroupFilter);
+ STRCMP_EQUAL("testname", UnityFixture.NameFilter);
+ TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount);
+}
+
+static const char* dashRNotLast[] = {
+ "testrunner.exe",
+ "-v",
+ "-g", "gggg",
+ "-r",
+ "-n", "tttt",
+};
+
+TEST(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified)
+{
+ TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(7, dashRNotLast));
+ TEST_ASSERT_EQUAL(1, UnityFixture.Verbose);
+ STRCMP_EQUAL("gggg", UnityFixture.GroupFilter);
+ STRCMP_EQUAL("tttt", UnityFixture.NameFilter);
+ TEST_ASSERT_EQUAL(2, UnityFixture.RepeatCount);
+}
+
+static const char* unknownCommand[] = {
+ "testrunner.exe",
+ "-v",
+ "-g", "groupname",
+ "-n", "testname",
+ "-r", "98",
+ "-z"
+};
+TEST(UnityCommandOptions, UnknownCommandIsIgnored)
+{
+ TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(9, unknownCommand));
+ TEST_ASSERT_EQUAL(1, UnityFixture.Verbose);
+ STRCMP_EQUAL("groupname", UnityFixture.GroupFilter);
+ STRCMP_EQUAL("testname", UnityFixture.NameFilter);
+ TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount);
+}
+
+TEST(UnityCommandOptions, GroupOrNameFilterWithoutStringFails)
+{
+ TEST_ASSERT_EQUAL(1, UnityGetCommandLineOptions(3, unknownCommand));
+ TEST_ASSERT_EQUAL(1, UnityGetCommandLineOptions(5, unknownCommand));
+ TEST_ASSERT_EQUAL(1, UnityMain(3, unknownCommand, NULL));
+}
+
+TEST(UnityCommandOptions, GroupFilterReallyFilters)
+{
+ UNITY_UINT saved = Unity.NumberOfTests;
+ TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(4, unknownCommand));
+ UnityIgnoreTest(NULL, "non-matching", NULL);
+ TEST_ASSERT_EQUAL(saved, Unity.NumberOfTests);
+}
+
+IGNORE_TEST(UnityCommandOptions, TestShouldBeIgnored)
+{
+ TEST_FAIL_MESSAGE("This test should not run!");
+}
+
+/*------------------------------------------------------------ */
+
+TEST_GROUP(LeakDetection);
+
+TEST_SETUP(LeakDetection)
+{
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ UnityOutputCharSpy_Create(200);
+#else
+ UnityOutputCharSpy_Create(1000);
+#endif
+}
+
+TEST_TEAR_DOWN(LeakDetection)
+{
+ UnityOutputCharSpy_Destroy();
+}
+
+#define EXPECT_ABORT_BEGIN \
+ { \
+ jmp_buf TestAbortFrame; \
+ memcpy(TestAbortFrame, Unity.AbortFrame, sizeof(jmp_buf)); \
+ if (TEST_PROTECT()) \
+ {
+
+#define EXPECT_ABORT_END \
+ } \
+ memcpy(Unity.AbortFrame, TestAbortFrame, sizeof(jmp_buf)); \
+ }
+
+/* This tricky set of defines lets us see if we are using the Spy, returns 1 if true */
+#ifdef __STDC_VERSION__
+
+#if __STDC_VERSION__ >= 199901L
+#define USING_SPY_AS(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0)
+#define ASSIGN_VALUE(a) VAL_##a
+#define VAL_UnityOutputCharSpy_OutputChar 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 /* UNITY_OUTPUT_CHAR = UnityOutputCharSpy_OutputChar */
+#endif
+#endif /* >= 199901 */
+
+#else /* __STDC_VERSION__ else */
+#define UnityOutputCharSpy_OutputChar 42
+#if UNITY_OUTPUT_CHAR == UnityOutputCharSpy_OutputChar /* Works if no -Wundef -Werror */
+ #define USING_OUTPUT_SPY
+#endif
+#undef UnityOutputCharSpy_OutputChar
+#endif /* __STDC_VERSION__ */
+
+TEST(LeakDetection, DetectsLeak)
+{
+#ifndef USING_OUTPUT_SPY
+ TEST_IGNORE_MESSAGE("Build with '-D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar' to enable tests");
+#else
+ void* m = malloc(10);
+ TEST_ASSERT_NOT_NULL(m);
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ UnityMalloc_EndTest();
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ CHECK(strstr(UnityOutputCharSpy_Get(), "This test leaks!"));
+ free(m);
+#endif
+}
+
+TEST(LeakDetection, BufferOverrunFoundDuringFree)
+{
+#ifndef USING_OUTPUT_SPY
+ TEST_IGNORE();
+#else
+ void* m = malloc(10);
+ char* s = (char*)m;
+ TEST_ASSERT_NOT_NULL(m);
+ s[10] = (char)0xFF;
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ free(m);
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()"));
+#endif
+}
+
+TEST(LeakDetection, BufferOverrunFoundDuringRealloc)
+{
+#ifndef USING_OUTPUT_SPY
+ TEST_IGNORE();
+#else
+ void* m = malloc(10);
+ char* s = (char*)m;
+ TEST_ASSERT_NOT_NULL(m);
+ s[10] = (char)0xFF;
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ m = realloc(m, 100);
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()"));
+#endif
+}
+
+TEST(LeakDetection, BufferGuardWriteFoundDuringFree)
+{
+#ifndef USING_OUTPUT_SPY
+ TEST_IGNORE();
+#else
+ void* m = malloc(10);
+ char* s = (char*)m;
+ TEST_ASSERT_NOT_NULL(m);
+ s[-1] = (char)0x00; /* Will not detect 0 */
+ s[-2] = (char)0x01;
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ free(m);
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()"));
+#endif
+}
+
+TEST(LeakDetection, BufferGuardWriteFoundDuringRealloc)
+{
+#ifndef USING_OUTPUT_SPY
+ TEST_IGNORE();
+#else
+ void* m = malloc(10);
+ char* s = (char*)m;
+ TEST_ASSERT_NOT_NULL(m);
+ s[-1] = (char)0x0A;
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ m = realloc(m, 100);
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()"));
+#endif
+}
+
+TEST(LeakDetection, PointerSettingMax)
+{
+#ifndef USING_OUTPUT_SPY
+ TEST_IGNORE();
+#else
+ int i;
+ for (i = 0; i < UNITY_MAX_POINTERS; i++) UT_PTR_SET(pointer1, &int1);
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ UT_PTR_SET(pointer1, &int1);
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ CHECK(strstr(UnityOutputCharSpy_Get(), "Too many pointers set"));
+#endif
+}
+
+/*------------------------------------------------------------ */
+
+TEST_GROUP(InternalMalloc);
+#define TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(first_mem_ptr, ptr) \
+ ptr = malloc(10); free(ptr); \
+ TEST_ASSERT_EQUAL_PTR_MESSAGE(first_mem_ptr, ptr, "Memory was stranded, free in LIFO order");
+
+
+TEST_SETUP(InternalMalloc) { }
+TEST_TEAR_DOWN(InternalMalloc) { }
+
+TEST(InternalMalloc, MallocPastBufferFails)
+{
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1);
+ void* n = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2);
+ free(m);
+ TEST_ASSERT_NOT_NULL(m);
+ TEST_ASSERT_NULL(n);
+ TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n);
+#endif
+}
+
+TEST(InternalMalloc, CallocPastBufferFails)
+{
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ void* m = calloc(1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1);
+ void* n = calloc(1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2);
+ free(m);
+ TEST_ASSERT_NOT_NULL(m);
+ TEST_ASSERT_NULL(n);
+ TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n);
+#endif
+}
+
+TEST(InternalMalloc, MallocThenReallocGrowsMemoryInPlace)
+{
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1);
+ void* n = realloc(m, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 9);
+ free(n);
+ TEST_ASSERT_NOT_NULL(m);
+ TEST_ASSERT_EQUAL(m, n);
+ TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n);
+#endif
+}
+
+TEST(InternalMalloc, ReallocFailDoesNotFreeMem)
+{
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2);
+ void* n1 = malloc(10);
+ void* out_of_mem = realloc(n1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1);
+ void* n2 = malloc(10);
+
+ free(n2);
+ if (out_of_mem == NULL) free(n1);
+ free(m);
+
+ TEST_ASSERT_NOT_NULL(m); /* Got a real memory location */
+ TEST_ASSERT_NULL(out_of_mem); /* The realloc should have failed */
+ TEST_ASSERT_NOT_EQUAL(n2, n1); /* If n1 != n2 then realloc did not free n1 */
+ TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n2);
+#endif
+}
diff --git a/external/Unity/extras/fixture/test/unity_fixture_TestRunner.c b/external/Unity/extras/fixture/test/unity_fixture_TestRunner.c
new file mode 100644
index 0000000..e8713e1
--- /dev/null
+++ b/external/Unity/extras/fixture/test/unity_fixture_TestRunner.c
@@ -0,0 +1,57 @@
+/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
+ * ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#include "unity_fixture.h"
+
+TEST_GROUP_RUNNER(UnityFixture)
+{
+ RUN_TEST_CASE(UnityFixture, PointerSetting);
+ RUN_TEST_CASE(UnityFixture, ForceMallocFail);
+ RUN_TEST_CASE(UnityFixture, ReallocSmallerIsUnchanged);
+ RUN_TEST_CASE(UnityFixture, ReallocSameIsUnchanged);
+ RUN_TEST_CASE(UnityFixture, ReallocLargerNeeded);
+ RUN_TEST_CASE(UnityFixture, ReallocNullPointerIsLikeMalloc);
+ RUN_TEST_CASE(UnityFixture, ReallocSizeZeroFreesMemAndReturnsNullPointer);
+ RUN_TEST_CASE(UnityFixture, CallocFillsWithZero);
+ RUN_TEST_CASE(UnityFixture, PointerSet);
+ RUN_TEST_CASE(UnityFixture, FreeNULLSafety);
+ RUN_TEST_CASE(UnityFixture, ConcludeTestIncrementsFailCount);
+}
+
+TEST_GROUP_RUNNER(UnityCommandOptions)
+{
+ RUN_TEST_CASE(UnityCommandOptions, DefaultOptions);
+ RUN_TEST_CASE(UnityCommandOptions, OptionVerbose);
+ RUN_TEST_CASE(UnityCommandOptions, OptionSelectTestByGroup);
+ RUN_TEST_CASE(UnityCommandOptions, OptionSelectTestByName);
+ RUN_TEST_CASE(UnityCommandOptions, OptionSelectRepeatTestsDefaultCount);
+ RUN_TEST_CASE(UnityCommandOptions, OptionSelectRepeatTestsSpecificCount);
+ RUN_TEST_CASE(UnityCommandOptions, MultipleOptions);
+ RUN_TEST_CASE(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified);
+ RUN_TEST_CASE(UnityCommandOptions, UnknownCommandIsIgnored);
+ RUN_TEST_CASE(UnityCommandOptions, GroupOrNameFilterWithoutStringFails);
+ RUN_TEST_CASE(UnityCommandOptions, GroupFilterReallyFilters);
+ RUN_TEST_CASE(UnityCommandOptions, TestShouldBeIgnored);
+}
+
+TEST_GROUP_RUNNER(LeakDetection)
+{
+ RUN_TEST_CASE(LeakDetection, DetectsLeak);
+ RUN_TEST_CASE(LeakDetection, BufferOverrunFoundDuringFree);
+ RUN_TEST_CASE(LeakDetection, BufferOverrunFoundDuringRealloc);
+ RUN_TEST_CASE(LeakDetection, BufferGuardWriteFoundDuringFree);
+ RUN_TEST_CASE(LeakDetection, BufferGuardWriteFoundDuringRealloc);
+ RUN_TEST_CASE(LeakDetection, PointerSettingMax);
+}
+
+TEST_GROUP_RUNNER(InternalMalloc)
+{
+ RUN_TEST_CASE(InternalMalloc, MallocPastBufferFails);
+ RUN_TEST_CASE(InternalMalloc, CallocPastBufferFails);
+ RUN_TEST_CASE(InternalMalloc, MallocThenReallocGrowsMemoryInPlace);
+ RUN_TEST_CASE(InternalMalloc, ReallocFailDoesNotFreeMem);
+}
diff --git a/external/Unity/extras/fixture/test/unity_output_Spy.c b/external/Unity/extras/fixture/test/unity_output_Spy.c
new file mode 100644
index 0000000..be87bd5
--- /dev/null
+++ b/external/Unity/extras/fixture/test/unity_output_Spy.c
@@ -0,0 +1,57 @@
+/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
+ * ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+
+#include "unity_output_Spy.h"
+#include "unity_fixture.h"
+
+#include <stdio.h>
+#include <string.h>
+
+static int size;
+static int count;
+static char* buffer;
+static int spy_enable;
+
+void UnityOutputCharSpy_Create(int s)
+{
+ size = (s > 0) ? s : 0;
+ count = 0;
+ spy_enable = 0;
+ buffer = malloc((size_t)size);
+ TEST_ASSERT_NOT_NULL_MESSAGE(buffer, "Internal malloc failed in Spy Create():" __FILE__);
+ memset(buffer, 0, (size_t)size);
+}
+
+void UnityOutputCharSpy_Destroy(void)
+{
+ size = 0;
+ free(buffer);
+}
+
+void UnityOutputCharSpy_OutputChar(int c)
+{
+ if (spy_enable)
+ {
+ if (count < (size-1))
+ buffer[count++] = (char)c;
+ }
+ else
+ {
+ putchar(c);
+ }
+}
+
+const char * UnityOutputCharSpy_Get(void)
+{
+ return buffer;
+}
+
+void UnityOutputCharSpy_Enable(int enable)
+{
+ spy_enable = enable;
+}
diff --git a/external/Unity/extras/fixture/test/unity_output_Spy.h b/external/Unity/extras/fixture/test/unity_output_Spy.h
new file mode 100644
index 0000000..b30a7f1
--- /dev/null
+++ b/external/Unity/extras/fixture/test/unity_output_Spy.h
@@ -0,0 +1,17 @@
+/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
+ * ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#ifndef D_unity_output_Spy_H
+#define D_unity_output_Spy_H
+
+void UnityOutputCharSpy_Create(int s);
+void UnityOutputCharSpy_Destroy(void);
+void UnityOutputCharSpy_OutputChar(int c);
+const char * UnityOutputCharSpy_Get(void);
+void UnityOutputCharSpy_Enable(int enable);
+
+#endif