[glib: 1/2] Improve test coverage of glib/tests/asyncqueue.c




commit aa99af54aa84502164ce5eaba1455ce50c605029
Author: Emmanuel Fleury <emmanuel fleury gmail com>
Date:   Fri Dec 17 11:57:25 2021 +0100

    Improve test coverage of glib/tests/asyncqueue.c

 glib/tests/asyncqueue.c | 211 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 205 insertions(+), 6 deletions(-)
---
diff --git a/glib/tests/asyncqueue.c b/glib/tests/asyncqueue.c
index de8c47e07..792b0113a 100644
--- a/glib/tests/asyncqueue.c
+++ b/glib/tests/asyncqueue.c
@@ -51,6 +51,41 @@ void test_async_queue_sort (void)
 
   g_async_queue_sort (q, compare_func, NULL);
 
+  if (g_test_undefined ())
+    {
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_push_sorted (NULL, GINT_TO_POINTER (1),
+                                 compare_func, NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_push_sorted_unlocked (NULL, GINT_TO_POINTER (1),
+                                          compare_func, NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_sort (NULL, compare_func, NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_sort (q, NULL, NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_sort_unlocked (NULL, compare_func, NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_sort_unlocked (q, NULL, NULL);
+      g_test_assert_expected_messages ();
+    }
+
   g_async_queue_push_sorted (q, GINT_TO_POINTER (1), compare_func, NULL);
   g_async_queue_push_sorted (q, GINT_TO_POINTER (8), compare_func, NULL);
 
@@ -183,11 +218,24 @@ test_async_queue_timed (void)
   gint64 start, end, diff;
   gpointer val;
 
+  g_get_current_time (&tv);
+  if (g_test_undefined ())
+    {
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_timed_pop (NULL, &tv);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_timed_pop_unlocked (NULL, &tv);
+      g_test_assert_expected_messages ();
+    }
+
   q = g_async_queue_new ();
 
   start = g_get_monotonic_time ();
-  val = g_async_queue_timeout_pop (q, G_USEC_PER_SEC / 10);
-  g_assert_null (val);
+  g_assert_null (g_async_queue_timeout_pop (q, G_USEC_PER_SEC / 10));
 
   end = g_get_monotonic_time ();
   diff = end - start;
@@ -197,24 +245,32 @@ test_async_queue_timed (void)
    */
   g_assert_cmpint (diff, <, 2 * G_USEC_PER_SEC);
 
+  g_async_queue_push (q, GINT_TO_POINTER (10));
+  val = g_async_queue_timed_pop (q, NULL);
+  g_assert_cmpint (GPOINTER_TO_INT (val), ==, 10);
+  g_assert_null (g_async_queue_try_pop (q));
+
   start = end;
   g_get_current_time (&tv);
   g_time_val_add (&tv, G_USEC_PER_SEC / 10);
-  val = g_async_queue_timed_pop (q, &tv);
-  g_assert_null (val);
+  g_assert_null (g_async_queue_timed_pop (q, &tv));
 
   end = g_get_monotonic_time ();
   diff = end - start;
   g_assert_cmpint (diff, >=, G_USEC_PER_SEC / 10);
   g_assert_cmpint (diff, <, 2 * G_USEC_PER_SEC);
 
+  g_async_queue_push (q, GINT_TO_POINTER (10));
+  val = g_async_queue_timed_pop_unlocked (q, NULL);
+  g_assert_cmpint (GPOINTER_TO_INT (val), ==, 10);
+  g_assert_null (g_async_queue_try_pop (q));
+
   start = end;
   g_get_current_time (&tv);
   g_time_val_add (&tv, G_USEC_PER_SEC / 10);
   g_async_queue_lock (q);
-  val = g_async_queue_timed_pop_unlocked (q, &tv);
+  g_assert_null (g_async_queue_timed_pop_unlocked (q, &tv));
   g_async_queue_unlock (q);
-  g_assert_null (val);
 
   end = g_get_monotonic_time ();
   diff = end - start;
@@ -231,6 +287,29 @@ test_async_queue_remove (void)
 
   q = g_async_queue_new ();
 
+  if (g_test_undefined ())
+    {
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_remove (NULL, GINT_TO_POINTER (1));
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_remove (q, NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_remove_unlocked (NULL, GINT_TO_POINTER (1));
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_remove_unlocked (q, NULL);
+      g_test_assert_expected_messages ();
+    }
+
   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));
@@ -254,6 +333,29 @@ test_async_queue_push_front (void)
 
   q = g_async_queue_new ();
 
+  if (g_test_undefined ())
+    {
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_push_front (NULL, GINT_TO_POINTER (1));
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_push_front (q, NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_push_front_unlocked (NULL, GINT_TO_POINTER (1));
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_push_front_unlocked (q, NULL);
+      g_test_assert_expected_messages ();
+    }
+
   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));
@@ -278,7 +380,104 @@ test_basics (void)
 
   destroy_count = 0;
 
+  if (g_test_undefined ())
+    {
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_length (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_length_unlocked (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_ref (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_ref_unlocked (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_unref (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_unref_and_unlock (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_lock (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_unlock (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_pop (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_pop_unlocked (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_try_pop (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_try_pop_unlocked (NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_timeout_pop (NULL, 1);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_timeout_pop_unlocked (NULL, 1);
+      g_test_assert_expected_messages ();
+    }
+
   q = g_async_queue_new_full (destroy_notify);
+
+  if (g_test_undefined ())
+    {
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_push (NULL, GINT_TO_POINTER (1));
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_push (q, NULL);
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_push_unlocked (NULL, GINT_TO_POINTER (1));
+      g_test_assert_expected_messages ();
+
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "*assertion* failed*");
+      g_async_queue_push_unlocked (q, NULL);
+      g_test_assert_expected_messages ();
+    }
+
   g_async_queue_lock (q);
   g_async_queue_ref (q);
   g_async_queue_unlock (q);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]