blob: 7490f01c957112dfcae271e5d6ee6436f8bddc13 [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;
Andrew Jeffery8f548f62023-04-18 11:48:49 +093015 size_t i;
16 int rc;
Jeremy Kerrc9775ce2017-02-07 16:25:34 +080017
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 /* test all possible offsets */
25 for (i = 0; i <= sizeof(in_buf); i++) {
26 len = ringbuffer_dequeue_peek(rbc, i, &out_buf);
27 assert(len == sizeof(in_buf) - i);
28 if (len)
29 assert(!memcmp(in_buf + i, out_buf, len));
30 }
31
32 ringbuffer_fini(rb);
33}
34
35int main(void)
36{
37 test_contained_offset_read();
38 return EXIT_SUCCESS;
39}