This commit is contained in:
Rens Pastoor
2025-05-27 22:41:46 +02:00
parent d141296aea
commit 11b391b8a1
416 changed files with 25232 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
animal_shelter
admin_test

View File

@@ -0,0 +1,2 @@
[InternetShortcut]
URL=https://git.fhict.nl/technology/t-oer-prc2/-/blob/master/arrays/challenges/animal-shelter/2-Assignment%20-%20AnimalShelter.docx

View File

@@ -0,0 +1,44 @@
PROD_DIR := ./product
SHARED_DIR := ./shared
TEST_DIR := ./test
UNITY_FOLDER :=./Unity
BUILD_DIR :=./build
PROD_EXEC = main
PROD_DIRS := $(PROD_DIR) $(SHARED_DIR)
PROD_FILES := $(wildcard $(patsubst %,%/*.c, $(PROD_DIRS)))
HEADER_PROD_FILES := $(wildcard $(patsubst %,%/*.h, $(PROD_DIRS)))
PROD_INC_DIRS=-I$(PROD_DIR) -I$(SHARED_DIR)
TEST_EXEC = main_test
TEST_DIRS := $(TEST_DIR) $(SHARED_DIR) $(UNITY_FOLDER)
TEST_FILES := $(wildcard $(patsubst %,%/*.c, $(TEST_DIRS)))
HEADER_TEST_FILES := $(wildcard $(patsubst %,%/*.h, $(TEST_DIRS)))
TEST_INC_DIRS=-I$(TEST_DIR) -I$(SHARED_DIR) -I$(UNITY_FOLDER)
CC=gcc
SYMBOLS=-Wall -Werror -g -pedantic -O0 -std=c99
TEST_SYMBOLS=$(SYMBOLS) -DTEST -DUNITY_USE_MODULE_SETUP_TEARDOWN
.PHONY: clean test
all: $(PROD_EXEC)
$(PROD_EXEC): Makefile $(PROD_FILES) $(HEADER_FILES)
$(CC) $(PROD_INC_DIRS) $(SYMBOLS) $(PROD_FILES) -o $(BUILD_DIR)/$(PROD_EXEC)
$(TEST_EXEC): Makefile $(TEST_FILES) $(HEADER_FILES)
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(BUILD_DIR)/$(TEST_EXEC)
run: $(PROD_EXEC)
@./$(BUILD_DIR)/$(PROD_EXEC)
test: $(TEST_EXEC)
@./$(BUILD_DIR)/$(TEST_EXEC) administration
testfile : $(TEST_EXEC)
@./$(BUILD_DIR)/$(TEST_EXEC) file_element
clean:
rm -f $(BUILD_DIR)/$(PROD_EXEC)
rm -f $(BUILD_DIR)/$(TEST_EXEC)

View File

@@ -0,0 +1,841 @@
/* ==========================================
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.h"
#include <stdio.h>
#include <string.h>
#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
/// return prematurely if we are already in failure or ignore state
#define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); }
struct _Unity Unity = { 0 };
const char* UnityStrNull = "NULL";
const char* UnityStrSpacer = ". ";
const char* UnityStrExpected = " Expected ";
const char* UnityStrWas = " Was ";
const char* UnityStrTo = " To ";
const char* UnityStrElement = " Element ";
const char* UnityStrMemory = " Memory Mismatch";
const char* UnityStrDelta = " Values Not Within Delta ";
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
//-----------------------------------------------
// Pretty Printers & Test Result Output Handlers
//-----------------------------------------------
void UnityPrint(const char* string)
{
const char* pch = string;
if (pch != NULL)
{
while (*pch)
{
// printable characters plus CR & LF are printed
if ((*pch <= 126) && (*pch >= 32))
{
UNITY_OUTPUT_CHAR(*pch);
}
//write escaped carriage returns
else if (*pch == 13)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('r');
}
//write escaped line feeds
else if (*pch == 10)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('n');
}
// unprintable characters are shown as codes
else
{
UNITY_OUTPUT_CHAR('\\');
UnityPrintNumberHex((_U_SINT)*pch, 2);
}
pch++;
}
}
}
//-----------------------------------------------
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
{
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
UnityPrintNumber(number);
}
else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
{
UnityPrintNumberUnsigned((_U_UINT)number);
}
else
{
UnityPrintNumberHex((_U_UINT)number, (style & 0x000F) << 1);
}
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumber(const _U_SINT number_to_print)
{
_U_SINT divisor = 1;
_U_SINT next_divisor;
_U_SINT number = number_to_print;
if (number < 0)
{
UNITY_OUTPUT_CHAR('-');
number = -number;
}
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumberUnsigned(const _U_UINT number)
{
_U_UINT divisor = 1;
_U_UINT next_divisor;
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
}
//-----------------------------------------------
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
{
_U_UINT nibble;
char nibbles = nibbles_to_print;
UNITY_OUTPUT_CHAR('0');
UNITY_OUTPUT_CHAR('x');
while (nibbles > 0)
{
nibble = (number >> (--nibbles << 2)) & 0x0000000F;
if (nibble <= 9)
{
UNITY_OUTPUT_CHAR((char)('0' + nibble));
}
else
{
UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
}
}
}
//-----------------------------------------------
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
{
_U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
_US32 i;
for (i = 0; i < UNITY_INT_WIDTH; i++)
{
if (current_bit & mask)
{
if (current_bit & number)
{
UNITY_OUTPUT_CHAR('1');
}
else
{
UNITY_OUTPUT_CHAR('0');
}
}
else
{
UNITY_OUTPUT_CHAR('X');
}
current_bit = current_bit >> 1;
}
}
//-----------------------------------------------
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(_UF number)
{
char TempBuffer[32];
sprintf(TempBuffer, "%.6f", number);
UnityPrint(TempBuffer);
}
#endif
//-----------------------------------------------
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
{
UnityPrint(file);
UNITY_OUTPUT_CHAR(':');
UnityPrintNumber(line);
UNITY_OUTPUT_CHAR(':');
UnityPrint(Unity.CurrentTestName);
UNITY_OUTPUT_CHAR(':');
}
//-----------------------------------------------
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
{
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("FAIL:");
}
//-----------------------------------------------
void UnityConcludeTest(void)
{
if (Unity.CurrentTestIgnored)
{
Unity.TestIgnores++;
}
else if (!Unity.CurrentTestFailed)
{
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
UnityPrint("PASS");
UNITY_PRINT_EOL;
}
else
{
Unity.TestFailures++;
}
Unity.CurrentTestFailed = 0;
Unity.CurrentTestIgnored = 0;
}
//-----------------------------------------------
void UnityAddMsgIfSpecified(const char* msg)
{
if (msg)
{
UnityPrint(UnityStrSpacer);
UnityPrint(msg);
}
}
//-----------------------------------------------
void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
{
UnityPrint(UnityStrExpected);
if (expected != NULL)
{
UNITY_OUTPUT_CHAR('\'');
UnityPrint(expected);
UNITY_OUTPUT_CHAR('\'');
}
else
{
UnityPrint(UnityStrNull);
}
UnityPrint(UnityStrWas);
if (actual != NULL)
{
UNITY_OUTPUT_CHAR('\'');
UnityPrint(actual);
UNITY_OUTPUT_CHAR('\'');
}
else
{
UnityPrint(UnityStrNull);
}
}
//-----------------------------------------------
// Assertion & Control Helpers
//-----------------------------------------------
int UnityCheckArraysForNull(const void* expected, const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
{
//return true if they are both NULL
if ((expected == NULL) && (actual == NULL))
return 1;
//throw error if just expected is NULL
if (expected == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForExpected);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
//throw error if just actual is NULL
if (actual == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForActual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
//return false if neither is NULL
return 0;
}
//-----------------------------------------------
// Assertion Functions
//-----------------------------------------------
void UnityAssertBits(const _U_SINT mask,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if ((mask & expected) != (mask & actual))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintMask(mask, expected);
UnityPrint(UnityStrWas);
UnityPrintMask(mask, actual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualNumber(const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
UNITY_SKIP_EXECUTION;
if (expected != actual)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualIntArray(const _U_SINT* expected,
const _U_SINT* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
_UU32 elements = num_elements;
const _US8* ptr_exp = (_US8*)expected;
const _US8* ptr_act = (_US8*)actual;
UNITY_SKIP_EXECUTION;
if (elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
switch(style)
{
case UNITY_DISPLAY_STYLE_HEX8:
case UNITY_DISPLAY_STYLE_INT8:
case UNITY_DISPLAY_STYLE_UINT8:
while (elements--)
{
if (*ptr_exp != *ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 1;
ptr_act += 1;
}
break;
case UNITY_DISPLAY_STYLE_HEX16:
case UNITY_DISPLAY_STYLE_INT16:
case UNITY_DISPLAY_STYLE_UINT16:
while (elements--)
{
if (*(_US16*)ptr_exp != *(_US16*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US16*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US16*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 2;
ptr_act += 2;
}
break;
#ifdef UNITY_SUPPORT_64
case UNITY_DISPLAY_STYLE_HEX64:
case UNITY_DISPLAY_STYLE_INT64:
case UNITY_DISPLAY_STYLE_UINT64:
while (elements--)
{
if (*(_US64*)ptr_exp != *(_US64*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US64*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US64*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 8;
ptr_act += 8;
}
break;
#endif
default:
while (elements--)
{
if (*(_US32*)ptr_exp != *(_US32*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US32*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US32*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 4;
ptr_act += 4;
}
break;
}
}
//-----------------------------------------------
#ifndef UNITY_EXCLUDE_FLOAT
void UnityAssertEqualFloatArray(const _UF* expected,
const _UF* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 elements = num_elements;
const _UF* ptr_expected = expected;
const _UF* ptr_actual = actual;
_UF diff, tol;
UNITY_SKIP_EXECUTION;
if (elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
while (elements--)
{
diff = *ptr_expected - *ptr_actual;
if (diff < 0.0)
diff = 0.0 - diff;
tol = UNITY_FLOAT_PRECISION * *ptr_expected;
if (tol < 0.0)
tol = 0.0 - tol;
if (diff > tol)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrintFloat(*ptr_expected);
UnityPrint(UnityStrWas);
UnityPrintFloat(*ptr_actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_expected++;
ptr_actual++;
}
}
//-----------------------------------------------
void UnityAssertFloatsWithin(const _UF delta,
const _UF expected,
const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UF diff = actual - expected;
_UF pos_delta = delta;
UNITY_SKIP_EXECUTION;
if (diff < 0)
{
diff = 0.0f - diff;
}
if (pos_delta < 0)
{
pos_delta = 0.0f - pos_delta;
}
if (pos_delta < diff)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrintFloat(expected);
UnityPrint(UnityStrWas);
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
#endif
//-----------------------------------------------
void UnityAssertNumbersWithin( const _U_SINT delta,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
UNITY_SKIP_EXECUTION;
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
if (actual > expected)
Unity.CurrentTestFailed = ((actual - expected) > delta);
else
Unity.CurrentTestFailed = ((expected - actual) > delta);
}
else
{
if ((_U_UINT)actual > (_U_UINT)expected)
Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
else
Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrDelta);
UnityPrintNumberByStyle(delta, style);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 i;
UNITY_SKIP_EXECUTION;
// if both pointers not null compare the strings
if (expected && actual)
{
for (i = 0; expected[i] || actual[i]; i++)
{
if (expected[i] != actual[i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected != actual)
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrintExpectedAndActualStrings(expected, actual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualStringArray( const char** expected,
const char** actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 i, j = 0;
UNITY_SKIP_EXECUTION;
// if no elements, it's an error
if (num_elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
do
{
// if both pointers not null compare the strings
if (expected[j] && actual[j])
{
for (i = 0; expected[j][i] || actual[j][i]; i++)
{
if (expected[j][i] != actual[j][i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected[j] != actual[j])
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT);
}
UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
} while (++j < num_elements);
}
//-----------------------------------------------
void UnityAssertEqualMemory( const void* expected,
const void* actual,
_UU32 length,
_UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
unsigned char* expected_ptr = (unsigned char*)expected;
unsigned char* actual_ptr = (unsigned char*)actual;
_UU32 elements = num_elements;
UNITY_SKIP_EXECUTION;
if ((elements == 0) || (length == 0))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
while (elements--)
{
if (memcmp((const void*)expected_ptr, (const void*)actual_ptr, length) != 0)
{
Unity.CurrentTestFailed = 1;
break;
}
expected_ptr += length;
actual_ptr += length;
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
}
UnityPrint(UnityStrMemory);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
// Control Functions
//-----------------------------------------------
void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
{
UNITY_SKIP_EXECUTION;
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("FAIL");
if (msg != NULL)
{
UNITY_OUTPUT_CHAR(':');
if (msg[0] != ' ')
{
UNITY_OUTPUT_CHAR(' ');
}
UnityPrint(msg);
}
UNITY_FAIL_AND_BAIL;
}
//-----------------------------------------------
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
{
UNITY_SKIP_EXECUTION;
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("IGNORE");
if (msg != NULL)
{
UNITY_OUTPUT_CHAR(':');
UNITY_OUTPUT_CHAR(' ');
UnityPrint(msg);
}
UNITY_IGNORE_AND_BAIL;
}
//-----------------------------------------------
void setUp(void);
void tearDown(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
Unity.CurrentTestName = FuncName;
Unity.CurrentTestLineNumber = FuncLineNum;
Unity.NumberOfTests++;
if (TEST_PROTECT())
{
setUp();
Func();
}
if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
{
tearDown();
}
UnityConcludeTest();
}
//-----------------------------------------------
void UnityBegin(void)
{
Unity.NumberOfTests = 0;
}
//-----------------------------------------------
int UnityEnd(void)
{
UnityPrint("-----------------------");
UNITY_PRINT_EOL;
UnityPrintNumber(Unity.NumberOfTests);
UnityPrint(" Tests ");
UnityPrintNumber(Unity.TestFailures);
UnityPrint(" Failures ");
UnityPrintNumber(Unity.TestIgnores);
UnityPrint(" Ignored");
UNITY_PRINT_EOL;
if (Unity.TestFailures == 0U)
{
UnityPrint("OK");
}
else
{
UnityPrint("FAIL");
}
UNITY_PRINT_EOL;
return Unity.TestFailures;
}

View File

@@ -0,0 +1,209 @@
/* ==========================================
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 UNITY_FRAMEWORK_H
#define UNITY_FRAMEWORK_H
#define UNITY
#include "unity_internals.h"
//-------------------------------------------------------
// Configuration Options
//-------------------------------------------------------
// Integers
// - Unity assumes 32 bit integers by default
// - If your compiler treats ints of a different size, define UNITY_INT_WIDTH
// Floats
// - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
// - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
// - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
// - define UNITY_FLOAT_VERBOSE to print floating point values in errors (uses sprintf)
// Output
// - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
// Optimization
// - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge
// - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests.
//-------------------------------------------------------
// Test Running Macros
//-------------------------------------------------------
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
#ifndef RUN_TEST
#define RUN_TEST(func, line_num) UnityDefaultTestRun(func, #func, line_num)
#endif
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
#define TEST_CASE(...)
//-------------------------------------------------------
// Basic Fail and Ignore
//-------------------------------------------------------
#define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, message)
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, message)
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
#define TEST_ONLY()
//-------------------------------------------------------
// Test Asserts (simple)
//-------------------------------------------------------
//Boolean
#define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE")
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE")
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE")
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL")
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL")
//Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal")
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, NULL)
//Integer Ranges (of all sizes)
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, NULL)
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, NULL)
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, NULL)
//Floating Point (If Enabled)
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
//-------------------------------------------------------
// Test Asserts (with additional messages)
//-------------------------------------------------------
//Boolean
#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, message)
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, message)
//Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, message)
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, message)
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, message)
//Integer Ranges (of all sizes)
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, message)
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, message)
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_STRING_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, message)
//Floating Point (If Enabled)
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message)
#endif

View File

@@ -0,0 +1,356 @@
/* ==========================================
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 UNITY_INTERNALS_H
#define UNITY_INTERNALS_H
#include <stdio.h>
#include <setjmp.h>
//-------------------------------------------------------
// Int Support
//-------------------------------------------------------
#ifndef UNITY_INT_WIDTH
#define UNITY_INT_WIDTH (32)
#endif
#ifndef UNITY_LONG_WIDTH
#define UNITY_LONG_WIDTH (32)
#endif
#if (UNITY_INT_WIDTH == 32)
typedef unsigned char _UU8;
typedef unsigned short _UU16;
typedef unsigned int _UU32;
typedef signed char _US8;
typedef signed short _US16;
typedef signed int _US32;
#elif (UNITY_INT_WIDTH == 16)
typedef unsigned char _UU8;
typedef unsigned int _UU16;
typedef unsigned long _UU32;
typedef signed char _US8;
typedef signed int _US16;
typedef signed long _US32;
#else
#error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported)
#endif
//-------------------------------------------------------
// 64-bit Support
//-------------------------------------------------------
#ifndef UNITY_SUPPORT_64
//No 64-bit Support
typedef _UU32 _U_UINT;
typedef _US32 _U_SINT;
#else
//64-bit Support
#if (UNITY_LONG_WIDTH == 32)
typedef unsigned long long _UU64;
typedef signed long long _US64;
#elif (UNITY_LONG_WIDTH == 64)
typedef unsigned long _UU64;
typedef signed long _US64;
#else
#error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported)
#endif
typedef _UU64 _U_UINT;
typedef _US64 _U_SINT;
#endif
//-------------------------------------------------------
// Pointer Support
//-------------------------------------------------------
#ifndef UNITY_POINTER_WIDTH
#define UNITY_POINTER_WIDTH (32)
#endif
#if (UNITY_POINTER_WIDTH == 32)
typedef _UU32 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32
#elif (UNITY_POINTER_WIDTH == 64)
typedef _UU64 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64
#elif (UNITY_POINTER_WIDTH == 16)
typedef _UU16 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16
#else
#error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported)
#endif
//-------------------------------------------------------
// Float Support
//-------------------------------------------------------
#ifdef UNITY_EXCLUDE_FLOAT
//No Floating Point Support
#undef UNITY_FLOAT_PRECISION
#undef UNITY_FLOAT_TYPE
#undef UNITY_FLOAT_VERBOSE
#else
//Floating Point Support
#ifndef UNITY_FLOAT_PRECISION
#define UNITY_FLOAT_PRECISION (0.00001f)
#endif
#ifndef UNITY_FLOAT_TYPE
#define UNITY_FLOAT_TYPE float
#endif
typedef UNITY_FLOAT_TYPE _UF;
#endif
//-------------------------------------------------------
// Output Method
//-------------------------------------------------------
#ifndef UNITY_OUTPUT_CHAR
//Default to using putchar, which is defined in stdio.h above
#define UNITY_OUTPUT_CHAR(a) putchar(a)
#else
//If defined as something else, make sure we declare it here so it's ready for use
extern int UNITY_OUTPUT_CHAR(int);
#endif
//-------------------------------------------------------
// Footprint
//-------------------------------------------------------
#ifndef UNITY_LINE_TYPE
#define UNITY_LINE_TYPE unsigned short
#endif
#ifndef UNITY_COUNTER_TYPE
#define UNITY_COUNTER_TYPE unsigned short
#endif
//-------------------------------------------------------
// Internal Structs Needed
//-------------------------------------------------------
typedef void (*UnityTestFunction)(void);
#define UNITY_DISPLAY_RANGE_INT (0x10)
#define UNITY_DISPLAY_RANGE_UINT (0x20)
#define UNITY_DISPLAY_RANGE_HEX (0x40)
#define UNITY_DISPLAY_RANGE_AUTO (0x80)
typedef enum
{
UNITY_DISPLAY_STYLE_INT = 4 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO,
UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT,
UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT,
UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT,
#endif
UNITY_DISPLAY_STYLE_UINT = 4 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO,
UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT,
UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT,
UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT,
#endif
UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX,
UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX,
UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX,
#endif
} UNITY_DISPLAY_STYLE_T;
struct _Unity
{
const char* TestFile;
const char* CurrentTestName;
_UU32 CurrentTestLineNumber;
UNITY_COUNTER_TYPE NumberOfTests;
UNITY_COUNTER_TYPE TestFailures;
UNITY_COUNTER_TYPE TestIgnores;
UNITY_COUNTER_TYPE CurrentTestFailed;
UNITY_COUNTER_TYPE CurrentTestIgnored;
jmp_buf AbortFrame;
};
extern struct _Unity Unity;
//-------------------------------------------------------
// Test Suite Management
//-------------------------------------------------------
void UnityBegin(void);
int UnityEnd(void);
void UnityConcludeTest(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
//-------------------------------------------------------
// Test Output
//-------------------------------------------------------
void UnityPrint(const char* string);
void UnityPrintMask(const _U_UINT mask, const _U_UINT number);
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style);
void UnityPrintNumber(const _U_SINT number);
void UnityPrintNumberUnsigned(const _U_UINT number);
void UnityPrintNumberHex(const _U_UINT number, const char nibbles);
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(const _UF number);
#endif
//-------------------------------------------------------
// Test Assertion Fuctions
//-------------------------------------------------------
// Use the macros below this section instead of calling
// these directly. The macros have a consistent naming
// convention and will pull in file and line information
// for you.
void UnityAssertEqualNumber(const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertEqualIntArray(const _U_SINT* expected,
const _U_SINT* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertBits(const _U_SINT mask,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualStringArray( const char** expected,
const char** actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualMemory( const void* expected,
const void* actual,
const _UU32 length,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertNumbersWithin(const _U_SINT delta,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
#ifndef UNITY_EXCLUDE_FLOAT
void UnityAssertFloatsWithin(const _UF delta,
const _UF expected,
const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualFloatArray(const _UF* expected,
const _UF* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
#endif
//-------------------------------------------------------
// Basic Fail and Ignore
//-------------------------------------------------------
#define UNITY_TEST_FAIL(line, message) UnityFail( (message), (UNITY_LINE_TYPE)line);
#define UNITY_TEST_IGNORE(line, message) UnityIgnore( (message), (UNITY_LINE_TYPE)line);
//-------------------------------------------------------
// Test Asserts
//-------------------------------------------------------
#define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, message);}
#define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((_U_SINT)(mask), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER)
#define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT8)
#define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT16)
#define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT32)
#define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT8)
#define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT16)
#define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT32)
#define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((const char**)(expected), (const char**)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#ifdef UNITY_SUPPORT_64
#define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
#define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
#define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#endif
#ifdef UNITY_EXCLUDE_FLOAT
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#else
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#endif
#endif

View File

@@ -0,0 +1,97 @@
#include "unity_test_module.h"
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "unity.h"
void (*unity_setUp_ptr)(void) = NULL;
void (*unit_tearDown_ptr)(void) = NULL;
#ifdef UNITY_USE_MODULE_SETUP_TEARDOWN
void setUp()
{
if(unity_setUp_ptr != NULL) unity_setUp_ptr();
}
void tearDown()
{
if(unit_tearDown_ptr != NULL) unit_tearDown_ptr();
}
#endif
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) )
{
unity_setUp_ptr = setUp;
unit_tearDown_ptr = tearDown;
}
void UnityUnregisterSetupTearDown(void)
{
unity_setUp_ptr = NULL;
unit_tearDown_ptr = NULL;
}
UnityTestModule* UnityTestModuleFind(
UnityTestModule* modules,
size_t number_of_modules,
char* wantedModule)
{
for(size_t i = 0; i < number_of_modules; i++) {
if(strcmp(wantedModule, modules[i].name) == 0) {
return &modules[i];
}
}
return NULL;
}
void UnityTestModuleRunRequestedModules(
int number_of_requested_modules,
char* requested_modules_names[],
UnityTestModule* allModules,
size_t number_of_modules )
{
for(int i = 0; i < number_of_requested_modules; i++)
{
UnityTestModule* module = UnityTestModuleFind(allModules,
number_of_modules, requested_modules_names[i]);
if(module != NULL)
{
module->run_tests();
}
else
{
printf("Ignoring: could not find requested module: %s\n",
requested_modules_names[i]);
}
}
}
int UnityTestModuleRun(
int argc,
char * argv[],
UnityTestModule* allModules,
size_t number_of_modules)
{
UnityBegin();
bool moduleRequests = (argc > 1);
if(moduleRequests)
{
UnityTestModuleRunRequestedModules(argc-1, &argv[1],
allModules, number_of_modules);
}
else
{
for(int i = 0; i < number_of_modules; i++)
{
allModules[i].run_tests();
}
}
return UnityEnd();
}

View File

@@ -0,0 +1,31 @@
#ifndef UNITY_TEST_MODULE_H
#define UNITY_TEST_MODULE_H
#include <stddef.h>
typedef struct {
char name[24];
void(*run_tests)(void);
} UnityTestModule;
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) );
void UnityUnregisterSetupTearDown(void);
UnityTestModule* UnityTestModuleFind(
UnityTestModule* modules,
size_t number_of_modules,
char* wantedModule);
void UnityTestModuleRunRequestedModules(
int number_of_requested_modules,
char* requested_modules_names[],
UnityTestModule* allModules,
size_t number_of_modules );
int UnityTestModuleRun(
int argc,
char * argv[],
UnityTestModule* allModules,
size_t number_of_modules);
#endif

Binary file not shown.

View File

@@ -0,0 +1,77 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "administration.h"
#include "animal.h"
#include "terminal_io.h"
static void addTestData(Animal* animals, size_t* nrAnimals)
{
Animal a1 = { 1, Dog, Male, 12, { 1, 2, 3 } };
Animal a2 = { 2, Cat, Female, 4, { 4, 3, 2 } };
Animal a3 = { 3, Parrot, Male, 40, { 8, 9, 10 } };
Animal a4 = { 4, Dog, Female, 1, { 1, 1, 100 } };
Animal a5 = { 5, GuineaPig, Male, 3, { 3, 4, 1 } };
animals[(*nrAnimals)++] = a1;
animals[(*nrAnimals)++] = a2;
animals[(*nrAnimals)++] = a3;
animals[(*nrAnimals)++] = a4;
animals[(*nrAnimals)++] = a5;
}
int main(int argc, char* argv[])
{
const size_t MaxNrAnimals = 20;
Animal animals[MaxNrAnimals];
size_t nrAnimals = 0;
MenuOptions choice = MO_SHOW_ANIMALS;
addTestData(animals, &nrAnimals);
printf("PRC assignment 'Animal Shelter'\n"
"-------------------------------------------");
if (argc != 1)
{
fprintf(stderr, "%s: argc=%d\n", argv[0], argc);
}
while (choice != MO_QUIT)
{
printf("\n\nMENU\n====\n\n");
choice = getMenuChoice();
switch (choice)
{
case MO_SHOW_ANIMALS:
printAnimals(animals, nrAnimals);
break;
case MO_ADD_ANIMAL:
break;
case MO_REMOVE_ANIMAL:
break;
case MO_SORT_ANIMALS_BY_AGE:
break;
case MO_SORT_ANIMALS_BY_YEAR_FOUND:
break;
case MO_SORT_ANIMALS_BY_SEX:
break;
case MO_FIND_ANIMAL:
break;
case MO_SAVE:
break;
case MO_LOAD:
break;
case MO_QUIT:
break;
default:
printf("ERROR: invalid choice: %d\n", choice);
break;
}
}
return 0;
}

View File

@@ -0,0 +1,98 @@
#include <stdio.h>
#include <string.h>
#include "terminal_io.h"
#define MAX_STRLEN 80
static const char* SpeciesNames[] = { "Cat", "Dog", "Guinea pig", "Parrot" };
static const char* SexNames[] = { "Male", "Female" };
static const char* MenuStrings[] = {
"Show animals",
"Add animal",
"Remove animal",
"Sort animals by age",
"Sort animals by year found",
"Sort animals by sex",
"Find animal",
"Load administration from disk",
"Save administration to disk",
"Quit"
};
static const size_t NrMenuStrings =
sizeof(MenuStrings) / sizeof(MenuStrings[0]);
int getInt(const char* message)
{
char line[MAX_STRLEN];
char* result = NULL;
int value = -1;
printf("%s", message);
result = fgets(line, sizeof(line), stdin);
if (result != NULL)
{
sscanf(result, "%d", &value);
}
return value;
}
int getLimitedInt(const char* message, const char* items[], int nrItems)
{
int choice = -1;
do
{
for (int i = 0; i < nrItems; i++)
{
printf(" [%d] %s\n", i, items[i]);
}
choice = getInt(message);
} while (choice < 0 || choice >= nrItems);
return choice;
}
MenuOptions getMenuChoice(void)
{
return (MenuOptions)getLimitedInt("choice: ", MenuStrings, NrMenuStrings);
}
Date getDate(const char* message)
{
Date temp = { 0, 0, 0 };
printf("%s", message);
temp.Day = getInt(" enter day: ");
temp.Month = getInt(" enter month: ");
temp.Year = getInt(" enter year: ");
return temp;
}
void printAnimals(const Animal* animals, int nrAnimals)
{
if (animals != NULL)
{
if (nrAnimals <= 0)
{
printf("\nAnimal array is empty, or nrAnimals is less than 0\n\n");
}
else
{
for (int i = 0; i < nrAnimals; i++)
{
printf("\nAnimal %d:\n", i + 1);
printf("Id: %d\n", animals[i].Id);
printf("Species: %s\n", SpeciesNames[animals[i].Species]);
printf("Sex: %s\n", SexNames[animals[i].Sex]);
printf("Age: %d\n", animals[i].Age);
printf("Animal was found:\n");
printf(" at date: %02d-%02d-%02d\n",
animals[i].DateFound.Day, animals[i].DateFound.Month,
animals[i].DateFound.Year);
}
}
}
}

View File

@@ -0,0 +1,25 @@
#ifndef TERMINAL_IO_H
#define TERMINAL_IO_H
#include "animal.h"
typedef enum
{
MO_SHOW_ANIMALS,
MO_ADD_ANIMAL,
MO_REMOVE_ANIMAL,
MO_SORT_ANIMALS_BY_AGE,
MO_SORT_ANIMALS_BY_YEAR_FOUND,
MO_SORT_ANIMALS_BY_SEX,
MO_FIND_ANIMAL,
MO_LOAD,
MO_SAVE,
MO_QUIT
} MenuOptions;
MenuOptions getMenuChoice(void);
void printAnimals(const Animal* animals, int nrAnimals);
//add the missing functions
#endif

View File

@@ -0,0 +1,59 @@
#include "administration.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "animal.h"
int addAnimal(const Animal* animalPtr, Animal* animalArray, size_t animalArrayLength, size_t numberOfAnimalsPresent, size_t* newNumberOfAnimalsPresent){
int fault = 0;
if (animalArray == NULL || animalPtr == NULL || numberOfAnimalsPresent >= animalArrayLength) {
fault = -1; // Invalid
} else {
animalArray[numberOfAnimalsPresent] = *animalPtr;
++numberOfAnimalsPresent;
}
*newNumberOfAnimalsPresent = numberOfAnimalsPresent;
return fault;
}
int removeAnimal(int animalId, Animal* animalArray, size_t numberOfAnimalsPresent, size_t* newNumberOfAnimalsPresent){
int fault = -1;
if (animalArray == NULL || numberOfAnimalsPresent == 0) {
fault = -1; // Invalid
} else {
for (size_t i = 0; i < numberOfAnimalsPresent; ++i) {
if (animalArray[i].Id == animalId) {
// move the array elements to the left to remove the animal
for (size_t j = i; j < numberOfAnimalsPresent - 1; ++j) {
animalArray[j] = animalArray[j + 1];
}
--numberOfAnimalsPresent;
fault = 0;
break;
}
}
}
*newNumberOfAnimalsPresent = numberOfAnimalsPresent;
return fault;
}
int findAnimalById(int animalId, const Animal* animalArray, size_t numberOfAnimalsPresent, Animal* foundAnimal) {
int fault = -1;
if (animalArray == NULL || numberOfAnimalsPresent == 0 || foundAnimal == NULL) {
fault = -1;
} else {
for (size_t i = 0; i < numberOfAnimalsPresent; i++) {
if (animalArray[i].Id == animalId) {
*foundAnimal = animalArray[i];
fault = 0;
break; // Exit loop after finding the animal
}
}
if (fault == -1) { // Only zero out if animal wasn't found
memset(foundAnimal, 0, sizeof(Animal));
}
}
return fault;
}

View File

@@ -0,0 +1,56 @@
#ifndef ADMINISTRATION_H
#define ADMINISTRATION_H
#include <stddef.h>
#include "animal.h"
/* pre : animalArrayLength must be greater than numberOfAnimalsPresent
* post : animalArray is updated with the information from animalPtr, the
* updated number of animals is passed in newNumberOfAnimalsPresent returns: 0
* on success or -1 if an error occurs
*/
int addAnimal(
const Animal* animalPtr, Animal* animalArray,
size_t animalArrayLength, size_t numberOfAnimalsPresent,
size_t* newNumberOfAnimalsPresent);
/* pre :
* post : All animals with id 'animalId' are removed from AnimalArray, the
* updated number of animals is passed in newNumberOfAnimalsPresent returns: The
* number of removed animals, 0 if no animals removed or -1 if an error occurs
*/
int removeAnimal(
int animalId, Animal* animalArray,
size_t numberOfAnimalsPresent,
size_t* newNumberOfAnimalsPresent);
/* pre :
* post : The first animal from animalArray with id 'animalId' is copied into
* animalPtr returns: 1 on success, 0 if not found or -1 if an error occurs
*/
int findAnimalById(
int animalId, const Animal* animalArray,
size_t numberOfAnimalsPresent, Animal* animalPtr);
/* pre :
* post : All animals in animalArray are sorted by age
* returns: 0 on success or -1 if an error occurs
*/
int sortAnimalsByAge(Animal* animalArray, size_t numberOfAnimalsPresent);
/* pre :
* post : All animals in animalArray are sorted by the year in which they were
* found returns: 0 on success or -1 if an error occurs
*/
int sortAnimalsByYearFound(
Animal* animalArray, size_t numberOfAnimalsPresent);
/* pre :
* post : All animals in animalArray are sorted: first female animals and then
* male animals returns: 0 on success or -1 if an error occurs
*/
int sortAnimalsBySex(Animal* animalArray, size_t numberOfAnimalsPresent);
#endif

View File

@@ -0,0 +1,37 @@
#ifndef ANIMAL_H
#define ANIMAL_H
typedef enum
{
Cat,
Dog,
GuineaPig,
Parrot
} Species;
typedef enum
{
Male,
Female
} Sex;
typedef struct
{
int Day;
int Month;
int Year;
} Date;
#define MaxNameLength 25
#define MaxLocationLength 100
typedef struct
{
int Id;
Species Species;
Sex Sex;
int Age;
Date DateFound;
} Animal;
#endif

View File

@@ -0,0 +1,35 @@
#include "file_element.h"
int readAnimals(const char* filename, Animal* animalPtr, size_t nrAnimals)
{
return -1;
}
int writeAnimals(const char* filename, const Animal* animalPtr, size_t nrAnimals)
{
return -1;
}
int getNrAnimalsInFile(const char* filename, size_t* nrAnimals)
{
return -1;
}
int readAnimalFromFile(
const char* filename, size_t filePosition, Animal* animalPtr)
{
return -1;
}
int writeAnimalToFile(
const char* filename, size_t filePosition, const Animal* animalPtr)
{
return -1;
}
int renameAnimalInFile(
const char* filename, size_t filePosition, const char* animalSurname)
{
return -1;
}

View File

@@ -0,0 +1,66 @@
#ifndef FILE_ELEMENT_H
#define FILE_ELEMENT_H
#include <stddef.h>
#include "animal.h"
int readAnimals(const char* filename, Animal* animalPtr, size_t nrAnimals);
/* pre : n.a.
* post : If file contains enough Animals, nrAnimals Animals are read into
* animalPtr. If less animals than nrAnimals exist, all animals from
* the file are read into animalPtr.
* returns: Nr of animals written into animalPtr or -1 if an error occurs
*/
int writeAnimals(const char* filename, const Animal* animalPtr, size_t nrAnimals);
/* pre : n.a.
* post : nrAnimals animals are written into a new file with data from
* animalPtr
* returns: On succes: 0, on error (file could not be written, input pointers
* are NULL): -1
*/
int getNrAnimalsInFile(const char* filename, size_t* nrAnimals);
/* pre : n.a.
* post : get number of animals (Animal structures) in the file
* returns: on succes: 0, on error: -1
*
*/
int readAnimalFromFile(
const char* filename, size_t filePosition, Animal* animalPtr);
/* pre : n.a.
* post : read the animal on filePosition (first animal is filePosition 0,
* second animal is filePosition 1, ...) into animalPtr
* returns: On success: 0, on error: -1 (no data available on filePosition,
* file could not be read, ...)
*/
int writeAnimalToFile(
const char* filename, size_t filePosition, const Animal* animalPtr);
/* pre :
* post : write the animal in animalPtr to the file at position 'filePosition'
* returns: On success: 0, on error: -1
*
**** note: do not open the file in append mode (a or a+): in append mode you
**** ALWAYS write to the end of the file. You cannot open the file in
**** write mode either (w or w+), as this will truncate an existing file
**** to 0 bytes. You MUST open the file in "r+" mode (means: r+w) and if
**** that fails (could mean: file does not exist) retry in "w" mode.
*/
int renameAnimalInFile(
const char* filename, size_t filePosition, const char* animalSurname);
/* pre :
* post : change the animal name on the filePosition in this way:
* The new animal name will start with animalSurname, followed
* by a space and followed by the original animal name
* Example : We have animal called "Max" on filePosition and animalSurname
* "Verstappen". The new animal name will be "Verstappen Max".
* The renamed animal will be written back to the file.
* returns : On success: 0, on error: -1
*/
#endif

View File

@@ -0,0 +1,86 @@
#include <string.h>
#include "administration.h"
#include "unity.h"
#include "unity_test_module.h"
// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
// Keep the original array constant to prevent modifications
const Animal originalArray[5] = {
{.Id = 1, .Species = Cat, .Age = 8, .Sex = Male, .DateFound = {1, 1, 2020}},
{.Id = 2, .Species = Dog, .Age = 2, .Sex = Female, .DateFound = {1, 1, 2021}},
{.Id = 3, .Species = GuineaPig, .Age = 92, .Sex = Female, .DateFound = {1, 1, 2022}}
};
// Arrays for testing
Animal animalArray[5];
Animal searchArray[5];
void administration_setUp(void) {
// Reset both arrays before each test
memcpy(animalArray, originalArray, sizeof(originalArray));
memcpy(searchArray, originalArray, sizeof(originalArray));
}
void administration_tearDown(void){}
void test_administration_remove_valid(void){
size_t newNumberOfAnimalsPresent = 0;
int errorCode = removeAnimal(2, animalArray, 3, &newNumberOfAnimalsPresent);
TEST_ASSERT_EQUAL(0, errorCode);
TEST_ASSERT_EQUAL(2, newNumberOfAnimalsPresent);
}
void test_administration_remove_invalid(void){
size_t newNumberOfAnimalsPresent = 0;
int errorCode = removeAnimal(12, animalArray, 3, &newNumberOfAnimalsPresent);
TEST_ASSERT_EQUAL(-1, errorCode);
TEST_ASSERT_EQUAL(3, newNumberOfAnimalsPresent);
}
void test_administration_add_valid(void){
Animal newAnimal = {.Id = 4, .Species = Dog, .Age = 3, .Sex = Male, .DateFound = {1, 1, 2023}};
size_t newNumberOfAnimalsPresent = 0;
int errorCode = addAnimal(&newAnimal, animalArray, 5, 3, &newNumberOfAnimalsPresent);
TEST_ASSERT_EQUAL(0, errorCode);
TEST_ASSERT_EQUAL(4, newNumberOfAnimalsPresent);
}
void test_administration_add_invalid(void){
Animal newAnimal = {.Id = 5, .Species = Cat, .Age = 2, .Sex = Female, .DateFound = {1, 1, 2024}};
size_t newNumberOfAnimalsPresent = 0;
int errorCode = addAnimal(&newAnimal, animalArray, 3, 3, &newNumberOfAnimalsPresent);
TEST_ASSERT_EQUAL(-1, errorCode);
TEST_ASSERT_EQUAL(3, newNumberOfAnimalsPresent);
}
void test_administration_find_valid(void){
Animal foundAnimalV;
int errorCode = findAnimalById(2, searchArray, 3, &foundAnimalV);
TEST_ASSERT_EQUAL(0, errorCode);
TEST_ASSERT_EQUAL(2, foundAnimalV.Id);
TEST_ASSERT_EQUAL(Dog, foundAnimalV.Species);
}
void test_administration_find_invalid(void){
Animal foundAnimalinV;
int errorCode = findAnimalById(12, searchArray, 3, &foundAnimalinV);
TEST_ASSERT_EQUAL(-1, errorCode);
TEST_ASSERT_EQUAL(0, foundAnimalinV.Id);
}
void run_administration_tests()
{
UnityRegisterSetupTearDown(administration_setUp, administration_tearDown);
MY_RUN_TEST(test_administration_remove_valid);
MY_RUN_TEST(test_administration_remove_invalid);
MY_RUN_TEST(test_administration_add_valid);
MY_RUN_TEST(test_administration_add_invalid);
MY_RUN_TEST(test_administration_find_valid);
MY_RUN_TEST(test_administration_find_invalid);
UnityUnregisterSetupTearDown();
}

View File

@@ -0,0 +1,34 @@
#include <string.h>
#include "file_element.h"
#include "unity.h"
#include "unity_test_module.h"
// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
void file_element_setUp(void)
{
// This is run before EACH test
}
void file_element_tearDown(void)
{
// This is run after EACH test
}
void test_EmptyTest_file(void)
{
TEST_ASSERT_EQUAL(1, 0);
}
void run_file_element_tests()
{
UnityRegisterSetupTearDown( file_element_setUp, file_element_tearDown);
MY_RUN_TEST(test_EmptyTest_file);
UnityUnregisterSetupTearDown();
}

View File

@@ -0,0 +1,19 @@
#include "unity_test_module.h"
/* As an alternative for header files we can declare that
* the following methos are available 'extern'ally.
*/
extern void run_administration_tests();
extern void run_file_element_tests();
int main (int argc, char * argv[])
{
UnityTestModule allModules[] = { { "administration", run_administration_tests} ,
{ "file_element", run_file_element_tests}
};
size_t number_of_modules = sizeof(allModules)/sizeof(allModules[0]);
return UnityTestModuleRun(argc, argv, allModules, number_of_modules);
}

View File

@@ -0,0 +1 @@
main

View File

@@ -0,0 +1,20 @@
NAME=main
FILES=main.c
CC=gcc
SYMBOLS=-g -O0 -std=c99 -Wall -Werror -Wextra -pedantic -Wno-unused-parameter
.PHONY: clean
all: product
product: Makefile $(FILES)
$(CC) $(INC_DIRS) $(SYMBOLS) $(FILES) -o $(NAME)
run: product
./$(NAME)
clean:
rm -f $(NAME)

View File

@@ -0,0 +1,256 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/*---------------------------------------------------------------*/
#define BIKE_COMPUTER_SIMULATOR_VALUE_MIN_SPEED (27)
#define BIKE_COMPUTER_SIMULATOR_VALUE_MAX_SPEED (30)
#define BIKE_COMPUTER_SIMULATOR_VALUE_MIN_POWER (150)
#define BIKE_COMPUTER_SIMULATOR_VALUE_MAX_POWER (200)
#define BIKE_COMPUTER_SIMULATOR_VALUE_MIN_HEART_RATE (130)
#define BIKE_COMPUTER_SIMULATOR_VALUE_MAX_HEART_RATE (140)
#define BIKE_COMPUTER_SIMULATOR_VALUE_MIN_CADENCE (88)
#define BIKE_COMPUTER_SIMULATOR_VALUE_MAX_CADENCE (98)
#define BIKE_STORE_MAX_NUMBER_MEASUREMENTS (32)
typedef enum {
BIKE_SPEED,
BIKE_HEART_RATE,
BIKE_CADENCE,
BIKE_POWER
} bike_data_type;
typedef struct
{
uint16_t speed;
uint16_t heart_rate;
uint16_t cadence;
uint16_t power;
} bike_store_measurement;
bike_store_measurement bike_store_array[BIKE_STORE_MAX_NUMBER_MEASUREMENTS] = {
{ 0, },
};
uint16_t bike_store_number_of_measurements_present = 0;
/*---------------------------------------------------------------*/
uint16_t
bike_computer_simulator_get_random_value(uint16_t min_range, uint16_t max_range)
{
uint16_t range = (max_range - min_range);
uint16_t random_value = min_range + (rand() % range);
return random_value;
}
uint16_t bike_measure_speed_in_kmh()
{
return bike_computer_simulator_get_random_value(
BIKE_COMPUTER_SIMULATOR_VALUE_MIN_SPEED,
BIKE_COMPUTER_SIMULATOR_VALUE_MAX_SPEED);
}
uint16_t bike_measure_power_in_watt()
{
return bike_computer_simulator_get_random_value(
BIKE_COMPUTER_SIMULATOR_VALUE_MIN_POWER,
BIKE_COMPUTER_SIMULATOR_VALUE_MAX_POWER);
}
uint16_t bike_measure_cadence_in_rpm()
{
return bike_computer_simulator_get_random_value(
BIKE_COMPUTER_SIMULATOR_VALUE_MIN_CADENCE,
BIKE_COMPUTER_SIMULATOR_VALUE_MAX_CADENCE);
}
uint16_t bike_measure_heart_rate_in_bpm()
{
return bike_computer_simulator_get_random_value(
BIKE_COMPUTER_SIMULATOR_VALUE_MIN_HEART_RATE,
BIKE_COMPUTER_SIMULATOR_VALUE_MAX_HEART_RATE);
}
/*---------------------------------------------------------------*/
uint16_t bike_store_get_maximum_bike_store_size()
{
return BIKE_STORE_MAX_NUMBER_MEASUREMENTS;
}
void bike_store_add_measurement(bike_store_measurement value)
{
if (bike_store_number_of_measurements_present >=
bike_store_get_maximum_bike_store_size())
{
bike_store_number_of_measurements_present = 0;
}
bike_store_array[bike_store_number_of_measurements_present] = value;
bike_store_number_of_measurements_present++;
}
uint16_t bike_store_get_number_of_measurements_present()
{
return bike_store_number_of_measurements_present;
}
bike_store_measurement bike_store_get_measurement(uint16_t index_position)
{
bike_store_measurement value = bike_store_array[index_position];
return value;
}
/*---------------------------------------------------------------*/
uint16_t bike_math_get_value_for_data_type(
bike_store_measurement measurement, bike_data_type data_type)
{
uint16_t value = 0;
if (data_type == BIKE_CADENCE)
{
value = measurement.cadence;
}
else if (data_type == BIKE_SPEED)
{
value = measurement.speed;
}
else if (data_type == BIKE_HEART_RATE)
{
value = measurement.heart_rate;
}
else if (data_type == BIKE_POWER)
{
value = measurement.power;
}
return value;
}
uint16_t bike_math_calculate_min_value(bike_data_type data_type)
{
uint16_t number_of_measurements =
bike_store_get_number_of_measurements_present();
uint16_t min_value = UINT16_MAX;
for (uint16_t index_position = 0; index_position < number_of_measurements;
index_position++)
{
bike_store_measurement measurement =
bike_store_get_measurement(index_position);
uint16_t value =
bike_math_get_value_for_data_type(measurement, data_type);
if (value < min_value)
{
min_value = value;
}
}
return min_value;
}
uint16_t bike_math_calculate_max_value(bike_data_type data_type)
{
uint16_t number_of_measurements =
bike_store_get_number_of_measurements_present();
uint16_t max_value = 0;
for (uint16_t index_position = 0; index_position < number_of_measurements;
index_position++)
{
bike_store_measurement measurement =
bike_store_get_measurement(index_position);
uint16_t value =
bike_math_get_value_for_data_type(measurement, data_type);
if (value > max_value)
{
max_value = value;
}
}
return max_value;
}
uint16_t bike_math_calculate_average_value(bike_data_type data_type)
{
uint16_t number_of_measurements =
bike_store_get_number_of_measurements_present();
if (number_of_measurements == 0)
return 0;
uint16_t average = 0;
uint32_t sum = 0;
for (uint16_t index_position = 0; index_position < number_of_measurements;
index_position++)
{
bike_store_measurement measurement =
bike_store_get_measurement(index_position);
uint16_t value =
bike_math_get_value_for_data_type(measurement, data_type);
sum += value;
}
average = sum / number_of_measurements;
return average;
}
/*---------------------------------------------------------------*/
int main(int argc, char* argv[])
{
bike_store_measurement measurement;
uint16_t min = 0, max = 0, average = 0;
bike_data_type data_type;
while (true)
{
measurement.speed = bike_measure_speed_in_kmh();
measurement.cadence = bike_measure_cadence_in_rpm();
measurement.heart_rate = bike_measure_heart_rate_in_bpm();
measurement.power = bike_measure_power_in_watt();
bike_store_add_measurement(measurement);
data_type = BIKE_SPEED;
min = bike_math_calculate_min_value(data_type);
max = bike_math_calculate_max_value(data_type);
average = bike_math_calculate_average_value(data_type);
printf("SPEED:\t\t%d, average = %d, min = %d, max = %d [km/h]\n",
measurement.speed, average, min, max);
data_type = BIKE_CADENCE;
min = bike_math_calculate_min_value(data_type);
max = bike_math_calculate_max_value(data_type);
average = bike_math_calculate_average_value(data_type);
printf("CADENCE:\t%d, average = %d, min = %d, max = %d [rpm]\n",
measurement.cadence, average, min, max);
data_type = BIKE_HEART_RATE;
min = bike_math_calculate_min_value(data_type);
max = bike_math_calculate_max_value(data_type);
average = bike_math_calculate_average_value(data_type);
printf("HEART-RATE:\t%d, average = %d, min = %d, max = %d [hrm]\n",
measurement.heart_rate, average, min, max);
data_type = BIKE_POWER;
min = bike_math_calculate_min_value(data_type);
max = bike_math_calculate_max_value(data_type);
average = bike_math_calculate_average_value(data_type);
printf("POWER:\t\t%d, average = %d, min = %d, max = %d [watt]\n",
measurement.power, average, min, max);
printf("\n");
sleep(1);
}
}

View File

@@ -0,0 +1,42 @@
PROD_DIR := ./product
SHARED_DIR := ./shared
TEST_DIR := ./test
UNITY_FOLDER :=./Unity
RES_DIR := ./ResourceDetector
BUILD_DIR :=./build
PROD_EXEC = main
PROD_DIRS := $(PROD_DIR) $(SHARED_DIR) $(RES_DIR)
PROD_FILES := $(wildcard $(patsubst %,%/*.c, $(PROD_DIRS)))
HEADER_PROD_FILES := $(wildcard $(patsubst %,%/*.h, $(PROD_DIRS)))
PROD_INC_DIRS=-I$(PROD_DIR) -I$(SHARED_DIR) -I$(RES_DIR)
TEST_EXEC = main_test
TEST_DIRS := $(TEST_DIR) $(SHARED_DIR) $(RES_DIR) $(UNITY_FOLDER)
TEST_FILES := $(wildcard $(patsubst %,%/*.c, $(TEST_DIRS)))
HEADER_TEST_FILES := $(wildcard $(patsubst %,%/*.h, $(TEST_DIRS)))
TEST_INC_DIRS=-I$(TEST_DIR) -I$(SHARED_DIR) -I$(UNITY_FOLDER) -I$(RES_DIR)
CC=gcc
SYMBOLS=-Wall -Werror -g -pedantic -O0 -std=c99
TEST_SYMBOLS=$(SYMBOLS) -DTEST
.PHONY: clean test
all: $(PROD_EXEC)
$(PROD_EXEC): Makefile $(PROD_FILES) $(HEADER_FILES)
$(CC) $(PROD_INC_DIRS) $(TEST_SYMBOLS) $(PROD_FILES) -o $(BUILD_DIR)/$(PROD_EXEC)
$(TEST_EXEC): Makefile $(TEST_FILES) $(HEADER_FILES)
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(BUILD_DIR)/$(TEST_EXEC)
run: $(PROD_EXEC)
@./$(BUILD_DIR)/$(PROD_EXEC)
test: $(TEST_EXEC)
@./$(BUILD_DIR)/$(TEST_EXEC)
clean:
rm -f $(BUILD_DIR)/$(PROD_EXEC)
rm -f $(BUILD_DIR)/$(TEST_EXEC)

View File

@@ -0,0 +1,841 @@
/* ==========================================
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.h"
#include <stdio.h>
#include <string.h>
#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
/// return prematurely if we are already in failure or ignore state
#define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); }
struct _Unity Unity = { 0 };
const char* UnityStrNull = "NULL";
const char* UnityStrSpacer = ". ";
const char* UnityStrExpected = " Expected ";
const char* UnityStrWas = " Was ";
const char* UnityStrTo = " To ";
const char* UnityStrElement = " Element ";
const char* UnityStrMemory = " Memory Mismatch";
const char* UnityStrDelta = " Values Not Within Delta ";
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
//-----------------------------------------------
// Pretty Printers & Test Result Output Handlers
//-----------------------------------------------
void UnityPrint(const char* string)
{
const char* pch = string;
if (pch != NULL)
{
while (*pch)
{
// printable characters plus CR & LF are printed
if ((*pch <= 126) && (*pch >= 32))
{
UNITY_OUTPUT_CHAR(*pch);
}
//write escaped carriage returns
else if (*pch == 13)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('r');
}
//write escaped line feeds
else if (*pch == 10)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('n');
}
// unprintable characters are shown as codes
else
{
UNITY_OUTPUT_CHAR('\\');
UnityPrintNumberHex((_U_SINT)*pch, 2);
}
pch++;
}
}
}
//-----------------------------------------------
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
{
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
UnityPrintNumber(number);
}
else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
{
UnityPrintNumberUnsigned((_U_UINT)number);
}
else
{
UnityPrintNumberHex((_U_UINT)number, (style & 0x000F) << 1);
}
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumber(const _U_SINT number_to_print)
{
_U_SINT divisor = 1;
_U_SINT next_divisor;
_U_SINT number = number_to_print;
if (number < 0)
{
UNITY_OUTPUT_CHAR('-');
number = -number;
}
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumberUnsigned(const _U_UINT number)
{
_U_UINT divisor = 1;
_U_UINT next_divisor;
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
}
//-----------------------------------------------
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
{
_U_UINT nibble;
char nibbles = nibbles_to_print;
UNITY_OUTPUT_CHAR('0');
UNITY_OUTPUT_CHAR('x');
while (nibbles > 0)
{
nibble = (number >> (--nibbles << 2)) & 0x0000000F;
if (nibble <= 9)
{
UNITY_OUTPUT_CHAR((char)('0' + nibble));
}
else
{
UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
}
}
}
//-----------------------------------------------
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
{
_U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
_US32 i;
for (i = 0; i < UNITY_INT_WIDTH; i++)
{
if (current_bit & mask)
{
if (current_bit & number)
{
UNITY_OUTPUT_CHAR('1');
}
else
{
UNITY_OUTPUT_CHAR('0');
}
}
else
{
UNITY_OUTPUT_CHAR('X');
}
current_bit = current_bit >> 1;
}
}
//-----------------------------------------------
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(_UF number)
{
char TempBuffer[32];
sprintf(TempBuffer, "%.6f", number);
UnityPrint(TempBuffer);
}
#endif
//-----------------------------------------------
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
{
UnityPrint(file);
UNITY_OUTPUT_CHAR(':');
UnityPrintNumber(line);
UNITY_OUTPUT_CHAR(':');
UnityPrint(Unity.CurrentTestName);
UNITY_OUTPUT_CHAR(':');
}
//-----------------------------------------------
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
{
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("FAIL:");
}
//-----------------------------------------------
void UnityConcludeTest(void)
{
if (Unity.CurrentTestIgnored)
{
Unity.TestIgnores++;
}
else if (!Unity.CurrentTestFailed)
{
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
UnityPrint("PASS");
UNITY_PRINT_EOL;
}
else
{
Unity.TestFailures++;
}
Unity.CurrentTestFailed = 0;
Unity.CurrentTestIgnored = 0;
}
//-----------------------------------------------
void UnityAddMsgIfSpecified(const char* msg)
{
if (msg)
{
UnityPrint(UnityStrSpacer);
UnityPrint(msg);
}
}
//-----------------------------------------------
void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
{
UnityPrint(UnityStrExpected);
if (expected != NULL)
{
UNITY_OUTPUT_CHAR('\'');
UnityPrint(expected);
UNITY_OUTPUT_CHAR('\'');
}
else
{
UnityPrint(UnityStrNull);
}
UnityPrint(UnityStrWas);
if (actual != NULL)
{
UNITY_OUTPUT_CHAR('\'');
UnityPrint(actual);
UNITY_OUTPUT_CHAR('\'');
}
else
{
UnityPrint(UnityStrNull);
}
}
//-----------------------------------------------
// Assertion & Control Helpers
//-----------------------------------------------
int UnityCheckArraysForNull(const void* expected, const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
{
//return true if they are both NULL
if ((expected == NULL) && (actual == NULL))
return 1;
//throw error if just expected is NULL
if (expected == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForExpected);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
//throw error if just actual is NULL
if (actual == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForActual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
//return false if neither is NULL
return 0;
}
//-----------------------------------------------
// Assertion Functions
//-----------------------------------------------
void UnityAssertBits(const _U_SINT mask,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if ((mask & expected) != (mask & actual))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintMask(mask, expected);
UnityPrint(UnityStrWas);
UnityPrintMask(mask, actual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualNumber(const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
UNITY_SKIP_EXECUTION;
if (expected != actual)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualIntArray(const _U_SINT* expected,
const _U_SINT* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
_UU32 elements = num_elements;
const _US8* ptr_exp = (_US8*)expected;
const _US8* ptr_act = (_US8*)actual;
UNITY_SKIP_EXECUTION;
if (elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
switch(style)
{
case UNITY_DISPLAY_STYLE_HEX8:
case UNITY_DISPLAY_STYLE_INT8:
case UNITY_DISPLAY_STYLE_UINT8:
while (elements--)
{
if (*ptr_exp != *ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 1;
ptr_act += 1;
}
break;
case UNITY_DISPLAY_STYLE_HEX16:
case UNITY_DISPLAY_STYLE_INT16:
case UNITY_DISPLAY_STYLE_UINT16:
while (elements--)
{
if (*(_US16*)ptr_exp != *(_US16*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US16*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US16*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 2;
ptr_act += 2;
}
break;
#ifdef UNITY_SUPPORT_64
case UNITY_DISPLAY_STYLE_HEX64:
case UNITY_DISPLAY_STYLE_INT64:
case UNITY_DISPLAY_STYLE_UINT64:
while (elements--)
{
if (*(_US64*)ptr_exp != *(_US64*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US64*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US64*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 8;
ptr_act += 8;
}
break;
#endif
default:
while (elements--)
{
if (*(_US32*)ptr_exp != *(_US32*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US32*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US32*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 4;
ptr_act += 4;
}
break;
}
}
//-----------------------------------------------
#ifndef UNITY_EXCLUDE_FLOAT
void UnityAssertEqualFloatArray(const _UF* expected,
const _UF* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 elements = num_elements;
const _UF* ptr_expected = expected;
const _UF* ptr_actual = actual;
_UF diff, tol;
UNITY_SKIP_EXECUTION;
if (elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
while (elements--)
{
diff = *ptr_expected - *ptr_actual;
if (diff < 0.0)
diff = 0.0 - diff;
tol = UNITY_FLOAT_PRECISION * *ptr_expected;
if (tol < 0.0)
tol = 0.0 - tol;
if (diff > tol)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrintFloat(*ptr_expected);
UnityPrint(UnityStrWas);
UnityPrintFloat(*ptr_actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_expected++;
ptr_actual++;
}
}
//-----------------------------------------------
void UnityAssertFloatsWithin(const _UF delta,
const _UF expected,
const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UF diff = actual - expected;
_UF pos_delta = delta;
UNITY_SKIP_EXECUTION;
if (diff < 0)
{
diff = 0.0f - diff;
}
if (pos_delta < 0)
{
pos_delta = 0.0f - pos_delta;
}
if (pos_delta < diff)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrintFloat(expected);
UnityPrint(UnityStrWas);
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
#endif
//-----------------------------------------------
void UnityAssertNumbersWithin( const _U_SINT delta,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
UNITY_SKIP_EXECUTION;
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
if (actual > expected)
Unity.CurrentTestFailed = ((actual - expected) > delta);
else
Unity.CurrentTestFailed = ((expected - actual) > delta);
}
else
{
if ((_U_UINT)actual > (_U_UINT)expected)
Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
else
Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrDelta);
UnityPrintNumberByStyle(delta, style);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 i;
UNITY_SKIP_EXECUTION;
// if both pointers not null compare the strings
if (expected && actual)
{
for (i = 0; expected[i] || actual[i]; i++)
{
if (expected[i] != actual[i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected != actual)
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrintExpectedAndActualStrings(expected, actual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualStringArray( const char** expected,
const char** actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 i, j = 0;
UNITY_SKIP_EXECUTION;
// if no elements, it's an error
if (num_elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
do
{
// if both pointers not null compare the strings
if (expected[j] && actual[j])
{
for (i = 0; expected[j][i] || actual[j][i]; i++)
{
if (expected[j][i] != actual[j][i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected[j] != actual[j])
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT);
}
UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
} while (++j < num_elements);
}
//-----------------------------------------------
void UnityAssertEqualMemory( const void* expected,
const void* actual,
_UU32 length,
_UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
unsigned char* expected_ptr = (unsigned char*)expected;
unsigned char* actual_ptr = (unsigned char*)actual;
_UU32 elements = num_elements;
UNITY_SKIP_EXECUTION;
if ((elements == 0) || (length == 0))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
while (elements--)
{
if (memcmp((const void*)expected_ptr, (const void*)actual_ptr, length) != 0)
{
Unity.CurrentTestFailed = 1;
break;
}
expected_ptr += length;
actual_ptr += length;
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
}
UnityPrint(UnityStrMemory);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
// Control Functions
//-----------------------------------------------
void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
{
UNITY_SKIP_EXECUTION;
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("FAIL");
if (msg != NULL)
{
UNITY_OUTPUT_CHAR(':');
if (msg[0] != ' ')
{
UNITY_OUTPUT_CHAR(' ');
}
UnityPrint(msg);
}
UNITY_FAIL_AND_BAIL;
}
//-----------------------------------------------
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
{
UNITY_SKIP_EXECUTION;
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("IGNORE");
if (msg != NULL)
{
UNITY_OUTPUT_CHAR(':');
UNITY_OUTPUT_CHAR(' ');
UnityPrint(msg);
}
UNITY_IGNORE_AND_BAIL;
}
//-----------------------------------------------
void setUp(void);
void tearDown(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
Unity.CurrentTestName = FuncName;
Unity.CurrentTestLineNumber = FuncLineNum;
Unity.NumberOfTests++;
if (TEST_PROTECT())
{
setUp();
Func();
}
if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
{
tearDown();
}
UnityConcludeTest();
}
//-----------------------------------------------
void UnityBegin(void)
{
Unity.NumberOfTests = 0;
}
//-----------------------------------------------
int UnityEnd(void)
{
UnityPrint("-----------------------");
UNITY_PRINT_EOL;
UnityPrintNumber(Unity.NumberOfTests);
UnityPrint(" Tests ");
UnityPrintNumber(Unity.TestFailures);
UnityPrint(" Failures ");
UnityPrintNumber(Unity.TestIgnores);
UnityPrint(" Ignored");
UNITY_PRINT_EOL;
if (Unity.TestFailures == 0U)
{
UnityPrint("OK");
}
else
{
UnityPrint("FAIL");
}
UNITY_PRINT_EOL;
return Unity.TestFailures;
}

View File

@@ -0,0 +1,209 @@
/* ==========================================
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 UNITY_FRAMEWORK_H
#define UNITY_FRAMEWORK_H
#define UNITY
#include "unity_internals.h"
//-------------------------------------------------------
// Configuration Options
//-------------------------------------------------------
// Integers
// - Unity assumes 32 bit integers by default
// - If your compiler treats ints of a different size, define UNITY_INT_WIDTH
// Floats
// - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
// - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
// - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
// - define UNITY_FLOAT_VERBOSE to print floating point values in errors (uses sprintf)
// Output
// - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
// Optimization
// - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge
// - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests.
//-------------------------------------------------------
// Test Running Macros
//-------------------------------------------------------
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
#ifndef RUN_TEST
#define RUN_TEST(func, line_num) UnityDefaultTestRun(func, #func, line_num)
#endif
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
#define TEST_CASE(...)
//-------------------------------------------------------
// Basic Fail and Ignore
//-------------------------------------------------------
#define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, message)
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, message)
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
#define TEST_ONLY()
//-------------------------------------------------------
// Test Asserts (simple)
//-------------------------------------------------------
//Boolean
#define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE")
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE")
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE")
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL")
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL")
//Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal")
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, NULL)
//Integer Ranges (of all sizes)
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, NULL)
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, NULL)
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, NULL)
//Floating Point (If Enabled)
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
//-------------------------------------------------------
// Test Asserts (with additional messages)
//-------------------------------------------------------
//Boolean
#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, message)
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, message)
//Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, message)
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, message)
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, message)
//Integer Ranges (of all sizes)
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, message)
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, message)
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_STRING_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, message)
//Floating Point (If Enabled)
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message)
#endif

View File

@@ -0,0 +1,356 @@
/* ==========================================
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 UNITY_INTERNALS_H
#define UNITY_INTERNALS_H
#include <stdio.h>
#include <setjmp.h>
//-------------------------------------------------------
// Int Support
//-------------------------------------------------------
#ifndef UNITY_INT_WIDTH
#define UNITY_INT_WIDTH (32)
#endif
#ifndef UNITY_LONG_WIDTH
#define UNITY_LONG_WIDTH (32)
#endif
#if (UNITY_INT_WIDTH == 32)
typedef unsigned char _UU8;
typedef unsigned short _UU16;
typedef unsigned int _UU32;
typedef signed char _US8;
typedef signed short _US16;
typedef signed int _US32;
#elif (UNITY_INT_WIDTH == 16)
typedef unsigned char _UU8;
typedef unsigned int _UU16;
typedef unsigned long _UU32;
typedef signed char _US8;
typedef signed int _US16;
typedef signed long _US32;
#else
#error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported)
#endif
//-------------------------------------------------------
// 64-bit Support
//-------------------------------------------------------
#ifndef UNITY_SUPPORT_64
//No 64-bit Support
typedef _UU32 _U_UINT;
typedef _US32 _U_SINT;
#else
//64-bit Support
#if (UNITY_LONG_WIDTH == 32)
typedef unsigned long long _UU64;
typedef signed long long _US64;
#elif (UNITY_LONG_WIDTH == 64)
typedef unsigned long _UU64;
typedef signed long _US64;
#else
#error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported)
#endif
typedef _UU64 _U_UINT;
typedef _US64 _U_SINT;
#endif
//-------------------------------------------------------
// Pointer Support
//-------------------------------------------------------
#ifndef UNITY_POINTER_WIDTH
#define UNITY_POINTER_WIDTH (32)
#endif
#if (UNITY_POINTER_WIDTH == 32)
typedef _UU32 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32
#elif (UNITY_POINTER_WIDTH == 64)
typedef _UU64 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64
#elif (UNITY_POINTER_WIDTH == 16)
typedef _UU16 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16
#else
#error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported)
#endif
//-------------------------------------------------------
// Float Support
//-------------------------------------------------------
#ifdef UNITY_EXCLUDE_FLOAT
//No Floating Point Support
#undef UNITY_FLOAT_PRECISION
#undef UNITY_FLOAT_TYPE
#undef UNITY_FLOAT_VERBOSE
#else
//Floating Point Support
#ifndef UNITY_FLOAT_PRECISION
#define UNITY_FLOAT_PRECISION (0.00001f)
#endif
#ifndef UNITY_FLOAT_TYPE
#define UNITY_FLOAT_TYPE float
#endif
typedef UNITY_FLOAT_TYPE _UF;
#endif
//-------------------------------------------------------
// Output Method
//-------------------------------------------------------
#ifndef UNITY_OUTPUT_CHAR
//Default to using putchar, which is defined in stdio.h above
#define UNITY_OUTPUT_CHAR(a) putchar(a)
#else
//If defined as something else, make sure we declare it here so it's ready for use
extern int UNITY_OUTPUT_CHAR(int);
#endif
//-------------------------------------------------------
// Footprint
//-------------------------------------------------------
#ifndef UNITY_LINE_TYPE
#define UNITY_LINE_TYPE unsigned short
#endif
#ifndef UNITY_COUNTER_TYPE
#define UNITY_COUNTER_TYPE unsigned short
#endif
//-------------------------------------------------------
// Internal Structs Needed
//-------------------------------------------------------
typedef void (*UnityTestFunction)(void);
#define UNITY_DISPLAY_RANGE_INT (0x10)
#define UNITY_DISPLAY_RANGE_UINT (0x20)
#define UNITY_DISPLAY_RANGE_HEX (0x40)
#define UNITY_DISPLAY_RANGE_AUTO (0x80)
typedef enum
{
UNITY_DISPLAY_STYLE_INT = 4 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO,
UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT,
UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT,
UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT,
#endif
UNITY_DISPLAY_STYLE_UINT = 4 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO,
UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT,
UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT,
UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT,
#endif
UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX,
UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX,
UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX,
#endif
} UNITY_DISPLAY_STYLE_T;
struct _Unity
{
const char* TestFile;
const char* CurrentTestName;
_UU32 CurrentTestLineNumber;
UNITY_COUNTER_TYPE NumberOfTests;
UNITY_COUNTER_TYPE TestFailures;
UNITY_COUNTER_TYPE TestIgnores;
UNITY_COUNTER_TYPE CurrentTestFailed;
UNITY_COUNTER_TYPE CurrentTestIgnored;
jmp_buf AbortFrame;
};
extern struct _Unity Unity;
//-------------------------------------------------------
// Test Suite Management
//-------------------------------------------------------
void UnityBegin(void);
int UnityEnd(void);
void UnityConcludeTest(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
//-------------------------------------------------------
// Test Output
//-------------------------------------------------------
void UnityPrint(const char* string);
void UnityPrintMask(const _U_UINT mask, const _U_UINT number);
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style);
void UnityPrintNumber(const _U_SINT number);
void UnityPrintNumberUnsigned(const _U_UINT number);
void UnityPrintNumberHex(const _U_UINT number, const char nibbles);
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(const _UF number);
#endif
//-------------------------------------------------------
// Test Assertion Fuctions
//-------------------------------------------------------
// Use the macros below this section instead of calling
// these directly. The macros have a consistent naming
// convention and will pull in file and line information
// for you.
void UnityAssertEqualNumber(const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertEqualIntArray(const _U_SINT* expected,
const _U_SINT* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertBits(const _U_SINT mask,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualStringArray( const char** expected,
const char** actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualMemory( const void* expected,
const void* actual,
const _UU32 length,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertNumbersWithin(const _U_SINT delta,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
#ifndef UNITY_EXCLUDE_FLOAT
void UnityAssertFloatsWithin(const _UF delta,
const _UF expected,
const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualFloatArray(const _UF* expected,
const _UF* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
#endif
//-------------------------------------------------------
// Basic Fail and Ignore
//-------------------------------------------------------
#define UNITY_TEST_FAIL(line, message) UnityFail( (message), (UNITY_LINE_TYPE)line);
#define UNITY_TEST_IGNORE(line, message) UnityIgnore( (message), (UNITY_LINE_TYPE)line);
//-------------------------------------------------------
// Test Asserts
//-------------------------------------------------------
#define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, message);}
#define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((_U_SINT)(mask), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER)
#define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT8)
#define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT16)
#define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT32)
#define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT8)
#define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT16)
#define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT32)
#define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((const char**)(expected), (const char**)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#ifdef UNITY_SUPPORT_64
#define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
#define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
#define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#endif
#ifdef UNITY_EXCLUDE_FLOAT
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#else
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#endif
#endif

View File

@@ -0,0 +1,97 @@
#include "unity_test_module.h"
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "unity.h"
void (*unity_setUp_ptr)(void) = NULL;
void (*unit_tearDown_ptr)(void) = NULL;
#ifdef UNITY_USE_MODULE_SETUP_TEARDOWN
void setUp()
{
if(unity_setUp_ptr != NULL) unity_setUp_ptr();
}
void tearDown()
{
if(unit_tearDown_ptr != NULL) unit_tearDown_ptr();
}
#endif
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) )
{
unity_setUp_ptr = setUp;
unit_tearDown_ptr = tearDown;
}
void UnityUnregisterSetupTearDown(void)
{
unity_setUp_ptr = NULL;
unit_tearDown_ptr = NULL;
}
UnityTestModule* UnityTestModuleFind(
UnityTestModule* modules,
size_t number_of_modules,
char* wantedModule)
{
for(size_t i = 0; i < number_of_modules; i++) {
if(strcmp(wantedModule, modules[i].name) == 0) {
return &modules[i];
}
}
return NULL;
}
void UnityTestModuleRunRequestedModules(
int number_of_requested_modules,
char* requested_modules_names[],
UnityTestModule* allModules,
size_t number_of_modules )
{
for(int i = 0; i < number_of_requested_modules; i++)
{
UnityTestModule* module = UnityTestModuleFind(allModules,
number_of_modules, requested_modules_names[i]);
if(module != NULL)
{
module->run_tests();
}
else
{
printf("Ignoring: could not find requested module: %s\n",
requested_modules_names[i]);
}
}
}
int UnityTestModuleRun(
int argc,
char * argv[],
UnityTestModule* allModules,
size_t number_of_modules)
{
UnityBegin();
bool moduleRequests = (argc > 1);
if(moduleRequests)
{
UnityTestModuleRunRequestedModules(argc-1, &argv[1],
allModules, number_of_modules);
}
else
{
for(int i = 0; i < number_of_modules; i++)
{
allModules[i].run_tests();
}
}
return UnityEnd();
}

View File

@@ -0,0 +1,31 @@
#ifndef UNITY_TEST_MODULE_H
#define UNITY_TEST_MODULE_H
#include <stddef.h>
typedef struct {
char name[24];
void(*run_tests)(void);
} UnityTestModule;
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) );
void UnityUnregisterSetupTearDown(void);
UnityTestModule* UnityTestModuleFind(
UnityTestModule* modules,
size_t number_of_modules,
char* wantedModule);
void UnityTestModuleRunRequestedModules(
int number_of_requested_modules,
char* requested_modules_names[],
UnityTestModule* allModules,
size_t number_of_modules );
int UnityTestModuleRun(
int argc,
char * argv[],
UnityTestModule* allModules,
size_t number_of_modules);
#endif

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include "bit_stuff.h"
// leave resource_detector.h as last include!
#include "resource_detector.h"
int main(int argc, char* argv[])
{
// TODO: implement if you want
return 0;
}

View File

@@ -0,0 +1,44 @@
#include "bit_stuff.h"
#include <limits.h>
#include <stddef.h>
// leave resource_detector.h as last include!
#include "resource_detector.h"
unsigned int count_ones(unsigned int value){
unsigned int count = 0;
while (value){
count += value & 1;
value >>= 1;
}
return count;
}
void make_bitmask(unsigned int width, unsigned int shift, unsigned int* mask){
if (width == 0 || width > sizeof(unsigned int)*CHAR_BIT) return;
if (width == sizeof(unsigned int) * CHAR_BIT) *mask = ~0U << shift;
else *mask = ((1U << width) - 1) << shift;
}
void apply_bitmask(unsigned int value, unsigned int mask, unsigned int* masked_value) {
if (masked_value != NULL) {
*masked_value = value & mask;
}
}
void flip_bit(unsigned int value, unsigned int bit_index, unsigned int* updated_value){
if (updated_value == 0 || bit_index >= sizeof(unsigned int) * CHAR_BIT) return;
*updated_value = value ^ (1U << bit_index);
}
void extract_nibbles_from_byte(uint8_t value, uint8_t* high_nibble, uint8_t* low_nibble){
if (high_nibble == NULL || low_nibble == NULL) return;
*high_nibble = (value >> 4) & 0xF;
*low_nibble = value & 0xF;
}
void combine_nibles_to_byte(uint8_t high_nibble, uint8_t low_nibble, uint8_t* value){
if (value == NULL) return;
*value = (high_nibble << 4) | (low_nibble);
}

View File

@@ -0,0 +1,36 @@
#pragma once
#include <stdint.h>
/* pre : -
* post: the number of bits with value 1 is counted and returned
*/
unsigned int count_ones(unsigned int value);
/* pre : -
* post: a bitmask with a given width and a given shift is generated (so w=5 and
* s=1 gives 00111110)
*/
void make_bitmask(unsigned int width, unsigned int shift, unsigned int* mask);
/* pre : -
* post: 'masked_value' is assigned the value of 'value' with the 'mask' applied
*/
void apply_bitmask(unsigned int value, unsigned int mask, unsigned int* masked_value);
/* pre : -
* post: the bit of index 'bit_index' of 'value' is flipped: 0 --> 1, 1 --> 0.
*/
void flip_bit(unsigned int value, unsigned int bit_index, unsigned int* updated_value);
/* pre : -
* post: the high and low nibbles of 'value' of stored in 'high_nibble' and
* 'low_nibble'.
*/
void extract_nibbles_from_byte(uint8_t value, uint8_t* high_nibble, uint8_t* low_nibbe);
/* pre : -
* post: the nibble values of the 'high_nibble' and 'low_nibble' are combined
* and stored in 'value'
*/
void combine_nibles_to_byte(uint8_t high_nibble, uint8_t low_nibbe, uint8_t* value);

View File

@@ -0,0 +1,112 @@
#include "bit_stuff.h"
#include "unity.h"
// leave resource_detector.h as last include!
#include "resource_detector.h"
// I rather dislike keeping line numbers updated, so I made my own macro to
// ditch the line number
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
void setUp(void)
{
// This is run before EACH test
}
void tearDown(void)
{
// This is run after EACH test
}
static void test_countOnes(void)
{
TEST_ASSERT_EQUAL_UINT32(0, count_ones(0x0));
TEST_ASSERT_EQUAL_UINT32(32, count_ones(0xffffffff));
TEST_ASSERT_EQUAL_UINT32(16, count_ones(0x5a5a5a5a));
}
static void test_make_bitmask_creates_mask_with_correct_width(void)
{
unsigned int mask = 0;
make_bitmask(1, 0, &mask);
TEST_ASSERT_EQUAL_HEX32(0x1, mask);
make_bitmask(2, 0, &mask);
TEST_ASSERT_EQUAL_HEX32(0x3, mask);
make_bitmask(5, 0, &mask);
TEST_ASSERT_EQUAL_HEX32(0x1f, mask);
make_bitmask(32, 0, &mask);
TEST_ASSERT_EQUAL_HEX32(0xffffffff, mask);
}
static void test_make_bitmask_creates_mask_with_correct_width_and_shift(void)
{
unsigned int mask = 0;
make_bitmask(1, 1, &mask);
TEST_ASSERT_EQUAL_HEX32(0x2, mask);
make_bitmask(1, 7, &mask);
TEST_ASSERT_EQUAL_HEX32(0x80, mask);
make_bitmask(1, 8, &mask);
TEST_ASSERT_EQUAL_HEX32(0x100, mask);
make_bitmask(3, 15, &mask);
TEST_ASSERT_EQUAL_HEX32(0x38000, mask);
make_bitmask(8, 30, &mask);
TEST_ASSERT_EQUAL_HEX32(0xC0000000, mask);
}
static void test_countOnesInBitMask(void)
{
unsigned int i = 0, mask = 0;
for (i = 0; i < 32; i++)
{
make_bitmask(i, 0, &mask);
TEST_ASSERT_EQUAL_UINT32(i, count_ones(mask));
}
}
static void test_apply_bit_mask(void)
{
unsigned int masked_value = 0;
apply_bitmask(0xAE, 0xC3, &masked_value);
TEST_ASSERT_EQUAL(0x82, masked_value);
}
static void test_flip_bit(void)
{
unsigned int updated_value = 0;
flip_bit(0xB, 0, &updated_value);
TEST_ASSERT_EQUAL(0xA, updated_value);
flip_bit(0xB, 2, &updated_value);
TEST_ASSERT_EQUAL(0xF, updated_value);
}
static void test_extract_nibbles_from_byte(void)
{
uint8_t high_nibble = 0, low_nibble = 0;
extract_nibbles_from_byte(0xB9, &high_nibble, &low_nibble);
TEST_ASSERT_EQUAL(0x9, low_nibble);
TEST_ASSERT_EQUAL(0xB, high_nibble);
}
static void test_combine_nibles_to_byte(void)
{
uint8_t value = 0;
combine_nibles_to_byte(0xB, 0x5, &value);
TEST_ASSERT_EQUAL(0xB5, value);
}
int main(int argc, char* argv[])
{
UnityBegin();
MY_RUN_TEST(test_make_bitmask_creates_mask_with_correct_width);
MY_RUN_TEST(test_make_bitmask_creates_mask_with_correct_width_and_shift);
MY_RUN_TEST(test_countOnes);
MY_RUN_TEST(test_countOnesInBitMask);
MY_RUN_TEST(test_apply_bit_mask);
MY_RUN_TEST(test_flip_bit);
MY_RUN_TEST(test_extract_nibbles_from_byte);
MY_RUN_TEST(test_combine_nibles_to_byte);
return UnityEnd();
}

View File

@@ -0,0 +1,41 @@
PROD_DIR := ./product
SHARED_DIR := ./shared
TEST_DIR := ./test
UNITY_FOLDER :=./Unity
BUILD_DIR :=./build
PROD_EXEC = main
PROD_DIRS := $(PROD_DIR) $(SHARED_DIR)
PROD_FILES := $(wildcard $(patsubst %,%/*.c, $(PROD_DIRS)))
HEADER_PROD_FILES := $(wildcard $(patsubst %,%/*.h, $(PROD_DIRS)))
PROD_INC_DIRS=-I$(PROD_DIR) -I$(SHARED_DIR)
TEST_EXEC = main_test
TEST_DIRS := $(TEST_DIR) $(SHARED_DIR) $(UNITY_FOLDER)
TEST_FILES := $(wildcard $(patsubst %,%/*.c, $(TEST_DIRS)))
HEADER_TEST_FILES := $(wildcard $(patsubst %,%/*.h, $(TEST_DIRS)))
TEST_INC_DIRS=-I$(TEST_DIR) -I$(SHARED_DIR) -I$(UNITY_FOLDER)
CC=gcc
SYMBOLS=-Wall -Werror -g -pedantic -O0 -std=c99
TEST_SYMBOLS=$(SYMBOLS) -DTEST -DUNITY_USE_MODULE_SETUP_TEARDOWN
.PHONY: clean test
all: $(PROD_EXEC)
$(PROD_EXEC): Makefile $(PROD_FILES) $(HEADER_FILES)
$(CC) $(PROD_INC_DIRS) $(SYMBOLS) $(PROD_FILES) -o $(BUILD_DIR)/$(PROD_EXEC)
$(TEST_EXEC): Makefile $(TEST_FILES) $(HEADER_FILES)
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(BUILD_DIR)/$(TEST_EXEC)
run: $(PROD_EXEC)
@./$(BUILD_DIR)/$(PROD_EXEC)
test: $(TEST_EXEC)
@./$(BUILD_DIR)/$(TEST_EXEC)
clean:
rm -f $(BUILD_DIR)/$(PROD_EXEC)
rm -f $(BUILD_DIR)/$(TEST_EXEC)

View File

@@ -0,0 +1,841 @@
/* ==========================================
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.h"
#include <stdio.h>
#include <string.h>
#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
/// return prematurely if we are already in failure or ignore state
#define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); }
struct _Unity Unity = { 0 };
const char* UnityStrNull = "NULL";
const char* UnityStrSpacer = ". ";
const char* UnityStrExpected = " Expected ";
const char* UnityStrWas = " Was ";
const char* UnityStrTo = " To ";
const char* UnityStrElement = " Element ";
const char* UnityStrMemory = " Memory Mismatch";
const char* UnityStrDelta = " Values Not Within Delta ";
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
//-----------------------------------------------
// Pretty Printers & Test Result Output Handlers
//-----------------------------------------------
void UnityPrint(const char* string)
{
const char* pch = string;
if (pch != NULL)
{
while (*pch)
{
// printable characters plus CR & LF are printed
if ((*pch <= 126) && (*pch >= 32))
{
UNITY_OUTPUT_CHAR(*pch);
}
//write escaped carriage returns
else if (*pch == 13)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('r');
}
//write escaped line feeds
else if (*pch == 10)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('n');
}
// unprintable characters are shown as codes
else
{
UNITY_OUTPUT_CHAR('\\');
UnityPrintNumberHex((_U_SINT)*pch, 2);
}
pch++;
}
}
}
//-----------------------------------------------
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
{
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
UnityPrintNumber(number);
}
else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
{
UnityPrintNumberUnsigned((_U_UINT)number);
}
else
{
UnityPrintNumberHex((_U_UINT)number, (style & 0x000F) << 1);
}
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumber(const _U_SINT number_to_print)
{
_U_SINT divisor = 1;
_U_SINT next_divisor;
_U_SINT number = number_to_print;
if (number < 0)
{
UNITY_OUTPUT_CHAR('-');
number = -number;
}
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumberUnsigned(const _U_UINT number)
{
_U_UINT divisor = 1;
_U_UINT next_divisor;
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
}
//-----------------------------------------------
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
{
_U_UINT nibble;
char nibbles = nibbles_to_print;
UNITY_OUTPUT_CHAR('0');
UNITY_OUTPUT_CHAR('x');
while (nibbles > 0)
{
nibble = (number >> (--nibbles << 2)) & 0x0000000F;
if (nibble <= 9)
{
UNITY_OUTPUT_CHAR((char)('0' + nibble));
}
else
{
UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
}
}
}
//-----------------------------------------------
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
{
_U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
_US32 i;
for (i = 0; i < UNITY_INT_WIDTH; i++)
{
if (current_bit & mask)
{
if (current_bit & number)
{
UNITY_OUTPUT_CHAR('1');
}
else
{
UNITY_OUTPUT_CHAR('0');
}
}
else
{
UNITY_OUTPUT_CHAR('X');
}
current_bit = current_bit >> 1;
}
}
//-----------------------------------------------
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(_UF number)
{
char TempBuffer[32];
sprintf(TempBuffer, "%.6f", number);
UnityPrint(TempBuffer);
}
#endif
//-----------------------------------------------
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
{
UnityPrint(file);
UNITY_OUTPUT_CHAR(':');
UnityPrintNumber(line);
UNITY_OUTPUT_CHAR(':');
UnityPrint(Unity.CurrentTestName);
UNITY_OUTPUT_CHAR(':');
}
//-----------------------------------------------
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
{
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("FAIL:");
}
//-----------------------------------------------
void UnityConcludeTest(void)
{
if (Unity.CurrentTestIgnored)
{
Unity.TestIgnores++;
}
else if (!Unity.CurrentTestFailed)
{
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
UnityPrint("PASS");
UNITY_PRINT_EOL;
}
else
{
Unity.TestFailures++;
}
Unity.CurrentTestFailed = 0;
Unity.CurrentTestIgnored = 0;
}
//-----------------------------------------------
void UnityAddMsgIfSpecified(const char* msg)
{
if (msg)
{
UnityPrint(UnityStrSpacer);
UnityPrint(msg);
}
}
//-----------------------------------------------
void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
{
UnityPrint(UnityStrExpected);
if (expected != NULL)
{
UNITY_OUTPUT_CHAR('\'');
UnityPrint(expected);
UNITY_OUTPUT_CHAR('\'');
}
else
{
UnityPrint(UnityStrNull);
}
UnityPrint(UnityStrWas);
if (actual != NULL)
{
UNITY_OUTPUT_CHAR('\'');
UnityPrint(actual);
UNITY_OUTPUT_CHAR('\'');
}
else
{
UnityPrint(UnityStrNull);
}
}
//-----------------------------------------------
// Assertion & Control Helpers
//-----------------------------------------------
int UnityCheckArraysForNull(const void* expected, const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
{
//return true if they are both NULL
if ((expected == NULL) && (actual == NULL))
return 1;
//throw error if just expected is NULL
if (expected == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForExpected);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
//throw error if just actual is NULL
if (actual == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForActual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
//return false if neither is NULL
return 0;
}
//-----------------------------------------------
// Assertion Functions
//-----------------------------------------------
void UnityAssertBits(const _U_SINT mask,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if ((mask & expected) != (mask & actual))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintMask(mask, expected);
UnityPrint(UnityStrWas);
UnityPrintMask(mask, actual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualNumber(const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
UNITY_SKIP_EXECUTION;
if (expected != actual)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualIntArray(const _U_SINT* expected,
const _U_SINT* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
_UU32 elements = num_elements;
const _US8* ptr_exp = (_US8*)expected;
const _US8* ptr_act = (_US8*)actual;
UNITY_SKIP_EXECUTION;
if (elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
switch(style)
{
case UNITY_DISPLAY_STYLE_HEX8:
case UNITY_DISPLAY_STYLE_INT8:
case UNITY_DISPLAY_STYLE_UINT8:
while (elements--)
{
if (*ptr_exp != *ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 1;
ptr_act += 1;
}
break;
case UNITY_DISPLAY_STYLE_HEX16:
case UNITY_DISPLAY_STYLE_INT16:
case UNITY_DISPLAY_STYLE_UINT16:
while (elements--)
{
if (*(_US16*)ptr_exp != *(_US16*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US16*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US16*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 2;
ptr_act += 2;
}
break;
#ifdef UNITY_SUPPORT_64
case UNITY_DISPLAY_STYLE_HEX64:
case UNITY_DISPLAY_STYLE_INT64:
case UNITY_DISPLAY_STYLE_UINT64:
while (elements--)
{
if (*(_US64*)ptr_exp != *(_US64*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US64*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US64*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 8;
ptr_act += 8;
}
break;
#endif
default:
while (elements--)
{
if (*(_US32*)ptr_exp != *(_US32*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US32*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US32*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 4;
ptr_act += 4;
}
break;
}
}
//-----------------------------------------------
#ifndef UNITY_EXCLUDE_FLOAT
void UnityAssertEqualFloatArray(const _UF* expected,
const _UF* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 elements = num_elements;
const _UF* ptr_expected = expected;
const _UF* ptr_actual = actual;
_UF diff, tol;
UNITY_SKIP_EXECUTION;
if (elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
while (elements--)
{
diff = *ptr_expected - *ptr_actual;
if (diff < 0.0)
diff = 0.0 - diff;
tol = UNITY_FLOAT_PRECISION * *ptr_expected;
if (tol < 0.0)
tol = 0.0 - tol;
if (diff > tol)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrintFloat(*ptr_expected);
UnityPrint(UnityStrWas);
UnityPrintFloat(*ptr_actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_expected++;
ptr_actual++;
}
}
//-----------------------------------------------
void UnityAssertFloatsWithin(const _UF delta,
const _UF expected,
const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UF diff = actual - expected;
_UF pos_delta = delta;
UNITY_SKIP_EXECUTION;
if (diff < 0)
{
diff = 0.0f - diff;
}
if (pos_delta < 0)
{
pos_delta = 0.0f - pos_delta;
}
if (pos_delta < diff)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrintFloat(expected);
UnityPrint(UnityStrWas);
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
#endif
//-----------------------------------------------
void UnityAssertNumbersWithin( const _U_SINT delta,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
UNITY_SKIP_EXECUTION;
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
if (actual > expected)
Unity.CurrentTestFailed = ((actual - expected) > delta);
else
Unity.CurrentTestFailed = ((expected - actual) > delta);
}
else
{
if ((_U_UINT)actual > (_U_UINT)expected)
Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
else
Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrDelta);
UnityPrintNumberByStyle(delta, style);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 i;
UNITY_SKIP_EXECUTION;
// if both pointers not null compare the strings
if (expected && actual)
{
for (i = 0; expected[i] || actual[i]; i++)
{
if (expected[i] != actual[i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected != actual)
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrintExpectedAndActualStrings(expected, actual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualStringArray( const char** expected,
const char** actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 i, j = 0;
UNITY_SKIP_EXECUTION;
// if no elements, it's an error
if (num_elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
do
{
// if both pointers not null compare the strings
if (expected[j] && actual[j])
{
for (i = 0; expected[j][i] || actual[j][i]; i++)
{
if (expected[j][i] != actual[j][i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected[j] != actual[j])
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT);
}
UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
} while (++j < num_elements);
}
//-----------------------------------------------
void UnityAssertEqualMemory( const void* expected,
const void* actual,
_UU32 length,
_UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
unsigned char* expected_ptr = (unsigned char*)expected;
unsigned char* actual_ptr = (unsigned char*)actual;
_UU32 elements = num_elements;
UNITY_SKIP_EXECUTION;
if ((elements == 0) || (length == 0))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
while (elements--)
{
if (memcmp((const void*)expected_ptr, (const void*)actual_ptr, length) != 0)
{
Unity.CurrentTestFailed = 1;
break;
}
expected_ptr += length;
actual_ptr += length;
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
}
UnityPrint(UnityStrMemory);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
// Control Functions
//-----------------------------------------------
void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
{
UNITY_SKIP_EXECUTION;
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("FAIL");
if (msg != NULL)
{
UNITY_OUTPUT_CHAR(':');
if (msg[0] != ' ')
{
UNITY_OUTPUT_CHAR(' ');
}
UnityPrint(msg);
}
UNITY_FAIL_AND_BAIL;
}
//-----------------------------------------------
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
{
UNITY_SKIP_EXECUTION;
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("IGNORE");
if (msg != NULL)
{
UNITY_OUTPUT_CHAR(':');
UNITY_OUTPUT_CHAR(' ');
UnityPrint(msg);
}
UNITY_IGNORE_AND_BAIL;
}
//-----------------------------------------------
void setUp(void);
void tearDown(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
Unity.CurrentTestName = FuncName;
Unity.CurrentTestLineNumber = FuncLineNum;
Unity.NumberOfTests++;
if (TEST_PROTECT())
{
setUp();
Func();
}
if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
{
tearDown();
}
UnityConcludeTest();
}
//-----------------------------------------------
void UnityBegin(void)
{
Unity.NumberOfTests = 0;
}
//-----------------------------------------------
int UnityEnd(void)
{
UnityPrint("-----------------------");
UNITY_PRINT_EOL;
UnityPrintNumber(Unity.NumberOfTests);
UnityPrint(" Tests ");
UnityPrintNumber(Unity.TestFailures);
UnityPrint(" Failures ");
UnityPrintNumber(Unity.TestIgnores);
UnityPrint(" Ignored");
UNITY_PRINT_EOL;
if (Unity.TestFailures == 0U)
{
UnityPrint("OK");
}
else
{
UnityPrint("FAIL");
}
UNITY_PRINT_EOL;
return Unity.TestFailures;
}

View File

@@ -0,0 +1,209 @@
/* ==========================================
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 UNITY_FRAMEWORK_H
#define UNITY_FRAMEWORK_H
#define UNITY
#include "unity_internals.h"
//-------------------------------------------------------
// Configuration Options
//-------------------------------------------------------
// Integers
// - Unity assumes 32 bit integers by default
// - If your compiler treats ints of a different size, define UNITY_INT_WIDTH
// Floats
// - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
// - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
// - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
// - define UNITY_FLOAT_VERBOSE to print floating point values in errors (uses sprintf)
// Output
// - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
// Optimization
// - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge
// - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests.
//-------------------------------------------------------
// Test Running Macros
//-------------------------------------------------------
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
#ifndef RUN_TEST
#define RUN_TEST(func, line_num) UnityDefaultTestRun(func, #func, line_num)
#endif
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
#define TEST_CASE(...)
//-------------------------------------------------------
// Basic Fail and Ignore
//-------------------------------------------------------
#define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, message)
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, message)
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
#define TEST_ONLY()
//-------------------------------------------------------
// Test Asserts (simple)
//-------------------------------------------------------
//Boolean
#define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE")
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE")
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE")
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL")
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL")
//Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal")
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, NULL)
//Integer Ranges (of all sizes)
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, NULL)
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, NULL)
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, NULL)
//Floating Point (If Enabled)
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
//-------------------------------------------------------
// Test Asserts (with additional messages)
//-------------------------------------------------------
//Boolean
#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, message)
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, message)
//Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, message)
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, message)
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, message)
//Integer Ranges (of all sizes)
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, message)
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, message)
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_STRING_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, message)
//Floating Point (If Enabled)
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message)
#endif

View File

@@ -0,0 +1,356 @@
/* ==========================================
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 UNITY_INTERNALS_H
#define UNITY_INTERNALS_H
#include <stdio.h>
#include <setjmp.h>
//-------------------------------------------------------
// Int Support
//-------------------------------------------------------
#ifndef UNITY_INT_WIDTH
#define UNITY_INT_WIDTH (32)
#endif
#ifndef UNITY_LONG_WIDTH
#define UNITY_LONG_WIDTH (32)
#endif
#if (UNITY_INT_WIDTH == 32)
typedef unsigned char _UU8;
typedef unsigned short _UU16;
typedef unsigned int _UU32;
typedef signed char _US8;
typedef signed short _US16;
typedef signed int _US32;
#elif (UNITY_INT_WIDTH == 16)
typedef unsigned char _UU8;
typedef unsigned int _UU16;
typedef unsigned long _UU32;
typedef signed char _US8;
typedef signed int _US16;
typedef signed long _US32;
#else
#error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported)
#endif
//-------------------------------------------------------
// 64-bit Support
//-------------------------------------------------------
#ifndef UNITY_SUPPORT_64
//No 64-bit Support
typedef _UU32 _U_UINT;
typedef _US32 _U_SINT;
#else
//64-bit Support
#if (UNITY_LONG_WIDTH == 32)
typedef unsigned long long _UU64;
typedef signed long long _US64;
#elif (UNITY_LONG_WIDTH == 64)
typedef unsigned long _UU64;
typedef signed long _US64;
#else
#error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported)
#endif
typedef _UU64 _U_UINT;
typedef _US64 _U_SINT;
#endif
//-------------------------------------------------------
// Pointer Support
//-------------------------------------------------------
#ifndef UNITY_POINTER_WIDTH
#define UNITY_POINTER_WIDTH (32)
#endif
#if (UNITY_POINTER_WIDTH == 32)
typedef _UU32 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32
#elif (UNITY_POINTER_WIDTH == 64)
typedef _UU64 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64
#elif (UNITY_POINTER_WIDTH == 16)
typedef _UU16 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16
#else
#error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported)
#endif
//-------------------------------------------------------
// Float Support
//-------------------------------------------------------
#ifdef UNITY_EXCLUDE_FLOAT
//No Floating Point Support
#undef UNITY_FLOAT_PRECISION
#undef UNITY_FLOAT_TYPE
#undef UNITY_FLOAT_VERBOSE
#else
//Floating Point Support
#ifndef UNITY_FLOAT_PRECISION
#define UNITY_FLOAT_PRECISION (0.00001f)
#endif
#ifndef UNITY_FLOAT_TYPE
#define UNITY_FLOAT_TYPE float
#endif
typedef UNITY_FLOAT_TYPE _UF;
#endif
//-------------------------------------------------------
// Output Method
//-------------------------------------------------------
#ifndef UNITY_OUTPUT_CHAR
//Default to using putchar, which is defined in stdio.h above
#define UNITY_OUTPUT_CHAR(a) putchar(a)
#else
//If defined as something else, make sure we declare it here so it's ready for use
extern int UNITY_OUTPUT_CHAR(int);
#endif
//-------------------------------------------------------
// Footprint
//-------------------------------------------------------
#ifndef UNITY_LINE_TYPE
#define UNITY_LINE_TYPE unsigned short
#endif
#ifndef UNITY_COUNTER_TYPE
#define UNITY_COUNTER_TYPE unsigned short
#endif
//-------------------------------------------------------
// Internal Structs Needed
//-------------------------------------------------------
typedef void (*UnityTestFunction)(void);
#define UNITY_DISPLAY_RANGE_INT (0x10)
#define UNITY_DISPLAY_RANGE_UINT (0x20)
#define UNITY_DISPLAY_RANGE_HEX (0x40)
#define UNITY_DISPLAY_RANGE_AUTO (0x80)
typedef enum
{
UNITY_DISPLAY_STYLE_INT = 4 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO,
UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT,
UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT,
UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT,
#endif
UNITY_DISPLAY_STYLE_UINT = 4 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO,
UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT,
UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT,
UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT,
#endif
UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX,
UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX,
UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX,
#endif
} UNITY_DISPLAY_STYLE_T;
struct _Unity
{
const char* TestFile;
const char* CurrentTestName;
_UU32 CurrentTestLineNumber;
UNITY_COUNTER_TYPE NumberOfTests;
UNITY_COUNTER_TYPE TestFailures;
UNITY_COUNTER_TYPE TestIgnores;
UNITY_COUNTER_TYPE CurrentTestFailed;
UNITY_COUNTER_TYPE CurrentTestIgnored;
jmp_buf AbortFrame;
};
extern struct _Unity Unity;
//-------------------------------------------------------
// Test Suite Management
//-------------------------------------------------------
void UnityBegin(void);
int UnityEnd(void);
void UnityConcludeTest(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
//-------------------------------------------------------
// Test Output
//-------------------------------------------------------
void UnityPrint(const char* string);
void UnityPrintMask(const _U_UINT mask, const _U_UINT number);
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style);
void UnityPrintNumber(const _U_SINT number);
void UnityPrintNumberUnsigned(const _U_UINT number);
void UnityPrintNumberHex(const _U_UINT number, const char nibbles);
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(const _UF number);
#endif
//-------------------------------------------------------
// Test Assertion Fuctions
//-------------------------------------------------------
// Use the macros below this section instead of calling
// these directly. The macros have a consistent naming
// convention and will pull in file and line information
// for you.
void UnityAssertEqualNumber(const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertEqualIntArray(const _U_SINT* expected,
const _U_SINT* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertBits(const _U_SINT mask,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualStringArray( const char** expected,
const char** actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualMemory( const void* expected,
const void* actual,
const _UU32 length,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertNumbersWithin(const _U_SINT delta,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
#ifndef UNITY_EXCLUDE_FLOAT
void UnityAssertFloatsWithin(const _UF delta,
const _UF expected,
const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualFloatArray(const _UF* expected,
const _UF* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
#endif
//-------------------------------------------------------
// Basic Fail and Ignore
//-------------------------------------------------------
#define UNITY_TEST_FAIL(line, message) UnityFail( (message), (UNITY_LINE_TYPE)line);
#define UNITY_TEST_IGNORE(line, message) UnityIgnore( (message), (UNITY_LINE_TYPE)line);
//-------------------------------------------------------
// Test Asserts
//-------------------------------------------------------
#define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, message);}
#define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((_U_SINT)(mask), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER)
#define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT8)
#define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT16)
#define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT32)
#define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT8)
#define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT16)
#define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT32)
#define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((const char**)(expected), (const char**)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#ifdef UNITY_SUPPORT_64
#define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
#define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
#define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#endif
#ifdef UNITY_EXCLUDE_FLOAT
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#else
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#endif
#endif

View File

@@ -0,0 +1,97 @@
#include "unity_test_module.h"
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "unity.h"
void (*unity_setUp_ptr)(void) = NULL;
void (*unit_tearDown_ptr)(void) = NULL;
#ifdef UNITY_USE_MODULE_SETUP_TEARDOWN
void setUp()
{
if(unity_setUp_ptr != NULL) unity_setUp_ptr();
}
void tearDown()
{
if(unit_tearDown_ptr != NULL) unit_tearDown_ptr();
}
#endif
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) )
{
unity_setUp_ptr = setUp;
unit_tearDown_ptr = tearDown;
}
void UnityUnregisterSetupTearDown(void)
{
unity_setUp_ptr = NULL;
unit_tearDown_ptr = NULL;
}
UnityTestModule* UnityTestModuleFind(
UnityTestModule* modules,
size_t number_of_modules,
char* wantedModule)
{
for(size_t i = 0; i < number_of_modules; i++) {
if(strcmp(wantedModule, modules[i].name) == 0) {
return &modules[i];
}
}
return NULL;
}
void UnityTestModuleRunRequestedModules(
int number_of_requested_modules,
char* requested_modules_names[],
UnityTestModule* allModules,
size_t number_of_modules )
{
for(int i = 0; i < number_of_requested_modules; i++)
{
UnityTestModule* module = UnityTestModuleFind(allModules,
number_of_modules, requested_modules_names[i]);
if(module != NULL)
{
module->run_tests();
}
else
{
printf("Ignoring: could not find requested module: %s\n",
requested_modules_names[i]);
}
}
}
int UnityTestModuleRun(
int argc,
char * argv[],
UnityTestModule* allModules,
size_t number_of_modules)
{
UnityBegin();
bool moduleRequests = (argc > 1);
if(moduleRequests)
{
UnityTestModuleRunRequestedModules(argc-1, &argv[1],
allModules, number_of_modules);
}
else
{
for(int i = 0; i < number_of_modules; i++)
{
allModules[i].run_tests();
}
}
return UnityEnd();
}

View File

@@ -0,0 +1,31 @@
#ifndef UNITY_TEST_MODULE_H
#define UNITY_TEST_MODULE_H
#include <stddef.h>
typedef struct {
char name[24];
void(*run_tests)(void);
} UnityTestModule;
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) );
void UnityUnregisterSetupTearDown(void);
UnityTestModule* UnityTestModuleFind(
UnityTestModule* modules,
size_t number_of_modules,
char* wantedModule);
void UnityTestModuleRunRequestedModules(
int number_of_requested_modules,
char* requested_modules_names[],
UnityTestModule* allModules,
size_t number_of_modules );
int UnityTestModuleRun(
int argc,
char * argv[],
UnityTestModule* allModules,
size_t number_of_modules);
#endif

View File

@@ -0,0 +1,59 @@
A program for a skating weekend.
================================
General
-------
In these directories you'll find an empty project in which you can add your code for the skating program. This file contains everything you need to know.
As usual in this assignments directory you will have a pre-made Makefile in the main directory. If you call 'make' on the commandline in that directory, the normal executable (skates) will be built. With 'make test' the test application is built and run.
If you add new .c and .h files to the 'product' directory, these will automatically be recognized by the Makefile. For testing you can do 3 things:
1. rename 'empty_test.c' to something sensible and include all tests in it.
2. rename 'empty_test.c' to "your module name"_test.c and only include tests for a particular module. You'll also have to create header files for all test function prototypes and a test_main.c that runs all these tests.
Option 1 is the easiest, 2 is neater.
Desired features
-----------------
This program should be used for a skating weekend. In this weekend 8 skaters participate and they all ride 4 distances:
- 500 m
- 1500 m
- 5 km
- 10 km
A menu structure has already been created, more or less copied from Animal Shelter. Below are the menu options with the desired behavior:
- Show Skaters:
Shows the data of all 8 skaters. Initially all data are empty or zero.
- Add Skater:
This option allows you to add 1 of the 8 skaters. Your code will ask the skater's name and nationality. Times cannot be entered here yet, but your administration should keep a skater's name, nationality and time for each distance.
- Remove Skater:
This option asks which skater should be removed and clears the data of that skater.
- Add time:
This option asks for which skater and for which distance the time should be changed. If the time increases from previous entry a warning must be given.
So: suppose skater 1 raced the 500 m distance in 50 seconds and you have already filled that in. If a user now wants to change that time to 51 seconds, your program will ask if the user is sure and will only change the time if the user was sure.
- Show fastest times:
With this option the program asks you for which distance you want to see the times. After you have entered them, the program shows all skaters that have already ridden this distance in order from fastest to slowest. Skaters that have not ridden this distance will not be shown!
- Show final classification:
With this option the final classification is given. The skaters are sorted on their average speed, the fastest skater is on top.
If not all skaters have ridden all distances yet, a warning will be written to the screen that this is a preliminary ranking. After this warning only the skaters who have ridden all distances will be shown.
- Load file from disk:
Optional: if you don't want to retype all skaters every time (easier for testing your user interface!)
- Save administration to disk:
Optional.
- Quit:
Exits the program. IF you have implemented the Save/Load functions, the program will keep track of any data that has not been saved. If this is the case, you will first be asked if you still want to save the data before the program closes (Yes/No/Cancel or Save/Discard/Cancel).
Design
-------
As you learned in the first semester, the UI code may not be in the same unit (C file) as the 'rest'. This also applies here, of course. In addition, the 'rest' can certainly be subdivided into several small parts. Try to think about that. Think from different responsibilities in the application (for example: sorting of skaters is a different responsibility than reading/writing files on disk, so maybe the code should be in a separate file...).
HINT: reading and writing from the terminal is now done in terminal_io.c, so if you want to keep your design clean, the main function should not have that same responsibility.
Good Luck!

View File

@@ -0,0 +1,55 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Add your includes here:
#include "terminal_io.h"
int main(int argc, char* argv[])
{
MenuOptions choice = MO_SHOW_ICESKATERS;
printProgramHeader();
while (choice != MO_QUIT)
{
choice = getMenuChoice();
switch (choice)
{
case MO_SHOW_ICESKATERS:
fprintf(stderr, "not yet implemented\n");
break;
case MO_ADD_ICESKATER:
fprintf(stderr, "not yet implemented\n");
break;
case MO_REMOVE_ICESKATER:
fprintf(stderr, "not yet implemented\n");
break;
case MO_ADD_TIME:
fprintf(stderr, "not yet implemented\n");
break;
case MO_SHOW_CLASSIFICATION:
fprintf(stderr, "not yet implemented\n");
break;
case MO_SHOW_FINAL_CLASSIFICATION:
fprintf(stderr, "not yet implemented\n");
break;
case MO_LOAD:
fprintf(stderr, "not yet implemented\n");
break;
case MO_SAVE:
fprintf(stderr, "not yet implemented\n");
break;
case MO_QUIT:
// nothing to do here
break;
default:
fprintf(stderr, "ERROR: invalid choice: %d\n", choice);
break;
}
}
return 0;
}

View File

@@ -0,0 +1,92 @@
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "terminal_io.h"
#define MAX_STRLEN 80
static const char* MenuStrings[] =
{
"Show Iceskaters",
"Add Iceskater",
"Remove Iceskater",
"Add time",
"Show classification",
"Show final classification",
"Load ...",
"Save ...",
"Quit"
};
static const size_t NrMenuStrings =
sizeof(MenuStrings) / sizeof(MenuStrings[0]);
void clearScreen()
{
printf("\033[2J\033[1;1H");
}
int getInt(const char* message)
{
char line[MAX_STRLEN];
char* result = NULL;
int value = -1;
printf("%s", message);
result = fgets(line, sizeof(line), stdin);
if (result != NULL)
{
sscanf(result, "%d", &value);
}
return value;
}
int getLimitedInt(const char* message, const char* items[], int nrItems)
{
int choice = -1;
do
{
if (items != NULL)
{
for (int i = 0; i < nrItems; i++)
{
printf(" [%d] %s\n", i, items[i]);
}
}
choice = getInt(message);
} while (choice < 0 || choice >= nrItems);
return choice;
}
void getStr(const char* message, char* str, int maxLength)
{
char line[maxLength];
char* result = NULL;
printf("%s", message);
result = fgets(line, sizeof(line), stdin);
if (result != NULL)
{
if (result[strlen(result) - 1] == '\n')
{
result[strlen(result) - 1] = '\0';
}
strncpy(str, result, maxLength);
str[maxLength - 1] = '\0';
}
}
MenuOptions getMenuChoice()
{
printf("\n\nMENU\n====\n");
return (MenuOptions)getLimitedInt("choice: ", MenuStrings, NrMenuStrings);
}
void printProgramHeader()
{
printf("PRC2 opdracht 'Schaatsen'\n"
"-------------------------");
}

View File

@@ -0,0 +1,27 @@
#ifndef TERMINAL_IO_H
#define TERMINAL_IO_H
#include "skater.h"
typedef enum
{
MO_SHOW_ICESKATERS,
MO_ADD_ICESKATER,
MO_REMOVE_ICESKATER,
MO_ADD_TIME,
MO_SHOW_CLASSIFICATION,
MO_SHOW_FINAL_CLASSIFICATION,
MO_LOAD,
MO_SAVE,
MO_QUIT
} MenuOptions;
void clearScreen();
int getInt(const char* message);
int getLimitedInt(const char* message, const char* items[], int nrItems);
void getStr(const char* message, char* str, int maxLength);
MenuOptions getMenuChoice();
void printProgramHeader();
#endif

View File

@@ -0,0 +1,2 @@
#include "skater.h"

View File

@@ -0,0 +1,6 @@
#ifndef SKATER_H
#define SKATER_H
// define your skater datatypes here
#endif

View File

@@ -0,0 +1,16 @@
#include "unity_test_module.h"
/* As an alternative for header files we can declare that
* the following methos are available 'extern'ally.
*/
extern void run_skater_tests();
int main (int argc, char * argv[])
{
UnityTestModule allModules[] = { { "skater", run_skater_tests}
};
size_t number_of_modules = sizeof(allModules)/sizeof(allModules[0]);
return UnityTestModuleRun(argc, argv, allModules, number_of_modules);
}

View File

@@ -0,0 +1,41 @@
#include <string.h>
// add your include here
#include "unity.h"
#include "unity_test_module.h"
#include "skater.h"
// I rather dislike keeping line numbers updated, so I made my own
// macro to ditch the line number
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
void skater_setUp(void)
{
// This is run before EACH test
}
void skater_tearDown(void)
{
// This is run after EACH test
}
// TODO:
// - Rename and change this test to something usefull
// - Add more tests
// - Remove this comment :)
// Should you need a list of all TEST_ASSERT macros: take a look
// at unity.h
void test_skater_EmptyTest(void)
{
TEST_ASSERT_EQUAL(1, 0);
}
void run_skater_tests()
{
UnityRegisterSetupTearDown( skater_setUp, skater_tearDown);
MY_RUN_TEST(test_skater_EmptyTest);
UnityUnregisterSetupTearDown();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 KiB

View File

@@ -0,0 +1,51 @@
ASSIGNMENT=stegano
UNITY_FOLDER=./Unity
RESOURCE_CHECK_FOLDER=./ResourceDetector
INC_DIRS=-I$(RESOURCE_CHECK_FOLDER)
TEST_INC_DIRS=$(INC_DIRS) -I$(UNITY_FOLDER)
SRC_FILES=$(ASSIGNMENT)_main.c \
$(RESOURCE_CHECK_FOLDER)/resource_detector.c \
$(RESOURCE_CHECK_FOLDER)/list.c \
$(ASSIGNMENT).c
TEST_FILES=$(UNITY_FOLDER)/unity.c \
$(ASSIGNMENT)_test.c \
$(RESOURCE_CHECK_FOLDER)/resource_detector.c \
$(RESOURCE_CHECK_FOLDER)/list.c \
$(ASSIGNMENT).c
HEADER_FILES=*.h
TEST = $(ASSIGNMENT)_test
CC=gcc
SYMBOLS=-g -O0 -std=c99 -Wall -Werror -Wextra -pedantic -Wno-unused-parameter
TEST_SYMBOLS=$(SYMBOLS) -DTEST
.PHONY: clean test
all: $(ASSIGNMENT) $(TEST)
$(ASSIGNMENT): $(SRC_FILES) $(HEADER_FILES) Makefile
$(CC) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(ASSIGNMENT)
$(TEST): Makefile $(TEST_FILES) $(HEADER_FILES)
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(TEST)
clean:
rm -f $(ASSIGNMENT) $(TEST)
test: $(TEST)
@./$(TEST)
klocwork:
kwcheck run
klocwork_after_makefile_change: clean
kwinject make
kwcheck create -b kwinject.out
kwcheck import /opt/klocwork/Fontys_default.pconf
kwcheck run

View File

@@ -0,0 +1,278 @@
/* **********************************************
* generic linked list in plain c
* author: Freddy Hurkmans
* date: dec 20, 2014
* **********************************************/
/* ******************************************************************************
* This list is designed using object oriented ideas, but is implemented in c.
*
* The idea is: you construct a list for a certain data structure (say: mystruct):
* list_admin* mylist = construct_list(sizeof(mystruct))
* mylist contains private data for this list implementation. You need not worry
* about it, only give it as first parameter to each list method.
*
* This means you can have multiple lists at the same time, just make sure you
* give the right list_admin structure to the list function.
* When you're done with your list, just call the destructor: destruct_list(&mylist)
* The destructor automatically deletes remaining list elements and the list administration.
*
* As this list implementation keeps its own administration in list_admin, you need
* not worry about next pointers and such. Your structure doesn't even need pointers
* to itself, you only need to worry about data. A valid struct could thus be:
* typedef struct
* {
* int nr;
* char text[100];
* } mystruct;
*
* Adding data to the list is done using list_add_* methods, such as list_add_tail,
* which adds data to the end of the list:
* mystruct data = {10, "hello world!"};
* int result = list_add_tail(mylist, &data);
* You don't have to provide the size of your struct, you've already done that in
* the destructor. If result < 0 list_add_* has failed (either a parameter problem
* or malloc didn't give memory).
*
* You can get a pointer to your data using list_get_*, e.g. get the 2nd element:
* mystruct* dataptr = list_get_element(admin, 1);
* or get the last element:
* mystruct* dataptr = list_get_last(admin);
* If dataptr is not NULL it points to the correct data, else the operation failed.
*
* Searching for data in your list can be done with list_index_of*. list_index_of
* compares the data in each list item to the given data. If they are the same, it
* returns the index. If you want to search for an element with a certain value for
* nr or text (see mystruct) you can implement your own compare function and use
* list_index_of_special (check memcmp for required return values):
* int mycompare(void* p1, void* p2, size_t size)
* {
* // this example doesn't need size!
* mystruct* org = (mystruct*)p1;
* int* nr = (int*)p2;
* return org->nr - nr; // return 0 if they are the same
* }
* Say you want to search for an element that has nr 10:
* int nr = 10;
* int index = list_index_of_special(mylist, &nr, mycompare);
* As noted earlier: mycompare must have the same prototype as memcmp. In fact:
* list_index_of is a shortcut for list_index_of_special(mylist, data, memcmp).
*
* Finally you can delete items with list_delete_*. They should work rather
* straight forward. If they succeed they return 0. You don't have to delete
* all items before destructing your list.
*
* ******************************************************************************/
#include <string.h> /* for memcmp and memcpy */
#include "list.h"
static size_t data_size(const list_admin* admin);
static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index);
static list_head* get_list_head_of_element_n(list_admin* admin, size_t index);
static void remove_first_element(list_admin* admin);
static int remove_non_first_element(list_admin* admin, size_t index);
/* **********************************************
* Constructor / destructor
* **********************************************/
list_admin* construct_list(size_t element_size)
{
list_admin* admin = malloc(sizeof(*admin));
if (admin != NULL)
{
admin->head = NULL;
admin->element_size = element_size;
admin->nr_elements = 0;
}
return admin;
}
void destruct_list(list_admin** admin)
{
if ((admin != NULL) && (*admin != NULL))
{
while ((*admin)->head != NULL)
{
list_head* temp = (*admin)->head;
(*admin)->head = (*admin)->head->next;
free(temp);
temp = NULL;
}
free(*admin);
*admin = NULL;
}
}
/* **********************************************
* Public functions
* **********************************************/
int list_get_nr_elements(list_admin* admin)
{
int nr_elements = -1;
if (admin != NULL)
{
nr_elements = admin->nr_elements;
}
return nr_elements;
}
int list_add_tail(list_admin* admin, const void* data)
{
int result = -1;
if ((admin != NULL) && (data != NULL))
{
list_head* new = malloc(data_size(admin));
if (new != NULL)
{
result = 0;
new->next = NULL;
memcpy(new+1, data, admin->element_size);
if (admin->head == NULL)
{
admin->head = new;
}
else
{
list_head* temp = get_guaranteed_list_head_of_element_n(admin, admin->nr_elements-1);
temp->next = new;
}
admin->nr_elements++;
}
}
return result;
}
void* list_get_element(list_admin* admin, size_t index)
{
list_head* item = get_list_head_of_element_n(admin, index);
if(item != NULL)
{
item++; // user data is just beyond list_head, thus we must increase the pointer
}
return item;
}
void* list_get_last(list_admin* admin)
{
list_head* item = NULL;
if (admin != NULL)
{
item = list_get_element(admin, admin->nr_elements-1);
}
return item;
}
int list_index_of(list_admin* admin, const void* data)
{
return list_index_of_special(admin, data, memcmp);
}
int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr compare)
{
int index = -1;
if ((admin != NULL) && (data != NULL) && (compare != NULL))
{
list_head* temp = admin->head;
index = 0;
while ((temp != NULL) && (compare(temp+1, data, admin->element_size) != 0))
{
temp = temp->next;
index++;
}
if (temp == NULL)
{
index = -1;
}
}
return index;
}
int list_delete_item(list_admin* admin, size_t index)
{
int result = -1;
if ((admin != NULL) && (admin->head != NULL) && (index < admin->nr_elements))
{
if (index == 0)
{
result = 0;
remove_first_element(admin);
}
else
{
result = remove_non_first_element(admin, index);
}
}
return result;
}
int list_delete_last(list_admin* admin)
{
int result = -1;
if (admin != NULL)
{
result = list_delete_item(admin, admin->nr_elements - 1);
}
return result;
}
/* **********************************************
* Private functions
* **********************************************/
static size_t data_size(const list_admin* admin)
{
return admin->element_size + sizeof(list_head);
}
static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index)
{
list_head* item = admin->head;
for (size_t i = 0; (i < index) && (item != NULL); i++)
{
item = item->next;
}
return item;
}
static list_head* get_list_head_of_element_n(list_admin* admin, size_t index)
{
list_head* item = NULL;
if ((admin != NULL) && (index < admin->nr_elements))
{
item = get_guaranteed_list_head_of_element_n(admin, index);
}
return item;
}
static void remove_first_element(list_admin* admin)
{
list_head* temp = admin->head;
admin->head = admin->head->next;
free(temp);
temp = NULL;
admin->nr_elements--;
}
static int remove_non_first_element(list_admin* admin, size_t index)
{
int result = -1;
if (index > 0)
{
list_head* temp = get_list_head_of_element_n(admin, index-1);
if ((temp != NULL) && (temp->next != NULL)) // to remove element n, element n-1 and n must exist
{
result = 0;
list_head* to_delete = temp->next;
temp->next = to_delete->next;
free(to_delete);
to_delete = NULL;
admin->nr_elements--;
}
}
return result;
}

View File

@@ -0,0 +1,52 @@
#pragma once
#include <stdlib.h>
typedef struct list_head
{
struct list_head* next;
} list_head;
typedef struct
{
struct list_head* head;
size_t element_size;
size_t nr_elements;
} list_admin;
typedef int (*CompareFuncPtr)(const void*, const void*, size_t);
// call the constructor before using the list:
// list_admin* mylist = construct_list(sizeof(mystruct));
// if mylist equals NULL, no memory could be allocated. Please don't
// mess with the admin data, this can corrupt your data.
list_admin* construct_list(size_t element_size);
// call the destructor when you're done, pass the list administration
// as referenced parameter (the variable will be set to NULL).
void destruct_list(list_admin** admin);
// Reads the number of elements in your list. Returns -1 in case of
// errors, else the number of elements.
int list_get_nr_elements(list_admin* admin);
// Add data to the end of the list. Returns -1 in case of errors, else 0
int list_add_tail(list_admin* admin, const void* data);
// Returns a pointer to the requested element. Returns NULL in case of
// errors (such as: the element does not exist).
void* list_get_element(list_admin* admin, size_t index);
void* list_get_last(list_admin* admin);
// Returns the index to the first found list element that's equal to data,
// or -1 in case of errors (such as: not found).
int list_index_of(list_admin* admin, const void* data);
// Returns the index to the first found list element for which cmp says it's,
// equal to data, or -1 in case of errors (such as: not found). cmp must behave
// just like memcmp, i.e.: return 0 when the data matches.
int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr cmp);
// Delete an item in the list. Returns -1 in case of errors, else 0.
int list_delete_item(list_admin* admin, size_t index);
int list_delete_last(list_admin* admin);

View File

@@ -0,0 +1,270 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
//#include <malloc.h>
#include <string.h>
#include "resource_detector.h"
#undef malloc
#undef free
#undef main
#undef fopen
#undef fclose
#include "list.h"
#define MAGIC_CODE 0x78563412
#define ADDR(addr,offset) ((addr) + (offset))
#define SET_MAGIC_CODE(addr,offset) *((int*) ADDR(addr,offset)) = MAGIC_CODE
#define MAGIC_CODE_OK(addr,offset) (*((int*) ADDR(addr,offset)) == MAGIC_CODE)
typedef struct
{
char* addr;
unsigned int size;
const char* file;
unsigned int line;
} mem_data;
typedef struct
{
FILE* addr;
const char* file_to_open;
const char* mode;
const char* file;
unsigned int line;
} file_data;
static list_admin* memlist = NULL;
static list_admin* filelist = NULL;
static int memory_compare(const void* meminfo, const void* address, size_t size)
{
mem_data* info = (mem_data*)meminfo;
char* addr = (char*)address;
return info->addr - addr;
}
static int file_compare(const void* fileinfo, const void* address, size_t size)
{
file_data* info = (file_data*)fileinfo;
FILE* addr = (FILE*)address;
return info->addr - addr;
}
static void
invalidate (mem_data* info)
{
char* user_addr;
char* raw_addr;
unsigned int size;
user_addr = info->addr;
size = info->size;
raw_addr = ADDR (user_addr, -sizeof(int));
if (!MAGIC_CODE_OK(user_addr, -sizeof(int)) || !MAGIC_CODE_OK(user_addr, size))
{
fprintf (stderr, "ERROR: addr %p (%s, line %d): out-of-bound access\n", (void*)user_addr, info->file, info->line);
}
memset (raw_addr, 0xff, size + (2 * sizeof(int)));
free (raw_addr);
}
/*
* replacement of malloc
*/
extern void*
xmalloc (unsigned int size, const char* file, unsigned int line)
{
char* raw_addr = malloc (size + (2 * sizeof(int)));
char* user_addr;
mem_data info = {NULL, 0, NULL, 0};
if (raw_addr == NULL)
{
fprintf (stderr, "ERROR: malloc failed for %d bytes (%s, line %d)\n", size, file, line);
return (NULL);
}
else
{
user_addr = ADDR (raw_addr, sizeof (int));
SET_MAGIC_CODE (raw_addr, 0);
SET_MAGIC_CODE (user_addr, size);
info.addr = user_addr;
info.size = size;
info.file = file;
info.line = line;
list_add_tail(memlist, &info);
}
return ((void*) user_addr);
}
/*
* replacement of free
*/
extern void
xfree (void* addr, const char* filename, int linenr)
{
char* user_addr = (char*) addr;
mem_data* info = NULL;
/* check if allocated memory is in our list and retrieve its info */
int index = list_index_of_special(memlist, addr, memory_compare);
info = list_get_element(memlist, index);
if (info == NULL)
{
fprintf (stderr, "ERROR: trying to free memory that was not malloc-ed (addr %p) in %s : %d\n", (void*)user_addr, filename, linenr);
return;
}
invalidate (info);
list_delete_item(memlist, index);
}
static void
print_empty_lines(int n)
{
int i;
for (i = 0; i < n; i++)
{
fprintf(stderr, "\n");
}
}
static void set_colour_red(void)
{
fprintf(stderr, "\033[10;31m");
}
static void set_colour_gray(void)
{
fprintf(stderr, "\033[22;37m");
}
static void
print_line(void)
{
fprintf (stderr, "---------------------------------------------------------\n");
}
static void
print_not_good(void)
{
set_colour_gray();
print_line();
set_colour_red();
fprintf (stderr, " # # ###\n");
fprintf (stderr, " ## # #### ##### #### #### #### ##### ###\n");
fprintf (stderr, " # # # # # # # # # # # # # # ###\n");
fprintf (stderr, " # # # # # # # # # # # # # # \n");
fprintf (stderr, " # # # # # # # ### # # # # # # \n");
fprintf (stderr, " # ## # # # # # # # # # # # ###\n");
fprintf (stderr, " # # #### # #### #### #### ##### ###\n");
set_colour_gray();
print_line();
}
/*
* writes all info of the unallocated memory
*/
static void
resource_detection (void)
{
time_t now = time (NULL);
int forgotten_frees = list_get_nr_elements(memlist);
int nr_files_open = list_get_nr_elements(filelist);
if ((forgotten_frees > 0) || (nr_files_open > 0))
{
print_empty_lines(15);
}
if (forgotten_frees > 0)
{
mem_data* info = NULL;
print_line();
fprintf (stderr, "Memory Leak Summary, generated: %s", ctime (&now));
print_not_good();
set_colour_red();
while((info = list_get_element(memlist, 0)) != NULL)
{
fprintf (stderr, "forgot to free address: %p (%d bytes) that was allocated in: %s on line: %d\n",
(void*)info->addr, info->size, info->file, info->line);
list_delete_item(memlist, 0);
}
set_colour_gray();
print_line();
print_empty_lines(1);
}
if (nr_files_open > 0)
{
file_data* info = NULL;
print_line();
fprintf (stderr, "File Management Summary, generated: %s", ctime (&now));
print_not_good();
set_colour_red();
while((info = list_get_element(filelist, 0)) != NULL)
{
fprintf (stderr, "forgot to close file: %s (ptr %p, mode \"%s\") that was opened from: %s on line: %d\n",
info->file_to_open, (void*)(info->addr), info->mode, info->file, info->line);
list_delete_item(filelist, 0);
}
set_colour_gray();
print_line();
print_empty_lines(1);
}
if ((forgotten_frees == 0) && (nr_files_open == 0))
{
printf ("\nResource checks: OK\n\n");
}
destruct_list(&memlist);
destruct_list(&filelist);
}
extern FILE*
xfopen (const char* file_to_open, const char* mode, const char* filename, int linenr)
{
file_data info = {0};
info.addr = fopen(file_to_open, mode);
if (info.addr != NULL)
{
info.file_to_open = file_to_open;
info.mode = mode;
info.file = filename;
info.line = linenr;
list_add_tail(filelist, &info);
}
return info.addr;
}
extern int
xfclose(FILE* fptr, const char* filename, int linenr)
{
int index = list_index_of_special(filelist, fptr, file_compare);
if (index < 0)
{
fprintf (stderr, "ERROR: trying to close an unopened file in %s on line number %d.\n", filename, linenr);
return -1;
}
list_delete_item(filelist, index);
return (fclose (fptr));
}
extern int
main (int argc, char* argv[])
{
atexit (resource_detection);
memlist = construct_list(sizeof(mem_data));
filelist = construct_list(sizeof(file_data));
return (xmain (argc, argv));
}

View File

@@ -0,0 +1,18 @@
#ifndef RESOURCE_DETECTOR_H
#define RESOURCE_DETECTOR_H
#include <stdio.h>
#define main xmain
#define malloc(size) xmalloc ((size), (__FILE__), (__LINE__))
#define free(addr) xfree ((addr), __FILE__, __LINE__)
#define fopen(name,mode) xfopen ((name),(mode), __FILE__, __LINE__)
#define fclose(fptr) xfclose ((fptr), __FILE__, __LINE__)
extern int xmain(int argc, char* argv[]);
extern void* xmalloc(unsigned int size, const char* file, unsigned int line);
extern void xfree(void* addr, const char* filename, int linenr);
extern FILE* xfopen(const char* file_to_open, const char* mode, const char* filename, int linenr);
extern int xfclose(FILE* fptr, const char* filename, int linenr);
#endif

View File

@@ -0,0 +1,28 @@
UNITY_FOLDER=../Unity
TEST_INC_DIRS=$(INC_DIRS) -I$(UNITY_FOLDER)
TEST_FILES=$(UNITY_FOLDER)/unity.c \
list_test.c \
list.c
HEADER_FILES=*.h
TEST = list_test
CC=gcc
SYMBOLS=-Wall -Werror -pedantic -O0 -ggdb -std=c99
TEST_SYMBOLS=$(SYMBOLS) -DTEST
.PHONY: clean test
all: $(TEST)
$(TEST): Makefile $(TEST_FILES) $(HEADER_FILES)
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(TEST)
clean:
rm -f list $(TEST)
test: $(TEST)
@valgrind ./$(TEST)

View File

@@ -0,0 +1,300 @@
#include <string.h> /* for memcmp */
#include "list.h"
#include "unity.h"
// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
static list_admin* mylist = NULL;
typedef struct
{
int i;
int j;
} test_struct;
// compare function that returns 0 if test_struct.i matches, it ignores .j
static int compare_test_func(const void* p1, const void* p2, size_t size)
{
size = size; // to prevent warnings
const test_struct* data1 = (const test_struct*)p1;
const test_struct* data2 = (const test_struct*)p2;
return data1->i - data2->i;
}
// check n items in list against verify_data
// IMPORTANT: this function must check using list_get_element,
// else the test for that function is no longer useful
static void check_n_list_elements_ok(list_admin* admin, int nr_items, const test_struct* verify_data)
{
for(int i = 0; i < nr_items; i++)
{
test_struct* ptr = list_get_element(admin, i);
TEST_ASSERT_NOT_NULL(ptr);
TEST_ASSERT_EQUAL(0, memcmp(verify_data+i, ptr, sizeof(*ptr)));
}
}
void setUp(void)
{
// This is run before EACH test
mylist = construct_list(sizeof(test_struct));
TEST_ASSERT_NOT_NULL(mylist);
}
void tearDown(void)
{
// This is run after EACH test
destruct_list(&mylist);
TEST_ASSERT_NULL(mylist);
}
static void test_ConstructList(void)
{
TEST_ASSERT_NULL(mylist->head);
TEST_ASSERT_EQUAL(sizeof(test_struct), mylist->element_size);
TEST_ASSERT_EQUAL(0, mylist->nr_elements);
}
static void test_NrElements_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_get_nr_elements(NULL));
}
static void test_AddData_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_add_tail(mylist, NULL));
TEST_ASSERT_EQUAL(-1, list_add_tail(NULL, mylist));
}
static void test_AddData(void)
{
test_struct data = {3, 4};
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data));
TEST_ASSERT_NOT_NULL(mylist->head);
TEST_ASSERT_EQUAL(1, list_get_nr_elements(mylist));
list_head* head = mylist->head;
test_struct* element = (test_struct*)(head+1);
TEST_ASSERT_EQUAL(data.i, element->i);
TEST_ASSERT_EQUAL(data.j, element->j);
}
static void test_Add2PiecesOfData(void)
{
test_struct data1 = {8, 9};
test_struct data2 = {-3, -4};
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data1));
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data2));
TEST_ASSERT_NOT_NULL(mylist->head);
TEST_ASSERT_NOT_NULL(mylist->head->next);
TEST_ASSERT_EQUAL(2, list_get_nr_elements(mylist));
list_head* head = mylist->head->next;
test_struct* element = (test_struct*)(head+1);
TEST_ASSERT_EQUAL(data2.i, element->i);
TEST_ASSERT_EQUAL(data2.j, element->j);
}
static void test_GetElement_parameters(void)
{
TEST_ASSERT_NULL(list_get_element(NULL, 0));
}
static void test_GetElement(void)
{
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}};
const int nr_elements = sizeof(data)/sizeof(data[0]);
for(int i = 0; i < nr_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
}
check_n_list_elements_ok(mylist, nr_elements, data); // checks using list_get_element
TEST_ASSERT_NULL(list_get_element(mylist, nr_elements));
TEST_ASSERT_NULL(list_get_element(mylist, -1));
}
static void test_GetLast_parameters(void)
{
TEST_ASSERT_NULL(list_get_last(NULL));
}
static void test_GetLast(void)
{
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}};
const int nr_elements = sizeof(data)/sizeof(data[0]);
TEST_ASSERT_NULL(list_get_last(mylist));
for(int i = 0; i < nr_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
test_struct* ptr = list_get_last(mylist);
TEST_ASSERT_NOT_NULL(ptr);
TEST_ASSERT_EQUAL(0, memcmp(&(data[i]), ptr, sizeof(*ptr)));
}
}
static void test_IndexOf_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_index_of(mylist, NULL));
TEST_ASSERT_EQUAL(-1, list_index_of(NULL, mylist));
}
static void test_IndexOf(void)
{
const test_struct real_data[] = {{8, 9}, {-3, -4}, {21, 56}};
const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]);
const test_struct false_data[] = {{-3, 9}, {8, 56}, {21, -4}, {0, 0}};
const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]);
for(int i = 0; i < nr_real_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(real_data[i])));
}
for(int i = 0; i < nr_real_elements; i++)
{
TEST_ASSERT_EQUAL(i, list_index_of(mylist, &(real_data[i])));
}
for(int i = 0; i < nr_false_elements; i++)
{
TEST_ASSERT_EQUAL(-1, list_index_of(mylist, &(false_data[i])));
}
}
static void test_IndexOfSpecial_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, NULL, compare_test_func));
TEST_ASSERT_EQUAL(-1, list_index_of_special(NULL, mylist, compare_test_func));
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, mylist, NULL));
}
static void test_IndexOfSpecial(void)
{
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}}; // data in list
const test_struct real_data[] = {{8, -4}, {-3, 56}, {21, 9}}; // data to search for (i equals)
const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]);
const test_struct false_data[] = {{-2, 9}, {9, -4}, {22, 56}, {0, 0}}; // data that doesn't exist
const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]);
// first make sure our compare function works
for(int i = 0; i < nr_real_elements; i++)
{
TEST_ASSERT_EQUAL(0, compare_test_func(&(data[i]), &(real_data[i]), 0));
for (int j = 0; j < nr_false_elements; j++)
{
TEST_ASSERT_NOT_EQUAL(0, compare_test_func(&(data[i]), &(false_data[j]), 0))
}
}
for(int i = 0; i < nr_real_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
}
for(int i = 0; i < nr_real_elements; i++)
{
TEST_ASSERT_EQUAL(i, list_index_of_special(mylist, &(real_data[i]), compare_test_func));
}
for(int i = 0; i < nr_false_elements; i++)
{
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, &(false_data[i]), compare_test_func));
}
}
static void test_DeleteItem_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_delete_item(NULL, 0));
TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, -1));
}
static void test_DeleteItem(void)
{
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
int nr_elements = sizeof(data)/sizeof(data[0]);
const test_struct data_noFirst[] = {{-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
const test_struct data_noLast[] = {{-3, -4}, {21, 56}, {0, 0}};
const test_struct data_noMiddle[] = {{-3, -4}, {0, 0}};
TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, 0));
for(int i = 0; i < nr_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
}
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 0));
nr_elements--;
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
check_n_list_elements_ok(mylist, nr_elements, data_noFirst);
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, nr_elements-1));
nr_elements--;
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
check_n_list_elements_ok(mylist, nr_elements, data_noLast);
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 1));
nr_elements--;
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
check_n_list_elements_ok(mylist, nr_elements, data_noMiddle);
}
static void test_DeleteLast_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_delete_last(NULL));
}
static void test_DeleteLast(void)
{
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
int nr_elements = sizeof(data)/sizeof(data[0]);
TEST_ASSERT_EQUAL(-1, list_delete_last(mylist));
for(int i = 0; i < nr_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
}
for (int i = nr_elements-1; i >= 0; i--)
{
TEST_ASSERT_EQUAL(0, list_delete_last(mylist));
TEST_ASSERT_EQUAL(i, list_get_nr_elements(mylist));
check_n_list_elements_ok(mylist, i, data);
}
TEST_ASSERT_NULL(mylist->head);
TEST_ASSERT_EQUAL(0, list_get_nr_elements(mylist));
}
int main(void)
{
UnityBegin();
MY_RUN_TEST(test_ConstructList);
MY_RUN_TEST(test_NrElements_parameters);
MY_RUN_TEST(test_AddData_parameters);
MY_RUN_TEST(test_AddData);
MY_RUN_TEST(test_Add2PiecesOfData);
MY_RUN_TEST(test_GetElement_parameters);
MY_RUN_TEST(test_GetElement);
MY_RUN_TEST(test_GetLast_parameters);
MY_RUN_TEST(test_GetLast);
MY_RUN_TEST(test_IndexOf_parameters);
MY_RUN_TEST(test_IndexOf);
MY_RUN_TEST(test_IndexOfSpecial_parameters);
MY_RUN_TEST(test_IndexOfSpecial);
MY_RUN_TEST(test_DeleteItem_parameters);
MY_RUN_TEST(test_DeleteItem);
MY_RUN_TEST(test_DeleteLast_parameters);
MY_RUN_TEST(test_DeleteLast);
// MY_RUN_TEST();
// MY_RUN_TEST();
// MY_RUN_TEST();
// MY_RUN_TEST();
return UnityEnd();
}

