From 03bfeedc5f4c04c20764c8a9a58bd02604f27b2c Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Tue, 27 Feb 2018 22:32:49 +0000 Subject: Created circular buffer --- test_circ.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 test_circ.c (limited to 'test_circ.c') diff --git a/test_circ.c b/test_circ.c new file mode 100644 index 0000000..60746f0 --- /dev/null +++ b/test_circ.c @@ -0,0 +1,95 @@ +#include +#include + +#include "buf.h" +#include "buf_misc.h" +#include "debug.h" + +void blow_if_error(int err) +{ + if (err < 0) + { + printf("Should be no error but there is\n"); + exit(1); + } +} + +//#define B(X) PNL();blow_if_error(X); +#define B(X) blow_if_error(X); + +void error_is_good(int err) +{ + if (err >= 0) + { + printf("Should be error but there is no\n"); + exit(1); + } +} +#define E(X) error_is_good(X); + +int main() +{ + + bbuf_circ *bc=NULL; + bbuf *b1=NULL; + char ch; + int i; + + B(bbuf_circ_new(&bc, 8)); + bbuf_print(bc->buf); printf("\r\n"); + + B(bbuf_circ_put(bc, 'A')); + bbuf_print(bc->buf); printf("\r\n"); + + B(bbuf_circ_put(bc, 'B')); + bbuf_print(bc->buf); printf("\r\n"); + + B(bbuf_circ_put(bc, 'C')); + B(bbuf_circ_put(bc, 'D')); + B(bbuf_circ_put(bc, 'E')); + B(bbuf_circ_put(bc, 'F')); + B(bbuf_circ_put(bc, 'G')); + B(bbuf_circ_put(bc, 'H')); + bbuf_print(bc->buf); printf("\r\n"); + + B(bbuf_circ_put(bc, 'I')); + bbuf_print(bc->buf); printf("\r\n"); + + B(bbuf_circ_reset(bc)); + E(bbuf_circ_get(bc, &ch)); + + B(bbuf_circ_put(bc, 'M')); + B(bbuf_circ_put(bc, 'O')); + B(bbuf_circ_put(bc, 'S')); + B(bbuf_circ_put(bc, 'S')); + B(bbuf_circ_put(bc, 'A')); + B(bbuf_circ_put(bc, 'D')); + for (i=0;i<10;i++) + { + if (0 == bbuf_circ_get(bc, &ch)) + { + printf("%c",ch); + } + } + printf("\r\n"); + bbuf_circ_reset(bc); + + char name1[] = "FREDOME"; + b1 = bbuf_new(strlen(name1)); + bbuf_set(b1, name1, strlen(name1)); + bbuf_print(b1); printf("\r\n"); + printf("Added =%d\r\n",bbuf_circ_add(bc, b1)); + for (i=0;i<10;i++) + { + if (0 == bbuf_circ_get(bc, &ch)) + { + printf("!%c",ch); + } + } + printf("\r\n"); + + bbuf_circ_free(bc); + bbuf_free(b1); + + return 0; +} \ No newline at end of file -- cgit v1.2.3