1
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <stdio.h>
5
6 #include "ringbuffer.c"
7 #include "ringbuffer-test-utils.c"
8
test_contained_read(void)9 void test_contained_read(void)
10 {
11 uint8_t *out_buf;
12 uint8_t in_buf[] = { 'a', 'b', 'c' };
13 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
main(void)31 int main(void)
32 {
33 test_contained_read();
34 return EXIT_SUCCESS;
35 }
36