forked from Roen-Ro/CircularBuffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testMain.c
104 lines (85 loc) · 2.66 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
//
// 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\n",len);
circularBufferPush(&cb, a+offset, len );
offset += len;
logCircularBuffer(cb);
//push
printf("\n=====================================\n");
len = 7;
printf("++push=> %d\n",len);
circularBufferPush(&cb, a+offset, len );
offset += len;
logCircularBuffer(cb);
//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);
logCircularBuffer(cb);
//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);
logCircularBuffer(cb);
//push
printf("\n=====================================\n");
len = 10;
printf("++push=> %d\n",len);
circularBufferPush(&cb, a+offset, len );
offset += len;
logCircularBuffer(cb);
//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);
logCircularBuffer(cb);
//pop
printf("\n=====================================\n");
len = 10;
memset(b, '\0', 128);
outLen = (int)CircularBufferPop(&cb, len, b);
printf("--pop=> %d expect %d data:%s\n",outLen,len,b);
logCircularBuffer(cb);
//push
printf("\n=====================================\n");
len = 5;
printf("++push=> %d\n",len);
circularBufferPush(&cb, a+offset, len );
offset += len;
logCircularBuffer(cb);
//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);
logCircularBuffer(cb);
//push
printf("\n=====================================\n");
len = 3;
printf("++push=> %d\n",len);
circularBufferPush(&cb, a+offset, len );
offset += len;
logCircularBuffer(cb);
}