Browse Source

adding macro & function for runtime error generation;

adding mock implementation of runtime error functions for tests
master
T. Meissner 9 years ago
parent
commit
bd4fb69b58
4 changed files with 44 additions and 1 deletions
  1. +2
    -1
      tdd_for_embedded_c/chapter04/Makefile
  2. +33
    -0
      tdd_for_embedded_c/chapter04/mocks/RuntimeErrorStub.c
  3. +3
    -0
      tdd_for_embedded_c/chapter04/mocks/RuntimeErrorStub.h
  4. +6
    -0
      tdd_for_embedded_c/chapter04/util/RuntimeError.h

+ 2
- 1
tdd_for_embedded_c/chapter04/Makefile View File

@ -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=


+ 33
- 0
tdd_for_embedded_c/chapter04/mocks/RuntimeErrorStub.c View File

@ -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;
}

+ 3
- 0
tdd_for_embedded_c/chapter04/mocks/RuntimeErrorStub.h View File

@ -0,0 +1,3 @@
void RuntimeErrorStub_Reset(void);
const char *RuntimeErrorStub_GetLastError(void);
int RuntimeErrorStub_GetLastParameter(void);

+ 6
- 0
tdd_for_embedded_c/chapter04/util/RuntimeError.h View File

@ -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__)

Loading…
Cancel
Save