sync
This commit is contained in:
BIN
C/Adidas.zip
Normal file
BIN
C/Adidas.zip
Normal file
Binary file not shown.
9
C/Adidas/.gitignore
vendored
Normal file
9
C/Adidas/.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
encode
|
||||
channel
|
||||
decode
|
||||
encode_test
|
||||
channel_test
|
||||
decode_test
|
||||
a.tmp
|
||||
b.tmp
|
||||
c.tmp
|
||||
BIN
C/Adidas/Adidas-module-design.pptx
Normal file
BIN
C/Adidas/Adidas-module-design.pptx
Normal file
Binary file not shown.
BIN
C/Adidas/Assignment - Adidas.docx
Normal file
BIN
C/Adidas/Assignment - Adidas.docx
Normal file
Binary file not shown.
62
C/Adidas/Makefile
Normal file
62
C/Adidas/Makefile
Normal file
@@ -0,0 +1,62 @@
|
||||
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 -O0 -std=c99
|
||||
|
||||
TEST_SYMBOLS=$(SYMBOLS) -DTEST -DUNITY_USE_MODULE_SETUP_TEARDOWN
|
||||
|
||||
.PHONY: clean test
|
||||
|
||||
all: $(PROD_EXEC) $(TEST_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) encode Makefile a.tmp
|
||||
@./$(BUILD_DIR)/$(PROD_EXEC) channel a.tmp b.tmp
|
||||
@./$(BUILD_DIR)/$(PROD_EXEC) decode b.tmp c.tmp
|
||||
cmp Makefile c.tmp
|
||||
|
||||
test: $(TEST_EXEC)
|
||||
@./$(BUILD_DIR)/$(TEST_EXEC)
|
||||
|
||||
encode_test : $(TEST_EXEC)
|
||||
@./$(BUILD_DIR)/$(TEST_EXEC) encode
|
||||
|
||||
channel_test : $(TEST_EXEC)
|
||||
@./$(BUILD_DIR)/$(TEST_EXEC) channel
|
||||
|
||||
decode_test : $(TEST_EXEC)
|
||||
@./$(BUILD_DIR)/$(TEST_EXEC) decode
|
||||
|
||||
parity_test : $(TEST_EXEC)
|
||||
@./$(BUILD_DIR)/$(TEST_EXEC) parity
|
||||
|
||||
testio : $(TEST_EXEC)
|
||||
@./$(BUILD_DIR)/$(TEST_EXEC) io
|
||||
|
||||
clean:
|
||||
rm -f $(BUILD_DIR)/$(PROD_EXEC)
|
||||
rm -f $(BUILD_DIR)/$(TEST_EXEC)
|
||||
841
C/Adidas/Unity/unity.c
Normal file
841
C/Adidas/Unity/unity.c
Normal 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;
|
||||
}
|
||||
209
C/Adidas/Unity/unity.h
Normal file
209
C/Adidas/Unity/unity.h
Normal 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
|
||||
356
C/Adidas/Unity/unity_internals.h
Normal file
356
C/Adidas/Unity/unity_internals.h
Normal 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
|
||||
97
C/Adidas/Unity/unity_test_module.c
Normal file
97
C/Adidas/Unity/unity_test_module.c
Normal 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();
|
||||
}
|
||||
31
C/Adidas/Unity/unity_test_module.h
Normal file
31
C/Adidas/Unity/unity_test_module.h
Normal 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
|
||||
1
C/Adidas/build/.gitkeep
Normal file
1
C/Adidas/build/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
BIN
C/Adidas/build/main_test
Executable file
BIN
C/Adidas/build/main_test
Executable file
Binary file not shown.
9
C/Adidas/product/channel_main.c
Normal file
9
C/Adidas/product/channel_main.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "channel.h"
|
||||
// add here includes, if needed
|
||||
|
||||
int channel_main(int argc, char* argv[])
|
||||
{
|
||||
//add your code here
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
C/Adidas/product/decode_main.c
Normal file
10
C/Adidas/product/decode_main.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "decode.h"
|
||||
// add here includes, if needed
|
||||
|
||||
|
||||
int decode_main(int argc, char* argv[])
|
||||
{
|
||||
//add your code here
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
C/Adidas/product/encode_main.c
Normal file
10
C/Adidas/product/encode_main.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "encode.h"
|
||||
// add here includes, if needed
|
||||
|
||||
|
||||
int encode_main(int argc, char* argv[])
|
||||
{
|
||||
//add your code here
|
||||
|
||||
return 0;
|
||||
}
|
||||
38
C/Adidas/product/main.c
Normal file
38
C/Adidas/product/main.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "encode.h"
|
||||
|
||||
extern int encode_main(int argc, char* argv[]);
|
||||
extern int channel_main(int argc, char* argv[]);
|
||||
extern int decode_main(int argc, char* argv[]);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 4)
|
||||
{
|
||||
printf("Please provide file name arguments:\n");
|
||||
printf("[encode|channel|decode] inputfile outpfile\n\n");
|
||||
printf("Example:\n");
|
||||
printf("main encode input.txt output.txt\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf("%s: %s --> %s\n", argv[1], argv[2], argv[3]);
|
||||
|
||||
if(strcmp("encode", argv[1]) == 0)
|
||||
{
|
||||
return encode_main(argc,argv);
|
||||
}
|
||||
else if(strcmp("channel", argv[1]) == 0)
|
||||
{
|
||||
return channel_main(argc,argv);
|
||||
}
|
||||
else if(strcmp("decode", argv[1]) == 0)
|
||||
{
|
||||
return decode_main(argc,argv);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
40
C/Adidas/shared/bit_stuff.c
Normal file
40
C/Adidas/shared/bit_stuff.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "bit_stuff.h"
|
||||
#include <limits.h>
|
||||
#include <stddef.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);
|
||||
}
|
||||
36
C/Adidas/shared/bit_stuff.h
Normal file
36
C/Adidas/shared/bit_stuff.h
Normal 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);
|
||||
4
C/Adidas/shared/channel.c
Normal file
4
C/Adidas/shared/channel.c
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "channel.h"
|
||||
// add here includes, if needed
|
||||
|
||||
// add here your implementation
|
||||
22
C/Adidas/shared/channel.h
Normal file
22
C/Adidas/shared/channel.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef CHANNEL_H
|
||||
#define CHANNEL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/*!
|
||||
* Initialiase the channel module
|
||||
*/
|
||||
void channel_init();
|
||||
|
||||
/*!
|
||||
* Randomly invert one the bits of the input 'value' parameter
|
||||
*
|
||||
* @param value: A byte
|
||||
*
|
||||
* @return: The input 'value' where on of the bits is randomly inverted
|
||||
*/
|
||||
uint8_t channel_change_one_random_bit(uint8_t value);
|
||||
|
||||
#endif
|
||||
|
||||
4
C/Adidas/shared/decode.c
Normal file
4
C/Adidas/shared/decode.c
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "decode.h"
|
||||
// add here includes, if needed
|
||||
|
||||
// add here your implementation
|
||||
28
C/Adidas/shared/decode.h
Normal file
28
C/Adidas/shared/decode.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef DECODE_H_
|
||||
#define DECODE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*!
|
||||
* Combines the nibbles located at the 4-least-significant bits of
|
||||
* parameters 'low' and 'high' into one byte.
|
||||
*
|
||||
* @param high: A nibble that contains the 4 most-significant bits
|
||||
* @param low: A nibble that contains the 4 most-significant bits
|
||||
*
|
||||
* @return: A byte that combines the high and low nibble.
|
||||
*/
|
||||
uint8_t decode_combine_nibbles(uint8_t high, uint8_t low);
|
||||
|
||||
/*!
|
||||
* Decodes a nibble from a byte that contains the nible (4-bits) and
|
||||
* corresponding parity bits (3-bits). See assignment for more details.
|
||||
*
|
||||
* @param in: A bytes that contains a nibble and parity bits.
|
||||
* @param nibble: The address to which the decoded nibble
|
||||
* of 'in' will be written.
|
||||
*
|
||||
*/
|
||||
void decode_byte(uint8_t in, uint8_t* nibble);
|
||||
|
||||
#endif
|
||||
34
C/Adidas/shared/encode.c
Normal file
34
C/Adidas/shared/encode.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "encode.h"
|
||||
#include "parity.h"
|
||||
#include "bit_stuff.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
void encode_get_nibbles(uint8_t value, uint8_t* high, uint8_t* low) {
|
||||
if (high == NULL || low == NULL) {
|
||||
return;
|
||||
}
|
||||
// Just extract the nibbles without encoding them
|
||||
extract_nibbles_from_byte(value, high, low);
|
||||
}
|
||||
|
||||
uint8_t encode_nibble(uint8_t nibble) {
|
||||
uint8_t p0, p1, p2;
|
||||
calculate_parity_bits(nibble, &p0, &p1, &p2);
|
||||
// Format: [0][d3][d2][d1][d0][p2][p1][p0] (MSB first)
|
||||
return ((nibble & 0x0F) << 3) | (p2 << 2) | (p1 << 1) | p0;
|
||||
}
|
||||
|
||||
void encode_value(uint8_t input, uint8_t* high, uint8_t* low) {
|
||||
if (high == NULL || low == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t high_nibble, low_nibble;
|
||||
encode_get_nibbles(input, &high_nibble, &low_nibble);
|
||||
|
||||
// Encode each nibble with parity bits
|
||||
*high = encode_nibble(high_nibble);
|
||||
*low = encode_nibble(low_nibble);
|
||||
}
|
||||
33
C/Adidas/shared/encode.h
Normal file
33
C/Adidas/shared/encode.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef ENCODE_H_
|
||||
#define ENCODE_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*!
|
||||
* Split a byte 'value' into two nibbles (4-bits) named 'low' and 'high'.
|
||||
* See assignment for more details.
|
||||
*
|
||||
* @param value: A byte that will be encoded.
|
||||
* @param low: The address to which the 4 least-significant-bits
|
||||
* of 'value' will be written.
|
||||
* @param high: The address to which the 4 most-significant-bits
|
||||
* of 'value' will be written.
|
||||
*/
|
||||
void encode_get_nibbles(uint8_t value, uint8_t* high, uint8_t* low);
|
||||
|
||||
/*!
|
||||
* Encodes a the byte 'value' into two bytes named 'low' and 'high'.
|
||||
* The encoded bytes contain the parity bits. See assignment for more details.
|
||||
*
|
||||
* @param value: A byte that will be encoded.
|
||||
* @param low: The address to which the encoded value of the
|
||||
* 4 least-significant-bits of 'value' will be written.
|
||||
* @param high: The address to which the encoded value of the
|
||||
* 4 most-significant-bits of 'value' will be written.
|
||||
*/
|
||||
void encode_value(uint8_t input, uint8_t* high, uint8_t* low);
|
||||
|
||||
uint8_t encode_nibble(uint8_t nibble);
|
||||
|
||||
#endif
|
||||
14
C/Adidas/shared/parity.c
Normal file
14
C/Adidas/shared/parity.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "parity.h"
|
||||
|
||||
void calculate_parity_bits(uint8_t nibble, uint8_t* p0, uint8_t* p1, uint8_t* p2) {
|
||||
// Extract each data bit
|
||||
uint8_t d0 = (nibble >> 0) & 1;
|
||||
uint8_t d1 = (nibble >> 1) & 1;
|
||||
uint8_t d2 = (nibble >> 2) & 1;
|
||||
uint8_t d3 = (nibble >> 3) & 1;
|
||||
|
||||
// Parity bits as per assignment examples
|
||||
*p0 = d0 ^ d1 ^ d2; // Circle with d0,d1,d2
|
||||
*p1 = d0 ^ d1 ^ d3; // Circle with d0,d1,d3
|
||||
*p2 = d0 ^ d2 ^ d3; // Circle with d0,d2,d3
|
||||
}
|
||||
8
C/Adidas/shared/parity.h
Normal file
8
C/Adidas/shared/parity.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef PARITY_H_
|
||||
#define PARITY_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void calculate_parity_bits(uint8_t nibble, uint8_t* p0, uint8_t* p1, uint8_t* p2);
|
||||
|
||||
#endif
|
||||
31
C/Adidas/test/channel_test.c
Normal file
31
C/Adidas/test/channel_test.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "unity.h"
|
||||
#include "unity_test_module.h"
|
||||
#include "channel.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)
|
||||
|
||||
extern void channel_setUp(void)
|
||||
{
|
||||
// This is run before EACH test
|
||||
}
|
||||
|
||||
extern void channel_tearDown(void)
|
||||
{
|
||||
// This is run after EACH test
|
||||
}
|
||||
|
||||
static void test_channel(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(1, 0);
|
||||
}
|
||||
|
||||
void run_channel_tests()
|
||||
{
|
||||
UnityRegisterSetupTearDown( channel_setUp, channel_tearDown);
|
||||
|
||||
MY_RUN_TEST(test_channel);
|
||||
|
||||
UnityUnregisterSetupTearDown();
|
||||
}
|
||||
30
C/Adidas/test/decode_test.c
Normal file
30
C/Adidas/test/decode_test.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "unity.h"
|
||||
#include "unity_test_module.h"
|
||||
#include "decode.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)
|
||||
|
||||
extern void decode_setUp(void)
|
||||
{
|
||||
// This is run before EACH test
|
||||
}
|
||||
|
||||
extern void decode_tearDown(void)
|
||||
{
|
||||
// This is run after EACH test
|
||||
}
|
||||
|
||||
void test_decode(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(1, 0);
|
||||
}
|
||||
|
||||
void run_decode_tests()
|
||||
{
|
||||
UnityRegisterSetupTearDown( decode_setUp, decode_tearDown);
|
||||
|
||||
MY_RUN_TEST(test_decode);
|
||||
|
||||
UnityUnregisterSetupTearDown();
|
||||
}
|
||||
64
C/Adidas/test/encode_test.c
Normal file
64
C/Adidas/test/encode_test.c
Normal file
@@ -0,0 +1,64 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "unity.h"
|
||||
#include "parity.h"
|
||||
#include "unity_test_module.h"
|
||||
#include "encode.h"
|
||||
|
||||
// Macro om zonder regelnummers te testen
|
||||
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
|
||||
|
||||
extern void encode_setUp(void) {}
|
||||
extern void encode_tearDown(void) {}
|
||||
|
||||
void test_encode_get_nibbles_normal(void) {
|
||||
uint8_t high, low;
|
||||
encode_get_nibbles(0xAB, &high, &low);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x0A, high); // High nibble of 0xAB is 0xA
|
||||
TEST_ASSERT_EQUAL_UINT8(0x0B, low); // Low nibble of 0xAB is 0xB
|
||||
}
|
||||
|
||||
void test_encode_get_nibbles_null_ptrs(void) {
|
||||
encode_get_nibbles(0xAA, NULL, NULL); // Should not crash
|
||||
}
|
||||
|
||||
void test_encode_value_normal(void) {
|
||||
uint8_t high, low;
|
||||
encode_value(0x41, &high, &low);
|
||||
//0x41 = 01000001 --> nibHigh = 0x04, and nibLow = 0x01
|
||||
// Format: [0][d3][d2][d1][d0][p2][p1][p0] (MSB first)
|
||||
//high: 0 0100 101 --> 0x25
|
||||
//low: 0 0001 111 --> 0x0F
|
||||
TEST_ASSERT_EQUAL_HEX8(0x25, high);
|
||||
TEST_ASSERT_EQUAL_HEX8(0x0F, low);
|
||||
}
|
||||
|
||||
void test_encode_value_null_pointers(void) {
|
||||
encode_value(0x55, NULL, NULL); // Should not crash
|
||||
}
|
||||
|
||||
void test_encode_value_all_zeros(void) {
|
||||
uint8_t high, low;
|
||||
encode_value(0x00, &high, &low);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, high);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, low);
|
||||
}
|
||||
|
||||
void test_encode_nibble_values(void) {
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, encode_nibble(0x00)); // All zeros
|
||||
TEST_ASSERT_EQUAL_UINT8(0x7F, encode_nibble(0x0F)); // All ones in nibble
|
||||
TEST_ASSERT_EQUAL_UINT8(0x55, encode_nibble(0x0A)); // 1010 pattern
|
||||
}
|
||||
|
||||
void run_encode_tests() {
|
||||
UnityRegisterSetupTearDown(encode_setUp, encode_tearDown);
|
||||
|
||||
MY_RUN_TEST(test_encode_get_nibbles_normal);
|
||||
MY_RUN_TEST(test_encode_get_nibbles_null_ptrs);
|
||||
MY_RUN_TEST(test_encode_value_normal);
|
||||
MY_RUN_TEST(test_encode_value_null_pointers);
|
||||
MY_RUN_TEST(test_encode_value_all_zeros);
|
||||
MY_RUN_TEST(test_encode_nibble_values);
|
||||
|
||||
UnityUnregisterSetupTearDown();
|
||||
}
|
||||
29
C/Adidas/test/main.c
Normal file
29
C/Adidas/test/main.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#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_encode_tests();
|
||||
extern void run_channel_tests();
|
||||
extern void run_decode_tests();
|
||||
extern void run_parity_tests();
|
||||
/*
|
||||
* You can add here additional run_XXX_tests modules, if needed. Can be handy when you have
|
||||
* code that can be used by the encoder as well as the decoder.
|
||||
* Then you need to add additional files!
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
int main (int argc, char * argv[])
|
||||
{
|
||||
UnityTestModule allModules[] = { { "encode", run_encode_tests},
|
||||
{ "parity", run_parity_tests},
|
||||
{ "channel", run_channel_tests},
|
||||
{ "decode", run_decode_tests}
|
||||
};
|
||||
|
||||
size_t number_of_modules = sizeof(allModules)/sizeof(allModules[0]);
|
||||
|
||||
return UnityTestModuleRun(argc, argv, allModules, number_of_modules);
|
||||
}
|
||||
42
C/Adidas/test/parity_test.c
Normal file
42
C/Adidas/test/parity_test.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "unity.h"
|
||||
#include "unity_test_module.h"
|
||||
#include "parity.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)
|
||||
|
||||
extern void parity_setUp(void){
|
||||
// This is run before EACH test
|
||||
}
|
||||
|
||||
extern void parity_tearDown(void){
|
||||
// This is run after EACH test
|
||||
}
|
||||
|
||||
void test_calculate_parity_bits_all_zeros(void) {
|
||||
uint8_t p0, p1, p2;
|
||||
calculate_parity_bits(0x00, &p0, &p1, &p2);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, p0);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, p1);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, p2);
|
||||
}
|
||||
|
||||
void test_calculate_parity_bits_all_ones(void) {
|
||||
uint8_t p0, p1, p2;
|
||||
calculate_parity_bits(0x0F, &p0, &p1, &p2);
|
||||
// 0x0F = 1111
|
||||
// dus p0, p1 en p2 zijn '1'
|
||||
TEST_ASSERT_EQUAL_UINT8(1, p0);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, p1);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, p2);
|
||||
}
|
||||
|
||||
// Update run_parity_tests function
|
||||
void run_parity_tests(void) {
|
||||
UnityRegisterSetupTearDown(parity_setUp, parity_tearDown);
|
||||
|
||||
MY_RUN_TEST(test_calculate_parity_bits_all_zeros);
|
||||
MY_RUN_TEST(test_calculate_parity_bits_all_ones);
|
||||
|
||||
UnityUnregisterSetupTearDown();
|
||||
}
|
||||
9
C/C1/.vscode/settings.json
vendored
Normal file
9
C/C1/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"bike_measure.h": "c",
|
||||
"stdint.h": "c",
|
||||
"bike_store.h": "c",
|
||||
"stdlib.h": "c",
|
||||
"unistd.h": "c"
|
||||
}
|
||||
}
|
||||
21
C/C1/Makefile
Normal file
21
C/C1/Makefile
Normal file
@@ -0,0 +1,21 @@
|
||||
NAME=main
|
||||
|
||||
FILES = $(wildcard *.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)
|
||||
|
||||
69
C/C1/bike_math.c
Normal file
69
C/C1/bike_math.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "bike_math.h"
|
||||
#include "bike_store.h"
|
||||
|
||||
uint16_t bikeMathGetValueForDataType(bikeStoreMeasurement measurement, bikeDataType data_type) {
|
||||
uint16_t value = 0;
|
||||
|
||||
if (data_type == BIKECADENCE) {
|
||||
value = measurement.cadence;
|
||||
} else if (data_type == BIKESPEED) {
|
||||
value = measurement.speed;
|
||||
} else if (data_type == BIKEHEARTRATE) {
|
||||
value = measurement.heartRate;
|
||||
} else if (data_type == BIKEPOWER) {
|
||||
value = measurement.power;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
uint16_t bikeMathCalculateMinValue(bikeDataType data_type) {
|
||||
uint16_t number_of_measurements = bikeStoreGetNumberOfMeasurementsPresent();
|
||||
|
||||
uint16_t min_value = UINT16_MAX;
|
||||
|
||||
for (uint16_t index_position = 0; index_position < number_of_measurements; index_position++) {
|
||||
bikeStoreMeasurement measurement = bikeStoreGetMeasurement(index_position);
|
||||
uint16_t value = bikeMathGetValueForDataType(measurement, data_type);
|
||||
if (value < min_value) {
|
||||
min_value = value;
|
||||
}
|
||||
}
|
||||
|
||||
return min_value;
|
||||
}
|
||||
|
||||
uint16_t bikeMathCalculateMaxValue(bikeDataType data_type) {
|
||||
uint16_t number_of_measurements = bikeStoreGetNumberOfMeasurementsPresent();
|
||||
|
||||
uint16_t max_value = 0;
|
||||
|
||||
for (uint16_t index_position = 0; index_position < number_of_measurements; index_position++) {
|
||||
bikeStoreMeasurement measurement = bikeStoreGetMeasurement(index_position);
|
||||
uint16_t value = bikeMathGetValueForDataType(measurement, data_type);
|
||||
if (value > max_value) {
|
||||
max_value = value;
|
||||
}
|
||||
}
|
||||
|
||||
return max_value;
|
||||
}
|
||||
|
||||
uint16_t bikeMathCalculateAverageValue(bikeDataType data_type) {
|
||||
uint16_t number_of_measurements = bikeStoreGetNumberOfMeasurementsPresent();
|
||||
|
||||
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++) {
|
||||
bikeStoreMeasurement measurement = bikeStoreGetMeasurement(index_position);
|
||||
uint16_t value = bikeMathGetValueForDataType(measurement, data_type);
|
||||
sum += value;
|
||||
}
|
||||
|
||||
average = sum / number_of_measurements;
|
||||
|
||||
return average;
|
||||
}
|
||||
19
C/C1/bike_math.h
Normal file
19
C/C1/bike_math.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef BIKE_MATH_H
|
||||
#define BIKE_MATH_H
|
||||
|
||||
#include <stdint.h>
|
||||
//#include "bike_store.h"
|
||||
|
||||
typedef enum {
|
||||
BIKESPEED,
|
||||
BIKEHEARTRATE,
|
||||
BIKECADENCE,
|
||||
BIKEPOWER
|
||||
} bikeDataType;
|
||||
|
||||
uint16_t bikeMathCalculateMinValue(bikeDataType dataType);
|
||||
uint16_t bikeMathCalculateMaxValue(bikeDataType dataType);
|
||||
uint16_t bikeMathCalculateAverageValue(bikeDataType dataType);
|
||||
//uint16_t bikeMathGetValueForDataType(bikeStoreMeasurement measurement, bikeDataType dataType);
|
||||
|
||||
#endif
|
||||
47
C/C1/bike_measure.c
Normal file
47
C/C1/bike_measure.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "bike_measure.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.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_HEARTRATE (130)
|
||||
#define BIKE_COMPUTER_SIMULATOR_VALUE_MAX_HEARTRATE (140)
|
||||
|
||||
#define BIKE_COMPUTER_SIMULATOR_VALUE_MIN_CADENCE (88)
|
||||
#define BIKE_COMPUTER_SIMULATOR_VALUE_MAX_CADENCE (98)
|
||||
|
||||
static uint16_t bikeComputerSimulatorGetRandomValue(uint16_t minRange, uint16_t maxRange) {
|
||||
uint16_t range = (maxRange - minRange);
|
||||
|
||||
uint16_t randomValue = minRange + (rand() % range);
|
||||
|
||||
return randomValue;
|
||||
}
|
||||
|
||||
uint16_t bikeMeasureSpeedInKmh() {
|
||||
return bikeComputerSimulatorGetRandomValue(
|
||||
BIKE_COMPUTER_SIMULATOR_VALUE_MIN_SPEED,
|
||||
BIKE_COMPUTER_SIMULATOR_VALUE_MAX_SPEED);
|
||||
}
|
||||
|
||||
uint16_t bikeMeasurePowerInWatt() {
|
||||
return bikeComputerSimulatorGetRandomValue(
|
||||
BIKE_COMPUTER_SIMULATOR_VALUE_MIN_POWER,
|
||||
BIKE_COMPUTER_SIMULATOR_VALUE_MAX_POWER);
|
||||
}
|
||||
|
||||
uint16_t bikeMeasureCadenceInRpm() {
|
||||
return bikeComputerSimulatorGetRandomValue(
|
||||
BIKE_COMPUTER_SIMULATOR_VALUE_MIN_CADENCE,
|
||||
BIKE_COMPUTER_SIMULATOR_VALUE_MAX_CADENCE);
|
||||
}
|
||||
|
||||
uint16_t bikeMeasureHeartRateInBpm() {
|
||||
return bikeComputerSimulatorGetRandomValue(
|
||||
BIKE_COMPUTER_SIMULATOR_VALUE_MIN_HEARTRATE,
|
||||
BIKE_COMPUTER_SIMULATOR_VALUE_MAX_HEARTRATE);
|
||||
}
|
||||
11
C/C1/bike_measure.h
Normal file
11
C/C1/bike_measure.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef BIKE_MEASURE_H
|
||||
#define BIKE_MEASURE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint16_t bikeMeasureSpeedInKmh();
|
||||
uint16_t bikeMeasurePowerInWatt();
|
||||
uint16_t bikeMeasureCadenceInRpm();
|
||||
uint16_t bikeMeasureHeartRateInBpm();
|
||||
|
||||
#endif
|
||||
31
C/C1/bike_store.c
Normal file
31
C/C1/bike_store.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "bike_store.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define BIKE_STORE_MAX_NUMBER_MEASUREMENTS (32)
|
||||
|
||||
static uint16_t bikeStoreGetMaximumBikeStoreSize() {
|
||||
return BIKE_STORE_MAX_NUMBER_MEASUREMENTS;
|
||||
}
|
||||
|
||||
static bikeStoreMeasurement bikeStoreArray[BIKE_STORE_MAX_NUMBER_MEASUREMENTS] = {{ 0, },};
|
||||
|
||||
static uint16_t bikeStoreNumberOfMeasurementsPresent = 0;
|
||||
|
||||
void bikeStoreAddMeasurement(bikeStoreMeasurement value)
|
||||
{
|
||||
if (bikeStoreNumberOfMeasurementsPresent >= bikeStoreGetMaximumBikeStoreSize()) {
|
||||
bikeStoreNumberOfMeasurementsPresent = 0;
|
||||
}
|
||||
bikeStoreArray[bikeStoreNumberOfMeasurementsPresent] = value;
|
||||
bikeStoreNumberOfMeasurementsPresent++;
|
||||
}
|
||||
|
||||
uint16_t bikeStoreGetNumberOfMeasurementsPresent() {
|
||||
return bikeStoreNumberOfMeasurementsPresent;
|
||||
}
|
||||
|
||||
bikeStoreMeasurement bikeStoreGetMeasurement(uint16_t indexPosition) {
|
||||
bikeStoreMeasurement value = bikeStoreArray[indexPosition];
|
||||
|
||||
return value;
|
||||
}
|
||||
18
C/C1/bike_store.h
Normal file
18
C/C1/bike_store.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef BIKE_STORE_H
|
||||
#define BIKE_STORE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint16_t speed;
|
||||
uint16_t heartRate;
|
||||
uint16_t cadence;
|
||||
uint16_t power;
|
||||
} bikeStoreMeasurement;
|
||||
|
||||
void bikeStoreAddMeasurement(bikeStoreMeasurement value);
|
||||
uint16_t bikeStoreGetNumberOfMeasurementsPresent();
|
||||
bikeStoreMeasurement bikeStoreGetMeasurement(uint16_t indexPosition);
|
||||
//uint16_t bikeStoreGetMaximumBikeStoreSize();
|
||||
|
||||
#endif
|
||||
51
C/C1/main.c
Normal file
51
C/C1/main.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "bike_store.h"
|
||||
#include "bike_math.h"
|
||||
#include "bike_measure.h"
|
||||
|
||||
#define True (1)
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
bikeStoreMeasurement measurement;
|
||||
uint16_t min = 0, max = 0, average = 0;
|
||||
bikeDataType dataType;
|
||||
|
||||
while (True) {
|
||||
measurement.speed = bikeMeasureSpeedInKmh();
|
||||
measurement.cadence = bikeMeasureCadenceInRpm();
|
||||
measurement.heartRate = bikeMeasureHeartRateInBpm();
|
||||
measurement.power = bikeMeasurePowerInWatt();
|
||||
|
||||
bikeStoreAddMeasurement(measurement);
|
||||
|
||||
dataType = BIKESPEED;
|
||||
min = bikeMathCalculateMinValue(dataType);
|
||||
max = bikeMathCalculateMaxValue(dataType);
|
||||
average = bikeMathCalculateAverageValue(dataType);
|
||||
printf("SPEED:\t%d, average = %d, min = %d, max = %d [km/h]\n", measurement.speed, average, min, max);
|
||||
|
||||
dataType = BIKECADENCE;
|
||||
min = bikeMathCalculateMinValue(dataType);
|
||||
max = bikeMathCalculateMaxValue(dataType);
|
||||
average = bikeMathCalculateAverageValue(dataType);
|
||||
printf("CADENCE:\t%d, average = %d, min = %d, max = %d [rpm]\n", measurement.cadence, average, min, max);
|
||||
|
||||
dataType = BIKEHEARTRATE;
|
||||
min = bikeMathCalculateMinValue(dataType);
|
||||
max = bikeMathCalculateMaxValue(dataType);
|
||||
average = bikeMathCalculateAverageValue(dataType);
|
||||
printf("HEART-RATE:\t%d, average = %d, min = %d, max = %d [hrm]\n", measurement.heartRate, average, min, max);
|
||||
|
||||
dataType = BIKEPOWER;
|
||||
min = bikeMathCalculateMinValue(dataType);
|
||||
max = bikeMathCalculateMaxValue(dataType);
|
||||
average = bikeMathCalculateAverageValue(dataType);
|
||||
printf("POWER:\t%d, average = %d, min = %d, max = %d [watt]\n", measurement.power, average, min, max);
|
||||
printf("\n");
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
18
C/C2/.vscode/c_cpp_properties.json
vendored
Normal file
18
C/C2/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
32
C/C2/.vscode/launch.json
vendored
Normal file
32
C/C2/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug",
|
||||
"program": "${workspaceFolder}/<executable file>",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": false,
|
||||
"cwd": "/home/rens/T2/C/C2",
|
||||
"program": "/home/rens/T2/C/C2/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
59
C/C2/.vscode/settings.json
vendored
Normal file
59
C/C2/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||
}
|
||||
BIN
C/C2/2-Assignment - AnimalShelter.docx
Normal file
BIN
C/C2/2-Assignment - AnimalShelter.docx
Normal file
Binary file not shown.
44
C/C2/Makefile
Normal file
44
C/C2/Makefile
Normal 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)
|
||||
841
C/C2/Unity/unity.c
Normal file
841
C/C2/Unity/unity.c
Normal 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;
|
||||
}
|
||||
209
C/C2/Unity/unity.h
Normal file
209
C/C2/Unity/unity.h
Normal 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
|
||||
356
C/C2/Unity/unity_internals.h
Normal file
356
C/C2/Unity/unity_internals.h
Normal 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
|
||||
97
C/C2/Unity/unity_test_module.c
Normal file
97
C/C2/Unity/unity_test_module.c
Normal 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();
|
||||
}
|
||||
31
C/C2/Unity/unity_test_module.h
Normal file
31
C/C2/Unity/unity_test_module.h
Normal 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
|
||||
BIN
C/C2/assignment.pdf
Normal file
BIN
C/C2/assignment.pdf
Normal file
Binary file not shown.
BIN
C/C2/build/main
Executable file
BIN
C/C2/build/main
Executable file
Binary file not shown.
BIN
C/C2/build/main_test
Normal file
BIN
C/C2/build/main_test
Normal file
Binary file not shown.
160
C/C2/product/main.c
Normal file
160
C/C2/product/main.c
Normal file
@@ -0,0 +1,160 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "administration.h"
|
||||
#include "animal.h"
|
||||
#include "terminal_io.h"
|
||||
#include "file_element.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:
|
||||
{
|
||||
Animal newAnimal;
|
||||
newAnimal.Id = getInt("Enter animal ID: ");
|
||||
newAnimal.Species = (Species)getLimitedInt("Enter species: ", SpeciesNames, sizeof(SpeciesNames) / sizeof(SpeciesNames[0]));
|
||||
newAnimal.Sex = (Sex)getLimitedInt("Enter sex: ", SexNames, sizeof(SexNames) / sizeof(SexNames[0]));
|
||||
newAnimal.Age = getInt("Enter age: ");
|
||||
newAnimal.DateFound = getDate("Enter date found: ");
|
||||
if (addAnimal(&newAnimal, animals, MaxNrAnimals, nrAnimals, &nrAnimals) == 0)
|
||||
{
|
||||
printf("Animal added successfully.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed to add animal.\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MO_REMOVE_ANIMAL:
|
||||
{
|
||||
int animalId = getInt("Enter animal ID to remove: ");
|
||||
size_t newNrAnimals;
|
||||
if (removeAnimal(animalId, animals, nrAnimals, &newNrAnimals) >= 0)
|
||||
{
|
||||
nrAnimals = newNrAnimals;
|
||||
printf("Animal removed successfully.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed to remove animal.\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MO_SORT_ANIMALS_BY_AGE:
|
||||
if (sortAnimalsByAge(animals, nrAnimals) == 0)
|
||||
{
|
||||
printf("Animals sorted by age successfully.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed to sort animals by age.\n");
|
||||
}
|
||||
break;
|
||||
case MO_SORT_ANIMALS_BY_YEAR_FOUND:
|
||||
if (sortAnimalsByYearFound(animals, nrAnimals) == 0)
|
||||
{
|
||||
printf("Animals sorted by year found successfully.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed to sort animals by year found.\n");
|
||||
}
|
||||
break;
|
||||
case MO_SORT_ANIMALS_BY_SEX:
|
||||
if (sortAnimalsBySex(animals, nrAnimals) == 0)
|
||||
{
|
||||
printf("Animals sorted by sex successfully.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed to sort animals by sex.\n");
|
||||
}
|
||||
break;
|
||||
case MO_FIND_ANIMAL:
|
||||
{
|
||||
int animalId = getInt("Enter animal ID to find: ");
|
||||
Animal foundAnimal;
|
||||
if (findAnimalById(animalId, animals, nrAnimals, &foundAnimal) == 1)
|
||||
{
|
||||
printf("Animal found:\n");
|
||||
printAnimals(&foundAnimal, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Animal not found.\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MO_SAVE:
|
||||
if (writeAnimals("animals.dat", animals, nrAnimals) == 0)
|
||||
{
|
||||
printf("Animals saved to disk successfully.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed to save animals to disk.\n");
|
||||
}
|
||||
break;
|
||||
case MO_LOAD:
|
||||
if (readAnimals("animals.dat", animals, MaxNrAnimals) >= 0)
|
||||
{
|
||||
printf("Animals loaded from disk successfully.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed to load animals from disk.\n");
|
||||
}
|
||||
break;
|
||||
case MO_QUIT:
|
||||
break;
|
||||
default:
|
||||
printf("ERROR: invalid choice: %d\n", choice);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
98
C/C2/product/terminal_io.c
Normal file
98
C/C2/product/terminal_io.c
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
C/C2/product/terminal_io.h
Normal file
25
C/C2/product/terminal_io.h
Normal 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
|
||||
22
C/C2/shared/administration.c
Normal file
22
C/C2/shared/administration.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "administration.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "animal.h"
|
||||
|
||||
|
||||
int removeAnimal(
|
||||
int animalId, Animal* animalArray,
|
||||
size_t numberOfAnimalsPresent,
|
||||
size_t* newNumberOfAnimalsPresent)
|
||||
{
|
||||
//add implementation
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// To do : add the missing functions
|
||||
|
||||
|
||||
56
C/C2/shared/administration.h
Normal file
56
C/C2/shared/administration.h
Normal 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
|
||||
33
C/C2/shared/animal.h
Normal file
33
C/C2/shared/animal.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#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
|
||||
35
C/C2/shared/file_element.c
Normal file
35
C/C2/shared/file_element.c
Normal 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;
|
||||
}
|
||||
66
C/C2/shared/file_element.h
Normal file
66
C/C2/shared/file_element.h
Normal 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
|
||||
35
C/C2/test/administration_test.c
Normal file
35
C/C2/test/administration_test.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#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)
|
||||
|
||||
void administration_setUp(void)
|
||||
{
|
||||
// This is run before EACH test
|
||||
}
|
||||
|
||||
void administration_tearDown(void)
|
||||
{
|
||||
// This is run after EACH test
|
||||
}
|
||||
|
||||
void test_EmptyTest(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(1, 0);
|
||||
}
|
||||
|
||||
//add here your testcases
|
||||
|
||||
void run_administration_tests()
|
||||
{
|
||||
UnityRegisterSetupTearDown(administration_setUp, administration_tearDown);
|
||||
|
||||
MY_RUN_TEST(test_EmptyTest);
|
||||
|
||||
UnityUnregisterSetupTearDown();
|
||||
}
|
||||
|
||||
34
C/C2/test/file_element_test.c
Normal file
34
C/C2/test/file_element_test.c
Normal 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();
|
||||
}
|
||||
19
C/C2/test/main.c
Normal file
19
C/C2/test/main.c
Normal 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);
|
||||
}
|
||||
BIN
C/CS/ContainerApp - Gijs van Maanen.zip
Normal file
BIN
C/CS/ContainerApp - Gijs van Maanen.zip
Normal file
Binary file not shown.
BIN
C/CS/Starter_assignment.zip
Normal file
BIN
C/CS/Starter_assignment.zip
Normal file
Binary file not shown.
13
C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/.gitignore
generated
vendored
Normal file
13
C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/contentModel.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/.idea.Starter_assignment.iml
|
||||
/modules.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
4
C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/encodings.xml
generated
Normal file
4
C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/indexLayout.xml
generated
Normal file
8
C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
BIN
C/CS/Starter_assignment/Archive.zip
Normal file
BIN
C/CS/Starter_assignment/Archive.zip
Normal file
Binary file not shown.
74
C/CS/Starter_assignment/Course.cs
Normal file
74
C/CS/Starter_assignment/Course.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
namespace Starter_assignment;
|
||||
|
||||
class Course {
|
||||
private List<Student> students = new List<Student>();
|
||||
private Dictionary<string, List<Student>> groups = new Dictionary<string, List<Student>>();
|
||||
private int groupCounter = 1;
|
||||
|
||||
public void AddStudent(string name, int studentNumber) {
|
||||
name = name.Trim();
|
||||
|
||||
foreach (Student student in students) {
|
||||
if (student.GetStudentNumber() == studentNumber) {
|
||||
Console.WriteLine("Student number must be unique.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string groupName = groups.Keys.LastOrDefault();
|
||||
if (groupName == null || groups[groupName].Count >= 3) {
|
||||
groupName = $"PG{groupCounter}";
|
||||
groups[groupName] = new List<Student>();
|
||||
groupCounter++;
|
||||
}
|
||||
|
||||
Student newStudent = new Student(name, studentNumber, groupName);
|
||||
students.Add(newStudent);
|
||||
groups[groupName].Add(newStudent);
|
||||
Console.WriteLine($"Student {name} added successfully to {groupName}.");
|
||||
}
|
||||
|
||||
public void ViewAllStudents() {
|
||||
foreach (Student student in students) {
|
||||
Console.WriteLine(student.GetInfo());
|
||||
}
|
||||
}
|
||||
|
||||
public void ViewAllGroups() {
|
||||
foreach (KeyValuePair<string, List<Student>> group in groups) {
|
||||
Console.WriteLine(group.Key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SearchByStudentNumber(int studentNumber) {
|
||||
Student foundStudent = null;
|
||||
foreach (Student student in students) {
|
||||
int currentStudentNumber = student.GetStudentNumber();
|
||||
if (currentStudentNumber == studentNumber) {
|
||||
foundStudent = student;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundStudent != null) {
|
||||
Console.WriteLine(foundStudent.GetInfo());
|
||||
} else {
|
||||
Console.WriteLine("No student found.");
|
||||
}
|
||||
}
|
||||
|
||||
public void SearchByGroup(string groupName) {
|
||||
if (groups.ContainsKey(groupName)) {
|
||||
foreach (Student student in groups[groupName]) {
|
||||
Console.WriteLine(student.GetInfo());
|
||||
}
|
||||
} else {
|
||||
Console.WriteLine("Group not found.");
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowStatistics() {
|
||||
Console.WriteLine($"Total students: {students.Count}");
|
||||
Console.WriteLine($"Total groups: {groups.Count}");
|
||||
}
|
||||
}
|
||||
62
C/CS/Starter_assignment/Program.cs
Normal file
62
C/CS/Starter_assignment/Program.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
namespace Starter_assignment;
|
||||
|
||||
class Program {
|
||||
static void Main() {
|
||||
Course course = new Course();
|
||||
bool running = true;
|
||||
|
||||
while (running) {
|
||||
Console.WriteLine("\n1. Add Student" +
|
||||
"\n2. View All Students" +
|
||||
"\n3. View All Groups" +
|
||||
"\n4. Search Student by Number" +
|
||||
"\n5. Show Students in a Group" +
|
||||
"\n6. Show Statistics" +
|
||||
"\n7. Exit" +
|
||||
"\nChoose an option: ");
|
||||
|
||||
string choice = Console.ReadLine();
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
case "1":
|
||||
Console.Write("Enter student name: ");
|
||||
string name = Console.ReadLine();
|
||||
Console.Write("Enter student number: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int studentNumber)) {
|
||||
course.AddStudent(name, studentNumber);
|
||||
} else {
|
||||
Console.WriteLine("Invalid student number.");
|
||||
}
|
||||
break;
|
||||
case "2":
|
||||
course.ViewAllStudents();
|
||||
break;
|
||||
case "3":
|
||||
course.ViewAllGroups();
|
||||
break;
|
||||
case "4":
|
||||
Console.Write("Enter student number: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int searchNumber)) {
|
||||
course.SearchByStudentNumber(searchNumber);
|
||||
}
|
||||
break;
|
||||
case "5":
|
||||
Console.Write("Enter group name: ");
|
||||
string groupName = Console.ReadLine();
|
||||
course.SearchByGroup(groupName);
|
||||
break;
|
||||
case "6":
|
||||
course.ShowStatistics();
|
||||
break;
|
||||
case "7":
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Invalid option, try again.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
C/CS/Starter_assignment/Starter_assignment.csproj
Normal file
10
C/CS/Starter_assignment/Starter_assignment.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
BIN
C/CS/Starter_assignment/Starter_assignment.dll
Normal file
BIN
C/CS/Starter_assignment/Starter_assignment.dll
Normal file
Binary file not shown.
16
C/CS/Starter_assignment/Starter_assignment.sln
Normal file
16
C/CS/Starter_assignment/Starter_assignment.sln
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Starter_assignment", "Starter_assignment\Starter_assignment.csproj", "{C78EC255-456E-4C45-912E-49607AD28EDC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C78EC255-456E-4C45-912E-49607AD28EDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C78EC255-456E-4C45-912E-49607AD28EDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C78EC255-456E-4C45-912E-49607AD28EDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C78EC255-456E-4C45-912E-49607AD28EDC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,4 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConsole_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F2ccd2056ec55b7b67558d52e32a887ed5ac7e346fc429b218c188d0a99cb5be_003FConsole_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATextReader_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F5b34e2245c26def5c9df2f8c13df6c04246252f96a7cebf7db554fed90435_003FTextReader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">ERROR</s:String></wpf:ResourceDictionary>
|
||||
73
C/CS/Starter_assignment/Starter_assignment/Course.cs
Normal file
73
C/CS/Starter_assignment/Starter_assignment/Course.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
namespace Starter_assignment;
|
||||
|
||||
class Course {
|
||||
private List<Student> students = new List<Student>();
|
||||
private Dictionary<string, List<Student>> groups = new Dictionary<string, List<Student>>();
|
||||
private int groupCounter = 1;
|
||||
|
||||
public void AddStudent(string name, int studentNumber) {
|
||||
name = name.Trim();
|
||||
|
||||
foreach (Student student in students) {
|
||||
if (student.GetStudentNumber() == studentNumber) {
|
||||
Console.WriteLine("Student number must be unique.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string groupName = groups.Keys.LastOrDefault();
|
||||
if (groupName == null || groups[groupName].Count >= 3) {
|
||||
groupName = $"PG{groupCounter}";
|
||||
groups[groupName] = new List<Student>();
|
||||
groupCounter++;
|
||||
}
|
||||
|
||||
Student newStudent = new Student(name, studentNumber, groupName);
|
||||
students.Add(newStudent);
|
||||
groups[groupName].Add(newStudent);
|
||||
Console.WriteLine($"Student {name} added successfully to {groupName}.");
|
||||
}
|
||||
|
||||
public void ViewAllStudents() {
|
||||
foreach (Student student in students) {
|
||||
Console.WriteLine(student.GetInfo());
|
||||
}
|
||||
}
|
||||
|
||||
public void ViewAllGroups() {
|
||||
foreach (KeyValuePair<string, List<Student>> group in groups) {
|
||||
Console.WriteLine(group.Key);
|
||||
}
|
||||
}
|
||||
|
||||
public void SearchByStudentNumber(int studentNumber) {
|
||||
Student foundStudent = null;
|
||||
foreach (Student student in students) {
|
||||
int currentStudentNumber = student.GetStudentNumber();
|
||||
if (currentStudentNumber == studentNumber) {
|
||||
foundStudent = student;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundStudent != null) {
|
||||
Console.WriteLine(foundStudent.GetInfo());
|
||||
} else {
|
||||
Console.WriteLine("No student found.");
|
||||
}
|
||||
}
|
||||
|
||||
public void SearchByGroup(string groupName) {
|
||||
if (groups.ContainsKey(groupName)) {
|
||||
foreach (Student student in groups[groupName]) {
|
||||
Console.WriteLine(student.GetInfo());
|
||||
}
|
||||
} else {
|
||||
Console.WriteLine("Group not found.");
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowStatistics() {
|
||||
Console.WriteLine($"Total students: {students.Count}");
|
||||
Console.WriteLine($"Total groups: {groups.Count}");
|
||||
}
|
||||
}
|
||||
62
C/CS/Starter_assignment/Starter_assignment/Program.cs
Normal file
62
C/CS/Starter_assignment/Starter_assignment/Program.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
namespace Starter_assignment;
|
||||
|
||||
class Program {
|
||||
static void Main() {
|
||||
Course course = new Course();
|
||||
bool running = true;
|
||||
|
||||
while (running) {
|
||||
Console.WriteLine("\n1. Add Student" +
|
||||
"\n2. View All Students" +
|
||||
"\n3. View All Groups" +
|
||||
"\n4. Search Student by Number" +
|
||||
"\n5. Show Students in a Group" +
|
||||
"\n6. Show Statistics" +
|
||||
"\n7. Exit" +
|
||||
"\nChoose an option: ");
|
||||
|
||||
string choice = Console.ReadLine();
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
case "1":
|
||||
Console.Write("Enter student name: ");
|
||||
string name = Console.ReadLine();
|
||||
Console.Write("Enter student number: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int studentNumber)) {
|
||||
course.AddStudent(name, studentNumber);
|
||||
} else {
|
||||
Console.WriteLine("Invalid student number.");
|
||||
}
|
||||
break;
|
||||
case "2":
|
||||
course.ViewAllStudents();
|
||||
break;
|
||||
case "3":
|
||||
course.ViewAllGroups();
|
||||
break;
|
||||
case "4":
|
||||
Console.Write("Enter student number: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int searchNumber)) {
|
||||
course.SearchByStudentNumber(searchNumber);
|
||||
}
|
||||
break;
|
||||
case "5":
|
||||
Console.Write("Enter group name: ");
|
||||
string groupName = Console.ReadLine();
|
||||
course.SearchByGroup(groupName);
|
||||
break;
|
||||
case "6":
|
||||
course.ShowStatistics();
|
||||
break;
|
||||
case "7":
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Invalid option, try again.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
27
C/CS/Starter_assignment/Starter_assignment/Student.cs
Normal file
27
C/CS/Starter_assignment/Starter_assignment/Student.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace Starter_assignment;
|
||||
|
||||
class Student {
|
||||
private string Name { get; }
|
||||
private int StudentNumber { get; }
|
||||
private string GroupName { get; }
|
||||
|
||||
public Student(string name, int studentNumber, string groupName) {
|
||||
if (string.IsNullOrWhiteSpace(name)) {
|
||||
throw new ArgumentException("Name cannot be empty.");
|
||||
}
|
||||
if (studentNumber < 10000 && studentNumber != -1) {
|
||||
throw new ArgumentException("Student number must be >= 10000 or -1.");
|
||||
}
|
||||
|
||||
Name = name;
|
||||
StudentNumber = studentNumber;
|
||||
GroupName = groupName;
|
||||
}
|
||||
|
||||
public int GetStudentNumber() {
|
||||
return StudentNumber;
|
||||
}
|
||||
public string GetInfo() {
|
||||
return $"{Name} ({StudentNumber}) - {GroupName}";
|
||||
}
|
||||
}
|
||||
BIN
C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment
Executable file
BIN
C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment
Executable file
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETCoreApp,Version=v8.0",
|
||||
"signature": ""
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
".NETCoreApp,Version=v8.0": {
|
||||
"Starter_assignment/1.0.0": {
|
||||
"runtime": {
|
||||
"Starter_assignment.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"Starter_assignment/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net8.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "8.0.0"
|
||||
},
|
||||
"configProperties": {
|
||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
|
||||
@@ -0,0 +1,22 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Starter_assignment")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Starter_assignment")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Starter_assignment")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
77da79aa1d8b67801697281643b61dd3f4e48c0c7f245ecd395dee391118be92
|
||||
@@ -0,0 +1,13 @@
|
||||
is_global = true
|
||||
build_property.TargetFramework = net8.0
|
||||
build_property.TargetPlatformMinVersion =
|
||||
build_property.UsingMicrosoftNETSdkWeb =
|
||||
build_property.ProjectTypeGuids =
|
||||
build_property.InvariantGlobalization =
|
||||
build_property.PlatformNeutralAssembly =
|
||||
build_property.EnforceExtendedAnalyzerRules =
|
||||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
||||
build_property.RootNamespace = Starter_assignment
|
||||
build_property.ProjectDir = /home/rens/T2/CS/Starter_assignment/Starter_assignment/
|
||||
build_property.EnableComHosting =
|
||||
build_property.EnableGeneratedComInterfaceComImportInterop =
|
||||
@@ -0,0 +1,8 @@
|
||||
// <auto-generated/>
|
||||
global using global::System;
|
||||
global using global::System.Collections.Generic;
|
||||
global using global::System.IO;
|
||||
global using global::System.Linq;
|
||||
global using global::System.Net.Http;
|
||||
global using global::System.Threading;
|
||||
global using global::System.Threading.Tasks;
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
63f646a6f5c36f8a67f54301cd756f80709a6758f27e90e85bd3caa85964b27d
|
||||
@@ -0,0 +1,10 @@
|
||||
/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment
|
||||
/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.dll
|
||||
/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.pdb
|
||||
/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GeneratedMSBuildEditorConfig.editorconfig
|
||||
/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfoInputs.cache
|
||||
/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfo.cs
|
||||
/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.CoreCompileInputs.cache
|
||||
/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.dll
|
||||
/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/refint/Starter_assignment.dll
|
||||
/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.pdb
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
4028af397b722be4e5490a9f64106d4a5c363b00c8703dae917b145b5632baa4
|
||||
Binary file not shown.
BIN
C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/apphost
Executable file
BIN
C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/apphost
Executable file
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user