[glib: 2/5] tests: Add a test for calling g_queue_clear_full() with a NULL free_func



commit f033948998c63993bc57743b4189a3b58bc1e782
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Apr 30 10:24:37 2019 +0100

    tests: Add a test for calling g_queue_clear_full() with a NULL free_func
    
    This improves the branch coverage of gqueue.c a little.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 glib/tests/queue.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
---
diff --git a/glib/tests/queue.c b/glib/tests/queue.c
index f9e9281fb..7b2bb8749 100644
--- a/glib/tests/queue.c
+++ b/glib/tests/queue.c
@@ -1093,6 +1093,38 @@ test_clear_full (void)
   g_queue_free (queue);
 }
 
+/* Check that g_queue_clear_full() called with a NULL free_func is equivalent
+ * to g_queue_clear(). */
+static void
+test_clear_full_noop (void)
+{
+  QueueItem *one, *two, *three, *four;
+  GQueue *queue;
+
+  queue = g_queue_new ();
+  g_queue_push_tail (queue, one = new_item (1));
+  g_queue_push_tail (queue, two = new_item (2));
+  g_queue_push_tail (queue, three = new_item (3));
+  g_queue_push_tail (queue, four = new_item (4));
+
+  g_assert_cmpint (g_queue_get_length (queue), ==, 4);
+  g_assert_false (one->freed);
+  g_assert_false (two->freed);
+  g_assert_false (three->freed);
+  g_assert_false (four->freed);
+
+  g_queue_clear_full (queue, NULL);
+
+  g_assert_true (g_queue_is_empty (queue));
+  check_integrity (queue);
+
+  g_slice_free (QueueItem, one);
+  g_slice_free (QueueItem, two);
+  g_slice_free (QueueItem, three);
+  g_slice_free (QueueItem, four);
+  g_queue_free (queue);
+}
+
 static void
 test_free_full (void)
 {
@@ -1165,6 +1197,7 @@ int main (int argc, char *argv[])
   g_test_add_func ("/queue/clear", test_clear);
   g_test_add_func ("/queue/free-full", test_free_full);
   g_test_add_func ("/queue/clear-full", test_clear_full);
+  g_test_add_func ("/queue/clear-full/noop", test_clear_full_noop);
   g_test_add_func ("/queue/insert-sibling-link", test_insert_sibling_link);
 
   seed = g_test_rand_int_range (0, G_MAXINT);


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