core/containers/queue: Add _q_size() function

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-11-30 10:30:55 -05:00
parent 79627bb287
commit bf332b36a5
2 changed files with 11 additions and 4 deletions

View File

@ -21,4 +21,10 @@ static inline void _q_init(struct _queue *queue)
g_queue_init(&queue->_queue);
}
/* Called to find the size of a queue. */
static inline guint _q_size(struct _queue *queue)
{
return g_queue_get_length(&queue->_queue);
}
#endif /* OCARINA_CORE_CONTAINERS_QUEUE_H */

View File

@ -4,17 +4,18 @@
#include <core/containers/queue.h>
#include <tests/test.h>
static void test_init()
static void test_stress(unsigned int N)
{
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);
test_equal(_q_size(&queue), 0);
}
static void test_basics() { test_stress(10); }
DECLARE_UNIT_TESTS(
UNIT_TEST("Queue Initialization", test_init),
UNIT_TEST("Queue Basics", test_basics),
);