Jeremy Kerr | c9775ce | 2017-02-07 16:25:34 +0800 | [diff] [blame] | 1 | |
| 2 | #include <stdlib.h> |
| 3 | #include <stdint.h> |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | #include "ringbuffer.c" |
| 7 | #include "ringbuffer-test-utils.c" |
| 8 | |
| 9 | void test_read_commit(void) |
| 10 | { |
Andrew Jeffery | b70f871 | 2023-04-19 12:53:34 +0930 | [diff] [blame^] | 11 | uint8_t *out_buf; |
| 12 | uint8_t in_buf[] = { |
Andrew Jeffery | a72711a | 2023-04-18 18:19:41 +0930 | [diff] [blame] | 13 | 'a', |
| 14 | 'b', |
| 15 | 'c', |
| 16 | }; |
Jeremy Kerr | c9775ce | 2017-02-07 16:25:34 +0800 | [diff] [blame] | 17 | 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 | |
| 34 | int main(void) |
| 35 | { |
| 36 | test_read_commit(); |
| 37 | return EXIT_SUCCESS; |
| 38 | } |