diff --git a/tdd_for_embedded_c/chapter04/Makefile b/tdd_for_embedded_c/chapter04/Makefile index 62e823d..e9c6c6b 100644 --- a/tdd_for_embedded_c/chapter04/Makefile +++ b/tdd_for_embedded_c/chapter04/Makefile @@ -48,7 +48,8 @@ SRC_FILES=\ ../test/LedDriverTest.c \ ../test/LedDriverTestRunner.c \ ../test/AllTests.c \ - ../src/LedDriver.c + ../src/LedDriver.c \ + ../mocks/RuntimeErrorStub.c INC_DIRS=-I$(UNITY_ROOT)/src -I$(UNITY_ROOT)/extras/fixture/src SYMBOLS= diff --git a/tdd_for_embedded_c/chapter04/mocks/RuntimeErrorStub.c b/tdd_for_embedded_c/chapter04/mocks/RuntimeErrorStub.c new file mode 100644 index 0000000..9562a4f --- /dev/null +++ b/tdd_for_embedded_c/chapter04/mocks/RuntimeErrorStub.c @@ -0,0 +1,33 @@ +#include "RuntimeErrorStub.h" +#include "../util/RuntimeError.h" + + +static const char *message = "No Error"; +static int parameter = -1; +static const char *file = 0; +static int line = -1; + + +void RuntimeErrorStub_Reset(void) { + message = "No Error"; + parameter = -1; +} + + +const char *RuntimeErrorStub_GetLastError(void) { + return message; +} + + +void RuntimeError(const char *m, int p, + const char *f, int l) { + message = m; + parameter = p; + file = f; + line = l; +} + + +int RuntimeErrorStub_GetLastParameter(void) { + return parameter; +} diff --git a/tdd_for_embedded_c/chapter04/mocks/RuntimeErrorStub.h b/tdd_for_embedded_c/chapter04/mocks/RuntimeErrorStub.h new file mode 100644 index 0000000..d2756ea --- /dev/null +++ b/tdd_for_embedded_c/chapter04/mocks/RuntimeErrorStub.h @@ -0,0 +1,3 @@ +void RuntimeErrorStub_Reset(void); +const char *RuntimeErrorStub_GetLastError(void); +int RuntimeErrorStub_GetLastParameter(void); diff --git a/tdd_for_embedded_c/chapter04/util/RuntimeError.h b/tdd_for_embedded_c/chapter04/util/RuntimeError.h new file mode 100644 index 0000000..8970f37 --- /dev/null +++ b/tdd_for_embedded_c/chapter04/util/RuntimeError.h @@ -0,0 +1,6 @@ +void RuntimeError(const char *m, int p, + const char *f, int l); + + +#define RUNTIME_ERROR(description, parameter) \ + RuntimeError(description, parameter, __FILE__, __LINE__) \ No newline at end of file