View File

@@ -0,0 +1,102 @@
*** Eindhoven ***
De Technische Universiteit Eindhoven en Fontys Hogescholen trekken veel
studenten naar Eindhoven. In de digitale stad Eindhoven en
Eindhoven.beginthier.nl vind je een bundeling van informatie over Eindhoven.
Je mag Eindhoven een echte studentenstad noemen. Studentvoorzieningen zijn
er op allerlei gebied. Hieronder vind je een aantal mogelijkheden:
Introfestival
=============
Om je kennis te laten maken met het studentenleven in Eindhoven
worden al jaren de HBO Introductiedagen (HID) georganiseerd: een
bruisend festival met veel muziek. Tijdens deze drie dwaze dagen leer
je de studentenverenigingen kennen, je gaat langs bij veel kroegen in
de stad en je ontmoet een heleboel medestudenten. Je ontvangt automatisch
bericht over de HID als je je hebt aangemeld voor een opleiding.
FEID (Fontys Eindhoven Introductie Dag) is de algemene introductiedag
van Fontys in Eindhoven waar alle studenten die gaan studeren aan een
van de opleidingen die Fontys aanbiedt, aan mee doen.
Gezelligheid
------------
Een geslaagd studentenleven kan je in Eindhoven op verschillende manier
bereiken. Op de donderdagavonden in de stad, bijvoorbeeld op uitgaansgebied
Stratumseind, bij de cultuur- en sportverenigingen, enz. De drie Eindhovense
studenten-gezelligheidsverenigingen vervullen een sleutelrol in dit geheel.
Ze hebben alledrie een eigen identiteit en unieke sfeer: het Eindhovense
Studentencorps, SSRE en Demos.
Sport
+++++
Als Fontysstudent kun je gebruik maken van alle accommodaties van het
TU-Sportcentrum op het terrein van de Technische Universiteit Eindhoven.
Als je bent ingeschreven voor een Fontysopleiding ontvang je daarover
automatisch informatie.
De Eindhovense Studenten Sport Federatie (de ESSF) is een overkoepelend
orgaan en belangenbehartiger van alle studenten sportverenigingen en
alle sportkaarthouders in Eindhoven. Heb je vragen over de sportkaart
en/of het sporten, kijk dan op de website van de ESSF.
Wat houdt Technische Informatica in?
====================================
Binnen het vakgebied Technische Informatica ben je samen met anderen bezig
om computerprogrammatuur te maken in een technische omgeving. Je doorloopt
in een aantal projecten en modulen het totale ontwikkeltraject van
softwaresystemen: van het inventariseren van wensen van toekomstige gebruikers,
via het beschrijven en realiseren van een ontwerp tot het testen en implementeren
in een werkomgeving. De opleiding besteedt uitgebreid aandacht aan embedded
systemen: software die in apparaten wordt ingebouwd. Denk maar eens aan al
die programmatuur in kopieerapparaten, liften, wasmachines en mobiele
telefoons.
Een ander aandachtsgebied is industri<72>le automatisering. Bij industri<72>le
automatisering kun je denken aan robots. Andere voorbeelden zijn:
verkeerssystemen op snelwegen en in tunnels, parkeergarages met automatische
betalingen, massafabricage in de auto- en elektronica-industrie, procesbesturing
via internet,en productinspectie met camera's en beeldbewerking. Omdat je als
ict<EFBFBD>ers, dus ook als technisch informaticus, met en voor mensen werkt, is er
ook aandacht voor communicatieve en sociale vaardigheden.
Learning Community
==================
Fontys wil een open organisatie zijn, waarin geleerd wordt in wisselwerking
met de omgeving. Leren gebeurt vooral met anderen en in steeds wisselende
groepen en situaties. Met haar studenten wil Fontys een hechte en langdurige
relatie aangaan. Ontwikkeling, competenties, vaardigheden en eigen keuzes
staan daarbij voorop.
Elke student formuleert eigen leervragen, be<62>nvloedt de eigen leerroute en
reflecteert kritisch op het eigen leerproces. Binnen de instituten worden
studenten praktijkgericht opgeleid tot professional.
Organisatie
===========
Fontys telt zo'n 33.000 studenten en 3.500 personeelsleden.
De opleidingen en diensten van Fontys Hogescholen worden verzorgd door 35
hogescholen (met eigen directies). De leiding van Fontys Hogescholen berust
bij de Raad van Bestuur, die ondersteund wordt door een Bestuursstaf. Zowel
de Raad van Bestuur als de hogescholen maken voor diverse diensten gebruik
van het Facilitair Bedrijf, dat afdelingen herbergt als ICT-Services,
Studentenvoorzieningen, Administratieve en Huishoudelijke functies.
Bron: http://www.fontys.nl
-- einde --

