2019-08-01 20:53:02 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2019-11-24 10:53:00 +00:00
|
|
|
#include "util/queue.h"
|
2019-08-01 20:53:02 +00:00
|
|
|
|
|
|
|
struct foo {
|
|
|
|
int value;
|
|
|
|
struct foo *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_queue(void) {
|
|
|
|
struct my_queue QUEUE(struct foo) queue;
|
|
|
|
queue_init(&queue);
|
|
|
|
|
|
|
|
assert(queue_is_empty(&queue));
|
|
|
|
|
|
|
|
struct foo v1 = { .value = 42 };
|
|
|
|
struct foo v2 = { .value = 27 };
|
|
|
|
|
|
|
|
queue_push(&queue, next, &v1);
|
|
|
|
queue_push(&queue, next, &v2);
|
|
|
|
|
|
|
|
struct foo *foo;
|
|
|
|
|
|
|
|
assert(!queue_is_empty(&queue));
|
|
|
|
queue_take(&queue, next, &foo);
|
|
|
|
assert(foo->value == 42);
|
|
|
|
|
|
|
|
assert(!queue_is_empty(&queue));
|
|
|
|
queue_take(&queue, next, &foo);
|
|
|
|
assert(foo->value == 27);
|
|
|
|
|
|
|
|
assert(queue_is_empty(&queue));
|
|
|
|
}
|
|
|
|
|
2020-07-15 10:17:04 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
|
2019-08-01 20:53:02 +00:00
|
|
|
test_queue();
|
|
|
|
return 0;
|
|
|
|
}
|