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