core/containers/queue: Add basic queue struct
This struct is a wrapper around the GQueue container, similar to how we do sets. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
58a983efd1
commit
79627bb287
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*/
|
||||
#ifndef OCARINA_CORE_CONTAINERS_QUEUE_H
|
||||
#define OCARINA_CORE_CONTAINERS_QUEUE_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
struct _queue {
|
||||
GQueue _queue;
|
||||
};
|
||||
|
||||
#define _Q_INIT() \
|
||||
{ \
|
||||
._queue = G_QUEUE_INIT, \
|
||||
}
|
||||
|
||||
/* Called to initialize a queue. */
|
||||
static inline void _q_init(struct _queue *queue)
|
||||
{
|
||||
g_queue_init(&queue->_queue);
|
||||
}
|
||||
|
||||
#endif /* OCARINA_CORE_CONTAINERS_QUEUE_H */
|
|
@ -14,5 +14,6 @@ def ContainerTest(name, source):
|
|||
res = [ ContainerTest("set", "set.c") ]
|
||||
res = [ ContainerTest("database", "database.c") ]
|
||||
res += [ ContainerTest("index", "index.c") ]
|
||||
res += [ ContainerTest("queue", "queue.c") ]
|
||||
|
||||
Return("res")
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/containers/queue.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
static void test_init()
|
||||
{
|
||||
struct _queue queue = _Q_INIT();
|
||||
|
||||
/* _q_init() */
|
||||
test_equal((void *)queue._queue.head, NULL);
|
||||
test_equal((void *)queue._queue.tail, NULL);
|
||||
test_equal(queue._queue.length, 0);
|
||||
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Queue Initialization", test_init),
|
||||
);
|
Loading…
Reference in New Issue