View File

@@ -0,0 +1,841 @@
/* ==========================================
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.h"
#include <stdio.h>
#include <string.h>
#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
/// return prematurely if we are already in failure or ignore state
#define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); }
struct _Unity Unity = { 0 };
const char* UnityStrNull = "NULL";
const char* UnityStrSpacer = ". ";
const char* UnityStrExpected = " Expected ";
const char* UnityStrWas = " Was ";
const char* UnityStrTo = " To ";
const char* UnityStrElement = " Element ";
const char* UnityStrMemory = " Memory Mismatch";
const char* UnityStrDelta = " Values Not Within Delta ";
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
//-----------------------------------------------
// Pretty Printers & Test Result Output Handlers
//-----------------------------------------------
void UnityPrint(const char* string)
{
const char* pch = string;
if (pch != NULL)
{
while (*pch)
{
// printable characters plus CR & LF are printed
if ((*pch <= 126) && (*pch >= 32))
{
UNITY_OUTPUT_CHAR(*pch);
}
//write escaped carriage returns
else if (*pch == 13)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('r');
}
//write escaped line feeds
else if (*pch == 10)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('n');
}
// unprintable characters are shown as codes
else
{
UNITY_OUTPUT_CHAR('\\');
UnityPrintNumberHex((_U_SINT)*pch, 2);
}
pch++;
}
}
}
//-----------------------------------------------
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
{
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
UnityPrintNumber(number);
}
else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
{
UnityPrintNumberUnsigned((_U_UINT)number);
}
else
{
UnityPrintNumberHex((_U_UINT)number, (style & 0x000F) << 1);
}
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumber(const _U_SINT number_to_print)
{
_U_SINT divisor = 1;
_U_SINT next_divisor;
_U_SINT number = number_to_print;
if (number < 0)
{
UNITY_OUTPUT_CHAR('-');
number = -number;
}
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumberUnsigned(const _U_UINT number)
{
_U_UINT divisor = 1;
_U_UINT next_divisor;
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
}
//-----------------------------------------------
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
{
_U_UINT nibble;
char nibbles = nibbles_to_print;
UNITY_OUTPUT_CHAR('0');
UNITY_OUTPUT_CHAR('x');
while (nibbles > 0)
{
nibble = (number >> (--nibbles << 2)) & 0x0000000F;
if (nibble <= 9)
{
UNITY_OUTPUT_CHAR((char)('0' + nibble));
}
else
{
UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
}
}
}
//-----------------------------------------------
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
{
_U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
_US32 i;
for (i = 0; i < UNITY_INT_WIDTH; i++)
{
if (current_bit & mask)
{
if (current_bit & number)
{
UNITY_OUTPUT_CHAR('1');
}
else
{
UNITY_OUTPUT_CHAR('0');
}
}
else
{
UNITY_OUTPUT_CHAR('X');
}
current_bit = current_bit >> 1;
}
}
//-----------------------------------------------
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(_UF number)
{
char TempBuffer[32];
sprintf(TempBuffer, "%.6f", number);
UnityPrint(TempBuffer);
}
#endif
//-----------------------------------------------
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
{
UnityPrint(file);
UNITY_OUTPUT_CHAR(':');
UnityPrintNumber(line);
UNITY_OUTPUT_CHAR(':');
UnityPrint(Unity.CurrentTestName);
UNITY_OUTPUT_CHAR(':');
}
//-----------------------------------------------
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
{
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("FAIL:");
}
//-----------------------------------------------
void UnityConcludeTest(void)
{
if (Unity.CurrentTestIgnored)
{
Unity.TestIgnores++;
}
else if (!Unity.CurrentTestFailed)
{
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
UnityPrint("PASS");
UNITY_PRINT_EOL;
}
else
{
Unity.TestFailures++;
}
Unity.CurrentTestFailed = 0;
Unity.CurrentTestIgnored = 0;
}
//-----------------------------------------------
void UnityAddMsgIfSpecified(const char* msg)
{
if (msg)
{
UnityPrint(UnityStrSpacer);
UnityPrint(msg);
}
}
//-----------------------------------------------
void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
{
UnityPrint(UnityStrExpected);
if (expected != NULL)
{
UNITY_OUTPUT_CHAR('\'');
UnityPrint(expected);
UNITY_OUTPUT_CHAR('\'');
}
else
{
UnityPrint(UnityStrNull);
}
UnityPrint(UnityStrWas);
if (actual != NULL)
{
UNITY_OUTPUT_CHAR('\'');
UnityPrint(actual);
UNITY_OUTPUT_CHAR('\'');
}
else
{
UnityPrint(UnityStrNull);
}
}
//-----------------------------------------------
// Assertion & Control Helpers
//-----------------------------------------------
int UnityCheckArraysForNull(const void* expected, const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
{
//return true if they are both NULL
if ((expected == NULL) && (actual == NULL))
return 1;
//throw error if just expected is NULL
if (expected == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForExpected);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
//throw error if just actual is NULL
if (actual == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForActual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
//return false if neither is NULL
return 0;
}
//-----------------------------------------------
// Assertion Functions
//-----------------------------------------------
void UnityAssertBits(const _U_SINT mask,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if ((mask & expected) != (mask & actual))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintMask(mask, expected);
UnityPrint(UnityStrWas);
UnityPrintMask(mask, actual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualNumber(const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
UNITY_SKIP_EXECUTION;
if (expected != actual)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualIntArray(const _U_SINT* expected,
const _U_SINT* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
_UU32 elements = num_elements;
const _US8* ptr_exp = (_US8*)expected;
const _US8* ptr_act = (_US8*)actual;
UNITY_SKIP_EXECUTION;
if (elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
switch(style)
{
case UNITY_DISPLAY_STYLE_HEX8:
case UNITY_DISPLAY_STYLE_INT8:
case UNITY_DISPLAY_STYLE_UINT8:
while (elements--)
{
if (*ptr_exp != *ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 1;
ptr_act += 1;
}
break;
case UNITY_DISPLAY_STYLE_HEX16:
case UNITY_DISPLAY_STYLE_INT16:
case UNITY_DISPLAY_STYLE_UINT16:
while (elements--)
{
if (*(_US16*)ptr_exp != *(_US16*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US16*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US16*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 2;
ptr_act += 2;
}
break;
#ifdef UNITY_SUPPORT_64
case UNITY_DISPLAY_STYLE_HEX64:
case UNITY_DISPLAY_STYLE_INT64:
case UNITY_DISPLAY_STYLE_UINT64:
while (elements--)
{
if (*(_US64*)ptr_exp != *(_US64*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US64*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US64*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 8;
ptr_act += 8;
}
break;
#endif
default:
while (elements--)
{
if (*(_US32*)ptr_exp != *(_US32*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US32*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US32*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 4;
ptr_act += 4;
}
break;
}
}
//-----------------------------------------------
#ifndef UNITY_EXCLUDE_FLOAT
void UnityAssertEqualFloatArray(const _UF* expected,
const _UF* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 elements = num_elements;
const _UF* ptr_expected = expected;
const _UF* ptr_actual = actual;
_UF diff, tol;
UNITY_SKIP_EXECUTION;
if (elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
while (elements--)
{
diff = *ptr_expected - *ptr_actual;
if (diff < 0.0)
diff = 0.0 - diff;
tol = UNITY_FLOAT_PRECISION * *ptr_expected;
if (tol < 0.0)
tol = 0.0 - tol;
if (diff > tol)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrintFloat(*ptr_expected);
UnityPrint(UnityStrWas);
UnityPrintFloat(*ptr_actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_expected++;
ptr_actual++;
}
}
//-----------------------------------------------
void UnityAssertFloatsWithin(const _UF delta,
const _UF expected,
const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UF diff = actual - expected;
_UF pos_delta = delta;
UNITY_SKIP_EXECUTION;
if (diff < 0)
{
diff = 0.0f - diff;
}
if (pos_delta < 0)
{
pos_delta = 0.0f - pos_delta;
}
if (pos_delta < diff)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrintFloat(expected);
UnityPrint(UnityStrWas);
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
#endif
//-----------------------------------------------
void UnityAssertNumbersWithin( const _U_SINT delta,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
UNITY_SKIP_EXECUTION;
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
if (actual > expected)
Unity.CurrentTestFailed = ((actual - expected) > delta);
else
Unity.CurrentTestFailed = ((expected - actual) > delta);
}
else
{
if ((_U_UINT)actual > (_U_UINT)expected)
Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
else
Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrDelta);
UnityPrintNumberByStyle(delta, style);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 i;
UNITY_SKIP_EXECUTION;
// if both pointers not null compare the strings
if (expected && actual)
{
for (i = 0; expected[i] || actual[i]; i++)
{
if (expected[i] != actual[i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected != actual)
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrintExpectedAndActualStrings(expected, actual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualStringArray( const char** expected,
const char** actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 i, j = 0;
UNITY_SKIP_EXECUTION;
// if no elements, it's an error
if (num_elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
do
{
// if both pointers not null compare the strings
if (expected[j] && actual[j])
{
for (i = 0; expected[j][i] || actual[j][i]; i++)
{
if (expected[j][i] != actual[j][i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected[j] != actual[j])
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT);
}
UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
} while (++j < num_elements);
}
//-----------------------------------------------
void UnityAssertEqualMemory( const void* expected,
const void* actual,
_UU32 length,
_UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
unsigned char* expected_ptr = (unsigned char*)expected;
unsigned char* actual_ptr = (unsigned char*)actual;
_UU32 elements = num_elements;
UNITY_SKIP_EXECUTION;
if ((elements == 0) || (length == 0))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
while (elements--)
{
if (memcmp((const void*)expected_ptr, (const void*)actual_ptr, length) != 0)
{
Unity.CurrentTestFailed = 1;
break;
}
expected_ptr += length;
actual_ptr += length;
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
}
UnityPrint(UnityStrMemory);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
// Control Functions
//-----------------------------------------------
void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
{
UNITY_SKIP_EXECUTION;
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("FAIL");
if (msg != NULL)
{
UNITY_OUTPUT_CHAR(':');
if (msg[0] != ' ')
{
UNITY_OUTPUT_CHAR(' ');
}
UnityPrint(msg);
}
UNITY_FAIL_AND_BAIL;
}
//-----------------------------------------------
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
{
UNITY_SKIP_EXECUTION;
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("IGNORE");
if (msg != NULL)
{
UNITY_OUTPUT_CHAR(':');
UNITY_OUTPUT_CHAR(' ');
UnityPrint(msg);
}
UNITY_IGNORE_AND_BAIL;
}
//-----------------------------------------------
void setUp(void);
void tearDown(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
Unity.CurrentTestName = FuncName;
Unity.CurrentTestLineNumber = FuncLineNum;
Unity.NumberOfTests++;
if (TEST_PROTECT())
{
setUp();
Func();
}
if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
{
tearDown();
}
UnityConcludeTest();
}
//-----------------------------------------------
void UnityBegin(void)
{
Unity.NumberOfTests = 0;
}
//-----------------------------------------------
int UnityEnd(void)
{
UnityPrint("-----------------------");
UNITY_PRINT_EOL;
UnityPrintNumber(Unity.NumberOfTests);
UnityPrint(" Tests ");
UnityPrintNumber(Unity.TestFailures);
UnityPrint(" Failures ");
UnityPrintNumber(Unity.TestIgnores);
UnityPrint(" Ignored");
UNITY_PRINT_EOL;
if (Unity.TestFailures == 0U)
{
UnityPrint("OK");
}
else
{
UnityPrint("FAIL");
}
UNITY_PRINT_EOL;
return Unity.TestFailures;
}

View File

@@ -0,0 +1,209 @@
/* ==========================================
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 UNITY_FRAMEWORK_H
#define UNITY_FRAMEWORK_H
#define UNITY
#include "unity_internals.h"
//-------------------------------------------------------
// Configuration Options
//-------------------------------------------------------
// Integers
// - Unity assumes 32 bit integers by default
// - If your compiler treats ints of a different size, define UNITY_INT_WIDTH
// Floats
// - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
// - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
// - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
// - define UNITY_FLOAT_VERBOSE to print floating point values in errors (uses sprintf)
// Output
// - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
// Optimization
// - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge
// - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests.
//-------------------------------------------------------
// Test Running Macros
//-------------------------------------------------------
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
#ifndef RUN_TEST
#define RUN_TEST(func, line_num) UnityDefaultTestRun(func, #func, line_num)
#endif
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
#define TEST_CASE(...)
//-------------------------------------------------------
// Basic Fail and Ignore
//-------------------------------------------------------
#define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, message)
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, message)
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
#define TEST_ONLY()
//-------------------------------------------------------
// Test Asserts (simple)
//-------------------------------------------------------
//Boolean
#define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE")
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE")
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE")
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL")
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL")
//Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal")
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, NULL)
//Integer Ranges (of all sizes)
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, NULL)
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, NULL)
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, NULL)
//Floating Point (If Enabled)
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
//-------------------------------------------------------
// Test Asserts (with additional messages)
//-------------------------------------------------------
//Boolean
#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, message)
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, message)
//Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, message)
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, message)
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, message)
//Integer Ranges (of all sizes)
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, message)
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, message)
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_STRING_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, message)
//Floating Point (If Enabled)
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message)
#endif

View File

@@ -0,0 +1,356 @@
/* ==========================================
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 UNITY_INTERNALS_H
#define UNITY_INTERNALS_H
#include <stdio.h>
#include <setjmp.h>
//-------------------------------------------------------
// Int Support
//-------------------------------------------------------
#ifndef UNITY_INT_WIDTH
#define UNITY_INT_WIDTH (32)
#endif
#ifndef UNITY_LONG_WIDTH
#define UNITY_LONG_WIDTH (32)
#endif
#if (UNITY_INT_WIDTH == 32)
typedef unsigned char _UU8;
typedef unsigned short _UU16;
typedef unsigned int _UU32;
typedef signed char _US8;
typedef signed short _US16;
typedef signed int _US32;
#elif (UNITY_INT_WIDTH == 16)
typedef unsigned char _UU8;
typedef unsigned int _UU16;
typedef unsigned long _UU32;
typedef signed char _US8;
typedef signed int _US16;
typedef signed long _US32;
#else
#error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported)
#endif
//-------------------------------------------------------
// 64-bit Support
//-------------------------------------------------------
#ifndef UNITY_SUPPORT_64
//No 64-bit Support
typedef _UU32 _U_UINT;
typedef _US32 _U_SINT;
#else
//64-bit Support
#if (UNITY_LONG_WIDTH == 32)
typedef unsigned long long _UU64;
typedef signed long long _US64;
#elif (UNITY_LONG_WIDTH == 64)
typedef unsigned long _UU64;
typedef signed long _US64;
#else
#error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported)
#endif
typedef _UU64 _U_UINT;
typedef _US64 _U_SINT;
#endif
//-------------------------------------------------------
// Pointer Support
//-------------------------------------------------------
#ifndef UNITY_POINTER_WIDTH
#define UNITY_POINTER_WIDTH (32)
#endif
#if (UNITY_POINTER_WIDTH == 32)
typedef _UU32 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32
#elif (UNITY_POINTER_WIDTH == 64)
typedef _UU64 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64
#elif (UNITY_POINTER_WIDTH == 16)
typedef _UU16 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16
#else
#error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported)
#endif
//-------------------------------------------------------
// Float Support
//-------------------------------------------------------
#ifdef UNITY_EXCLUDE_FLOAT
//No Floating Point Support
#undef UNITY_FLOAT_PRECISION
#undef UNITY_FLOAT_TYPE
#undef UNITY_FLOAT_VERBOSE
#else
//Floating Point Support
#ifndef UNITY_FLOAT_PRECISION
#define UNITY_FLOAT_PRECISION (0.00001f)
#endif
#ifndef UNITY_FLOAT_TYPE
#define UNITY_FLOAT_TYPE float
#endif
typedef UNITY_FLOAT_TYPE _UF;
#endif
//-------------------------------------------------------
// Output Method
//-------------------------------------------------------
#ifndef UNITY_OUTPUT_CHAR
//Default to using putchar, which is defined in stdio.h above
#define UNITY_OUTPUT_CHAR(a) putchar(a)
#else
//If defined as something else, make sure we declare it here so it's ready for use
extern int UNITY_OUTPUT_CHAR(int);
#endif
//-------------------------------------------------------
// Footprint
//-------------------------------------------------------
#ifndef UNITY_LINE_TYPE
#define UNITY_LINE_TYPE unsigned short
#endif
#ifndef UNITY_COUNTER_TYPE
#define UNITY_COUNTER_TYPE unsigned short
#endif
//-------------------------------------------------------
// Internal Structs Needed
//-------------------------------------------------------
typedef void (*UnityTestFunction)(void);
#define UNITY_DISPLAY_RANGE_INT (0x10)
#define UNITY_DISPLAY_RANGE_UINT (0x20)
#define UNITY_DISPLAY_RANGE_HEX (0x40)
#define UNITY_DISPLAY_RANGE_AUTO (0x80)
typedef enum
{
UNITY_DISPLAY_STYLE_INT = 4 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO,
UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT,
UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT,
UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT,
#endif
UNITY_DISPLAY_STYLE_UINT = 4 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO,
UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT,
UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT,
UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT,
#endif
UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX,
UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX,
UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX,
#endif
} UNITY_DISPLAY_STYLE_T;
struct _Unity
{
const char* TestFile;
const char* CurrentTestName;
_UU32 CurrentTestLineNumber;
UNITY_COUNTER_TYPE NumberOfTests;
UNITY_COUNTER_TYPE TestFailures;
UNITY_COUNTER_TYPE TestIgnores;
UNITY_COUNTER_TYPE CurrentTestFailed;
UNITY_COUNTER_TYPE CurrentTestIgnored;
jmp_buf AbortFrame;
};
extern struct _Unity Unity;
//-------------------------------------------------------
// Test Suite Management
//-------------------------------------------------------
void UnityBegin(void);
int UnityEnd(void);
void UnityConcludeTest(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
//-------------------------------------------------------
// Test Output
//-------------------------------------------------------
void UnityPrint(const char* string);
void UnityPrintMask(const _U_UINT mask, const _U_UINT number);
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style);
void UnityPrintNumber(const _U_SINT number);
void UnityPrintNumberUnsigned(const _U_UINT number);
void UnityPrintNumberHex(const _U_UINT number, const char nibbles);
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(const _UF number);
#endif
//-------------------------------------------------------
// Test Assertion Fuctions
//-------------------------------------------------------
// Use the macros below this section instead of calling
// these directly. The macros have a consistent naming
// convention and will pull in file and line information
// for you.
void UnityAssertEqualNumber(const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertEqualIntArray(const _U_SINT* expected,
const _U_SINT* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertBits(const _U_SINT mask,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualStringArray( const char** expected,
const char** actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualMemory( const void* expected,
const void* actual,
const _UU32 length,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertNumbersWithin(const _U_SINT delta,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
#ifndef UNITY_EXCLUDE_FLOAT
void UnityAssertFloatsWithin(const _UF delta,
const _UF expected,
const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualFloatArray(const _UF* expected,
const _UF* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
#endif
//-------------------------------------------------------
// Basic Fail and Ignore
//-------------------------------------------------------
#define UNITY_TEST_FAIL(line, message) UnityFail( (message), (UNITY_LINE_TYPE)line);
#define UNITY_TEST_IGNORE(line, message) UnityIgnore( (message), (UNITY_LINE_TYPE)line);
//-------------------------------------------------------
// Test Asserts
//-------------------------------------------------------
#define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, message);}
#define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((_U_SINT)(mask), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER)
#define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT8)
#define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT16)
#define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT32)
#define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT8)
#define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT16)
#define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT32)
#define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((const char**)(expected), (const char**)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#ifdef UNITY_SUPPORT_64
#define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
#define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
#define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#endif
#ifdef UNITY_EXCLUDE_FLOAT
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#else
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#endif
#endif

View File

@@ -0,0 +1,97 @@
#include "unity_test_module.h"
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "unity.h"
void (*unity_setUp_ptr)(void) = NULL;
void (*unit_tearDown_ptr)(void) = NULL;
#ifdef UNITY_USE_MODULE_SETUP_TEARDOWN
void setUp()
{
if(unity_setUp_ptr != NULL) unity_setUp_ptr();
}
void tearDown()
{
if(unit_tearDown_ptr != NULL) unit_tearDown_ptr();
}
#endif
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) )
{
unity_setUp_ptr = setUp;
unit_tearDown_ptr = tearDown;
}
void UnityUnregisterSetupTearDown(void)
{
unity_setUp_ptr = NULL;
unit_tearDown_ptr = NULL;
}
UnityTestModule* UnityTestModuleFind(
UnityTestModule* modules,
size_t number_of_modules,
char* wantedModule)
{
for(size_t i = 0; i < number_of_modules; i++) {
if(strcmp(wantedModule, modules[i].name) == 0) {
return &modules[i];
}
}
return NULL;
}
void UnityTestModuleRunRequestedModules(
int number_of_requested_modules,
char* requested_modules_names[],
UnityTestModule* allModules,
size_t number_of_modules )
{
for(int i = 0; i < number_of_requested_modules; i++)
{
UnityTestModule* module = UnityTestModuleFind(allModules,
number_of_modules, requested_modules_names[i]);
if(module != NULL)
{
module->run_tests();
}
else
{
printf("Ignoring: could not find requested module: %s\n",
requested_modules_names[i]);
}
}
}
int UnityTestModuleRun(
int argc,
char * argv[],
UnityTestModule* allModules,
size_t number_of_modules)
{
UnityBegin();
bool moduleRequests = (argc > 1);
if(moduleRequests)
{
UnityTestModuleRunRequestedModules(argc-1, &argv[1],
allModules, number_of_modules);
}
else
{
for(int i = 0; i < number_of_modules; i++)
{
allModules[i].run_tests();
}
}
return UnityEnd();
}

View File

@@ -0,0 +1,31 @@
#ifndef UNITY_TEST_MODULE_H
#define UNITY_TEST_MODULE_H
#include <stddef.h>
typedef struct {
char name[24];
void(*run_tests)(void);
} UnityTestModule;
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) );
void UnityUnregisterSetupTearDown(void);
UnityTestModule* UnityTestModuleFind(
UnityTestModule* modules,
size_t number_of_modules,
char* wantedModule);
void UnityTestModuleRunRequestedModules(
int number_of_requested_modules,
char* requested_modules_names[],
UnityTestModule* allModules,
size_t number_of_modules );
int UnityTestModuleRun(
int argc,
char * argv[],
UnityTestModule* allModules,
size_t number_of_modules);
#endif

View File

@@ -0,0 +1,43 @@
/*
* bmp.h
*
* Created on: Feb 23, 2012
* Author: student
*/
#ifndef BMP_H_
#define BMP_H_
#include <stdint.h>
// datatypes obtained from http://en.wikipedia.org/wiki/BMP_file_format
typedef struct
{
uint8_t magic[2];
} __attribute__ (( packed )) BMP_MAGIC_t;
typedef struct
{
uint32_t filesz;
uint16_t creator1;
uint16_t creator2;
uint32_t bmp_offset;
} __attribute__ (( packed )) BMP_FILE_t;
typedef struct
{
uint32_t header_sz;
int32_t width;
int32_t height;
uint16_t nplanes;
uint16_t bitspp;
uint32_t compress_type;
uint32_t bmp_bytesz;
int32_t hres;
int32_t vres;
uint32_t ncolors;
uint32_t nimpcolors;
} __attribute__ (( packed )) BMP_INFO_t;
#endif /* BMP_H_ */

