tests: Remove funnel pad_alloc test
[platform/upstream/gstreamer.git] / tests / check / elements / funnel.c
1 /* GStreamer unit tests for the funnel
2  *
3  * Copyright (C) 2008 Collabora, Nokia
4  * @author: Olivier Crete <olivier.crete@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 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  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
19 */
20
21
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25
26 #include <gst/check/gstcheck.h>
27
28 struct TestData
29 {
30   GstElement *funnel;
31   GstPad *funnelsrc, *funnelsink11, *funnelsink22;
32   GstPad *mysink, *mysrc1, *mysrc2;
33   GstCaps *mycaps;
34 };
35
36 static void
37 setup_test_objects (struct TestData *td, GstPadChainFunction chain_func)
38 {
39   td->mycaps = gst_caps_new_empty_simple ("test/test");
40
41   td->funnel = gst_element_factory_make ("funnel", NULL);
42
43   td->funnelsrc = gst_element_get_static_pad (td->funnel, "src");
44   fail_unless (td->funnelsrc != NULL);
45
46   td->funnelsink11 = gst_element_get_request_pad (td->funnel, "sink_11");
47   fail_unless (td->funnelsink11 != NULL);
48   fail_unless (!strcmp (GST_OBJECT_NAME (td->funnelsink11), "sink_11"));
49
50   td->funnelsink22 = gst_element_get_request_pad (td->funnel, "sink_22");
51   fail_unless (td->funnelsink22 != NULL);
52   fail_unless (!strcmp (GST_OBJECT_NAME (td->funnelsink22), "sink_22"));
53
54   fail_unless (gst_element_set_state (td->funnel, GST_STATE_PLAYING) ==
55       GST_STATE_CHANGE_SUCCESS);
56
57   td->mysink = gst_pad_new ("sink", GST_PAD_SINK);
58   gst_pad_set_chain_function (td->mysink, chain_func);
59   gst_pad_set_active (td->mysink, TRUE);
60
61   td->mysrc1 = gst_pad_new ("src1", GST_PAD_SRC);
62   gst_pad_set_active (td->mysrc1, TRUE);
63   gst_check_setup_events_with_stream_id (td->mysrc1, td->funnel, td->mycaps,
64       GST_FORMAT_BYTES, "test1");
65
66   td->mysrc2 = gst_pad_new ("src2", GST_PAD_SRC);
67   gst_pad_set_active (td->mysrc2, TRUE);
68   gst_check_setup_events_with_stream_id (td->mysrc2, td->funnel, td->mycaps,
69       GST_FORMAT_BYTES, "test2");
70
71   fail_unless (GST_PAD_LINK_SUCCESSFUL (gst_pad_link (td->funnelsrc,
72               td->mysink)));
73
74   fail_unless (GST_PAD_LINK_SUCCESSFUL (gst_pad_link (td->mysrc1,
75               td->funnelsink11)));
76
77   fail_unless (GST_PAD_LINK_SUCCESSFUL (gst_pad_link (td->mysrc2,
78               td->funnelsink22)));
79
80 }
81
82 static void
83 release_test_objects (struct TestData *td)
84 {
85   gst_pad_set_active (td->mysink, FALSE);
86   gst_pad_set_active (td->mysrc1, FALSE);
87   gst_pad_set_active (td->mysrc1, FALSE);
88
89   gst_object_unref (td->mysink);
90   gst_object_unref (td->mysrc1);
91   gst_object_unref (td->mysrc2);
92
93   fail_unless (gst_element_set_state (td->funnel, GST_STATE_NULL) ==
94       GST_STATE_CHANGE_SUCCESS);
95
96   gst_object_unref (td->funnelsrc);
97   gst_element_release_request_pad (td->funnel, td->funnelsink11);
98   gst_object_unref (td->funnelsink11);
99   gst_element_release_request_pad (td->funnel, td->funnelsink22);
100   gst_object_unref (td->funnelsink22);
101
102   gst_caps_unref (td->mycaps);
103   gst_object_unref (td->funnel);
104 }
105
106 static gint bufcount = 0;
107 static gint alloccount = 0;
108
109 static GstFlowReturn
110 chain_ok (GstPad * pad, GstObject * parent, GstBuffer * buffer)
111 {
112   bufcount++;
113
114   gst_buffer_unref (buffer);
115
116   return GST_FLOW_OK;
117 }
118
119 GST_START_TEST (test_funnel_simple)
120 {
121   struct TestData td;
122
123   setup_test_objects (&td, chain_ok);
124
125   bufcount = 0;
126   alloccount = 0;
127
128   fail_unless (gst_pad_push (td.mysrc1, gst_buffer_new ()) == GST_FLOW_OK);
129   fail_unless (gst_pad_push (td.mysrc2, gst_buffer_new ()) == GST_FLOW_OK);
130
131   fail_unless (bufcount == 2);
132
133   release_test_objects (&td);
134 }
135
136 GST_END_TEST;
137
138 guint num_eos = 0;
139
140 static gboolean
141 eos_event_func (GstPad * pad, GstObject * parent, GstEvent * event)
142 {
143   if (GST_EVENT_TYPE (event) == GST_EVENT_EOS)
144     ++num_eos;
145
146   return gst_pad_event_default (pad, parent, event);
147 }
148
149 GST_START_TEST (test_funnel_eos)
150 {
151   struct TestData td;
152   GstSegment segment;
153
154   setup_test_objects (&td, chain_ok);
155
156   num_eos = 0;
157   bufcount = 0;
158
159   gst_pad_set_event_function (td.mysink, eos_event_func);
160
161   fail_unless (gst_pad_push (td.mysrc1, gst_buffer_new ()) == GST_FLOW_OK);
162   fail_unless (gst_pad_push (td.mysrc2, gst_buffer_new ()) == GST_FLOW_OK);
163
164   fail_unless (bufcount == 2);
165
166   fail_unless (gst_pad_push_event (td.mysrc1, gst_event_new_eos ()));
167   fail_unless (num_eos == 0);
168
169   fail_unless (gst_pad_push (td.mysrc1, gst_buffer_new ()) == GST_FLOW_EOS);
170   fail_unless (gst_pad_push (td.mysrc2, gst_buffer_new ()) == GST_FLOW_OK);
171
172   fail_unless (bufcount == 3);
173
174   fail_unless (gst_pad_push_event (td.mysrc2, gst_event_new_eos ()));
175   fail_unless (num_eos == 1);
176
177   fail_unless (gst_pad_push (td.mysrc1, gst_buffer_new ()) == GST_FLOW_EOS);
178   fail_unless (gst_pad_push (td.mysrc2, gst_buffer_new ()) == GST_FLOW_EOS);
179
180   fail_unless (bufcount == 3);
181
182   fail_unless (gst_pad_push_event (td.mysrc1, gst_event_new_flush_start ()));
183   fail_unless (gst_pad_push_event (td.mysrc1, gst_event_new_flush_stop (TRUE)));
184
185   gst_segment_init (&segment, GST_FORMAT_BYTES);
186   gst_pad_push_event (td.mysrc1, gst_event_new_segment (&segment));
187   gst_pad_push_event (td.mysrc2, gst_event_new_segment (&segment));
188
189   fail_unless (gst_pad_push (td.mysrc1, gst_buffer_new ()) == GST_FLOW_OK);
190   fail_unless (gst_pad_push (td.mysrc2, gst_buffer_new ()) == GST_FLOW_EOS);
191
192   fail_unless (bufcount == 4);
193
194   fail_unless (gst_pad_unlink (td.mysrc1, td.funnelsink11));
195   gst_element_release_request_pad (td.funnel, td.funnelsink11);
196   gst_object_unref (td.funnelsink11);
197   fail_unless (num_eos == 2);
198
199   td.funnelsink11 = gst_element_get_request_pad (td.funnel, "sink_11");
200   fail_unless (td.funnelsink11 != NULL);
201   fail_unless (!strcmp (GST_OBJECT_NAME (td.funnelsink11), "sink_11"));
202
203   fail_unless (GST_PAD_LINK_SUCCESSFUL (gst_pad_link (td.mysrc1,
204               td.funnelsink11)));
205
206   /* This will fail because everything is EOS already */
207   fail_if (gst_pad_push_event (td.mysrc1, gst_event_new_eos ()));
208   fail_unless (num_eos == 2);
209
210   fail_unless (gst_pad_unlink (td.mysrc1, td.funnelsink11));
211   gst_element_release_request_pad (td.funnel, td.funnelsink11);
212   gst_object_unref (td.funnelsink11);
213   fail_unless (num_eos == 2);
214
215   td.funnelsink11 = gst_element_get_request_pad (td.funnel, "sink_11");
216   fail_unless (td.funnelsink11 != NULL);
217   fail_unless (!strcmp (GST_OBJECT_NAME (td.funnelsink11), "sink_11"));
218
219   release_test_objects (&td);
220 }
221
222 GST_END_TEST;
223
224 static Suite *
225 funnel_suite (void)
226 {
227   Suite *s = suite_create ("funnel");
228   TCase *tc_chain;
229
230   tc_chain = tcase_create ("funnel simple");
231   tcase_add_test (tc_chain, test_funnel_simple);
232   tcase_add_test (tc_chain, test_funnel_eos);
233   suite_add_tcase (s, tc_chain);
234
235   return s;
236 }
237
238 GST_CHECK_MAIN (funnel);