Added unit tests for buffer list support in appsink.

This commit is contained in:
Branko Subasic 2009-06-29 10:24:36 +02:00 committed by Wim Taymans
parent 6518d283d5
commit 55a5679d89

View file

@ -201,6 +201,128 @@ GST_START_TEST (test_notify1)
GST_END_TEST; GST_END_TEST;
static GstBufferList *mylist;
static GstCaps *mycaps;
static GstBufferList *
create_buffer_list (void)
{
GstBufferListIterator *it;
GstBuffer *buffer;
mylist = gst_buffer_list_new ();
fail_if (mylist == NULL);
mycaps = gst_caps_from_string ("application/x-gst-check");
fail_if (mycaps == NULL);
it = gst_buffer_list_iterate (mylist);
fail_if (it == NULL);
gst_buffer_list_iterator_add_group (it);
buffer = gst_buffer_new_and_alloc (sizeof (gint));
*(gint *) GST_BUFFER_DATA (buffer) = 1;
gst_buffer_set_caps (buffer, mycaps);
gst_buffer_list_iterator_add (it, buffer);
gst_buffer_list_iterator_add_group (it);
buffer = gst_buffer_new_and_alloc (sizeof (gint));
*(gint *) GST_BUFFER_DATA (buffer) = 2;
gst_buffer_set_caps (buffer, mycaps);
gst_buffer_list_iterator_add (it, buffer);
buffer = gst_buffer_new_and_alloc (sizeof (gint));
*(gint *) GST_BUFFER_DATA (buffer) = 4;
gst_buffer_set_caps (buffer, mycaps);
gst_buffer_list_iterator_add (it, buffer);
gst_buffer_list_iterator_free (it);
return mylist;
}
static void
check_buffer_list (GstBufferList * list)
{
GstBufferListIterator *it;
GstBuffer *buf;
GstCaps *caps;
fail_unless (list == mylist);
fail_unless (gst_buffer_list_n_groups (list) == 2);
it = gst_buffer_list_iterate (list);
fail_if (it == NULL);
fail_unless (gst_buffer_list_iterator_next_group (it));
fail_unless (gst_buffer_list_iterator_n_buffers (it) == 1);
buf = gst_buffer_list_iterator_next (it);
fail_if (buf == NULL);
fail_unless (*(gint *) GST_BUFFER_DATA (buf) == 1);
caps = gst_buffer_get_caps (buf);
fail_unless (caps == mycaps);
fail_unless (gst_caps_is_equal (caps, mycaps));
gst_caps_unref (caps);
fail_unless (gst_buffer_list_iterator_next_group (it));
fail_unless (gst_buffer_list_iterator_n_buffers (it) == 2);
buf = gst_buffer_list_iterator_next (it);
fail_if (buf == NULL);
fail_unless (*(gint *) GST_BUFFER_DATA (buf) == 2);
caps = gst_buffer_get_caps (buf);
fail_unless (caps == mycaps);
gst_caps_unref (caps);
buf = gst_buffer_list_iterator_next (it);
fail_if (buf == NULL);
fail_unless (*(gint *) GST_BUFFER_DATA (buf) == 4);
caps = gst_buffer_get_caps (buf);
fail_unless (caps == mycaps);
gst_caps_unref (caps);
gst_buffer_list_iterator_free (it);
}
static GstFlowReturn
callback_function_buffer_list (GstAppSink * appsink, gpointer callback_data)
{
GstBufferList *list;
list = gst_app_sink_pull_buffer_list (appsink);
fail_unless (GST_IS_BUFFER_LIST (list));
check_buffer_list (list);
gst_buffer_list_unref (list);
return GST_FLOW_OK;
}
GST_START_TEST (test_buffer_list)
{
GstElement *sink;
GstBufferList *list;
GstAppSinkCallbacks callbacks = { NULL };
sink = setup_appsink ();
callbacks.new_buffer_list = callback_function_buffer_list;
gst_app_sink_set_callbacks (GST_APP_SINK (sink), &callbacks, NULL, NULL);
ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC);
list = create_buffer_list ();
fail_unless (gst_pad_push_list (mysrcpad, list) == GST_FLOW_OK);
ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
cleanup_appsink (sink);
}
GST_END_TEST;
static Suite * static Suite *
appsink_suite (void) appsink_suite (void)
{ {
@ -212,6 +334,7 @@ appsink_suite (void)
tcase_add_test (tc_chain, test_handoff_callback); tcase_add_test (tc_chain, test_handoff_callback);
tcase_add_test (tc_chain, test_notify0); tcase_add_test (tc_chain, test_notify0);
tcase_add_test (tc_chain, test_notify1); tcase_add_test (tc_chain, test_notify1);
tcase_add_test (tc_chain, test_buffer_list);
return s; return s;
} }