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_contained_read(void) |
| 10 | { |
Andrew Jeffery | b70f871 | 2023-04-19 12:53:34 +0930 | [diff] [blame] | 11 | uint8_t *out_buf; |
| 12 | uint8_t in_buf[] = { 'a', 'b', 'c' }; |
Jeremy Kerr | c9775ce | 2017-02-07 16:25:34 +0800 | [diff] [blame] | 13 | struct ringbuffer_consumer *rbc; |
| 14 | struct ringbuffer *rb; |
| 15 | size_t len; |
| 16 | int rc; |
| 17 | |
| 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 | len = ringbuffer_dequeue_peek(rbc, 0, &out_buf); |
| 25 | assert(len == sizeof(in_buf)); |
| 26 | assert(!memcmp(in_buf, out_buf, sizeof(in_buf))); |
| 27 | |
| 28 | ringbuffer_fini(rb); |
| 29 | } |
| 30 | |
| 31 | int main(void) |
| 32 | { |
| 33 | test_contained_read(); |
| 34 | return EXIT_SUCCESS; |
| 35 | } |