diff --git a/C/Adidas.zip b/C/Adidas.zip new file mode 100644 index 0000000..ad38d67 Binary files /dev/null and b/C/Adidas.zip differ diff --git a/C/Adidas/.gitignore b/C/Adidas/.gitignore new file mode 100644 index 0000000..8e048a9 --- /dev/null +++ b/C/Adidas/.gitignore @@ -0,0 +1,9 @@ +encode +channel +decode +encode_test +channel_test +decode_test +a.tmp +b.tmp +c.tmp diff --git a/C/Adidas/Adidas-module-design.pptx b/C/Adidas/Adidas-module-design.pptx new file mode 100644 index 0000000..fb142d9 Binary files /dev/null and b/C/Adidas/Adidas-module-design.pptx differ diff --git a/C/Adidas/Assignment - Adidas.docx b/C/Adidas/Assignment - Adidas.docx new file mode 100644 index 0000000..deff4e8 Binary files /dev/null and b/C/Adidas/Assignment - Adidas.docx differ diff --git a/C/Adidas/Makefile b/C/Adidas/Makefile new file mode 100644 index 0000000..35e0c37 --- /dev/null +++ b/C/Adidas/Makefile @@ -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) diff --git a/C/Adidas/Unity/unity.c b/C/Adidas/Unity/unity.c new file mode 100644 index 0000000..7b10aa6 --- /dev/null +++ b/C/Adidas/Unity/unity.c @@ -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 +#include + +#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; +} diff --git a/C/Adidas/Unity/unity.h b/C/Adidas/Unity/unity.h new file mode 100644 index 0000000..8b16111 --- /dev/null +++ b/C/Adidas/Unity/unity.h @@ -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 diff --git a/C/Adidas/Unity/unity_internals.h b/C/Adidas/Unity/unity_internals.h new file mode 100644 index 0000000..b0d0637 --- /dev/null +++ b/C/Adidas/Unity/unity_internals.h @@ -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 +#include + +//------------------------------------------------------- +// 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 diff --git a/C/Adidas/Unity/unity_test_module.c b/C/Adidas/Unity/unity_test_module.c new file mode 100644 index 0000000..ba18f7f --- /dev/null +++ b/C/Adidas/Unity/unity_test_module.c @@ -0,0 +1,97 @@ +#include "unity_test_module.h" +#include +#include +#include +#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(); +} diff --git a/C/Adidas/Unity/unity_test_module.h b/C/Adidas/Unity/unity_test_module.h new file mode 100644 index 0000000..c16ec8d --- /dev/null +++ b/C/Adidas/Unity/unity_test_module.h @@ -0,0 +1,31 @@ +#ifndef UNITY_TEST_MODULE_H +#define UNITY_TEST_MODULE_H + +#include + +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 diff --git a/C/Adidas/build/.gitkeep b/C/Adidas/build/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/C/Adidas/build/.gitkeep @@ -0,0 +1 @@ + diff --git a/C/Adidas/build/main_test b/C/Adidas/build/main_test new file mode 100755 index 0000000..6dc41e0 Binary files /dev/null and b/C/Adidas/build/main_test differ diff --git a/C/Adidas/product/channel_main.c b/C/Adidas/product/channel_main.c new file mode 100644 index 0000000..1a28f3e --- /dev/null +++ b/C/Adidas/product/channel_main.c @@ -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; +} diff --git a/C/Adidas/product/decode_main.c b/C/Adidas/product/decode_main.c new file mode 100644 index 0000000..7ed5d24 --- /dev/null +++ b/C/Adidas/product/decode_main.c @@ -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; +} diff --git a/C/Adidas/product/encode_main.c b/C/Adidas/product/encode_main.c new file mode 100644 index 0000000..85f6124 --- /dev/null +++ b/C/Adidas/product/encode_main.c @@ -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; +} diff --git a/C/Adidas/product/main.c b/C/Adidas/product/main.c new file mode 100644 index 0000000..b640df1 --- /dev/null +++ b/C/Adidas/product/main.c @@ -0,0 +1,38 @@ +#include +#include +#include + +#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; +} diff --git a/C/Adidas/shared/bit_stuff.c b/C/Adidas/shared/bit_stuff.c new file mode 100644 index 0000000..29a4a08 --- /dev/null +++ b/C/Adidas/shared/bit_stuff.c @@ -0,0 +1,40 @@ +#include "bit_stuff.h" +#include +#include + +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); +} \ No newline at end of file diff --git a/C/Adidas/shared/bit_stuff.h b/C/Adidas/shared/bit_stuff.h new file mode 100644 index 0000000..9326db1 --- /dev/null +++ b/C/Adidas/shared/bit_stuff.h @@ -0,0 +1,36 @@ +#pragma once + +#include + +/* 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); diff --git a/C/Adidas/shared/channel.c b/C/Adidas/shared/channel.c new file mode 100644 index 0000000..6dc2db5 --- /dev/null +++ b/C/Adidas/shared/channel.c @@ -0,0 +1,4 @@ +#include "channel.h" +// add here includes, if needed + +// add here your implementation diff --git a/C/Adidas/shared/channel.h b/C/Adidas/shared/channel.h new file mode 100644 index 0000000..910a626 --- /dev/null +++ b/C/Adidas/shared/channel.h @@ -0,0 +1,22 @@ +#ifndef CHANNEL_H +#define CHANNEL_H + +#include + + +/*! + * 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 + diff --git a/C/Adidas/shared/decode.c b/C/Adidas/shared/decode.c new file mode 100644 index 0000000..c315a13 --- /dev/null +++ b/C/Adidas/shared/decode.c @@ -0,0 +1,4 @@ +#include "decode.h" +// add here includes, if needed + +// add here your implementation \ No newline at end of file diff --git a/C/Adidas/shared/decode.h b/C/Adidas/shared/decode.h new file mode 100644 index 0000000..3e2de26 --- /dev/null +++ b/C/Adidas/shared/decode.h @@ -0,0 +1,28 @@ +#ifndef DECODE_H_ +#define DECODE_H_ + +#include + +/*! + * 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 diff --git a/C/Adidas/shared/encode.c b/C/Adidas/shared/encode.c new file mode 100644 index 0000000..c2eef0d --- /dev/null +++ b/C/Adidas/shared/encode.c @@ -0,0 +1,34 @@ +#include "encode.h" +#include "parity.h" +#include "bit_stuff.h" +#include +#include +#include + +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); +} \ No newline at end of file diff --git a/C/Adidas/shared/encode.h b/C/Adidas/shared/encode.h new file mode 100644 index 0000000..8bf009b --- /dev/null +++ b/C/Adidas/shared/encode.h @@ -0,0 +1,33 @@ +#ifndef ENCODE_H_ +#define ENCODE_H_ + +#include +#include + +/*! + * 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 \ No newline at end of file diff --git a/C/Adidas/shared/parity.c b/C/Adidas/shared/parity.c new file mode 100644 index 0000000..a3c347d --- /dev/null +++ b/C/Adidas/shared/parity.c @@ -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 +} diff --git a/C/Adidas/shared/parity.h b/C/Adidas/shared/parity.h new file mode 100644 index 0000000..dcb7c91 --- /dev/null +++ b/C/Adidas/shared/parity.h @@ -0,0 +1,8 @@ +#ifndef PARITY_H_ +#define PARITY_H_ + +#include + +void calculate_parity_bits(uint8_t nibble, uint8_t* p0, uint8_t* p1, uint8_t* p2); + +#endif \ No newline at end of file diff --git a/C/Adidas/test/channel_test.c b/C/Adidas/test/channel_test.c new file mode 100644 index 0000000..86529e8 --- /dev/null +++ b/C/Adidas/test/channel_test.c @@ -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(); +} diff --git a/C/Adidas/test/decode_test.c b/C/Adidas/test/decode_test.c new file mode 100644 index 0000000..0e08dc0 --- /dev/null +++ b/C/Adidas/test/decode_test.c @@ -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(); +} diff --git a/C/Adidas/test/encode_test.c b/C/Adidas/test/encode_test.c new file mode 100644 index 0000000..9f3a029 --- /dev/null +++ b/C/Adidas/test/encode_test.c @@ -0,0 +1,64 @@ +#include +#include +#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(); +} diff --git a/C/Adidas/test/main.c b/C/Adidas/test/main.c new file mode 100644 index 0000000..dcf7277 --- /dev/null +++ b/C/Adidas/test/main.c @@ -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); +} diff --git a/C/Adidas/test/parity_test.c b/C/Adidas/test/parity_test.c new file mode 100644 index 0000000..0f63028 --- /dev/null +++ b/C/Adidas/test/parity_test.c @@ -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(); +} \ No newline at end of file diff --git a/C/C1.zip b/C/C1.zip new file mode 100644 index 0000000..7b92707 Binary files /dev/null and b/C/C1.zip differ diff --git a/C/C1/.vscode/settings.json b/C/C1/.vscode/settings.json new file mode 100644 index 0000000..df8473c --- /dev/null +++ b/C/C1/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "files.associations": { + "bike_measure.h": "c", + "stdint.h": "c", + "bike_store.h": "c", + "stdlib.h": "c", + "unistd.h": "c" + } +} \ No newline at end of file diff --git a/C/C1/Makefile b/C/C1/Makefile new file mode 100644 index 0000000..e935d3e --- /dev/null +++ b/C/C1/Makefile @@ -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) + \ No newline at end of file diff --git a/C/C1/bike_math.c b/C/C1/bike_math.c new file mode 100644 index 0000000..112f1a7 --- /dev/null +++ b/C/C1/bike_math.c @@ -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; +} \ No newline at end of file diff --git a/C/C1/bike_math.h b/C/C1/bike_math.h new file mode 100644 index 0000000..eda8552 --- /dev/null +++ b/C/C1/bike_math.h @@ -0,0 +1,19 @@ +#ifndef BIKE_MATH_H +#define BIKE_MATH_H + +#include +//#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 \ No newline at end of file diff --git a/C/C1/bike_measure.c b/C/C1/bike_measure.c new file mode 100644 index 0000000..822c684 --- /dev/null +++ b/C/C1/bike_measure.c @@ -0,0 +1,47 @@ +#include "bike_measure.h" +#include +#include + +#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); +} \ No newline at end of file diff --git a/C/C1/bike_measure.h b/C/C1/bike_measure.h new file mode 100644 index 0000000..f89e046 --- /dev/null +++ b/C/C1/bike_measure.h @@ -0,0 +1,11 @@ +#ifndef BIKE_MEASURE_H +#define BIKE_MEASURE_H + +#include + +uint16_t bikeMeasureSpeedInKmh(); +uint16_t bikeMeasurePowerInWatt(); +uint16_t bikeMeasureCadenceInRpm(); +uint16_t bikeMeasureHeartRateInBpm(); + +#endif \ No newline at end of file diff --git a/C/C1/bike_store.c b/C/C1/bike_store.c new file mode 100644 index 0000000..7f21d2c --- /dev/null +++ b/C/C1/bike_store.c @@ -0,0 +1,31 @@ +#include "bike_store.h" +#include + +#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; +} diff --git a/C/C1/bike_store.h b/C/C1/bike_store.h new file mode 100644 index 0000000..aa1f720 --- /dev/null +++ b/C/C1/bike_store.h @@ -0,0 +1,18 @@ +#ifndef BIKE_STORE_H +#define BIKE_STORE_H + +#include + +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 \ No newline at end of file diff --git a/C/C1/main b/C/C1/main new file mode 100755 index 0000000..305efc0 Binary files /dev/null and b/C/C1/main differ diff --git a/C/C1/main.c b/C/C1/main.c new file mode 100644 index 0000000..5357dd6 --- /dev/null +++ b/C/C1/main.c @@ -0,0 +1,51 @@ +#include +#include +#include + +#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); + } +} diff --git a/C/C2/.vscode/c_cpp_properties.json b/C/C2/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c2098a2 --- /dev/null +++ b/C/C2/.vscode/c_cpp_properties.json @@ -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 +} \ No newline at end of file diff --git a/C/C2/.vscode/launch.json b/C/C2/.vscode/launch.json new file mode 100644 index 0000000..a53e5db --- /dev/null +++ b/C/C2/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug", + "program": "${workspaceFolder}/", + "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 + } + ] + } + ] +} \ No newline at end of file diff --git a/C/C2/.vscode/settings.json b/C/C2/.vscode/settings.json new file mode 100644 index 0000000..3e5eb95 --- /dev/null +++ b/C/C2/.vscode/settings.json @@ -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 +} \ No newline at end of file diff --git a/C/C2/2-Assignment - AnimalShelter.docx b/C/C2/2-Assignment - AnimalShelter.docx new file mode 100644 index 0000000..401f9fe Binary files /dev/null and b/C/C2/2-Assignment - AnimalShelter.docx differ diff --git a/C/C2/Makefile b/C/C2/Makefile new file mode 100644 index 0000000..35ace1c --- /dev/null +++ b/C/C2/Makefile @@ -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) diff --git a/C/C2/Unity/unity.c b/C/C2/Unity/unity.c new file mode 100644 index 0000000..7b10aa6 --- /dev/null +++ b/C/C2/Unity/unity.c @@ -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 +#include + +#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; +} diff --git a/C/C2/Unity/unity.h b/C/C2/Unity/unity.h new file mode 100644 index 0000000..8b16111 --- /dev/null +++ b/C/C2/Unity/unity.h @@ -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 diff --git a/C/C2/Unity/unity_internals.h b/C/C2/Unity/unity_internals.h new file mode 100644 index 0000000..b0d0637 --- /dev/null +++ b/C/C2/Unity/unity_internals.h @@ -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 +#include + +//------------------------------------------------------- +// 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 diff --git a/C/C2/Unity/unity_test_module.c b/C/C2/Unity/unity_test_module.c new file mode 100644 index 0000000..ba18f7f --- /dev/null +++ b/C/C2/Unity/unity_test_module.c @@ -0,0 +1,97 @@ +#include "unity_test_module.h" +#include +#include +#include +#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(); +} diff --git a/C/C2/Unity/unity_test_module.h b/C/C2/Unity/unity_test_module.h new file mode 100644 index 0000000..c16ec8d --- /dev/null +++ b/C/C2/Unity/unity_test_module.h @@ -0,0 +1,31 @@ +#ifndef UNITY_TEST_MODULE_H +#define UNITY_TEST_MODULE_H + +#include + +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 diff --git a/C/C2/assignment.pdf b/C/C2/assignment.pdf new file mode 100644 index 0000000..75ade2e Binary files /dev/null and b/C/C2/assignment.pdf differ diff --git a/C/C2/build/main b/C/C2/build/main new file mode 100755 index 0000000..1f39513 Binary files /dev/null and b/C/C2/build/main differ diff --git a/C/C2/build/main_test b/C/C2/build/main_test new file mode 100644 index 0000000..df1347b Binary files /dev/null and b/C/C2/build/main_test differ diff --git a/C/C2/product/main.c b/C/C2/product/main.c new file mode 100644 index 0000000..a06d475 --- /dev/null +++ b/C/C2/product/main.c @@ -0,0 +1,160 @@ +#include +#include +#include +#include + +#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; +} diff --git a/C/C2/product/terminal_io.c b/C/C2/product/terminal_io.c new file mode 100644 index 0000000..59dd5b0 --- /dev/null +++ b/C/C2/product/terminal_io.c @@ -0,0 +1,98 @@ +#include +#include + +#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); + } + } + } +} diff --git a/C/C2/product/terminal_io.h b/C/C2/product/terminal_io.h new file mode 100644 index 0000000..c0c6036 --- /dev/null +++ b/C/C2/product/terminal_io.h @@ -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 diff --git a/C/C2/shared/administration.c b/C/C2/shared/administration.c new file mode 100644 index 0000000..04e1b76 --- /dev/null +++ b/C/C2/shared/administration.c @@ -0,0 +1,22 @@ +#include "administration.h" + +#include +#include +#include +#include +#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 + + diff --git a/C/C2/shared/administration.h b/C/C2/shared/administration.h new file mode 100644 index 0000000..5872413 --- /dev/null +++ b/C/C2/shared/administration.h @@ -0,0 +1,56 @@ +#ifndef ADMINISTRATION_H +#define ADMINISTRATION_H + +#include + +#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 diff --git a/C/C2/shared/animal.h b/C/C2/shared/animal.h new file mode 100644 index 0000000..d3fa4ad --- /dev/null +++ b/C/C2/shared/animal.h @@ -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 \ No newline at end of file diff --git a/C/C2/shared/file_element.c b/C/C2/shared/file_element.c new file mode 100644 index 0000000..cc4710e --- /dev/null +++ b/C/C2/shared/file_element.c @@ -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; +} diff --git a/C/C2/shared/file_element.h b/C/C2/shared/file_element.h new file mode 100644 index 0000000..ab8cf2f --- /dev/null +++ b/C/C2/shared/file_element.h @@ -0,0 +1,66 @@ +#ifndef FILE_ELEMENT_H +#define FILE_ELEMENT_H + +#include + +#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 diff --git a/C/C2/test/administration_test.c b/C/C2/test/administration_test.c new file mode 100644 index 0000000..a8d0b8a --- /dev/null +++ b/C/C2/test/administration_test.c @@ -0,0 +1,35 @@ +#include + +#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(); +} + diff --git a/C/C2/test/file_element_test.c b/C/C2/test/file_element_test.c new file mode 100644 index 0000000..16fd978 --- /dev/null +++ b/C/C2/test/file_element_test.c @@ -0,0 +1,34 @@ +#include + +#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(); +} diff --git a/C/C2/test/main.c b/C/C2/test/main.c new file mode 100644 index 0000000..4595f44 --- /dev/null +++ b/C/C2/test/main.c @@ -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); +} diff --git a/C/CS/ContainerApp - Gijs van Maanen.zip b/C/CS/ContainerApp - Gijs van Maanen.zip new file mode 100644 index 0000000..c661a4a Binary files /dev/null and b/C/CS/ContainerApp - Gijs van Maanen.zip differ diff --git a/C/CS/Starter_assignment.zip b/C/CS/Starter_assignment.zip new file mode 100644 index 0000000..26a1eca Binary files /dev/null and b/C/CS/Starter_assignment.zip differ diff --git a/C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/.gitignore b/C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/.gitignore new file mode 100644 index 0000000..3c841d4 --- /dev/null +++ b/C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/.gitignore @@ -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 diff --git a/C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/encodings.xml b/C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/indexLayout.xml b/C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/C/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/C/CS/Starter_assignment/Archive.zip b/C/CS/Starter_assignment/Archive.zip new file mode 100644 index 0000000..e7347c5 Binary files /dev/null and b/C/CS/Starter_assignment/Archive.zip differ diff --git a/C/CS/Starter_assignment/Course.cs b/C/CS/Starter_assignment/Course.cs new file mode 100644 index 0000000..9ac8887 --- /dev/null +++ b/C/CS/Starter_assignment/Course.cs @@ -0,0 +1,74 @@ +namespace Starter_assignment; + +class Course { + private List students = new List(); + private Dictionary> groups = new Dictionary>(); + 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(); + 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> 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}"); + } +} \ No newline at end of file diff --git a/C/CS/Starter_assignment/Program.cs b/C/CS/Starter_assignment/Program.cs new file mode 100644 index 0000000..ae39d83 --- /dev/null +++ b/C/CS/Starter_assignment/Program.cs @@ -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; + } + } + } +} + diff --git a/C/CS/Starter_assignment/Starter_assignment.csproj b/C/CS/Starter_assignment/Starter_assignment.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/C/CS/Starter_assignment/Starter_assignment.dll b/C/CS/Starter_assignment/Starter_assignment.dll new file mode 100644 index 0000000..8ce0e2f Binary files /dev/null and b/C/CS/Starter_assignment/Starter_assignment.dll differ diff --git a/C/CS/Starter_assignment/Starter_assignment.sln b/C/CS/Starter_assignment/Starter_assignment.sln new file mode 100644 index 0000000..b71be33 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment.sln @@ -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 diff --git a/C/CS/Starter_assignment/Starter_assignment.sln.DotSettings.user b/C/CS/Starter_assignment/Starter_assignment.sln.DotSettings.user new file mode 100644 index 0000000..ccb66a8 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment.sln.DotSettings.user @@ -0,0 +1,4 @@ + + ForceIncluded + ForceIncluded + ERROR \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/Course.cs b/C/CS/Starter_assignment/Starter_assignment/Course.cs new file mode 100644 index 0000000..98a7504 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/Course.cs @@ -0,0 +1,73 @@ +namespace Starter_assignment; + +class Course { + private List students = new List(); + private Dictionary> groups = new Dictionary>(); + 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(); + 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> 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}"); + } +} \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/Program.cs b/C/CS/Starter_assignment/Starter_assignment/Program.cs new file mode 100644 index 0000000..ae39d83 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/Program.cs @@ -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; + } + } + } +} + diff --git a/C/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj b/C/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/C/CS/Starter_assignment/Starter_assignment/Student.cs b/C/CS/Starter_assignment/Starter_assignment/Student.cs new file mode 100644 index 0000000..618fa3c --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/Student.cs @@ -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}"; + } +} diff --git a/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment b/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment new file mode 100755 index 0000000..7364e5e Binary files /dev/null and b/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment differ diff --git a/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.deps.json b/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.deps.json new file mode 100644 index 0000000..c20d914 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.deps.json @@ -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": "" + } + } +} \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.dll b/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.dll new file mode 100644 index 0000000..5066089 Binary files /dev/null and b/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.dll differ diff --git a/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.pdb b/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.pdb new file mode 100644 index 0000000..e3dc1d9 Binary files /dev/null and b/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.pdb differ diff --git a/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.runtimeconfig.json b/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.runtimeconfig.json new file mode 100644 index 0000000..becfaea --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.runtimeconfig.json @@ -0,0 +1,12 @@ +{ + "runtimeOptions": { + "tfm": "net8.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "8.0.0" + }, + "configProperties": { + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false + } + } +} \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs new file mode 100644 index 0000000..dca70aa --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")] diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfo.cs b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfo.cs new file mode 100644 index 0000000..5b35b66 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfo.cs @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +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. + diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfoInputs.cache b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfoInputs.cache new file mode 100644 index 0000000..2b7cd31 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +77da79aa1d8b67801697281643b61dd3f4e48c0c7f245ecd395dee391118be92 diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GeneratedMSBuildEditorConfig.editorconfig b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..10df626 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GeneratedMSBuildEditorConfig.editorconfig @@ -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 = diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GlobalUsings.g.cs b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GlobalUsings.g.cs new file mode 100644 index 0000000..8578f3d --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GlobalUsings.g.cs @@ -0,0 +1,8 @@ +// +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; diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.assets.cache b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.assets.cache new file mode 100644 index 0000000..eea52c3 Binary files /dev/null and b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.assets.cache differ diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.CoreCompileInputs.cache b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..ee2f4d4 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +63f646a6f5c36f8a67f54301cd756f80709a6758f27e90e85bd3caa85964b27d diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.FileListAbsolute.txt b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..8703dff --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.FileListAbsolute.txt @@ -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 diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.dll b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.dll new file mode 100644 index 0000000..5066089 Binary files /dev/null and b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.dll differ diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.genruntimeconfig.cache b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.genruntimeconfig.cache new file mode 100644 index 0000000..39e2157 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.genruntimeconfig.cache @@ -0,0 +1 @@ +4028af397b722be4e5490a9f64106d4a5c363b00c8703dae917b145b5632baa4 diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.pdb b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.pdb new file mode 100644 index 0000000..e3dc1d9 Binary files /dev/null and b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.pdb differ diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/apphost b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/apphost new file mode 100755 index 0000000..7364e5e Binary files /dev/null and b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/apphost differ diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/ref/Starter_assignment.dll b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/ref/Starter_assignment.dll new file mode 100644 index 0000000..dd1190c Binary files /dev/null and b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/ref/Starter_assignment.dll differ diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/refint/Starter_assignment.dll b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/refint/Starter_assignment.dll new file mode 100644 index 0000000..dd1190c Binary files /dev/null and b/C/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/refint/Starter_assignment.dll differ diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.dgspec.json b/C/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.dgspec.json new file mode 100644 index 0000000..fc9be79 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.dgspec.json @@ -0,0 +1,66 @@ +{ + "format": 1, + "restore": { + "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj": {} + }, + "projects": { + "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj", + "projectName": "Starter_assignment", + "projectPath": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj", + "packagesPath": "/home/rens/.nuget/packages/", + "outputPath": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/", + "projectStyle": "PackageReference", + "configFilePaths": [ + "/home/rens/.nuget/NuGet/NuGet.Config" + ], + "originalTargetFrameworks": [ + "net8.0" + ], + "sources": { + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + }, + "restoreAuditProperties": { + "enableAudit": "true", + "auditLevel": "low", + "auditMode": "direct" + } + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "/home/rens/.dotnet/sdk/8.0.404/PortableRuntimeIdentifierGraph.json" + } + } + } + } +} \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.props b/C/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.props new file mode 100644 index 0000000..1ee7f5f --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.props @@ -0,0 +1,15 @@ + + + + True + NuGet + $(MSBuildThisFileDirectory)project.assets.json + /home/rens/.nuget/packages/ + /home/rens/.nuget/packages/ + PackageReference + 6.12.2 + + + + + \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.targets b/C/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.targets new file mode 100644 index 0000000..3dc06ef --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.targets @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/project.assets.json b/C/CS/Starter_assignment/Starter_assignment/obj/project.assets.json new file mode 100644 index 0000000..3edcb61 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/project.assets.json @@ -0,0 +1,71 @@ +{ + "version": 3, + "targets": { + "net8.0": {} + }, + "libraries": {}, + "projectFileDependencyGroups": { + "net8.0": [] + }, + "packageFolders": { + "/home/rens/.nuget/packages/": {} + }, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj", + "projectName": "Starter_assignment", + "projectPath": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj", + "packagesPath": "/home/rens/.nuget/packages/", + "outputPath": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/", + "projectStyle": "PackageReference", + "configFilePaths": [ + "/home/rens/.nuget/NuGet/NuGet.Config" + ], + "originalTargetFrameworks": [ + "net8.0" + ], + "sources": { + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + }, + "restoreAuditProperties": { + "enableAudit": "true", + "auditLevel": "low", + "auditMode": "direct" + } + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "/home/rens/.dotnet/sdk/8.0.404/PortableRuntimeIdentifierGraph.json" + } + } + } +} \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/project.nuget.cache b/C/CS/Starter_assignment/Starter_assignment/obj/project.nuget.cache new file mode 100644 index 0000000..65b5e2d --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/project.nuget.cache @@ -0,0 +1,8 @@ +{ + "version": 2, + "dgSpecHash": "0d5jt8ngUw0=", + "success": true, + "projectFilePath": "/home/rens/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj", + "expectedPackageFiles": [], + "logs": [] +} \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/project.packagespec.json b/C/CS/Starter_assignment/Starter_assignment/obj/project.packagespec.json new file mode 100644 index 0000000..deb1fd1 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/project.packagespec.json @@ -0,0 +1 @@ +"restore":{"projectUniqueName":"/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj","projectName":"Starter_assignment","projectPath":"/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj","outputPath":"/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/","projectStyle":"PackageReference","originalTargetFrameworks":["net8.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net8.0":{"targetAlias":"net8.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]},"restoreAuditProperties":{"enableAudit":"true","auditLevel":"low","auditMode":"direct"}}"frameworks":{"net8.0":{"targetAlias":"net8.0","imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"/home/rens/.dotnet/sdk/8.0.404/PortableRuntimeIdentifierGraph.json"}} \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/rider.project.model.nuget.info b/C/CS/Starter_assignment/Starter_assignment/obj/rider.project.model.nuget.info new file mode 100644 index 0000000..a86fdb3 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/rider.project.model.nuget.info @@ -0,0 +1 @@ +17406469005085962 \ No newline at end of file diff --git a/C/CS/Starter_assignment/Starter_assignment/obj/rider.project.restore.info b/C/CS/Starter_assignment/Starter_assignment/obj/rider.project.restore.info new file mode 100644 index 0000000..a86fdb3 --- /dev/null +++ b/C/CS/Starter_assignment/Starter_assignment/obj/rider.project.restore.info @@ -0,0 +1 @@ +17406469005085962 \ No newline at end of file diff --git a/C/CS/Starter_assignment/Student.cs b/C/CS/Starter_assignment/Student.cs new file mode 100644 index 0000000..618fa3c --- /dev/null +++ b/C/CS/Starter_assignment/Student.cs @@ -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}"; + } +} diff --git a/C/CS/Starter_assignment/starter_assignment b/C/CS/Starter_assignment/starter_assignment new file mode 100755 index 0000000..7364e5e Binary files /dev/null and b/C/CS/Starter_assignment/starter_assignment differ diff --git a/C/ES/PlatformIO/Projects/ES state machine.zip b/C/ES/PlatformIO/Projects/ES state machine.zip new file mode 100644 index 0000000..b4001d4 Binary files /dev/null and b/C/ES/PlatformIO/Projects/ES state machine.zip differ diff --git a/C/ES/PlatformIO/Projects/ES state machine/.gitignore b/C/ES/PlatformIO/Projects/ES state machine/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES state machine/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/C/ES/PlatformIO/Projects/ES state machine/.vscode/extensions.json b/C/ES/PlatformIO/Projects/ES state machine/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES state machine/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/C/ES/PlatformIO/Projects/ES state machine/include/SerialProcess.h b/C/ES/PlatformIO/Projects/ES state machine/include/SerialProcess.h new file mode 100755 index 0000000..5bd6c56 --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES state machine/include/SerialProcess.h @@ -0,0 +1,39 @@ +#include +#ifndef SERIALPROCESS_H +#define SERIALPROCESS_H + +class SerialProcess { +private: + uint8_t ndx; // Current index for the buffer + const char beginMarker = '#'; // Marker to indicate the start of a message + const char endMarker = ';'; // Marker to indicate the end of a message + char rc; // Character read from Serial + int address; // Device address + bool newData; // Flag for new data availability + static const uint8_t numChars = 255; // Maximum size of the buffer + char receivedChars[numChars]; // Buffer for incoming data + bool rcCheck; + +public: + // Constructor + explicit SerialProcess(int addr); + + // Store Serial Input (if available) + void SerialInput(); + + // Check if new data is available + bool isNewDataAvailable(); + + // Get the received data + char* getReceivedData(); + + // Process the received message + void getPayload(char* payload); + + // Send message in the correct format + void sendMessage(int receiver, const char* payload); + + void changeAddress(int addr); +}; + +#endif // SERIALPROCESS_H diff --git a/C/ES/PlatformIO/Projects/ES state machine/lib/README b/C/ES/PlatformIO/Projects/ES state machine/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES state machine/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/C/ES/PlatformIO/Projects/ES state machine/platformio.ini b/C/ES/PlatformIO/Projects/ES state machine/platformio.ini new file mode 100644 index 0000000..dbb4289 --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES state machine/platformio.ini @@ -0,0 +1,16 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32dev] +platform = espressif32 +board = esp32dev +framework = arduino +monitor_speed = 115200 +lib_deps = plerup/EspSoftwareSerial@^8.2.0 diff --git a/C/ES/PlatformIO/Projects/ES state machine/src/SerialProcess.cpp b/C/ES/PlatformIO/Projects/ES state machine/src/SerialProcess.cpp new file mode 100755 index 0000000..e6b6fc6 --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES state machine/src/SerialProcess.cpp @@ -0,0 +1,74 @@ +#include "SerialProcess.h" +#include + +// Constructor +SerialProcess::SerialProcess(int addr) + : address(addr), ndx(0), rc(0), newData(false), rcCheck(false) { + Serial.begin(115200); +} + +// Processes Serial Input +void SerialProcess::SerialInput() { + while (Serial.available() > 0) { + rc = static_cast(Serial.read()); + + if (rc == beginMarker) { + rcCheck = true; // Start reading after the begin marker + ndx = 0; // Reset index for new message + } + + if (rcCheck) { + // Store the character if within bounds + if (ndx < numChars - 1) { + receivedChars[ndx++] = rc; + } + + // Check for end marker + if (rc == endMarker) { + receivedChars[ndx] = '\0'; // Null-terminate the string + newData = true; // Mark new data as available + rcCheck = false; // Stop reading until the next begin marker + } + } + } +} + +// Check if new data is available +bool SerialProcess::isNewDataAvailable() { + return newData; +} + +// Get the received data +char* SerialProcess::getReceivedData() { + if (newData) { + newData = false; // Reset the flag after accessing the data + return receivedChars; + } + return nullptr; // No new data +} + +// Process the received message +void SerialProcess::getPayload(char *payload) { + if (newData) { + uint8_t source; + uint8_t destination; + char data[255]; // Allocate a buffer for the data + int parsed = sscanf(receivedChars, "#%hhu:%hhu:%63s;", &source, &destination, data); + if (parsed == 3 && destination == address) { // Ensure all fields are parsed correctly + strcpy(payload, data); // Copy data to the provided buffer + newData = false; // Mark the data as processed + } else if (address != source) { + Serial.print(receivedChars); // Forward the message + } + } +} + +// Send a message in the correct format +void SerialProcess::sendMessage(int receiver, const char* payload) { + Serial.printf("#%u:%u:%s;", address, receiver, payload); +} + + +void SerialProcess::changeAddress(int addr) { + address = addr; // Update the device address +} \ No newline at end of file diff --git a/C/ES/PlatformIO/Projects/ES state machine/src/main.cpp b/C/ES/PlatformIO/Projects/ES state machine/src/main.cpp new file mode 100755 index 0000000..7fbdcae --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES state machine/src/main.cpp @@ -0,0 +1,238 @@ +#include +#include "SerialProcess.h" + +#define LEDRED 14 +#define LEDORANGE 13 +#define LEDGREEN 12 + +unsigned long previousMillis = 0; +const unsigned long greenDuration = 5000; +const unsigned long yellowDuration = 2000; +const unsigned long redDuration = 5000; +const unsigned long transitionDuration = 2000; +const unsigned long heartbeatInterval = 1000; +const unsigned long heartbeatTimeout = 3000; +const unsigned long blinkInterval = 500; +unsigned long lastHeartbeatMillis = 0; +unsigned long lastBlinkMillis = 0; +bool blinkState = false; + +enum State { GREEN, YELLOW, RED, TRANSITION, ERROR }; +State currentState = GREEN; + +const char *slavecheck = "#slvchck;"; +const char *slaveack = "#slvack;"; +const char *masterack = "#mstack;"; + +const char *turnRed = "tr"; +const char *turnOrange = "to"; +const char *turnGreen = "tg"; +const char *heartbeat = "hb"; + +int node; // other bord addres number +int address = 0; // Device address + +void setRed(){ + digitalWrite(LEDRED, HIGH); + digitalWrite(LEDORANGE, LOW); + digitalWrite(LEDGREEN, LOW); +} +void setOrange(){ + digitalWrite(LEDRED, LOW); + digitalWrite(LEDORANGE, HIGH); + digitalWrite(LEDGREEN, LOW); +} +void setGreen(){ + digitalWrite(LEDRED, LOW); + digitalWrite(LEDORANGE, LOW); + digitalWrite(LEDGREEN, HIGH); +} + +SerialProcess serialcom(0); + +bool MasterCheck() { + SerialProcess serialcomchecker(1000); + const unsigned long timeout = 2000; + unsigned long startTime = millis(); + bool isMaster = true; + bool checkSent = false; + bool gotResponse = false; + + delay(random(100, 600)); // Randomize startup slightly + + Serial.print(slavecheck); // Send check to see if someone replies + checkSent = true; + + while (millis() - startTime < timeout) { + if (Serial.available()) { + serialcomchecker.SerialInput(); + char* payload = serialcomchecker.getReceivedData(); + + if (strcmp(payload, slavecheck) == 0) { + // Got a check while we also sent a check — respond and become SLAVE + Serial.print(slaveack); + isMaster = false; + break; + } else if (strcmp(payload, slaveack) == 0) { + // Got an ACK from the other side — we are master + Serial.print(masterack); + isMaster = true; + break; + } else if (strcmp(payload, masterack) == 0) { + // Got master ack — we must be slave + isMaster = false; + break; + } + } + } + + // Failsafe: no response at all + if (!Serial.available() && !gotResponse) { + // Assume we are master + isMaster = true; + Serial.print(masterack); + } + + return isMaster; +} + + +void updateLights() { + switch (currentState) { + case GREEN: + setGreen(); + serialcom.sendMessage(node, turnGreen); + break; + case YELLOW: + setOrange(); + serialcom.sendMessage(node, turnOrange); + break; + case RED: + setGreen(); + serialcom.sendMessage(node, turnRed); + break; + case TRANSITION: + serialcom.sendMessage(node, turnOrange); + break; + case ERROR: + if (millis() - lastBlinkMillis >= blinkInterval) { + blinkState = !blinkState; + digitalWrite(LEDORANGE, blinkState ? HIGH : LOW); + lastBlinkMillis = millis(); + } + break; + } +} + +void sendHeartbeat() { + serialcom.sendMessage(node,heartbeat); + Serial.println("Sent: Heartbeat"); +} + +void master(){ + bool running = true; + while (running){ + unsigned long currentMillis = millis(); + + if (currentMillis - lastHeartbeatMillis >= heartbeatInterval) { + sendHeartbeat(); + lastHeartbeatMillis = currentMillis; + } + + if (currentMillis - lastHeartbeatMillis > heartbeatTimeout) { + currentState = ERROR; + updateLights(); + return; + } + + switch (currentState) { + case GREEN: + if (currentMillis - previousMillis >= greenDuration) { + currentState = YELLOW; + previousMillis = currentMillis; + updateLights(); + } + break; + case YELLOW: + if (currentMillis - previousMillis >= yellowDuration) { + currentState = RED; + previousMillis = currentMillis; + updateLights(); + } + break; + case RED: + if (currentMillis - previousMillis >= redDuration) { + currentState = TRANSITION; + previousMillis = currentMillis; + updateLights(); + } + break; + case TRANSITION: + if (currentMillis - previousMillis >= transitionDuration) { + currentState = GREEN; + previousMillis = millis(); + updateLights(); + } + break; + case ERROR: + updateLights(); + break; + } + } +} + +void setup() { + Serial.begin(115200); + pinMode(LEDGREEN, OUTPUT); + pinMode(LEDORANGE, OUTPUT); + pinMode(LEDRED, OUTPUT); + bool MorS = MasterCheck(); // Check if master or slave + //set address for master or slave + if (MorS == false){ + address = 2; // Set address for this slave + node = 1; // Set address for master + } else { + address = 1; // Set address for this master + node = 2; // Set address for slave + } + previousMillis = millis(); + lastHeartbeatMillis = millis(); + updateLights(); + setRed(); + serialcom.changeAddress(address); // Set address for serial communication +} + +void slave(){ + bool running = true; + char *command; + while (running && Serial.available() > 0){ + serialcom.SerialInput(); + serialcom.getPayload(command); + if (strcmp(command, turnRed)) setRed(); + else if (strcmp(command, turnOrange)) setOrange(); + else if (strcmp(command, turnGreen)) setGreen(); + else if (strcmp(command, heartbeat)) { + lastHeartbeatMillis = millis(); + digitalWrite(LEDRED, LOW); // Reset the orange blink pattern + digitalWrite(LEDORANGE, LOW); + } + else { + Serial.print("slave: unknown command"); + } + } + if (millis() - lastHeartbeatMillis > heartbeatTimeout) { + // Blink the red and yellow LEDs to indicate an error (orange light) + if (millis() - lastBlinkMillis >= blinkInterval) { + blinkState = !blinkState; + digitalWrite(LEDORANGE, blinkState ? HIGH : LOW); + lastBlinkMillis = millis(); + } + } +} + +void loop(){ + serialcom.changeAddress(2); + if (address == 1) slave(); //master + else if (address == 2) slave(); //slave + else Serial.print("master slave issue"); +} diff --git a/C/ES/PlatformIO/Projects/ES state machine/test/README b/C/ES/PlatformIO/Projects/ES state machine/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES state machine/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/C/ES/PlatformIO/Projects/ES2_1_C/.gitignore b/C/ES/PlatformIO/Projects/ES2_1_C/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES2_1_C/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/C/ES/PlatformIO/Projects/ES2_1_C/.vscode/extensions.json b/C/ES/PlatformIO/Projects/ES2_1_C/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES2_1_C/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/C/ES/PlatformIO/Projects/ES2_1_C/include/README b/C/ES/PlatformIO/Projects/ES2_1_C/include/README new file mode 100644 index 0000000..49819c0 --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES2_1_C/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/C/ES/PlatformIO/Projects/ES2_1_C/lib/README b/C/ES/PlatformIO/Projects/ES2_1_C/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES2_1_C/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/C/ES/PlatformIO/Projects/ES2_1_C/platformio.ini b/C/ES/PlatformIO/Projects/ES2_1_C/platformio.ini new file mode 100644 index 0000000..ea23b77 --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES2_1_C/platformio.ini @@ -0,0 +1,14 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:uno] +platform = atmelavr +board = uno +framework = arduino diff --git a/C/ES/PlatformIO/Projects/ES2_1_C/src/main.cpp b/C/ES/PlatformIO/Projects/ES2_1_C/src/main.cpp new file mode 100644 index 0000000..b0d7c6a --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES2_1_C/src/main.cpp @@ -0,0 +1,14 @@ +#include + +int analogValue; +int readPin = 23; +void setup() { + Serial.begin(115200); + pinMode(readPin,INPUT); +} + +void loop() { + analogValue = analogRead(readPin); + Serial.print(analogValue); +} + diff --git a/C/ES/PlatformIO/Projects/ES2_1_C/test/README b/C/ES/PlatformIO/Projects/ES2_1_C/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/C/ES/PlatformIO/Projects/ES2_1_C/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/C/ES/PlatformIO/Projects/esp32test/.gitignore b/C/ES/PlatformIO/Projects/esp32test/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/C/ES/PlatformIO/Projects/esp32test/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/C/ES/PlatformIO/Projects/esp32test/.vscode/extensions.json b/C/ES/PlatformIO/Projects/esp32test/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/C/ES/PlatformIO/Projects/esp32test/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/C/ES/PlatformIO/Projects/esp32test/include/README b/C/ES/PlatformIO/Projects/esp32test/include/README new file mode 100644 index 0000000..49819c0 --- /dev/null +++ b/C/ES/PlatformIO/Projects/esp32test/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/C/ES/PlatformIO/Projects/esp32test/lib/README b/C/ES/PlatformIO/Projects/esp32test/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/C/ES/PlatformIO/Projects/esp32test/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/C/ES/PlatformIO/Projects/esp32test/platformio.ini b/C/ES/PlatformIO/Projects/esp32test/platformio.ini new file mode 100644 index 0000000..8dd1b2d --- /dev/null +++ b/C/ES/PlatformIO/Projects/esp32test/platformio.ini @@ -0,0 +1,15 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32dev] +platform = espressif32 +board = esp32dev +framework = arduino +monitor_speed = 115200 \ No newline at end of file diff --git a/C/ES/PlatformIO/Projects/esp32test/src/main.cpp b/C/ES/PlatformIO/Projects/esp32test/src/main.cpp new file mode 100644 index 0000000..91eff1f --- /dev/null +++ b/C/ES/PlatformIO/Projects/esp32test/src/main.cpp @@ -0,0 +1,15 @@ +#include + +int analogValue; +int readPin = 32; +void setup() { + Serial.begin(115200); + analogReadResolution(10); + pinMode(readPin,INPUT); +} + +void loop() { + analogValue = analogRead(readPin); + Serial.println(840); +} + diff --git a/C/ES/PlatformIO/Projects/esp32test/test/README b/C/ES/PlatformIO/Projects/esp32test/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/C/ES/PlatformIO/Projects/esp32test/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas (1).zip b/C/t-oer-prc2-cbdb-main-Assignments-Adidas (1).zip new file mode 100644 index 0000000..b4938a9 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main-Assignments-Adidas (1).zip differ diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/.vscode/c_cpp_properties.json b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..653e1ee --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "${workspaceFolder}/Assignments/Adidas/Unity", + "${workspaceFolder}/Assignments/Adidas/BitStuff/product" + ], + "defines": [], + "compilerPath": "/usr/bin/clang", + "cStandard": "c17", + "cppStandard": "c++14", + "intelliSenseMode": "linux-clang-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/.vscode/settings.json b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/.vscode/settings.json new file mode 100644 index 0000000..ab9995c --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "parity.h": "c", + "stddef.h": "c", + "encode.h": "c" + } +} \ No newline at end of file diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/.gitignore b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/.gitignore new file mode 100644 index 0000000..8e048a9 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/.gitignore @@ -0,0 +1,9 @@ +encode +channel +decode +encode_test +channel_test +decode_test +a.tmp +b.tmp +c.tmp diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/.~lock.Assignment - Adidas.docx# b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/.~lock.Assignment - Adidas.docx# new file mode 100644 index 0000000..d12518a --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/.~lock.Assignment - Adidas.docx# @@ -0,0 +1 @@ +,thijs,thijs,20.05.2025 13:21,file:///home/thijs/.config/libreoffice/4; \ No newline at end of file diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Adidas-module-design.pptx b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Adidas-module-design.pptx new file mode 100644 index 0000000..fb142d9 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Adidas-module-design.pptx differ diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Assignment - Adidas.docx b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Assignment - Adidas.docx new file mode 100644 index 0000000..deff4e8 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Assignment - Adidas.docx differ diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Makefile b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Makefile new file mode 100644 index 0000000..35e0c37 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Makefile @@ -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) diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity.c new file mode 100644 index 0000000..7b10aa6 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity.c @@ -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 +#include + +#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; +} diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity.h b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity.h new file mode 100644 index 0000000..8b16111 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity.h @@ -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 diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity_internals.h b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity_internals.h new file mode 100644 index 0000000..b0d0637 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity_internals.h @@ -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 +#include + +//------------------------------------------------------- +// 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 diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity_test_module.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity_test_module.c new file mode 100644 index 0000000..ba18f7f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity_test_module.c @@ -0,0 +1,97 @@ +#include "unity_test_module.h" +#include +#include +#include +#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(); +} diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity_test_module.h b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity_test_module.h new file mode 100644 index 0000000..c16ec8d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/Unity/unity_test_module.h @@ -0,0 +1,31 @@ +#ifndef UNITY_TEST_MODULE_H +#define UNITY_TEST_MODULE_H + +#include + +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 diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/build/.gitkeep b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/build/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/build/.gitkeep @@ -0,0 +1 @@ + diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/build/main b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/build/main new file mode 100755 index 0000000..3cdbfcd Binary files /dev/null and b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/build/main differ diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/build/main_test b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/build/main_test new file mode 100755 index 0000000..fa6f990 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/build/main_test differ diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/channel_main.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/channel_main.c new file mode 100644 index 0000000..1a28f3e --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/channel_main.c @@ -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; +} diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/decode_main.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/decode_main.c new file mode 100644 index 0000000..7ed5d24 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/decode_main.c @@ -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; +} diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/encode_main.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/encode_main.c new file mode 100644 index 0000000..85f6124 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/encode_main.c @@ -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; +} diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/main.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/main.c new file mode 100644 index 0000000..b640df1 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/product/main.c @@ -0,0 +1,38 @@ +#include +#include +#include + +#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; +} diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/channel.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/channel.c new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/channel.h b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/channel.h new file mode 100644 index 0000000..910a626 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/channel.h @@ -0,0 +1,22 @@ +#ifndef CHANNEL_H +#define CHANNEL_H + +#include + + +/*! + * 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 + diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/decode.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/decode.c new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/decode.h b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/decode.h new file mode 100644 index 0000000..5ed4e2e --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/decode.h @@ -0,0 +1,29 @@ +#ifndef DECODE_H_ +#define DECODE_H_ + +#include + +/*! + * 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 + diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/encode.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/encode.c new file mode 100644 index 0000000..047f6bf --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/encode.c @@ -0,0 +1,27 @@ +#include "encode.h" +#include "parity.h" +#include +#include + +void encode_get_nibbles(uint8_t value, uint8_t* high, uint8_t* low) { + if (high == NULL || low == NULL) { + return; + } + *high = (value >> 4) & 0x0F; // bits 7-4 + *low = value & 0x0F; // bits 3-0 +} + +void encode_value(uint8_t input, uint8_t* high, uint8_t* low) { + if (high == NULL || low == NULL) { + return; + } + + uint8_t nibble_high, nibble_low; + + // Splits input-byte in twee nibbles + encode_get_nibbles(input, &nibble_high, &nibble_low); + + // Voeg pariteitsbits toe + *high = add_parity(nibble_high); + *low = add_parity(nibble_low); +} \ No newline at end of file diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/encode.h b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/encode.h new file mode 100644 index 0000000..1aff76d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/encode.h @@ -0,0 +1,32 @@ +#ifndef ENCODE_H_ +#define ENCODE_H_ + +#include +#include + +/*! + * 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); + +#endif + diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/parity.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/parity.c new file mode 100644 index 0000000..6e43836 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/parity.c @@ -0,0 +1,16 @@ +#include "parity.h" + +uint8_t add_parity(uint8_t nibble) { + + uint8_t d0 = (nibble >> 0) & 1; + uint8_t d1 = (nibble >> 1) & 1; + uint8_t d2 = (nibble >> 2) & 1; + uint8_t d3 = (nibble >> 3) & 1; + + // Stel pariteitsbits samen (voorbeeld: p0 = even(d0, d1, d3), etc.) + uint8_t p0 = (d0 ^ d1 ^ d2) % 1; + uint8_t p1 = (d0 ^ d1 ^ d3) % 1; + uint8_t p2 = (d1 ^ d2 ^ d3) % 1; + + // Plaats bits op juiste posities: d3–d0 op bits 7–4, p2–p0 op bits 2–0 + return (nibble << 4) | (p2 << 2) | (p1 << 1) | (p0 << 0);} diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/parity.h b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/parity.h new file mode 100644 index 0000000..ed44af9 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/parity.h @@ -0,0 +1,8 @@ +#ifndef PARITY_H +#define PARITY_H + +#include + +uint8_t add_parity(uint8_t nibble); + +#endif diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/channel_test.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/channel_test.c new file mode 100644 index 0000000..86529e8 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/channel_test.c @@ -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(); +} diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/decode_test.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/decode_test.c new file mode 100644 index 0000000..0e08dc0 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/decode_test.c @@ -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(); +} diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/encode_test.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/encode_test.c new file mode 100644 index 0000000..157ce7f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/encode_test.c @@ -0,0 +1,87 @@ +#include +#include // for close() + +#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) + +// Setup/teardown hooks +extern void encode_setUp(void) {} +extern void encode_tearDown(void) {} + +/// --- TEST: encode_get_nibbles --- + +void test_encode_get_nibbles_normal(void) { + uint8_t high, low; + encode_get_nibbles(0xAB, &high, &low); // 0xAB = 10101011 + TEST_ASSERT_EQUAL_UINT8(0x0A, high); // 1010 + TEST_ASSERT_EQUAL_UINT8(0x0B, low); // 1011 +} + +void test_encode_get_nibbles_null_ptrs(void) { + uint8_t value = 0xAA; + encode_get_nibbles(value, NULL, NULL); // mag niet crashen + // Geen assert nodig; slaagt bij geen crash +} + +void test_encode_value_normal(void) { + uint8_t high, low; + encode_value(0xAC, &high, &low); // 0xA = 1010, 0xC = 1100 + TEST_ASSERT_EQUAL_UINT8(add_parity(0xA), high); + TEST_ASSERT_EQUAL_UINT8(add_parity(0xC), low); +} + +void test_encode_value_null_pointers(void) { + encode_value(0x55, NULL, NULL); // mag niet crashen +} + +void test_encode_value_all_zeros(void) { + uint8_t high, low; + encode_value(0x00, &high, &low); + TEST_ASSERT_EQUAL_UINT8(add_parity(0x00), high); + TEST_ASSERT_EQUAL_UINT8(add_parity(0x00), low); +} + +void test_encode_value_all_ones(void) { + uint8_t high, low; + encode_value(0xFF, &high, &low); + TEST_ASSERT_EQUAL_UINT8(add_parity(0x0F), high); // 1111 + TEST_ASSERT_EQUAL_UINT8(add_parity(0x0F), low); // 1111 +} + +void test_encode_value_output_differs_from_input(void) { + uint8_t input = 0x3C; + uint8_t high, low; + encode_value(input, &high, &low); + TEST_ASSERT_NOT_EQUAL(input, high); + TEST_ASSERT_NOT_EQUAL(input, low); +} + +void test_encode_value_is_consistent(void) { + uint8_t h1, l1, h2, l2; + encode_value(0x6E, &h1, &l1); + encode_value(0x6E, &h2, &l2); + TEST_ASSERT_EQUAL_UINT8(h1, h2); + TEST_ASSERT_EQUAL_UINT8(l1, l2); +} + + +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_value_all_ones); + MY_RUN_TEST(test_encode_value_output_differs_from_input); + MY_RUN_TEST(test_encode_value_is_consistent); + + UnityUnregisterSetupTearDown(); +} diff --git a/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/main.c b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/main.c new file mode 100644 index 0000000..5be7c1d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/test/main.c @@ -0,0 +1,27 @@ +#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(); +/* + * 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}, + { "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); +} diff --git a/C/t-oer-prc2-cbdb-main.zip b/C/t-oer-prc2-cbdb-main.zip new file mode 100644 index 0000000..9ad61b6 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/.gitignore b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/.gitignore new file mode 100644 index 0000000..271edd6 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/.gitignore @@ -0,0 +1,2 @@ +animal_shelter +admin_test diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/2-Assignment - AnimalShelter.docx.url b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/2-Assignment - AnimalShelter.docx.url new file mode 100644 index 0000000..6f4c31f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/2-Assignment - AnimalShelter.docx.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://git.fhict.nl/technology/t-oer-prc2/-/blob/master/arrays/challenges/animal-shelter/2-Assignment%20-%20AnimalShelter.docx diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Makefile b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Makefile new file mode 100644 index 0000000..35ace1c --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Makefile @@ -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) diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity.c b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity.c new file mode 100644 index 0000000..7b10aa6 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity.c @@ -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 +#include + +#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; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity.h b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity.h new file mode 100644 index 0000000..8b16111 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity.h @@ -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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity_internals.h b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity_internals.h new file mode 100644 index 0000000..b0d0637 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity_internals.h @@ -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 +#include + +//------------------------------------------------------- +// 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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity_test_module.c b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity_test_module.c new file mode 100644 index 0000000..ba18f7f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity_test_module.c @@ -0,0 +1,97 @@ +#include "unity_test_module.h" +#include +#include +#include +#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(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity_test_module.h b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity_test_module.h new file mode 100644 index 0000000..c16ec8d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/Unity/unity_test_module.h @@ -0,0 +1,31 @@ +#ifndef UNITY_TEST_MODULE_H +#define UNITY_TEST_MODULE_H + +#include + +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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/build/.gitkeep b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/build/main b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/build/main new file mode 100755 index 0000000..ae43b77 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/build/main differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/build/main_test b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/build/main_test new file mode 100755 index 0000000..4125116 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/build/main_test differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/product/main.c b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/product/main.c new file mode 100644 index 0000000..b4858d7 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/product/main.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include + +#include "administration.h" +#include "animal.h" +#include "terminal_io.h" + + +static void addTestData(Animal* animals, size_t* nrAnimals) +{ + Animal a1 = { 1, Dog, Male, 12, { 1, 2, 3 } }; + Animal a2 = { 2, Cat, Female, 4, { 4, 3, 2 } }; + Animal a3 = { 3, Parrot, Male, 40, { 8, 9, 10 } }; + Animal a4 = { 4, Dog, Female, 1, { 1, 1, 100 } }; + Animal a5 = { 5, GuineaPig, Male, 3, { 3, 4, 1 } }; + + animals[(*nrAnimals)++] = a1; + animals[(*nrAnimals)++] = a2; + animals[(*nrAnimals)++] = a3; + animals[(*nrAnimals)++] = a4; + animals[(*nrAnimals)++] = a5; +} + +int main(int argc, char* argv[]) +{ + const size_t MaxNrAnimals = 20; + Animal animals[MaxNrAnimals]; + size_t nrAnimals = 0; + MenuOptions choice = MO_SHOW_ANIMALS; + + addTestData(animals, &nrAnimals); + + printf("PRC assignment 'Animal Shelter'\n" + "-------------------------------------------"); + + if (argc != 1) + { + fprintf(stderr, "%s: argc=%d\n", argv[0], argc); + } + + while (choice != MO_QUIT) + { + printf("\n\nMENU\n====\n\n"); + choice = getMenuChoice(); + + switch (choice) + { + case MO_SHOW_ANIMALS: + printAnimals(animals, nrAnimals); + break; + case MO_ADD_ANIMAL: + break; + case MO_REMOVE_ANIMAL: + break; + case MO_SORT_ANIMALS_BY_AGE: + break; + case MO_SORT_ANIMALS_BY_YEAR_FOUND: + break; + case MO_SORT_ANIMALS_BY_SEX: + break; + case MO_FIND_ANIMAL: + break; + case MO_SAVE: + break; + case MO_LOAD: + break; + case MO_QUIT: + break; + default: + printf("ERROR: invalid choice: %d\n", choice); + break; + } + } + return 0; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/product/terminal_io.c b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/product/terminal_io.c new file mode 100644 index 0000000..59dd5b0 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/product/terminal_io.c @@ -0,0 +1,98 @@ +#include +#include + +#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); + } + } + } +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/product/terminal_io.h b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/product/terminal_io.h new file mode 100644 index 0000000..c0c6036 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/product/terminal_io.h @@ -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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/administration.c b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/administration.c new file mode 100644 index 0000000..8a032fe --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/administration.c @@ -0,0 +1,59 @@ +#include "administration.h" + +#include +#include +#include +#include +#include "animal.h" + +int addAnimal(const Animal* animalPtr, Animal* animalArray, size_t animalArrayLength, size_t numberOfAnimalsPresent, size_t* newNumberOfAnimalsPresent){ + int fault = 0; + if (animalArray == NULL || animalPtr == NULL || numberOfAnimalsPresent >= animalArrayLength) { + fault = -1; // Invalid + } else { + animalArray[numberOfAnimalsPresent] = *animalPtr; + ++numberOfAnimalsPresent; + } + *newNumberOfAnimalsPresent = numberOfAnimalsPresent; + return fault; +} + +int removeAnimal(int animalId, Animal* animalArray, size_t numberOfAnimalsPresent, size_t* newNumberOfAnimalsPresent){ + int fault = -1; + if (animalArray == NULL || numberOfAnimalsPresent == 0) { + fault = -1; // Invalid + } else { + for (size_t i = 0; i < numberOfAnimalsPresent; ++i) { + if (animalArray[i].Id == animalId) { + // move the array elements to the left to remove the animal + for (size_t j = i; j < numberOfAnimalsPresent - 1; ++j) { + animalArray[j] = animalArray[j + 1]; + } + --numberOfAnimalsPresent; + fault = 0; + break; + } + } + } + *newNumberOfAnimalsPresent = numberOfAnimalsPresent; + return fault; +} + +int findAnimalById(int animalId, const Animal* animalArray, size_t numberOfAnimalsPresent, Animal* foundAnimal) { + int fault = -1; + if (animalArray == NULL || numberOfAnimalsPresent == 0 || foundAnimal == NULL) { + fault = -1; + } else { + for (size_t i = 0; i < numberOfAnimalsPresent; i++) { + if (animalArray[i].Id == animalId) { + *foundAnimal = animalArray[i]; + fault = 0; + break; // Exit loop after finding the animal + } + } + if (fault == -1) { // Only zero out if animal wasn't found + memset(foundAnimal, 0, sizeof(Animal)); + } + } + return fault; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/administration.h b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/administration.h new file mode 100644 index 0000000..5872413 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/administration.h @@ -0,0 +1,56 @@ +#ifndef ADMINISTRATION_H +#define ADMINISTRATION_H + +#include + +#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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/animal.h b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/animal.h new file mode 100644 index 0000000..227c71d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/animal.h @@ -0,0 +1,37 @@ +#ifndef ANIMAL_H +#define ANIMAL_H + +typedef enum +{ + Cat, + Dog, + GuineaPig, + Parrot +} Species; + +typedef enum +{ + Male, + Female +} Sex; + +typedef struct +{ + int Day; + int Month; + int Year; +} Date; + +#define MaxNameLength 25 +#define MaxLocationLength 100 + +typedef struct +{ + int Id; + Species Species; + Sex Sex; + int Age; + Date DateFound; +} Animal; + +#endif diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/file_element.c b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/file_element.c new file mode 100644 index 0000000..cc4710e --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/file_element.c @@ -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; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/file_element.h b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/file_element.h new file mode 100644 index 0000000..ab8cf2f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/shared/file_element.h @@ -0,0 +1,66 @@ +#ifndef FILE_ELEMENT_H +#define FILE_ELEMENT_H + +#include + +#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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/test/administration_test.c b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/test/administration_test.c new file mode 100644 index 0000000..3d33366 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/test/administration_test.c @@ -0,0 +1,86 @@ +#include + +#include "administration.h" +#include "unity.h" +#include "unity_test_module.h" + +// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number +#define MY_RUN_TEST(func) RUN_TEST(func, 0) + +// Keep the original array constant to prevent modifications +const Animal originalArray[5] = { + {.Id = 1, .Species = Cat, .Age = 8, .Sex = Male, .DateFound = {1, 1, 2020}}, + {.Id = 2, .Species = Dog, .Age = 2, .Sex = Female, .DateFound = {1, 1, 2021}}, + {.Id = 3, .Species = GuineaPig, .Age = 92, .Sex = Female, .DateFound = {1, 1, 2022}} +}; + +// Arrays for testing +Animal animalArray[5]; +Animal searchArray[5]; + +void administration_setUp(void) { + // Reset both arrays before each test + memcpy(animalArray, originalArray, sizeof(originalArray)); + memcpy(searchArray, originalArray, sizeof(originalArray)); +} + +void administration_tearDown(void){} + +void test_administration_remove_valid(void){ + size_t newNumberOfAnimalsPresent = 0; + int errorCode = removeAnimal(2, animalArray, 3, &newNumberOfAnimalsPresent); + TEST_ASSERT_EQUAL(0, errorCode); + TEST_ASSERT_EQUAL(2, newNumberOfAnimalsPresent); +} + +void test_administration_remove_invalid(void){ + size_t newNumberOfAnimalsPresent = 0; + int errorCode = removeAnimal(12, animalArray, 3, &newNumberOfAnimalsPresent); + TEST_ASSERT_EQUAL(-1, errorCode); + TEST_ASSERT_EQUAL(3, newNumberOfAnimalsPresent); +} + +void test_administration_add_valid(void){ + Animal newAnimal = {.Id = 4, .Species = Dog, .Age = 3, .Sex = Male, .DateFound = {1, 1, 2023}}; + size_t newNumberOfAnimalsPresent = 0; + int errorCode = addAnimal(&newAnimal, animalArray, 5, 3, &newNumberOfAnimalsPresent); + TEST_ASSERT_EQUAL(0, errorCode); + TEST_ASSERT_EQUAL(4, newNumberOfAnimalsPresent); +} + +void test_administration_add_invalid(void){ + Animal newAnimal = {.Id = 5, .Species = Cat, .Age = 2, .Sex = Female, .DateFound = {1, 1, 2024}}; + size_t newNumberOfAnimalsPresent = 0; + int errorCode = addAnimal(&newAnimal, animalArray, 3, 3, &newNumberOfAnimalsPresent); + TEST_ASSERT_EQUAL(-1, errorCode); + TEST_ASSERT_EQUAL(3, newNumberOfAnimalsPresent); +} + +void test_administration_find_valid(void){ + Animal foundAnimalV; + int errorCode = findAnimalById(2, searchArray, 3, &foundAnimalV); + TEST_ASSERT_EQUAL(0, errorCode); + TEST_ASSERT_EQUAL(2, foundAnimalV.Id); + TEST_ASSERT_EQUAL(Dog, foundAnimalV.Species); +} + +void test_administration_find_invalid(void){ + Animal foundAnimalinV; + int errorCode = findAnimalById(12, searchArray, 3, &foundAnimalinV); + TEST_ASSERT_EQUAL(-1, errorCode); + TEST_ASSERT_EQUAL(0, foundAnimalinV.Id); +} + +void run_administration_tests() +{ + UnityRegisterSetupTearDown(administration_setUp, administration_tearDown); + + MY_RUN_TEST(test_administration_remove_valid); + MY_RUN_TEST(test_administration_remove_invalid); + MY_RUN_TEST(test_administration_add_valid); + MY_RUN_TEST(test_administration_add_invalid); + MY_RUN_TEST(test_administration_find_valid); + MY_RUN_TEST(test_administration_find_invalid); + + UnityUnregisterSetupTearDown(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/test/file_element_test.c b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/test/file_element_test.c new file mode 100644 index 0000000..16fd978 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/test/file_element_test.c @@ -0,0 +1,34 @@ +#include + +#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(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/test/main.c b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/test/main.c new file mode 100644 index 0000000..4595f44 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/AnimalShelter/test/main.c @@ -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); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/.gitignore b/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/.gitignore new file mode 100644 index 0000000..ba2906d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/.gitignore @@ -0,0 +1 @@ +main diff --git a/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/1-Assignment - bike computer - Makefile and Headerfiles.docx b/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/1-Assignment - bike computer - Makefile and Headerfiles.docx new file mode 100644 index 0000000..bc87cc3 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/1-Assignment - bike computer - Makefile and Headerfiles.docx differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/Makefile b/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/Makefile new file mode 100644 index 0000000..886cd3e --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/Makefile @@ -0,0 +1,20 @@ +NAME=main + +FILES=main.c + +CC=gcc + +SYMBOLS=-g -O0 -std=c99 -Wall -Werror -Wextra -pedantic -Wno-unused-parameter + +.PHONY: clean + +all: product + +product: Makefile $(FILES) + $(CC) $(INC_DIRS) $(SYMBOLS) $(FILES) -o $(NAME) + +run: product + ./$(NAME) + +clean: + rm -f $(NAME) diff --git a/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/main.c b/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/main.c new file mode 100644 index 0000000..cabf530 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/BikeComputer/main.c @@ -0,0 +1,256 @@ +#include +#include +#include +#include +#include + +/*---------------------------------------------------------------*/ +#define BIKE_COMPUTER_SIMULATOR_VALUE_MIN_SPEED (27) +#define BIKE_COMPUTER_SIMULATOR_VALUE_MAX_SPEED (30) + +#define BIKE_COMPUTER_SIMULATOR_VALUE_MIN_POWER (150) +#define BIKE_COMPUTER_SIMULATOR_VALUE_MAX_POWER (200) + +#define BIKE_COMPUTER_SIMULATOR_VALUE_MIN_HEART_RATE (130) +#define BIKE_COMPUTER_SIMULATOR_VALUE_MAX_HEART_RATE (140) + +#define BIKE_COMPUTER_SIMULATOR_VALUE_MIN_CADENCE (88) +#define BIKE_COMPUTER_SIMULATOR_VALUE_MAX_CADENCE (98) + +#define BIKE_STORE_MAX_NUMBER_MEASUREMENTS (32) + +typedef enum { + BIKE_SPEED, + BIKE_HEART_RATE, + BIKE_CADENCE, + BIKE_POWER +} bike_data_type; + +typedef struct +{ + uint16_t speed; + uint16_t heart_rate; + uint16_t cadence; + uint16_t power; +} bike_store_measurement; + +bike_store_measurement bike_store_array[BIKE_STORE_MAX_NUMBER_MEASUREMENTS] = { + { 0, }, +}; +uint16_t bike_store_number_of_measurements_present = 0; + +/*---------------------------------------------------------------*/ +uint16_t +bike_computer_simulator_get_random_value(uint16_t min_range, uint16_t max_range) +{ + uint16_t range = (max_range - min_range); + + uint16_t random_value = min_range + (rand() % range); + + return random_value; +} + +uint16_t bike_measure_speed_in_kmh() +{ + return bike_computer_simulator_get_random_value( + BIKE_COMPUTER_SIMULATOR_VALUE_MIN_SPEED, + BIKE_COMPUTER_SIMULATOR_VALUE_MAX_SPEED); +} + +uint16_t bike_measure_power_in_watt() +{ + return bike_computer_simulator_get_random_value( + BIKE_COMPUTER_SIMULATOR_VALUE_MIN_POWER, + BIKE_COMPUTER_SIMULATOR_VALUE_MAX_POWER); +} + +uint16_t bike_measure_cadence_in_rpm() +{ + return bike_computer_simulator_get_random_value( + BIKE_COMPUTER_SIMULATOR_VALUE_MIN_CADENCE, + BIKE_COMPUTER_SIMULATOR_VALUE_MAX_CADENCE); +} + +uint16_t bike_measure_heart_rate_in_bpm() +{ + return bike_computer_simulator_get_random_value( + BIKE_COMPUTER_SIMULATOR_VALUE_MIN_HEART_RATE, + BIKE_COMPUTER_SIMULATOR_VALUE_MAX_HEART_RATE); +} + +/*---------------------------------------------------------------*/ +uint16_t bike_store_get_maximum_bike_store_size() +{ + return BIKE_STORE_MAX_NUMBER_MEASUREMENTS; +} + +void bike_store_add_measurement(bike_store_measurement value) +{ + if (bike_store_number_of_measurements_present >= + bike_store_get_maximum_bike_store_size()) + { + bike_store_number_of_measurements_present = 0; + } + + bike_store_array[bike_store_number_of_measurements_present] = value; + bike_store_number_of_measurements_present++; +} + +uint16_t bike_store_get_number_of_measurements_present() +{ + return bike_store_number_of_measurements_present; +} + +bike_store_measurement bike_store_get_measurement(uint16_t index_position) +{ + bike_store_measurement value = bike_store_array[index_position]; + + return value; +} + +/*---------------------------------------------------------------*/ +uint16_t bike_math_get_value_for_data_type( + bike_store_measurement measurement, bike_data_type data_type) +{ + uint16_t value = 0; + + if (data_type == BIKE_CADENCE) + { + value = measurement.cadence; + } + else if (data_type == BIKE_SPEED) + { + value = measurement.speed; + } + else if (data_type == BIKE_HEART_RATE) + { + value = measurement.heart_rate; + } + else if (data_type == BIKE_POWER) + { + value = measurement.power; + } + + return value; +} + +uint16_t bike_math_calculate_min_value(bike_data_type data_type) +{ + uint16_t number_of_measurements = + bike_store_get_number_of_measurements_present(); + + uint16_t min_value = UINT16_MAX; + + for (uint16_t index_position = 0; index_position < number_of_measurements; + index_position++) + { + bike_store_measurement measurement = + bike_store_get_measurement(index_position); + uint16_t value = + bike_math_get_value_for_data_type(measurement, data_type); + if (value < min_value) + { + min_value = value; + } + } + + return min_value; +} + +uint16_t bike_math_calculate_max_value(bike_data_type data_type) +{ + uint16_t number_of_measurements = + bike_store_get_number_of_measurements_present(); + + uint16_t max_value = 0; + + for (uint16_t index_position = 0; index_position < number_of_measurements; + index_position++) + { + bike_store_measurement measurement = + bike_store_get_measurement(index_position); + uint16_t value = + bike_math_get_value_for_data_type(measurement, data_type); + if (value > max_value) + { + max_value = value; + } + } + + return max_value; +} + +uint16_t bike_math_calculate_average_value(bike_data_type data_type) +{ + uint16_t number_of_measurements = + bike_store_get_number_of_measurements_present(); + + if (number_of_measurements == 0) + return 0; + + uint16_t average = 0; + uint32_t sum = 0; + + for (uint16_t index_position = 0; index_position < number_of_measurements; + index_position++) + { + bike_store_measurement measurement = + bike_store_get_measurement(index_position); + uint16_t value = + bike_math_get_value_for_data_type(measurement, data_type); + sum += value; + } + + average = sum / number_of_measurements; + + return average; +} + +/*---------------------------------------------------------------*/ +int main(int argc, char* argv[]) +{ + bike_store_measurement measurement; + uint16_t min = 0, max = 0, average = 0; + bike_data_type data_type; + + while (true) + { + measurement.speed = bike_measure_speed_in_kmh(); + measurement.cadence = bike_measure_cadence_in_rpm(); + measurement.heart_rate = bike_measure_heart_rate_in_bpm(); + measurement.power = bike_measure_power_in_watt(); + + bike_store_add_measurement(measurement); + + data_type = BIKE_SPEED; + min = bike_math_calculate_min_value(data_type); + max = bike_math_calculate_max_value(data_type); + average = bike_math_calculate_average_value(data_type); + printf("SPEED:\t\t%d, average = %d, min = %d, max = %d [km/h]\n", + measurement.speed, average, min, max); + + data_type = BIKE_CADENCE; + min = bike_math_calculate_min_value(data_type); + max = bike_math_calculate_max_value(data_type); + average = bike_math_calculate_average_value(data_type); + printf("CADENCE:\t%d, average = %d, min = %d, max = %d [rpm]\n", + measurement.cadence, average, min, max); + + data_type = BIKE_HEART_RATE; + min = bike_math_calculate_min_value(data_type); + max = bike_math_calculate_max_value(data_type); + average = bike_math_calculate_average_value(data_type); + printf("HEART-RATE:\t%d, average = %d, min = %d, max = %d [hrm]\n", + measurement.heart_rate, average, min, max); + + data_type = BIKE_POWER; + min = bike_math_calculate_min_value(data_type); + max = bike_math_calculate_max_value(data_type); + average = bike_math_calculate_average_value(data_type); + printf("POWER:\t\t%d, average = %d, min = %d, max = %d [watt]\n", + measurement.power, average, min, max); + printf("\n"); + + sleep(1); + } +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/.gitkeep b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/1-Assignment_-_BitManipulations.docx b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/1-Assignment_-_BitManipulations.docx new file mode 100644 index 0000000..8078c3e Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/1-Assignment_-_BitManipulations.docx differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Makefile b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Makefile new file mode 100644 index 0000000..a717be4 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Makefile @@ -0,0 +1,42 @@ +PROD_DIR := ./product +SHARED_DIR := ./shared +TEST_DIR := ./test +UNITY_FOLDER :=./Unity +RES_DIR := ./ResourceDetector +BUILD_DIR :=./build + +PROD_EXEC = main +PROD_DIRS := $(PROD_DIR) $(SHARED_DIR) $(RES_DIR) +PROD_FILES := $(wildcard $(patsubst %,%/*.c, $(PROD_DIRS))) +HEADER_PROD_FILES := $(wildcard $(patsubst %,%/*.h, $(PROD_DIRS))) +PROD_INC_DIRS=-I$(PROD_DIR) -I$(SHARED_DIR) -I$(RES_DIR) + +TEST_EXEC = main_test +TEST_DIRS := $(TEST_DIR) $(SHARED_DIR) $(RES_DIR) $(UNITY_FOLDER) +TEST_FILES := $(wildcard $(patsubst %,%/*.c, $(TEST_DIRS))) +HEADER_TEST_FILES := $(wildcard $(patsubst %,%/*.h, $(TEST_DIRS))) +TEST_INC_DIRS=-I$(TEST_DIR) -I$(SHARED_DIR) -I$(UNITY_FOLDER) -I$(RES_DIR) + +CC=gcc +SYMBOLS=-Wall -Werror -g -pedantic -O0 -std=c99 +TEST_SYMBOLS=$(SYMBOLS) -DTEST + +.PHONY: clean test + +all: $(PROD_EXEC) + +$(PROD_EXEC): Makefile $(PROD_FILES) $(HEADER_FILES) + $(CC) $(PROD_INC_DIRS) $(TEST_SYMBOLS) $(PROD_FILES) -o $(BUILD_DIR)/$(PROD_EXEC) + +$(TEST_EXEC): Makefile $(TEST_FILES) $(HEADER_FILES) + $(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(BUILD_DIR)/$(TEST_EXEC) + +run: $(PROD_EXEC) + @./$(BUILD_DIR)/$(PROD_EXEC) + +test: $(TEST_EXEC) + @./$(BUILD_DIR)/$(TEST_EXEC) + +clean: + rm -f $(BUILD_DIR)/$(PROD_EXEC) + rm -f $(BUILD_DIR)/$(TEST_EXEC) diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/.gitkeep b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity.c new file mode 100644 index 0000000..b9462c9 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity.c @@ -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 +#include + +#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; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity.h new file mode 100644 index 0000000..902edd6 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity.h @@ -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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity_internals.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity_internals.h new file mode 100644 index 0000000..4827fa1 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity_internals.h @@ -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 +#include + +//------------------------------------------------------- +// 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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity_test_module.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity_test_module.c new file mode 100644 index 0000000..ba18f7f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity_test_module.c @@ -0,0 +1,97 @@ +#include "unity_test_module.h" +#include +#include +#include +#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(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity_test_module.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity_test_module.h new file mode 100644 index 0000000..c16ec8d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/Unity/unity_test_module.h @@ -0,0 +1,31 @@ +#ifndef UNITY_TEST_MODULE_H +#define UNITY_TEST_MODULE_H + +#include + +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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/build/.gitkeep b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/build/main_test b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/build/main_test new file mode 100755 index 0000000..4346a91 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/build/main_test differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/product/.gitkeep b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/product/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/product/bit_stuff_main.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/product/bit_stuff_main.c new file mode 100644 index 0000000..857f37d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/product/bit_stuff_main.c @@ -0,0 +1,12 @@ +#include + +#include "bit_stuff.h" + +// leave resource_detector.h as last include! +#include "resource_detector.h" + +int main(int argc, char* argv[]) +{ + // TODO: implement if you want + return 0; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/shared/.gitkeep b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/shared/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/shared/bit_stuff.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/shared/bit_stuff.c new file mode 100644 index 0000000..f45d975 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/shared/bit_stuff.c @@ -0,0 +1,44 @@ +#include "bit_stuff.h" +#include +#include + +// leave resource_detector.h as last include! +#include "resource_detector.h" + +unsigned int count_ones(unsigned int value){ + unsigned int count = 0; + while (value){ + count += value & 1; + value >>= 1; + } + return count; +} + +void make_bitmask(unsigned int width, unsigned int shift, unsigned int* mask){ + if (width == 0 || width > sizeof(unsigned int)*CHAR_BIT) return; + if (width == sizeof(unsigned int) * CHAR_BIT) *mask = ~0U << shift; + else *mask = ((1U << width) - 1) << shift; +} + +void apply_bitmask(unsigned int value, unsigned int mask, unsigned int* masked_value) { + if (masked_value != NULL) { + *masked_value = value & mask; + } +} + +void flip_bit(unsigned int value, unsigned int bit_index, unsigned int* updated_value){ + + if (updated_value == 0 || bit_index >= sizeof(unsigned int) * CHAR_BIT) return; + *updated_value = value ^ (1U << bit_index); +} + +void extract_nibbles_from_byte(uint8_t value, uint8_t* high_nibble, uint8_t* low_nibble){ + if (high_nibble == NULL || low_nibble == NULL) return; + *high_nibble = (value >> 4) & 0xF; + *low_nibble = value & 0xF; +} + +void combine_nibles_to_byte(uint8_t high_nibble, uint8_t low_nibble, uint8_t* value){ + if (value == NULL) return; + *value = (high_nibble << 4) | (low_nibble); +} \ No newline at end of file diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/shared/bit_stuff.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/shared/bit_stuff.h new file mode 100644 index 0000000..9326db1 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/shared/bit_stuff.h @@ -0,0 +1,36 @@ +#pragma once + +#include + +/* 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); diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/test/.gitkeep b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/test/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/test/bit_stuff_test.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/test/bit_stuff_test.c new file mode 100644 index 0000000..aa2c6a4 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/BitStuff/test/bit_stuff_test.c @@ -0,0 +1,112 @@ +#include "bit_stuff.h" +#include "unity.h" + +// leave resource_detector.h as last include! +#include "resource_detector.h" + +// I rather dislike keeping line numbers updated, so I made my own macro to +// ditch the line number +#define MY_RUN_TEST(func) RUN_TEST(func, 0) + +void setUp(void) +{ + // This is run before EACH test +} + +void tearDown(void) +{ + // This is run after EACH test +} + +static void test_countOnes(void) +{ + TEST_ASSERT_EQUAL_UINT32(0, count_ones(0x0)); + TEST_ASSERT_EQUAL_UINT32(32, count_ones(0xffffffff)); + TEST_ASSERT_EQUAL_UINT32(16, count_ones(0x5a5a5a5a)); +} + +static void test_make_bitmask_creates_mask_with_correct_width(void) +{ + unsigned int mask = 0; + make_bitmask(1, 0, &mask); + TEST_ASSERT_EQUAL_HEX32(0x1, mask); + make_bitmask(2, 0, &mask); + TEST_ASSERT_EQUAL_HEX32(0x3, mask); + make_bitmask(5, 0, &mask); + TEST_ASSERT_EQUAL_HEX32(0x1f, mask); + make_bitmask(32, 0, &mask); + TEST_ASSERT_EQUAL_HEX32(0xffffffff, mask); +} + +static void test_make_bitmask_creates_mask_with_correct_width_and_shift(void) +{ + unsigned int mask = 0; + make_bitmask(1, 1, &mask); + TEST_ASSERT_EQUAL_HEX32(0x2, mask); + make_bitmask(1, 7, &mask); + TEST_ASSERT_EQUAL_HEX32(0x80, mask); + make_bitmask(1, 8, &mask); + TEST_ASSERT_EQUAL_HEX32(0x100, mask); + make_bitmask(3, 15, &mask); + TEST_ASSERT_EQUAL_HEX32(0x38000, mask); + make_bitmask(8, 30, &mask); + TEST_ASSERT_EQUAL_HEX32(0xC0000000, mask); +} + +static void test_countOnesInBitMask(void) +{ + unsigned int i = 0, mask = 0; + for (i = 0; i < 32; i++) + { + make_bitmask(i, 0, &mask); + TEST_ASSERT_EQUAL_UINT32(i, count_ones(mask)); + } +} + +static void test_apply_bit_mask(void) +{ + unsigned int masked_value = 0; + apply_bitmask(0xAE, 0xC3, &masked_value); + TEST_ASSERT_EQUAL(0x82, masked_value); +} + +static void test_flip_bit(void) +{ + unsigned int updated_value = 0; + flip_bit(0xB, 0, &updated_value); + TEST_ASSERT_EQUAL(0xA, updated_value); + + flip_bit(0xB, 2, &updated_value); + TEST_ASSERT_EQUAL(0xF, updated_value); +} + +static void test_extract_nibbles_from_byte(void) +{ + uint8_t high_nibble = 0, low_nibble = 0; + extract_nibbles_from_byte(0xB9, &high_nibble, &low_nibble); + TEST_ASSERT_EQUAL(0x9, low_nibble); + TEST_ASSERT_EQUAL(0xB, high_nibble); +} + +static void test_combine_nibles_to_byte(void) +{ + uint8_t value = 0; + combine_nibles_to_byte(0xB, 0x5, &value); + TEST_ASSERT_EQUAL(0xB5, value); +} + +int main(int argc, char* argv[]) +{ + UnityBegin(); + + MY_RUN_TEST(test_make_bitmask_creates_mask_with_correct_width); + MY_RUN_TEST(test_make_bitmask_creates_mask_with_correct_width_and_shift); + MY_RUN_TEST(test_countOnes); + MY_RUN_TEST(test_countOnesInBitMask); + MY_RUN_TEST(test_apply_bit_mask); + MY_RUN_TEST(test_flip_bit); + MY_RUN_TEST(test_extract_nibbles_from_byte); + MY_RUN_TEST(test_combine_nibles_to_byte); + + return UnityEnd(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/SecretService/2-Challenge Secret Service.pdf b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/SecretService/2-Challenge Secret Service.pdf new file mode 100644 index 0000000..386fbc4 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/SecretService/2-Challenge Secret Service.pdf differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/2-Assignment - Skater.docx b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/2-Assignment - Skater.docx new file mode 100644 index 0000000..de8e433 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/2-Assignment - Skater.docx differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Makefile b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Makefile new file mode 100644 index 0000000..a71daf0 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Makefile @@ -0,0 +1,41 @@ +PROD_DIR := ./product +SHARED_DIR := ./shared +TEST_DIR := ./test +UNITY_FOLDER :=./Unity +BUILD_DIR :=./build + +PROD_EXEC = main +PROD_DIRS := $(PROD_DIR) $(SHARED_DIR) +PROD_FILES := $(wildcard $(patsubst %,%/*.c, $(PROD_DIRS))) +HEADER_PROD_FILES := $(wildcard $(patsubst %,%/*.h, $(PROD_DIRS))) +PROD_INC_DIRS=-I$(PROD_DIR) -I$(SHARED_DIR) + +TEST_EXEC = main_test +TEST_DIRS := $(TEST_DIR) $(SHARED_DIR) $(UNITY_FOLDER) +TEST_FILES := $(wildcard $(patsubst %,%/*.c, $(TEST_DIRS))) +HEADER_TEST_FILES := $(wildcard $(patsubst %,%/*.h, $(TEST_DIRS))) +TEST_INC_DIRS=-I$(TEST_DIR) -I$(SHARED_DIR) -I$(UNITY_FOLDER) + +CC=gcc +SYMBOLS=-Wall -Werror -g -pedantic -O0 -std=c99 +TEST_SYMBOLS=$(SYMBOLS) -DTEST -DUNITY_USE_MODULE_SETUP_TEARDOWN + +.PHONY: clean test + +all: $(PROD_EXEC) + +$(PROD_EXEC): Makefile $(PROD_FILES) $(HEADER_FILES) + $(CC) $(PROD_INC_DIRS) $(SYMBOLS) $(PROD_FILES) -o $(BUILD_DIR)/$(PROD_EXEC) + +$(TEST_EXEC): Makefile $(TEST_FILES) $(HEADER_FILES) + $(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(BUILD_DIR)/$(TEST_EXEC) + +run: $(PROD_EXEC) + @./$(BUILD_DIR)/$(PROD_EXEC) + +test: $(TEST_EXEC) + @./$(BUILD_DIR)/$(TEST_EXEC) + +clean: + rm -f $(BUILD_DIR)/$(PROD_EXEC) + rm -f $(BUILD_DIR)/$(TEST_EXEC) diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity.c new file mode 100644 index 0000000..7b10aa6 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity.c @@ -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 +#include + +#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; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity.h new file mode 100644 index 0000000..8b16111 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity.h @@ -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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity_internals.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity_internals.h new file mode 100644 index 0000000..b0d0637 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity_internals.h @@ -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 +#include + +//------------------------------------------------------- +// 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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity_test_module.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity_test_module.c new file mode 100644 index 0000000..ba18f7f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity_test_module.c @@ -0,0 +1,97 @@ +#include "unity_test_module.h" +#include +#include +#include +#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(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity_test_module.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity_test_module.h new file mode 100644 index 0000000..c16ec8d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/Unity/unity_test_module.h @@ -0,0 +1,31 @@ +#ifndef UNITY_TEST_MODULE_H +#define UNITY_TEST_MODULE_H + +#include + +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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/doc/Assignment.txt b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/doc/Assignment.txt new file mode 100644 index 0000000..6eb6add --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/doc/Assignment.txt @@ -0,0 +1,59 @@ +A program for a skating weekend. +================================ + +General +------- +In these directories you'll find an empty project in which you can add your code for the skating program. This file contains everything you need to know. + +As usual in this assignments directory you will have a pre-made Makefile in the main directory. If you call 'make' on the commandline in that directory, the normal executable (skates) will be built. With 'make test' the test application is built and run. + +If you add new .c and .h files to the 'product' directory, these will automatically be recognized by the Makefile. For testing you can do 3 things: + 1. rename 'empty_test.c' to something sensible and include all tests in it. + 2. rename 'empty_test.c' to "your module name"_test.c and only include tests for a particular module. You'll also have to create header files for all test function prototypes and a test_main.c that runs all these tests. +Option 1 is the easiest, 2 is neater. + + +Desired features +----------------- +This program should be used for a skating weekend. In this weekend 8 skaters participate and they all ride 4 distances: + - 500 m + - 1500 m + - 5 km + - 10 km +A menu structure has already been created, more or less copied from Animal Shelter. Below are the menu options with the desired behavior: + - Show Skaters: + Shows the data of all 8 skaters. Initially all data are empty or zero. + + - Add Skater: + This option allows you to add 1 of the 8 skaters. Your code will ask the skater's name and nationality. Times cannot be entered here yet, but your administration should keep a skater's name, nationality and time for each distance. + + - Remove Skater: + This option asks which skater should be removed and clears the data of that skater. + + - Add time: + This option asks for which skater and for which distance the time should be changed. If the time increases from previous entry a warning must be given. + So: suppose skater 1 raced the 500 m distance in 50 seconds and you have already filled that in. If a user now wants to change that time to 51 seconds, your program will ask if the user is sure and will only change the time if the user was sure. + + - Show fastest times: + With this option the program asks you for which distance you want to see the times. After you have entered them, the program shows all skaters that have already ridden this distance in order from fastest to slowest. Skaters that have not ridden this distance will not be shown! + + - Show final classification: + With this option the final classification is given. The skaters are sorted on their average speed, the fastest skater is on top. + If not all skaters have ridden all distances yet, a warning will be written to the screen that this is a preliminary ranking. After this warning only the skaters who have ridden all distances will be shown. + + - Load file from disk: + Optional: if you don't want to retype all skaters every time (easier for testing your user interface!) + + - Save administration to disk: + Optional. + + - Quit: + Exits the program. IF you have implemented the Save/Load functions, the program will keep track of any data that has not been saved. If this is the case, you will first be asked if you still want to save the data before the program closes (Yes/No/Cancel or Save/Discard/Cancel). + + +Design +------- +As you learned in the first semester, the UI code may not be in the same unit (C file) as the 'rest'. This also applies here, of course. In addition, the 'rest' can certainly be subdivided into several small parts. Try to think about that. Think from different responsibilities in the application (for example: sorting of skaters is a different responsibility than reading/writing files on disk, so maybe the code should be in a separate file...). +HINT: reading and writing from the terminal is now done in terminal_io.c, so if you want to keep your design clean, the main function should not have that same responsibility. + +Good Luck! diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/product/main.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/product/main.c new file mode 100644 index 0000000..4102ffd --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/product/main.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include + +// Add your includes here: +#include "terminal_io.h" + + +int main(int argc, char* argv[]) +{ + MenuOptions choice = MO_SHOW_ICESKATERS; + printProgramHeader(); + + while (choice != MO_QUIT) + { + choice = getMenuChoice(); + + switch (choice) + { + case MO_SHOW_ICESKATERS: + fprintf(stderr, "not yet implemented\n"); + break; + case MO_ADD_ICESKATER: + fprintf(stderr, "not yet implemented\n"); + break; + case MO_REMOVE_ICESKATER: + fprintf(stderr, "not yet implemented\n"); + break; + case MO_ADD_TIME: + fprintf(stderr, "not yet implemented\n"); + break; + case MO_SHOW_CLASSIFICATION: + fprintf(stderr, "not yet implemented\n"); + break; + case MO_SHOW_FINAL_CLASSIFICATION: + fprintf(stderr, "not yet implemented\n"); + break; + case MO_LOAD: + fprintf(stderr, "not yet implemented\n"); + break; + case MO_SAVE: + fprintf(stderr, "not yet implemented\n"); + break; + case MO_QUIT: + // nothing to do here + break; + default: + fprintf(stderr, "ERROR: invalid choice: %d\n", choice); + break; + } + } + return 0; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/product/terminal_io.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/product/terminal_io.c new file mode 100644 index 0000000..83e9404 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/product/terminal_io.c @@ -0,0 +1,92 @@ +#include +#include +#include + +#include "terminal_io.h" + + +#define MAX_STRLEN 80 + +static const char* MenuStrings[] = +{ + "Show Iceskaters", + "Add Iceskater", + "Remove Iceskater", + "Add time", + "Show classification", + "Show final classification", + "Load ...", + "Save ...", + "Quit" +}; +static const size_t NrMenuStrings = + sizeof(MenuStrings) / sizeof(MenuStrings[0]); + +void clearScreen() +{ + printf("\033[2J\033[1;1H"); +} + +int getInt(const char* message) +{ + char line[MAX_STRLEN]; + char* result = NULL; + int value = -1; + + printf("%s", message); + result = fgets(line, sizeof(line), stdin); + if (result != NULL) + { + sscanf(result, "%d", &value); + } + + return value; +} + +int getLimitedInt(const char* message, const char* items[], int nrItems) +{ + int choice = -1; + do + { + if (items != NULL) + { + for (int i = 0; i < nrItems; i++) + { + printf(" [%d] %s\n", i, items[i]); + } + } + choice = getInt(message); + } while (choice < 0 || choice >= nrItems); + + return choice; +} + +void getStr(const char* message, char* str, int maxLength) +{ + char line[maxLength]; + char* result = NULL; + + printf("%s", message); + result = fgets(line, sizeof(line), stdin); + if (result != NULL) + { + if (result[strlen(result) - 1] == '\n') + { + result[strlen(result) - 1] = '\0'; + } + strncpy(str, result, maxLength); + str[maxLength - 1] = '\0'; + } +} + +MenuOptions getMenuChoice() +{ + printf("\n\nMENU\n====\n"); + return (MenuOptions)getLimitedInt("choice: ", MenuStrings, NrMenuStrings); +} + +void printProgramHeader() +{ + printf("PRC2 opdracht 'Schaatsen'\n" + "-------------------------"); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/product/terminal_io.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/product/terminal_io.h new file mode 100644 index 0000000..dce5fdb --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/product/terminal_io.h @@ -0,0 +1,27 @@ +#ifndef TERMINAL_IO_H +#define TERMINAL_IO_H + +#include "skater.h" + +typedef enum +{ + MO_SHOW_ICESKATERS, + MO_ADD_ICESKATER, + MO_REMOVE_ICESKATER, + MO_ADD_TIME, + MO_SHOW_CLASSIFICATION, + MO_SHOW_FINAL_CLASSIFICATION, + MO_LOAD, + MO_SAVE, + MO_QUIT +} MenuOptions; + +void clearScreen(); +int getInt(const char* message); +int getLimitedInt(const char* message, const char* items[], int nrItems); +void getStr(const char* message, char* str, int maxLength); +MenuOptions getMenuChoice(); + +void printProgramHeader(); + +#endif diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/shared/skater.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/shared/skater.c new file mode 100644 index 0000000..edd5683 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/shared/skater.c @@ -0,0 +1,2 @@ +#include "skater.h" + diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/shared/skater.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/shared/skater.h new file mode 100644 index 0000000..8cd4e1d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/shared/skater.h @@ -0,0 +1,6 @@ +#ifndef SKATER_H +#define SKATER_H + +// define your skater datatypes here + +#endif diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/test/main.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/test/main.c new file mode 100644 index 0000000..fa6cf5c --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/test/main.c @@ -0,0 +1,16 @@ +#include "unity_test_module.h" + +/* As an alternative for header files we can declare that + * the following methos are available 'extern'ally. + */ +extern void run_skater_tests(); + +int main (int argc, char * argv[]) +{ + UnityTestModule allModules[] = { { "skater", run_skater_tests} + }; + + size_t number_of_modules = sizeof(allModules)/sizeof(allModules[0]); + + return UnityTestModuleRun(argc, argv, allModules, number_of_modules); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/test/skater_test.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/test/skater_test.c new file mode 100644 index 0000000..5d0844f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Skater/test/skater_test.c @@ -0,0 +1,41 @@ +#include +// add your include here +#include "unity.h" +#include "unity_test_module.h" +#include "skater.h" + + +// I rather dislike keeping line numbers updated, so I made my own +// macro to ditch the line number +#define MY_RUN_TEST(func) RUN_TEST(func, 0) + +void skater_setUp(void) +{ + // This is run before EACH test +} + +void skater_tearDown(void) +{ + // This is run after EACH test +} + + +// TODO: +// - Rename and change this test to something usefull +// - Add more tests +// - Remove this comment :) +// Should you need a list of all TEST_ASSERT macros: take a look +// at unity.h +void test_skater_EmptyTest(void) +{ + TEST_ASSERT_EQUAL(1, 0); +} + +void run_skater_tests() +{ + UnityRegisterSetupTearDown( skater_setUp, skater_tearDown); + + MY_RUN_TEST(test_skater_EmptyTest); + + UnityUnregisterSetupTearDown(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageCitroen2Cv.bmp b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageCitroen2Cv.bmp new file mode 100644 index 0000000..665213c Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageCitroen2Cv.bmp differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageRedFerrari.bmp b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageRedFerrari.bmp new file mode 100644 index 0000000..74e5ca1 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageRedFerrari.bmp differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageTrabant.bmp b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageTrabant.bmp new file mode 100644 index 0000000..ce64e85 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageTrabant.bmp differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageYellowFerrari.bmp b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageYellowFerrari.bmp new file mode 100644 index 0000000..8a03b7e Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ImageYellowFerrari.bmp differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Makefile b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Makefile new file mode 100644 index 0000000..e8e2ff7 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Makefile @@ -0,0 +1,51 @@ +ASSIGNMENT=stegano + +UNITY_FOLDER=./Unity +RESOURCE_CHECK_FOLDER=./ResourceDetector +INC_DIRS=-I$(RESOURCE_CHECK_FOLDER) +TEST_INC_DIRS=$(INC_DIRS) -I$(UNITY_FOLDER) + +SRC_FILES=$(ASSIGNMENT)_main.c \ + $(RESOURCE_CHECK_FOLDER)/resource_detector.c \ + $(RESOURCE_CHECK_FOLDER)/list.c \ + $(ASSIGNMENT).c + +TEST_FILES=$(UNITY_FOLDER)/unity.c \ + $(ASSIGNMENT)_test.c \ + $(RESOURCE_CHECK_FOLDER)/resource_detector.c \ + $(RESOURCE_CHECK_FOLDER)/list.c \ + $(ASSIGNMENT).c + +HEADER_FILES=*.h + +TEST = $(ASSIGNMENT)_test + +CC=gcc + +SYMBOLS=-g -O0 -std=c99 -Wall -Werror -Wextra -pedantic -Wno-unused-parameter +TEST_SYMBOLS=$(SYMBOLS) -DTEST + +.PHONY: clean test + +all: $(ASSIGNMENT) $(TEST) + +$(ASSIGNMENT): $(SRC_FILES) $(HEADER_FILES) Makefile + $(CC) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(ASSIGNMENT) + +$(TEST): Makefile $(TEST_FILES) $(HEADER_FILES) + $(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(TEST) + +clean: + rm -f $(ASSIGNMENT) $(TEST) + +test: $(TEST) + @./$(TEST) + +klocwork: + kwcheck run + +klocwork_after_makefile_change: clean + kwinject make + kwcheck create -b kwinject.out + kwcheck import /opt/klocwork/Fontys_default.pconf + kwcheck run diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/list.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/list.c new file mode 100644 index 0000000..fc396be --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/list.c @@ -0,0 +1,278 @@ +/* ********************************************** + * generic linked list in plain c + * author: Freddy Hurkmans + * date: dec 20, 2014 + * **********************************************/ + +/* ****************************************************************************** + * This list is designed using object oriented ideas, but is implemented in c. + * + * The idea is: you construct a list for a certain data structure (say: mystruct): + * list_admin* mylist = construct_list(sizeof(mystruct)) + * mylist contains private data for this list implementation. You need not worry + * about it, only give it as first parameter to each list method. + * + * This means you can have multiple lists at the same time, just make sure you + * give the right list_admin structure to the list function. + * When you're done with your list, just call the destructor: destruct_list(&mylist) + * The destructor automatically deletes remaining list elements and the list administration. + * + * As this list implementation keeps its own administration in list_admin, you need + * not worry about next pointers and such. Your structure doesn't even need pointers + * to itself, you only need to worry about data. A valid struct could thus be: + * typedef struct + * { + * int nr; + * char text[100]; + * } mystruct; + * + * Adding data to the list is done using list_add_* methods, such as list_add_tail, + * which adds data to the end of the list: + * mystruct data = {10, "hello world!"}; + * int result = list_add_tail(mylist, &data); + * You don't have to provide the size of your struct, you've already done that in + * the destructor. If result < 0 list_add_* has failed (either a parameter problem + * or malloc didn't give memory). + * + * You can get a pointer to your data using list_get_*, e.g. get the 2nd element: + * mystruct* dataptr = list_get_element(admin, 1); + * or get the last element: + * mystruct* dataptr = list_get_last(admin); + * If dataptr is not NULL it points to the correct data, else the operation failed. + * + * Searching for data in your list can be done with list_index_of*. list_index_of + * compares the data in each list item to the given data. If they are the same, it + * returns the index. If you want to search for an element with a certain value for + * nr or text (see mystruct) you can implement your own compare function and use + * list_index_of_special (check memcmp for required return values): + * int mycompare(void* p1, void* p2, size_t size) + * { + * // this example doesn't need size! + * mystruct* org = (mystruct*)p1; + * int* nr = (int*)p2; + * return org->nr - nr; // return 0 if they are the same + * } + * Say you want to search for an element that has nr 10: + * int nr = 10; + * int index = list_index_of_special(mylist, &nr, mycompare); + * As noted earlier: mycompare must have the same prototype as memcmp. In fact: + * list_index_of is a shortcut for list_index_of_special(mylist, data, memcmp). + * + * Finally you can delete items with list_delete_*. They should work rather + * straight forward. If they succeed they return 0. You don't have to delete + * all items before destructing your list. + * + * ******************************************************************************/ + + +#include /* for memcmp and memcpy */ + +#include "list.h" + +static size_t data_size(const list_admin* admin); +static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index); +static list_head* get_list_head_of_element_n(list_admin* admin, size_t index); +static void remove_first_element(list_admin* admin); +static int remove_non_first_element(list_admin* admin, size_t index); + +/* ********************************************** + * Constructor / destructor + * **********************************************/ +list_admin* construct_list(size_t element_size) +{ + list_admin* admin = malloc(sizeof(*admin)); + if (admin != NULL) + { + admin->head = NULL; + admin->element_size = element_size; + admin->nr_elements = 0; + } + return admin; +} + +void destruct_list(list_admin** admin) +{ + if ((admin != NULL) && (*admin != NULL)) + { + while ((*admin)->head != NULL) + { + list_head* temp = (*admin)->head; + (*admin)->head = (*admin)->head->next; + free(temp); + temp = NULL; + } + free(*admin); + *admin = NULL; + } +} + +/* ********************************************** + * Public functions + * **********************************************/ +int list_get_nr_elements(list_admin* admin) +{ + int nr_elements = -1; + if (admin != NULL) + { + nr_elements = admin->nr_elements; + } + return nr_elements; +} + +int list_add_tail(list_admin* admin, const void* data) +{ + int result = -1; + if ((admin != NULL) && (data != NULL)) + { + list_head* new = malloc(data_size(admin)); + if (new != NULL) + { + result = 0; + new->next = NULL; + memcpy(new+1, data, admin->element_size); + + if (admin->head == NULL) + { + admin->head = new; + } + else + { + list_head* temp = get_guaranteed_list_head_of_element_n(admin, admin->nr_elements-1); + temp->next = new; + } + + admin->nr_elements++; + } + } + return result; +} + + +void* list_get_element(list_admin* admin, size_t index) +{ + list_head* item = get_list_head_of_element_n(admin, index); + if(item != NULL) + { + item++; // user data is just beyond list_head, thus we must increase the pointer + } + return item; +} + +void* list_get_last(list_admin* admin) +{ + list_head* item = NULL; + if (admin != NULL) + { + item = list_get_element(admin, admin->nr_elements-1); + } + return item; +} + +int list_index_of(list_admin* admin, const void* data) +{ + return list_index_of_special(admin, data, memcmp); +} + +int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr compare) +{ + int index = -1; + if ((admin != NULL) && (data != NULL) && (compare != NULL)) + { + list_head* temp = admin->head; + index = 0; + while ((temp != NULL) && (compare(temp+1, data, admin->element_size) != 0)) + { + temp = temp->next; + index++; + } + if (temp == NULL) + { + index = -1; + } + } + return index; +} + +int list_delete_item(list_admin* admin, size_t index) +{ + int result = -1; + if ((admin != NULL) && (admin->head != NULL) && (index < admin->nr_elements)) + { + if (index == 0) + { + result = 0; + remove_first_element(admin); + } + else + { + result = remove_non_first_element(admin, index); + } + } + return result; +} + +int list_delete_last(list_admin* admin) +{ + int result = -1; + if (admin != NULL) + { + result = list_delete_item(admin, admin->nr_elements - 1); + } + return result; +} + +/* ********************************************** + * Private functions + * **********************************************/ +static size_t data_size(const list_admin* admin) +{ + return admin->element_size + sizeof(list_head); +} + +static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index) +{ + list_head* item = admin->head; + for (size_t i = 0; (i < index) && (item != NULL); i++) + { + item = item->next; + } + return item; +} + +static list_head* get_list_head_of_element_n(list_admin* admin, size_t index) +{ + list_head* item = NULL; + if ((admin != NULL) && (index < admin->nr_elements)) + { + item = get_guaranteed_list_head_of_element_n(admin, index); + } + return item; +} + +static void remove_first_element(list_admin* admin) +{ + list_head* temp = admin->head; + admin->head = admin->head->next; + free(temp); + temp = NULL; + admin->nr_elements--; +} + +static int remove_non_first_element(list_admin* admin, size_t index) +{ + int result = -1; + if (index > 0) + { + list_head* temp = get_list_head_of_element_n(admin, index-1); + if ((temp != NULL) && (temp->next != NULL)) // to remove element n, element n-1 and n must exist + { + result = 0; + list_head* to_delete = temp->next; + temp->next = to_delete->next; + free(to_delete); + to_delete = NULL; + admin->nr_elements--; + } + } + return result; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/list.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/list.h new file mode 100644 index 0000000..c70c552 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/list.h @@ -0,0 +1,52 @@ +#pragma once + +#include + +typedef struct list_head +{ + struct list_head* next; +} list_head; + +typedef struct +{ + struct list_head* head; + size_t element_size; + size_t nr_elements; +} list_admin; + +typedef int (*CompareFuncPtr)(const void*, const void*, size_t); + +// call the constructor before using the list: +// list_admin* mylist = construct_list(sizeof(mystruct)); +// if mylist equals NULL, no memory could be allocated. Please don't +// mess with the admin data, this can corrupt your data. +list_admin* construct_list(size_t element_size); + +// call the destructor when you're done, pass the list administration +// as referenced parameter (the variable will be set to NULL). +void destruct_list(list_admin** admin); + +// Reads the number of elements in your list. Returns -1 in case of +// errors, else the number of elements. +int list_get_nr_elements(list_admin* admin); + +// Add data to the end of the list. Returns -1 in case of errors, else 0 +int list_add_tail(list_admin* admin, const void* data); + +// Returns a pointer to the requested element. Returns NULL in case of +// errors (such as: the element does not exist). +void* list_get_element(list_admin* admin, size_t index); +void* list_get_last(list_admin* admin); + +// Returns the index to the first found list element that's equal to data, +// or -1 in case of errors (such as: not found). +int list_index_of(list_admin* admin, const void* data); + +// Returns the index to the first found list element for which cmp says it's, +// equal to data, or -1 in case of errors (such as: not found). cmp must behave +// just like memcmp, i.e.: return 0 when the data matches. +int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr cmp); + +// Delete an item in the list. Returns -1 in case of errors, else 0. +int list_delete_item(list_admin* admin, size_t index); +int list_delete_last(list_admin* admin); diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/resource_detector.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/resource_detector.c new file mode 100644 index 0000000..30a4360 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/resource_detector.c @@ -0,0 +1,270 @@ +#include +#include +#include +#include +//#include +#include + +#include "resource_detector.h" + +#undef malloc +#undef free +#undef main +#undef fopen +#undef fclose + +#include "list.h" + +#define MAGIC_CODE 0x78563412 + +#define ADDR(addr,offset) ((addr) + (offset)) +#define SET_MAGIC_CODE(addr,offset) *((int*) ADDR(addr,offset)) = MAGIC_CODE +#define MAGIC_CODE_OK(addr,offset) (*((int*) ADDR(addr,offset)) == MAGIC_CODE) + +typedef struct +{ + char* addr; + unsigned int size; + const char* file; + unsigned int line; +} mem_data; + +typedef struct +{ + FILE* addr; + const char* file_to_open; + const char* mode; + const char* file; + unsigned int line; +} file_data; + +static list_admin* memlist = NULL; +static list_admin* filelist = NULL; + +static int memory_compare(const void* meminfo, const void* address, size_t size) +{ + mem_data* info = (mem_data*)meminfo; + char* addr = (char*)address; + return info->addr - addr; +} + +static int file_compare(const void* fileinfo, const void* address, size_t size) +{ + file_data* info = (file_data*)fileinfo; + FILE* addr = (FILE*)address; + return info->addr - addr; +} + + +static void +invalidate (mem_data* info) +{ + char* user_addr; + char* raw_addr; + unsigned int size; + + user_addr = info->addr; + size = info->size; + raw_addr = ADDR (user_addr, -sizeof(int)); + + if (!MAGIC_CODE_OK(user_addr, -sizeof(int)) || !MAGIC_CODE_OK(user_addr, size)) + { + fprintf (stderr, "ERROR: addr %p (%s, line %d): out-of-bound access\n", (void*)user_addr, info->file, info->line); + } + + memset (raw_addr, 0xff, size + (2 * sizeof(int))); + free (raw_addr); +} + +/* + * replacement of malloc + */ +extern void* +xmalloc (unsigned int size, const char* file, unsigned int line) +{ + char* raw_addr = malloc (size + (2 * sizeof(int))); + char* user_addr; + mem_data info = {NULL, 0, NULL, 0}; + + if (raw_addr == NULL) + { + fprintf (stderr, "ERROR: malloc failed for %d bytes (%s, line %d)\n", size, file, line); + return (NULL); + } + else + { + user_addr = ADDR (raw_addr, sizeof (int)); + SET_MAGIC_CODE (raw_addr, 0); + SET_MAGIC_CODE (user_addr, size); + + info.addr = user_addr; + info.size = size; + info.file = file; + info.line = line; + list_add_tail(memlist, &info); + } + return ((void*) user_addr); +} + +/* + * replacement of free + */ +extern void +xfree (void* addr, const char* filename, int linenr) +{ + char* user_addr = (char*) addr; + mem_data* info = NULL; + + /* check if allocated memory is in our list and retrieve its info */ + int index = list_index_of_special(memlist, addr, memory_compare); + info = list_get_element(memlist, index); + + if (info == NULL) + { + fprintf (stderr, "ERROR: trying to free memory that was not malloc-ed (addr %p) in %s : %d\n", (void*)user_addr, filename, linenr); + return; + } + + invalidate (info); + list_delete_item(memlist, index); +} + +static void +print_empty_lines(int n) +{ + int i; + for (i = 0; i < n; i++) + { + fprintf(stderr, "\n"); + } +} + +static void set_colour_red(void) +{ + fprintf(stderr, "\033[10;31m"); +} +static void set_colour_gray(void) +{ + fprintf(stderr, "\033[22;37m"); +} +static void +print_line(void) +{ + fprintf (stderr, "---------------------------------------------------------\n"); +} + +static void +print_not_good(void) +{ + set_colour_gray(); + print_line(); + set_colour_red(); + fprintf (stderr, " # # ###\n"); + fprintf (stderr, " ## # #### ##### #### #### #### ##### ###\n"); + fprintf (stderr, " # # # # # # # # # # # # # # ###\n"); + fprintf (stderr, " # # # # # # # # # # # # # # \n"); + fprintf (stderr, " # # # # # # # ### # # # # # # \n"); + fprintf (stderr, " # ## # # # # # # # # # # # ###\n"); + fprintf (stderr, " # # #### # #### #### #### ##### ###\n"); + set_colour_gray(); + print_line(); +} + +/* + * writes all info of the unallocated memory + */ +static void +resource_detection (void) +{ + time_t now = time (NULL); + + int forgotten_frees = list_get_nr_elements(memlist); + int nr_files_open = list_get_nr_elements(filelist); + + if ((forgotten_frees > 0) || (nr_files_open > 0)) + { + print_empty_lines(15); + } + + if (forgotten_frees > 0) + { + mem_data* info = NULL; + print_line(); + fprintf (stderr, "Memory Leak Summary, generated: %s", ctime (&now)); + print_not_good(); + set_colour_red(); + while((info = list_get_element(memlist, 0)) != NULL) + { + fprintf (stderr, "forgot to free address: %p (%d bytes) that was allocated in: %s on line: %d\n", + (void*)info->addr, info->size, info->file, info->line); + list_delete_item(memlist, 0); + } + set_colour_gray(); + print_line(); + print_empty_lines(1); + } + + if (nr_files_open > 0) + { + file_data* info = NULL; + print_line(); + fprintf (stderr, "File Management Summary, generated: %s", ctime (&now)); + print_not_good(); + set_colour_red(); + while((info = list_get_element(filelist, 0)) != NULL) + { + fprintf (stderr, "forgot to close file: %s (ptr %p, mode \"%s\") that was opened from: %s on line: %d\n", + info->file_to_open, (void*)(info->addr), info->mode, info->file, info->line); + list_delete_item(filelist, 0); + } + set_colour_gray(); + print_line(); + print_empty_lines(1); + } + if ((forgotten_frees == 0) && (nr_files_open == 0)) + { + printf ("\nResource checks: OK\n\n"); + } + + destruct_list(&memlist); + destruct_list(&filelist); +} + +extern FILE* +xfopen (const char* file_to_open, const char* mode, const char* filename, int linenr) +{ + file_data info = {0}; + info.addr = fopen(file_to_open, mode); + if (info.addr != NULL) + { + info.file_to_open = file_to_open; + info.mode = mode; + info.file = filename; + info.line = linenr; + list_add_tail(filelist, &info); + } + return info.addr; +} + +extern int +xfclose(FILE* fptr, const char* filename, int linenr) +{ + int index = list_index_of_special(filelist, fptr, file_compare); + if (index < 0) + { + fprintf (stderr, "ERROR: trying to close an unopened file in %s on line number %d.\n", filename, linenr); + return -1; + } + list_delete_item(filelist, index); + return (fclose (fptr)); +} + +extern int +main (int argc, char* argv[]) +{ + atexit (resource_detection); + memlist = construct_list(sizeof(mem_data)); + filelist = construct_list(sizeof(file_data)); + + return (xmain (argc, argv)); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/resource_detector.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/resource_detector.h new file mode 100644 index 0000000..0a1811b --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/resource_detector.h @@ -0,0 +1,18 @@ +#ifndef RESOURCE_DETECTOR_H +#define RESOURCE_DETECTOR_H + +#include + +#define main xmain +#define malloc(size) xmalloc ((size), (__FILE__), (__LINE__)) +#define free(addr) xfree ((addr), __FILE__, __LINE__) +#define fopen(name,mode) xfopen ((name),(mode), __FILE__, __LINE__) +#define fclose(fptr) xfclose ((fptr), __FILE__, __LINE__) + +extern int xmain(int argc, char* argv[]); +extern void* xmalloc(unsigned int size, const char* file, unsigned int line); +extern void xfree(void* addr, const char* filename, int linenr); +extern FILE* xfopen(const char* file_to_open, const char* mode, const char* filename, int linenr); +extern int xfclose(FILE* fptr, const char* filename, int linenr); + +#endif diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/test/Makefile b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/test/Makefile new file mode 100644 index 0000000..7915049 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/test/Makefile @@ -0,0 +1,28 @@ +UNITY_FOLDER=../Unity +TEST_INC_DIRS=$(INC_DIRS) -I$(UNITY_FOLDER) + +TEST_FILES=$(UNITY_FOLDER)/unity.c \ + list_test.c \ + list.c + +HEADER_FILES=*.h + +TEST = list_test + +CC=gcc + +SYMBOLS=-Wall -Werror -pedantic -O0 -ggdb -std=c99 +TEST_SYMBOLS=$(SYMBOLS) -DTEST + +.PHONY: clean test + +all: $(TEST) + +$(TEST): Makefile $(TEST_FILES) $(HEADER_FILES) + $(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(TEST) + +clean: + rm -f list $(TEST) + +test: $(TEST) + @valgrind ./$(TEST) diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/test/list_test.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/test/list_test.c new file mode 100644 index 0000000..704c7a7 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/ResourceDetector/test/list_test.c @@ -0,0 +1,300 @@ +#include /* for memcmp */ + +#include "list.h" +#include "unity.h" + +// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number +#define MY_RUN_TEST(func) RUN_TEST(func, 0) + +static list_admin* mylist = NULL; +typedef struct +{ + int i; + int j; +} test_struct; + +// compare function that returns 0 if test_struct.i matches, it ignores .j +static int compare_test_func(const void* p1, const void* p2, size_t size) +{ + size = size; // to prevent warnings + const test_struct* data1 = (const test_struct*)p1; + const test_struct* data2 = (const test_struct*)p2; + return data1->i - data2->i; +} +// check n items in list against verify_data +// IMPORTANT: this function must check using list_get_element, +// else the test for that function is no longer useful +static void check_n_list_elements_ok(list_admin* admin, int nr_items, const test_struct* verify_data) +{ + for(int i = 0; i < nr_items; i++) + { + test_struct* ptr = list_get_element(admin, i); + TEST_ASSERT_NOT_NULL(ptr); + TEST_ASSERT_EQUAL(0, memcmp(verify_data+i, ptr, sizeof(*ptr))); + } +} + + +void setUp(void) +{ + // This is run before EACH test + mylist = construct_list(sizeof(test_struct)); + TEST_ASSERT_NOT_NULL(mylist); +} + +void tearDown(void) +{ + // This is run after EACH test + destruct_list(&mylist); + TEST_ASSERT_NULL(mylist); +} + +static void test_ConstructList(void) +{ + TEST_ASSERT_NULL(mylist->head); + TEST_ASSERT_EQUAL(sizeof(test_struct), mylist->element_size); + TEST_ASSERT_EQUAL(0, mylist->nr_elements); +} + +static void test_NrElements_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_get_nr_elements(NULL)); +} + +static void test_AddData_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_add_tail(mylist, NULL)); + TEST_ASSERT_EQUAL(-1, list_add_tail(NULL, mylist)); +} + +static void test_AddData(void) +{ + test_struct data = {3, 4}; + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data)); + + TEST_ASSERT_NOT_NULL(mylist->head); + TEST_ASSERT_EQUAL(1, list_get_nr_elements(mylist)); + list_head* head = mylist->head; + test_struct* element = (test_struct*)(head+1); + TEST_ASSERT_EQUAL(data.i, element->i); + TEST_ASSERT_EQUAL(data.j, element->j); +} + +static void test_Add2PiecesOfData(void) +{ + test_struct data1 = {8, 9}; + test_struct data2 = {-3, -4}; + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data1)); + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data2)); + + TEST_ASSERT_NOT_NULL(mylist->head); + TEST_ASSERT_NOT_NULL(mylist->head->next); + TEST_ASSERT_EQUAL(2, list_get_nr_elements(mylist)); + list_head* head = mylist->head->next; + test_struct* element = (test_struct*)(head+1); + TEST_ASSERT_EQUAL(data2.i, element->i); + TEST_ASSERT_EQUAL(data2.j, element->j); +} + +static void test_GetElement_parameters(void) +{ + TEST_ASSERT_NULL(list_get_element(NULL, 0)); +} + +static void test_GetElement(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}}; + const int nr_elements = sizeof(data)/sizeof(data[0]); + + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + check_n_list_elements_ok(mylist, nr_elements, data); // checks using list_get_element + + TEST_ASSERT_NULL(list_get_element(mylist, nr_elements)); + TEST_ASSERT_NULL(list_get_element(mylist, -1)); +} + +static void test_GetLast_parameters(void) +{ + TEST_ASSERT_NULL(list_get_last(NULL)); +} + +static void test_GetLast(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}}; + const int nr_elements = sizeof(data)/sizeof(data[0]); + + TEST_ASSERT_NULL(list_get_last(mylist)); + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + test_struct* ptr = list_get_last(mylist); + TEST_ASSERT_NOT_NULL(ptr); + TEST_ASSERT_EQUAL(0, memcmp(&(data[i]), ptr, sizeof(*ptr))); + } +} + +static void test_IndexOf_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_index_of(mylist, NULL)); + TEST_ASSERT_EQUAL(-1, list_index_of(NULL, mylist)); +} + +static void test_IndexOf(void) +{ + const test_struct real_data[] = {{8, 9}, {-3, -4}, {21, 56}}; + const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]); + const test_struct false_data[] = {{-3, 9}, {8, 56}, {21, -4}, {0, 0}}; + const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]); + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(real_data[i]))); + } + + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(i, list_index_of(mylist, &(real_data[i]))); + } + for(int i = 0; i < nr_false_elements; i++) + { + TEST_ASSERT_EQUAL(-1, list_index_of(mylist, &(false_data[i]))); + } +} + +static void test_IndexOfSpecial_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, NULL, compare_test_func)); + TEST_ASSERT_EQUAL(-1, list_index_of_special(NULL, mylist, compare_test_func)); + TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, mylist, NULL)); +} + +static void test_IndexOfSpecial(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}}; // data in list + const test_struct real_data[] = {{8, -4}, {-3, 56}, {21, 9}}; // data to search for (i equals) + const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]); + const test_struct false_data[] = {{-2, 9}, {9, -4}, {22, 56}, {0, 0}}; // data that doesn't exist + const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]); + + // first make sure our compare function works + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(0, compare_test_func(&(data[i]), &(real_data[i]), 0)); + for (int j = 0; j < nr_false_elements; j++) + { + TEST_ASSERT_NOT_EQUAL(0, compare_test_func(&(data[i]), &(false_data[j]), 0)) + } + } + + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(i, list_index_of_special(mylist, &(real_data[i]), compare_test_func)); + } + for(int i = 0; i < nr_false_elements; i++) + { + TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, &(false_data[i]), compare_test_func)); + } +} + +static void test_DeleteItem_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_delete_item(NULL, 0)); + TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, -1)); +} + +static void test_DeleteItem(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; + int nr_elements = sizeof(data)/sizeof(data[0]); + const test_struct data_noFirst[] = {{-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; + const test_struct data_noLast[] = {{-3, -4}, {21, 56}, {0, 0}}; + const test_struct data_noMiddle[] = {{-3, -4}, {0, 0}}; + + TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, 0)); + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 0)); + nr_elements--; + TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); + + check_n_list_elements_ok(mylist, nr_elements, data_noFirst); + + TEST_ASSERT_EQUAL(0, list_delete_item(mylist, nr_elements-1)); + nr_elements--; + TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); + + check_n_list_elements_ok(mylist, nr_elements, data_noLast); + + TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 1)); + nr_elements--; + TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); + + check_n_list_elements_ok(mylist, nr_elements, data_noMiddle); +} + +static void test_DeleteLast_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_delete_last(NULL)); +} + +static void test_DeleteLast(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; + int nr_elements = sizeof(data)/sizeof(data[0]); + + TEST_ASSERT_EQUAL(-1, list_delete_last(mylist)); + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + for (int i = nr_elements-1; i >= 0; i--) + { + TEST_ASSERT_EQUAL(0, list_delete_last(mylist)); + TEST_ASSERT_EQUAL(i, list_get_nr_elements(mylist)); + check_n_list_elements_ok(mylist, i, data); + } + + TEST_ASSERT_NULL(mylist->head); + TEST_ASSERT_EQUAL(0, list_get_nr_elements(mylist)); +} + +int main(void) +{ + UnityBegin(); + + MY_RUN_TEST(test_ConstructList); + MY_RUN_TEST(test_NrElements_parameters); + MY_RUN_TEST(test_AddData_parameters); + MY_RUN_TEST(test_AddData); + MY_RUN_TEST(test_Add2PiecesOfData); + MY_RUN_TEST(test_GetElement_parameters); + MY_RUN_TEST(test_GetElement); + MY_RUN_TEST(test_GetLast_parameters); + MY_RUN_TEST(test_GetLast); + MY_RUN_TEST(test_IndexOf_parameters); + MY_RUN_TEST(test_IndexOf); + MY_RUN_TEST(test_IndexOfSpecial_parameters); + MY_RUN_TEST(test_IndexOfSpecial); + MY_RUN_TEST(test_DeleteItem_parameters); + MY_RUN_TEST(test_DeleteItem); + MY_RUN_TEST(test_DeleteLast_parameters); + MY_RUN_TEST(test_DeleteLast); + // MY_RUN_TEST(); + // MY_RUN_TEST(); + // MY_RUN_TEST(); + // MY_RUN_TEST(); + + return UnityEnd(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/SteganoAssignment.doc b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/SteganoAssignment.doc new file mode 100644 index 0000000..d8afd36 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/SteganoAssignment.doc differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/TextFontys.txt b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/TextFontys.txt new file mode 100644 index 0000000..2128f30 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/TextFontys.txt @@ -0,0 +1,102 @@ +*** Eindhoven *** + +De Technische Universiteit Eindhoven en Fontys Hogescholen trekken veel +studenten naar Eindhoven. In de digitale stad Eindhoven en +Eindhoven.beginthier.nl vind je een bundeling van informatie over Eindhoven. +Je mag Eindhoven een echte studentenstad noemen. Studentvoorzieningen zijn +er op allerlei gebied. Hieronder vind je een aantal mogelijkheden: + + +Introfestival +============= +Om je kennis te laten maken met het studentenleven in Eindhoven +worden al jaren de HBO Introductiedagen (HID) georganiseerd: een +bruisend festival met veel muziek. Tijdens deze drie dwaze dagen leer +je de studentenverenigingen kennen, je gaat langs bij veel kroegen in +de stad en je ontmoet een heleboel medestudenten. Je ontvangt automatisch +bericht over de HID als je je hebt aangemeld voor een opleiding. + + +FEID (Fontys Eindhoven Introductie Dag) is de algemene introductiedag +van Fontys in Eindhoven waar alle studenten die gaan studeren aan een +van de opleidingen die Fontys aanbiedt, aan mee doen. + + +Gezelligheid +------------ +Een geslaagd studentenleven kan je in Eindhoven op verschillende manier +bereiken. Op de donderdagavonden in de stad, bijvoorbeeld op uitgaansgebied +Stratumseind, bij de cultuur- en sportverenigingen, enz. De drie Eindhovense +studenten-gezelligheidsverenigingen vervullen een sleutelrol in dit geheel. +Ze hebben alledrie een eigen identiteit en unieke sfeer: het Eindhovense +Studentencorps, SSRE en Demos. + + +Sport ++++++ + +Als Fontysstudent kun je gebruik maken van alle accommodaties van het +TU-Sportcentrum op het terrein van de Technische Universiteit Eindhoven. +Als je bent ingeschreven voor een Fontysopleiding ontvang je daarover +automatisch informatie. + +De Eindhovense Studenten Sport Federatie (de ESSF) is een overkoepelend +orgaan en belangenbehartiger van alle studenten sportverenigingen en +alle sportkaarthouders in Eindhoven. Heb je vragen over de sportkaart +en/of het sporten, kijk dan op de website van de ESSF. + + +Wat houdt Technische Informatica in? +==================================== + +Binnen het vakgebied Technische Informatica ben je samen met anderen bezig +om computerprogrammatuur te maken in een technische omgeving. Je doorloopt +in een aantal projecten en modulen het totale ontwikkeltraject van +softwaresystemen: van het inventariseren van wensen van toekomstige gebruikers, +via het beschrijven en realiseren van een ontwerp tot het testen en implementeren +in een werkomgeving. De opleiding besteedt uitgebreid aandacht aan embedded +systemen: software die in apparaten wordt ingebouwd. Denk maar eens aan al +die programmatuur in kopieerapparaten, liften, wasmachines en mobiele +telefoons. + + +Een ander aandachtsgebied is industriële automatisering. Bij industriële +automatisering kun je denken aan robots. Andere voorbeelden zijn: +verkeerssystemen op snelwegen en in tunnels, parkeergarages met automatische +betalingen, massafabricage in de auto- en elektronica-industrie, procesbesturing +via internet,en productinspectie met camera's en beeldbewerking. Omdat je als +ict’ers, dus ook als technisch informaticus, met en voor mensen werkt, is er +ook aandacht voor communicatieve en sociale vaardigheden. + + +Learning Community +================== + +Fontys wil een open organisatie zijn, waarin geleerd wordt in wisselwerking +met de omgeving. Leren gebeurt vooral met anderen en in steeds wisselende +groepen en situaties. Met haar studenten wil Fontys een hechte en langdurige +relatie aangaan. Ontwikkeling, competenties, vaardigheden en eigen keuzes +staan daarbij voorop. + +Elke student formuleert eigen leervragen, beïnvloedt de eigen leerroute en +reflecteert kritisch op het eigen leerproces. Binnen de instituten worden +studenten praktijkgericht opgeleid tot professional. + + +Organisatie +=========== + +Fontys telt zo'n 33.000 studenten en 3.500 personeelsleden. + +De opleidingen en diensten van Fontys Hogescholen worden verzorgd door 35 +hogescholen (met eigen directies). De leiding van Fontys Hogescholen berust +bij de Raad van Bestuur, die ondersteund wordt door een Bestuursstaf. Zowel +de Raad van Bestuur als de hogescholen maken voor diverse diensten gebruik +van het Facilitair Bedrijf, dat afdelingen herbergt als ICT-Services, +Studentenvoorzieningen, Administratieve en Huishoudelijke functies. + + + +Bron: http://www.fontys.nl + +-- einde -- diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity.c new file mode 100644 index 0000000..7b10aa6 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity.c @@ -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 +#include + +#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; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity.h new file mode 100644 index 0000000..8b16111 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity.h @@ -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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity_internals.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity_internals.h new file mode 100644 index 0000000..b0d0637 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity_internals.h @@ -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 +#include + +//------------------------------------------------------- +// 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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity_test_module.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity_test_module.c new file mode 100644 index 0000000..ba18f7f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity_test_module.c @@ -0,0 +1,97 @@ +#include "unity_test_module.h" +#include +#include +#include +#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(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity_test_module.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity_test_module.h new file mode 100644 index 0000000..c16ec8d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/Unity/unity_test_module.h @@ -0,0 +1,31 @@ +#ifndef UNITY_TEST_MODULE_H +#define UNITY_TEST_MODULE_H + +#include + +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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/bmp.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/bmp.h new file mode 100644 index 0000000..f7625b2 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/bmp.h @@ -0,0 +1,43 @@ +/* + * bmp.h + * + * Created on: Feb 23, 2012 + * Author: student + */ + +#ifndef BMP_H_ +#define BMP_H_ + +#include + +// datatypes obtained from http://en.wikipedia.org/wiki/BMP_file_format + +typedef struct +{ + uint8_t magic[2]; +} __attribute__ (( packed )) BMP_MAGIC_t; + +typedef struct +{ + uint32_t filesz; + uint16_t creator1; + uint16_t creator2; + uint32_t bmp_offset; +} __attribute__ (( packed )) BMP_FILE_t; + +typedef struct +{ + uint32_t header_sz; + int32_t width; + int32_t height; + uint16_t nplanes; + uint16_t bitspp; + uint32_t compress_type; + uint32_t bmp_bytesz; + int32_t hres; + int32_t vres; + uint32_t ncolors; + uint32_t nimpcolors; +} __attribute__ (( packed )) BMP_INFO_t; + +#endif /* BMP_H_ */ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/challengelevel.json b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/challengelevel.json new file mode 100644 index 0000000..b169579 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/challengelevel.json @@ -0,0 +1,6 @@ +{ + "challenge":{ + "level":["shows"] , + "durationHours": 8 + } +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano.c new file mode 100644 index 0000000..d89e120 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano.c @@ -0,0 +1,168 @@ +/* + * stegano.c + * + * Created on: Nov 6, 2011 + * Author: J. Geurts + */ + +#include +#include +#include +#include + +#include "bmp.h" +#include "resource_detector.h" +#include "stegano.h" + +#define MAX_FILENAME 80 + +extern uint8_t SteganoGetSubstring( + uint8_t Src, uint8_t SrcPos, uint8_t NrOfBits, uint8_t DestPos) +/* description: get a substring of bits from a uint8_t (i.e. a byte) + * + * example: SteganoGetSubstring (Src, 3, 4, 1) with Src=ABCDEFGH (bit H is LSB) + * = 000BCDE0 + * + * parameters: + * Src: byte to get the substring from + * SrcPos: position of the first bit of the substring (LSB=0) + * NrOfBits: length of the substring + * DestPos: position of the first bits of the destination substring + * + * return: + * substring, starting at DestPos + */ +{ + // to be implemented + return 0; +} + + +// should be static in real life, but would give a compiling error in the +// unchanged code because this function is not yet used +static void ReadHdr( + FILE* FilePtr, BMP_MAGIC_t* Magic, BMP_FILE_t* File, + BMP_INFO_t* Info) +/* + * description: read the header of a bmp File, and store the data in the + * provided parameters + * + * parameters: + * FilePtr: file, opened for reading + * Magic: output-parameter to store the read BMP_MAGIC_t structure + * File: output-parameter to store the read BMP_FILE_t structure + * Info: output-parameter to store the read BMP_INFO_t structure + * + * Note: caller should provide enough memory for parameters 'Magic', 'File' and + * 'Info' + */ +{ + // to be implemented +} + + +// should be static in real life, but would give a compiling error in the +// unchanged code because this function is not yet used +static void WriteHdr( + FILE* FilePtr, BMP_MAGIC_t* Magic, BMP_FILE_t* File, + BMP_INFO_t* Info) +/* + * description: write the header of a bmp File, where the data comes from the + * provided parameters + * + * parameters: + * FilePtr: file, opened for writing + * Magic: input-parameter with a BMP_MAGIC_t structure + * File: input-parameter with a BMP_FILE_t structure + * Info: input-parameter with a BMP_INFO_t structure + * + */ +{ + // to be implemented +} + + +extern void SteganoMultiplex(const char* File0, const char* File1) +{ + FILE* FilePtr0 = NULL; + FILE* FilePtr1 = NULL; + FILE* FilePtr2 = NULL; + char buf[MAX_FILENAME]; + + for (int NrBits = 0; NrBits <= 8; NrBits++) + { + // NrBits: number of bits for the hidden image + sprintf(buf, "mux_%s_%s_%d.bmp", File0, File1, NrBits); + FilePtr0 = fopen(File0, "rb"); + FilePtr1 = fopen(File1, "rb"); + FilePtr2 = fopen(buf, "wb"); + + // to be implemented + + + fclose(FilePtr0); + fclose(FilePtr1); + fclose(FilePtr2); + } +} + + +extern void SteganoMultiplexText(const char* File0, const char* File1) +{ + FILE* FilePtr0 = NULL; + FILE* FilePtr1 = NULL; + FILE* FilePtr2 = NULL; + char buf[MAX_FILENAME]; + + sprintf(buf, "mux_%s_%s.bmp", File0, File1); + FilePtr0 = fopen(File0, "rb"); + FilePtr1 = fopen(File1, "rb"); + FilePtr2 = fopen(buf, "wb"); + + // to be implemented + + + fclose(FilePtr0); + fclose(FilePtr1); + fclose(FilePtr2); +} + + +extern void +SteganoDemultiplex(const char* File0, const char* File1, const char* File2) +{ + FILE* FilePtr0 = NULL; + FILE* FilePtr1 = NULL; + FILE* FilePtr2 = NULL; + + FilePtr0 = fopen(File0, "rb"); + FilePtr1 = fopen(File1, "wb"); + FilePtr2 = fopen(File2, "wb"); + + // to be implemented + + + fclose(FilePtr0); + fclose(FilePtr1); + fclose(FilePtr2); +} + + +extern void +SteganoDemultiplexText(const char* File0, const char* File1, const char* File2) +{ + FILE* FilePtr0 = NULL; + FILE* FilePtr1 = NULL; + FILE* FilePtr2 = NULL; + + FilePtr0 = fopen(File0, "rb"); /* binair lezen */ + FilePtr1 = fopen(File1, "wb"); /* binair schrijven */ + FilePtr2 = fopen(File2, "wb"); /* binair schrijven */ + + // to be implemented + + + fclose(FilePtr0); + fclose(FilePtr1); + fclose(FilePtr2); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano.h b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano.h new file mode 100644 index 0000000..d1bccd5 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano.h @@ -0,0 +1,23 @@ +/* + * stegano.h + * + * Created on: Nov 6, 2011 + * Author: J. Geurts + */ + +#ifndef STEGANO_H_ +#define STEGANO_H_ + +#include + +extern uint8_t SteganoGetSubstring( + uint8_t src, uint8_t src_pos, uint8_t nrof_bits, uint8_t dest_pos); + +extern void SteganoMultiplex(const char* File0, const char* File1); +extern void SteganoMultiplexText(const char* File0, const char* File1); +extern void SteganoDemultiplex( + const char* File0, const char* File1, const char* File2); +extern void SteganoDemultiplexText( + const char* File0, const char* File1, const char* File2); + +#endif diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano_main.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano_main.c new file mode 100644 index 0000000..16c18fe --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano_main.c @@ -0,0 +1,128 @@ +/* + * main.c + * + * Created on: Nov 6, 2011 + * Author: student + */ + +#include +#include +#include +#include + +#include "bmp.h" +#include "resource_detector.h" +#include "stegano.h" + +#define MAX_STRLEN 80 + +static bool WithMenu = true; + +static int GetInt(const char* Message) +{ + char Line[MAX_STRLEN]; + char* Result = NULL; + int Value = -1; + + if (WithMenu) + { + printf("%s", Message); + } + Result = fgets(Line, sizeof(Line), stdin); + if (Result != NULL) + { + sscanf(Result, "%d", &Value); + } + + return Value; +} + +static void GetStr(const char* Message, char* Str) +{ + char Line[MAX_STRLEN]; + char* Result = NULL; + + if (WithMenu) + { + printf("%s", Message); + } + Result = fgets(Line, sizeof(Line), stdin); + if (Result != NULL) + { + sscanf(Result, "%s", Str); + } +} + + +extern int main(int argc, char* argv[]) +{ + char File0[MAX_STRLEN]; + char File1[MAX_STRLEN]; + char File2[MAX_STRLEN]; + int Choice; + bool Quit = false; + + printf("PRC assignment 'SteganoC' (version 2)\n" + "-------------------------------------\n"); + + if (argc != 1) + { + fprintf(stderr, "%s: argc=%d\n", argv[0], argc); + } + + while (!Quit) + { + if (WithMenu) + { + printf("\n\nMENU\n" + "===================\n" + "[1] multiplex\n" + "[2] multiplex text\n" + "[3] demultiplex\n" + "[4] demultiplex text\n" + "[8] show/hide menu\n" + "[9] Quit\n"); + } + Choice = GetInt("Choice: "); + + switch (Choice) + { + case 1: + GetStr("enter input file (visible): ", File0); + GetStr("enter input file (hidden): ", File1); + SteganoMultiplex(File0, File1); + break; + case 2: + GetStr("enter input file (visible): ", File0); + GetStr("enter input file (text): ", File1); + SteganoMultiplexText(File0, File1); + break; + case 3: + GetStr("enter input file: ", File0); + GetStr("enter output file (visible): ", File1); + GetStr("enter output file (hidden): ", File2); + SteganoDemultiplex(File0, File1, File2); + break; + case 4: + GetStr("enter input file: ", File0); + GetStr("enter output file (visible): ", File1); + GetStr("enter output file (text): ", File2); + SteganoDemultiplexText(File0, File1, File2); + break; + case 8: + if (WithMenu) + { + printf("printing of MENU is disabled\n"); + } + WithMenu = !WithMenu; + break; + case 9: + Quit = true; + break; + default: + printf("ERROR: invalid Choice: %d\n", Choice); + break; + } + } + return (0); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano_test.c b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano_test.c new file mode 100644 index 0000000..15c4fa4 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/ExtraAssignments/Stegano/stegano_test.c @@ -0,0 +1,435 @@ +/* auteur : F.J. Hurkmans + * datum : November 4th 2013 + * code : Ansi C + * versie : 1 + */ + +#include "bmp.h" +#include "stegano.h" +#include "unity.h" + +#include +#include +#include + +#include "resource_detector.h" + +// I rather dislike keeping line numbers updated, so I made my own macro to +// ditch the line number +#define MY_RUN_TEST(func) RUN_TEST(func, 0) + + +void setUp(void) +{ + // This is run before EACH test +} + +void tearDown(void) +{ + // This is run after EACH test + const char* FilenamesToDeleteAfterTest[] = { + "demux_ImageCitroen2Cv.bmp", + "demux_TextFontys.txt", + "demux_ImageRedFerrari_0.bmp", + "demux_ImageRedFerrari_1.bmp", + "demux_ImageRedFerrari_4.bmp", + "demux_ImageRedFerrari_7.bmp", + "demux_ImageRedFerrari_8.bmp", + "demux_ImageTrabant_0.bmp", + "demux_ImageTrabant_1.bmp", + "demux_ImageTrabant_4.bmp", + "demux_ImageTrabant_7.bmp", + "demux_ImageTrabant_8.bmp", + "mux_ImageCitroen2Cv.bmp_TextFontys.txt.bmp", + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp.bmp", + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_0.bmp", + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_1.bmp", + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_2.bmp", + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_3.bmp", + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_4.bmp", + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_5.bmp", + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_6.bmp", + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_7.bmp", + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_8.bmp" + }; + + for (size_t i = 0; i < (sizeof(FilenamesToDeleteAfterTest) / + sizeof(FilenamesToDeleteAfterTest[0])); + i++) + { + remove(FilenamesToDeleteAfterTest[i]); + } +} + +static int GetFileSize(FILE* FilePtr) +{ + int CurrPos = ftell(FilePtr); + int EndPos = 0; + TEST_ASSERT_EQUAL(0, fseek(FilePtr, 0L, SEEK_END)); + EndPos = ftell(FilePtr); + TEST_ASSERT_EQUAL(0, fseek(FilePtr, CurrPos, SEEK_SET)); + return EndPos; +} + +static void Assert2FilesEqual(char* File1, char* File2) +{ + const size_t BufferSize = 4096; + FILE* File1Ptr = fopen(File1, "rb"); + TEST_ASSERT_NOT_NULL(File1Ptr); + FILE* File2Ptr = fopen(File2, "rb"); + TEST_ASSERT_NOT_NULL(File2Ptr); + + int File1Size = GetFileSize(File1Ptr); + int File2Size = GetFileSize(File2Ptr); + + TEST_ASSERT_EQUAL(File1Size, File2Size); + + char* File1Buffer = malloc(BufferSize); + TEST_ASSERT_NOT_NULL(File1Buffer); + char* File2Buffer = malloc(BufferSize); + TEST_ASSERT_NOT_NULL(File2Buffer); + + size_t File1Read = 0; + size_t File2Read = 0; + + do + { + File1Read = fread(File1Buffer, 1, BufferSize, File1Ptr); + File2Read = fread(File2Buffer, 1, BufferSize, File2Ptr); + TEST_ASSERT_EQUAL(File1Read, File2Read); + if (File1Read > 0) + { + TEST_ASSERT_EQUAL_INT8_ARRAY(File1Buffer, File2Buffer, File1Read); + } + } while ((File1Read > 0) && (File2Read > 0)); + + free(File1Buffer); + free(File2Buffer); + + fclose(File1Ptr); + fclose(File2Ptr); +} + +static void +CheckBmp(char* Filename, const uint32_t* CorrectHeader, + const uint8_t* FirstPixels, const uint8_t* LastPixels) +{ + const int NrHeaderInts = 13; + const int NrPixels = 8; + const int BytesPerPixel = 3; + char message[300]; + sprintf(message, "CheckBmp on filename: %s", Filename); + FILE* FilePtr = NULL; + uint32_t Header[NrHeaderInts]; + uint8_t PixelData[NrPixels * BytesPerPixel]; + int Result = 0; + + FilePtr = fopen(Filename, "rb"); + TEST_ASSERT_NOT_NULL(FilePtr); + + + fseek(FilePtr, 0x02, SEEK_SET);// skip 'BM' magic + TEST_ASSERT_EQUAL_MESSAGE( + NrHeaderInts, + fread(&Header, sizeof(Header[0]), NrHeaderInts, FilePtr), + message); + TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE( + CorrectHeader, Header, NrHeaderInts, message); + + fseek(FilePtr, + sizeof(BMP_MAGIC_t) + sizeof(BMP_FILE_t) + sizeof(BMP_INFO_t), + SEEK_SET); + Result = fread(PixelData, sizeof(PixelData[0]), NrPixels * BytesPerPixel, + FilePtr); + TEST_ASSERT_EQUAL_MESSAGE(NrPixels * BytesPerPixel, Result, message); + TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE( + FirstPixels, PixelData, NrPixels * BytesPerPixel, message); + + fseek(FilePtr, -1 * NrPixels * BytesPerPixel, SEEK_END); + Result = fread(PixelData, sizeof(PixelData[0]), NrPixels * BytesPerPixel, + FilePtr); + TEST_ASSERT_EQUAL_MESSAGE(NrPixels * BytesPerPixel, Result, message); + TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE( + LastPixels, PixelData, NrPixels * BytesPerPixel, message); + + fclose(FilePtr); +} + + +static void test_GetSubstring(void) +{ + const uint8_t TestData[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, + 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08, + 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, + 0x40, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08, + 0x10, 0x20, 0x40, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x03, 0x06, + 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x02, + 0x04, 0x08, 0x10, 0x20, 0x40, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x02, + 0x04, 0x08, 0x10, 0x20, 0x40, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x06, + 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x04, 0x08, 0x10, 0x20, 0x40, 0x0a, 0x14, + 0x28, 0x50, 0xa0, 0x05, 0x0a, 0x14, 0x28, 0x50, 0x0a, 0x14, 0x28, 0x50, + 0xa0, 0x0d, 0x1a, 0x34, 0x68, 0xd0, 0x14, 0x28, 0x50, 0xa0, 0x0a, 0x14, + 0x28, 0x50, 0x15, 0x2a, 0x54, 0xa8, 0x1a, 0x34, 0x68, 0xd0, 0x14, 0x28, + 0x50, 0x2a, 0x54, 0xa8, 0x35, 0x6a, 0xd4, 0x54, 0xa8, 0x6a, 0xd4 + }; + uint8_t Src = 0xd4; + uint8_t SrcPos; + uint8_t NrBits; + uint8_t DestPos; + int TestDataIndex = 0; + + for (int j = 1; j < 8; j++) + { + for (int i = 0; i < 8; i++) + { + for (int k = 0; k < 8; k++) + { + if ((i + j <= 8) && (k + j <= 8)) + { + SrcPos = i; + NrBits = j; + DestPos = k; + char message[80]; + sprintf(message, "SrcPos: %i, NrBits: %i, DestPos: %i", + SrcPos, NrBits, DestPos); + TEST_ASSERT_EQUAL_HEX8_MESSAGE( + TestData[TestDataIndex++], + SteganoGetSubstring( + Src, SrcPos, NrBits, DestPos), + message); + } + } + } + } +} + +static void test_MultiplexTwoImages(void) +{ + const char* File1 = "ImageTrabant.bmp"; + const char* File2 = "ImageRedFerrari.bmp"; + SteganoMultiplex(File1, File2); + + uint32_t CorrectHeader0[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280, + 0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4, + 0xec4, 0x0, 0x0 }; + uint8_t CorrectFirstBytes0[] = { 0x58, 0x5d, 0x5e, 0x4e, 0x53, 0x54, + 0x4e, 0x53, 0x54, 0x58, 0x5d, 0x5e, + 0x57, 0x5c, 0x5d, 0x4d, 0x52, 0x53, + 0x4d, 0x52, 0x55, 0x57, 0x5c, 0x5f }; + uint8_t CorrectLastBytes0[] = { 0x11, 0x58, 0x48, 0x11, 0x5a, 0x4a, + 0x13, 0x5b, 0x4e, 0x1b, 0x63, 0x56, + 0x22, 0x67, 0x5c, 0x17, 0x5c, 0x51, + 0x11, 0x54, 0x4b, 0x19, 0x5c, 0x53 }; + CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_0.bmp", CorrectHeader0, + CorrectFirstBytes0, CorrectLastBytes0); + uint32_t CorrectHeader1[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280, + 0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4, + 0xec4, 0x0, 0x1 }; + uint8_t CorrectFirstBytes1[] = { 0x59, 0x5d, 0x5f, 0x4f, 0x53, 0x55, + 0x4f, 0x53, 0x55, 0x59, 0x5d, 0x5f, + 0x57, 0x5d, 0x5d, 0x4d, 0x53, 0x53, + 0x4d, 0x53, 0x55, 0x57, 0x5d, 0x5f }; + uint8_t CorrectLastBytes1[] = { 0x10, 0x58, 0x48, 0x10, 0x5a, 0x4a, + 0x12, 0x5a, 0x4e, 0x1a, 0x62, 0x56, + 0x22, 0x66, 0x5c, 0x16, 0x5c, 0x50, + 0x10, 0x54, 0x4a, 0x18, 0x5c, 0x52 }; + CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_1.bmp", CorrectHeader1, + CorrectFirstBytes1, CorrectLastBytes1); + uint32_t CorrectHeader4[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280, + 0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4, + 0xec4, 0x0, 0x4 }; + uint8_t CorrectFirstBytes4[] = { 0x5d, 0x5d, 0x5d, 0x4d, 0x5d, 0x5d, + 0x4d, 0x5d, 0x5d, 0x5d, 0x5d, 0x5d, + 0x5d, 0x5d, 0x5d, 0x4d, 0x5d, 0x5d, + 0x4d, 0x5d, 0x5d, 0x5d, 0x5d, 0x5d }; + uint8_t CorrectLastBytes4[] = { 0x10, 0x50, 0x40, 0x10, 0x50, 0x40, + 0x10, 0x50, 0x40, 0x10, 0x60, 0x50, + 0x20, 0x60, 0x50, 0x10, 0x50, 0x50, + 0x10, 0x50, 0x40, 0x10, 0x50, 0x50 }; + CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_4.bmp", CorrectHeader4, + CorrectFirstBytes4, CorrectLastBytes4); + uint32_t CorrectHeader7[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280, + 0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4, + 0xec4, 0x0, 0x7 }; + uint8_t CorrectFirstBytes7[] = { 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, + 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, + 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, + 0x69, 0x69, 0x69, 0x69, 0x69, 0x69 }; + uint8_t CorrectLastBytes7[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_7.bmp", CorrectHeader7, + CorrectFirstBytes7, CorrectLastBytes7); + uint32_t CorrectHeader8[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280, + 0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4, + 0xec4, 0x0, 0x8 }; + uint8_t CorrectFirstBytes8[] = { 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, + 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, + 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, + 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3 }; + uint8_t CorrectLastBytes8[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_8.bmp", CorrectHeader8, + CorrectFirstBytes8, CorrectLastBytes8); +} + +static void test_DemultiplexTwoImages(void) +{ + const char* File1 = "ImageTrabant.bmp"; + const char* File2 = "ImageRedFerrari.bmp"; + SteganoMultiplex(File1, File2); + + SteganoDemultiplex( + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_0.bmp", + "demux_ImageTrabant_0.bmp", "demux_ImageRedFerrari_0.bmp"); + SteganoDemultiplex( + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_1.bmp", + "demux_ImageTrabant_1.bmp", "demux_ImageRedFerrari_1.bmp"); + SteganoDemultiplex( + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_4.bmp", + "demux_ImageTrabant_4.bmp", "demux_ImageRedFerrari_4.bmp"); + SteganoDemultiplex( + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_7.bmp", + "demux_ImageTrabant_7.bmp", "demux_ImageRedFerrari_7.bmp"); + SteganoDemultiplex( + "mux_ImageTrabant.bmp_ImageRedFerrari.bmp_8.bmp", + "demux_ImageTrabant_8.bmp", "demux_ImageRedFerrari_8.bmp"); + uint32_t CorrectHeader0[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280, + 0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4, + 0xec4, 0x0, 0x0 }; + uint8_t CorrectFirstBytes0[] = { 0x50, 0x50, 0x50, 0x40, 0x50, 0x50, + 0x40, 0x50, 0x50, 0x50, 0x50, 0x50, + 0x50, 0x50, 0x50, 0x40, 0x50, 0x50, + 0x40, 0x50, 0x50, 0x50, 0x50, 0x50 }; + uint8_t CorrectLastBytes0[] = { 0x10, 0x50, 0x40, 0x10, 0x50, 0x40, + 0x10, 0x50, 0x40, 0x10, 0x60, 0x50, + 0x20, 0x60, 0x50, 0x10, 0x50, 0x50, + 0x10, 0x50, 0x40, 0x10, 0x50, 0x50 }; + CheckBmp("demux_ImageTrabant_4.bmp", CorrectHeader0, CorrectFirstBytes0, + CorrectLastBytes0); + uint32_t CorrectHeader1[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280, + 0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4, + 0xec4, 0x0, 0x0 }; + uint8_t CorrectFirstBytes1[] = { 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, + 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, + 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, + 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2 }; + uint8_t CorrectLastBytes1[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + CheckBmp("demux_ImageRedFerrari_7.bmp", CorrectHeader1, CorrectFirstBytes1, + CorrectLastBytes1); + uint32_t CorrectHeader2[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280, + 0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4, + 0xec4, 0x0, 0x0 }; + uint8_t CorrectFirstBytes2[] = { 0x58, 0x5c, 0x5e, 0x4e, 0x52, 0x54, + 0x4e, 0x52, 0x54, 0x58, 0x5c, 0x5e, + 0x56, 0x5c, 0x5c, 0x4c, 0x52, 0x52, + 0x4c, 0x52, 0x54, 0x56, 0x5c, 0x5e }; + uint8_t CorrectLastBytes2[] = { 0x10, 0x58, 0x48, 0x10, 0x5a, 0x4a, + 0x12, 0x5a, 0x4e, 0x1a, 0x62, 0x56, + 0x22, 0x66, 0x5c, 0x16, 0x5c, 0x50, + 0x10, 0x54, 0x4a, 0x18, 0x5c, 0x52 }; + CheckBmp("demux_ImageTrabant_1.bmp", CorrectHeader2, CorrectFirstBytes2, + CorrectLastBytes2); + uint32_t CorrectHeader3[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280, + 0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4, + 0xec4, 0x0, 0x0 }; + uint8_t CorrectFirstBytes3[] = { 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, + 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, + 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, + 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0 }; + uint8_t CorrectLastBytes3[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + CheckBmp("demux_ImageRedFerrari_4.bmp", CorrectHeader3, CorrectFirstBytes3, + CorrectLastBytes3); + + Assert2FilesEqual("ImageTrabant.bmp", "demux_ImageTrabant_0.bmp"); + Assert2FilesEqual("ImageRedFerrari.bmp", "demux_ImageRedFerrari_8.bmp"); +} + +static void test_MultiplexTextAndImage(void) +{ + const char* File1 = "ImageCitroen2Cv.bmp"; + const char* File2 = "TextFontys.txt"; + SteganoMultiplexText(File1, File2); + + uint32_t CorrectHeader0[] = { 0x56616, 0x115d, 0x36, 0x28, 0x1b8, + 0x10c, 0x180001, 0x0, 0x565e0, 0x0, + 0x0, 0x0, 0x0 }; + uint8_t CorrectFirstBytes0[] = { 0x74, 0x86, 0x8b, 0x98, 0xab, 0xae, + 0x61, 0x74, 0x76, 0x7c, 0x91, 0x8e, + 0x91, 0xa4, 0xa3, 0x88, 0x9e, 0x9a, + 0x93, 0xa8, 0xa3, 0x8c, 0xa3, 0x9c }; + uint8_t CorrectLastBytes0[] = { 0x3e, 0x5d, 0x36, 0x4a, 0x69, 0x42, + 0x39, 0x58, 0x33, 0x37, 0x56, 0x31, + 0x32, 0x50, 0x2d, 0x32, 0x50, 0x2d, + 0x30, 0x4e, 0x2b, 0x36, 0x54, 0x31 }; + CheckBmp("mux_ImageCitroen2Cv.bmp_TextFontys.txt.bmp", CorrectHeader0, + CorrectFirstBytes0, CorrectLastBytes0); +} + +static void test_DemultiplexTextAndImage(void) +{ + const char* File1 = "ImageCitroen2Cv.bmp"; + const char* File2 = "TextFontys.txt"; + SteganoMultiplexText(File1, File2); + + SteganoDemultiplexText( + "mux_ImageCitroen2Cv.bmp_TextFontys.txt.bmp", + "demux_ImageCitroen2Cv.bmp", "demux_TextFontys.txt"); + uint32_t CorrectHeader0[] = { 0x56616, 0x0, 0x36, 0x28, 0x1b8, + 0x10c, 0x180001, 0x0, 0x565e0, 0x0, + 0x0, 0x0, 0x0 }; + uint8_t CorrectFirstBytes0[] = { 0x74, 0x86, 0x8a, 0x98, 0xaa, 0xae, + 0x60, 0x74, 0x76, 0x7c, 0x90, 0x8e, + 0x90, 0xa4, 0xa2, 0x88, 0x9e, 0x9a, + 0x92, 0xa8, 0xa2, 0x8c, 0xa2, 0x9c }; + uint8_t CorrectLastBytes0[] = { 0x3e, 0x5d, 0x36, 0x4a, 0x69, 0x42, + 0x39, 0x58, 0x33, 0x37, 0x56, 0x31, + 0x32, 0x50, 0x2d, 0x32, 0x50, 0x2d, + 0x30, 0x4e, 0x2b, 0x36, 0x54, 0x31 }; + CheckBmp("demux_ImageCitroen2Cv.bmp", CorrectHeader0, CorrectFirstBytes0, + CorrectLastBytes0); + uint32_t CorrectHeader1[] = { 0x6945202a, 0x6f68646e, 0x206e6576, + 0x0d2a2a2a, 0x440a0d0a, 0x65542065, + 0x696e6863, 0x65686373, 0x696e5520, + 0x73726576, 0x69657469, 0x69452074, + 0x6f68646e }; + uint8_t CorrectFirstBytes1[] = { 0x76, 0x65, 0x6e, 0x20, 0x65, 0x6e, + 0x20, 0x46, 0x6f, 0x6e, 0x74, 0x79, + 0x73, 0x20, 0x48, 0x6f, 0x67, 0x65, + 0x73, 0x63, 0x68, 0x6f, 0x6c, 0x65 }; + uint8_t CorrectLastBytes1[] = { 0x6e, 0x74, 0x79, 0x73, 0x2e, 0x6e, + 0x6c, 0x0d, 0x0a, 0x0d, 0x0a, 0x2d, + 0x2d, 0x20, 0x65, 0x69, 0x6e, 0x64, + 0x65, 0x20, 0x2d, 0x2d, 0x0d, 0x0a }; + CheckBmp("demux_TextFontys.txt", CorrectHeader1, CorrectFirstBytes1, + CorrectLastBytes1); + + Assert2FilesEqual("TextFontys.txt", "demux_TextFontys.txt"); +} + +int main(int argc, char* argv[]) +{ + UnityBegin(); + + MY_RUN_TEST(test_GetSubstring); + MY_RUN_TEST(test_MultiplexTwoImages); + MY_RUN_TEST(test_DemultiplexTwoImages); + MY_RUN_TEST(test_MultiplexTextAndImage); + MY_RUN_TEST(test_DemultiplexTextAndImage); + + return UnityEnd(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/.gitignore b/C/t-oer-prc2-cbdb-main/Assignments/Watch/.gitignore new file mode 100644 index 0000000..f1896c6 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/.gitignore @@ -0,0 +1,3 @@ +watch +watch_test + diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/Makefile b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Makefile new file mode 100644 index 0000000..193abb2 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Makefile @@ -0,0 +1,42 @@ +PROD_DIR := ./product +SHARED_DIR := ./shared +TEST_DIR := ./test +UNITY_FOLDER :=./Unity +RES_DIR := ./ResourceDetector +BUILD_DIR :=./build + +PROD_EXEC = main +PROD_DIRS := $(PROD_DIR) $(SHARED_DIR) $(RES_DIR) +PROD_FILES := $(wildcard $(patsubst %,%/*.c, $(PROD_DIRS))) +HEADER_PROD_FILES := $(wildcard $(patsubst %,%/*.h, $(PROD_DIRS))) +PROD_INC_DIRS=-I$(PROD_DIR) -I$(SHARED_DIR) -I$(RES_DIR) + +TEST_EXEC = main_test +TEST_DIRS := $(TEST_DIR) $(SHARED_DIR) $(RES_DIR) $(UNITY_FOLDER) +TEST_FILES := $(wildcard $(patsubst %,%/*.c, $(TEST_DIRS))) +HEADER_TEST_FILES := $(wildcard $(patsubst %,%/*.h, $(TEST_DIRS))) +TEST_INC_DIRS=-I$(TEST_DIR) -I$(SHARED_DIR) -I$(UNITY_FOLDER) -I$(RES_DIR) + +CC=gcc +SYMBOLS=-Wall -Werror -g -O0 -std=c99 +TEST_SYMBOLS=$(SYMBOLS) -DTEST -DUNITY_USE_MODULE_SETUP_TEARDOWN + +.PHONY: clean test + +all: $(PROD_EXEC) + +$(PROD_EXEC): Makefile $(PROD_FILES) $(HEADER_FILES) + $(CC) $(PROD_INC_DIRS) $(SYMBOLS) $(PROD_FILES) -o $(BUILD_DIR)/$(PROD_EXEC) + +$(TEST_EXEC): Makefile $(TEST_FILES) $(HEADER_FILES) + $(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(BUILD_DIR)/$(TEST_EXEC) + +run: $(PROD_EXEC) + @./$(BUILD_DIR)/$(PROD_EXEC) + +test: $(TEST_EXEC) + @./$(BUILD_DIR)/$(TEST_EXEC) + +clean: + rm -f $(BUILD_DIR)/$(PROD_EXEC) + rm -f $(BUILD_DIR)/$(TEST_EXEC) diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/list.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/list.c new file mode 100644 index 0000000..fc396be --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/list.c @@ -0,0 +1,278 @@ +/* ********************************************** + * generic linked list in plain c + * author: Freddy Hurkmans + * date: dec 20, 2014 + * **********************************************/ + +/* ****************************************************************************** + * This list is designed using object oriented ideas, but is implemented in c. + * + * The idea is: you construct a list for a certain data structure (say: mystruct): + * list_admin* mylist = construct_list(sizeof(mystruct)) + * mylist contains private data for this list implementation. You need not worry + * about it, only give it as first parameter to each list method. + * + * This means you can have multiple lists at the same time, just make sure you + * give the right list_admin structure to the list function. + * When you're done with your list, just call the destructor: destruct_list(&mylist) + * The destructor automatically deletes remaining list elements and the list administration. + * + * As this list implementation keeps its own administration in list_admin, you need + * not worry about next pointers and such. Your structure doesn't even need pointers + * to itself, you only need to worry about data. A valid struct could thus be: + * typedef struct + * { + * int nr; + * char text[100]; + * } mystruct; + * + * Adding data to the list is done using list_add_* methods, such as list_add_tail, + * which adds data to the end of the list: + * mystruct data = {10, "hello world!"}; + * int result = list_add_tail(mylist, &data); + * You don't have to provide the size of your struct, you've already done that in + * the destructor. If result < 0 list_add_* has failed (either a parameter problem + * or malloc didn't give memory). + * + * You can get a pointer to your data using list_get_*, e.g. get the 2nd element: + * mystruct* dataptr = list_get_element(admin, 1); + * or get the last element: + * mystruct* dataptr = list_get_last(admin); + * If dataptr is not NULL it points to the correct data, else the operation failed. + * + * Searching for data in your list can be done with list_index_of*. list_index_of + * compares the data in each list item to the given data. If they are the same, it + * returns the index. If you want to search for an element with a certain value for + * nr or text (see mystruct) you can implement your own compare function and use + * list_index_of_special (check memcmp for required return values): + * int mycompare(void* p1, void* p2, size_t size) + * { + * // this example doesn't need size! + * mystruct* org = (mystruct*)p1; + * int* nr = (int*)p2; + * return org->nr - nr; // return 0 if they are the same + * } + * Say you want to search for an element that has nr 10: + * int nr = 10; + * int index = list_index_of_special(mylist, &nr, mycompare); + * As noted earlier: mycompare must have the same prototype as memcmp. In fact: + * list_index_of is a shortcut for list_index_of_special(mylist, data, memcmp). + * + * Finally you can delete items with list_delete_*. They should work rather + * straight forward. If they succeed they return 0. You don't have to delete + * all items before destructing your list. + * + * ******************************************************************************/ + + +#include /* for memcmp and memcpy */ + +#include "list.h" + +static size_t data_size(const list_admin* admin); +static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index); +static list_head* get_list_head_of_element_n(list_admin* admin, size_t index); +static void remove_first_element(list_admin* admin); +static int remove_non_first_element(list_admin* admin, size_t index); + +/* ********************************************** + * Constructor / destructor + * **********************************************/ +list_admin* construct_list(size_t element_size) +{ + list_admin* admin = malloc(sizeof(*admin)); + if (admin != NULL) + { + admin->head = NULL; + admin->element_size = element_size; + admin->nr_elements = 0; + } + return admin; +} + +void destruct_list(list_admin** admin) +{ + if ((admin != NULL) && (*admin != NULL)) + { + while ((*admin)->head != NULL) + { + list_head* temp = (*admin)->head; + (*admin)->head = (*admin)->head->next; + free(temp); + temp = NULL; + } + free(*admin); + *admin = NULL; + } +} + +/* ********************************************** + * Public functions + * **********************************************/ +int list_get_nr_elements(list_admin* admin) +{ + int nr_elements = -1; + if (admin != NULL) + { + nr_elements = admin->nr_elements; + } + return nr_elements; +} + +int list_add_tail(list_admin* admin, const void* data) +{ + int result = -1; + if ((admin != NULL) && (data != NULL)) + { + list_head* new = malloc(data_size(admin)); + if (new != NULL) + { + result = 0; + new->next = NULL; + memcpy(new+1, data, admin->element_size); + + if (admin->head == NULL) + { + admin->head = new; + } + else + { + list_head* temp = get_guaranteed_list_head_of_element_n(admin, admin->nr_elements-1); + temp->next = new; + } + + admin->nr_elements++; + } + } + return result; +} + + +void* list_get_element(list_admin* admin, size_t index) +{ + list_head* item = get_list_head_of_element_n(admin, index); + if(item != NULL) + { + item++; // user data is just beyond list_head, thus we must increase the pointer + } + return item; +} + +void* list_get_last(list_admin* admin) +{ + list_head* item = NULL; + if (admin != NULL) + { + item = list_get_element(admin, admin->nr_elements-1); + } + return item; +} + +int list_index_of(list_admin* admin, const void* data) +{ + return list_index_of_special(admin, data, memcmp); +} + +int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr compare) +{ + int index = -1; + if ((admin != NULL) && (data != NULL) && (compare != NULL)) + { + list_head* temp = admin->head; + index = 0; + while ((temp != NULL) && (compare(temp+1, data, admin->element_size) != 0)) + { + temp = temp->next; + index++; + } + if (temp == NULL) + { + index = -1; + } + } + return index; +} + +int list_delete_item(list_admin* admin, size_t index) +{ + int result = -1; + if ((admin != NULL) && (admin->head != NULL) && (index < admin->nr_elements)) + { + if (index == 0) + { + result = 0; + remove_first_element(admin); + } + else + { + result = remove_non_first_element(admin, index); + } + } + return result; +} + +int list_delete_last(list_admin* admin) +{ + int result = -1; + if (admin != NULL) + { + result = list_delete_item(admin, admin->nr_elements - 1); + } + return result; +} + +/* ********************************************** + * Private functions + * **********************************************/ +static size_t data_size(const list_admin* admin) +{ + return admin->element_size + sizeof(list_head); +} + +static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index) +{ + list_head* item = admin->head; + for (size_t i = 0; (i < index) && (item != NULL); i++) + { + item = item->next; + } + return item; +} + +static list_head* get_list_head_of_element_n(list_admin* admin, size_t index) +{ + list_head* item = NULL; + if ((admin != NULL) && (index < admin->nr_elements)) + { + item = get_guaranteed_list_head_of_element_n(admin, index); + } + return item; +} + +static void remove_first_element(list_admin* admin) +{ + list_head* temp = admin->head; + admin->head = admin->head->next; + free(temp); + temp = NULL; + admin->nr_elements--; +} + +static int remove_non_first_element(list_admin* admin, size_t index) +{ + int result = -1; + if (index > 0) + { + list_head* temp = get_list_head_of_element_n(admin, index-1); + if ((temp != NULL) && (temp->next != NULL)) // to remove element n, element n-1 and n must exist + { + result = 0; + list_head* to_delete = temp->next; + temp->next = to_delete->next; + free(to_delete); + to_delete = NULL; + admin->nr_elements--; + } + } + return result; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/list.h b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/list.h new file mode 100644 index 0000000..c70c552 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/list.h @@ -0,0 +1,52 @@ +#pragma once + +#include + +typedef struct list_head +{ + struct list_head* next; +} list_head; + +typedef struct +{ + struct list_head* head; + size_t element_size; + size_t nr_elements; +} list_admin; + +typedef int (*CompareFuncPtr)(const void*, const void*, size_t); + +// call the constructor before using the list: +// list_admin* mylist = construct_list(sizeof(mystruct)); +// if mylist equals NULL, no memory could be allocated. Please don't +// mess with the admin data, this can corrupt your data. +list_admin* construct_list(size_t element_size); + +// call the destructor when you're done, pass the list administration +// as referenced parameter (the variable will be set to NULL). +void destruct_list(list_admin** admin); + +// Reads the number of elements in your list. Returns -1 in case of +// errors, else the number of elements. +int list_get_nr_elements(list_admin* admin); + +// Add data to the end of the list. Returns -1 in case of errors, else 0 +int list_add_tail(list_admin* admin, const void* data); + +// Returns a pointer to the requested element. Returns NULL in case of +// errors (such as: the element does not exist). +void* list_get_element(list_admin* admin, size_t index); +void* list_get_last(list_admin* admin); + +// Returns the index to the first found list element that's equal to data, +// or -1 in case of errors (such as: not found). +int list_index_of(list_admin* admin, const void* data); + +// Returns the index to the first found list element for which cmp says it's, +// equal to data, or -1 in case of errors (such as: not found). cmp must behave +// just like memcmp, i.e.: return 0 when the data matches. +int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr cmp); + +// Delete an item in the list. Returns -1 in case of errors, else 0. +int list_delete_item(list_admin* admin, size_t index); +int list_delete_last(list_admin* admin); diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/resource_detector.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/resource_detector.c new file mode 100644 index 0000000..30a4360 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/resource_detector.c @@ -0,0 +1,270 @@ +#include +#include +#include +#include +//#include +#include + +#include "resource_detector.h" + +#undef malloc +#undef free +#undef main +#undef fopen +#undef fclose + +#include "list.h" + +#define MAGIC_CODE 0x78563412 + +#define ADDR(addr,offset) ((addr) + (offset)) +#define SET_MAGIC_CODE(addr,offset) *((int*) ADDR(addr,offset)) = MAGIC_CODE +#define MAGIC_CODE_OK(addr,offset) (*((int*) ADDR(addr,offset)) == MAGIC_CODE) + +typedef struct +{ + char* addr; + unsigned int size; + const char* file; + unsigned int line; +} mem_data; + +typedef struct +{ + FILE* addr; + const char* file_to_open; + const char* mode; + const char* file; + unsigned int line; +} file_data; + +static list_admin* memlist = NULL; +static list_admin* filelist = NULL; + +static int memory_compare(const void* meminfo, const void* address, size_t size) +{ + mem_data* info = (mem_data*)meminfo; + char* addr = (char*)address; + return info->addr - addr; +} + +static int file_compare(const void* fileinfo, const void* address, size_t size) +{ + file_data* info = (file_data*)fileinfo; + FILE* addr = (FILE*)address; + return info->addr - addr; +} + + +static void +invalidate (mem_data* info) +{ + char* user_addr; + char* raw_addr; + unsigned int size; + + user_addr = info->addr; + size = info->size; + raw_addr = ADDR (user_addr, -sizeof(int)); + + if (!MAGIC_CODE_OK(user_addr, -sizeof(int)) || !MAGIC_CODE_OK(user_addr, size)) + { + fprintf (stderr, "ERROR: addr %p (%s, line %d): out-of-bound access\n", (void*)user_addr, info->file, info->line); + } + + memset (raw_addr, 0xff, size + (2 * sizeof(int))); + free (raw_addr); +} + +/* + * replacement of malloc + */ +extern void* +xmalloc (unsigned int size, const char* file, unsigned int line) +{ + char* raw_addr = malloc (size + (2 * sizeof(int))); + char* user_addr; + mem_data info = {NULL, 0, NULL, 0}; + + if (raw_addr == NULL) + { + fprintf (stderr, "ERROR: malloc failed for %d bytes (%s, line %d)\n", size, file, line); + return (NULL); + } + else + { + user_addr = ADDR (raw_addr, sizeof (int)); + SET_MAGIC_CODE (raw_addr, 0); + SET_MAGIC_CODE (user_addr, size); + + info.addr = user_addr; + info.size = size; + info.file = file; + info.line = line; + list_add_tail(memlist, &info); + } + return ((void*) user_addr); +} + +/* + * replacement of free + */ +extern void +xfree (void* addr, const char* filename, int linenr) +{ + char* user_addr = (char*) addr; + mem_data* info = NULL; + + /* check if allocated memory is in our list and retrieve its info */ + int index = list_index_of_special(memlist, addr, memory_compare); + info = list_get_element(memlist, index); + + if (info == NULL) + { + fprintf (stderr, "ERROR: trying to free memory that was not malloc-ed (addr %p) in %s : %d\n", (void*)user_addr, filename, linenr); + return; + } + + invalidate (info); + list_delete_item(memlist, index); +} + +static void +print_empty_lines(int n) +{ + int i; + for (i = 0; i < n; i++) + { + fprintf(stderr, "\n"); + } +} + +static void set_colour_red(void) +{ + fprintf(stderr, "\033[10;31m"); +} +static void set_colour_gray(void) +{ + fprintf(stderr, "\033[22;37m"); +} +static void +print_line(void) +{ + fprintf (stderr, "---------------------------------------------------------\n"); +} + +static void +print_not_good(void) +{ + set_colour_gray(); + print_line(); + set_colour_red(); + fprintf (stderr, " # # ###\n"); + fprintf (stderr, " ## # #### ##### #### #### #### ##### ###\n"); + fprintf (stderr, " # # # # # # # # # # # # # # ###\n"); + fprintf (stderr, " # # # # # # # # # # # # # # \n"); + fprintf (stderr, " # # # # # # # ### # # # # # # \n"); + fprintf (stderr, " # ## # # # # # # # # # # # ###\n"); + fprintf (stderr, " # # #### # #### #### #### ##### ###\n"); + set_colour_gray(); + print_line(); +} + +/* + * writes all info of the unallocated memory + */ +static void +resource_detection (void) +{ + time_t now = time (NULL); + + int forgotten_frees = list_get_nr_elements(memlist); + int nr_files_open = list_get_nr_elements(filelist); + + if ((forgotten_frees > 0) || (nr_files_open > 0)) + { + print_empty_lines(15); + } + + if (forgotten_frees > 0) + { + mem_data* info = NULL; + print_line(); + fprintf (stderr, "Memory Leak Summary, generated: %s", ctime (&now)); + print_not_good(); + set_colour_red(); + while((info = list_get_element(memlist, 0)) != NULL) + { + fprintf (stderr, "forgot to free address: %p (%d bytes) that was allocated in: %s on line: %d\n", + (void*)info->addr, info->size, info->file, info->line); + list_delete_item(memlist, 0); + } + set_colour_gray(); + print_line(); + print_empty_lines(1); + } + + if (nr_files_open > 0) + { + file_data* info = NULL; + print_line(); + fprintf (stderr, "File Management Summary, generated: %s", ctime (&now)); + print_not_good(); + set_colour_red(); + while((info = list_get_element(filelist, 0)) != NULL) + { + fprintf (stderr, "forgot to close file: %s (ptr %p, mode \"%s\") that was opened from: %s on line: %d\n", + info->file_to_open, (void*)(info->addr), info->mode, info->file, info->line); + list_delete_item(filelist, 0); + } + set_colour_gray(); + print_line(); + print_empty_lines(1); + } + if ((forgotten_frees == 0) && (nr_files_open == 0)) + { + printf ("\nResource checks: OK\n\n"); + } + + destruct_list(&memlist); + destruct_list(&filelist); +} + +extern FILE* +xfopen (const char* file_to_open, const char* mode, const char* filename, int linenr) +{ + file_data info = {0}; + info.addr = fopen(file_to_open, mode); + if (info.addr != NULL) + { + info.file_to_open = file_to_open; + info.mode = mode; + info.file = filename; + info.line = linenr; + list_add_tail(filelist, &info); + } + return info.addr; +} + +extern int +xfclose(FILE* fptr, const char* filename, int linenr) +{ + int index = list_index_of_special(filelist, fptr, file_compare); + if (index < 0) + { + fprintf (stderr, "ERROR: trying to close an unopened file in %s on line number %d.\n", filename, linenr); + return -1; + } + list_delete_item(filelist, index); + return (fclose (fptr)); +} + +extern int +main (int argc, char* argv[]) +{ + atexit (resource_detection); + memlist = construct_list(sizeof(mem_data)); + filelist = construct_list(sizeof(file_data)); + + return (xmain (argc, argv)); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/resource_detector.h b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/resource_detector.h new file mode 100644 index 0000000..0a1811b --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/resource_detector.h @@ -0,0 +1,18 @@ +#ifndef RESOURCE_DETECTOR_H +#define RESOURCE_DETECTOR_H + +#include + +#define main xmain +#define malloc(size) xmalloc ((size), (__FILE__), (__LINE__)) +#define free(addr) xfree ((addr), __FILE__, __LINE__) +#define fopen(name,mode) xfopen ((name),(mode), __FILE__, __LINE__) +#define fclose(fptr) xfclose ((fptr), __FILE__, __LINE__) + +extern int xmain(int argc, char* argv[]); +extern void* xmalloc(unsigned int size, const char* file, unsigned int line); +extern void xfree(void* addr, const char* filename, int linenr); +extern FILE* xfopen(const char* file_to_open, const char* mode, const char* filename, int linenr); +extern int xfclose(FILE* fptr, const char* filename, int linenr); + +#endif diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/test/Makefile b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/test/Makefile new file mode 100644 index 0000000..7915049 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/test/Makefile @@ -0,0 +1,28 @@ +UNITY_FOLDER=../Unity +TEST_INC_DIRS=$(INC_DIRS) -I$(UNITY_FOLDER) + +TEST_FILES=$(UNITY_FOLDER)/unity.c \ + list_test.c \ + list.c + +HEADER_FILES=*.h + +TEST = list_test + +CC=gcc + +SYMBOLS=-Wall -Werror -pedantic -O0 -ggdb -std=c99 +TEST_SYMBOLS=$(SYMBOLS) -DTEST + +.PHONY: clean test + +all: $(TEST) + +$(TEST): Makefile $(TEST_FILES) $(HEADER_FILES) + $(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(TEST) + +clean: + rm -f list $(TEST) + +test: $(TEST) + @valgrind ./$(TEST) diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/test/list_test.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/test/list_test.c new file mode 100644 index 0000000..704c7a7 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/ResourceDetector/test/list_test.c @@ -0,0 +1,300 @@ +#include /* for memcmp */ + +#include "list.h" +#include "unity.h" + +// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number +#define MY_RUN_TEST(func) RUN_TEST(func, 0) + +static list_admin* mylist = NULL; +typedef struct +{ + int i; + int j; +} test_struct; + +// compare function that returns 0 if test_struct.i matches, it ignores .j +static int compare_test_func(const void* p1, const void* p2, size_t size) +{ + size = size; // to prevent warnings + const test_struct* data1 = (const test_struct*)p1; + const test_struct* data2 = (const test_struct*)p2; + return data1->i - data2->i; +} +// check n items in list against verify_data +// IMPORTANT: this function must check using list_get_element, +// else the test for that function is no longer useful +static void check_n_list_elements_ok(list_admin* admin, int nr_items, const test_struct* verify_data) +{ + for(int i = 0; i < nr_items; i++) + { + test_struct* ptr = list_get_element(admin, i); + TEST_ASSERT_NOT_NULL(ptr); + TEST_ASSERT_EQUAL(0, memcmp(verify_data+i, ptr, sizeof(*ptr))); + } +} + + +void setUp(void) +{ + // This is run before EACH test + mylist = construct_list(sizeof(test_struct)); + TEST_ASSERT_NOT_NULL(mylist); +} + +void tearDown(void) +{ + // This is run after EACH test + destruct_list(&mylist); + TEST_ASSERT_NULL(mylist); +} + +static void test_ConstructList(void) +{ + TEST_ASSERT_NULL(mylist->head); + TEST_ASSERT_EQUAL(sizeof(test_struct), mylist->element_size); + TEST_ASSERT_EQUAL(0, mylist->nr_elements); +} + +static void test_NrElements_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_get_nr_elements(NULL)); +} + +static void test_AddData_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_add_tail(mylist, NULL)); + TEST_ASSERT_EQUAL(-1, list_add_tail(NULL, mylist)); +} + +static void test_AddData(void) +{ + test_struct data = {3, 4}; + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data)); + + TEST_ASSERT_NOT_NULL(mylist->head); + TEST_ASSERT_EQUAL(1, list_get_nr_elements(mylist)); + list_head* head = mylist->head; + test_struct* element = (test_struct*)(head+1); + TEST_ASSERT_EQUAL(data.i, element->i); + TEST_ASSERT_EQUAL(data.j, element->j); +} + +static void test_Add2PiecesOfData(void) +{ + test_struct data1 = {8, 9}; + test_struct data2 = {-3, -4}; + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data1)); + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data2)); + + TEST_ASSERT_NOT_NULL(mylist->head); + TEST_ASSERT_NOT_NULL(mylist->head->next); + TEST_ASSERT_EQUAL(2, list_get_nr_elements(mylist)); + list_head* head = mylist->head->next; + test_struct* element = (test_struct*)(head+1); + TEST_ASSERT_EQUAL(data2.i, element->i); + TEST_ASSERT_EQUAL(data2.j, element->j); +} + +static void test_GetElement_parameters(void) +{ + TEST_ASSERT_NULL(list_get_element(NULL, 0)); +} + +static void test_GetElement(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}}; + const int nr_elements = sizeof(data)/sizeof(data[0]); + + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + check_n_list_elements_ok(mylist, nr_elements, data); // checks using list_get_element + + TEST_ASSERT_NULL(list_get_element(mylist, nr_elements)); + TEST_ASSERT_NULL(list_get_element(mylist, -1)); +} + +static void test_GetLast_parameters(void) +{ + TEST_ASSERT_NULL(list_get_last(NULL)); +} + +static void test_GetLast(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}}; + const int nr_elements = sizeof(data)/sizeof(data[0]); + + TEST_ASSERT_NULL(list_get_last(mylist)); + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + test_struct* ptr = list_get_last(mylist); + TEST_ASSERT_NOT_NULL(ptr); + TEST_ASSERT_EQUAL(0, memcmp(&(data[i]), ptr, sizeof(*ptr))); + } +} + +static void test_IndexOf_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_index_of(mylist, NULL)); + TEST_ASSERT_EQUAL(-1, list_index_of(NULL, mylist)); +} + +static void test_IndexOf(void) +{ + const test_struct real_data[] = {{8, 9}, {-3, -4}, {21, 56}}; + const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]); + const test_struct false_data[] = {{-3, 9}, {8, 56}, {21, -4}, {0, 0}}; + const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]); + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(real_data[i]))); + } + + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(i, list_index_of(mylist, &(real_data[i]))); + } + for(int i = 0; i < nr_false_elements; i++) + { + TEST_ASSERT_EQUAL(-1, list_index_of(mylist, &(false_data[i]))); + } +} + +static void test_IndexOfSpecial_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, NULL, compare_test_func)); + TEST_ASSERT_EQUAL(-1, list_index_of_special(NULL, mylist, compare_test_func)); + TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, mylist, NULL)); +} + +static void test_IndexOfSpecial(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}}; // data in list + const test_struct real_data[] = {{8, -4}, {-3, 56}, {21, 9}}; // data to search for (i equals) + const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]); + const test_struct false_data[] = {{-2, 9}, {9, -4}, {22, 56}, {0, 0}}; // data that doesn't exist + const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]); + + // first make sure our compare function works + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(0, compare_test_func(&(data[i]), &(real_data[i]), 0)); + for (int j = 0; j < nr_false_elements; j++) + { + TEST_ASSERT_NOT_EQUAL(0, compare_test_func(&(data[i]), &(false_data[j]), 0)) + } + } + + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(i, list_index_of_special(mylist, &(real_data[i]), compare_test_func)); + } + for(int i = 0; i < nr_false_elements; i++) + { + TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, &(false_data[i]), compare_test_func)); + } +} + +static void test_DeleteItem_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_delete_item(NULL, 0)); + TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, -1)); +} + +static void test_DeleteItem(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; + int nr_elements = sizeof(data)/sizeof(data[0]); + const test_struct data_noFirst[] = {{-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; + const test_struct data_noLast[] = {{-3, -4}, {21, 56}, {0, 0}}; + const test_struct data_noMiddle[] = {{-3, -4}, {0, 0}}; + + TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, 0)); + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 0)); + nr_elements--; + TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); + + check_n_list_elements_ok(mylist, nr_elements, data_noFirst); + + TEST_ASSERT_EQUAL(0, list_delete_item(mylist, nr_elements-1)); + nr_elements--; + TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); + + check_n_list_elements_ok(mylist, nr_elements, data_noLast); + + TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 1)); + nr_elements--; + TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); + + check_n_list_elements_ok(mylist, nr_elements, data_noMiddle); +} + +static void test_DeleteLast_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_delete_last(NULL)); +} + +static void test_DeleteLast(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; + int nr_elements = sizeof(data)/sizeof(data[0]); + + TEST_ASSERT_EQUAL(-1, list_delete_last(mylist)); + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + for (int i = nr_elements-1; i >= 0; i--) + { + TEST_ASSERT_EQUAL(0, list_delete_last(mylist)); + TEST_ASSERT_EQUAL(i, list_get_nr_elements(mylist)); + check_n_list_elements_ok(mylist, i, data); + } + + TEST_ASSERT_NULL(mylist->head); + TEST_ASSERT_EQUAL(0, list_get_nr_elements(mylist)); +} + +int main(void) +{ + UnityBegin(); + + MY_RUN_TEST(test_ConstructList); + MY_RUN_TEST(test_NrElements_parameters); + MY_RUN_TEST(test_AddData_parameters); + MY_RUN_TEST(test_AddData); + MY_RUN_TEST(test_Add2PiecesOfData); + MY_RUN_TEST(test_GetElement_parameters); + MY_RUN_TEST(test_GetElement); + MY_RUN_TEST(test_GetLast_parameters); + MY_RUN_TEST(test_GetLast); + MY_RUN_TEST(test_IndexOf_parameters); + MY_RUN_TEST(test_IndexOf); + MY_RUN_TEST(test_IndexOfSpecial_parameters); + MY_RUN_TEST(test_IndexOfSpecial); + MY_RUN_TEST(test_DeleteItem_parameters); + MY_RUN_TEST(test_DeleteItem); + MY_RUN_TEST(test_DeleteLast_parameters); + MY_RUN_TEST(test_DeleteLast); + // MY_RUN_TEST(); + // MY_RUN_TEST(); + // MY_RUN_TEST(); + // MY_RUN_TEST(); + + return UnityEnd(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity.c new file mode 100644 index 0000000..7b10aa6 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity.c @@ -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 +#include + +#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; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity.h b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity.h new file mode 100644 index 0000000..8b16111 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity.h @@ -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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity_internals.h b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity_internals.h new file mode 100644 index 0000000..b0d0637 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity_internals.h @@ -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 +#include + +//------------------------------------------------------- +// 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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity_test_module.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity_test_module.c new file mode 100644 index 0000000..d1dc63e --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity_test_module.c @@ -0,0 +1,97 @@ +#include "unity_test_module.h" +#include +#include +#include +#include "unity.h" + +void (*unity_setUp_ptr)(void) = NULL; +void (*unit_tearDown_ptr)(void) = NULL; + +#ifdef UNITY_USE_MODULE_SETUP_TEARDOWN + +void setUp() +{ + if(unity_setUp_ptr != NULL) unity_setUp_ptr(); +} + +void tearDown() +{ + if(unit_tearDown_ptr != NULL) unit_tearDown_ptr(); +} + +#endif + +void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) ) +{ + unity_setUp_ptr = setUp; + unit_tearDown_ptr = tearDown; +} + +void UnityUnregisterSetupTearDown(void) +{ + unity_setUp_ptr = NULL; + unit_tearDown_ptr = NULL; +} + +UnityTestModule* UnityTestModuleFind( + UnityTestModule* modules, + size_t number_of_modules, + char* wantedModule) +{ + for(size_t i = 0; i < number_of_modules; i++) { + if(strcmp(wantedModule, modules[i].name) == 0) { + return &modules[i]; + } + } + + return NULL; +} + +void UnityTestModuleRunRequestedModules( + int number_of_requested_modules, + char* requested_modules_names[], + UnityTestModule* allModules, + size_t number_of_modules ) +{ + for(int i = 0; i < number_of_requested_modules; i++) + { + UnityTestModule* module = UnityTestModuleFind(allModules, + number_of_modules, requested_modules_names[i]); + + if(module != NULL) + { + module->run_tests(); + } + else + { + printf("Ignoring: could not find requested module: %s\n", + requested_modules_names[i]); + } + } +} + +int UnityTestModuleRun( + int argc, + char * argv[], + UnityTestModule* allModules, + size_t number_of_modules) +{ + UnityBegin(); + + bool moduleRequests = (argc > 1); + + if(moduleRequests) + { + UnityTestModuleRunRequestedModules(argc-1, &argv[1], + allModules, number_of_modules); + } + else + { + for(size_t i = 0; i < number_of_modules; i++) + { + allModules[i].run_tests(); + } + } + + return UnityEnd(); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity_test_module.h b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity_test_module.h new file mode 100644 index 0000000..c16ec8d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Unity/unity_test_module.h @@ -0,0 +1,31 @@ +#ifndef UNITY_TEST_MODULE_H +#define UNITY_TEST_MODULE_H + +#include + +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 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/Watch-Registers-Assignment.docx b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Watch-Registers-Assignment.docx new file mode 100644 index 0000000..784765a Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/Watch/Watch-Registers-Assignment.docx differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/build/.gitkeep b/C/t-oer-prc2-cbdb-main/Assignments/Watch/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/build/main b/C/t-oer-prc2-cbdb-main/Assignments/Watch/build/main new file mode 100755 index 0000000..af393fd Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/Watch/build/main differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/build/main_test b/C/t-oer-prc2-cbdb-main/Assignments/Watch/build/main_test new file mode 100755 index 0000000..5df50b3 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Assignments/Watch/build/main_test differ diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/main.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/main.c new file mode 100644 index 0000000..0c1fe1f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/main.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include + +#include "watch.h" +#include "watch_device_simulator.h" + +// leave resource_detector.h as last include! +#include "resource_detector.h" + +int main(int argc, char* argv[]) +{ + uint8_t hours = 11, minutes = 55, seconds = 42; + + watch_set_time_hours(hours); + watch_set_time_minutes(minutes); + watch_set_time_seconds(seconds); + + while (true) + { + watch_get_time(&hours, &minutes, &seconds); + watch_device_simulator_print_time(hours, minutes, seconds); + + uint8_t number_seconds_update = 10; + watch_device_simulator_increase_time(number_seconds_update); + sleep(number_seconds_update); + } + + return 0; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch.c new file mode 100644 index 0000000..7775a42 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch.c @@ -0,0 +1,303 @@ +#include "watch.h" +#include "watch_i2c.h" +#include "watch_registers.h" + +// leave resource_detector.h as last include! +#include "resource_detector.h" + +/*----------------------------------------------------------------------------*/ +/* C O N F I G */ +/*----------------------------------------------------------------------------*/ +int watch_config_reset() +{ + uint8_t config = 0; + if (watch_i2c_write_byte(ADDRESS_CONFIG, config) != 0) + { + return -1; + } + return 0; +} + +int watch_config_toggle_pause() +{ + uint8_t config; + if (watch_i2c_read_byte(ADDRESS_CONFIG, &config) != 0) + { + return -1; + } + watch_registers_toggle_config_is_paused(&config); + if (watch_i2c_write_byte(ADDRESS_CONFIG, config) != 0) + { + return -1; + } + + return 0; +} + +int watch_config_set_time_format(time_format format) +{ + uint8_t config; + if (watch_i2c_read_byte(ADDRESS_CONFIG, &config) != 0) + { + return -1; + } + watch_registers_set_config_time_format(&config, format); + if (watch_i2c_write_byte(ADDRESS_CONFIG, config) != 0) + { + return -1; + } + + return 0; +} + +int watch_config_set_time_update_interval(time_update_interval interval) +{ + uint8_t config; + if (watch_i2c_read_byte(ADDRESS_CONFIG, &config) != 0) + { + return -1; + } + watch_registers_set_config_time_update_interval(&config, interval); + if (watch_i2c_write_byte(ADDRESS_CONFIG, config) != 0) + { + return -1; + } + + return 0; +} + +int watch_config_get_settings( + bool* is_paused, time_format* format, + time_update_interval* interval) +{ + uint8_t config; + + if (is_paused == NULL || format == NULL || interval == NULL) + { + return -1; + } + + if (watch_i2c_read_byte(ADDRESS_CONFIG, &config) != 0) + { + return -1; + } + watch_registers_get_config_settings(config, is_paused, format, interval); + + return 0; +} + +/*----------------------------------------------------------------------------*/ +/* T I M E */ +/*----------------------------------------------------------------------------*/ +int watch_set_time_hours(uint8_t hours) +{ + uint8_t time_bits_low, time_bits_high; + + if (watch_i2c_read_byte(ADDRESS_TIME_LOW, &time_bits_low) != 0) + { + return -1; + } + if (watch_i2c_read_byte(ADDRESS_TIME_HIGH, &time_bits_high) != 0) + { + return -1; + } + watch_registers_set_time_hours(&time_bits_low, &time_bits_high, hours); + + if (watch_i2c_write_byte(ADDRESS_TIME_LOW, time_bits_low) != 0) + { + return -1; + } + if (watch_i2c_write_byte(ADDRESS_TIME_HIGH, time_bits_high) != 0) + { + return -1; + } + + return 0; +} + +int watch_set_time_minutes(uint8_t minutes) +{ + uint8_t time_bits_low, time_bits_high; + + if (watch_i2c_read_byte(ADDRESS_TIME_LOW, &time_bits_low) != 0) + { + return -1; + } + if (watch_i2c_read_byte(ADDRESS_TIME_HIGH, &time_bits_high) != 0) + { + return -1; + } + + watch_registers_set_time_minutes(&time_bits_low, &time_bits_high, minutes); + + if (watch_i2c_write_byte(ADDRESS_TIME_LOW, time_bits_low) != 0) + { + return -1; + } + if (watch_i2c_write_byte(ADDRESS_TIME_HIGH, time_bits_high) != 0) + { + return -1; + } + + return 0; +} + +int watch_set_time_seconds(uint8_t seconds) +{ + uint8_t time_bits_low, time_bits_high; + + if (watch_i2c_read_byte(ADDRESS_TIME_LOW, &time_bits_low) != 0) + { + return -1; + } + if (watch_i2c_read_byte(ADDRESS_TIME_HIGH, &time_bits_high) != 0) + { + return -1; + } + + watch_registers_set_time_seconds(&time_bits_low, &time_bits_high, seconds); + + if (watch_i2c_write_byte(ADDRESS_TIME_LOW, time_bits_low) != 0) + { + return -1; + } + if (watch_i2c_write_byte(ADDRESS_TIME_HIGH, time_bits_high) != 0) + { + return -1; + } + + return 0; +} + +int watch_get_time(uint8_t* hours, uint8_t* minutes, uint8_t* seconds) +{ + uint8_t time_bits_low, time_bits_high; + + if (hours == NULL || minutes == NULL || seconds == NULL) + { + return -1; + } + + if (watch_i2c_read_byte(ADDRESS_TIME_LOW, &time_bits_low) != 0) + { + return -1; + } + if (watch_i2c_read_byte(ADDRESS_TIME_HIGH, &time_bits_high) != 0) + { + return -1; + } + + watch_registers_get_time( + time_bits_low, time_bits_high, hours, minutes, seconds); + + return 0; +} + +/*----------------------------------------------------------------------------*/ +/* D A T E */ +/*----------------------------------------------------------------------------*/ +int watch_set_date_year(uint16_t year) +{ + uint8_t date_bits_low, date_bits_high; + + if (watch_i2c_read_byte(ADDRESS_DATE_LOW, &date_bits_low) != 0) + { + return -1; + } + if (watch_i2c_read_byte(ADDRESS_DATE_HIGH, &date_bits_high) != 0) + { + return -1; + } + + watch_registers_set_date_year(&date_bits_low, &date_bits_low, year); + + if (watch_i2c_write_byte(ADDRESS_DATE_LOW, date_bits_low) != 0) + { + return -1; + } + if (watch_i2c_write_byte(ADDRESS_DATE_HIGH, date_bits_high) != 0) + { + return -1; + } + + return 0; +} + +int watch_set_date_month(uint8_t month) +{ + uint8_t date_bits_low, date_bits_high; + + if (watch_i2c_read_byte(ADDRESS_DATE_LOW, &date_bits_low) != 0) + { + return -1; + } + if (watch_i2c_read_byte(ADDRESS_DATE_HIGH, &date_bits_high) != 0) + { + return -1; + } + + watch_registers_set_date_month(&date_bits_low, &date_bits_low, month); + + if (watch_i2c_write_byte(ADDRESS_DATE_LOW, date_bits_low) != 0) + { + return -1; + } + if (watch_i2c_write_byte(ADDRESS_DATE_HIGH, date_bits_high) != 0) + { + return -1; + } + + return 0; +} + +int watch_set_date_day_of_month(uint8_t day_of_month) +{ + uint8_t date_bits_low, date_bits_high; + + if (watch_i2c_read_byte(ADDRESS_DATE_LOW, &date_bits_low) != 0) + { + return -1; + } + if (watch_i2c_read_byte(ADDRESS_DATE_HIGH, &date_bits_high) != 0) + { + return -1; + } + + watch_registers_set_date_day_of_month( + &date_bits_low, &date_bits_low, day_of_month); + + if (watch_i2c_write_byte(ADDRESS_DATE_LOW, date_bits_low) != 0) + { + return -1; + } + if (watch_i2c_write_byte(ADDRESS_DATE_HIGH, date_bits_high) != 0) + { + return -1; + } + + return 0; +} + +int watch_get_date(uint8_t* year, uint8_t* month, uint8_t* day_of_month) +{ + uint8_t date_bits_low, date_bits_high; + + if (year == NULL || month == NULL || day_of_month == NULL) + { + return -1; + } + + if (watch_i2c_read_byte(ADDRESS_DATE_LOW, &date_bits_low) != 0) + { + return -1; + } + if (watch_i2c_read_byte(ADDRESS_DATE_HIGH, &date_bits_high) != 0) + { + return -1; + } + + watch_registers_get_date( + date_bits_low, date_bits_low, year, month, day_of_month); + + return 0; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch.h b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch.h new file mode 100644 index 0000000..2a1b578 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch.h @@ -0,0 +1,31 @@ +#ifndef WATCH_H +#define WATCH_H + +#include +#include +#include + +#include "watch_registers.h" + +int watch_config_reset(); +int watch_config_toggle_pause(); +int watch_config_set_time_format(time_format format); +int watch_config_set_time_update_interval(time_update_interval interval); +int watch_config_get_settings( + bool *is_paused, + time_format* format, + time_update_interval *interval); + +int watch_set_time_hours(uint8_t hours); +int watch_set_time_minutes(uint8_t minutes); +int watch_set_time_seconds(uint8_t seconds); +int watch_get_time(uint8_t* hours, uint8_t* minutes, uint8_t* seconds); + +int watch_set_date_year(uint16_t year); +int watch_set_date_month(uint8_t month); +int watch_set_date_day_of_month(uint8_t day_of_month); +int watch_get_date(uint8_t *year, + uint8_t* month, + uint8_t* day_of_month); + +#endif diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_device_simulator.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_device_simulator.c new file mode 100644 index 0000000..c339243 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_device_simulator.c @@ -0,0 +1,107 @@ +#include +#include + +#include "watch_device_simulator.h" +#include "watch_i2c.h" +#include "watch_registers.h" + +// leave resource_detector.h as last include! +#include "resource_detector.h" + +uint8_t register_values[5]; + +static int watch_device_simulator_address_to_array_index( + uint8_t address, uint8_t* register_value_index) +{ + if (register_value_index == NULL) + { + return -1; + } + + if ((address < ADDRESS_CONFIG) || (address > ADDRESS_DATE_HIGH)) + { + return -1; + } + + *register_value_index = address - ADDRESS_CONFIG; + + return 0; +} + +int watch_device_simulator_write_byte(uint8_t address, uint8_t value) +{ + uint8_t index = 0; + if (watch_device_simulator_address_to_array_index(address, &index) != 0) + { + return -1; + } + + register_values[index] = value; + + return 0; +} + +int watch_device_simulator_read_byte(uint8_t address, uint8_t* value) +{ + uint8_t index = 0; + if (watch_device_simulator_address_to_array_index(address, &index) != 0) + { + return -1; + } + + *value = register_values[index]; + + return 0; +} + +static void watch_device_simulator_add_one_second( + uint8_t* hours, uint8_t* minutes, uint8_t* seconds) +{ + *seconds += 1; + + if (*seconds == 60) + { + *seconds = 0; + *minutes += 1; + if (*minutes == 60) + { + *minutes = 0; + *hours += 1; + if (*hours == 12) + { + *hours = 0; + } + } + } +} + +void watch_device_simulator_print_time( + uint8_t hours, uint8_t minutes, uint8_t seconds) +{ + printf("Time: %02d:%02d:%02d\n", hours, minutes, seconds); +} + +int watch_device_simulator_increase_time(uint8_t number_of_seconds) +{ + uint8_t time_bits_low, time_bits_high = 0; + watch_device_simulator_read_byte(ADDRESS_TIME_LOW, &time_bits_low); + watch_device_simulator_read_byte(ADDRESS_TIME_HIGH, &time_bits_high); + + uint8_t seconds = 0, minutes = 0, hours = 0; + watch_registers_get_time( + time_bits_low, time_bits_high, &hours, &minutes, &seconds); + + for (uint8_t i = 0; i < number_of_seconds; i++) + { + watch_device_simulator_add_one_second(&hours, &minutes, &seconds); + } + + watch_registers_set_time_hours(&time_bits_low, &time_bits_high, hours); + watch_registers_set_time_minutes(&time_bits_low, &time_bits_high, minutes); + watch_registers_set_time_seconds(&time_bits_low, &time_bits_high, seconds); + + watch_device_simulator_write_byte(ADDRESS_TIME_LOW, time_bits_low); + watch_device_simulator_write_byte(ADDRESS_TIME_HIGH, time_bits_high); + + return 0; +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_device_simulator.h b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_device_simulator.h new file mode 100644 index 0000000..62307c7 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_device_simulator.h @@ -0,0 +1,13 @@ +#ifndef WATCH_DEVICE_SIMULATOR_H +#define WATCH_DEVICE_SIMULATOR_H + +#include + +int watch_device_simulator_write_byte(uint8_t address, uint8_t value); +int watch_device_simulator_read_byte(uint8_t address, uint8_t* value); + +int watch_device_simulator_increase_time(uint8_t number_of_seconds); +void watch_device_simulator_print_time( + uint8_t hours, uint8_t minutes, uint8_t seconds); + +#endif diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_i2c.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_i2c.c new file mode 100644 index 0000000..26c1b7d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_i2c.c @@ -0,0 +1,15 @@ +#include "watch_i2c.h" +#include "watch_device_simulator.h" + +// leave resource_detector.h as last include! +#include "resource_detector.h" + +int watch_i2c_write_byte(uint8_t address, uint8_t value) +{ + return watch_device_simulator_write_byte(address, value); +} + +int watch_i2c_read_byte(uint8_t address, uint8_t* value) +{ + return watch_device_simulator_read_byte(address, value); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_i2c.h b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_i2c.h new file mode 100644 index 0000000..036ea5d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/product/watch_i2c.h @@ -0,0 +1,11 @@ +#ifndef WATCH_I2C_H +#define WATCH_I2C_H + +#include +#include +#include + +int watch_i2c_write_byte(uint8_t address, uint8_t value); +int watch_i2c_read_byte(uint8_t address, uint8_t* value); + +#endif diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/shared/watch_registers.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/shared/watch_registers.c new file mode 100644 index 0000000..6e4897f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/shared/watch_registers.c @@ -0,0 +1,66 @@ +#include "watch_registers.h" + +// leave resource_detector.h as last include! +#include "resource_detector.h" + +void watch_registers_toggle_config_is_paused(uint8_t* config) +{ +} + +void watch_registers_set_config_time_format(uint8_t* config, time_format format) +{ +} + +void watch_registers_set_config_time_update_interval( + uint8_t* config, time_update_interval interval) +{ +} + +void watch_registers_get_config_settings( + uint8_t config, bool* is_paused, time_format* format, + time_update_interval* interval) +{ +} + +void watch_registers_set_time_hours( + uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t hours) +{ +} + +void watch_registers_set_time_minutes( + uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t minutes) +{ +} + +void watch_registers_set_time_seconds( + uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t seconds) +{ +} + +void watch_registers_get_time( + uint8_t time_bits_low, uint8_t time_bits_high, uint8_t* hours, + uint8_t* minutes, uint8_t* seconds) +{ +} + +void watch_registers_set_date_year( + uint8_t* date_bits_low, uint8_t* date_bits_high, uint8_t year) +{ +} + +void watch_registers_set_date_month( + uint8_t* date_bits_low, uint8_t* date_bits_high, uint8_t month) +{ +} + +void watch_registers_set_date_day_of_month( + uint8_t* date_bits_low, uint8_t* date_bits_high, + uint8_t day_of_month) +{ +} + +void watch_registers_get_date( + uint8_t date_bits_low, uint8_t date_bits_high, uint8_t* year, + uint8_t* month, uint8_t* day_of_month) +{ +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/shared/watch_registers.h b/C/t-oer-prc2-cbdb-main/Assignments/Watch/shared/watch_registers.h new file mode 100644 index 0000000..6693118 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/shared/watch_registers.h @@ -0,0 +1,189 @@ +#ifndef WATCH_REGISTERS_H +#define WATCH_REGISTERS_H + +#include +#include +#include + +#include "watch_registers.h" + +#define ADDRESS_CONFIG (0x20) +#define ADDRESS_TIME_HIGH (0x21) +#define ADDRESS_TIME_LOW (0x22) +#define ADDRESS_DATE_HIGH (0x23) +#define ADDRESS_DATE_LOW (0x24) + +typedef enum { + TIME_HOUR_MINUTE = 0, + TIME_HOUR_MINUTE_SECOND = 1 +} time_format; + +typedef enum { + TIME_UPDATE_DISABLED = 0, + TIME_EVERY_1_SECOND = 1, + TIME_EVERY_30_SECONDS = 2, + TIME_EVERY_MINUTE = 3 +} time_update_interval; + +/*! + * Update the configuration byte by toggling the pause bit. + * + * @param config: The address of the configuration byte that must be updated. + * + * @pre config may not be NULL. + */ +void watch_registers_toggle_config_is_paused(uint8_t* config); + +/*! + * Update the configuration byte by updating the time format. + * + * @param config: The address of the configuration byte that must be updated. + * @param format: Time format setting. + * + * @pre config may not be NULL. + */ +void watch_registers_set_config_time_format( + uint8_t* config, time_format format); + +/*! + * Update the configuration byte by updating the time update interval. + * + * @param config: The address of the configuration byte that must be updated. + * @param interval: Time update interval setting. + * + * @pre config may not be NULL. + */ +void watch_registers_set_config_time_update_interval( + uint8_t* config, time_update_interval interval); + +/*! + * Retrieve the configuration settings. + * + * @param config: The configuration byte. + * @param is_paused: The address to which the is_paused setting will be written. + * @param format: The address to which the time format will be written. + * @param interval: The address to which the time update interval will be + * written. + * + * @pre is_paused, format and interval may not be NULL. + */ +void watch_registers_get_config_settings( + uint8_t config, bool* is_paused, time_format* format, + time_update_interval* interval); + +/*! + * Update the time bytes by updating the hours bits. + * + * @param time_bits_low: The address to which the updated LSB part + of the time will be written. + * @param time_bits_high: The address to which the updated MSB part + of the time will be written. + * @param hours: The hour part of the time. + * + * @pre time_bits_low and time_bits_high may not be NULL. + */ +void watch_registers_set_time_hours( + uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t hours); + +/*! + * Update the time bytes by updating the minutes bits. + * + * @param time_bits_low: The address to which the updated LSB part + of the time will be written. + * @param time_bits_high: The address to which the updated MSB part + of the time will be written. + * @param minutes: The minute part of the time. + * + * @pre time_bits_low and time_bits_high may not be NULL. + */ +void watch_registers_set_time_minutes( + uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t minutes); + +/*! + * Update the time bytes by updating the seconds bits. + * + * @param time_bits_low: The address to which the updated LSB part + of the time will be written. + * @param time_bits_high: The address to which the updated MSB part + of the time will be written. + * @param seconds: The seconds part of the time. + * + * @pre time_bits_low and time_bits_high may not be NULL. + */ +void watch_registers_set_time_seconds( + uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t seconds); + +/*! + * Retrieve the time fields. + * + * @param time_bits_low: The LSB part of the time. + * @param time_bits_high: The MSB part of the time. + * @param hours: The address to which the hours will be written. + * @param minutes: The address to which the minutes will be written. + * @param seconds: The address to which the seconds will be written. + * + * @pre hours, minutes and seconds may not be NULL. + */ +void watch_registers_get_time( + uint8_t time_bits_low, uint8_t time_bits_high, uint8_t* hours, + uint8_t* minutes, uint8_t* seconds); + +/*! + * Update the date bytes by updating the year bits. + * + * @param date_bits_low: The address to which the updated LSB part + of the date will be written. + * @param date_bits_high: The address to which the updated MSB part + of the date will be written. + * @param year: The year part of the time. + * + * @pre date_bits_low and date_bits_high may not be NULL. + */ +void watch_registers_set_date_year( + uint8_t* date_bits_low, uint8_t* date_bits_high, uint8_t year); + +/*! + * Update the date bytes by updating the month bits. + * + * @param date_bits_low: The address to which the updated LSB part + of the date will be written. + * @param date_bits_high: The address to which the updated MSB part + of the date will be written. + * @param month: The month part of the time. + * + * @pre date_bits_low and date_bits_high may not be NULL. + */ +void watch_registers_set_date_month( + uint8_t* date_bits_low, uint8_t* date_bits_high, uint8_t month); + +/*! + * Update the date bytes by updating the day_of_month bits. + * + * @param date_bits_low: The address to which the updated LSB part + of the date will be written. + * @param date_bits_high: The address to which the updated MSB part + of the date will be written. + * @param day_of_month: The day_of_month part of the time. + * + * @pre date_bits_low and date_bits_high may not be NULL. + */ +void watch_registers_set_date_day_of_month( + uint8_t* date_bits_low, uint8_t* date_bits_high, + uint8_t day_of_month); + +/*! + * Retrieve the date fields. + * + * @param date_bits_low: The LSB part of the date. + * @param date_bits_high: The MSB part of the date. + * @param year: The address to which the year will be written. + * @param month: The address to which the month will be written. + * @param day_of_month: The address to which the day_of_month will be written. + * + * @pre year, month and day_of_month may not be NULL. + */ +void watch_registers_get_date( + uint8_t date_bits_low, uint8_t date_bits_high, uint8_t* year, + uint8_t* month, uint8_t* day_of_month); + +#endif diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/test/main.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/test/main.c new file mode 100644 index 0000000..e63f2fa --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/test/main.c @@ -0,0 +1,20 @@ +#include "unity_test_module.h" + +// leave resource_detector.h as last include! +#include "resource_detector.h" + +/* As an alternative for header files we can declare that + * the following methos are available 'extern'ally. + */ +extern void run_watch_tests(); +extern void run_file_element_tests(); + +int main (int argc, char * argv[]) +{ + UnityTestModule allModules[] = { { "watch", run_watch_tests} + }; + + size_t number_of_modules = sizeof(allModules)/sizeof(allModules[0]); + + return UnityTestModuleRun(argc, argv, allModules, number_of_modules); +} diff --git a/C/t-oer-prc2-cbdb-main/Assignments/Watch/test/watch_registers_test.c b/C/t-oer-prc2-cbdb-main/Assignments/Watch/test/watch_registers_test.c new file mode 100644 index 0000000..4f95a3d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Assignments/Watch/test/watch_registers_test.c @@ -0,0 +1,65 @@ +#include +#include + +#include "unity.h" +#include "unity_test_module.h" +#include "watch_registers.h" + +// leave resource_detector.h as last include! +#include "resource_detector.h" + +// I rather dislike keeping line numbers updated, so I made my own macro to +// ditch the line number +#define MY_RUN_TEST(func) RUN_TEST(func, 0) + +void watch_setUp(void) +{ +} + +void watch_tearDown(void) +{ + // This is run after EACH test +} + +void test_setting_time_hours(void) +{ + const uint8_t hours = 0xA5; + uint8_t time_bits_high = 0xA5; + uint8_t time_bits_low = 0x5A; + + watch_registers_set_time_hours(&time_bits_low, &time_bits_high, hours); + TEST_ASSERT_EQUAL_HEX8(0x55, time_bits_high); + TEST_ASSERT_EQUAL_HEX8(0x5A, time_bits_low); +} + +void test_get_time() +{ + const uint8_t hours = 11; + const uint8_t minutes = 55; + const uint8_t seconds = 42; + uint8_t time_bits_low = 0; + uint8_t time_bits_high = 0b00; + + watch_registers_set_time_seconds(&time_bits_low, &time_bits_high, seconds); + watch_registers_set_time_minutes(&time_bits_low, &time_bits_high, minutes); + watch_registers_set_time_hours(&time_bits_low, &time_bits_high, hours); + + uint8_t h; + uint8_t m; + uint8_t s; + watch_registers_get_time(time_bits_low, time_bits_high, &h, &m, &s); + TEST_ASSERT_EQUAL(hours, h); + TEST_ASSERT_EQUAL(minutes, m); + TEST_ASSERT_EQUAL(seconds, s); +} + + +void run_watch_tests() +{ + UnityRegisterSetupTearDown( watch_setUp, watch_tearDown); + + MY_RUN_TEST(test_setting_time_hours); + MY_RUN_TEST(test_get_time); + + UnityUnregisterSetupTearDown(); +} diff --git a/C/t-oer-prc2-cbdb-main/README.md b/C/t-oer-prc2-cbdb-main/README.md new file mode 100644 index 0000000..2b852b4 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/README.md @@ -0,0 +1,92 @@ +# t-oer-prc2-CBDB + + + +## Getting started + +To make it easy for you to get started with GitLab, here's a list of recommended next steps. + +Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! + +## Add your files + +- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files +- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: + +``` +cd existing_repo +git remote add origin https://git.fhict.nl/technology/t-oer-prc2-cbdb.git +git branch -M main +git push -uf origin main +``` + +## Integrate with your tools + +- [ ] [Set up project integrations](https://git.fhict.nl/technology/t-oer-prc2-cbdb/-/settings/integrations) + +## Collaborate with your team + +- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) +- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) +- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) +- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) +- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) + +## Test and Deploy + +Use the built-in continuous integration in GitLab. + +- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) +- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) +- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) +- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) +- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) + +*** + +# Editing this README + +When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. + +## Suggestions for a good README +Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. + +## Name +Choose a self-explaining name for your project. + +## Description +Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. + +## Badges +On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. + +## Visuals +Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. + +## Installation +Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. + +## Usage +Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. + +## Support +Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. + +## Roadmap +If you have ideas for releases in the future, it is a good idea to list them in the README. + +## Contributing +State if you are open to contributions and what your requirements are for accepting them. + +For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. + +You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. + +## Authors and acknowledgment +Show your appreciation to those who have contributed to the project. + +## License +For open source projects, say how it is licensed. + +## Project status +If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week1/.placeholder b/C/t-oer-prc2-cbdb-main/Workshops/Week1/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week1/demo_arrays.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week1/demo_arrays.zip new file mode 100644 index 0000000..28acb1d Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week1/demo_arrays.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week1/week_1.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week1/week_1.pptx new file mode 100644 index 0000000..31ade3f Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week1/week_1.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week10/.gitkeep b/C/t-oer-prc2-cbdb-main/Workshops/Week10/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week10/exercise-bit-manipulation.docx b/C/t-oer-prc2-cbdb-main/Workshops/Week10/exercise-bit-manipulation.docx new file mode 100644 index 0000000..a026294 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week10/exercise-bit-manipulation.docx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week11/.gitkeep b/C/t-oer-prc2-cbdb-main/Workshops/Week11/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week11/review-watch-assignment.docx b/C/t-oer-prc2-cbdb-main/Workshops/Week11/review-watch-assignment.docx new file mode 100644 index 0000000..de9f55c Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week11/review-watch-assignment.docx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week12/.placeholder b/C/t-oer-prc2-cbdb-main/Workshops/Week12/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week12/demoReadFile.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week12/demoReadFile.zip new file mode 100644 index 0000000..0154f20 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week12/demoReadFile.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week12/demoWriteFile.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week12/demoWriteFile.zip new file mode 100644 index 0000000..77f32fb Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week12/demoWriteFile.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week12/story.txt b/C/t-oer-prc2-cbdb-main/Workshops/Week12/story.txt new file mode 100644 index 0000000..c2ab2f3 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/Workshops/Week12/story.txt @@ -0,0 +1,14 @@ +Anything that happens. happens, + +Anything that. in happening. causes something +else to happen. causes something else to happen, + +Anything that. in happening. causes +itself to happen again. happens again, + +It doesn't necessarily do it +in chronological order. though, + + +From: The Hitchhiker's guide to the Galaxy by Douglas Adams, +Book five in the trilogy of five: Mostly Harmless, \ No newline at end of file diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week12/week_12.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week12/week_12.pptx new file mode 100644 index 0000000..d8785de Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week12/week_12.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week13/.gitkeep b/C/t-oer-prc2-cbdb-main/Workshops/Week13/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week13/Kickoff1_-_ADIDAS.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week13/Kickoff1_-_ADIDAS.pptx new file mode 100644 index 0000000..d9791f9 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week13/Kickoff1_-_ADIDAS.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week2/.placeholder b/C/t-oer-prc2-cbdb-main/Workshops/Week2/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week2/demoWeek2.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week2/demoWeek2.zip new file mode 100644 index 0000000..7bb2894 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week2/demoWeek2.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week2/startUpProject.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week2/startUpProject.zip new file mode 100644 index 0000000..f0bfd85 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week2/startUpProject.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week2/week_2.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week2/week_2.pptx new file mode 100644 index 0000000..79a3a55 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week2/week_2.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week3/.placeholder b/C/t-oer-prc2-cbdb-main/Workshops/Week3/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week3/demoFunctions.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week3/demoFunctions.zip new file mode 100644 index 0000000..ae336df Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week3/demoFunctions.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week3/demoStructures.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week3/demoStructures.zip new file mode 100644 index 0000000..e4b13eb Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week3/demoStructures.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week3/exercises_week3.pdf b/C/t-oer-prc2-cbdb-main/Workshops/Week3/exercises_week3.pdf new file mode 100644 index 0000000..fbe364d Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week3/exercises_week3.pdf differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week3/startUpExerciseWeek3.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week3/startUpExerciseWeek3.zip new file mode 100644 index 0000000..bbbc4df Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week3/startUpExerciseWeek3.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week3/week_3.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week3/week_3.pptx new file mode 100644 index 0000000..b94b771 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week3/week_3.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week4/.placeholder b/C/t-oer-prc2-cbdb-main/Workshops/Week4/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week4/demoPointers.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week4/demoPointers.zip new file mode 100644 index 0000000..63b2de5 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week4/demoPointers.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week4/week_4.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week4/week_4.pptx new file mode 100644 index 0000000..18652fb Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week4/week_4.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week5/.placeholder b/C/t-oer-prc2-cbdb-main/Workshops/Week5/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week5/debuggingChallenge.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week5/debuggingChallenge.zip new file mode 100644 index 0000000..3570bff Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week5/debuggingChallenge.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week5/demoArraysWithPointers.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week5/demoArraysWithPointers.zip new file mode 100644 index 0000000..2f23803 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week5/demoArraysWithPointers.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week5/week_5a.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week5/week_5a.pptx new file mode 100644 index 0000000..7682909 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week5/week_5a.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week5/week_5b.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week5/week_5b.pptx new file mode 100644 index 0000000..52eadc9 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week5/week_5b.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week6/.placeholder b/C/t-oer-prc2-cbdb-main/Workshops/Week6/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week6/exercises_UnitTests.pdf b/C/t-oer-prc2-cbdb-main/Workshops/Week6/exercises_UnitTests.pdf new file mode 100644 index 0000000..b3863b4 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week6/exercises_UnitTests.pdf differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week6/startUp_UnitTests.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week6/startUp_UnitTests.zip new file mode 100644 index 0000000..5a32ff2 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week6/startUp_UnitTests.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week6/week_6.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week6/week_6.pptx new file mode 100644 index 0000000..eb767f4 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week6/week_6.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week8/.placeholder b/C/t-oer-prc2-cbdb-main/Workshops/Week8/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week8/demoBitManipulationBasics.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week8/demoBitManipulationBasics.zip new file mode 100644 index 0000000..590a7c7 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week8/demoBitManipulationBasics.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week8/week_8.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week8/week_8.pptx new file mode 100644 index 0000000..f496f21 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week8/week_8.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week9/.placeholder b/C/t-oer-prc2-cbdb-main/Workshops/Week9/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week9/demoBitManipulationApplied.zip b/C/t-oer-prc2-cbdb-main/Workshops/Week9/demoBitManipulationApplied.zip new file mode 100644 index 0000000..547d9ec Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week9/demoBitManipulationApplied.zip differ diff --git a/C/t-oer-prc2-cbdb-main/Workshops/Week9/week_9.pptx b/C/t-oer-prc2-cbdb-main/Workshops/Week9/week_9.pptx new file mode 100644 index 0000000..0197c59 Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/Workshops/Week9/week_9.pptx differ diff --git a/C/t-oer-prc2-cbdb-main/development-setup/README.md b/C/t-oer-prc2-cbdb-main/development-setup/README.md new file mode 100644 index 0000000..be664ad --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/README.md @@ -0,0 +1,52 @@ +[[_TOC_]] + +# Introduction + +In this module you will find an introduction the required tooling and hardware you will need for this course. + +# Setup + +## Linux virtual image + ++ Linux Virtual image for programming environment is available at: + + [www.fhict.nl/docent/downloads/TI/S3/](https://www.fhict.nl/docent/downloads/TI/S3/) (please use the kathara image) This image includes visual studio code setup and kathare (used for networking challenges) ++ If you use your own Linux installation you can use (at your own risk!) the script for the required tooling: [link](https://git.fhict.nl/technology/t-sem2-code/blob/master/es2/scripts/install-tooling.sh). ++ You can download VMware via [FHICT Studentenplein](https://portal.fhict.nl/Studentenplein/SitePages/Home.aspx) via link `VMware Store`. + +# Information-resources + +## Development environment + +For editing and compiling your code we recommend the following options: + ++ For Arduino and PC code: [Visual Code](https://code.visualstudio.com/) editor with use of the [PlatformIO](https://platformio.org/install/ide?install=vscode). The provided VmWare image has Visual Code already installed and is configured with a number of plugins to support building executables for your PC and Arduino (see the above installation script for details). You can start up Visual Code from a terminal by the command `code .` (don't forget the `.` (point!): it means it will use the current directory as project directory). ++ For PC-code: a simple text editor (like [Geany](https://www.geany.org/), [Sublime](https://www.sublimetext.com/), [Vim](http://www.vim.org/), [Emacs](https://www.gnu.org/software/emacs/) and a [terminal](https://www.google.nl/search?q=linux+terminal+tutorial) using the [make](https://linux.die.net/man/1/make) program. + + For building code using a terminal and make see [link](https://www.google.nl/search?q=linux+using+make+terminal). ++ For Arduino code: [Arduino IDE](https://www.arduino.cc/en/Main/Software). We will however require you to use [header-files](https://www.google.nl/search?q=header+files+in+c). + ++ An online editor to try some basic stuff: [https://www.onlinegdb.com/](https://www.onlinegdb.com/) + ++ Tip: you can install other software in your Linux environment by using [apt-get](https://www.google.nl/search?q=linux+using+apt-get+install). + +## For Windows users + +It is possible, with some effort on your side, to run C-programs on a Windows machine. This is however at your own initiative to install, and your teacher may offer limited support because of the availability of the Linux image. + +### WSL + +An option is to use WSL [Windows Subsystem for Linux(WSL)](https://docs.microsoft.com/en-us/windows/wsl/install-win10). Install the following: + ++ [Ubuntu](https://docs.microsoft.com/en-us/windows/wsl/install-win10) and execute the following command in a terminal: + + `sudo apt-get install -y build-essential make gcc g++` ++ [Visual Studio Code](https://code.visualstudio.com/) met de volgende extensies: + + [WSL integratie](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) + + [PlatformIO](https://marketplace.visualstudio.com/items?itemName=platformio.platformio-ide) ++ For onnecting USB devices to your WSL see [Connect-usb](https://learn.microsoft.com/en-us/windows/wsl/connect-usb#install-the-usbipd-win-project) + +### MinGW Gcc compiler + +The other option for c-compiling is [TDM-GCC MinGW Compiler](https://sourceforge.net/projects/tdm-gcc/). Here you have to install make and a gcc compiler. + +# Starting project + +You can use the startingproject in the enclosed folder to test your setup. Content and way of working is explained [here](https://git.fhict.nl/technology/t-oer-prc2/-/blob/master/development-setup/startingProject/README.md). diff --git a/C/t-oer-prc2-cbdb-main/development-setup/Visual Code IDE v0.4.docx b/C/t-oer-prc2-cbdb-main/development-setup/Visual Code IDE v0.4.docx new file mode 100644 index 0000000..d3fe04d Binary files /dev/null and b/C/t-oer-prc2-cbdb-main/development-setup/Visual Code IDE v0.4.docx differ diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/.gitignore b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/.gitignore new file mode 100644 index 0000000..0048524 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/.gitignore @@ -0,0 +1,3 @@ +!build/ +build/* +!build/.gitkeep \ No newline at end of file diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/.vscode/launch.json b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/.vscode/launch.json new file mode 100644 index 0000000..182cbc4 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/main_test", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Makefile b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Makefile new file mode 100644 index 0000000..1524bb2 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Makefile @@ -0,0 +1,41 @@ +PROD_DIR := ./product +SHARED_DIR := ./shared +TEST_DIR := ./test +UNITY_FOLDER=./Unity +BUILD_DIR=./build + +PROD_EXEC = main +PROD_DIRS := $(PROD_DIR) $(SHARED_DIR) +PROD_FILES := $(wildcard $(patsubst %,%/*.c, $(PROD_DIRS))) +HEADER_PROD_FILES := $(wildcard $(patsubst %,%/*.h, $(PROD_DIRS))) +PROD_INC_DIRS=-I$(PROD_DIR) -I$(SHARED_DIR) + +TEST_EXEC = main_test +TEST_DIRS := $(TEST_DIR) $(SHARED_DIR) $(UNITY_FOLDER) +TEST_FILES := $(wildcard $(patsubst %,%/*.c, $(TEST_DIRS))) +HEADER_TEST_FILES := $(wildcard $(patsubst %,%/*.h, $(TEST_DIRS))) +TEST_INC_DIRS=-I$(TEST_DIR) -I$(SHARED_DIR) -I$(UNITY_FOLDER) + +CC=gcc +SYMBOLS=-Wall -Werror -g -pedantic -O0 -std=c99 +TEST_SYMBOLS=$(SYMBOLS) -DTEST + +.PHONY: clean test + +all: $(PROD_EXEC) $(TEST_EXEC) + +$(PROD_EXEC): Makefile $(PROD_FILES) $(HEADER_FILES) + $(CC) $(PROD_INC_DIRS) $(TEST_SYMBOLS) $(PROD_FILES) -o $(BUILD_DIR)/$(PROD_EXEC) + +$(TEST_EXEC): Makefile $(TEST_FILES) $(HEADER_FILES) + $(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(BUILD_DIR)/$(TEST_EXEC) + +run: $(PROD_EXEC) + @./$(BUILD_DIR)/$(PROD_EXEC) + +test: $(TEST_EXEC) + @./$(BUILD_DIR)/$(TEST_EXEC) + +clean: + rm -f $(BUILD_DIR)/$(PROD_EXEC) + rm -f $(BUILD_DIR)/$(TEST_EXEC) diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/README.md b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/README.md new file mode 100644 index 0000000..701d54d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/README.md @@ -0,0 +1,69 @@ +# What does this project contain? + +This directory holds an (almost) empty C project. +It can be used as a template for your own project. + +It contains of: + ++ a main which is the starting point for you program ++ an example of a c and corresponding header file + * you have to complete the swap code. ++ an example of a unittest + +## Directory structure + +Directory | Purpose +---|--- +product | Holds the main.c file and c-source files that are **only** needed to build the **main** executable. +test | Holds all the unit tests that are used are build the **main_test** executable. +shared | Holds the files that are used by both the **main** as **main_test** executable. In general these are the c-source files that you wish to unit test. +build | Holds the build [artifacts](https://en.wikipedia.org/wiki/Artifact_(software_development): **main** and **main_test** + + +# System Preconditions + +Preconditions before this project can be used: + ++ up and running linux (virtual) machine ++ GIT client up and running ++ working copy of this git repository available + +# Project use + +To prepare your own working environment it is advised to follow the following steps: + ++ open your virtual machine ++ start linux image ++ COPY this project directory to your own GIT archive. Think about the directory where you want put it and how you are going to name it. ++ start visual studio code and load the project ++ start a terminal in visual studio code + +# Building the code + +You build the code by using a terminal: + +Action | Terminal command to type +---|--- +Build main code: | make main +Build test code: | make main_test +Build all code: | make all +Run main code: | make run +Run test code: | make test + +If you type make run and you get this message: + +*failed, the implementation is empty.* + +Then you have succesfully installed and ran the code. +If not, you have the fix whatever there needs to be fixed. + +# Debugging + +This project is configure to debug the test code. +Please refer to [https://code.visualstudio.com/docs/editor/debugging] on how to debug this code. + +# Personal projects + +If you have succesfully altered this project, commit & push it to your git archive. + +Once this is done you have completed one complete development cycle and you can apply this knowledge in challenges to come. diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/list.c b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/list.c new file mode 100644 index 0000000..fc396be --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/list.c @@ -0,0 +1,278 @@ +/* ********************************************** + * generic linked list in plain c + * author: Freddy Hurkmans + * date: dec 20, 2014 + * **********************************************/ + +/* ****************************************************************************** + * This list is designed using object oriented ideas, but is implemented in c. + * + * The idea is: you construct a list for a certain data structure (say: mystruct): + * list_admin* mylist = construct_list(sizeof(mystruct)) + * mylist contains private data for this list implementation. You need not worry + * about it, only give it as first parameter to each list method. + * + * This means you can have multiple lists at the same time, just make sure you + * give the right list_admin structure to the list function. + * When you're done with your list, just call the destructor: destruct_list(&mylist) + * The destructor automatically deletes remaining list elements and the list administration. + * + * As this list implementation keeps its own administration in list_admin, you need + * not worry about next pointers and such. Your structure doesn't even need pointers + * to itself, you only need to worry about data. A valid struct could thus be: + * typedef struct + * { + * int nr; + * char text[100]; + * } mystruct; + * + * Adding data to the list is done using list_add_* methods, such as list_add_tail, + * which adds data to the end of the list: + * mystruct data = {10, "hello world!"}; + * int result = list_add_tail(mylist, &data); + * You don't have to provide the size of your struct, you've already done that in + * the destructor. If result < 0 list_add_* has failed (either a parameter problem + * or malloc didn't give memory). + * + * You can get a pointer to your data using list_get_*, e.g. get the 2nd element: + * mystruct* dataptr = list_get_element(admin, 1); + * or get the last element: + * mystruct* dataptr = list_get_last(admin); + * If dataptr is not NULL it points to the correct data, else the operation failed. + * + * Searching for data in your list can be done with list_index_of*. list_index_of + * compares the data in each list item to the given data. If they are the same, it + * returns the index. If you want to search for an element with a certain value for + * nr or text (see mystruct) you can implement your own compare function and use + * list_index_of_special (check memcmp for required return values): + * int mycompare(void* p1, void* p2, size_t size) + * { + * // this example doesn't need size! + * mystruct* org = (mystruct*)p1; + * int* nr = (int*)p2; + * return org->nr - nr; // return 0 if they are the same + * } + * Say you want to search for an element that has nr 10: + * int nr = 10; + * int index = list_index_of_special(mylist, &nr, mycompare); + * As noted earlier: mycompare must have the same prototype as memcmp. In fact: + * list_index_of is a shortcut for list_index_of_special(mylist, data, memcmp). + * + * Finally you can delete items with list_delete_*. They should work rather + * straight forward. If they succeed they return 0. You don't have to delete + * all items before destructing your list. + * + * ******************************************************************************/ + + +#include /* for memcmp and memcpy */ + +#include "list.h" + +static size_t data_size(const list_admin* admin); +static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index); +static list_head* get_list_head_of_element_n(list_admin* admin, size_t index); +static void remove_first_element(list_admin* admin); +static int remove_non_first_element(list_admin* admin, size_t index); + +/* ********************************************** + * Constructor / destructor + * **********************************************/ +list_admin* construct_list(size_t element_size) +{ + list_admin* admin = malloc(sizeof(*admin)); + if (admin != NULL) + { + admin->head = NULL; + admin->element_size = element_size; + admin->nr_elements = 0; + } + return admin; +} + +void destruct_list(list_admin** admin) +{ + if ((admin != NULL) && (*admin != NULL)) + { + while ((*admin)->head != NULL) + { + list_head* temp = (*admin)->head; + (*admin)->head = (*admin)->head->next; + free(temp); + temp = NULL; + } + free(*admin); + *admin = NULL; + } +} + +/* ********************************************** + * Public functions + * **********************************************/ +int list_get_nr_elements(list_admin* admin) +{ + int nr_elements = -1; + if (admin != NULL) + { + nr_elements = admin->nr_elements; + } + return nr_elements; +} + +int list_add_tail(list_admin* admin, const void* data) +{ + int result = -1; + if ((admin != NULL) && (data != NULL)) + { + list_head* new = malloc(data_size(admin)); + if (new != NULL) + { + result = 0; + new->next = NULL; + memcpy(new+1, data, admin->element_size); + + if (admin->head == NULL) + { + admin->head = new; + } + else + { + list_head* temp = get_guaranteed_list_head_of_element_n(admin, admin->nr_elements-1); + temp->next = new; + } + + admin->nr_elements++; + } + } + return result; +} + + +void* list_get_element(list_admin* admin, size_t index) +{ + list_head* item = get_list_head_of_element_n(admin, index); + if(item != NULL) + { + item++; // user data is just beyond list_head, thus we must increase the pointer + } + return item; +} + +void* list_get_last(list_admin* admin) +{ + list_head* item = NULL; + if (admin != NULL) + { + item = list_get_element(admin, admin->nr_elements-1); + } + return item; +} + +int list_index_of(list_admin* admin, const void* data) +{ + return list_index_of_special(admin, data, memcmp); +} + +int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr compare) +{ + int index = -1; + if ((admin != NULL) && (data != NULL) && (compare != NULL)) + { + list_head* temp = admin->head; + index = 0; + while ((temp != NULL) && (compare(temp+1, data, admin->element_size) != 0)) + { + temp = temp->next; + index++; + } + if (temp == NULL) + { + index = -1; + } + } + return index; +} + +int list_delete_item(list_admin* admin, size_t index) +{ + int result = -1; + if ((admin != NULL) && (admin->head != NULL) && (index < admin->nr_elements)) + { + if (index == 0) + { + result = 0; + remove_first_element(admin); + } + else + { + result = remove_non_first_element(admin, index); + } + } + return result; +} + +int list_delete_last(list_admin* admin) +{ + int result = -1; + if (admin != NULL) + { + result = list_delete_item(admin, admin->nr_elements - 1); + } + return result; +} + +/* ********************************************** + * Private functions + * **********************************************/ +static size_t data_size(const list_admin* admin) +{ + return admin->element_size + sizeof(list_head); +} + +static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index) +{ + list_head* item = admin->head; + for (size_t i = 0; (i < index) && (item != NULL); i++) + { + item = item->next; + } + return item; +} + +static list_head* get_list_head_of_element_n(list_admin* admin, size_t index) +{ + list_head* item = NULL; + if ((admin != NULL) && (index < admin->nr_elements)) + { + item = get_guaranteed_list_head_of_element_n(admin, index); + } + return item; +} + +static void remove_first_element(list_admin* admin) +{ + list_head* temp = admin->head; + admin->head = admin->head->next; + free(temp); + temp = NULL; + admin->nr_elements--; +} + +static int remove_non_first_element(list_admin* admin, size_t index) +{ + int result = -1; + if (index > 0) + { + list_head* temp = get_list_head_of_element_n(admin, index-1); + if ((temp != NULL) && (temp->next != NULL)) // to remove element n, element n-1 and n must exist + { + result = 0; + list_head* to_delete = temp->next; + temp->next = to_delete->next; + free(to_delete); + to_delete = NULL; + admin->nr_elements--; + } + } + return result; +} diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/list.h b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/list.h new file mode 100644 index 0000000..c70c552 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/list.h @@ -0,0 +1,52 @@ +#pragma once + +#include + +typedef struct list_head +{ + struct list_head* next; +} list_head; + +typedef struct +{ + struct list_head* head; + size_t element_size; + size_t nr_elements; +} list_admin; + +typedef int (*CompareFuncPtr)(const void*, const void*, size_t); + +// call the constructor before using the list: +// list_admin* mylist = construct_list(sizeof(mystruct)); +// if mylist equals NULL, no memory could be allocated. Please don't +// mess with the admin data, this can corrupt your data. +list_admin* construct_list(size_t element_size); + +// call the destructor when you're done, pass the list administration +// as referenced parameter (the variable will be set to NULL). +void destruct_list(list_admin** admin); + +// Reads the number of elements in your list. Returns -1 in case of +// errors, else the number of elements. +int list_get_nr_elements(list_admin* admin); + +// Add data to the end of the list. Returns -1 in case of errors, else 0 +int list_add_tail(list_admin* admin, const void* data); + +// Returns a pointer to the requested element. Returns NULL in case of +// errors (such as: the element does not exist). +void* list_get_element(list_admin* admin, size_t index); +void* list_get_last(list_admin* admin); + +// Returns the index to the first found list element that's equal to data, +// or -1 in case of errors (such as: not found). +int list_index_of(list_admin* admin, const void* data); + +// Returns the index to the first found list element for which cmp says it's, +// equal to data, or -1 in case of errors (such as: not found). cmp must behave +// just like memcmp, i.e.: return 0 when the data matches. +int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr cmp); + +// Delete an item in the list. Returns -1 in case of errors, else 0. +int list_delete_item(list_admin* admin, size_t index); +int list_delete_last(list_admin* admin); diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/resource_detector.c b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/resource_detector.c new file mode 100644 index 0000000..30a4360 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/resource_detector.c @@ -0,0 +1,270 @@ +#include +#include +#include +#include +//#include +#include + +#include "resource_detector.h" + +#undef malloc +#undef free +#undef main +#undef fopen +#undef fclose + +#include "list.h" + +#define MAGIC_CODE 0x78563412 + +#define ADDR(addr,offset) ((addr) + (offset)) +#define SET_MAGIC_CODE(addr,offset) *((int*) ADDR(addr,offset)) = MAGIC_CODE +#define MAGIC_CODE_OK(addr,offset) (*((int*) ADDR(addr,offset)) == MAGIC_CODE) + +typedef struct +{ + char* addr; + unsigned int size; + const char* file; + unsigned int line; +} mem_data; + +typedef struct +{ + FILE* addr; + const char* file_to_open; + const char* mode; + const char* file; + unsigned int line; +} file_data; + +static list_admin* memlist = NULL; +static list_admin* filelist = NULL; + +static int memory_compare(const void* meminfo, const void* address, size_t size) +{ + mem_data* info = (mem_data*)meminfo; + char* addr = (char*)address; + return info->addr - addr; +} + +static int file_compare(const void* fileinfo, const void* address, size_t size) +{ + file_data* info = (file_data*)fileinfo; + FILE* addr = (FILE*)address; + return info->addr - addr; +} + + +static void +invalidate (mem_data* info) +{ + char* user_addr; + char* raw_addr; + unsigned int size; + + user_addr = info->addr; + size = info->size; + raw_addr = ADDR (user_addr, -sizeof(int)); + + if (!MAGIC_CODE_OK(user_addr, -sizeof(int)) || !MAGIC_CODE_OK(user_addr, size)) + { + fprintf (stderr, "ERROR: addr %p (%s, line %d): out-of-bound access\n", (void*)user_addr, info->file, info->line); + } + + memset (raw_addr, 0xff, size + (2 * sizeof(int))); + free (raw_addr); +} + +/* + * replacement of malloc + */ +extern void* +xmalloc (unsigned int size, const char* file, unsigned int line) +{ + char* raw_addr = malloc (size + (2 * sizeof(int))); + char* user_addr; + mem_data info = {NULL, 0, NULL, 0}; + + if (raw_addr == NULL) + { + fprintf (stderr, "ERROR: malloc failed for %d bytes (%s, line %d)\n", size, file, line); + return (NULL); + } + else + { + user_addr = ADDR (raw_addr, sizeof (int)); + SET_MAGIC_CODE (raw_addr, 0); + SET_MAGIC_CODE (user_addr, size); + + info.addr = user_addr; + info.size = size; + info.file = file; + info.line = line; + list_add_tail(memlist, &info); + } + return ((void*) user_addr); +} + +/* + * replacement of free + */ +extern void +xfree (void* addr, const char* filename, int linenr) +{ + char* user_addr = (char*) addr; + mem_data* info = NULL; + + /* check if allocated memory is in our list and retrieve its info */ + int index = list_index_of_special(memlist, addr, memory_compare); + info = list_get_element(memlist, index); + + if (info == NULL) + { + fprintf (stderr, "ERROR: trying to free memory that was not malloc-ed (addr %p) in %s : %d\n", (void*)user_addr, filename, linenr); + return; + } + + invalidate (info); + list_delete_item(memlist, index); +} + +static void +print_empty_lines(int n) +{ + int i; + for (i = 0; i < n; i++) + { + fprintf(stderr, "\n"); + } +} + +static void set_colour_red(void) +{ + fprintf(stderr, "\033[10;31m"); +} +static void set_colour_gray(void) +{ + fprintf(stderr, "\033[22;37m"); +} +static void +print_line(void) +{ + fprintf (stderr, "---------------------------------------------------------\n"); +} + +static void +print_not_good(void) +{ + set_colour_gray(); + print_line(); + set_colour_red(); + fprintf (stderr, " # # ###\n"); + fprintf (stderr, " ## # #### ##### #### #### #### ##### ###\n"); + fprintf (stderr, " # # # # # # # # # # # # # # ###\n"); + fprintf (stderr, " # # # # # # # # # # # # # # \n"); + fprintf (stderr, " # # # # # # # ### # # # # # # \n"); + fprintf (stderr, " # ## # # # # # # # # # # # ###\n"); + fprintf (stderr, " # # #### # #### #### #### ##### ###\n"); + set_colour_gray(); + print_line(); +} + +/* + * writes all info of the unallocated memory + */ +static void +resource_detection (void) +{ + time_t now = time (NULL); + + int forgotten_frees = list_get_nr_elements(memlist); + int nr_files_open = list_get_nr_elements(filelist); + + if ((forgotten_frees > 0) || (nr_files_open > 0)) + { + print_empty_lines(15); + } + + if (forgotten_frees > 0) + { + mem_data* info = NULL; + print_line(); + fprintf (stderr, "Memory Leak Summary, generated: %s", ctime (&now)); + print_not_good(); + set_colour_red(); + while((info = list_get_element(memlist, 0)) != NULL) + { + fprintf (stderr, "forgot to free address: %p (%d bytes) that was allocated in: %s on line: %d\n", + (void*)info->addr, info->size, info->file, info->line); + list_delete_item(memlist, 0); + } + set_colour_gray(); + print_line(); + print_empty_lines(1); + } + + if (nr_files_open > 0) + { + file_data* info = NULL; + print_line(); + fprintf (stderr, "File Management Summary, generated: %s", ctime (&now)); + print_not_good(); + set_colour_red(); + while((info = list_get_element(filelist, 0)) != NULL) + { + fprintf (stderr, "forgot to close file: %s (ptr %p, mode \"%s\") that was opened from: %s on line: %d\n", + info->file_to_open, (void*)(info->addr), info->mode, info->file, info->line); + list_delete_item(filelist, 0); + } + set_colour_gray(); + print_line(); + print_empty_lines(1); + } + if ((forgotten_frees == 0) && (nr_files_open == 0)) + { + printf ("\nResource checks: OK\n\n"); + } + + destruct_list(&memlist); + destruct_list(&filelist); +} + +extern FILE* +xfopen (const char* file_to_open, const char* mode, const char* filename, int linenr) +{ + file_data info = {0}; + info.addr = fopen(file_to_open, mode); + if (info.addr != NULL) + { + info.file_to_open = file_to_open; + info.mode = mode; + info.file = filename; + info.line = linenr; + list_add_tail(filelist, &info); + } + return info.addr; +} + +extern int +xfclose(FILE* fptr, const char* filename, int linenr) +{ + int index = list_index_of_special(filelist, fptr, file_compare); + if (index < 0) + { + fprintf (stderr, "ERROR: trying to close an unopened file in %s on line number %d.\n", filename, linenr); + return -1; + } + list_delete_item(filelist, index); + return (fclose (fptr)); +} + +extern int +main (int argc, char* argv[]) +{ + atexit (resource_detection); + memlist = construct_list(sizeof(mem_data)); + filelist = construct_list(sizeof(file_data)); + + return (xmain (argc, argv)); +} diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/resource_detector.h b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/resource_detector.h new file mode 100644 index 0000000..0a1811b --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/resource_detector.h @@ -0,0 +1,18 @@ +#ifndef RESOURCE_DETECTOR_H +#define RESOURCE_DETECTOR_H + +#include + +#define main xmain +#define malloc(size) xmalloc ((size), (__FILE__), (__LINE__)) +#define free(addr) xfree ((addr), __FILE__, __LINE__) +#define fopen(name,mode) xfopen ((name),(mode), __FILE__, __LINE__) +#define fclose(fptr) xfclose ((fptr), __FILE__, __LINE__) + +extern int xmain(int argc, char* argv[]); +extern void* xmalloc(unsigned int size, const char* file, unsigned int line); +extern void xfree(void* addr, const char* filename, int linenr); +extern FILE* xfopen(const char* file_to_open, const char* mode, const char* filename, int linenr); +extern int xfclose(FILE* fptr, const char* filename, int linenr); + +#endif diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/test/Makefile b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/test/Makefile new file mode 100644 index 0000000..7915049 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/test/Makefile @@ -0,0 +1,28 @@ +UNITY_FOLDER=../Unity +TEST_INC_DIRS=$(INC_DIRS) -I$(UNITY_FOLDER) + +TEST_FILES=$(UNITY_FOLDER)/unity.c \ + list_test.c \ + list.c + +HEADER_FILES=*.h + +TEST = list_test + +CC=gcc + +SYMBOLS=-Wall -Werror -pedantic -O0 -ggdb -std=c99 +TEST_SYMBOLS=$(SYMBOLS) -DTEST + +.PHONY: clean test + +all: $(TEST) + +$(TEST): Makefile $(TEST_FILES) $(HEADER_FILES) + $(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(TEST) + +clean: + rm -f list $(TEST) + +test: $(TEST) + @valgrind ./$(TEST) diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/test/list_test.c b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/test/list_test.c new file mode 100644 index 0000000..704c7a7 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/ResourceDetector/test/list_test.c @@ -0,0 +1,300 @@ +#include /* for memcmp */ + +#include "list.h" +#include "unity.h" + +// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number +#define MY_RUN_TEST(func) RUN_TEST(func, 0) + +static list_admin* mylist = NULL; +typedef struct +{ + int i; + int j; +} test_struct; + +// compare function that returns 0 if test_struct.i matches, it ignores .j +static int compare_test_func(const void* p1, const void* p2, size_t size) +{ + size = size; // to prevent warnings + const test_struct* data1 = (const test_struct*)p1; + const test_struct* data2 = (const test_struct*)p2; + return data1->i - data2->i; +} +// check n items in list against verify_data +// IMPORTANT: this function must check using list_get_element, +// else the test for that function is no longer useful +static void check_n_list_elements_ok(list_admin* admin, int nr_items, const test_struct* verify_data) +{ + for(int i = 0; i < nr_items; i++) + { + test_struct* ptr = list_get_element(admin, i); + TEST_ASSERT_NOT_NULL(ptr); + TEST_ASSERT_EQUAL(0, memcmp(verify_data+i, ptr, sizeof(*ptr))); + } +} + + +void setUp(void) +{ + // This is run before EACH test + mylist = construct_list(sizeof(test_struct)); + TEST_ASSERT_NOT_NULL(mylist); +} + +void tearDown(void) +{ + // This is run after EACH test + destruct_list(&mylist); + TEST_ASSERT_NULL(mylist); +} + +static void test_ConstructList(void) +{ + TEST_ASSERT_NULL(mylist->head); + TEST_ASSERT_EQUAL(sizeof(test_struct), mylist->element_size); + TEST_ASSERT_EQUAL(0, mylist->nr_elements); +} + +static void test_NrElements_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_get_nr_elements(NULL)); +} + +static void test_AddData_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_add_tail(mylist, NULL)); + TEST_ASSERT_EQUAL(-1, list_add_tail(NULL, mylist)); +} + +static void test_AddData(void) +{ + test_struct data = {3, 4}; + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data)); + + TEST_ASSERT_NOT_NULL(mylist->head); + TEST_ASSERT_EQUAL(1, list_get_nr_elements(mylist)); + list_head* head = mylist->head; + test_struct* element = (test_struct*)(head+1); + TEST_ASSERT_EQUAL(data.i, element->i); + TEST_ASSERT_EQUAL(data.j, element->j); +} + +static void test_Add2PiecesOfData(void) +{ + test_struct data1 = {8, 9}; + test_struct data2 = {-3, -4}; + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data1)); + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data2)); + + TEST_ASSERT_NOT_NULL(mylist->head); + TEST_ASSERT_NOT_NULL(mylist->head->next); + TEST_ASSERT_EQUAL(2, list_get_nr_elements(mylist)); + list_head* head = mylist->head->next; + test_struct* element = (test_struct*)(head+1); + TEST_ASSERT_EQUAL(data2.i, element->i); + TEST_ASSERT_EQUAL(data2.j, element->j); +} + +static void test_GetElement_parameters(void) +{ + TEST_ASSERT_NULL(list_get_element(NULL, 0)); +} + +static void test_GetElement(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}}; + const int nr_elements = sizeof(data)/sizeof(data[0]); + + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + check_n_list_elements_ok(mylist, nr_elements, data); // checks using list_get_element + + TEST_ASSERT_NULL(list_get_element(mylist, nr_elements)); + TEST_ASSERT_NULL(list_get_element(mylist, -1)); +} + +static void test_GetLast_parameters(void) +{ + TEST_ASSERT_NULL(list_get_last(NULL)); +} + +static void test_GetLast(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}}; + const int nr_elements = sizeof(data)/sizeof(data[0]); + + TEST_ASSERT_NULL(list_get_last(mylist)); + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + test_struct* ptr = list_get_last(mylist); + TEST_ASSERT_NOT_NULL(ptr); + TEST_ASSERT_EQUAL(0, memcmp(&(data[i]), ptr, sizeof(*ptr))); + } +} + +static void test_IndexOf_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_index_of(mylist, NULL)); + TEST_ASSERT_EQUAL(-1, list_index_of(NULL, mylist)); +} + +static void test_IndexOf(void) +{ + const test_struct real_data[] = {{8, 9}, {-3, -4}, {21, 56}}; + const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]); + const test_struct false_data[] = {{-3, 9}, {8, 56}, {21, -4}, {0, 0}}; + const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]); + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(real_data[i]))); + } + + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(i, list_index_of(mylist, &(real_data[i]))); + } + for(int i = 0; i < nr_false_elements; i++) + { + TEST_ASSERT_EQUAL(-1, list_index_of(mylist, &(false_data[i]))); + } +} + +static void test_IndexOfSpecial_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, NULL, compare_test_func)); + TEST_ASSERT_EQUAL(-1, list_index_of_special(NULL, mylist, compare_test_func)); + TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, mylist, NULL)); +} + +static void test_IndexOfSpecial(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}}; // data in list + const test_struct real_data[] = {{8, -4}, {-3, 56}, {21, 9}}; // data to search for (i equals) + const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]); + const test_struct false_data[] = {{-2, 9}, {9, -4}, {22, 56}, {0, 0}}; // data that doesn't exist + const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]); + + // first make sure our compare function works + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(0, compare_test_func(&(data[i]), &(real_data[i]), 0)); + for (int j = 0; j < nr_false_elements; j++) + { + TEST_ASSERT_NOT_EQUAL(0, compare_test_func(&(data[i]), &(false_data[j]), 0)) + } + } + + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + for(int i = 0; i < nr_real_elements; i++) + { + TEST_ASSERT_EQUAL(i, list_index_of_special(mylist, &(real_data[i]), compare_test_func)); + } + for(int i = 0; i < nr_false_elements; i++) + { + TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, &(false_data[i]), compare_test_func)); + } +} + +static void test_DeleteItem_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_delete_item(NULL, 0)); + TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, -1)); +} + +static void test_DeleteItem(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; + int nr_elements = sizeof(data)/sizeof(data[0]); + const test_struct data_noFirst[] = {{-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; + const test_struct data_noLast[] = {{-3, -4}, {21, 56}, {0, 0}}; + const test_struct data_noMiddle[] = {{-3, -4}, {0, 0}}; + + TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, 0)); + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 0)); + nr_elements--; + TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); + + check_n_list_elements_ok(mylist, nr_elements, data_noFirst); + + TEST_ASSERT_EQUAL(0, list_delete_item(mylist, nr_elements-1)); + nr_elements--; + TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); + + check_n_list_elements_ok(mylist, nr_elements, data_noLast); + + TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 1)); + nr_elements--; + TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); + + check_n_list_elements_ok(mylist, nr_elements, data_noMiddle); +} + +static void test_DeleteLast_parameters(void) +{ + TEST_ASSERT_EQUAL(-1, list_delete_last(NULL)); +} + +static void test_DeleteLast(void) +{ + const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; + int nr_elements = sizeof(data)/sizeof(data[0]); + + TEST_ASSERT_EQUAL(-1, list_delete_last(mylist)); + for(int i = 0; i < nr_elements; i++) + { + TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); + } + + for (int i = nr_elements-1; i >= 0; i--) + { + TEST_ASSERT_EQUAL(0, list_delete_last(mylist)); + TEST_ASSERT_EQUAL(i, list_get_nr_elements(mylist)); + check_n_list_elements_ok(mylist, i, data); + } + + TEST_ASSERT_NULL(mylist->head); + TEST_ASSERT_EQUAL(0, list_get_nr_elements(mylist)); +} + +int main(void) +{ + UnityBegin(); + + MY_RUN_TEST(test_ConstructList); + MY_RUN_TEST(test_NrElements_parameters); + MY_RUN_TEST(test_AddData_parameters); + MY_RUN_TEST(test_AddData); + MY_RUN_TEST(test_Add2PiecesOfData); + MY_RUN_TEST(test_GetElement_parameters); + MY_RUN_TEST(test_GetElement); + MY_RUN_TEST(test_GetLast_parameters); + MY_RUN_TEST(test_GetLast); + MY_RUN_TEST(test_IndexOf_parameters); + MY_RUN_TEST(test_IndexOf); + MY_RUN_TEST(test_IndexOfSpecial_parameters); + MY_RUN_TEST(test_IndexOfSpecial); + MY_RUN_TEST(test_DeleteItem_parameters); + MY_RUN_TEST(test_DeleteItem); + MY_RUN_TEST(test_DeleteLast_parameters); + MY_RUN_TEST(test_DeleteLast); + // MY_RUN_TEST(); + // MY_RUN_TEST(); + // MY_RUN_TEST(); + // MY_RUN_TEST(); + + return UnityEnd(); +} diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity.c b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity.c new file mode 100644 index 0000000..7b10aa6 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity.c @@ -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 +#include + +#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; +} diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity.h b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity.h new file mode 100644 index 0000000..8b16111 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity.h @@ -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 diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity_internals.h b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity_internals.h new file mode 100644 index 0000000..b0d0637 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity_internals.h @@ -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 +#include + +//------------------------------------------------------- +// 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 diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity_test_module.c b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity_test_module.c new file mode 100644 index 0000000..ba18f7f --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity_test_module.c @@ -0,0 +1,97 @@ +#include "unity_test_module.h" +#include +#include +#include +#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(); +} diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity_test_module.h b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity_test_module.h new file mode 100644 index 0000000..c16ec8d --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/Unity/unity_test_module.h @@ -0,0 +1,31 @@ +#ifndef UNITY_TEST_MODULE_H +#define UNITY_TEST_MODULE_H + +#include + +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 diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/build/.gitkeep b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/challengelevel.json b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/challengelevel.json new file mode 100644 index 0000000..e956d94 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/challengelevel.json @@ -0,0 +1,6 @@ +{ + "challenge":{ + "level":["knows"] , + "durationHours": 4 + } +} diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/product/main.c b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/product/main.c new file mode 100644 index 0000000..c0643f0 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/product/main.c @@ -0,0 +1,22 @@ +#include +#include "calculations.h" + +int main() +{ + // from her your program starts + int variableWithAName = 14; + int variableWithAnotherName = 12; + + int result = swap(&variableWithAName, &variableWithAnotherName); + + if (result==0) + { + printf("succeeded\n"); + } + else + { + printf("failed, the implementation is empty\n"); + } + + return (0); +} diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/shared/calculations.c b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/shared/calculations.c new file mode 100644 index 0000000..615b128 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/shared/calculations.c @@ -0,0 +1,15 @@ +#include "calculations.h" +#include + +int swap(int* getal1, int* getal2) +{ + if(getal1 == NULL || getal2==NULL) + { + return -1; + } + + //TODO insert code here + + return -1; + +} \ No newline at end of file diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/shared/calculations.h b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/shared/calculations.h new file mode 100644 index 0000000..1f35ab6 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/shared/calculations.h @@ -0,0 +1,16 @@ +#ifndef CALCULATIONS_H +#define CALCULATIONS_H + +#include + +// return +// 0 : swap gelukt +//-1 : fout opgtreden + +int swap(int* getal1, int* getal2); + +// 0 : GELUKT +// -1 : er is iets mis gegaan +int sort (int array[]); + +#endif \ No newline at end of file diff --git a/C/t-oer-prc2-cbdb-main/development-setup/startingProject/test/calculations_test.c b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/test/calculations_test.c new file mode 100644 index 0000000..4401400 --- /dev/null +++ b/C/t-oer-prc2-cbdb-main/development-setup/startingProject/test/calculations_test.c @@ -0,0 +1,76 @@ +/* + * auteur : Freddy Hurkmans + * datum : November 15th 2015 + * code : C99 + */ + + +#include "calculations.h" +#include "unity.h" + +// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number +#define MY_RUN_TEST(func) RUN_TEST(func, 0) + +void setUp(void) +{ + // This is run before EACH test +} + +void tearDown(void) +{ + // This is run after EACH test +} + +void test_to_see_if_our_compiler_can_add_2_integers(void) +{ + int result = 2; + TEST_ASSERT_EQUAL(result, 1+1); +} + + + +void testswap() +{ + int getal1 =15; + int getal2 = 20; + int *getalptr = NULL; + getalptr = &getal1; + + int result = swap(getalptr,&getal2); + TEST_ASSERT_EQUAL(0,result); + TEST_ASSERT_EQUAL(20,getal1); + TEST_ASSERT_EQUAL(15,getal2); + + getal1 =0; + getal2 = 0; + result = swap(&getal1,&getal2); + TEST_ASSERT_EQUAL(0,result); + TEST_ASSERT_EQUAL(0,getal1); + TEST_ASSERT_EQUAL(0,getal2); + + +} + +void testswapptrnull() +{ + int getal1 =15; + int getal2 = 20; + int result = swap(&getal1,NULL); + TEST_ASSERT_EQUAL(-1,result); + result = swap(NULL,&getal2); + TEST_ASSERT_EQUAL(-1,result); + +} + + +int main (int argc, char * argv[]) +{ + UnityBegin(); + + MY_RUN_TEST(test_to_see_if_our_compiler_can_add_2_integers); + + MY_RUN_TEST(testswap); + MY_RUN_TEST (testswapptrnull); + + return UnityEnd(); +} diff --git a/CS/ContainerApp - Gijs van Maanen.zip b/CS/ContainerApp - Gijs van Maanen.zip new file mode 100644 index 0000000..c661a4a Binary files /dev/null and b/CS/ContainerApp - Gijs van Maanen.zip differ diff --git a/CS/Starter_assignment.zip b/CS/Starter_assignment.zip new file mode 100644 index 0000000..26a1eca Binary files /dev/null and b/CS/Starter_assignment.zip differ diff --git a/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/.gitignore b/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/.gitignore new file mode 100644 index 0000000..3c841d4 --- /dev/null +++ b/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/.gitignore @@ -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 diff --git a/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/encodings.xml b/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/indexLayout.xml b/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/CS/Starter_assignment/.idea/.idea.Starter_assignment/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CS/Starter_assignment/Archive.zip b/CS/Starter_assignment/Archive.zip new file mode 100644 index 0000000..e7347c5 Binary files /dev/null and b/CS/Starter_assignment/Archive.zip differ diff --git a/CS/Starter_assignment/Course.cs b/CS/Starter_assignment/Course.cs new file mode 100644 index 0000000..9ac8887 --- /dev/null +++ b/CS/Starter_assignment/Course.cs @@ -0,0 +1,74 @@ +namespace Starter_assignment; + +class Course { + private List students = new List(); + private Dictionary> groups = new Dictionary>(); + 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(); + 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> 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}"); + } +} \ No newline at end of file diff --git a/CS/Starter_assignment/Program.cs b/CS/Starter_assignment/Program.cs new file mode 100644 index 0000000..ae39d83 --- /dev/null +++ b/CS/Starter_assignment/Program.cs @@ -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; + } + } + } +} + diff --git a/CS/Starter_assignment/Starter_assignment.csproj b/CS/Starter_assignment/Starter_assignment.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/CS/Starter_assignment/Starter_assignment.dll b/CS/Starter_assignment/Starter_assignment.dll new file mode 100644 index 0000000..8ce0e2f Binary files /dev/null and b/CS/Starter_assignment/Starter_assignment.dll differ diff --git a/CS/Starter_assignment/Starter_assignment.sln b/CS/Starter_assignment/Starter_assignment.sln new file mode 100644 index 0000000..b71be33 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment.sln @@ -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 diff --git a/CS/Starter_assignment/Starter_assignment.sln.DotSettings.user b/CS/Starter_assignment/Starter_assignment.sln.DotSettings.user new file mode 100644 index 0000000..ccb66a8 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment.sln.DotSettings.user @@ -0,0 +1,4 @@ + + ForceIncluded + ForceIncluded + ERROR \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/Course.cs b/CS/Starter_assignment/Starter_assignment/Course.cs new file mode 100644 index 0000000..98a7504 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/Course.cs @@ -0,0 +1,73 @@ +namespace Starter_assignment; + +class Course { + private List students = new List(); + private Dictionary> groups = new Dictionary>(); + 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(); + 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> 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}"); + } +} \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/Program.cs b/CS/Starter_assignment/Starter_assignment/Program.cs new file mode 100644 index 0000000..ae39d83 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/Program.cs @@ -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; + } + } + } +} + diff --git a/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj b/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/CS/Starter_assignment/Starter_assignment/Student.cs b/CS/Starter_assignment/Starter_assignment/Student.cs new file mode 100644 index 0000000..618fa3c --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/Student.cs @@ -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}"; + } +} diff --git a/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment b/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment new file mode 100755 index 0000000..7364e5e Binary files /dev/null and b/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment differ diff --git a/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.deps.json b/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.deps.json new file mode 100644 index 0000000..c20d914 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.deps.json @@ -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": "" + } + } +} \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.dll b/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.dll new file mode 100644 index 0000000..5066089 Binary files /dev/null and b/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.dll differ diff --git a/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.pdb b/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.pdb new file mode 100644 index 0000000..e3dc1d9 Binary files /dev/null and b/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.pdb differ diff --git a/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.runtimeconfig.json b/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.runtimeconfig.json new file mode 100644 index 0000000..becfaea --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/bin/Debug/net8.0/Starter_assignment.runtimeconfig.json @@ -0,0 +1,12 @@ +{ + "runtimeOptions": { + "tfm": "net8.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "8.0.0" + }, + "configProperties": { + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false + } + } +} \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs new file mode 100644 index 0000000..dca70aa --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")] diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfo.cs b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfo.cs new file mode 100644 index 0000000..5b35b66 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfo.cs @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +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. + diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfoInputs.cache b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfoInputs.cache new file mode 100644 index 0000000..2b7cd31 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +77da79aa1d8b67801697281643b61dd3f4e48c0c7f245ecd395dee391118be92 diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GeneratedMSBuildEditorConfig.editorconfig b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..10df626 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GeneratedMSBuildEditorConfig.editorconfig @@ -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 = diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GlobalUsings.g.cs b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GlobalUsings.g.cs new file mode 100644 index 0000000..8578f3d --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.GlobalUsings.g.cs @@ -0,0 +1,8 @@ +// +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; diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.assets.cache b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.assets.cache new file mode 100644 index 0000000..eea52c3 Binary files /dev/null and b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.assets.cache differ diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.CoreCompileInputs.cache b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..ee2f4d4 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +63f646a6f5c36f8a67f54301cd756f80709a6758f27e90e85bd3caa85964b27d diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.FileListAbsolute.txt b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..8703dff --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.csproj.FileListAbsolute.txt @@ -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 diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.dll b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.dll new file mode 100644 index 0000000..5066089 Binary files /dev/null and b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.dll differ diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.genruntimeconfig.cache b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.genruntimeconfig.cache new file mode 100644 index 0000000..39e2157 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.genruntimeconfig.cache @@ -0,0 +1 @@ +4028af397b722be4e5490a9f64106d4a5c363b00c8703dae917b145b5632baa4 diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.pdb b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.pdb new file mode 100644 index 0000000..e3dc1d9 Binary files /dev/null and b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/Starter_assignment.pdb differ diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/apphost b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/apphost new file mode 100755 index 0000000..7364e5e Binary files /dev/null and b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/apphost differ diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/ref/Starter_assignment.dll b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/ref/Starter_assignment.dll new file mode 100644 index 0000000..dd1190c Binary files /dev/null and b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/ref/Starter_assignment.dll differ diff --git a/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/refint/Starter_assignment.dll b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/refint/Starter_assignment.dll new file mode 100644 index 0000000..dd1190c Binary files /dev/null and b/CS/Starter_assignment/Starter_assignment/obj/Debug/net8.0/refint/Starter_assignment.dll differ diff --git a/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.dgspec.json b/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.dgspec.json new file mode 100644 index 0000000..fc9be79 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.dgspec.json @@ -0,0 +1,66 @@ +{ + "format": 1, + "restore": { + "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj": {} + }, + "projects": { + "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj", + "projectName": "Starter_assignment", + "projectPath": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj", + "packagesPath": "/home/rens/.nuget/packages/", + "outputPath": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/", + "projectStyle": "PackageReference", + "configFilePaths": [ + "/home/rens/.nuget/NuGet/NuGet.Config" + ], + "originalTargetFrameworks": [ + "net8.0" + ], + "sources": { + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + }, + "restoreAuditProperties": { + "enableAudit": "true", + "auditLevel": "low", + "auditMode": "direct" + } + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "/home/rens/.dotnet/sdk/8.0.404/PortableRuntimeIdentifierGraph.json" + } + } + } + } +} \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.props b/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.props new file mode 100644 index 0000000..1ee7f5f --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.props @@ -0,0 +1,15 @@ + + + + True + NuGet + $(MSBuildThisFileDirectory)project.assets.json + /home/rens/.nuget/packages/ + /home/rens/.nuget/packages/ + PackageReference + 6.12.2 + + + + + \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.targets b/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.targets new file mode 100644 index 0000000..3dc06ef --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/Starter_assignment.csproj.nuget.g.targets @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/obj/project.assets.json b/CS/Starter_assignment/Starter_assignment/obj/project.assets.json new file mode 100644 index 0000000..3edcb61 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/project.assets.json @@ -0,0 +1,71 @@ +{ + "version": 3, + "targets": { + "net8.0": {} + }, + "libraries": {}, + "projectFileDependencyGroups": { + "net8.0": [] + }, + "packageFolders": { + "/home/rens/.nuget/packages/": {} + }, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj", + "projectName": "Starter_assignment", + "projectPath": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj", + "packagesPath": "/home/rens/.nuget/packages/", + "outputPath": "/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/", + "projectStyle": "PackageReference", + "configFilePaths": [ + "/home/rens/.nuget/NuGet/NuGet.Config" + ], + "originalTargetFrameworks": [ + "net8.0" + ], + "sources": { + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + }, + "restoreAuditProperties": { + "enableAudit": "true", + "auditLevel": "low", + "auditMode": "direct" + } + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "/home/rens/.dotnet/sdk/8.0.404/PortableRuntimeIdentifierGraph.json" + } + } + } +} \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/obj/project.nuget.cache b/CS/Starter_assignment/Starter_assignment/obj/project.nuget.cache new file mode 100644 index 0000000..65b5e2d --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/project.nuget.cache @@ -0,0 +1,8 @@ +{ + "version": 2, + "dgSpecHash": "0d5jt8ngUw0=", + "success": true, + "projectFilePath": "/home/rens/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj", + "expectedPackageFiles": [], + "logs": [] +} \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/obj/project.packagespec.json b/CS/Starter_assignment/Starter_assignment/obj/project.packagespec.json new file mode 100644 index 0000000..deb1fd1 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/project.packagespec.json @@ -0,0 +1 @@ +"restore":{"projectUniqueName":"/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj","projectName":"Starter_assignment","projectPath":"/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/Starter_assignment.csproj","outputPath":"/home/rens/files/T2/CS/Starter_assignment/Starter_assignment/obj/","projectStyle":"PackageReference","originalTargetFrameworks":["net8.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net8.0":{"targetAlias":"net8.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]},"restoreAuditProperties":{"enableAudit":"true","auditLevel":"low","auditMode":"direct"}}"frameworks":{"net8.0":{"targetAlias":"net8.0","imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"/home/rens/.dotnet/sdk/8.0.404/PortableRuntimeIdentifierGraph.json"}} \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/obj/rider.project.model.nuget.info b/CS/Starter_assignment/Starter_assignment/obj/rider.project.model.nuget.info new file mode 100644 index 0000000..a86fdb3 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/rider.project.model.nuget.info @@ -0,0 +1 @@ +17406469005085962 \ No newline at end of file diff --git a/CS/Starter_assignment/Starter_assignment/obj/rider.project.restore.info b/CS/Starter_assignment/Starter_assignment/obj/rider.project.restore.info new file mode 100644 index 0000000..a86fdb3 --- /dev/null +++ b/CS/Starter_assignment/Starter_assignment/obj/rider.project.restore.info @@ -0,0 +1 @@ +17406469005085962 \ No newline at end of file diff --git a/CS/Starter_assignment/Student.cs b/CS/Starter_assignment/Student.cs new file mode 100644 index 0000000..618fa3c --- /dev/null +++ b/CS/Starter_assignment/Student.cs @@ -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}"; + } +} diff --git a/CS/Starter_assignment/starter_assignment b/CS/Starter_assignment/starter_assignment new file mode 100755 index 0000000..7364e5e Binary files /dev/null and b/CS/Starter_assignment/starter_assignment differ diff --git a/ES/PlatformIO/Projects/ES state machine.zip b/ES/PlatformIO/Projects/ES state machine.zip new file mode 100644 index 0000000..b4001d4 Binary files /dev/null and b/ES/PlatformIO/Projects/ES state machine.zip differ diff --git a/ES/PlatformIO/Projects/ES state machine/.gitignore b/ES/PlatformIO/Projects/ES state machine/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/ES/PlatformIO/Projects/ES state machine/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/ES/PlatformIO/Projects/ES state machine/.vscode/extensions.json b/ES/PlatformIO/Projects/ES state machine/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/ES/PlatformIO/Projects/ES state machine/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/ES/PlatformIO/Projects/ES state machine/include/SerialProcess.h b/ES/PlatformIO/Projects/ES state machine/include/SerialProcess.h new file mode 100755 index 0000000..5bd6c56 --- /dev/null +++ b/ES/PlatformIO/Projects/ES state machine/include/SerialProcess.h @@ -0,0 +1,39 @@ +#include +#ifndef SERIALPROCESS_H +#define SERIALPROCESS_H + +class SerialProcess { +private: + uint8_t ndx; // Current index for the buffer + const char beginMarker = '#'; // Marker to indicate the start of a message + const char endMarker = ';'; // Marker to indicate the end of a message + char rc; // Character read from Serial + int address; // Device address + bool newData; // Flag for new data availability + static const uint8_t numChars = 255; // Maximum size of the buffer + char receivedChars[numChars]; // Buffer for incoming data + bool rcCheck; + +public: + // Constructor + explicit SerialProcess(int addr); + + // Store Serial Input (if available) + void SerialInput(); + + // Check if new data is available + bool isNewDataAvailable(); + + // Get the received data + char* getReceivedData(); + + // Process the received message + void getPayload(char* payload); + + // Send message in the correct format + void sendMessage(int receiver, const char* payload); + + void changeAddress(int addr); +}; + +#endif // SERIALPROCESS_H diff --git a/ES/PlatformIO/Projects/ES state machine/lib/README b/ES/PlatformIO/Projects/ES state machine/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/ES/PlatformIO/Projects/ES state machine/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/ES/PlatformIO/Projects/ES state machine/platformio.ini b/ES/PlatformIO/Projects/ES state machine/platformio.ini new file mode 100644 index 0000000..dbb4289 --- /dev/null +++ b/ES/PlatformIO/Projects/ES state machine/platformio.ini @@ -0,0 +1,16 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32dev] +platform = espressif32 +board = esp32dev +framework = arduino +monitor_speed = 115200 +lib_deps = plerup/EspSoftwareSerial@^8.2.0 diff --git a/ES/PlatformIO/Projects/ES state machine/src/SerialProcess.cpp b/ES/PlatformIO/Projects/ES state machine/src/SerialProcess.cpp new file mode 100755 index 0000000..e6b6fc6 --- /dev/null +++ b/ES/PlatformIO/Projects/ES state machine/src/SerialProcess.cpp @@ -0,0 +1,74 @@ +#include "SerialProcess.h" +#include + +// Constructor +SerialProcess::SerialProcess(int addr) + : address(addr), ndx(0), rc(0), newData(false), rcCheck(false) { + Serial.begin(115200); +} + +// Processes Serial Input +void SerialProcess::SerialInput() { + while (Serial.available() > 0) { + rc = static_cast(Serial.read()); + + if (rc == beginMarker) { + rcCheck = true; // Start reading after the begin marker + ndx = 0; // Reset index for new message + } + + if (rcCheck) { + // Store the character if within bounds + if (ndx < numChars - 1) { + receivedChars[ndx++] = rc; + } + + // Check for end marker + if (rc == endMarker) { + receivedChars[ndx] = '\0'; // Null-terminate the string + newData = true; // Mark new data as available + rcCheck = false; // Stop reading until the next begin marker + } + } + } +} + +// Check if new data is available +bool SerialProcess::isNewDataAvailable() { + return newData; +} + +// Get the received data +char* SerialProcess::getReceivedData() { + if (newData) { + newData = false; // Reset the flag after accessing the data + return receivedChars; + } + return nullptr; // No new data +} + +// Process the received message +void SerialProcess::getPayload(char *payload) { + if (newData) { + uint8_t source; + uint8_t destination; + char data[255]; // Allocate a buffer for the data + int parsed = sscanf(receivedChars, "#%hhu:%hhu:%63s;", &source, &destination, data); + if (parsed == 3 && destination == address) { // Ensure all fields are parsed correctly + strcpy(payload, data); // Copy data to the provided buffer + newData = false; // Mark the data as processed + } else if (address != source) { + Serial.print(receivedChars); // Forward the message + } + } +} + +// Send a message in the correct format +void SerialProcess::sendMessage(int receiver, const char* payload) { + Serial.printf("#%u:%u:%s;", address, receiver, payload); +} + + +void SerialProcess::changeAddress(int addr) { + address = addr; // Update the device address +} \ No newline at end of file diff --git a/ES/PlatformIO/Projects/ES state machine/src/main.cpp b/ES/PlatformIO/Projects/ES state machine/src/main.cpp new file mode 100755 index 0000000..7fbdcae --- /dev/null +++ b/ES/PlatformIO/Projects/ES state machine/src/main.cpp @@ -0,0 +1,238 @@ +#include +#include "SerialProcess.h" + +#define LEDRED 14 +#define LEDORANGE 13 +#define LEDGREEN 12 + +unsigned long previousMillis = 0; +const unsigned long greenDuration = 5000; +const unsigned long yellowDuration = 2000; +const unsigned long redDuration = 5000; +const unsigned long transitionDuration = 2000; +const unsigned long heartbeatInterval = 1000; +const unsigned long heartbeatTimeout = 3000; +const unsigned long blinkInterval = 500; +unsigned long lastHeartbeatMillis = 0; +unsigned long lastBlinkMillis = 0; +bool blinkState = false; + +enum State { GREEN, YELLOW, RED, TRANSITION, ERROR }; +State currentState = GREEN; + +const char *slavecheck = "#slvchck;"; +const char *slaveack = "#slvack;"; +const char *masterack = "#mstack;"; + +const char *turnRed = "tr"; +const char *turnOrange = "to"; +const char *turnGreen = "tg"; +const char *heartbeat = "hb"; + +int node; // other bord addres number +int address = 0; // Device address + +void setRed(){ + digitalWrite(LEDRED, HIGH); + digitalWrite(LEDORANGE, LOW); + digitalWrite(LEDGREEN, LOW); +} +void setOrange(){ + digitalWrite(LEDRED, LOW); + digitalWrite(LEDORANGE, HIGH); + digitalWrite(LEDGREEN, LOW); +} +void setGreen(){ + digitalWrite(LEDRED, LOW); + digitalWrite(LEDORANGE, LOW); + digitalWrite(LEDGREEN, HIGH); +} + +SerialProcess serialcom(0); + +bool MasterCheck() { + SerialProcess serialcomchecker(1000); + const unsigned long timeout = 2000; + unsigned long startTime = millis(); + bool isMaster = true; + bool checkSent = false; + bool gotResponse = false; + + delay(random(100, 600)); // Randomize startup slightly + + Serial.print(slavecheck); // Send check to see if someone replies + checkSent = true; + + while (millis() - startTime < timeout) { + if (Serial.available()) { + serialcomchecker.SerialInput(); + char* payload = serialcomchecker.getReceivedData(); + + if (strcmp(payload, slavecheck) == 0) { + // Got a check while we also sent a check — respond and become SLAVE + Serial.print(slaveack); + isMaster = false; + break; + } else if (strcmp(payload, slaveack) == 0) { + // Got an ACK from the other side — we are master + Serial.print(masterack); + isMaster = true; + break; + } else if (strcmp(payload, masterack) == 0) { + // Got master ack — we must be slave + isMaster = false; + break; + } + } + } + + // Failsafe: no response at all + if (!Serial.available() && !gotResponse) { + // Assume we are master + isMaster = true; + Serial.print(masterack); + } + + return isMaster; +} + + +void updateLights() { + switch (currentState) { + case GREEN: + setGreen(); + serialcom.sendMessage(node, turnGreen); + break; + case YELLOW: + setOrange(); + serialcom.sendMessage(node, turnOrange); + break; + case RED: + setGreen(); + serialcom.sendMessage(node, turnRed); + break; + case TRANSITION: + serialcom.sendMessage(node, turnOrange); + break; + case ERROR: + if (millis() - lastBlinkMillis >= blinkInterval) { + blinkState = !blinkState; + digitalWrite(LEDORANGE, blinkState ? HIGH : LOW); + lastBlinkMillis = millis(); + } + break; + } +} + +void sendHeartbeat() { + serialcom.sendMessage(node,heartbeat); + Serial.println("Sent: Heartbeat"); +} + +void master(){ + bool running = true; + while (running){ + unsigned long currentMillis = millis(); + + if (currentMillis - lastHeartbeatMillis >= heartbeatInterval) { + sendHeartbeat(); + lastHeartbeatMillis = currentMillis; + } + + if (currentMillis - lastHeartbeatMillis > heartbeatTimeout) { + currentState = ERROR; + updateLights(); + return; + } + + switch (currentState) { + case GREEN: + if (currentMillis - previousMillis >= greenDuration) { + currentState = YELLOW; + previousMillis = currentMillis; + updateLights(); + } + break; + case YELLOW: + if (currentMillis - previousMillis >= yellowDuration) { + currentState = RED; + previousMillis = currentMillis; + updateLights(); + } + break; + case RED: + if (currentMillis - previousMillis >= redDuration) { + currentState = TRANSITION; + previousMillis = currentMillis; + updateLights(); + } + break; + case TRANSITION: + if (currentMillis - previousMillis >= transitionDuration) { + currentState = GREEN; + previousMillis = millis(); + updateLights(); + } + break; + case ERROR: + updateLights(); + break; + } + } +} + +void setup() { + Serial.begin(115200); + pinMode(LEDGREEN, OUTPUT); + pinMode(LEDORANGE, OUTPUT); + pinMode(LEDRED, OUTPUT); + bool MorS = MasterCheck(); // Check if master or slave + //set address for master or slave + if (MorS == false){ + address = 2; // Set address for this slave + node = 1; // Set address for master + } else { + address = 1; // Set address for this master + node = 2; // Set address for slave + } + previousMillis = millis(); + lastHeartbeatMillis = millis(); + updateLights(); + setRed(); + serialcom.changeAddress(address); // Set address for serial communication +} + +void slave(){ + bool running = true; + char *command; + while (running && Serial.available() > 0){ + serialcom.SerialInput(); + serialcom.getPayload(command); + if (strcmp(command, turnRed)) setRed(); + else if (strcmp(command, turnOrange)) setOrange(); + else if (strcmp(command, turnGreen)) setGreen(); + else if (strcmp(command, heartbeat)) { + lastHeartbeatMillis = millis(); + digitalWrite(LEDRED, LOW); // Reset the orange blink pattern + digitalWrite(LEDORANGE, LOW); + } + else { + Serial.print("slave: unknown command"); + } + } + if (millis() - lastHeartbeatMillis > heartbeatTimeout) { + // Blink the red and yellow LEDs to indicate an error (orange light) + if (millis() - lastBlinkMillis >= blinkInterval) { + blinkState = !blinkState; + digitalWrite(LEDORANGE, blinkState ? HIGH : LOW); + lastBlinkMillis = millis(); + } + } +} + +void loop(){ + serialcom.changeAddress(2); + if (address == 1) slave(); //master + else if (address == 2) slave(); //slave + else Serial.print("master slave issue"); +} diff --git a/ES/PlatformIO/Projects/ES state machine/test/README b/ES/PlatformIO/Projects/ES state machine/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/ES/PlatformIO/Projects/ES state machine/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/ES/PlatformIO/Projects/ES2_1_C/.gitignore b/ES/PlatformIO/Projects/ES2_1_C/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/ES/PlatformIO/Projects/ES2_1_C/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/ES/PlatformIO/Projects/ES2_1_C/.vscode/extensions.json b/ES/PlatformIO/Projects/ES2_1_C/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/ES/PlatformIO/Projects/ES2_1_C/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/ES/PlatformIO/Projects/ES2_1_C/include/README b/ES/PlatformIO/Projects/ES2_1_C/include/README new file mode 100644 index 0000000..49819c0 --- /dev/null +++ b/ES/PlatformIO/Projects/ES2_1_C/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/ES/PlatformIO/Projects/ES2_1_C/lib/README b/ES/PlatformIO/Projects/ES2_1_C/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/ES/PlatformIO/Projects/ES2_1_C/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/ES/PlatformIO/Projects/ES2_1_C/platformio.ini b/ES/PlatformIO/Projects/ES2_1_C/platformio.ini new file mode 100644 index 0000000..ea23b77 --- /dev/null +++ b/ES/PlatformIO/Projects/ES2_1_C/platformio.ini @@ -0,0 +1,14 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:uno] +platform = atmelavr +board = uno +framework = arduino diff --git a/ES/PlatformIO/Projects/ES2_1_C/src/main.cpp b/ES/PlatformIO/Projects/ES2_1_C/src/main.cpp new file mode 100644 index 0000000..b0d7c6a --- /dev/null +++ b/ES/PlatformIO/Projects/ES2_1_C/src/main.cpp @@ -0,0 +1,14 @@ +#include + +int analogValue; +int readPin = 23; +void setup() { + Serial.begin(115200); + pinMode(readPin,INPUT); +} + +void loop() { + analogValue = analogRead(readPin); + Serial.print(analogValue); +} + diff --git a/ES/PlatformIO/Projects/ES2_1_C/test/README b/ES/PlatformIO/Projects/ES2_1_C/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/ES/PlatformIO/Projects/ES2_1_C/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/ES/PlatformIO/Projects/esp32test/.gitignore b/ES/PlatformIO/Projects/esp32test/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/ES/PlatformIO/Projects/esp32test/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/ES/PlatformIO/Projects/esp32test/.vscode/extensions.json b/ES/PlatformIO/Projects/esp32test/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/ES/PlatformIO/Projects/esp32test/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/ES/PlatformIO/Projects/esp32test/include/README b/ES/PlatformIO/Projects/esp32test/include/README new file mode 100644 index 0000000..49819c0 --- /dev/null +++ b/ES/PlatformIO/Projects/esp32test/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/ES/PlatformIO/Projects/esp32test/lib/README b/ES/PlatformIO/Projects/esp32test/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/ES/PlatformIO/Projects/esp32test/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/ES/PlatformIO/Projects/esp32test/platformio.ini b/ES/PlatformIO/Projects/esp32test/platformio.ini new file mode 100644 index 0000000..8dd1b2d --- /dev/null +++ b/ES/PlatformIO/Projects/esp32test/platformio.ini @@ -0,0 +1,15 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32dev] +platform = espressif32 +board = esp32dev +framework = arduino +monitor_speed = 115200 \ No newline at end of file diff --git a/ES/PlatformIO/Projects/esp32test/src/main.cpp b/ES/PlatformIO/Projects/esp32test/src/main.cpp new file mode 100644 index 0000000..91eff1f --- /dev/null +++ b/ES/PlatformIO/Projects/esp32test/src/main.cpp @@ -0,0 +1,15 @@ +#include + +int analogValue; +int readPin = 32; +void setup() { + Serial.begin(115200); + analogReadResolution(10); + pinMode(readPin,INPUT); +} + +void loop() { + analogValue = analogRead(readPin); + Serial.println(840); +} + diff --git a/ES/PlatformIO/Projects/esp32test/test/README b/ES/PlatformIO/Projects/esp32test/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/ES/PlatformIO/Projects/esp32test/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/HC/a.out b/HC/a.out new file mode 100755 index 0000000..21204c2 Binary files /dev/null and b/HC/a.out differ diff --git a/HC/holyc-lang b/HC/holyc-lang new file mode 160000 index 0000000..fd2d410 --- /dev/null +++ b/HC/holyc-lang @@ -0,0 +1 @@ +Subproject commit fd2d4105fae24dc24137c70b293f0b4e32675a83 diff --git a/HC/main.HC b/HC/main.HC new file mode 100644 index 0000000..7a3924d --- /dev/null +++ b/HC/main.HC @@ -0,0 +1,25 @@ +class SomethingWithAnAge +{ + I64 age; +}; + +class Person : SomethingWithAnAge +{ + U8 name[1<<5]; +}; + +U0 ExampleFunction(U0) +{ + Person *p = MAlloc(sizeof(Person)); + + MemCpy(p->name,"Bob",3); + p->age = 0; + + while (p->age < 42) { + p->age++; + } + "name: %s, age: %d\n",p->name,p->age; + Free(p); +} + +ExampleFunction;