From 65eb4d6ce2b0fcaf57b63411806db567731bc44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Wed, 10 Apr 2019 11:48:04 +0200 Subject: [PATCH] added an x86 test for the ringbuffer --- test/Makefile | 18 ++++++++++++++++++ test/test_ringbuffer.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/Makefile create mode 100644 test/test_ringbuffer.c diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..9718598 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,18 @@ +CC=gcc +CFLAG= -g -O + +tests= test_ringbuffer.test +objects= ../ringbuffer.o + +all: clean $(tests) + +clean: + -rm $(objects) + -rm $(tests) + +%.test: %.c $(objects) + $(CC) $(CFLAG) $(objects) -o $@ $< + ./$@ + +%.o: %.c + $(CC) $(CFLAG) -c -o $@ $< diff --git a/test/test_ringbuffer.c b/test/test_ringbuffer.c new file mode 100644 index 0000000..84316f3 --- /dev/null +++ b/test/test_ringbuffer.c @@ -0,0 +1,33 @@ +#include +#include + +#include "../ringbuffer.h" + +int main(void) +{ + ringbuffer_t buffer = ringbuffer_new(20); + + assert(ringbuffer_nonempty(buffer) == 0); + + assert(ringbuffer_put_char(buffer, 'a') == 0); + assert(ringbuffer_nonempty(buffer) == 1); + assert(ringbuffer_get_char(buffer) == 'a'); + assert(ringbuffer_nonempty(buffer) == 0); + + int i; + for(i = 0; i < 20; i++) + { + printf("%d: %c\n", i, 'A' + i); + assert(ringbuffer_empty_bytes(buffer) == 20 - i); + assert(ringbuffer_put_char(buffer, 'A' + i) == 0); + } + assert(ringbuffer_nonempty(buffer) == 1); + for(i = 0; i < 20; i++) + { + printf("%d\n", i); + assert(ringbuffer_nonempty(buffer) == 1); + assert(ringbuffer_get_char(buffer) == 'A' + i); + } + assert(ringbuffer_nonempty(buffer) == 0); + return 0; +}