2009-09-29 07:06:13 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* unit test for GstQueueArray
|
|
|
|
*
|
|
|
|
* Copyright (C) <2009> Edward Hervey <bilboed@bilboed.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-09-29 07:06:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/check/gstcheck.h>
|
2012-10-25 13:27:23 +00:00
|
|
|
#include <gst/base/gstqueuearray.h>
|
2009-09-29 07:06:13 +00:00
|
|
|
|
|
|
|
/* Simplest test
|
|
|
|
* Initial size : 10
|
|
|
|
* Add 10, Remove 10
|
|
|
|
*/
|
|
|
|
GST_START_TEST (test_array_1)
|
|
|
|
{
|
|
|
|
GstQueueArray *array;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* Create an array of initial size 10 */
|
|
|
|
array = gst_queue_array_new (10);
|
|
|
|
|
|
|
|
/* push 5 values in */
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
|
|
|
|
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 5);
|
2009-09-29 07:06:13 +00:00
|
|
|
|
|
|
|
/* pull 5 values out */
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 0);
|
2009-09-29 07:06:13 +00:00
|
|
|
|
|
|
|
gst_queue_array_free (array);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_array_grow)
|
|
|
|
{
|
|
|
|
GstQueueArray *array;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* Create an array of initial size 10 */
|
|
|
|
array = gst_queue_array_new (10);
|
|
|
|
|
|
|
|
/* push 10 values in */
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
|
|
|
|
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 10);
|
2009-09-29 07:06:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* If we add one value, it will grow */
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (10));
|
|
|
|
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 11);
|
2009-09-29 07:06:13 +00:00
|
|
|
|
|
|
|
/* pull the 11 values out */
|
|
|
|
for (i = 0; i < 11; i++) {
|
|
|
|
fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 0);
|
2009-09-29 07:06:13 +00:00
|
|
|
gst_queue_array_free (array);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_array_grow_multiple)
|
|
|
|
{
|
|
|
|
GstQueueArray *array;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* Create an array of initial size 10 */
|
|
|
|
array = gst_queue_array_new (10);
|
|
|
|
|
|
|
|
/* push 11 values in */
|
|
|
|
for (i = 0; i < 11; i++)
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
|
|
|
|
|
|
|
|
/* With 11 values, it should have grown once (15) */
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 11);
|
2009-09-29 07:06:13 +00:00
|
|
|
|
|
|
|
for (i = 11; i < 20; i++)
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
|
|
|
|
|
|
|
|
/* With 20 total values, it should have grown another time (3 * 15) / 2 = 22) */
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 20);
|
2009-09-29 07:06:13 +00:00
|
|
|
/* It did grow beyond initial size */
|
|
|
|
|
|
|
|
/* pull the 20 values out */
|
|
|
|
for (i = 0; i < 20; i++) {
|
|
|
|
fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 0);
|
2009-09-29 07:06:13 +00:00
|
|
|
gst_queue_array_free (array);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_array_grow_middle)
|
|
|
|
{
|
|
|
|
GstQueueArray *array;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* Create an array of initial size 10 */
|
|
|
|
array = gst_queue_array_new (10);
|
|
|
|
|
|
|
|
/* push/pull 5 values to end up in the middle */
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
|
|
|
|
fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* push 10 values in */
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
|
|
|
|
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 10);
|
2009-09-29 07:06:13 +00:00
|
|
|
|
|
|
|
/* If we add one value, it will grow */
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (10));
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 11);
|
2009-09-29 07:06:13 +00:00
|
|
|
|
|
|
|
/* pull the 11 values out */
|
|
|
|
for (i = 0; i < 11; i++) {
|
|
|
|
fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 0);
|
2009-09-29 07:06:13 +00:00
|
|
|
gst_queue_array_free (array);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_array_grow_end)
|
|
|
|
{
|
|
|
|
GstQueueArray *array;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* Create an array of initial size 10 */
|
|
|
|
array = gst_queue_array_new (10);
|
|
|
|
|
|
|
|
/* push/pull 9 values to end up at the last position */
|
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
|
|
|
|
fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* push 10 values in */
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
|
|
|
|
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 10);
|
2009-09-29 07:06:13 +00:00
|
|
|
|
|
|
|
/* If we add one value, it will grow */
|
|
|
|
gst_queue_array_push_tail (array, GINT_TO_POINTER (10));
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 11);
|
2009-09-29 07:06:13 +00:00
|
|
|
|
|
|
|
/* pull the 11 values out */
|
|
|
|
for (i = 0; i < 11; i++) {
|
|
|
|
fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_pop_head (array)),
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
|
2012-10-25 13:27:23 +00:00
|
|
|
fail_unless_equals_int (gst_queue_array_get_length (array), 0);
|
2009-09-29 07:06:13 +00:00
|
|
|
gst_queue_array_free (array);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
static Suite *
|
|
|
|
gst_queue_array_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("GstQueueArray");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
|
|
|
|
|
|
tcase_add_test (tc_chain, test_array_1);
|
|
|
|
tcase_add_test (tc_chain, test_array_grow);
|
|
|
|
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);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GST_CHECK_MAIN (gst_queue_array);
|