1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#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;i<sz;i++)
printf("%c",str[i]);
fflush(stdout);
}
int main()
{
/*
bbuf *b1=NULL, *b2=NULL;
int ret;
*/
Buf *b1=NULL, *b2=NULL;
int rc;
printf("Start test\n");
/*
bbuf_free(b1);
*/
delete b1;
printf("Create new buffer\n");
/*
b1 = bbuf_new(BUF_SIZE_1);
bbuf_free(b1);
*/
b1 = new Buf(BUF_SIZE_1);
delete b1;
printf("Copy buffer\n");
/*
b1 = bbuf_new(BUF_SIZE_1);
b2 = bbuf_copy(b1);
bbuf_free(b1);
bbuf_free(b2);
*/
b1 = new Buf(BUF_SIZE_1);
b2 = b1->copy();
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("End test\n");
return 0;
}
|