forked from bcharron/spcplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuftest.c
45 lines (36 loc) · 883 Bytes
/
buftest.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
#include <assert.h>
#include "buf.h"
int main(int argc, char *argv[]) {
int x;
buf_t *buf;
Sint16 v;
int ret;
int loop;
buf = buffer_create(100);
assert(NULL != buf);
for (loop = 0; loop < 5; loop++) {
/* All these adds should succeed */
for (x = 1; x <= 100; x++) {
v = (Sint16) x;
printf("buffer_add_one(buf, %d)\n", v);
ret = buffer_add_one(buf, v);
assert(ret == 1);
assert(buffer_get_len(buf) == x);
assert(buffer_get_free(buf) == (100 - x));
}
assert(buffer_get_len(buf) == 100);
/* This add should fail - buffer is full */
ret = buffer_add_one(buf, 0);
assert(ret == 0);
for (x = 1; x <= 100; x++) {
v = buffer_get_one(buf);
printf("get[%d]: %d\n", x, v);
assert(v == x);
assert(buffer_get_len(buf) == (100 - x));
}
x = buffer_get_len(buf);
printf("buffer len: %d\n", x);
assert(x == 0);
}
return(0);
}