summaryrefslogtreecommitdiff
path: root/test.c
blob: 9bb8f31015ef394ea15b020869eca2894fe2bd24 (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
#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;
}