Add tests for new GAsyncQueue api
authorMatthias Clasen <mclasen@redhat.com>
Mon, 22 Jun 2015 15:35:06 +0000 (11:35 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 29 Jun 2015 15:20:26 +0000 (08:20 -0700)
https://bugzilla.gnome.org/show_bug.cgi?id=751160

glib/tests/asyncqueue.c

index 5ccbb23..4a81d23 100644 (file)
@@ -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 ();
 }