forked from Roen-Ro/CircularBuffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testMain.c
125 lines (102 loc) · 3.62 KB
/
testMain.c
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
//
// test.c
// LAGDebugDemo
//
// Created by 罗亮富 on 2018/9/27.
// Copyright © 2018年 Roen Ro. All rights reserved.
//
#include "CircularBuffer.h"
#include <string.h>
int main(int argc, char * argv[]) {
CircularBuffer cb = CircularBufferCreate(8);
char *a = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char b[128];
int len = 0,offset = 0, outLen = 0;
//push
printf("\n=====================================\n");
len = 3;
printf("++push=> %d bytes chars:(%c - %c)\n",len,*(a+offset),*(a+offset+len-1));
CircularBufferPush(cb, a+offset, len );
offset += len;
CircularBufferPrint(cb,false);
//push
printf("\n=====================================\n");
len = 7;
printf("++push=> %d bytes chars:(%c - %c)\n",len,*(a+offset),*(a+offset+len-1));
CircularBufferPush(cb, a+offset, len );
offset += len;
CircularBufferPrint(cb,false);
//pop
printf("\n=====================================\n");
len = 3;
memset(b, '\0', 128);
outLen = (int)CircularBufferPop(cb, len, b);
printf("--pop=> %d expect %d data:%s\n",outLen,len,b);
CircularBufferPrint(cb,false);
//read
printf("\n=====================================\n");
len = 2;
memset(b, '\0', 128);
outLen = (int)CircularBufferRead(cb, len, b);
printf("||Read=> %d expect %d data:%s\n",outLen,len,b);
CircularBufferPrint(cb,false);
//push
printf("\n=====================================\n");
len = 10;
printf("++push=> %d bytes chars:(%c - %c)\n",len,*(a+offset),*(a+offset+len-1));
CircularBufferPush(cb, a+offset, len );
offset += len;
CircularBufferPrint(cb,false);
//pop
printf("\n=====================================\n");
len = 3;
memset(b, '\0', 128);
outLen = (int)CircularBufferPop(cb, len, b);
printf("--pop=> %d expect %d data:%s\n",outLen,len,b);
CircularBufferPrint(cb,false);
//pop
printf("\n============R-R====================\n");
len = 30;
memset(b, '\0', 128);
outLen = (int)CircularBufferPop(cb, len, b);
printf("--pop=> %d expect %d data:%s\n",outLen,len,b);
CircularBufferPrint(cb,false);
// printf("\n============RESET====================\n");
// CircularBufferReset(cb);
// CircularBufferPrint(cb,false);
//push
printf("\n=====================================\n");
len = 5;
printf("++push=> %d bytes chars:(%c - %c)\n",len,*(a+offset),*(a+offset+len-1));
CircularBufferPush(cb, a+offset, len );
offset += len;
CircularBufferPrint(cb,false);
//pop
printf("\n=====================================\n");
len = 2;
memset(b, '\0', 128);
outLen = (int)CircularBufferPop(cb, len, b);
printf("--pop=> %d expect %d data:%s\n",outLen,len,b);
CircularBufferPrint(cb,false);
//push
printf("\n=====================================\n");
len = 10;
printf("++push=> %d bytes chars:(%c - %c)\n",len,*(a+offset),*(a+offset+len-1));
CircularBufferPush(cb, a+offset, len );
offset += len;
CircularBufferPrint(cb,false);
//pop
printf("\n=====================================\n");
len = 6;
memset(b, '\0', 128);
outLen = (int)CircularBufferPop(cb, len, b);
printf("--pop=> %d expect %d data:%s\n",outLen,len,b);
CircularBufferPrint(cb,false);
//push
printf("\n=====================================\n");
len = 4;
printf("++push=> %d bytes chars:(%c - %c)\n",len,*(a+offset),*(a+offset+len-1));
CircularBufferPush(cb, a+offset, len );
offset += len;
CircularBufferPrint(cb,false);
}