avrinput/x86_tests/test_ringbuffer.c

34 lines
776 B
C
Raw Permalink Normal View History

2019-04-10 09:48:04 +00:00
#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;
}