X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Ftests%2Fqueue.c;h=f7c727692abbd900bdbe9afc23b8958ead740dcf;hb=49a5d0f6f2aed99cd78f25655f137f4448e47d92;hp=3aeea56522e2b6d7b8b4427e9934c2fc58d648ed;hpb=29f2ced8eb32d9001da8082c4530f017decb8267;p=platform%2Fupstream%2Fglib.git diff --git a/glib/tests/queue.c b/glib/tests/queue.c index 3aeea56..f7c7276 100644 --- a/glib/tests/queue.c +++ b/glib/tests/queue.c @@ -498,8 +498,9 @@ random_test (gconstpointer d) case REMOVE: if (!g_queue_is_empty (q)) g_queue_remove (q, qinf->tail->data); + /* qinf->head/qinf->tail may be invalid at this point */ if (!g_queue_is_empty (q)) - g_queue_remove (q, qinf->head->data); + g_queue_remove (q, q->head->data); if (!g_queue_is_empty (q)) g_queue_remove (q, g_queue_peek_nth (q, get_random_position (q, TRUE))); @@ -510,8 +511,9 @@ random_test (gconstpointer d) case REMOVE_ALL: if (!g_queue_is_empty (q)) g_queue_remove_all (q, qinf->tail->data); + /* qinf->head/qinf->tail may be invalid at this point */ if (!g_queue_is_empty (q)) - g_queue_remove_all (q, qinf->head->data); + g_queue_remove_all (q, q->head->data); if (!g_queue_is_empty (q)) g_queue_remove_all (q, g_queue_peek_nth (q, get_random_position (q, TRUE))); @@ -1028,6 +1030,55 @@ test_clear (void) g_queue_free (q); } +typedef struct +{ + gboolean freed; + int x; +} QueueItem; + +static void +free_func (gpointer data) +{ + QueueItem *item = data; + + item->freed = TRUE; +} + +static QueueItem * +new_item (int x) +{ + QueueItem *item; + + item = g_slice_new (QueueItem); + item->freed = FALSE; + item->x = x; + + return item; +} + +static void +test_free_full (void) +{ + QueueItem *one, *two, *three; + GQueue *queue = NULL; + + 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_assert (!one->freed); + g_assert (!two->freed); + g_assert (!three->freed); + g_queue_free_full (queue, free_func); + g_assert (one->freed); + g_assert (two->freed); + g_assert (three->freed); + g_slice_free (QueueItem, one); + g_slice_free (QueueItem, two); + g_slice_free (QueueItem, three); +} + + int main (int argc, char *argv[]) { guint32 seed; @@ -1041,6 +1092,7 @@ int main (int argc, char *argv[]) g_test_add_func ("/queue/find-custom", test_find_custom); g_test_add_func ("/queue/static", test_static); g_test_add_func ("/queue/clear", test_clear); + g_test_add_func ("/queue/free-full", test_free_full); seed = g_test_rand_int_range (0, G_MAXINT); path = g_strdup_printf ("/queue/random/seed:%u", seed);