2021-01-08 18:24:51 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
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) {
|
2021-07-04 13:05:08 +00:00
|
|
|
struct my_queue SC_QUEUE(struct foo) queue;
|
|
|
|
sc_queue_init(&queue);
|
2019-08-01 20:53:02 +00:00
|
|
|
|
2021-07-04 13:05:08 +00:00
|
|
|
assert(sc_queue_is_empty(&queue));
|
2019-08-01 20:53:02 +00:00
|
|
|
|
|
|
|
struct foo v1 = { .value = 42 };
|
|
|
|
struct foo v2 = { .value = 27 };
|
|
|
|
|
2021-07-04 13:05:08 +00:00
|
|
|
sc_queue_push(&queue, next, &v1);
|
|
|
|
sc_queue_push(&queue, next, &v2);
|
2019-08-01 20:53:02 +00:00
|
|
|
|
|
|
|
struct foo *foo;
|
|
|
|
|
2021-07-04 13:05:08 +00:00
|
|
|
assert(!sc_queue_is_empty(&queue));
|
|
|
|
sc_queue_take(&queue, next, &foo);
|
2019-08-01 20:53:02 +00:00
|
|
|
assert(foo->value == 42);
|
|
|
|
|
2021-07-04 13:05:08 +00:00
|
|
|
assert(!sc_queue_is_empty(&queue));
|
|
|
|
sc_queue_take(&queue, next, &foo);
|
2019-08-01 20:53:02 +00:00
|
|
|
assert(foo->value == 27);
|
|
|
|
|
2021-07-04 13:05:08 +00:00
|
|
|
assert(sc_queue_is_empty(&queue));
|
2019-08-01 20:53:02 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|