-
Notifications
You must be signed in to change notification settings - Fork 0
/
mirrorringbuffer_test.c
executable file
·68 lines (53 loc) · 1.23 KB
/
mirrorringbuffer_test.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
/*
* mirrorringbuffer_test.c
*
* Created on: 2013-7-17
*/
#include <stdio.h>
#include <assert.h>
#include "mirrorringbuffer.h"
#define BUFFER_SIZE 8
int main(int arc, char** argv)
{
CircularBuffer ringbuffer;
ElemType mocUp;
int rc, i;
cbInit(&ringbuffer, BUFFER_SIZE);
rc= cbIsEmpty(&ringbuffer);
assert(rc==1);
printf("cbIsEmpty empty passed\n");
rc= cbIsFull(&ringbuffer);
assert(rc==0);
printf("cbIsFull not full passed\n");
mocUp.id=0;
cbWrite(&ringbuffer, &mocUp);
rc= cbIsEmpty(&ringbuffer);
assert(rc==0);
for(i=1;i<3;i++)
{
mocUp.id=i;
cbWrite(&ringbuffer, &mocUp);
};
rc= cbIsEmpty(&ringbuffer);
assert(rc==0);
printf("cbIsEmpty not empty passed\n");
rc= cbIsFull(&ringbuffer);
assert(rc==0);
for(i=3;i<BUFFER_SIZE;i++)
{
mocUp.id=i;
cbWrite(&ringbuffer, &mocUp);
};
rc= cbIsEmpty(&ringbuffer);
assert(rc==0);
rc= cbIsFull(&ringbuffer);
assert(rc==1);
printf("cbIsFull full passed\n");
printf("cbIsFull write passed\n");
cbRead(&ringbuffer, &mocUp);
rc= cbIsFull(&ringbuffer);
assert(rc==0);
assert(mocUp.id==0);
printf("cbIsFull read passed\n");
return 0;
}