blob: 96018c4203da4c509b77a5aa44ab53d6702bac59 [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_contained_read(void)
10{
Andrew Jefferyb70f8712023-04-19 12:53:34 +093011 uint8_t *out_buf;
12 uint8_t in_buf[] = { 'a', 'b', 'c' };
Jeremy Kerrc9775ce2017-02-07 16:25:34 +080013 struct ringbuffer_consumer *rbc;
14 struct ringbuffer *rb;
15 size_t len;
16 int rc;
17
18 rb = ringbuffer_init(10);
19 rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_nop, NULL);
20
21 rc = ringbuffer_queue(rb, in_buf, sizeof(in_buf));
22 assert(!rc);
23
24 len = ringbuffer_dequeue_peek(rbc, 0, &out_buf);
25 assert(len == sizeof(in_buf));
26 assert(!memcmp(in_buf, out_buf, sizeof(in_buf)));
27
28 ringbuffer_fini(rb);
29}
30
31int main(void)
32{
33 test_contained_read();
34 return EXIT_SUCCESS;
35}