| |
| #include <stdlib.h> |
| #include <stdint.h> |
| #include <stdio.h> |
| |
| #include "ringbuffer.c" |
| #include "ringbuffer-test-utils.c" |
| |
| void test_contained_offset_read(void) |
| { |
| uint8_t *out_buf; |
| uint8_t in_buf[] = { 'a', 'b', 'c' }; |
| struct ringbuffer_consumer *rbc; |
| struct ringbuffer *rb; |
| size_t len; |
| size_t i; |
| int rc; |
| |
| rb = ringbuffer_init(10); |
| rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_nop, NULL); |
| |
| rc = ringbuffer_queue(rb, in_buf, sizeof(in_buf)); |
| assert(!rc); |
| |
| /* test all possible offsets */ |
| for (i = 0; i <= sizeof(in_buf); i++) { |
| len = ringbuffer_dequeue_peek(rbc, i, &out_buf); |
| assert(len == sizeof(in_buf) - i); |
| if (len) { |
| assert(!memcmp(in_buf + i, out_buf, len)); |
| } |
| } |
| |
| ringbuffer_fini(rb); |
| } |
| |
| int main(void) |
| { |
| test_contained_offset_read(); |
| return EXIT_SUCCESS; |
| } |