#include #include #include #include "__cpp.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;icopy(); delete b1; b1=NULL; delete b2; b2=NULL; 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"); */ b1 = new Buf(BUF_SIZE_1); B(b1->set(name1, strlen(name1))); B(b1->get(&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"); */ b2 = b1->copy(); B(b2->get(&get_val,&get_size)); print_s(get_val,get_size);printf("\n"); /* bbuf_free(b1); bbuf_free(b2); */ delete b1; delete b2; printf("Realloc buffer\n"); /* b1 = bbuf_new(BUF_SIZE_1); B(bbuf_realloc(b1,BUF_SIZE_2)); bbuf_free(b1); */ b1 = new Buf(BUF_SIZE_1); b1->realloc(BUF_SIZE_2); delete b1; printf("Concat 2 strings"); b1 = new Buf(8); b2 = new Buf(8); char n1[] = "Name"; char n2[] = "File"; char n3[] = "Nothing"; B(b1->set(n1)); B(b2->set(n2)); b1->print(); printf("\n"); b2->print(); printf("\n"); printf("%d:",b1->concat(b2)); b1->print(); printf("\n"); B(b2->set(n3)); printf("%d:",b1->concat(b2)); b1->print(); printf("\n"); delete b1; delete b2; printf("Shift string\n"); char shs1[] = "TheDominionOfTheLife"; b1 = new Buf(64); b1->set(shs1); b1->print(); printf("\n"); printf("%d:",b1->shiftleft(3)); b1->print(); printf("\n"); printf("%d:",b1->shiftleft(8)); b1->print(); printf("\n"); delete b1; printf("Pop substring\n"); b1 = new Buf(64); char *subs=NULL; int sz; b1->set(shs1); b1->print(); printf("\n"); printf("%d:",b1->popsubstring(3,&subs,&sz)); b1->print(); printf(" substring "); print_s(subs,sz); printf("\n"); free(subs);sz=0; printf("%d:",b1->popsubstring(8,&subs,&sz)); b1->print(); printf(" substring "); print_s(subs,sz); printf("\n"); free(subs);sz=0; printf("End test\n"); return 0; }