From 2d888a2a94645c86fd3c5aec52612d5d8b6321fe Mon Sep 17 00:00:00 2001 From: Etienne Brateau <etienne.brateau@ensiie.fr> Date: Thu, 28 Feb 2019 11:57:41 +0100 Subject: [PATCH] First unit test using criterion --- .gitignore | 1 + Makefile | 10 ++++++++++ test/strings.c | 10 ++++++++++ 3 files changed, 21 insertions(+) create mode 100644 test/strings.c diff --git a/.gitignore b/.gitignore index c9d14b4..fb7938d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ lib/untilstuff.ps build/ docs/html docs/latex +test/test diff --git a/Makefile b/Makefile index ffe1132..6f2cf71 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ LOGINC = include TARGET_DIR = target SRC_DIR = src TOOLS_DIR = tools +TEST_DIR = test LOGLIBDIR = `$(CD) lib; pwd` LIBDIR = `$(CD) lib; pwd` @@ -50,6 +51,8 @@ STDC = gnu11 CFLAGS = $(CHIPMUNKFLAGS) -I$(LOGINC) -I$(XINCLUDEDIR) \ -DLOGLIB="\"$(LOGLIBDIR)\"" -DF_OK=0 -std=$(STDC) -DCHIPLIB=$(LIBDIR) -g -Wall -Wextra +TESTLIB = -lcriterion + ## (3) Choosing default fonts ## -------------------------- ## @@ -123,6 +126,8 @@ TOOLOBJ = $(SIMOBJ) \ $(TARGET_DIR)/pen.o $(TARGET_DIR)/libraryreader.o \ $(TARGET_DIR)/display.o +TESTOBJ = $(TEST_DIR)/strings.c + $(TARGET_DIR)/ana/%.o: $(SRC_DIR)/ana/%.c $(TARGET_DIR)/graphics/%.o: $(SRC_DIR)/graphics/%.c @@ -149,6 +154,8 @@ setup: main: $(TARGET_DIR)/log $(TARGET_DIR)/loged +test: $(TEST_DIR)/test + LOGOBJ = $(TARGET_DIR)/log.o $(TOOLOBJ) $(TARGET_DIR)/tooldir.o $(TARGET_DIR)/logdef.o $(TARGET_DIR)/logstuff.o LOGEDOBJ = $(TARGET_DIR)/loged.o $(TARGET_DIR)/simdir.o $(SIMOBJ) $(TARGET_DIR)/logstuff.o @@ -166,6 +173,9 @@ $(TARGET_DIR)/log: $(LOGOBJ) $(GRAPHICSOBJ) $(UTILSOBJ) $(TARGET_DIR)/loged: $(LOGEDOBJ) $(GRAPHICSOBJ) $(UTILSOBJ) $(CC) $(CFLAGS) $^ $(LIBX11) $(OTHERLIBS) -o $@ +$(TEST_DIR)/test: $(UTILSOBJ) $(TESTOBJ) + $(CC) $(CFLAGS) $(TESTLIB) $^ -o $@ + docs: doxygen Doxyfile diff --git a/test/strings.c b/test/strings.c new file mode 100644 index 0000000..111b0e0 --- /dev/null +++ b/test/strings.c @@ -0,0 +1,10 @@ +#include <utils/strings.h> +#include <criterion/criterion.h> + +Test(strings, strreverse) { + char *test = malloc(sizeof(char) * 5); + strcpy(test, "test"); + test = strreverse(test, test); + cr_expect(strcmp(test, "tset") == 0, "simple test of reverse"); + free(test); +} -- GitLab