added an x86 test for the ringbuffer

This commit is contained in:
Daniel Knüttel 2019-04-10 11:48:04 +02:00
parent d806f057f9
commit 65eb4d6ce2
2 changed files with 51 additions and 0 deletions

18
test/Makefile Normal file
View File

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

33
test/test_ringbuffer.c Normal file
View File

@ -0,0 +1,33 @@
#include <assert.h>
#include <stdio.h>
#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;
}