blob: 497cf473141368030bd1d8c1a27b9cc2d2d3a9be (
plain) (
blame)
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
|
#include <stdio.h>
#include <stdlib.h>
#include "__cpp.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);
void print_s(char *str, int sz)
{
int i = 0;
for (i=0;i<sz;i++)
printf("%c",str[i]);
fflush(stdout);
}
int main()
{
Buf *b1=NULL, *b2=NULL, *b3=NULL;
BufLine *bline=NULL;
printf("Start test\n");
b1 = new Buf(8);
b2 = new Buf(8);
b3 = new Buf(1);
bline = new BufLine(32);
char n1[] = "Line";
char n2[] = "Home";
char n3[] = "\n";
b1->set(n1);
b2->set(n2);
b3->set(n3);
b1->print(); printf("\n");
b2->print(); printf("\n");
b1->print(); printf("\n");
bline->print(); printf("\n");
printf("Add data\n");
bline->add(b1); bline->print(); printf("\n");
bline->add(b3);
bline->add(b2); bline->print(); printf("\n");
printf("Get line\n");
int sz=-1;
char *getline=NULL;
if (0==bline->pop_line(&getline,&sz))
{
printf("[");print_s(getline,sz); printf("]\n");
bline->print();
}
printf("End test\n");
return 0;
}
|