3 * unit test for GstQueueArray
5 * Copyright (C) <2009> Edward Hervey <bilboed@bilboed.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
28 #include <gst/check/gstcheck.h>
29 #include "../../../plugins/elements/gstqueuearray.h"
30 #include "../../../plugins/elements/gstqueuearray.c"
36 GST_START_TEST (test_array_1)
41 /* Create an array of initial size 10 */
42 array = gst_queue_array_new (10);
44 /* push 5 values in */
45 for (i = 0; i < 5; i++)
46 gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
48 fail_unless_equals_int (array->length, 5);
50 /* pull 5 values out */
51 for (i = 0; i < 5; i++) {
52 fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
56 fail_unless_equals_int (array->length, 0);
58 gst_queue_array_free (array);
63 GST_START_TEST (test_array_grow)
68 /* Create an array of initial size 10 */
69 array = gst_queue_array_new (10);
70 fail_unless_equals_int (array->size, 10);
72 /* push 10 values in */
73 for (i = 0; i < 10; i++)
74 gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
76 fail_unless_equals_int (array->length, 10);
77 /* It did not grow beyond initial size */
78 fail_unless_equals_int (array->size, 10);
79 /* The head is still at the beginning */
80 fail_unless_equals_int (array->head, 0);
81 /* The tail wrapped around to the head */
82 fail_unless_equals_int (array->tail, 0);
85 /* If we add one value, it will grow */
86 gst_queue_array_push_tail (array, GINT_TO_POINTER (10));
88 fail_unless_equals_int (array->length, 11);
89 /* It did grow beyond initial size */
90 fail_unless_equals_int (array->size, 15);
91 /* The head remains the same */
92 fail_unless_equals_int (array->head, 0);
93 /* The tail was brought to position 11 */
94 fail_unless_equals_int (array->tail, 11);
96 /* pull the 11 values out */
97 for (i = 0; i < 11; i++) {
98 fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
102 fail_unless_equals_int (array->length, 0);
103 gst_queue_array_free (array);
108 GST_START_TEST (test_array_grow_multiple)
110 GstQueueArray *array;
113 /* Create an array of initial size 10 */
114 array = gst_queue_array_new (10);
115 fail_unless_equals_int (array->size, 10);
117 /* push 11 values in */
118 for (i = 0; i < 11; i++)
119 gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
121 /* With 11 values, it should have grown once (15) */
122 fail_unless_equals_int (array->length, 11);
123 fail_unless_equals_int (array->size, 15);
125 for (i = 11; i < 20; i++)
126 gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
128 /* With 20 total values, it should have grown another time (3 * 15) / 2 = 22) */
129 fail_unless_equals_int (array->length, 20);
130 /* It did grow beyond initial size */
131 fail_unless_equals_int (array->size, 22);
133 /* pull the 20 values out */
134 for (i = 0; i < 20; i++) {
135 fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
139 fail_unless_equals_int (array->length, 0);
140 gst_queue_array_free (array);
145 GST_START_TEST (test_array_grow_middle)
147 GstQueueArray *array;
150 /* Create an array of initial size 10 */
151 array = gst_queue_array_new (10);
152 fail_unless_equals_int (array->size, 10);
154 /* push/pull 5 values to end up in the middle */
155 for (i = 0; i < 5; i++) {
156 gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
157 fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
161 /* push 10 values in */
162 for (i = 0; i < 10; i++)
163 gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
165 fail_unless_equals_int (array->length, 10);
166 /* It did not grow beyond initial size */
167 fail_unless_equals_int (array->size, 10);
169 /* If we add one value, it will grow */
170 gst_queue_array_push_tail (array, GINT_TO_POINTER (10));
171 fail_unless_equals_int (array->length, 11);
172 /* It did grow beyond initial size */
173 fail_unless_equals_int (array->size, 15);
175 /* pull the 11 values out */
176 for (i = 0; i < 11; i++) {
177 fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
181 fail_unless_equals_int (array->length, 0);
182 gst_queue_array_free (array);
187 GST_START_TEST (test_array_grow_end)
189 GstQueueArray *array;
192 /* Create an array of initial size 10 */
193 array = gst_queue_array_new (10);
194 fail_unless_equals_int (array->size, 10);
196 /* push/pull 9 values to end up at the last position */
197 for (i = 0; i < 9; i++) {
198 gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
199 fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
203 /* push 10 values in */
204 for (i = 0; i < 10; i++)
205 gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
207 fail_unless_equals_int (array->length, 10);
208 /* It did not grow beyond initial size */
209 fail_unless_equals_int (array->size, 10);
211 /* If we add one value, it will grow */
212 gst_queue_array_push_tail (array, GINT_TO_POINTER (10));
213 fail_unless_equals_int (array->length, 11);
214 /* It did grow beyond initial size */
215 fail_unless_equals_int (array->size, 15);
217 /* pull the 11 values out */
218 for (i = 0; i < 11; i++) {
219 fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
223 fail_unless_equals_int (array->length, 0);
224 gst_queue_array_free (array);
230 gst_queue_array_suite (void)
232 Suite *s = suite_create ("GstQueueArray");
233 TCase *tc_chain = tcase_create ("general");
235 suite_add_tcase (s, tc_chain);
237 tcase_add_test (tc_chain, test_array_1);
238 tcase_add_test (tc_chain, test_array_grow);
239 tcase_add_test (tc_chain, test_array_grow_multiple);
240 tcase_add_test (tc_chain, test_array_grow_middle);
241 tcase_add_test (tc_chain, test_array_grow_end);
247 GST_CHECK_MAIN (gst_queue_array);