View File

@@ -0,0 +1,6 @@
{
"challenge":{
"level":["shows"] ,
"durationHours": 8
}
}

View File

@@ -0,0 +1,168 @@
/*
* stegano.c
*
* Created on: Nov 6, 2011
* Author: J. Geurts
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bmp.h"
#include "resource_detector.h"
#include "stegano.h"
#define MAX_FILENAME 80
extern uint8_t SteganoGetSubstring(
uint8_t Src, uint8_t SrcPos, uint8_t NrOfBits, uint8_t DestPos)
/* description: get a substring of bits from a uint8_t (i.e. a byte)
*
* example: SteganoGetSubstring (Src, 3, 4, 1) with Src=ABCDEFGH (bit H is LSB)
* = 000BCDE0
*
* parameters:
* Src: byte to get the substring from
* SrcPos: position of the first bit of the substring (LSB=0)
* NrOfBits: length of the substring
* DestPos: position of the first bits of the destination substring
*
* return:
* substring, starting at DestPos
*/
{
// to be implemented
return 0;
}
// should be static in real life, but would give a compiling error in the
// unchanged code because this function is not yet used
static void ReadHdr(
FILE* FilePtr, BMP_MAGIC_t* Magic, BMP_FILE_t* File,
BMP_INFO_t* Info)
/*
* description: read the header of a bmp File, and store the data in the
* provided parameters
*
* parameters:
* FilePtr: file, opened for reading
* Magic: output-parameter to store the read BMP_MAGIC_t structure
* File: output-parameter to store the read BMP_FILE_t structure
* Info: output-parameter to store the read BMP_INFO_t structure
*
* Note: caller should provide enough memory for parameters 'Magic', 'File' and
* 'Info'
*/
{
// to be implemented
}
// should be static in real life, but would give a compiling error in the
// unchanged code because this function is not yet used
static void WriteHdr(
FILE* FilePtr, BMP_MAGIC_t* Magic, BMP_FILE_t* File,
BMP_INFO_t* Info)
/*
* description: write the header of a bmp File, where the data comes from the
* provided parameters
*
* parameters:
* FilePtr: file, opened for writing
* Magic: input-parameter with a BMP_MAGIC_t structure
* File: input-parameter with a BMP_FILE_t structure
* Info: input-parameter with a BMP_INFO_t structure
*
*/
{
// to be implemented
}
extern void SteganoMultiplex(const char* File0, const char* File1)
{
FILE* FilePtr0 = NULL;
FILE* FilePtr1 = NULL;
FILE* FilePtr2 = NULL;
char buf[MAX_FILENAME];
for (int NrBits = 0; NrBits <= 8; NrBits++)
{
// NrBits: number of bits for the hidden image
sprintf(buf, "mux_%s_%s_%d.bmp", File0, File1, NrBits);
FilePtr0 = fopen(File0, "rb");
FilePtr1 = fopen(File1, "rb");
FilePtr2 = fopen(buf, "wb");
// to be implemented
fclose(FilePtr0);
fclose(FilePtr1);
fclose(FilePtr2);
}
}
extern void SteganoMultiplexText(const char* File0, const char* File1)
{
FILE* FilePtr0 = NULL;
FILE* FilePtr1 = NULL;
FILE* FilePtr2 = NULL;
char buf[MAX_FILENAME];
sprintf(buf, "mux_%s_%s.bmp", File0, File1);
FilePtr0 = fopen(File0, "rb");
FilePtr1 = fopen(File1, "rb");
FilePtr2 = fopen(buf, "wb");
// to be implemented
fclose(FilePtr0);
fclose(FilePtr1);
fclose(FilePtr2);
}
extern void
SteganoDemultiplex(const char* File0, const char* File1, const char* File2)
{
FILE* FilePtr0 = NULL;
FILE* FilePtr1 = NULL;
FILE* FilePtr2 = NULL;
FilePtr0 = fopen(File0, "rb");
FilePtr1 = fopen(File1, "wb");
FilePtr2 = fopen(File2, "wb");
// to be implemented
fclose(FilePtr0);
fclose(FilePtr1);
fclose(FilePtr2);
}
extern void
SteganoDemultiplexText(const char* File0, const char* File1, const char* File2)
{
FILE* FilePtr0 = NULL;
FILE* FilePtr1 = NULL;
FILE* FilePtr2 = NULL;
FilePtr0 = fopen(File0, "rb"); /* binair lezen */
FilePtr1 = fopen(File1, "wb"); /* binair schrijven */
FilePtr2 = fopen(File2, "wb"); /* binair schrijven */
// to be implemented
fclose(FilePtr0);
fclose(FilePtr1);
fclose(FilePtr2);
}

