From 26d87927109d0758775e5455d4c0a22c1b3f9f75 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 22 Jun 2015 11:35:06 -0400 Subject: [PATCH] Add tests for new GAsyncQueue api https://bugzilla.gnome.org/show_bug.cgi?id=751160 --- glib/tests/asyncqueue.c | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/glib/tests/asyncqueue.c b/glib/tests/asyncqueue.c index 5ccbb23b3..4a81d230c 100644 --- a/glib/tests/asyncqueue.c +++ b/glib/tests/asyncqueue.c @@ -220,6 +220,52 @@ test_async_queue_timed (void) g_async_queue_unref (q); } +static void +test_async_queue_remove (void) +{ + GAsyncQueue *q; + + q = g_async_queue_new (); + + g_async_queue_push (q, GINT_TO_POINTER (10)); + g_async_queue_push (q, GINT_TO_POINTER (2)); + g_async_queue_push (q, GINT_TO_POINTER (7)); + g_async_queue_push (q, GINT_TO_POINTER (1)); + + g_async_queue_remove (q, GINT_TO_POINTER (7)); + + g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 10); + g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 2); + g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 1); + + g_assert (g_async_queue_try_pop (q) == NULL); + + g_async_queue_unref (q); +} + +static void +test_async_queue_push_front (void) +{ + GAsyncQueue *q; + + q = g_async_queue_new (); + + g_async_queue_push (q, GINT_TO_POINTER (10)); + g_async_queue_push (q, GINT_TO_POINTER (2)); + g_async_queue_push (q, GINT_TO_POINTER (7)); + + g_async_queue_push_front (q, GINT_TO_POINTER (1)); + + g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 1); + g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 10); + g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 2); + g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 7); + + g_assert (g_async_queue_try_pop (q) == NULL); + + g_async_queue_unref (q); +} + int main (int argc, char *argv[]) { @@ -229,6 +275,8 @@ main (int argc, char *argv[]) g_test_add_func ("/asyncqueue/destroy", test_async_queue_destroy); g_test_add_func ("/asyncqueue/threads", test_async_queue_threads); g_test_add_func ("/asyncqueue/timed", test_async_queue_timed); + g_test_add_func ("/asyncqueue/remove", test_async_queue_remove); + g_test_add_func ("/asyncqueue/push_front", test_async_queue_push_front); return g_test_run (); }