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