diff --git a/gui/queue.c b/gui/queue.c new file mode 100644 index 00000000..8d776fda --- /dev/null +++ b/gui/queue.c @@ -0,0 +1,20 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#include + +void *gui_queue_alloc(struct queue *queue) +{ + struct gui_queue *gq = g_malloc(sizeof(struct gui_queue)); + + gq->gq_queue = queue; + return gq; +} + +void gui_queue_free(struct queue *queue) +{ + struct gui_queue *gq = gui_queue(queue); + + queue->q_private = NULL; + g_free(gq); +} diff --git a/gui/queue.cpp b/gui/queue_tab.cpp similarity index 100% rename from gui/queue.cpp rename to gui/queue_tab.cpp diff --git a/include/gui/queue.h b/include/gui/queue.h new file mode 100644 index 00000000..2e858f84 --- /dev/null +++ b/include/gui/queue.h @@ -0,0 +1,26 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#ifndef OCARINA_GUI_QUEUE_H +#define OCARINA_GUI_QUEUE_H + +#include + +struct gui_queue { + struct queue *gq_queue; +}; + + +/* Called to allocate a new struct gui_queue. */ +void *gui_queue_alloc(struct queue *); + +/* Called to free a struct gui_queue. */ +void gui_queue_free(struct queue *); + +/* Called to access a the struct gui_queue attached to a queue. */ +static inline struct gui_queue *gui_queue(struct queue *queue) +{ + return queue->q_private; +} + +#endif /* OCARINA_GUI_QUEUE_H */ diff --git a/tests/gui/.gitignore b/tests/gui/.gitignore index eb2d2716..08e3561c 100644 --- a/tests/gui/.gitignore +++ b/tests/gui/.gitignore @@ -1,5 +1,6 @@ builder settings +queue window sidebar collection diff --git a/tests/gui/Sconscript b/tests/gui/Sconscript index 801c74ac..de939d2b 100644 --- a/tests/gui/Sconscript +++ b/tests/gui/Sconscript @@ -26,6 +26,7 @@ def GuiTest(name): env.UsePackage("gmodule-export-2.0") res += [ GuiTest("builder") ] res += [ GuiTest("settings") ] +res += [ GuiTest("queue") ] res += [ GuiTest("window") ] res += [ GuiTest("sidebar") ] res += [ GuiTest("collection") ] diff --git a/tests/gui/queue.c b/tests/gui/queue.c new file mode 100644 index 00000000..2cdce96d --- /dev/null +++ b/tests/gui/queue.c @@ -0,0 +1,32 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#include +#include + +void __test_queue_clear(struct queue *queue, unsigned int n) {} + +static const struct queue_ops test_ops = { + .qop_init = gui_queue_alloc, + .qop_deinit = gui_queue_free, + .qop_cleared = __test_queue_clear, +}; + +static void test_queue() +{ + struct gui_queue *gq; + struct queue q; + + queue_init(&q, 0, &test_ops); + gq = gui_queue(&q); + + test_not_equal((void *)gq, NULL); + test_equal((void *)gq->gq_queue, (void *)&q); + + queue_deinit(&q); + test_equal((void *)gui_queue(&q), NULL); +} + +DECLARE_UNIT_TESTS( + UNIT_TEST("Queue", test_queue), +);