1 /* GStreamer unit test for queue
3 * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
4 * Copyright (C) 2009 Mark Nauwelaerts <mnauw users sourceforge net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include <gst/check/gstcheck.h>
27 modify_caps (GstObject * pad, GstEvent * event, gpointer data)
29 GstElement *filter = GST_ELEMENT (data);
32 fail_unless (event != NULL);
33 fail_unless (GST_IS_EVENT (event));
35 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
38 /* trigger caps negotiation error */
39 caps = gst_caps_new_simple ("video/x-raw-rgb", NULL);
40 g_object_set (filter, "caps", caps, NULL);
41 gst_caps_unref (caps);
46 GST_START_TEST (test_queue)
48 GstStateChangeReturn state_ret;
50 GstElement *pipeline, *filter, *queue;
55 g_strdup_printf ("fakesrc num-buffers=1 ! video/x-raw-yuv ! "
56 "queue min-threshold-buffers=2 name=queue ! "
57 "capsfilter name=nasty ! fakesink");
59 pipeline = gst_parse_launch (pipe_desc, NULL);
60 fail_unless (pipeline != NULL);
63 filter = gst_bin_get_by_name (GST_BIN (pipeline), "nasty");
64 fail_unless (filter != NULL);
66 /* queue waits for all data and EOS to arrive */
67 /* then probe forces downstream element to return negotiation error */
68 queue = gst_bin_get_by_name (GST_BIN (pipeline), "queue");
69 fail_unless (queue != NULL);
70 pad = gst_element_get_static_pad (queue, "sink");
71 fail_unless (pad != NULL);
72 probe = gst_pad_add_event_probe (pad, G_CALLBACK (modify_caps), filter);
74 bus = gst_element_get_bus (pipeline);
76 state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
77 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
79 msg = gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS, 5 * GST_SECOND);
80 fail_unless (msg != NULL, "timeout waiting for error or eos message");;
82 gst_message_unref (msg);
83 gst_object_unref (bus);
85 fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
86 GST_STATE_CHANGE_SUCCESS);
88 gst_pad_remove_event_probe (pad, probe);
89 gst_object_unref (queue);
90 gst_object_unref (pad);
91 gst_object_unref (filter);
92 gst_object_unref (pipeline);
100 Suite *s = suite_create ("queue");
101 TCase *tc_chain = tcase_create ("general");
103 suite_add_tcase (s, tc_chain);
104 tcase_add_test (tc_chain, test_queue);
109 GST_CHECK_MAIN (queue)