Git init
[framework/multimedia/gstreamer0.10.git] / tests / check / pipelines / queue-error.c
1 /* GStreamer unit test for queue
2  *
3  * Copyright (C) 2007 Tim-Philipp Müller  <tim centricular net>
4  * Copyright (C) 2009 Mark Nauwelaerts  <mnauw users sourceforge net>
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 #include <gst/check/gstcheck.h>
23
24 #include <gst/gst.h>
25
26 static gboolean
27 modify_caps (GstObject * pad, GstEvent * event, gpointer data)
28 {
29   GstElement *filter = GST_ELEMENT (data);
30   GstCaps *caps;
31
32   fail_unless (event != NULL);
33   fail_unless (GST_IS_EVENT (event));
34
35   if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
36     return TRUE;
37
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);
42
43   return TRUE;
44 }
45
46 GST_START_TEST (test_queue)
47 {
48   GstStateChangeReturn state_ret;
49   GstMessage *msg;
50   GstElement *pipeline, *filter, *queue;
51   GstBus *bus;
52   GstPad *pad;
53   guint probe;
54   gchar *pipe_desc =
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");
58
59   pipeline = gst_parse_launch (pipe_desc, NULL);
60   fail_unless (pipeline != NULL);
61   g_free (pipe_desc);
62
63   filter = gst_bin_get_by_name (GST_BIN (pipeline), "nasty");
64   fail_unless (filter != NULL);
65
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);
73
74   bus = gst_element_get_bus (pipeline);
75
76   state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
77   fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
78
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");;
81
82   gst_message_unref (msg);
83   gst_object_unref (bus);
84
85   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
86       GST_STATE_CHANGE_SUCCESS);
87
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);
93 }
94
95 GST_END_TEST;
96
97 static Suite *
98 queue_suite (void)
99 {
100   Suite *s = suite_create ("queue");
101   TCase *tc_chain = tcase_create ("general");
102
103   suite_add_tcase (s, tc_chain);
104   tcase_add_test (tc_chain, test_queue);
105
106   return s;
107 }
108
109 GST_CHECK_MAIN (queue)