blob: 2b7e4b4406a977c01ce25bfda9e0ed0fd1d7a190 [file] [log] [blame] [edit]
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include "ringbuffer.c"
#include "ringbuffer-test-utils.c"
void test_boundary_read(void)
{
uint8_t *out_buf;
uint8_t in_buf[] = { 'a', 'b', 'c', 'd', 'e', 'f' };
struct ringbuffer_consumer *rbc;
struct ringbuffer *rb;
size_t len;
size_t pos;
int rc;
static_assert(sizeof(in_buf) * 2 > 10, "");
rb = ringbuffer_init(10);
rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_nop, NULL);
/* queue and dequeue, so our tail is non-zero */
ringbuffer_queue(rb, in_buf, sizeof(in_buf));
ringbuffer_dequeue_commit(rbc, sizeof(in_buf));
/* ensure we're getting the second batch of data back */
in_buf[0] = 'A';
/* the next queue should cross the end of the buffer */
rc = ringbuffer_queue(rb, in_buf, sizeof(in_buf));
assert(!rc);
/* dequeue everything we can */
pos = 0;
for (;;) {
len = ringbuffer_dequeue_peek(rbc, pos, &out_buf);
if (len == 0) {
break;
}
assert(!memcmp(in_buf + pos, out_buf, len));
pos += len;
}
assert(pos == sizeof(in_buf));
ringbuffer_fini(rb);
}
int main(void)
{
test_boundary_read();
return EXIT_SUCCESS;
}