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 | { |
| 11 | uint8_t *out_buf, in_buf[] = { 'a', 'b', 'c', }; |
| 12 | struct ringbuffer_consumer *rbc; |
| 13 | struct ringbuffer *rb; |
| 14 | size_t len; |
| 15 | |
| 16 | rb = ringbuffer_init(10); |
| 17 | rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_nop, NULL); |
| 18 | |
| 19 | ringbuffer_queue(rb, in_buf, sizeof(in_buf)); |
| 20 | len = ringbuffer_dequeue_peek(rbc, 0, &out_buf); |
| 21 | |
| 22 | ringbuffer_dequeue_commit(rbc, len); |
| 23 | len = ringbuffer_dequeue_peek(rbc, 0, &out_buf); |
| 24 | assert(len == 0); |
| 25 | |
| 26 | ringbuffer_fini(rb); |
| 27 | } |
| 28 | |
| 29 | int main(void) |
| 30 | { |
| 31 | test_read_commit(); |
| 32 | return EXIT_SUCCESS; |
| 33 | } |