summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Schrab <alexas@axis.com>2013-01-30 09:11:24 +0100
committerTim-Philipp Müller <tim@centricular.net>2013-01-30 11:11:51 +0000
commit53a7fe04a0fc64d6e11d53291d7b22d999fe0b5d (patch)
tree19992080906e4602e17c405e92b7a94e94274c6e
parent0b2ccd5ff14c2f217bd0057555c63fc5925f18a3 (diff)
tests: add checks for gst_queue_array_find() and _drop_element()
https://bugzilla.gnome.org/show_bug.cgi?id=692691
-rw-r--r--tests/check/libs/queuearray.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/tests/check/libs/queuearray.c b/tests/check/libs/queuearray.c
index ca5024bce..586fa8ab6 100644
--- a/tests/check/libs/queuearray.c
+++ b/tests/check/libs/queuearray.c
@@ -226,6 +226,150 @@ GST_START_TEST (test_array_grow_end)
GST_END_TEST;
+static int
+compare_pointer_value (gconstpointer a, gconstpointer b)
+{
+ return (int) ((guintptr) a - (guintptr) b);
+}
+
+GST_START_TEST (test_array_find)
+{
+ GstQueueArray *array;
+ guint i;
+ guint index;
+
+ guint random_initial = g_random_int_range (10, 100);
+ guint value_to_find = 5;
+
+ /* Create an array of initial size 10 */
+ array = gst_queue_array_new (10);
+ fail_unless_equals_int (array->size, 10);
+
+ while (random_initial--) {
+ gst_queue_array_push_tail (array, GINT_TO_POINTER (g_random_int ()));
+ gst_queue_array_pop_head (array);
+ }
+
+ /* push 10 values in */
+ for (i = 0; i < 10; i++)
+ gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
+
+ fail_unless_equals_int (array->length, 10);
+ fail_unless_equals_int (array->size, 10);
+
+ index =
+ gst_queue_array_find (array, compare_pointer_value,
+ GINT_TO_POINTER (value_to_find));
+ fail_if (index == -1);
+ fail_unless_equals_int (value_to_find, GPOINTER_TO_INT (array->array[index]));
+
+ /* push 10 values in */
+ for (i = 0; i < 10; i++)
+ gst_queue_array_pop_head (array);
+
+ index =
+ gst_queue_array_find (array, compare_pointer_value,
+ GINT_TO_POINTER (value_to_find));
+ fail_unless (index == -1);
+
+ gst_queue_array_free (array);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_array_drop)
+{
+ GstQueueArray *array;
+ guint i;
+ guint index;
+ guint index_2;
+
+ /* Create an array of initial size 10 */
+ array = gst_queue_array_new (10);
+ fail_unless_equals_int (array->size, 10);
+
+ for (i = 0; i < 5; i++)
+ gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
+
+ fail_unless (array->length == 5);
+
+ /* Naive case remove head */
+ index =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (0));
+ fail_if (index == -1);
+ gst_queue_array_drop_element (array, index);
+ fail_unless (array->length == 4);
+ index =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (0));
+ fail_unless (index == -1);
+
+ /* Naive case remove tail */
+ index =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (4));
+ fail_if (index == -1);
+ gst_queue_array_drop_element (array, index);
+ fail_unless (array->length == 3);
+ index =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (4));
+ fail_unless (index == -1);
+
+ /* Remove in middle of non-wrapped */
+ index =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (2));
+ index_2 =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (3));
+ fail_if (index == -1);
+ fail_if (index_2 == -1);
+ gst_queue_array_drop_element (array, index);
+ fail_unless (array->length == 2);
+ index =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (2));
+ fail_unless (index == -1);
+ index_2 =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (3));
+ fail_if (index_2 == -1);
+
+ /* Remove the rest */
+ while (array->length)
+ gst_queue_array_pop_head (array);
+
+ /* Add until wrapping */
+ for (i = 0; i < 9; i++)
+ gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
+
+ fail_unless (array->head > array->tail);
+
+ /* Remove from between head and array end */
+ index =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (1));
+ fail_if (index == -1);
+ fail_unless (index > array->head);
+ index_2 = array->head;
+ gst_queue_array_drop_element (array, index);
+ fail_unless (array->length == 8);
+ fail_if (array->head == index_2);
+ index =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (1));
+ fail_unless (index == -1);
+
+ /* Remove from between head and array end */
+ index =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (8));
+ fail_if (index == -1);
+ fail_unless (index < array->tail);
+ index_2 = array->tail;
+ gst_queue_array_drop_element (array, index);
+ fail_unless (array->length == 7);
+ fail_if (array->tail == index_2);
+ index =
+ gst_queue_array_find (array, compare_pointer_value, GINT_TO_POINTER (8));
+ fail_unless (index == -1);
+
+ gst_queue_array_free (array);
+}
+
+GST_END_TEST;
+
static Suite *
gst_queue_array_suite (void)
{
@@ -239,6 +383,8 @@ gst_queue_array_suite (void)
tcase_add_test (tc_chain, test_array_grow_multiple);
tcase_add_test (tc_chain, test_array_grow_middle);
tcase_add_test (tc_chain, test_array_grow_end);
+ tcase_add_test (tc_chain, test_array_find);
+ tcase_add_test (tc_chain, test_array_drop);
return s;
}