View File

@@ -0,0 +1,23 @@
/*
* stegano.h
*
* Created on: Nov 6, 2011
* Author: J. Geurts
*/
#ifndef STEGANO_H_
#define STEGANO_H_
#include <stdint.h>
extern uint8_t SteganoGetSubstring(
uint8_t src, uint8_t src_pos, uint8_t nrof_bits, uint8_t dest_pos);
extern void SteganoMultiplex(const char* File0, const char* File1);
extern void SteganoMultiplexText(const char* File0, const char* File1);
extern void SteganoDemultiplex(
const char* File0, const char* File1, const char* File2);
extern void SteganoDemultiplexText(
const char* File0, const char* File1, const char* File2);
#endif

View File

@@ -0,0 +1,128 @@
/*
* main.c
*
* Created on: Nov 6, 2011
* Author: student
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "bmp.h"
#include "resource_detector.h"
#include "stegano.h"
#define MAX_STRLEN 80
static bool WithMenu = true;
static int GetInt(const char* Message)
{
char Line[MAX_STRLEN];
char* Result = NULL;
int Value = -1;
if (WithMenu)
{
printf("%s", Message);
}
Result = fgets(Line, sizeof(Line), stdin);
if (Result != NULL)
{
sscanf(Result, "%d", &Value);
}
return Value;
}
static void GetStr(const char* Message, char* Str)
{
char Line[MAX_STRLEN];
char* Result = NULL;
if (WithMenu)
{
printf("%s", Message);
}
Result = fgets(Line, sizeof(Line), stdin);
if (Result != NULL)
{
sscanf(Result, "%s", Str);
}
}
extern int main(int argc, char* argv[])
{
char File0[MAX_STRLEN];
char File1[MAX_STRLEN];
char File2[MAX_STRLEN];
int Choice;
bool Quit = false;
printf("PRC assignment 'SteganoC' (version 2)\n"
"-------------------------------------\n");
if (argc != 1)
{
fprintf(stderr, "%s: argc=%d\n", argv[0], argc);
}
while (!Quit)
{
if (WithMenu)
{
printf("\n\nMENU\n"
"===================\n"
"[1] multiplex\n"
"[2] multiplex text\n"
"[3] demultiplex\n"
"[4] demultiplex text\n"
"[8] show/hide menu\n"
"[9] Quit\n");
}
Choice = GetInt("Choice: ");
switch (Choice)
{
case 1:
GetStr("enter input file (visible): ", File0);
GetStr("enter input file (hidden): ", File1);
SteganoMultiplex(File0, File1);
break;
case 2:
GetStr("enter input file (visible): ", File0);
GetStr("enter input file (text): ", File1);
SteganoMultiplexText(File0, File1);
break;
case 3:
GetStr("enter input file: ", File0);
GetStr("enter output file (visible): ", File1);
GetStr("enter output file (hidden): ", File2);
SteganoDemultiplex(File0, File1, File2);
break;
case 4:
GetStr("enter input file: ", File0);
GetStr("enter output file (visible): ", File1);
GetStr("enter output file (text): ", File2);
SteganoDemultiplexText(File0, File1, File2);
break;
case 8:
if (WithMenu)
{
printf("printing of MENU is disabled\n");
}
WithMenu = !WithMenu;
break;
case 9:
Quit = true;
break;
default:
printf("ERROR: invalid Choice: %d\n", Choice);
break;
}
}
return (0);
}

View File

@@ -0,0 +1,435 @@
/* auteur : F.J. Hurkmans
* datum : November 4th 2013
* code : Ansi C
* versie : 1
*/
#include "bmp.h"
#include "stegano.h"
#include "unity.h"
#include <limits.h>
#include <stdlib.h>
#include <time.h>
#include "resource_detector.h"
// I rather dislike keeping line numbers updated, so I made my own macro to
// ditch the line number
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
void setUp(void)
{
// This is run before EACH test
}
void tearDown(void)
{
// This is run after EACH test
const char* FilenamesToDeleteAfterTest[] = {
"demux_ImageCitroen2Cv.bmp",
"demux_TextFontys.txt",
"demux_ImageRedFerrari_0.bmp",
"demux_ImageRedFerrari_1.bmp",
"demux_ImageRedFerrari_4.bmp",
"demux_ImageRedFerrari_7.bmp",
"demux_ImageRedFerrari_8.bmp",
"demux_ImageTrabant_0.bmp",
"demux_ImageTrabant_1.bmp",
"demux_ImageTrabant_4.bmp",
"demux_ImageTrabant_7.bmp",
"demux_ImageTrabant_8.bmp",
"mux_ImageCitroen2Cv.bmp_TextFontys.txt.bmp",
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp.bmp",
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_0.bmp",
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_1.bmp",
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_2.bmp",
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_3.bmp",
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_4.bmp",
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_5.bmp",
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_6.bmp",
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_7.bmp",
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_8.bmp"
};
for (size_t i = 0; i < (sizeof(FilenamesToDeleteAfterTest) /
sizeof(FilenamesToDeleteAfterTest[0]));
i++)
{
remove(FilenamesToDeleteAfterTest[i]);
}
}
static int GetFileSize(FILE* FilePtr)
{
int CurrPos = ftell(FilePtr);
int EndPos = 0;
TEST_ASSERT_EQUAL(0, fseek(FilePtr, 0L, SEEK_END));
EndPos = ftell(FilePtr);
TEST_ASSERT_EQUAL(0, fseek(FilePtr, CurrPos, SEEK_SET));
return EndPos;
}
static void Assert2FilesEqual(char* File1, char* File2)
{
const size_t BufferSize = 4096;
FILE* File1Ptr = fopen(File1, "rb");
TEST_ASSERT_NOT_NULL(File1Ptr);
FILE* File2Ptr = fopen(File2, "rb");
TEST_ASSERT_NOT_NULL(File2Ptr);
int File1Size = GetFileSize(File1Ptr);
int File2Size = GetFileSize(File2Ptr);
TEST_ASSERT_EQUAL(File1Size, File2Size);
char* File1Buffer = malloc(BufferSize);
TEST_ASSERT_NOT_NULL(File1Buffer);
char* File2Buffer = malloc(BufferSize);
TEST_ASSERT_NOT_NULL(File2Buffer);
size_t File1Read = 0;
size_t File2Read = 0;
do
{
File1Read = fread(File1Buffer, 1, BufferSize, File1Ptr);
File2Read = fread(File2Buffer, 1, BufferSize, File2Ptr);
TEST_ASSERT_EQUAL(File1Read, File2Read);
if (File1Read > 0)
{
TEST_ASSERT_EQUAL_INT8_ARRAY(File1Buffer, File2Buffer, File1Read);
}
} while ((File1Read > 0) && (File2Read > 0));
free(File1Buffer);
free(File2Buffer);
fclose(File1Ptr);
fclose(File2Ptr);
}
static void
CheckBmp(char* Filename, const uint32_t* CorrectHeader,
const uint8_t* FirstPixels, const uint8_t* LastPixels)
{
const int NrHeaderInts = 13;
const int NrPixels = 8;
const int BytesPerPixel = 3;
char message[300];
sprintf(message, "CheckBmp on filename: %s", Filename);
FILE* FilePtr = NULL;
uint32_t Header[NrHeaderInts];
uint8_t PixelData[NrPixels * BytesPerPixel];
int Result = 0;
FilePtr = fopen(Filename, "rb");
TEST_ASSERT_NOT_NULL(FilePtr);
fseek(FilePtr, 0x02, SEEK_SET);// skip 'BM' magic
TEST_ASSERT_EQUAL_MESSAGE(
NrHeaderInts,
fread(&Header, sizeof(Header[0]), NrHeaderInts, FilePtr),
message);
TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(
CorrectHeader, Header, NrHeaderInts, message);
fseek(FilePtr,
sizeof(BMP_MAGIC_t) + sizeof(BMP_FILE_t) + sizeof(BMP_INFO_t),
SEEK_SET);
Result = fread(PixelData, sizeof(PixelData[0]), NrPixels * BytesPerPixel,
FilePtr);
TEST_ASSERT_EQUAL_MESSAGE(NrPixels * BytesPerPixel, Result, message);
TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(
FirstPixels, PixelData, NrPixels * BytesPerPixel, message);
fseek(FilePtr, -1 * NrPixels * BytesPerPixel, SEEK_END);
Result = fread(PixelData, sizeof(PixelData[0]), NrPixels * BytesPerPixel,
FilePtr);
TEST_ASSERT_EQUAL_MESSAGE(NrPixels * BytesPerPixel, Result, message);
TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(
LastPixels, PixelData, NrPixels * BytesPerPixel, message);
fclose(FilePtr);
}
static void test_GetSubstring(void)
{
const uint8_t TestData[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08,
0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08,
0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
0x40, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08,
0x10, 0x20, 0x40, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x03, 0x06,
0x0c, 0x18, 0x30, 0x60, 0xc0, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x02,
0x04, 0x08, 0x10, 0x20, 0x40, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x02,
0x04, 0x08, 0x10, 0x20, 0x40, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x06,
0x0c, 0x18, 0x30, 0x60, 0xc0, 0x04, 0x08, 0x10, 0x20, 0x40, 0x0a, 0x14,
0x28, 0x50, 0xa0, 0x05, 0x0a, 0x14, 0x28, 0x50, 0x0a, 0x14, 0x28, 0x50,
0xa0, 0x0d, 0x1a, 0x34, 0x68, 0xd0, 0x14, 0x28, 0x50, 0xa0, 0x0a, 0x14,
0x28, 0x50, 0x15, 0x2a, 0x54, 0xa8, 0x1a, 0x34, 0x68, 0xd0, 0x14, 0x28,
0x50, 0x2a, 0x54, 0xa8, 0x35, 0x6a, 0xd4, 0x54, 0xa8, 0x6a, 0xd4
};
uint8_t Src = 0xd4;
uint8_t SrcPos;
uint8_t NrBits;
uint8_t DestPos;
int TestDataIndex = 0;
for (int j = 1; j < 8; j++)
{
for (int i = 0; i < 8; i++)
{
for (int k = 0; k < 8; k++)
{
if ((i + j <= 8) && (k + j <= 8))
{
SrcPos = i;
NrBits = j;
DestPos = k;
char message[80];
sprintf(message, "SrcPos: %i, NrBits: %i, DestPos: %i",
SrcPos, NrBits, DestPos);
TEST_ASSERT_EQUAL_HEX8_MESSAGE(
TestData[TestDataIndex++],
SteganoGetSubstring(
Src, SrcPos, NrBits, DestPos),
message);
}
}
}
}
}
static void test_MultiplexTwoImages(void)
{
const char* File1 = "ImageTrabant.bmp";
const char* File2 = "ImageRedFerrari.bmp";
SteganoMultiplex(File1, File2);
uint32_t CorrectHeader0[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280,
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
0xec4, 0x0, 0x0 };
uint8_t CorrectFirstBytes0[] = { 0x58, 0x5d, 0x5e, 0x4e, 0x53, 0x54,
0x4e, 0x53, 0x54, 0x58, 0x5d, 0x5e,
0x57, 0x5c, 0x5d, 0x4d, 0x52, 0x53,
0x4d, 0x52, 0x55, 0x57, 0x5c, 0x5f };
uint8_t CorrectLastBytes0[] = { 0x11, 0x58, 0x48, 0x11, 0x5a, 0x4a,
0x13, 0x5b, 0x4e, 0x1b, 0x63, 0x56,
0x22, 0x67, 0x5c, 0x17, 0x5c, 0x51,
0x11, 0x54, 0x4b, 0x19, 0x5c, 0x53 };
CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_0.bmp", CorrectHeader0,
CorrectFirstBytes0, CorrectLastBytes0);
uint32_t CorrectHeader1[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280,
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
0xec4, 0x0, 0x1 };
uint8_t CorrectFirstBytes1[] = { 0x59, 0x5d, 0x5f, 0x4f, 0x53, 0x55,
0x4f, 0x53, 0x55, 0x59, 0x5d, 0x5f,
0x57, 0x5d, 0x5d, 0x4d, 0x53, 0x53,
0x4d, 0x53, 0x55, 0x57, 0x5d, 0x5f };
uint8_t CorrectLastBytes1[] = { 0x10, 0x58, 0x48, 0x10, 0x5a, 0x4a,
0x12, 0x5a, 0x4e, 0x1a, 0x62, 0x56,
0x22, 0x66, 0x5c, 0x16, 0x5c, 0x50,
0x10, 0x54, 0x4a, 0x18, 0x5c, 0x52 };
CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_1.bmp", CorrectHeader1,
CorrectFirstBytes1, CorrectLastBytes1);
uint32_t CorrectHeader4[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280,
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
0xec4, 0x0, 0x4 };
uint8_t CorrectFirstBytes4[] = { 0x5d, 0x5d, 0x5d, 0x4d, 0x5d, 0x5d,
0x4d, 0x5d, 0x5d, 0x5d, 0x5d, 0x5d,
0x5d, 0x5d, 0x5d, 0x4d, 0x5d, 0x5d,
0x4d, 0x5d, 0x5d, 0x5d, 0x5d, 0x5d };
uint8_t CorrectLastBytes4[] = { 0x10, 0x50, 0x40, 0x10, 0x50, 0x40,
0x10, 0x50, 0x40, 0x10, 0x60, 0x50,
0x20, 0x60, 0x50, 0x10, 0x50, 0x50,
0x10, 0x50, 0x40, 0x10, 0x50, 0x50 };
CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_4.bmp", CorrectHeader4,
CorrectFirstBytes4, CorrectLastBytes4);
uint32_t CorrectHeader7[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280,
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
0xec4, 0x0, 0x7 };
uint8_t CorrectFirstBytes7[] = { 0x69, 0x69, 0x69, 0x69, 0x69, 0x69,
0x69, 0x69, 0x69, 0x69, 0x69, 0x69,
0x69, 0x69, 0x69, 0x69, 0x69, 0x69,
0x69, 0x69, 0x69, 0x69, 0x69, 0x69 };
uint8_t CorrectLastBytes7[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_7.bmp", CorrectHeader7,
CorrectFirstBytes7, CorrectLastBytes7);
uint32_t CorrectHeader8[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280,
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
0xec4, 0x0, 0x8 };
uint8_t CorrectFirstBytes8[] = { 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3,
0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3,
0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3,
0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3 };
uint8_t CorrectLastBytes8[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_8.bmp", CorrectHeader8,
CorrectFirstBytes8, CorrectLastBytes8);
}
static void test_DemultiplexTwoImages(void)
{
const char* File1 = "ImageTrabant.bmp";
const char* File2 = "ImageRedFerrari.bmp";
SteganoMultiplex(File1, File2);
SteganoDemultiplex(
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_0.bmp",
"demux_ImageTrabant_0.bmp", "demux_ImageRedFerrari_0.bmp");
SteganoDemultiplex(
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_1.bmp",
"demux_ImageTrabant_1.bmp", "demux_ImageRedFerrari_1.bmp");
SteganoDemultiplex(
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_4.bmp",
"demux_ImageTrabant_4.bmp", "demux_ImageRedFerrari_4.bmp");
SteganoDemultiplex(
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_7.bmp",
"demux_ImageTrabant_7.bmp", "demux_ImageRedFerrari_7.bmp");
SteganoDemultiplex(
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_8.bmp",
"demux_ImageTrabant_8.bmp", "demux_ImageRedFerrari_8.bmp");
uint32_t CorrectHeader0[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280,
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
0xec4, 0x0, 0x0 };
uint8_t CorrectFirstBytes0[] = { 0x50, 0x50, 0x50, 0x40, 0x50, 0x50,
0x40, 0x50, 0x50, 0x50, 0x50, 0x50,
0x50, 0x50, 0x50, 0x40, 0x50, 0x50,
0x40, 0x50, 0x50, 0x50, 0x50, 0x50 };
uint8_t CorrectLastBytes0[] = { 0x10, 0x50, 0x40, 0x10, 0x50, 0x40,
0x10, 0x50, 0x40, 0x10, 0x60, 0x50,
0x20, 0x60, 0x50, 0x10, 0x50, 0x50,
0x10, 0x50, 0x40, 0x10, 0x50, 0x50 };
CheckBmp("demux_ImageTrabant_4.bmp", CorrectHeader0, CorrectFirstBytes0,
CorrectLastBytes0);
uint32_t CorrectHeader1[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280,
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
0xec4, 0x0, 0x0 };
uint8_t CorrectFirstBytes1[] = { 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2,
0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2,
0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2,
0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2 };
uint8_t CorrectLastBytes1[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
CheckBmp("demux_ImageRedFerrari_7.bmp", CorrectHeader1, CorrectFirstBytes1,
CorrectLastBytes1);
uint32_t CorrectHeader2[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280,
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
0xec4, 0x0, 0x0 };
uint8_t CorrectFirstBytes2[] = { 0x58, 0x5c, 0x5e, 0x4e, 0x52, 0x54,
0x4e, 0x52, 0x54, 0x58, 0x5c, 0x5e,
0x56, 0x5c, 0x5c, 0x4c, 0x52, 0x52,
0x4c, 0x52, 0x54, 0x56, 0x5c, 0x5e };
uint8_t CorrectLastBytes2[] = { 0x10, 0x58, 0x48, 0x10, 0x5a, 0x4a,
0x12, 0x5a, 0x4e, 0x1a, 0x62, 0x56,
0x22, 0x66, 0x5c, 0x16, 0x5c, 0x50,
0x10, 0x54, 0x4a, 0x18, 0x5c, 0x52 };
CheckBmp("demux_ImageTrabant_1.bmp", CorrectHeader2, CorrectFirstBytes2,
CorrectLastBytes2);
uint32_t CorrectHeader3[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280,
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
0xec4, 0x0, 0x0 };
uint8_t CorrectFirstBytes3[] = { 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0,
0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0,
0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0,
0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0 };
uint8_t CorrectLastBytes3[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
CheckBmp("demux_ImageRedFerrari_4.bmp", CorrectHeader3, CorrectFirstBytes3,
CorrectLastBytes3);
Assert2FilesEqual("ImageTrabant.bmp", "demux_ImageTrabant_0.bmp");
Assert2FilesEqual("ImageRedFerrari.bmp", "demux_ImageRedFerrari_8.bmp");
}
static void test_MultiplexTextAndImage(void)
{
const char* File1 = "ImageCitroen2Cv.bmp";
const char* File2 = "TextFontys.txt";
SteganoMultiplexText(File1, File2);
uint32_t CorrectHeader0[] = { 0x56616, 0x115d, 0x36, 0x28, 0x1b8,
0x10c, 0x180001, 0x0, 0x565e0, 0x0,
0x0, 0x0, 0x0 };
uint8_t CorrectFirstBytes0[] = { 0x74, 0x86, 0x8b, 0x98, 0xab, 0xae,
0x61, 0x74, 0x76, 0x7c, 0x91, 0x8e,
0x91, 0xa4, 0xa3, 0x88, 0x9e, 0x9a,
0x93, 0xa8, 0xa3, 0x8c, 0xa3, 0x9c };
uint8_t CorrectLastBytes0[] = { 0x3e, 0x5d, 0x36, 0x4a, 0x69, 0x42,
0x39, 0x58, 0x33, 0x37, 0x56, 0x31,
0x32, 0x50, 0x2d, 0x32, 0x50, 0x2d,
0x30, 0x4e, 0x2b, 0x36, 0x54, 0x31 };
CheckBmp("mux_ImageCitroen2Cv.bmp_TextFontys.txt.bmp", CorrectHeader0,
CorrectFirstBytes0, CorrectLastBytes0);
}
static void test_DemultiplexTextAndImage(void)
{
const char* File1 = "ImageCitroen2Cv.bmp";
const char* File2 = "TextFontys.txt";
SteganoMultiplexText(File1, File2);
SteganoDemultiplexText(
"mux_ImageCitroen2Cv.bmp_TextFontys.txt.bmp",
"demux_ImageCitroen2Cv.bmp", "demux_TextFontys.txt");
uint32_t CorrectHeader0[] = { 0x56616, 0x0, 0x36, 0x28, 0x1b8,
0x10c, 0x180001, 0x0, 0x565e0, 0x0,
0x0, 0x0, 0x0 };
uint8_t CorrectFirstBytes0[] = { 0x74, 0x86, 0x8a, 0x98, 0xaa, 0xae,
0x60, 0x74, 0x76, 0x7c, 0x90, 0x8e,
0x90, 0xa4, 0xa2, 0x88, 0x9e, 0x9a,
0x92, 0xa8, 0xa2, 0x8c, 0xa2, 0x9c };
uint8_t CorrectLastBytes0[] = { 0x3e, 0x5d, 0x36, 0x4a, 0x69, 0x42,
0x39, 0x58, 0x33, 0x37, 0x56, 0x31,
0x32, 0x50, 0x2d, 0x32, 0x50, 0x2d,
0x30, 0x4e, 0x2b, 0x36, 0x54, 0x31 };
CheckBmp("demux_ImageCitroen2Cv.bmp", CorrectHeader0, CorrectFirstBytes0,
CorrectLastBytes0);
uint32_t CorrectHeader1[] = { 0x6945202a, 0x6f68646e, 0x206e6576,
0x0d2a2a2a, 0x440a0d0a, 0x65542065,
0x696e6863, 0x65686373, 0x696e5520,
0x73726576, 0x69657469, 0x69452074,
0x6f68646e };
uint8_t CorrectFirstBytes1[] = { 0x76, 0x65, 0x6e, 0x20, 0x65, 0x6e,
0x20, 0x46, 0x6f, 0x6e, 0x74, 0x79,
0x73, 0x20, 0x48, 0x6f, 0x67, 0x65,
0x73, 0x63, 0x68, 0x6f, 0x6c, 0x65 };
uint8_t CorrectLastBytes1[] = { 0x6e, 0x74, 0x79, 0x73, 0x2e, 0x6e,
0x6c, 0x0d, 0x0a, 0x0d, 0x0a, 0x2d,
0x2d, 0x20, 0x65, 0x69, 0x6e, 0x64,
0x65, 0x20, 0x2d, 0x2d, 0x0d, 0x0a };
CheckBmp("demux_TextFontys.txt", CorrectHeader1, CorrectFirstBytes1,
CorrectLastBytes1);
Assert2FilesEqual("TextFontys.txt", "demux_TextFontys.txt");
}
int main(int argc, char* argv[])
{
UnityBegin();
MY_RUN_TEST(test_GetSubstring);
MY_RUN_TEST(test_MultiplexTwoImages);
MY_RUN_TEST(test_DemultiplexTwoImages);
MY_RUN_TEST(test_MultiplexTextAndImage);
MY_RUN_TEST(test_DemultiplexTextAndImage);
return UnityEnd();
}

View File

@@ -0,0 +1,3 @@
watch
watch_test

View File

@@ -0,0 +1,42 @@
PROD_DIR := ./product
SHARED_DIR := ./shared
TEST_DIR := ./test
UNITY_FOLDER :=./Unity
RES_DIR := ./ResourceDetector
BUILD_DIR :=./build
PROD_EXEC = main
PROD_DIRS := $(PROD_DIR) $(SHARED_DIR) $(RES_DIR)
PROD_FILES := $(wildcard $(patsubst %,%/*.c, $(PROD_DIRS)))
HEADER_PROD_FILES := $(wildcard $(patsubst %,%/*.h, $(PROD_DIRS)))
PROD_INC_DIRS=-I$(PROD_DIR) -I$(SHARED_DIR) -I$(RES_DIR)
TEST_EXEC = main_test
TEST_DIRS := $(TEST_DIR) $(SHARED_DIR) $(RES_DIR) $(UNITY_FOLDER)
TEST_FILES := $(wildcard $(patsubst %,%/*.c, $(TEST_DIRS)))
HEADER_TEST_FILES := $(wildcard $(patsubst %,%/*.h, $(TEST_DIRS)))
TEST_INC_DIRS=-I$(TEST_DIR) -I$(SHARED_DIR) -I$(UNITY_FOLDER) -I$(RES_DIR)
CC=gcc
SYMBOLS=-Wall -Werror -g -O0 -std=c99
TEST_SYMBOLS=$(SYMBOLS) -DTEST -DUNITY_USE_MODULE_SETUP_TEARDOWN
.PHONY: clean test
all: $(PROD_EXEC)
$(PROD_EXEC): Makefile $(PROD_FILES) $(HEADER_FILES)
$(CC) $(PROD_INC_DIRS) $(SYMBOLS) $(PROD_FILES) -o $(BUILD_DIR)/$(PROD_EXEC)
$(TEST_EXEC): Makefile $(TEST_FILES) $(HEADER_FILES)
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(BUILD_DIR)/$(TEST_EXEC)
run: $(PROD_EXEC)
@./$(BUILD_DIR)/$(PROD_EXEC)
test: $(TEST_EXEC)
@./$(BUILD_DIR)/$(TEST_EXEC)
clean:
rm -f $(BUILD_DIR)/$(PROD_EXEC)
rm -f $(BUILD_DIR)/$(TEST_EXEC)

View File

@@ -0,0 +1,278 @@
/* **********************************************
* generic linked list in plain c
* author: Freddy Hurkmans
* date: dec 20, 2014
* **********************************************/
/* ******************************************************************************
* This list is designed using object oriented ideas, but is implemented in c.
*
* The idea is: you construct a list for a certain data structure (say: mystruct):
* list_admin* mylist = construct_list(sizeof(mystruct))
* mylist contains private data for this list implementation. You need not worry
* about it, only give it as first parameter to each list method.
*
* This means you can have multiple lists at the same time, just make sure you
* give the right list_admin structure to the list function.
* When you're done with your list, just call the destructor: destruct_list(&mylist)
* The destructor automatically deletes remaining list elements and the list administration.
*
* As this list implementation keeps its own administration in list_admin, you need
* not worry about next pointers and such. Your structure doesn't even need pointers
* to itself, you only need to worry about data. A valid struct could thus be:
* typedef struct
* {
* int nr;
* char text[100];
* } mystruct;
*
* Adding data to the list is done using list_add_* methods, such as list_add_tail,
* which adds data to the end of the list:
* mystruct data = {10, "hello world!"};
* int result = list_add_tail(mylist, &data);
* You don't have to provide the size of your struct, you've already done that in
* the destructor. If result < 0 list_add_* has failed (either a parameter problem
* or malloc didn't give memory).
*
* You can get a pointer to your data using list_get_*, e.g. get the 2nd element:
* mystruct* dataptr = list_get_element(admin, 1);
* or get the last element:
* mystruct* dataptr = list_get_last(admin);
* If dataptr is not NULL it points to the correct data, else the operation failed.
*
* Searching for data in your list can be done with list_index_of*. list_index_of
* compares the data in each list item to the given data. If they are the same, it
* returns the index. If you want to search for an element with a certain value for
* nr or text (see mystruct) you can implement your own compare function and use
* list_index_of_special (check memcmp for required return values):
* int mycompare(void* p1, void* p2, size_t size)
* {
* // this example doesn't need size!
* mystruct* org = (mystruct*)p1;
* int* nr = (int*)p2;
* return org->nr - nr; // return 0 if they are the same
* }
* Say you want to search for an element that has nr 10:
* int nr = 10;
* int index = list_index_of_special(mylist, &nr, mycompare);
* As noted earlier: mycompare must have the same prototype as memcmp. In fact:
* list_index_of is a shortcut for list_index_of_special(mylist, data, memcmp).
*
* Finally you can delete items with list_delete_*. They should work rather
* straight forward. If they succeed they return 0. You don't have to delete
* all items before destructing your list.
*
* ******************************************************************************/
#include <string.h> /* for memcmp and memcpy */
#include "list.h"
static size_t data_size(const list_admin* admin);
static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index);
static list_head* get_list_head_of_element_n(list_admin* admin, size_t index);
static void remove_first_element(list_admin* admin);
static int remove_non_first_element(list_admin* admin, size_t index);
/* **********************************************
* Constructor / destructor
* **********************************************/
list_admin* construct_list(size_t element_size)
{
list_admin* admin = malloc(sizeof(*admin));
if (admin != NULL)
{
admin->head = NULL;
admin->element_size = element_size;
admin->nr_elements = 0;
}
return admin;
}
void destruct_list(list_admin** admin)
{
if ((admin != NULL) && (*admin != NULL))
{
while ((*admin)->head != NULL)
{
list_head* temp = (*admin)->head;
(*admin)->head = (*admin)->head->next;
free(temp);
temp = NULL;
}
free(*admin);
*admin = NULL;
}
}
/* **********************************************
* Public functions
* **********************************************/
int list_get_nr_elements(list_admin* admin)
{
int nr_elements = -1;
if (admin != NULL)
{
nr_elements = admin->nr_elements;
}
return nr_elements;
}
int list_add_tail(list_admin* admin, const void* data)
{
int result = -1;
if ((admin != NULL) && (data != NULL))
{
list_head* new = malloc(data_size(admin));
if (new != NULL)
{
result = 0;
new->next = NULL;
memcpy(new+1, data, admin->element_size);
if (admin->head == NULL)
{
admin->head = new;
}
else
{
list_head* temp = get_guaranteed_list_head_of_element_n(admin, admin->nr_elements-1);
temp->next = new;
}
admin->nr_elements++;
}
}
return result;
}
void* list_get_element(list_admin* admin, size_t index)
{
list_head* item = get_list_head_of_element_n(admin, index);
if(item != NULL)
{
item++; // user data is just beyond list_head, thus we must increase the pointer
}
return item;
}
void* list_get_last(list_admin* admin)
{
list_head* item = NULL;
if (admin != NULL)
{
item = list_get_element(admin, admin->nr_elements-1);
}
return item;
}
int list_index_of(list_admin* admin, const void* data)
{
return list_index_of_special(admin, data, memcmp);
}
int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr compare)
{
int index = -1;
if ((admin != NULL) && (data != NULL) && (compare != NULL))
{
list_head* temp = admin->head;
index = 0;
while ((temp != NULL) && (compare(temp+1, data, admin->element_size) != 0))
{
temp = temp->next;
index++;
}
if (temp == NULL)
{
index = -1;
}
}
return index;
}
int list_delete_item(list_admin* admin, size_t index)
{
int result = -1;
if ((admin != NULL) && (admin->head != NULL) && (index < admin->nr_elements))
{
if (index == 0)
{
result = 0;
remove_first_element(admin);
}
else
{
result = remove_non_first_element(admin, index);
}
}
return result;
}
int list_delete_last(list_admin* admin)
{
int result = -1;
if (admin != NULL)
{
result = list_delete_item(admin, admin->nr_elements - 1);
}
return result;
}
/* **********************************************
* Private functions
* **********************************************/
static size_t data_size(const list_admin* admin)
{
return admin->element_size + sizeof(list_head);
}
static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index)
{
list_head* item = admin->head;
for (size_t i = 0; (i < index) && (item != NULL); i++)
{
item = item->next;
}
return item;
}
static list_head* get_list_head_of_element_n(list_admin* admin, size_t index)
{
list_head* item = NULL;
if ((admin != NULL) && (index < admin->nr_elements))
{
item = get_guaranteed_list_head_of_element_n(admin, index);
}
return item;
}
static void remove_first_element(list_admin* admin)
{
list_head* temp = admin->head;
admin->head = admin->head->next;
free(temp);
temp = NULL;
admin->nr_elements--;
}
static int remove_non_first_element(list_admin* admin, size_t index)
{
int result = -1;
if (index > 0)
{
list_head* temp = get_list_head_of_element_n(admin, index-1);
if ((temp != NULL) && (temp->next != NULL)) // to remove element n, element n-1 and n must exist
{
result = 0;
list_head* to_delete = temp->next;
temp->next = to_delete->next;
free(to_delete);
to_delete = NULL;
admin->nr_elements--;
}
}
return result;
}

View File

@@ -0,0 +1,52 @@
#pragma once
#include <stdlib.h>
typedef struct list_head
{
struct list_head* next;
} list_head;
typedef struct
{
struct list_head* head;
size_t element_size;
size_t nr_elements;
} list_admin;
typedef int (*CompareFuncPtr)(const void*, const void*, size_t);
// call the constructor before using the list:
// list_admin* mylist = construct_list(sizeof(mystruct));
// if mylist equals NULL, no memory could be allocated. Please don't
// mess with the admin data, this can corrupt your data.
list_admin* construct_list(size_t element_size);
// call the destructor when you're done, pass the list administration
// as referenced parameter (the variable will be set to NULL).
void destruct_list(list_admin** admin);
// Reads the number of elements in your list. Returns -1 in case of
// errors, else the number of elements.
int list_get_nr_elements(list_admin* admin);
// Add data to the end of the list. Returns -1 in case of errors, else 0
int list_add_tail(list_admin* admin, const void* data);
// Returns a pointer to the requested element. Returns NULL in case of
// errors (such as: the element does not exist).
void* list_get_element(list_admin* admin, size_t index);
void* list_get_last(list_admin* admin);
// Returns the index to the first found list element that's equal to data,
// or -1 in case of errors (such as: not found).
int list_index_of(list_admin* admin, const void* data);
// Returns the index to the first found list element for which cmp says it's,
// equal to data, or -1 in case of errors (such as: not found). cmp must behave
// just like memcmp, i.e.: return 0 when the data matches.
int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr cmp);
// Delete an item in the list. Returns -1 in case of errors, else 0.
int list_delete_item(list_admin* admin, size_t index);
int list_delete_last(list_admin* admin);

