blob: d94e5db77ff9eb35d3e78f4132d4eeaf13a397cc [file] [log] [blame]
Jeremy Kerrc9775ce2017-02-07 16:25:34 +08001
2#include <stdlib.h>
3#include <stdint.h>
4#include <stdio.h>
5
6#include "ringbuffer.c"
7#include "ringbuffer-test-utils.c"
8
9void test_simple_poll(void)
10{
11 uint8_t in_buf[] = { 'a', 'b', 'c' };
Andrew Jefferyb70f8712023-04-19 12:53:34 +093012 struct rb_test_ctx _ctx;
13 struct rb_test_ctx *ctx;
Jeremy Kerrc9775ce2017-02-07 16:25:34 +080014 struct ringbuffer *rb;
15 int rc;
16
17 ctx = &_ctx;
18 ringbuffer_test_context_init(ctx);
19
20 rb = ringbuffer_init(10);
Andrew Jefferya72711a2023-04-18 18:19:41 +093021 ctx->rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_append_all,
22 ctx);
Jeremy Kerrc9775ce2017-02-07 16:25:34 +080023
24 rc = ringbuffer_queue(rb, in_buf, sizeof(in_buf));
25 assert(!rc);
26
27 assert(ctx->count == 1);
28 assert(ctx->len == sizeof(in_buf));
29 assert(!memcmp(in_buf, ctx->data, ctx->len));
30
31 ringbuffer_fini(rb);
32 ringbuffer_test_context_fini(ctx);
33}
34
35int main(void)
36{
37 test_simple_poll();
38 return EXIT_SUCCESS;
39}