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>
This commit is contained in:
Philip Withnall 2019-04-30 10:24:37 +01:00
parent 2aa71ab63b
commit f033948998

View File

@ -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);