View File

@@ -0,0 +1,270 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
//#include <malloc.h>
#include <string.h>
#include "resource_detector.h"
#undef malloc
#undef free
#undef main
#undef fopen
#undef fclose
#include "list.h"
#define MAGIC_CODE 0x78563412
#define ADDR(addr,offset) ((addr) + (offset))
#define SET_MAGIC_CODE(addr,offset) *((int*) ADDR(addr,offset)) = MAGIC_CODE
#define MAGIC_CODE_OK(addr,offset) (*((int*) ADDR(addr,offset)) == MAGIC_CODE)
typedef struct
{
char* addr;
unsigned int size;
const char* file;
unsigned int line;
} mem_data;
typedef struct
{
FILE* addr;
const char* file_to_open;
const char* mode;
const char* file;
unsigned int line;
} file_data;
static list_admin* memlist = NULL;
static list_admin* filelist = NULL;
static int memory_compare(const void* meminfo, const void* address, size_t size)
{
mem_data* info = (mem_data*)meminfo;
char* addr = (char*)address;
return info->addr - addr;
}
static int file_compare(const void* fileinfo, const void* address, size_t size)
{
file_data* info = (file_data*)fileinfo;
FILE* addr = (FILE*)address;
return info->addr - addr;
}
static void
invalidate (mem_data* info)
{
char* user_addr;
char* raw_addr;
unsigned int size;
user_addr = info->addr;
size = info->size;
raw_addr = ADDR (user_addr, -sizeof(int));
if (!MAGIC_CODE_OK(user_addr, -sizeof(int)) || !MAGIC_CODE_OK(user_addr, size))
{
fprintf (stderr, "ERROR: addr %p (%s, line %d): out-of-bound access\n", (void*)user_addr, info->file, info->line);
}
memset (raw_addr, 0xff, size + (2 * sizeof(int)));
free (raw_addr);
}
/*
* replacement of malloc
*/
extern void*
xmalloc (unsigned int size, const char* file, unsigned int line)
{
char* raw_addr = malloc (size + (2 * sizeof(int)));
char* user_addr;
mem_data info = {NULL, 0, NULL, 0};
if (raw_addr == NULL)
{
fprintf (stderr, "ERROR: malloc failed for %d bytes (%s, line %d)\n", size, file, line);
return (NULL);
}
else
{
user_addr = ADDR (raw_addr, sizeof (int));
SET_MAGIC_CODE (raw_addr, 0);
SET_MAGIC_CODE (user_addr, size);
info.addr = user_addr;
info.size = size;
info.file = file;
info.line = line;
list_add_tail(memlist, &info);
}
return ((void*) user_addr);
}
/*
* replacement of free
*/
extern void
xfree (void* addr, const char* filename, int linenr)
{
char* user_addr = (char*) addr;
mem_data* info = NULL;
/* check if allocated memory is in our list and retrieve its info */
int index = list_index_of_special(memlist, addr, memory_compare);
info = list_get_element(memlist, index);
if (info == NULL)
{
fprintf (stderr, "ERROR: trying to free memory that was not malloc-ed (addr %p) in %s : %d\n", (void*)user_addr, filename, linenr);
return;
}
invalidate (info);
list_delete_item(memlist, index);
}
static void
print_empty_lines(int n)
{
int i;
for (i = 0; i < n; i++)
{
fprintf(stderr, "\n");
}
}
static void set_colour_red(void)
{
fprintf(stderr, "\033[10;31m");
}
static void set_colour_gray(void)
{
fprintf(stderr, "\033[22;37m");
}
static void
print_line(void)
{
fprintf (stderr, "---------------------------------------------------------\n");
}
static void
print_not_good(void)
{
set_colour_gray();
print_line();
set_colour_red();
fprintf (stderr, " # # ###\n");
fprintf (stderr, " ## # #### ##### #### #### #### ##### ###\n");
fprintf (stderr, " # # # # # # # # # # # # # # ###\n");
fprintf (stderr, " # # # # # # # # # # # # # # \n");
fprintf (stderr, " # # # # # # # ### # # # # # # \n");
fprintf (stderr, " # ## # # # # # # # # # # # ###\n");
fprintf (stderr, " # # #### # #### #### #### ##### ###\n");
set_colour_gray();
print_line();
}
/*
* writes all info of the unallocated memory
*/
static void
resource_detection (void)
{
time_t now = time (NULL);
int forgotten_frees = list_get_nr_elements(memlist);
int nr_files_open = list_get_nr_elements(filelist);
if ((forgotten_frees > 0) || (nr_files_open > 0))
{
print_empty_lines(15);
}
if (forgotten_frees > 0)
{
mem_data* info = NULL;
print_line();
fprintf (stderr, "Memory Leak Summary, generated: %s", ctime (&now));
print_not_good();
set_colour_red();
while((info = list_get_element(memlist, 0)) != NULL)
{
fprintf (stderr, "forgot to free address: %p (%d bytes) that was allocated in: %s on line: %d\n",
(void*)info->addr, info->size, info->file, info->line);
list_delete_item(memlist, 0);
}
set_colour_gray();
print_line();
print_empty_lines(1);
}
if (nr_files_open > 0)
{
file_data* info = NULL;
print_line();
fprintf (stderr, "File Management Summary, generated: %s", ctime (&now));
print_not_good();
set_colour_red();
while((info = list_get_element(filelist, 0)) != NULL)
{
fprintf (stderr, "forgot to close file: %s (ptr %p, mode \"%s\") that was opened from: %s on line: %d\n",
info->file_to_open, (void*)(info->addr), info->mode, info->file, info->line);
list_delete_item(filelist, 0);
}
set_colour_gray();
print_line();
print_empty_lines(1);
}
if ((forgotten_frees == 0) && (nr_files_open == 0))
{
printf ("\nResource checks: OK\n\n");
}
destruct_list(&memlist);
destruct_list(&filelist);
}
extern FILE*
xfopen (const char* file_to_open, const char* mode, const char* filename, int linenr)
{
file_data info = {0};
info.addr = fopen(file_to_open, mode);
if (info.addr != NULL)
{
info.file_to_open = file_to_open;
info.mode = mode;
info.file = filename;
info.line = linenr;
list_add_tail(filelist, &info);
}
return info.addr;
}
extern int
xfclose(FILE* fptr, const char* filename, int linenr)
{
int index = list_index_of_special(filelist, fptr, file_compare);
if (index < 0)
{
fprintf (stderr, "ERROR: trying to close an unopened file in %s on line number %d.\n", filename, linenr);
return -1;
}
list_delete_item(filelist, index);
return (fclose (fptr));
}
extern int
main (int argc, char* argv[])
{
atexit (resource_detection);
memlist = construct_list(sizeof(mem_data));
filelist = construct_list(sizeof(file_data));
return (xmain (argc, argv));
}

