Tidy up ringbuf and make tests
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#include <check.h>
|
||||
#include <unistd.h>
|
||||
#include "ucore/ringbuf.h"
|
||||
|
||||
START_TEST (test_ringbuf)
|
||||
{
|
||||
|
||||
UCRingBuf rb;
|
||||
int rc;
|
||||
int pgsize = getpagesize();
|
||||
rc = uc_ringbuf_init(&rb, pgsize);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
ck_assert_int_eq(uc_ringbuf_available(&rb), pgsize);
|
||||
|
||||
|
||||
for (int i = 0 ; i < pgsize; i++) {
|
||||
unsigned char data = i % 256;
|
||||
rc = uc_ringbuf_write(&rb, &data, 1);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
|
||||
}
|
||||
ck_assert_int_eq(uc_ringbuf_available(&rb), 0);
|
||||
|
||||
|
||||
for (int i = 0; i < pgsize; i++) {
|
||||
unsigned char data = 0;
|
||||
rc = uc_ringbuf_read(&rb, &data, 1);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
ck_assert_int_eq(data, i % 256);
|
||||
}
|
||||
ck_assert_int_eq(uc_ringbuf_available(&rb), pgsize);
|
||||
|
||||
}
|
||||
|
||||
Suite *ringbuf_suite(void)
|
||||
{
|
||||
Suite *s = suite_create("ringbuf");
|
||||
TCase *tc1 = tcase_create("ringbuf");
|
||||
|
||||
tcase_add_test(tc1, test_ringbuf);
|
||||
#ifndef __APPLE__
|
||||
#endif
|
||||
|
||||
suite_add_tcase(s, tc1);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user