blob: 5e41c6a5a1d91638c7f660280ee4d2a564befa60 [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_offset_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, i;
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 /* test all possible offsets */
24 for (i = 0; i <= sizeof(in_buf); i++) {
25 len = ringbuffer_dequeue_peek(rbc, i, &out_buf);
26 assert(len == sizeof(in_buf) - i);
27 if (len)
28 assert(!memcmp(in_buf + i, out_buf, len));
29 }
30
31 ringbuffer_fini(rb);
32}
33
34int main(void)
35{
36 test_contained_offset_read();
37 return EXIT_SUCCESS;
38}