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_offset_read(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; |
Andrew Jeffery | 8f548f6 | 2023-04-18 11:48:49 +0930 | [diff] [blame] | 15 | size_t i; |
| 16 | int rc; |
Jeremy Kerr | c9775ce | 2017-02-07 16:25:34 +0800 | [diff] [blame] | 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 | /* test all possible offsets */ |
| 25 | for (i = 0; i <= sizeof(in_buf); i++) { |
| 26 | len = ringbuffer_dequeue_peek(rbc, i, &out_buf); |
| 27 | assert(len == sizeof(in_buf) - i); |
| 28 | if (len) |
| 29 | assert(!memcmp(in_buf + i, out_buf, len)); |
| 30 | } |
| 31 | |
| 32 | ringbuffer_fini(rb); |
| 33 | } |
| 34 | |
| 35 | int main(void) |
| 36 | { |
| 37 | test_contained_offset_read(); |
| 38 | return EXIT_SUCCESS; |
| 39 | } |