ringbuf/driver.c
2024-07-02 06:49:49 +02:00

51 lines
1 KiB
C

/* SPDX-License-Identifier: MIT */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define rb_size_t size_t
#include "ringbuf.h"
int
main(void)
{
struct RingBuf rb;
rb_init(&rb, 10, malloc, sizeof(int));
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int ok = WriteOk; // Assume we can write
if(rb_push_many(&rb, arr, memcpy, 8) != WriteOk) {
printf("Failed to write data to buffer...\n");
}
int d;
printf("Data: [");
while(rb_pop_front(&rb, &d, memcpy) == ReadOk)
printf("%d,", d);
printf("\b]\n");
// Test wrap around
rb_push_many(&rb, arr, memcpy, 10);
printf("Data: [");
while(rb_pop_front(&rb, &d, memcpy) == ReadOk)
printf("%d,", d);
printf("\b]\n");
// Test clear
rb_clear(&rb);
if(rb_pop_front(&rb, &d, memcpy) != Empty) {
printf("Buffer is not empty after clear...\n");
}
rb_destroy(&rb, free);
enum WriteResult wr = WriteOk;
enum ReadResult rr = ReadOk;
printf("Size of wr: %lu bytes.\n", sizeof(wr));
printf("Size of rr: %lu bytes.\n", sizeof(rr));
return 0;
}