2021-01-09 02:24:51 +08:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-08-02 04:53:02 +08:00
|
|
|
#include <assert.h>
|
|
|
|
|
2019-11-24 18:53:00 +08:00
|
|
|
#include "util/queue.h"
|
2019-08-02 04:53:02 +08:00
|
|
|
|
|
|
|
struct foo {
|
|
|
|
int value;
|
|
|
|
struct foo *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_queue(void) {
|
2021-07-04 21:05:08 +08:00
|
|
|
struct my_queue SC_QUEUE(struct foo) queue;
|
|
|
|
sc_queue_init(&queue);
|
2019-08-02 04:53:02 +08:00
|
|
|
|
2021-07-04 21:05:08 +08:00
|
|
|
assert(sc_queue_is_empty(&queue));
|
2019-08-02 04:53:02 +08:00
|
|
|
|
|
|
|
struct foo v1 = { .value = 42 };
|
|
|
|
struct foo v2 = { .value = 27 };
|
|
|
|
|
2021-07-04 21:05:08 +08:00
|
|
|
sc_queue_push(&queue, next, &v1);
|
|
|
|
sc_queue_push(&queue, next, &v2);
|
2019-08-02 04:53:02 +08:00
|
|
|
|
|
|
|
struct foo *foo;
|
|
|
|
|
2021-07-04 21:05:08 +08:00
|
|
|
assert(!sc_queue_is_empty(&queue));
|
|
|
|
sc_queue_take(&queue, next, &foo);
|
2019-08-02 04:53:02 +08:00
|
|
|
assert(foo->value == 42);
|
|
|
|
|
2021-07-04 21:05:08 +08:00
|
|
|
assert(!sc_queue_is_empty(&queue));
|
|
|
|
sc_queue_take(&queue, next, &foo);
|
2019-08-02 04:53:02 +08:00
|
|
|
assert(foo->value == 27);
|
|
|
|
|
2021-07-04 21:05:08 +08:00
|
|
|
assert(sc_queue_is_empty(&queue));
|
2019-08-02 04:53:02 +08:00
|
|
|
}
|
|
|
|
|
2020-07-15 18:17:04 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
|
2019-08-02 04:53:02 +08:00
|
|
|
test_queue();
|
|
|
|
return 0;
|
|
|
|
}
|