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