diff options
author | FreeArtMan <dos21h@gmail.com> | 2018-02-27 22:32:49 +0000 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2018-02-27 22:32:49 +0000 |
commit | 03bfeedc5f4c04c20764c8a9a58bd02604f27b2c (patch) | |
tree | 7ab09ac16649d80ca9e6397fc1b19aa8e184e2db /test_circ.c | |
parent | a8b9b15b4f02ce3c6c7eac0d9393c44cb3fc668d (diff) | |
download | libbuf-03bfeedc5f4c04c20764c8a9a58bd02604f27b2c.tar.gz libbuf-03bfeedc5f4c04c20764c8a9a58bd02604f27b2c.zip |
Created circular buffer
Diffstat (limited to 'test_circ.c')
-rw-r--r-- | test_circ.c | 95 |
1 files changed, 95 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> + +#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 |