blob: 4cd1c20c6026823e20ab8982754f95eeaafd27aa [file] [log] [blame] [edit]
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include "ringbuffer.c"
#include "ringbuffer-test-utils.c"
void test_boundary_poll(void)
{
uint8_t in_buf[] = { 'a', 'b', 'c', 'd', 'e', 'f' };
struct rb_test_ctx _ctx;
struct rb_test_ctx *ctx = &_ctx;
struct ringbuffer *rb;
int rc;
ringbuffer_test_context_init(ctx);
rb = ringbuffer_init(10);
ctx->rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_append_all,
ctx);
/* don't consume initial data in the poll callback */
ctx->ignore_poll = true;
/* queue and dequeue, so our tail is non-zero */
ringbuffer_queue(rb, in_buf, sizeof(in_buf));
ringbuffer_dequeue_commit(ctx->rbc, sizeof(in_buf));
/* start queueing data */
ctx->ignore_poll = false;
/* ensure we're getting the second batch of data back */
in_buf[0] = 'A';
rc = ringbuffer_queue(rb, in_buf, sizeof(in_buf));
assert(!rc);
assert(ctx->count == 1);
assert(ctx->len == sizeof(in_buf));
assert(!memcmp(in_buf, ctx->data, ctx->len));
ringbuffer_fini(rb);
ringbuffer_test_context_fini(ctx);
}
int main(void)
{
test_boundary_poll();
return EXIT_SUCCESS;
}