View File

@@ -0,0 +1,18 @@
#ifndef RESOURCE_DETECTOR_H
#define RESOURCE_DETECTOR_H
#include <stdio.h>
#define main xmain
#define malloc(size) xmalloc ((size), (__FILE__), (__LINE__))
#define free(addr) xfree ((addr), __FILE__, __LINE__)
#define fopen(name,mode) xfopen ((name),(mode), __FILE__, __LINE__)
#define fclose(fptr) xfclose ((fptr), __FILE__, __LINE__)
extern int xmain(int argc, char* argv[]);
extern void* xmalloc(unsigned int size, const char* file, unsigned int line);
extern void xfree(void* addr, const char* filename, int linenr);
extern FILE* xfopen(const char* file_to_open, const char* mode, const char* filename, int linenr);
extern int xfclose(FILE* fptr, const char* filename, int linenr);
#endif

View File

@@ -0,0 +1,28 @@
UNITY_FOLDER=../Unity
TEST_INC_DIRS=$(INC_DIRS) -I$(UNITY_FOLDER)
TEST_FILES=$(UNITY_FOLDER)/unity.c \
list_test.c \
list.c
HEADER_FILES=*.h
TEST = list_test
CC=gcc
SYMBOLS=-Wall -Werror -pedantic -O0 -ggdb -std=c99
TEST_SYMBOLS=$(SYMBOLS) -DTEST
.PHONY: clean test
all: $(TEST)
$(TEST): Makefile $(TEST_FILES) $(HEADER_FILES)
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(TEST)
clean:
rm -f list $(TEST)
test: $(TEST)
@valgrind ./$(TEST)

View File

