summaryrefslogtreecommitdiff
path: root/test_circ.c
blob: 60746f0f39d1bedec566fbaf5b553085bdae2594 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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;
}