diff options
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 82 |
1 files changed, 82 insertions, 0 deletions
@@ -0,0 +1,82 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "buf.h" +#include "debug.h" + +#define BUF_SIZE_1 1024 +#define BUF_SIZE_2 2048 + +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); + +void error_is_good(int err) +{ + if (err >= 0) + { + printf("Should be error but there is no\n"); + exit(1); + } +} + +void print_s(char *str, int sz) +{ + int i = 0; + for (i=0;i<sz;i++) + printf("%c",str[i]); + fflush(stdout); +} + +int main() +{ + bbuf *b1=NULL, *b2=NULL; + int ret; + + printf("Start test\n"); + + bbuf_free(b1); + + printf("Create new buffer\n"); + b1 = bbuf_new(BUF_SIZE_1); + bbuf_free(b1); + + printf("Copy buffer\n"); + b1 = bbuf_new(BUF_SIZE_1); + b2 = bbuf_copy(b1); + bbuf_free(b1); + bbuf_free(b2); + + + printf("Get buffer\n"); + char name1[] = "Lets get buffer and print it out"; + char *get_val = NULL; + int get_size; + b1 = bbuf_new(BUF_SIZE_1); + B(bbuf_set(b1,name1,strlen(name1))); + B(bbuf_get(b1,&get_val,&get_size)); + print_s(get_val,get_size);printf("\n"); + + b2 = bbuf_copy(b1); + B(bbuf_get(b2,&get_val,&get_size)); + print_s(get_val,get_size);printf("\n"); + + bbuf_free(b1); + bbuf_free(b2); + + printf("Realloc buffer\n"); + b1 = bbuf_new(BUF_SIZE_1); + B(bbuf_realloc(b1,BUF_SIZE_2)); + bbuf_free(b1); + + + printf("End test\n"); + return 0; +}
\ No newline at end of file |