1
0
Fork 0

Small cleanups.

This commit is contained in:
Peter H. Fröhlich 2019-06-15 20:25:30 +02:00
parent e5bcaeb2e5
commit 3e7e869b41
1 changed files with 13 additions and 10 deletions

23
demo.c
View File

@ -7,25 +7,27 @@
#define FAKE(x) ((void *)(x))
/* Basic FIFO behavior and full/empty conditions. */
void
basic(void)
{
struct reconque *q1 = rcq_alloc(5);
assert(q1);
struct reconque *q = rcq_alloc(5);
assert(q);
for (size_t i = 0; i < 5; i++) {
assert(rcq_push(q1, FAKE(i + 1)) == 0);
assert(rcq_push(q, FAKE(i + 1)) == 0);
}
assert(rcq_push(q1, FAKE(1000)) < 0);
assert(rcq_push(q, FAKE(1000)) < 0); /* full */
for (size_t i = 0; i < 5; i++) {
assert(rcq_pop(q1) == FAKE(i + 1));
assert(rcq_pop(q) == FAKE(i + 1));
}
assert(rcq_pop(q1) == NULL);
assert(rcq_pop(q) == NULL); /* empty */
rcq_free(q1);
rcq_free(q);
}
/* Replace `q1` with bigger `q2` and show that `rcq_pop` works. */
void
grow(void)
{
@ -58,6 +60,7 @@ grow(void)
rcq_free(q2);
}
/* Just showing off at this point... */
void
triple(void)
{
@ -93,9 +96,9 @@ triple(void)
int
main(void)
{
basic(); /* just basic FIFO and full/empty */
grow(); /* replace with bigger queue */
triple(); /* just showing off at this point */
basic();
grow();
triple();
exit(EXIT_SUCCESS);
}