@@ -0,0 +1,300 @@
#include <string.h> /* for memcmp */
#include "list.h"
#include "unity.h"
// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
static list_admin* mylist = NULL;
typedef struct
{
int i;
int j;
} test_struct;
// compare function that returns 0 if test_struct.i matches, it ignores .j
static int compare_test_func(const void* p1, const void* p2, size_t size)
{
size = size; // to prevent warnings
const test_struct* data1 = (const test_struct*)p1;
const test_struct* data2 = (const test_struct*)p2;
return data1->i - data2->i;
}
// check n items in list against verify_data
// IMPORTANT: this function must check using list_get_element,
// else the test for that function is no longer useful
static void check_n_list_elements_ok(list_admin* admin, int nr_items, const test_struct* verify_data)
{
for(int i = 0; i < nr_items; i++)
{
test_struct* ptr = list_get_element(admin, i);
TEST_ASSERT_NOT_NULL(ptr);
TEST_ASSERT_EQUAL(0, memcmp(verify_data+i, ptr, sizeof(*ptr)));
}
}
void setUp(void)
{
// This is run before EACH test
mylist = construct_list(sizeof(test_struct));
TEST_ASSERT_NOT_NULL(mylist);
}
void tearDown(void)
{
// This is run after EACH test
destruct_list(&mylist);
TEST_ASSERT_NULL(mylist);
}
static void test_ConstructList(void)
{
TEST_ASSERT_NULL(mylist->head);
TEST_ASSERT_EQUAL(sizeof(test_struct), mylist->element_size);
TEST_ASSERT_EQUAL(0, mylist->nr_elements);
}
static void test_NrElements_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_get_nr_elements(NULL));
}
static void test_AddData_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_add_tail(mylist, NULL));
TEST_ASSERT_EQUAL(-1, list_add_tail(NULL, mylist));
}
static void test_AddData(void)
{
test_struct data = {3, 4};
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data));
TEST_ASSERT_NOT_NULL(mylist->head);
TEST_ASSERT_EQUAL(1, list_get_nr_elements(mylist));
list_head* head = mylist->head;
test_struct* element = (test_struct*)(head+1);
TEST_ASSERT_EQUAL(data.i, element->i);
TEST_ASSERT_EQUAL(data.j, element->j);
}
static void test_Add2PiecesOfData(void)
{
test_struct data1 = {8, 9};
test_struct data2 = {-3, -4};
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data1));
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data2));
TEST_ASSERT_NOT_NULL(mylist->head);
TEST_ASSERT_NOT_NULL(mylist->head->next);
TEST_ASSERT_EQUAL(2, list_get_nr_elements(mylist));
list_head* head = mylist->head->next;
test_struct* element = (test_struct*)(head+1);
TEST_ASSERT_EQUAL(data2.i, element->i);
TEST_ASSERT_EQUAL(data2.j, element->j);
}
static void test_GetElement_parameters(void)
{
TEST_ASSERT_NULL(list_get_element(NULL, 0));
}
static void test_GetElement(void)
{
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}};
const int nr_elements = sizeof(data)/sizeof(data[0]);
for(int i = 0; i < nr_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
}
check_n_list_elements_ok(mylist, nr_elements, data); // checks using list_get_element
TEST_ASSERT_NULL(list_get_element(mylist, nr_elements));
TEST_ASSERT_NULL(list_get_element(mylist, -1));
}
static void test_GetLast_parameters(void)
{
TEST_ASSERT_NULL(list_get_last(NULL));
}
static void test_GetLast(void)
{
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}};
const int nr_elements = sizeof(data)/sizeof(data[0]);
TEST_ASSERT_NULL(list_get_last(mylist));
for(int i = 0; i < nr_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
test_struct* ptr = list_get_last(mylist);
TEST_ASSERT_NOT_NULL(ptr);
TEST_ASSERT_EQUAL(0, memcmp(&(data[i]), ptr, sizeof(*ptr)));
}
}
static void test_IndexOf_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_index_of(mylist, NULL));
TEST_ASSERT_EQUAL(-1, list_index_of(NULL, mylist));
}
static void test_IndexOf(void)
{
const test_struct real_data[] = {{8, 9}, {-3, -4}, {21, 56}};
const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]);
const test_struct false_data[] = {{-3, 9}, {8, 56}, {21, -4}, {0, 0}};
const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]);
for(int i = 0; i < nr_real_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(real_data[i])));
}
for(int i = 0; i < nr_real_elements; i++)
{
TEST_ASSERT_EQUAL(i, list_index_of(mylist, &(real_data[i])));
}
for(int i = 0; i < nr_false_elements; i++)
{
TEST_ASSERT_EQUAL(-1, list_index_of(mylist, &(false_data[i])));
}
}
static void test_IndexOfSpecial_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, NULL, compare_test_func));
TEST_ASSERT_EQUAL(-1, list_index_of_special(NULL, mylist, compare_test_func));
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, mylist, NULL));
}
static void test_IndexOfSpecial(void)
{
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}}; // data in list
const test_struct real_data[] = {{8, -4}, {-3, 56}, {21, 9}}; // data to search for (i equals)
const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]);
const test_struct false_data[] = {{-2, 9}, {9, -4}, {22, 56}, {0, 0}}; // data that doesn't exist
const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]);
// first make sure our compare function works
for(int i = 0; i < nr_real_elements; i++)
{
TEST_ASSERT_EQUAL(0, compare_test_func(&(data[i]), &(real_data[i]), 0));
for (int j = 0; j < nr_false_elements; j++)
{
TEST_ASSERT_NOT_EQUAL(0, compare_test_func(&(data[i]), &(false_data[j]), 0))
}
}
for(int i = 0; i < nr_real_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
}
for(int i = 0; i < nr_real_elements; i++)
{
TEST_ASSERT_EQUAL(i, list_index_of_special(mylist, &(real_data[i]), compare_test_func));
}
for(int i = 0; i < nr_false_elements; i++)
{
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, &(false_data[i]), compare_test_func));
}
}
static void test_DeleteItem_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_delete_item(NULL, 0));
TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, -1));
}
static void test_DeleteItem(void)
{
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
int nr_elements = sizeof(data)/sizeof(data[0]);
const test_struct data_noFirst[] = {{-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
const test_struct data_noLast[] = {{-3, -4}, {21, 56}, {0, 0}};
const test_struct data_noMiddle[] = {{-3, -4}, {0, 0}};
TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, 0));
for(int i = 0; i < nr_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
}
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 0));
nr_elements--;
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
check_n_list_elements_ok(mylist, nr_elements, data_noFirst);
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, nr_elements-1));
nr_elements--;
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
check_n_list_elements_ok(mylist, nr_elements, data_noLast);
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 1));
nr_elements--;
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
check_n_list_elements_ok(mylist, nr_elements, data_noMiddle);
}
static void test_DeleteLast_parameters(void)
{
TEST_ASSERT_EQUAL(-1, list_delete_last(NULL));
}
static void test_DeleteLast(void)
{
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
int nr_elements = sizeof(data)/sizeof(data[0]);
TEST_ASSERT_EQUAL(-1, list_delete_last(mylist));
for(int i = 0; i < nr_elements; i++)
{
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
}
for (int i = nr_elements-1; i >= 0; i--)
{
TEST_ASSERT_EQUAL(0, list_delete_last(mylist));
TEST_ASSERT_EQUAL(i, list_get_nr_elements(mylist));
check_n_list_elements_ok(mylist, i, data);
}
TEST_ASSERT_NULL(mylist->head);
TEST_ASSERT_EQUAL(0, list_get_nr_elements(mylist));
}
int main(void)
{
UnityBegin();
MY_RUN_TEST(test_ConstructList);
MY_RUN_TEST(test_NrElements_parameters);
MY_RUN_TEST(test_AddData_parameters);
MY_RUN_TEST(test_AddData);
MY_RUN_TEST(test_Add2PiecesOfData);
MY_RUN_TEST(test_GetElement_parameters);
MY_RUN_TEST(test_GetElement);
MY_RUN_TEST(test_GetLast_parameters);
MY_RUN_TEST(test_GetLast);
MY_RUN_TEST(test_IndexOf_parameters);
MY_RUN_TEST(test_IndexOf);
MY_RUN_TEST(test_IndexOfSpecial_parameters);
MY_RUN_TEST(test_IndexOfSpecial);
MY_RUN_TEST(test_DeleteItem_parameters);
MY_RUN_TEST(test_DeleteItem);
MY_RUN_TEST(test_DeleteLast_parameters);
MY_RUN_TEST(test_DeleteLast);
// MY_RUN_TEST();
// MY_RUN_TEST();
// MY_RUN_TEST();
// MY_RUN_TEST();
return UnityEnd();
}

View File

@@ -0,0 +1,841 @@
/* ==========================================
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.h"
#include <stdio.h>
#include <string.h>
#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
/// return prematurely if we are already in failure or ignore state
#define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); }
struct _Unity Unity = { 0 };
const char* UnityStrNull = "NULL";
const char* UnityStrSpacer = ". ";
const char* UnityStrExpected = " Expected ";
const char* UnityStrWas = " Was ";
const char* UnityStrTo = " To ";
const char* UnityStrElement = " Element ";
const char* UnityStrMemory = " Memory Mismatch";
const char* UnityStrDelta = " Values Not Within Delta ";
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
//-----------------------------------------------
// Pretty Printers & Test Result Output Handlers
//-----------------------------------------------
void UnityPrint(const char* string)
{
const char* pch = string;
if (pch != NULL)
{
while (*pch)
{
// printable characters plus CR & LF are printed
if ((*pch <= 126) && (*pch >= 32))
{
UNITY_OUTPUT_CHAR(*pch);
}
//write escaped carriage returns
else if (*pch == 13)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('r');
}
//write escaped line feeds
else if (*pch == 10)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('n');
}
// unprintable characters are shown as codes
else
{
UNITY_OUTPUT_CHAR('\\');
UnityPrintNumberHex((_U_SINT)*pch, 2);
}
pch++;
}
}
}
//-----------------------------------------------
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
{
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
UnityPrintNumber(number);
}
else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
{
UnityPrintNumberUnsigned((_U_UINT)number);
}
else
{
UnityPrintNumberHex((_U_UINT)number, (style & 0x000F) << 1);
}
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumber(const _U_SINT number_to_print)
{
_U_SINT divisor = 1;
_U_SINT next_divisor;
_U_SINT number = number_to_print;
if (number < 0)
{
UNITY_OUTPUT_CHAR('-');
number = -number;
}
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumberUnsigned(const _U_UINT number)
{
_U_UINT divisor = 1;
_U_UINT next_divisor;
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
}
//-----------------------------------------------
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
{
_U_UINT nibble;
char nibbles = nibbles_to_print;
UNITY_OUTPUT_CHAR('0');
UNITY_OUTPUT_CHAR('x');
while (nibbles > 0)
{
nibble = (number >> (--nibbles << 2)) & 0x0000000F;
if (nibble <= 9)
{
UNITY_OUTPUT_CHAR((char)('0' + nibble));
}
else
{
UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
}
}
}
//-----------------------------------------------
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
{
_U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
_US32 i;
for (i = 0; i < UNITY_INT_WIDTH; i++)
{
if (current_bit & mask)
{
if (current_bit & number)
{
UNITY_OUTPUT_CHAR('1');
}
else
{
UNITY_OUTPUT_CHAR('0');
}
}
else
{
UNITY_OUTPUT_CHAR('X');
}
current_bit = current_bit >> 1;
}
}
//-----------------------------------------------
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(_UF number)
{
char TempBuffer[32];
sprintf(TempBuffer, "%.6f", number);
UnityPrint(TempBuffer);
}
#endif
//-----------------------------------------------
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
{
UnityPrint(file);
UNITY_OUTPUT_CHAR(':');
UnityPrintNumber(line);
UNITY_OUTPUT_CHAR(':');
UnityPrint(Unity.CurrentTestName);
UNITY_OUTPUT_CHAR(':');
}
//-----------------------------------------------
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
{
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("FAIL:");
}
//-----------------------------------------------
void UnityConcludeTest(void)
{
if (Unity.CurrentTestIgnored)
{
Unity.TestIgnores++;
}
else if (!Unity.CurrentTestFailed)
{
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
UnityPrint("PASS");
UNITY_PRINT_EOL;
}
else
{
Unity.TestFailures++;
}
Unity.CurrentTestFailed = 0;
Unity.CurrentTestIgnored = 0;
}
//-----------------------------------------------
void UnityAddMsgIfSpecified(const char* msg)
{
if (msg)
{
UnityPrint(UnityStrSpacer);
UnityPrint(msg);
}
}
//-----------------------------------------------
void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
{
UnityPrint(UnityStrExpected);
if (expected != NULL)
{
UNITY_OUTPUT_CHAR('\'');
UnityPrint(expected);
UNITY_OUTPUT_CHAR('\'');
}
else
{
UnityPrint(UnityStrNull);
}
UnityPrint(UnityStrWas);
if (actual != NULL)
{
UNITY_OUTPUT_CHAR('\'');
UnityPrint(actual);
UNITY_OUTPUT_CHAR('\'');
}
else
{
UnityPrint(UnityStrNull);
}
}
//-----------------------------------------------
// Assertion & Control Helpers
//-----------------------------------------------
int UnityCheckArraysForNull(const void* expected, const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
{
//return true if they are both NULL
if ((expected == NULL) && (actual == NULL))
return 1;
//throw error if just expected is NULL
if (expected == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForExpected);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
//throw error if just actual is NULL
if (actual == NULL)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrNullPointerForActual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
//return false if neither is NULL
return 0;
}
//-----------------------------------------------
// Assertion Functions
//-----------------------------------------------
void UnityAssertBits(const _U_SINT mask,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if ((mask & expected) != (mask & actual))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintMask(mask, expected);
UnityPrint(UnityStrWas);
UnityPrintMask(mask, actual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualNumber(const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
UNITY_SKIP_EXECUTION;
if (expected != actual)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualIntArray(const _U_SINT* expected,
const _U_SINT* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
_UU32 elements = num_elements;
const _US8* ptr_exp = (_US8*)expected;
const _US8* ptr_act = (_US8*)actual;
UNITY_SKIP_EXECUTION;
if (elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
switch(style)
{
case UNITY_DISPLAY_STYLE_HEX8:
case UNITY_DISPLAY_STYLE_INT8:
case UNITY_DISPLAY_STYLE_UINT8:
while (elements--)
{
if (*ptr_exp != *ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 1;
ptr_act += 1;
}
break;
case UNITY_DISPLAY_STYLE_HEX16:
case UNITY_DISPLAY_STYLE_INT16:
case UNITY_DISPLAY_STYLE_UINT16:
while (elements--)
{
if (*(_US16*)ptr_exp != *(_US16*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US16*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US16*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 2;
ptr_act += 2;
}
break;
#ifdef UNITY_SUPPORT_64
case UNITY_DISPLAY_STYLE_HEX64:
case UNITY_DISPLAY_STYLE_INT64:
case UNITY_DISPLAY_STYLE_UINT64:
while (elements--)
{
if (*(_US64*)ptr_exp != *(_US64*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US64*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US64*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 8;
ptr_act += 8;
}
break;
#endif
default:
while (elements--)
{
if (*(_US32*)ptr_exp != *(_US32*)ptr_act)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(*(_US32*)ptr_exp, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(*(_US32*)ptr_act, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_exp += 4;
ptr_act += 4;
}
break;
}
}
//-----------------------------------------------
#ifndef UNITY_EXCLUDE_FLOAT
void UnityAssertEqualFloatArray(const _UF* expected,
const _UF* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 elements = num_elements;
const _UF* ptr_expected = expected;
const _UF* ptr_actual = actual;
_UF diff, tol;
UNITY_SKIP_EXECUTION;
if (elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
while (elements--)
{
diff = *ptr_expected - *ptr_actual;
if (diff < 0.0)
diff = 0.0 - diff;
tol = UNITY_FLOAT_PRECISION * *ptr_expected;
if (tol < 0.0)
tol = 0.0 - tol;
if (diff > tol)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrintFloat(*ptr_expected);
UnityPrint(UnityStrWas);
UnityPrintFloat(*ptr_actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
ptr_expected++;
ptr_actual++;
}
}
//-----------------------------------------------
void UnityAssertFloatsWithin(const _UF delta,
const _UF expected,
const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UF diff = actual - expected;
_UF pos_delta = delta;
UNITY_SKIP_EXECUTION;
if (diff < 0)
{
diff = 0.0f - diff;
}
if (pos_delta < 0)
{
pos_delta = 0.0f - pos_delta;
}
if (pos_delta < diff)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrintFloat(expected);
UnityPrint(UnityStrWas);
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
#endif
//-----------------------------------------------
void UnityAssertNumbersWithin( const _U_SINT delta,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
UNITY_SKIP_EXECUTION;
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
if (actual > expected)
Unity.CurrentTestFailed = ((actual - expected) > delta);
else
Unity.CurrentTestFailed = ((expected - actual) > delta);
}
else
{
if ((_U_UINT)actual > (_U_UINT)expected)
Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
else
Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrDelta);
UnityPrintNumberByStyle(delta, style);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 i;
UNITY_SKIP_EXECUTION;
// if both pointers not null compare the strings
if (expected && actual)
{
for (i = 0; expected[i] || actual[i]; i++)
{
if (expected[i] != actual[i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected != actual)
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrintExpectedAndActualStrings(expected, actual);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertEqualStringArray( const char** expected,
const char** actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
_UU32 i, j = 0;
UNITY_SKIP_EXECUTION;
// if no elements, it's an error
if (num_elements == 0)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
do
{
// if both pointers not null compare the strings
if (expected[j] && actual[j])
{
for (i = 0; expected[j][i] || actual[j][i]; i++)
{
if (expected[j][i] != actual[j][i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ // handle case of one pointers being null (if both null, test should pass)
if (expected[j] != actual[j])
{
Unity.CurrentTestFailed = 1;
}
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT);
}
UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
} while (++j < num_elements);
}
//-----------------------------------------------
void UnityAssertEqualMemory( const void* expected,
const void* actual,
_UU32 length,
_UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
unsigned char* expected_ptr = (unsigned char*)expected;
unsigned char* actual_ptr = (unsigned char*)actual;
_UU32 elements = num_elements;
UNITY_SKIP_EXECUTION;
if ((elements == 0) || (length == 0))
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrPointless);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
return;
while (elements--)
{
if (memcmp((const void*)expected_ptr, (const void*)actual_ptr, length) != 0)
{
Unity.CurrentTestFailed = 1;
break;
}
expected_ptr += length;
actual_ptr += length;
}
if (Unity.CurrentTestFailed)
{
UnityTestResultsFailBegin(lineNumber);
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
}
UnityPrint(UnityStrMemory);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
// Control Functions
//-----------------------------------------------
void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
{
UNITY_SKIP_EXECUTION;
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("FAIL");
if (msg != NULL)
{
UNITY_OUTPUT_CHAR(':');
if (msg[0] != ' ')
{
UNITY_OUTPUT_CHAR(' ');
}
UnityPrint(msg);
}
UNITY_FAIL_AND_BAIL;
}
//-----------------------------------------------
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
{
UNITY_SKIP_EXECUTION;
UnityTestResultsBegin(Unity.TestFile, line);
UnityPrint("IGNORE");
if (msg != NULL)
{
UNITY_OUTPUT_CHAR(':');
UNITY_OUTPUT_CHAR(' ');
UnityPrint(msg);
}
UNITY_IGNORE_AND_BAIL;
}
//-----------------------------------------------
void setUp(void);
void tearDown(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
Unity.CurrentTestName = FuncName;
Unity.CurrentTestLineNumber = FuncLineNum;
Unity.NumberOfTests++;
if (TEST_PROTECT())
{
setUp();
Func();
}
if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
{
tearDown();
}
UnityConcludeTest();
}
//-----------------------------------------------
void UnityBegin(void)
{
Unity.NumberOfTests = 0;
}
//-----------------------------------------------
int UnityEnd(void)
{
UnityPrint("-----------------------");
UNITY_PRINT_EOL;
UnityPrintNumber(Unity.NumberOfTests);
UnityPrint(" Tests ");
UnityPrintNumber(Unity.TestFailures);
UnityPrint(" Failures ");
UnityPrintNumber(Unity.TestIgnores);
UnityPrint(" Ignored");
UNITY_PRINT_EOL;
if (Unity.TestFailures == 0U)
{
UnityPrint("OK");
}
else
{
UnityPrint("FAIL");
}
UNITY_PRINT_EOL;
return Unity.TestFailures;
}

View File

@@ -0,0 +1,209 @@
/* ==========================================
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 UNITY_FRAMEWORK_H
#define UNITY_FRAMEWORK_H
#define UNITY
#include "unity_internals.h"
//-------------------------------------------------------
// Configuration Options
//-------------------------------------------------------
// Integers
// - Unity assumes 32 bit integers by default
// - If your compiler treats ints of a different size, define UNITY_INT_WIDTH
// Floats
// - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
// - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
// - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
// - define UNITY_FLOAT_VERBOSE to print floating point values in errors (uses sprintf)
// Output
// - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
// Optimization
// - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge
// - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests.
//-------------------------------------------------------
// Test Running Macros
//-------------------------------------------------------
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
#ifndef RUN_TEST
#define RUN_TEST(func, line_num) UnityDefaultTestRun(func, #func, line_num)
#endif
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
#define TEST_CASE(...)
//-------------------------------------------------------
// Basic Fail and Ignore
//-------------------------------------------------------
#define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, message)
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, message)
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
#define TEST_ONLY()
//-------------------------------------------------------
// Test Asserts (simple)
//-------------------------------------------------------
//Boolean
#define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE")
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE")
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE")
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL")
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL")
//Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal")
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, NULL)
#define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, NULL)
//Integer Ranges (of all sizes)
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, NULL)
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, NULL)
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, NULL)
//Floating Point (If Enabled)
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
//-------------------------------------------------------
// Test Asserts (with additional messages)
//-------------------------------------------------------
//Boolean
#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, message)
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, message)
//Integers (of all sizes)
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, message)
#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, message)
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, message)
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, message)
//Integer Ranges (of all sizes)
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, message)
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, message)
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_STRING_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, message)
//Floating Point (If Enabled)
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message)
#endif

View File

@@ -0,0 +1,356 @@
/* ==========================================
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 UNITY_INTERNALS_H
#define UNITY_INTERNALS_H
#include <stdio.h>
#include <setjmp.h>
//-------------------------------------------------------
// Int Support
//-------------------------------------------------------
#ifndef UNITY_INT_WIDTH
#define UNITY_INT_WIDTH (32)
#endif
#ifndef UNITY_LONG_WIDTH
#define UNITY_LONG_WIDTH (32)
#endif
#if (UNITY_INT_WIDTH == 32)
typedef unsigned char _UU8;
typedef unsigned short _UU16;
typedef unsigned int _UU32;
typedef signed char _US8;
typedef signed short _US16;
typedef signed int _US32;
#elif (UNITY_INT_WIDTH == 16)
typedef unsigned char _UU8;
typedef unsigned int _UU16;
typedef unsigned long _UU32;
typedef signed char _US8;
typedef signed int _US16;
typedef signed long _US32;
#else
#error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported)
#endif
//-------------------------------------------------------
// 64-bit Support
//-------------------------------------------------------
#ifndef UNITY_SUPPORT_64
//No 64-bit Support
typedef _UU32 _U_UINT;
typedef _US32 _U_SINT;
#else
//64-bit Support
#if (UNITY_LONG_WIDTH == 32)
typedef unsigned long long _UU64;
typedef signed long long _US64;
#elif (UNITY_LONG_WIDTH == 64)
typedef unsigned long _UU64;
typedef signed long _US64;
#else
#error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported)
#endif
typedef _UU64 _U_UINT;
typedef _US64 _U_SINT;
#endif
//-------------------------------------------------------
// Pointer Support
//-------------------------------------------------------
#ifndef UNITY_POINTER_WIDTH
#define UNITY_POINTER_WIDTH (32)
#endif
#if (UNITY_POINTER_WIDTH == 32)
typedef _UU32 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32
#elif (UNITY_POINTER_WIDTH == 64)
typedef _UU64 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64
#elif (UNITY_POINTER_WIDTH == 16)
typedef _UU16 _UP;
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16
#else
#error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported)
#endif
//-------------------------------------------------------
// Float Support
//-------------------------------------------------------
#ifdef UNITY_EXCLUDE_FLOAT
//No Floating Point Support
#undef UNITY_FLOAT_PRECISION
#undef UNITY_FLOAT_TYPE
#undef UNITY_FLOAT_VERBOSE
#else
//Floating Point Support
#ifndef UNITY_FLOAT_PRECISION
#define UNITY_FLOAT_PRECISION (0.00001f)
#endif
#ifndef UNITY_FLOAT_TYPE
#define UNITY_FLOAT_TYPE float
#endif
typedef UNITY_FLOAT_TYPE _UF;
#endif
//-------------------------------------------------------
// Output Method
//-------------------------------------------------------
#ifndef UNITY_OUTPUT_CHAR
//Default to using putchar, which is defined in stdio.h above
#define UNITY_OUTPUT_CHAR(a) putchar(a)
#else
//If defined as something else, make sure we declare it here so it's ready for use
extern int UNITY_OUTPUT_CHAR(int);
#endif
//-------------------------------------------------------
// Footprint
//-------------------------------------------------------
#ifndef UNITY_LINE_TYPE
#define UNITY_LINE_TYPE unsigned short
#endif
#ifndef UNITY_COUNTER_TYPE
#define UNITY_COUNTER_TYPE unsigned short
#endif
//-------------------------------------------------------
// Internal Structs Needed
//-------------------------------------------------------
typedef void (*UnityTestFunction)(void);
#define UNITY_DISPLAY_RANGE_INT (0x10)
#define UNITY_DISPLAY_RANGE_UINT (0x20)
#define UNITY_DISPLAY_RANGE_HEX (0x40)
#define UNITY_DISPLAY_RANGE_AUTO (0x80)
typedef enum
{
UNITY_DISPLAY_STYLE_INT = 4 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO,
UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT,
UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT,
UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT,
#endif
UNITY_DISPLAY_STYLE_UINT = 4 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO,
UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT,
UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT,
UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT,
#endif
UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX,
UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX,
UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX,
#ifdef UNITY_SUPPORT_64
UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX,
#endif
} UNITY_DISPLAY_STYLE_T;
struct _Unity
{
const char* TestFile;
const char* CurrentTestName;
_UU32 CurrentTestLineNumber;
UNITY_COUNTER_TYPE NumberOfTests;
UNITY_COUNTER_TYPE TestFailures;
UNITY_COUNTER_TYPE TestIgnores;
UNITY_COUNTER_TYPE CurrentTestFailed;
UNITY_COUNTER_TYPE CurrentTestIgnored;
jmp_buf AbortFrame;
};
extern struct _Unity Unity;
//-------------------------------------------------------
// Test Suite Management
//-------------------------------------------------------
void UnityBegin(void);
int UnityEnd(void);
void UnityConcludeTest(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
//-------------------------------------------------------
// Test Output
//-------------------------------------------------------
void UnityPrint(const char* string);
void UnityPrintMask(const _U_UINT mask, const _U_UINT number);
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style);
void UnityPrintNumber(const _U_SINT number);
void UnityPrintNumberUnsigned(const _U_UINT number);
void UnityPrintNumberHex(const _U_UINT number, const char nibbles);
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(const _UF number);
#endif
//-------------------------------------------------------
// Test Assertion Fuctions
//-------------------------------------------------------
// Use the macros below this section instead of calling
// these directly. The macros have a consistent naming
// convention and will pull in file and line information
// for you.
void UnityAssertEqualNumber(const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertEqualIntArray(const _U_SINT* expected,
const _U_SINT* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityAssertBits(const _U_SINT mask,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualStringArray( const char** expected,
const char** actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualMemory( const void* expected,
const void* actual,
const _UU32 length,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertNumbersWithin(const _U_SINT delta,
const _U_SINT expected,
const _U_SINT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style);
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
#ifndef UNITY_EXCLUDE_FLOAT
void UnityAssertFloatsWithin(const _UF delta,
const _UF expected,
const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualFloatArray(const _UF* expected,
const _UF* actual,
const _UU32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
#endif
//-------------------------------------------------------
// Basic Fail and Ignore
//-------------------------------------------------------
#define UNITY_TEST_FAIL(line, message) UnityFail( (message), (UNITY_LINE_TYPE)line);
#define UNITY_TEST_IGNORE(line, message) UnityIgnore( (message), (UNITY_LINE_TYPE)line);
//-------------------------------------------------------
// Test Asserts
//-------------------------------------------------------
#define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, message);}
#define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((_U_SINT)(mask), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER)
#define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT8)
#define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT16)
#define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT32)
#define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
#define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT8)
#define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT16)
#define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT32)
#define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
#define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
#define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
#define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((const char**)(expected), (const char**)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#ifdef UNITY_SUPPORT_64
#define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
#define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
#define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
#endif
#ifdef UNITY_EXCLUDE_FLOAT
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#else
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#endif
#endif

View File

@@ -0,0 +1,97 @@
#include "unity_test_module.h"
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "unity.h"
void (*unity_setUp_ptr)(void) = NULL;
void (*unit_tearDown_ptr)(void) = NULL;
#ifdef UNITY_USE_MODULE_SETUP_TEARDOWN
void setUp()
{
if(unity_setUp_ptr != NULL) unity_setUp_ptr();
}
void tearDown()
{
if(unit_tearDown_ptr != NULL) unit_tearDown_ptr();
}
#endif
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) )
{
unity_setUp_ptr = setUp;
unit_tearDown_ptr = tearDown;
}
void UnityUnregisterSetupTearDown(void)
{
unity_setUp_ptr = NULL;
unit_tearDown_ptr = NULL;
}
UnityTestModule* UnityTestModuleFind(
UnityTestModule* modules,
size_t number_of_modules,
char* wantedModule)
{
for(size_t i = 0; i < number_of_modules; i++) {
if(strcmp(wantedModule, modules[i].name) == 0) {
return &modules[i];
}
}
return NULL;
}
void UnityTestModuleRunRequestedModules(
int number_of_requested_modules,
char* requested_modules_names[],
UnityTestModule* allModules,
size_t number_of_modules )
{
for(int i = 0; i < number_of_requested_modules; i++)
{
UnityTestModule* module = UnityTestModuleFind(allModules,
number_of_modules, requested_modules_names[i]);
if(module != NULL)
{
module->run_tests();
}
else
{
printf("Ignoring: could not find requested module: %s\n",
requested_modules_names[i]);
}
}
}
int UnityTestModuleRun(
int argc,
char * argv[],
UnityTestModule* allModules,
size_t number_of_modules)
{
UnityBegin();
bool moduleRequests = (argc > 1);
if(moduleRequests)
{
UnityTestModuleRunRequestedModules(argc-1, &argv[1],
allModules, number_of_modules);
}
else
{
for(size_t i = 0; i < number_of_modules; i++)
{
allModules[i].run_tests();
}
}
return UnityEnd();
}

View File

@@ -0,0 +1,31 @@
#ifndef UNITY_TEST_MODULE_H
#define UNITY_TEST_MODULE_H
#include <stddef.h>
typedef struct {
char name[24];
void(*run_tests)(void);
} UnityTestModule;
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) );
void UnityUnregisterSetupTearDown(void);
UnityTestModule* UnityTestModuleFind(
UnityTestModule* modules,
size_t number_of_modules,
char* wantedModule);
void UnityTestModuleRunRequestedModules(
int number_of_requested_modules,
char* requested_modules_names[],
UnityTestModule* allModules,
size_t number_of_modules );
int UnityTestModuleRun(
int argc,
char * argv[],
UnityTestModule* allModules,
size_t number_of_modules);
#endif

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More