2 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
3 * Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
5 * gstbin.c: Unit test for GstBin
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
26 #include <gst/check/gstcheck.h>
27 #include <gst/base/gstbasesrc.h>
30 pop_async_done (GstBus * bus)
34 GST_DEBUG ("popping async-done message");
35 message = gst_bus_poll (bus, GST_MESSAGE_ASYNC_DONE, -1);
37 fail_unless (message && GST_MESSAGE_TYPE (message)
38 == GST_MESSAGE_ASYNC_DONE, "did not get GST_MESSAGE_ASYNC_DONE");
40 gst_message_unref (message);
41 GST_DEBUG ("popped message");
45 pop_messages (GstBus * bus, int count)
51 GST_DEBUG ("popping %d messages", count);
52 for (i = 0; i < count; ++i) {
53 message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
55 fail_unless (message && GST_MESSAGE_TYPE (message)
56 == GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
58 gst_message_unref (message);
60 GST_DEBUG ("popped %d messages", count);
63 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
69 push_one_eos (GstPad * pad)
71 GST_DEBUG_OBJECT (pad, "Pushing EOS event");
72 gst_pad_push_event (pad, gst_event_new_eos ());
78 push_one_stream_start (GstPad * pad)
80 GST_DEBUG_OBJECT (pad, "Pushing STREAM_START event");
81 gst_pad_push_event (pad, gst_event_new_stream_start ("test"));
86 GST_START_TEST (test_interface)
93 bin = GST_BIN (gst_bin_new (NULL));
94 fail_unless (bin != NULL, "Could not create bin");
96 filesrc = gst_element_factory_make ("filesrc", NULL);
97 fail_unless (filesrc != NULL, "Could not create filesrc");
98 fail_unless (GST_IS_URI_HANDLER (filesrc), "Filesrc not a URI handler");
99 gst_bin_add (bin, filesrc);
101 fail_unless (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
102 gst_object_unref (filesrc);
104 it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
105 fail_unless (it != NULL);
106 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
107 fail_unless (g_value_get_object (&item) == (gpointer) filesrc);
108 g_value_reset (&item);
109 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
110 gst_iterator_free (it);
112 gst_bin_add_many (bin,
113 gst_element_factory_make ("identity", NULL),
114 gst_element_factory_make ("identity", NULL),
115 gst_element_factory_make ("identity", NULL), NULL);
116 it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
117 fail_unless (it != NULL);
118 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
119 fail_unless (g_value_get_object (&item) == (gpointer) filesrc);
120 g_value_reset (&item);
121 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
122 gst_iterator_free (it);
125 bin = GST_BIN (gst_bin_new (NULL));
126 fail_unless (bin != NULL);
127 gst_bin_add_many (bin,
128 gst_element_factory_make ("identity", NULL),
129 gst_element_factory_make ("identity", NULL),
130 GST_ELEMENT (bin2), gst_element_factory_make ("identity", NULL), NULL);
131 it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
132 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
133 fail_unless (g_value_get_object (&item) == (gpointer) filesrc);
134 g_value_reset (&item);
135 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
136 gst_iterator_free (it);
138 gst_bin_add (bin, gst_element_factory_make ("filesrc", NULL));
139 gst_bin_add (bin2, gst_element_factory_make ("filesrc", NULL));
140 it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
141 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
142 g_value_reset (&item);
143 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
144 g_value_reset (&item);
145 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
146 g_value_reset (&item);
147 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
148 g_value_unset (&item);
149 gst_iterator_free (it);
151 gst_object_unref (bin);
156 GST_START_TEST (test_eos)
159 GstElement *pipeline, *sink1, *sink2;
162 GThread *thread1, *thread2;
164 pipeline = gst_pipeline_new ("test_eos");
165 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
167 sink1 = gst_element_factory_make ("fakesink", "sink1");
168 sink2 = gst_element_factory_make ("fakesink", "sink2");
170 gst_bin_add_many (GST_BIN (pipeline), sink1, sink2, NULL);
172 pad1 = gst_check_setup_src_pad_by_name (sink1, &srctemplate, "sink");
173 pad2 = gst_check_setup_src_pad_by_name (sink2, &srctemplate, "sink");
175 gst_pad_set_active (pad1, TRUE);
176 gst_pad_set_active (pad2, TRUE);
178 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
179 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
181 /* Send one EOS to sink1 */
182 thread1 = g_thread_new ("thread1", (GThreadFunc) push_one_eos, pad1);
184 /* Make sure the EOS message is not sent */
186 gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS, 2 * GST_SECOND);
187 fail_if (message != NULL);
189 /* Send one EOS to sink2 */
190 thread2 = g_thread_new ("thread2", (GThreadFunc) push_one_eos, pad2);
192 /* Make sure the EOS message is sent then */
193 message = gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS, -1);
194 fail_if (message == NULL);
195 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS);
196 gst_message_unref (message);
199 g_thread_join (thread1);
200 g_thread_join (thread2);
202 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
203 gst_pad_set_active (pad1, FALSE);
204 gst_pad_set_active (pad2, FALSE);
205 gst_check_teardown_src_pad (sink1);
206 gst_check_teardown_src_pad (sink2);
207 gst_object_unref (bus);
208 gst_object_unref (pipeline);
213 GST_START_TEST (test_stream_start)
216 GstElement *pipeline, *sink1, *sink2;
219 GThread *thread1, *thread2;
221 pipeline = gst_pipeline_new ("test_stream_start");
222 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
224 sink1 = gst_element_factory_make ("fakesink", "sink1");
225 sink2 = gst_element_factory_make ("fakesink", "sink2");
227 gst_bin_add_many (GST_BIN (pipeline), sink1, sink2, NULL);
229 pad1 = gst_check_setup_src_pad_by_name (sink1, &srctemplate, "sink");
230 pad2 = gst_check_setup_src_pad_by_name (sink2, &srctemplate, "sink");
232 gst_pad_set_active (pad1, TRUE);
233 gst_pad_set_active (pad2, TRUE);
235 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
236 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
238 /* Send one STREAM_START to sink1 */
239 thread1 = g_thread_new ("thread1", (GThreadFunc) push_one_stream_start, pad1);
241 /* Make sure the STREAM_START message is not sent */
243 gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_STREAM_START,
245 fail_if (message != NULL);
247 /* Send one STREAM_START to sink2 */
248 thread2 = g_thread_new ("thread2", (GThreadFunc) push_one_stream_start, pad2);
250 /* Make sure the STREAM_START message is sent then */
252 gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_STREAM_START, -1);
253 fail_if (message == NULL);
254 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_START);
255 gst_message_unref (message);
258 g_thread_join (thread1);
259 g_thread_join (thread2);
261 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
262 gst_pad_set_active (pad1, FALSE);
263 gst_pad_set_active (pad2, FALSE);
264 gst_check_teardown_src_pad (sink1);
265 gst_check_teardown_src_pad (sink2);
266 gst_object_unref (bus);
267 gst_object_unref (pipeline);
272 GST_START_TEST (test_message_state_changed)
277 GstStateChangeReturn ret;
279 bin = GST_BIN (gst_bin_new (NULL));
280 fail_unless (bin != NULL, "Could not create bin");
281 ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
283 bus = g_object_new (gst_bus_get_type (), NULL);
284 gst_object_ref_sink (bus);
285 gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
287 /* change state, spawning a message, causing an incref on the bin */
288 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
289 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
291 ASSERT_OBJECT_REFCOUNT (bin, "bin", 2);
293 /* get and unref the message, causing a decref on the bin */
294 message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
296 fail_unless (message && GST_MESSAGE_TYPE (message)
297 == GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
299 gst_message_unref (message);
301 ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
303 gst_bus_set_flushing (bus, TRUE);
306 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
307 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
309 gst_object_unref (bus);
310 gst_object_unref (bin);
315 GST_START_TEST (test_message_state_changed_child)
321 GstStateChangeReturn ret;
323 bin = GST_BIN (gst_bin_new (NULL));
324 fail_unless (bin != NULL, "Could not create bin");
325 ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
327 bus = g_object_new (gst_bus_get_type (), NULL);
328 gst_object_ref_sink (bus);
329 gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
331 src = gst_element_factory_make ("fakesrc", NULL);
332 fail_if (src == NULL, "Could not create fakesrc");
333 gst_bin_add (bin, src);
334 ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
335 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
337 /* change state, spawning two messages:
338 * - first for fakesrc, forwarded to bin's bus, causing incref on fakesrc
339 * - second for bin, causing an incref on the bin */
340 GST_DEBUG ("setting bin to READY");
341 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
342 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
344 ASSERT_OBJECT_REFCOUNT (src, "src", 2);
345 ASSERT_OBJECT_REFCOUNT (bin, "bin", 2);
347 /* get and unref the message, causing a decref on the src */
348 message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
349 fail_unless (message && GST_MESSAGE_TYPE (message)
350 == GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
352 fail_unless (message->src == GST_OBJECT (src));
353 gst_message_unref (message);
355 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
356 ASSERT_OBJECT_REFCOUNT (bin, "bin", 2);
358 /* get and unref message 2, causing a decref on the bin */
359 message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
360 fail_unless (message && GST_MESSAGE_TYPE (message)
361 == GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
363 fail_unless (message->src == GST_OBJECT (bin));
364 gst_message_unref (message);
366 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
367 ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
369 gst_bus_set_flushing (bus, TRUE);
372 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
373 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
375 gst_object_unref (bus);
376 gst_object_unref (bin);
381 GST_START_TEST (test_message_state_changed_children)
383 GstPipeline *pipeline;
384 GstElement *src, *sink;
386 GstStateChangeReturn ret;
387 GstState current, pending;
389 pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
390 fail_unless (pipeline != NULL, "Could not create pipeline");
391 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
393 src = gst_element_factory_make ("fakesrc", NULL);
394 fail_if (src == NULL, "Could not create fakesrc");
395 /* need to silence the element as the deep_notify refcounts the
396 * parents while running */
397 g_object_set (G_OBJECT (src), "silent", TRUE, NULL);
398 gst_bin_add (GST_BIN (pipeline), src);
400 sink = gst_element_factory_make ("fakesink", NULL);
401 /* need to silence the element as the deep_notify refcounts the
402 * parents while running */
403 g_object_set (G_OBJECT (sink), "silent", TRUE, NULL);
404 fail_if (sink == NULL, "Could not create fakesink");
405 gst_bin_add (GST_BIN (pipeline), sink);
407 fail_unless (gst_element_link (src, sink), "could not link src and sink");
409 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
410 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
411 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
413 bus = gst_pipeline_get_bus (pipeline);
415 /* change state to READY, spawning three messages */
416 GST_DEBUG ("setting pipeline to READY");
417 ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY);
418 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
420 /* each object is referenced by a message */
421 ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
422 ASSERT_OBJECT_REFCOUNT (src, "src", 2);
423 ASSERT_OBJECT_REFCOUNT (sink, "sink", 2);
424 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 2);
426 pop_messages (bus, 3);
427 fail_if (gst_bus_have_pending (bus), "unexpected pending messages");
429 ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
430 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
431 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
432 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
434 /* change state to PAUSED, spawning four messages */
435 /* STATE_CHANGED (NULL => READY)
438 * STATE_CHANGED (READY => PAUSED)
440 GST_DEBUG ("setting pipeline to PAUSED");
441 ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
442 fail_unless (ret == GST_STATE_CHANGE_ASYNC);
444 gst_element_get_state (GST_ELEMENT (pipeline), ¤t, &pending,
445 GST_CLOCK_TIME_NONE);
446 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
447 fail_unless (current == GST_STATE_PAUSED);
448 fail_unless (pending == GST_STATE_VOID_PENDING);
450 /* wait for async thread to settle down */
451 GST_DEBUG ("waiting for refcount");
452 while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 4)
454 GST_DEBUG ("refcount <= 4 now");
456 /* each object is referenced by a message;
457 * base_src is blocked in the push and has an extra refcount.
458 * base_sink_chain has taken a refcount on the sink, and is blocked on
460 * The stream-status messages holds 2 more refs to the element */
461 ASSERT_OBJECT_REFCOUNT (src, "src", 4);
462 /* refcount can be 4 if the bin is still processing the async_done message of
464 ASSERT_OBJECT_REFCOUNT_BETWEEN (sink, "sink", 2, 3);
465 /* 3 or 4 is valid, because the pipeline might still be posting
466 * its state_change message */
467 ASSERT_OBJECT_REFCOUNT_BETWEEN (pipeline, "pipeline", 3, 4);
469 pop_messages (bus, 3);
470 pop_async_done (bus);
471 fail_if ((gst_bus_pop (bus)) != NULL);
473 ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
474 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
475 ASSERT_OBJECT_REFCOUNT (sink, "sink", 2);
476 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
478 /* change state to PLAYING, spawning three messages */
479 GST_DEBUG ("setting pipeline to PLAYING");
480 ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
481 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
483 gst_element_get_state (GST_ELEMENT (pipeline), ¤t, &pending,
484 GST_CLOCK_TIME_NONE);
485 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
486 fail_unless (current == GST_STATE_PLAYING);
487 fail_unless (pending == GST_STATE_VOID_PENDING);
489 /* each object is referenced by one message
490 * src might have an extra reference if it's still pushing
491 * sink might have an extra reference if it's still blocked on preroll
492 * pipeline posted a new-clock message too. */
493 ASSERT_OBJECT_REFCOUNT_BETWEEN (src, "src", 2, 3);
494 ASSERT_OBJECT_REFCOUNT_BETWEEN (sink, "sink", 2, 4);
495 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 3);
497 pop_messages (bus, 3);
498 fail_if ((gst_bus_pop (bus)) != NULL);
500 ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
501 /* src might have an extra reference if it's still pushing */
502 ASSERT_OBJECT_REFCOUNT_BETWEEN (src, "src", 1, 2);
503 /* sink might have an extra reference if it's still blocked on preroll */
504 ASSERT_OBJECT_REFCOUNT_BETWEEN (sink, "sink", 1, 3);
505 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
507 /* go back to READY, spawning six messages */
508 GST_DEBUG ("setting pipeline to READY");
509 ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY);
510 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
512 /* each object is referenced by two messages, the source also has the
513 * stream-status message referencing it */
514 ASSERT_OBJECT_REFCOUNT (src, "src", 4);
515 ASSERT_OBJECT_REFCOUNT (sink, "sink", 3);
516 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 3);
518 pop_messages (bus, 6);
519 fail_if ((gst_bus_pop (bus)) != NULL);
521 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
522 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
523 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
525 /* setting pipeline to NULL flushes the bus automatically */
526 ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
527 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
529 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
530 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
531 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
534 gst_object_unref (bus);
535 gst_object_unref (pipeline);
540 GST_START_TEST (test_watch_for_state_change)
542 GstElement *src, *sink, *bin;
544 GstStateChangeReturn ret;
546 bin = gst_element_factory_make ("bin", NULL);
547 fail_unless (bin != NULL, "Could not create bin");
549 bus = g_object_new (gst_bus_get_type (), NULL);
550 gst_object_ref_sink (bus);
551 gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
553 src = gst_element_factory_make ("fakesrc", NULL);
554 fail_if (src == NULL, "Could not create fakesrc");
555 sink = gst_element_factory_make ("fakesink", NULL);
556 fail_if (sink == NULL, "Could not create fakesink");
558 gst_bin_add (GST_BIN (bin), sink);
559 gst_bin_add (GST_BIN (bin), src);
561 fail_unless (gst_element_link (src, sink), "could not link src and sink");
563 /* change state, spawning two times three messages */
564 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
565 fail_unless (ret == GST_STATE_CHANGE_ASYNC);
567 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
568 GST_CLOCK_TIME_NONE);
569 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
571 pop_messages (bus, 6);
572 pop_async_done (bus);
574 fail_unless (gst_bus_have_pending (bus) == FALSE,
575 "Unexpected messages on bus");
577 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
578 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
580 pop_messages (bus, 3);
582 /* this one might return either SUCCESS or ASYNC, likely SUCCESS */
583 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
584 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE);
586 pop_messages (bus, 3);
587 if (ret == GST_STATE_CHANGE_ASYNC)
588 pop_async_done (bus);
590 fail_unless (gst_bus_have_pending (bus) == FALSE,
591 "Unexpected messages on bus");
593 gst_bus_set_flushing (bus, TRUE);
595 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
596 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
599 gst_object_unref (bus);
600 gst_object_unref (bin);
605 GST_START_TEST (test_state_change_error_message)
607 GstElement *src, *sink, *bin;
609 GstStateChangeReturn ret;
611 bin = gst_element_factory_make ("bin", NULL);
612 fail_unless (bin != NULL, "Could not create bin");
614 bus = g_object_new (gst_bus_get_type (), NULL);
615 gst_object_ref_sink (bus);
616 gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
618 src = gst_element_factory_make ("fakesrc", NULL);
619 fail_if (src == NULL, "Could not create fakesrc");
620 sink = gst_element_factory_make ("fakesink", NULL);
621 fail_if (sink == NULL, "Could not create fakesink");
623 /* add but don't link elements */
624 gst_bin_add (GST_BIN (bin), sink);
625 gst_bin_add (GST_BIN (bin), src);
627 /* change state, this should succeed */
628 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
629 fail_unless (ret == GST_STATE_CHANGE_ASYNC);
631 /* now wait, the streaming thread will error because the source is not
633 ret = gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
634 GST_CLOCK_TIME_NONE);
635 fail_unless (ret == GST_STATE_CHANGE_FAILURE);
637 gst_bus_set_flushing (bus, TRUE);
639 /* setting bin to NULL flushes the bus automatically */
640 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
641 fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
644 gst_object_unref (bus);
645 gst_object_unref (bin);
651 /* adding an element with linked pads to a bin unlinks the
653 GST_START_TEST (test_add_linked)
655 GstElement *src, *sink;
656 GstPad *srcpad, *sinkpad;
657 GstElement *pipeline;
659 pipeline = gst_pipeline_new (NULL);
660 fail_unless (pipeline != NULL, "Could not create pipeline");
662 src = gst_element_factory_make ("fakesrc", NULL);
663 fail_if (src == NULL, "Could not create fakesrc");
664 sink = gst_element_factory_make ("fakesink", NULL);
665 fail_if (sink == NULL, "Could not create fakesink");
667 srcpad = gst_element_get_static_pad (src, "src");
668 fail_unless (srcpad != NULL);
669 sinkpad = gst_element_get_static_pad (sink, "sink");
670 fail_unless (sinkpad != NULL);
672 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK);
674 /* pads are linked now */
675 fail_unless (gst_pad_is_linked (srcpad));
676 fail_unless (gst_pad_is_linked (sinkpad));
678 /* adding element to bin voids hierarchy so pads are unlinked */
679 gst_bin_add (GST_BIN (pipeline), src);
681 /* check if pads really are unlinked */
682 fail_unless (!gst_pad_is_linked (srcpad));
683 fail_unless (!gst_pad_is_linked (sinkpad));
685 /* cannot link pads in wrong hierarchy */
686 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_WRONG_HIERARCHY);
688 /* adding other element to bin as well */
689 gst_bin_add (GST_BIN (pipeline), sink);
691 /* now we can link again */
692 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK);
694 /* check if pads really are linked */
695 fail_unless (gst_pad_is_linked (srcpad));
696 fail_unless (gst_pad_is_linked (sinkpad));
698 gst_object_unref (srcpad);
699 gst_object_unref (sinkpad);
700 gst_object_unref (pipeline);
705 /* adding ourself should fail */
706 GST_START_TEST (test_add_self)
710 bin = gst_bin_new (NULL);
711 fail_unless (bin != NULL, "Could not create bin");
713 ASSERT_CRITICAL (gst_bin_add (GST_BIN (bin), bin));
715 gst_object_unref (bin);
721 /* g_print ("%10s: %4d => %4d\n", GST_OBJECT_NAME (msg->src), old, new); */
723 #define ASSERT_STATE_CHANGE_MSG(bus,element,old_state,new_state,num) \
726 GstState old = 0, new = 0, pending = 0; \
727 msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); \
728 fail_if (msg == NULL, "No state change message within 1 second (#" \
729 G_STRINGIFY (num) ")"); \
730 gst_message_parse_state_changed (msg, &old, &new, &pending); \
731 fail_if (msg->src != GST_OBJECT (element), G_STRINGIFY(element) \
732 " should have changed state next (#" G_STRINGIFY (num) ")"); \
733 fail_if (old != old_state || new != new_state, "state change is not " \
734 G_STRINGIFY (old_state) " => " G_STRINGIFY (new_state)); \
735 gst_message_unref (msg); \
738 GST_START_TEST (test_children_state_change_order_flagged_sink)
740 GstElement *src, *identity, *sink, *pipeline;
741 GstStateChangeReturn ret;
742 GstState current, pending;
745 pipeline = gst_pipeline_new (NULL);
746 fail_unless (pipeline != NULL, "Could not create pipeline");
748 bus = gst_element_get_bus (pipeline);
749 fail_unless (bus != NULL, "Pipeline has no bus?!");
751 src = gst_element_factory_make ("fakesrc", NULL);
752 fail_if (src == NULL, "Could not create fakesrc");
753 g_object_set (src, "num-buffers", 5, NULL);
755 identity = gst_element_factory_make ("identity", NULL);
756 fail_if (identity == NULL, "Could not create identity");
758 sink = gst_element_factory_make ("fakesink", NULL);
759 fail_if (sink == NULL, "Could not create fakesink");
761 gst_bin_add_many (GST_BIN (pipeline), src, identity, sink, NULL);
763 fail_unless (gst_element_link (src, identity) == TRUE);
764 fail_unless (gst_element_link (identity, sink) == TRUE);
766 /* (1) Test state change with fakesink being a regular sink */
767 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
768 fail_if (ret != GST_STATE_CHANGE_ASYNC,
769 "State change to PLAYING did not return ASYNC");
771 gst_element_get_state (pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
772 fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to PLAYING failed");
773 fail_if (current != GST_STATE_PLAYING, "State change to PLAYING failed");
774 fail_if (pending != GST_STATE_VOID_PENDING, "State change to PLAYING failed");
777 ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_NULL, GST_STATE_READY, 101);
778 ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_NULL, GST_STATE_READY, 102);
779 ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_NULL, GST_STATE_READY, 103);
780 ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_NULL, GST_STATE_READY, 104);
782 /* READY => PAUSED */
783 /* because of pre-rolling, sink will return ASYNC on state
784 * change and change state later when it has a buffer */
785 GST_DEBUG ("popping READY -> PAUSED messages");
786 ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_READY, GST_STATE_PAUSED,
789 /* From here on, all bets are off. Usually the source changes state next,
790 * but it might just as well be that the first buffer produced by the
791 * source reaches the sink before the source has finished its state change,
792 * in which case the sink will commit its new state before the source ... */
793 ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_READY, GST_STATE_PAUSED, 106);
794 ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_READY, GST_STATE_PAUSED, 107);
797 pop_messages (bus, 2); /* pop remaining ready => paused messages off the bus */
798 ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_READY, GST_STATE_PAUSED,
800 pop_async_done (bus);
802 /* PAUSED => PLAYING */
803 GST_DEBUG ("popping PAUSED -> PLAYING messages");
804 ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_PAUSED, GST_STATE_PLAYING, 109);
805 ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_PAUSED, GST_STATE_PLAYING,
807 ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_PAUSED, GST_STATE_PLAYING, 111);
808 ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_PAUSED, GST_STATE_PLAYING,
811 /* don't set to NULL that will set the bus flushing and kill our messages */
812 ret = gst_element_set_state (pipeline, GST_STATE_READY);
813 fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to READY failed");
814 ret = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
815 fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to READY failed");
817 /* TODO: do we need to check downwards state change order as well? */
818 pop_messages (bus, 4); /* pop playing => paused messages off the bus */
819 pop_messages (bus, 4); /* pop paused => ready messages off the bus */
821 while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 1)
824 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
825 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
826 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
828 ret = gst_element_set_state (pipeline, GST_STATE_NULL);
829 fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to NULL failed");
831 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
832 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
833 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
835 gst_object_unref (bus);
836 gst_object_unref (pipeline);
842 GST_START_TEST (test_children_state_change_order_semi_sink)
844 GstElement *src, *identity, *sink, *pipeline;
845 GstStateChangeReturn ret;
846 GstState current, pending;
849 /* (2) Now again, but check other code path where we don't have
850 * a proper sink correctly flagged as such, but a 'semi-sink' */
851 pipeline = gst_pipeline_new (NULL);
852 fail_unless (pipeline != NULL, "Could not create pipeline");
854 bus = gst_element_get_bus (pipeline);
855 fail_unless (bus != NULL, "Pipeline has no bus?!");
857 src = gst_element_factory_make ("fakesrc", NULL);
858 fail_if (src == NULL, "Could not create fakesrc");
860 identity = gst_element_factory_make ("identity", NULL);
861 fail_if (identity == NULL, "Could not create identity");
863 sink = gst_element_factory_make ("fakesink", NULL);
864 fail_if (sink == NULL, "Could not create fakesink");
866 gst_bin_add_many (GST_BIN (pipeline), src, identity, sink, NULL);
868 fail_unless (gst_element_link (src, identity) == TRUE);
869 fail_unless (gst_element_link (identity, sink) == TRUE);
871 /* this is not very nice but should work just fine in this case. */
872 GST_OBJECT_FLAG_UNSET (sink, GST_ELEMENT_FLAG_SINK); /* <======== */
874 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
875 fail_if (ret != GST_STATE_CHANGE_ASYNC, "State change to PLAYING not ASYNC");
877 gst_element_get_state (pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
878 fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to PLAYING failed");
879 fail_if (current != GST_STATE_PLAYING, "State change to PLAYING failed");
880 fail_if (pending != GST_STATE_VOID_PENDING, "State change to PLAYING failed");
883 ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_NULL, GST_STATE_READY, 201);
884 ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_NULL, GST_STATE_READY, 202);
885 ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_NULL, GST_STATE_READY, 203);
886 ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_NULL, GST_STATE_READY, 204);
888 /* READY => PAUSED */
889 /* because of pre-rolling, sink will return ASYNC on state
890 * change and change state later when it has a buffer */
891 GST_DEBUG ("popping READY -> PAUSED messages");
892 ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_READY, GST_STATE_PAUSED,
895 /* From here on, all bets are off. Usually the source changes state next,
896 * but it might just as well be that the first buffer produced by the
897 * source reaches the sink before the source has finished its state change,
898 * in which case the sink will commit its new state before the source ... */
899 ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_READY, GST_STATE_PAUSED, 206);
900 ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_READY, GST_STATE_PAUSED, 207);
902 pop_messages (bus, 2); /* pop remaining ready => paused messages off the bus */
903 ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_READY, GST_STATE_PAUSED,
905 pop_async_done (bus);
907 /* PAUSED => PLAYING */
908 GST_DEBUG ("popping PAUSED -> PLAYING messages");
909 ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_PAUSED, GST_STATE_PLAYING, 209);
910 ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_PAUSED, GST_STATE_PLAYING,
912 ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_PAUSED, GST_STATE_PLAYING, 211);
913 ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_PAUSED, GST_STATE_PLAYING,
917 /* don't set to NULL that will set the bus flushing and kill our messages */
918 ret = gst_element_set_state (pipeline, GST_STATE_READY);
919 fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to READY failed");
921 /* TODO: do we need to check downwards state change order as well? */
922 pop_messages (bus, 4); /* pop playing => paused messages off the bus */
923 pop_messages (bus, 4); /* pop paused => ready messages off the bus */
925 GST_DEBUG ("waiting for pipeline to reach refcount 1");
926 while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 1)
929 GST_DEBUG ("checking refcount");
930 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
931 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
932 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
934 ret = gst_element_set_state (pipeline, GST_STATE_NULL);
935 fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to NULL failed");
937 GST_DEBUG ("checking refcount");
938 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
939 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
940 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
942 GST_DEBUG ("cleanup");
943 gst_object_unref (bus);
944 gst_object_unref (pipeline);
949 GST_START_TEST (test_children_state_change_order_two_sink)
951 GstElement *src, *tee, *identity, *sink1, *sink2, *pipeline;
952 GstStateChangeReturn ret;
955 pipeline = gst_pipeline_new (NULL);
956 fail_unless (pipeline != NULL, "Could not create pipeline");
958 bus = gst_element_get_bus (pipeline);
959 fail_unless (bus != NULL, "Pipeline has no bus?!");
961 src = gst_element_factory_make ("fakesrc", NULL);
962 fail_if (src == NULL, "Could not create fakesrc");
964 tee = gst_element_factory_make ("tee", NULL);
965 fail_if (tee == NULL, "Could not create tee");
967 identity = gst_element_factory_make ("identity", NULL);
968 fail_if (identity == NULL, "Could not create identity");
970 sink1 = gst_element_factory_make ("fakesink", NULL);
971 fail_if (sink1 == NULL, "Could not create fakesink1");
973 sink2 = gst_element_factory_make ("fakesink", NULL);
974 fail_if (sink2 == NULL, "Could not create fakesink2");
976 gst_bin_add_many (GST_BIN (pipeline), src, tee, identity, sink1, sink2, NULL);
978 fail_unless (gst_element_link (src, tee) == TRUE);
979 fail_unless (gst_element_link (tee, identity) == TRUE);
980 fail_unless (gst_element_link (identity, sink1) == TRUE);
981 fail_unless (gst_element_link (tee, sink2) == TRUE);
983 ret = gst_element_set_state (pipeline, GST_STATE_READY);
984 fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to READY failed");
989 GstState old = 0, new = 0, pending = 0;
990 GstObject *first, *second;
992 msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND);
993 fail_if (msg == NULL, "No state change message within 1 second (#201)");
995 gst_message_parse_state_changed (msg, &old, &new, &pending);
996 first = gst_object_ref (msg->src);
998 fail_if (first != GST_OBJECT (sink1) && first != GST_OBJECT (sink2),
999 "sink1 or sink2 should have changed state next #(202)");
1000 gst_message_unref (msg);
1002 msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND);
1003 fail_if (msg == NULL, "No state change message within 1 second (#201)");
1005 gst_message_parse_state_changed (msg, &old, &new, &pending);
1006 second = gst_object_ref (msg->src);
1008 fail_if (second != GST_OBJECT (sink1) && second != GST_OBJECT (sink2),
1009 "sink1 or sink2 should have changed state next #(202)");
1010 gst_message_unref (msg);
1012 fail_if (second == first, "got state change from same object");
1014 gst_object_unref (first);
1015 gst_object_unref (second);
1017 ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_NULL, GST_STATE_READY, 203);
1018 ASSERT_STATE_CHANGE_MSG (bus, tee, GST_STATE_NULL, GST_STATE_READY, 204);
1019 ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_NULL, GST_STATE_READY, 205);
1020 ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_NULL, GST_STATE_READY, 206);
1022 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
1023 ASSERT_OBJECT_REFCOUNT (tee, "tee", 1);
1024 ASSERT_OBJECT_REFCOUNT (identity, "identity", 1);
1025 ASSERT_OBJECT_REFCOUNT (sink1, "sink1", 1);
1026 ASSERT_OBJECT_REFCOUNT (sink2, "sink2", 1);
1027 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
1029 ret = gst_element_set_state (pipeline, GST_STATE_NULL);
1030 fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to NULL failed");
1032 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
1033 ASSERT_OBJECT_REFCOUNT (tee, "tee", 1);
1034 ASSERT_OBJECT_REFCOUNT (identity, "identity", 1);
1035 ASSERT_OBJECT_REFCOUNT (sink1, "sink1", 1);
1036 ASSERT_OBJECT_REFCOUNT (sink2, "sink2", 1);
1037 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
1039 gst_object_unref (bus);
1040 gst_object_unref (pipeline);
1045 GST_START_TEST (test_iterate_sorted)
1047 GstElement *src, *tee, *identity, *sink1, *sink2, *pipeline, *bin;
1049 GValue elem = { 0, };
1051 pipeline = gst_pipeline_new (NULL);
1052 fail_unless (pipeline != NULL, "Could not create pipeline");
1054 bin = gst_bin_new (NULL);
1055 fail_unless (bin != NULL, "Could not create bin");
1057 src = gst_element_factory_make ("fakesrc", NULL);
1058 fail_if (src == NULL, "Could not create fakesrc");
1060 tee = gst_element_factory_make ("tee", NULL);
1061 fail_if (tee == NULL, "Could not create tee");
1063 sink1 = gst_element_factory_make ("fakesink", NULL);
1064 fail_if (sink1 == NULL, "Could not create fakesink1");
1066 gst_bin_add_many (GST_BIN (bin), src, tee, sink1, NULL);
1068 fail_unless (gst_element_link (src, tee) == TRUE);
1069 fail_unless (gst_element_link (tee, sink1) == TRUE);
1071 identity = gst_element_factory_make ("identity", NULL);
1072 fail_if (identity == NULL, "Could not create identity");
1074 sink2 = gst_element_factory_make ("fakesink", NULL);
1075 fail_if (sink2 == NULL, "Could not create fakesink2");
1077 gst_bin_add_many (GST_BIN (pipeline), bin, identity, sink2, NULL);
1079 fail_unless (gst_element_link (tee, identity) == TRUE);
1080 fail_unless (gst_element_link (identity, sink2) == TRUE);
1082 it = gst_bin_iterate_sorted (GST_BIN (pipeline));
1083 fail_unless (gst_iterator_next (it, &elem) == GST_ITERATOR_OK);
1084 fail_unless (g_value_get_object (&elem) == (gpointer) sink2);
1085 g_value_reset (&elem);
1087 fail_unless (gst_iterator_next (it, &elem) == GST_ITERATOR_OK);
1088 fail_unless (g_value_get_object (&elem) == (gpointer) identity);
1089 g_value_reset (&elem);
1091 fail_unless (gst_iterator_next (it, &elem) == GST_ITERATOR_OK);
1092 fail_unless (g_value_get_object (&elem) == (gpointer) bin);
1093 g_value_reset (&elem);
1095 g_value_unset (&elem);
1096 gst_iterator_free (it);
1098 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
1099 gst_object_unref (pipeline);
1104 GST_START_TEST (test_iterate_sorted_unlinked)
1106 GstElement *pipeline, *src, *sink, *identity;
1108 GValue elem = { 0, };
1110 pipeline = gst_pipeline_new (NULL);
1111 fail_unless (pipeline != NULL, "Could not create pipeline");
1113 src = gst_element_factory_make ("fakesrc", NULL);
1114 fail_if (src == NULL, "Could not create fakesrc");
1116 sink = gst_element_factory_make ("fakesink", NULL);
1117 fail_if (sink == NULL, "Could not create fakesink1");
1119 identity = gst_element_factory_make ("identity", NULL);
1120 fail_if (identity == NULL, "Could not create identity");
1122 gst_bin_add_many (GST_BIN (pipeline), sink, identity, src, NULL);
1124 /* If elements aren't linked, we should end up with:
1125 * * sink elements always first
1126 * * source elements always last
1127 * * any other elements in between
1130 it = gst_bin_iterate_sorted (GST_BIN (pipeline));
1131 fail_unless (gst_iterator_next (it, &elem) == GST_ITERATOR_OK);
1132 fail_unless (g_value_get_object (&elem) == (gpointer) sink);
1133 g_value_reset (&elem);
1135 fail_unless (gst_iterator_next (it, &elem) == GST_ITERATOR_OK);
1136 fail_unless (g_value_get_object (&elem) == (gpointer) identity);
1137 g_value_reset (&elem);
1139 fail_unless (gst_iterator_next (it, &elem) == GST_ITERATOR_OK);
1140 fail_unless (g_value_get_object (&elem) == (gpointer) src);
1141 g_value_reset (&elem);
1143 g_value_unset (&elem);
1144 gst_iterator_free (it);
1146 ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
1147 gst_object_unref (pipeline);
1153 test_link_structure_change_state_changed_sync_cb (GstBus * bus,
1154 GstMessage * message, gpointer data)
1156 GstPipeline *pipeline = GST_PIPELINE (data);
1157 GstElement *src, *identity, *sink;
1158 GstState old, snew, pending;
1160 sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
1161 fail_unless (sink != NULL, "Could not get sink");
1163 gst_message_parse_state_changed (message, &old, &snew, &pending);
1164 if (message->src != GST_OBJECT (sink) || snew != GST_STATE_READY) {
1165 gst_object_unref (sink);
1169 src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
1170 fail_unless (src != NULL, "Could not get src");
1172 identity = gst_bin_get_by_name (GST_BIN (pipeline), "identity");
1173 fail_unless (identity != NULL, "Could not get identity");
1175 /* link src to identity, the pipeline should detect the new link and
1176 * resync the state change */
1177 fail_unless (gst_element_link (src, identity) == TRUE);
1179 gst_object_unref (src);
1180 gst_object_unref (identity);
1181 gst_object_unref (sink);
1184 GST_START_TEST (test_link_structure_change)
1186 GstElement *src, *identity, *sink, *pipeline;
1190 pipeline = gst_pipeline_new (NULL);
1191 fail_unless (pipeline != NULL, "Could not create pipeline");
1193 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
1194 fail_unless (bus != NULL, "Could not get bus");
1196 /* use the sync signal handler to link elements while the pipeline is still
1197 * doing the state change */
1198 gst_bus_set_sync_handler (bus, gst_bus_sync_signal_handler, pipeline, NULL);
1199 g_object_connect (bus, "signal::sync-message::state-changed",
1200 G_CALLBACK (test_link_structure_change_state_changed_sync_cb), pipeline,
1203 src = gst_element_factory_make ("fakesrc", "src");
1204 fail_if (src == NULL, "Could not create fakesrc");
1206 identity = gst_element_factory_make ("identity", "identity");
1207 fail_if (identity == NULL, "Could not create identity");
1209 sink = gst_element_factory_make ("fakesink", "sink");
1210 fail_if (sink == NULL, "Could not create fakesink1");
1212 gst_bin_add_many (GST_BIN (pipeline), src, identity, sink, NULL);
1214 gst_element_set_state (pipeline, GST_STATE_READY);
1215 gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
1217 /* the state change will be done on src only if the pipeline correctly resyncs
1218 * after that fakesrc has been linked to identity */
1219 gst_element_get_state (src, &state, NULL, 0);
1220 fail_unless_equals_int (state, GST_STATE_READY);
1223 gst_element_set_state (pipeline, GST_STATE_NULL);
1224 gst_object_unref (bus);
1225 gst_object_unref (pipeline);
1230 static GstBusSyncReply
1231 sync_handler_remove_sink (GstBus * bus, GstMessage * message, gpointer data)
1233 if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR) {
1236 child = gst_bin_get_by_name (GST_BIN (data), "fakesink");
1237 fail_unless (child != NULL, "Could not find fakesink");
1239 gst_bin_remove (GST_BIN (data), child);
1240 gst_object_unref (child);
1242 return GST_BUS_PASS;
1245 GST_START_TEST (test_state_failure_remove)
1247 GstElement *src, *sink, *pipeline;
1249 GstStateChangeReturn ret;
1251 pipeline = gst_pipeline_new (NULL);
1252 fail_unless (pipeline != NULL, "Could not create pipeline");
1254 src = gst_element_factory_make ("fakesrc", "fakesrc");
1255 fail_unless (src != NULL, "Could not create fakesrc");
1257 sink = gst_element_factory_make ("fakesink", "fakesink");
1258 fail_unless (sink != NULL, "Could not create fakesink");
1260 g_object_set (sink, "state-error", 1, NULL);
1262 gst_bin_add (GST_BIN (pipeline), src);
1263 gst_bin_add (GST_BIN (pipeline), sink);
1265 gst_element_link (src, sink);
1267 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
1268 fail_unless (bus != NULL, "Could not get bus");
1270 gst_bus_set_sync_handler (bus, sync_handler_remove_sink, pipeline, NULL);
1272 ret = gst_element_set_state (pipeline, GST_STATE_READY);
1273 fail_unless (ret == GST_STATE_CHANGE_SUCCESS,
1274 "did not get state change success");
1276 gst_element_set_state (pipeline, GST_STATE_NULL);
1278 gst_object_unref (bus);
1279 gst_object_unref (pipeline);
1284 GST_START_TEST (test_many_bins)
1286 GstStateChangeReturn ret;
1287 GstElement *src, *sink, *pipeline, *last_bin = NULL;
1290 #define NUM_BINS 2000
1292 pipeline = gst_pipeline_new (NULL);
1293 fail_unless (pipeline != NULL, "Could not create pipeline");
1295 src = gst_element_factory_make ("fakesrc", "fakesrc");
1296 fail_unless (src != NULL, "Could not create fakesrc");
1297 g_object_set (src, "num-buffers", 3, NULL);
1299 sink = gst_element_factory_make ("fakesink", "fakesink");
1300 fail_unless (sink != NULL, "Could not create fakesink");
1302 gst_bin_add (GST_BIN (pipeline), src);
1303 gst_bin_add (GST_BIN (pipeline), sink);
1305 for (i = 0; i < NUM_BINS; ++i) {
1306 GstElement *bin, *identity;
1307 GstPad *srcpad, *sinkpad;
1309 bin = gst_bin_new (NULL);
1310 fail_unless (bin != NULL, "Could not create bin %d", i);
1311 identity = gst_element_factory_make ("identity", "identity");
1312 fail_unless (identity != NULL, "Could not create identity %d", i);
1313 g_object_set (identity, "silent", TRUE, NULL);
1314 gst_bin_add (GST_BIN (bin), identity);
1315 sinkpad = gst_element_get_static_pad (identity, "sink");
1316 srcpad = gst_element_get_static_pad (identity, "src");
1317 gst_element_add_pad (bin, gst_ghost_pad_new ("sink", sinkpad));
1318 gst_element_add_pad (bin, gst_ghost_pad_new ("src", srcpad));
1319 gst_object_unref (sinkpad);
1320 gst_object_unref (srcpad);
1322 gst_bin_add (GST_BIN (pipeline), bin);
1324 if (last_bin == NULL) {
1325 srcpad = gst_element_get_static_pad (src, "src");
1327 srcpad = gst_element_get_static_pad (last_bin, "src");
1329 sinkpad = gst_element_get_static_pad (bin, "sink");
1330 gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_NOTHING);
1331 gst_object_unref (sinkpad);
1332 gst_object_unref (srcpad);
1337 /* insert some queues to limit the number of function calls in a row */
1338 if ((i % 100) == 0) {
1339 GstElement *q = gst_element_factory_make ("queue", NULL);
1341 GST_LOG ("bin #%d, inserting queue", i);
1342 gst_bin_add (GST_BIN (pipeline), q);
1343 fail_unless (gst_element_link (last_bin, q));
1348 fail_unless (gst_element_link (last_bin, sink));
1350 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1351 fail_unless_equals_int (ret, GST_STATE_CHANGE_ASYNC);
1353 for (i = 0; i < 15; ++i) {
1354 GST_INFO ("waiting for preroll ...");
1355 ret = gst_element_get_state (pipeline, NULL, NULL, GST_SECOND);
1356 if (ret != GST_STATE_CHANGE_ASYNC)
1359 fail_unless_equals_int (ret, GST_STATE_CHANGE_SUCCESS);
1361 gst_element_set_state (pipeline, GST_STATE_NULL);
1362 gst_object_unref (pipeline);
1367 static GstPadProbeReturn
1368 fakesrc_pad_blocked_cb (GstPad * pad, GstPadProbeInfo * info, void *arg)
1370 GstPipeline *pipeline = (GstPipeline *) arg;
1371 GstElement *src, *sink;
1373 src = gst_bin_get_by_name (GST_BIN (pipeline), "fakesrc");
1374 fail_unless (src != NULL, "Could not get fakesrc");
1376 sink = gst_element_factory_make ("fakesink", "fakesink");
1377 fail_unless (sink != NULL, "Could not create fakesink");
1379 g_object_set (sink, "state-error", 1, NULL);
1380 gst_bin_add (GST_BIN (pipeline), sink);
1382 gst_element_link (src, sink);
1383 gst_element_sync_state_with_parent (sink);
1384 gst_object_unref (src);
1386 return GST_PAD_PROBE_REMOVE;
1389 GST_START_TEST (test_state_failure_unref)
1391 GstElement *src, *pipeline;
1394 GstStateChangeReturn ret;
1397 pipeline = gst_pipeline_new (NULL);
1398 fail_unless (pipeline != NULL, "Could not create pipeline");
1400 src = gst_element_factory_make ("fakesrc", "fakesrc");
1401 fail_unless (src != NULL, "Could not create fakesrc");
1403 srcpad = gst_element_get_static_pad (src, "src");
1404 fail_unless (srcpad != NULL, "Could not get fakesrc srcpad");
1406 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
1407 fakesrc_pad_blocked_cb, pipeline, NULL);
1408 gst_object_unref (srcpad);
1410 gst_bin_add (GST_BIN (pipeline), src);
1412 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
1413 fail_unless (bus != NULL, "Could not get bus");
1415 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1417 /* Wait for an error message from our fakesink (added from the
1418 pad block callback). */
1419 msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, GST_SECOND);
1420 fail_if (msg == NULL, "No error message within 1 second");
1421 gst_message_unref (msg);
1423 /* Check that after this failure, we can still stop, and then unref, the
1424 pipeline. This should always be possible. */
1425 ret = gst_element_set_state (pipeline, GST_STATE_NULL);
1426 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "downward state change failed");
1428 gst_object_unref (bus);
1429 gst_object_unref (pipeline);
1435 on_sync_bus_error (GstBus * bus, GstMessage * msg)
1437 fail_if (msg != NULL);
1440 GST_START_TEST (test_state_change_skip)
1442 GstElement *sink, *pipeline;
1443 GstStateChangeReturn ret;
1446 pipeline = gst_pipeline_new (NULL);
1447 fail_unless (pipeline != NULL, "Could not create pipeline");
1449 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
1450 fail_unless (bus != NULL, "Could not get bus");
1453 gst_bus_enable_sync_message_emission (bus);
1454 g_signal_connect (bus, "sync-message::error", (GCallback) on_sync_bus_error,
1457 sink = gst_element_factory_make ("fakesink", "fakesink");
1458 fail_unless (sink != NULL, "Could not create fakesink");
1459 gst_element_set_state (sink, GST_STATE_PAUSED);
1461 g_object_set (sink, "state-error", 5, NULL);
1463 gst_bin_add (GST_BIN (pipeline), sink);
1464 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1466 g_object_set (sink, "state-error", 0, NULL);
1468 /* Check that after this failure, we can still stop, and then unref, the
1469 pipeline. This should always be possible. */
1470 ret = gst_element_set_state (pipeline, GST_STATE_NULL);
1471 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "downward state change failed");
1473 gst_object_unref (pipeline);
1474 gst_object_unref (bus);
1479 GST_START_TEST (test_duration_is_max)
1481 GstElement *bin, *src[3], *sink[3];
1482 GstStateChangeReturn state_res;
1483 GstFormat format = GST_FORMAT_BYTES;
1488 GST_INFO ("preparing test");
1490 /* build pipeline */
1491 bin = gst_pipeline_new ("pipeline");
1493 /* 3 sources, an adder and a fakesink */
1494 src[0] = gst_element_factory_make ("fakesrc", NULL);
1495 src[1] = gst_element_factory_make ("fakesrc", NULL);
1496 src[2] = gst_element_factory_make ("fakesrc", NULL);
1497 sink[0] = gst_element_factory_make ("fakesink", NULL);
1498 sink[1] = gst_element_factory_make ("fakesink", NULL);
1499 sink[2] = gst_element_factory_make ("fakesink", NULL);
1500 gst_bin_add_many (GST_BIN (bin), src[0], src[1], src[2], sink[0], sink[1],
1503 gst_element_link (src[0], sink[0]);
1504 gst_element_link (src[1], sink[1]);
1505 gst_element_link (src[2], sink[2]);
1507 /* irks, duration is reset on basesrc */
1508 state_res = gst_element_set_state (bin, GST_STATE_PAUSED);
1509 fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
1511 /* set durations on src */
1512 GST_BASE_SRC (src[0])->segment.duration = 1000;
1513 GST_BASE_SRC (src[1])->segment.duration = 3000;
1514 GST_BASE_SRC (src[2])->segment.duration = 2000;
1516 /* set to playing */
1517 state_res = gst_element_set_state (bin, GST_STATE_PLAYING);
1518 fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
1520 /* wait for completion */
1522 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
1523 GST_CLOCK_TIME_NONE);
1524 fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
1526 res = gst_element_query_duration (GST_ELEMENT (bin), format, &duration);
1527 fail_unless (res, NULL);
1529 ck_assert_int_eq (duration, 3000);
1531 bus = gst_element_get_bus (bin);
1532 gst_bus_set_flushing (bus, TRUE);
1533 gst_object_unref (bus);
1535 gst_element_set_state (bin, GST_STATE_NULL);
1536 gst_object_unref (bin);
1541 GST_START_TEST (test_duration_unknown_overrides)
1543 GstElement *bin, *src[3], *sink[3];
1544 GstStateChangeReturn state_res;
1545 GstFormat format = GST_FORMAT_BYTES;
1550 GST_INFO ("preparing test");
1552 /* build pipeline */
1553 bin = gst_pipeline_new ("pipeline");
1555 /* 3 sources, an adder and a fakesink */
1556 src[0] = gst_element_factory_make ("fakesrc", NULL);
1557 src[1] = gst_element_factory_make ("fakesrc", NULL);
1558 src[2] = gst_element_factory_make ("fakesrc", NULL);
1559 sink[0] = gst_element_factory_make ("fakesink", NULL);
1560 sink[1] = gst_element_factory_make ("fakesink", NULL);
1561 sink[2] = gst_element_factory_make ("fakesink", NULL);
1562 gst_bin_add_many (GST_BIN (bin), src[0], src[1], src[2], sink[0], sink[1],
1565 gst_element_link (src[0], sink[0]);
1566 gst_element_link (src[1], sink[1]);
1567 gst_element_link (src[2], sink[2]);
1569 /* irks, duration is reset on basesrc */
1570 state_res = gst_element_set_state (bin, GST_STATE_PAUSED);
1571 fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
1573 /* set durations on src */
1574 GST_BASE_SRC (src[0])->segment.duration = GST_CLOCK_TIME_NONE;
1575 GST_BASE_SRC (src[1])->segment.duration = 3000;
1576 GST_BASE_SRC (src[2])->segment.duration = 2000;
1578 /* set to playing */
1579 state_res = gst_element_set_state (bin, GST_STATE_PLAYING);
1580 fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
1582 /* wait for completion */
1584 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
1585 GST_CLOCK_TIME_NONE);
1586 fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
1588 res = gst_element_query_duration (GST_ELEMENT (bin), format, &duration);
1589 fail_unless (res, NULL);
1591 ck_assert_int_eq (duration, GST_CLOCK_TIME_NONE);
1593 bus = gst_element_get_bus (bin);
1594 gst_bus_set_flushing (bus, TRUE);
1595 gst_object_unref (bus);
1597 gst_element_set_state (bin, GST_STATE_NULL);
1598 gst_object_unref (bin);
1604 element_in_list (GList ** list, GstElement * element)
1606 GList *l = g_list_find (*list, element);
1611 *list = g_list_delete_link (*list, l);
1615 #define element_was_added(e) element_in_list(&added,e)
1616 #define element_was_removed(e) element_in_list(&removed,e)
1619 add_cb (GstBin * pipeline, GstBin * bin, GstElement * element, GList ** list)
1621 fail_unless (GST_OBJECT_PARENT (element) == GST_OBJECT_CAST (bin));
1623 *list = g_list_prepend (*list, element);
1627 remove_cb (GstBin * pipeline, GstBin * bin, GstElement * element, GList ** list)
1629 *list = g_list_prepend (*list, element);
1632 GST_START_TEST (test_deep_added_removed)
1634 GstElement *pipe, *e, *bin0, *bin1;
1635 gulong id_removed, id_added;
1636 GList *removed = NULL;
1637 GList *added = NULL;
1639 pipe = gst_pipeline_new (NULL);
1641 id_added = g_signal_connect (pipe, "deep-element-added",
1642 G_CALLBACK (add_cb), &added);
1643 id_removed = g_signal_connect (pipe, "deep-element-removed",
1644 G_CALLBACK (remove_cb), &removed);
1646 /* simple add/remove */
1647 e = gst_element_factory_make ("identity", NULL);
1648 gst_bin_add (GST_BIN (pipe), e);
1649 fail_unless (element_was_added (e));
1650 gst_bin_remove (GST_BIN (pipe), e);
1651 fail_unless (element_was_removed (e));
1653 /* let's try with a deeper hierarchy, construct it from top-level down */
1654 bin0 = gst_bin_new (NULL);
1655 gst_bin_add (GST_BIN (pipe), bin0);
1656 bin1 = gst_bin_new (NULL);
1657 gst_bin_add (GST_BIN (bin0), bin1);
1658 e = gst_element_factory_make ("identity", NULL);
1659 gst_bin_add (GST_BIN (bin1), e);
1660 fail_unless (element_was_added (bin0));
1661 fail_unless (element_was_added (bin1));
1662 fail_unless (element_was_added (e));
1663 fail_unless (added == NULL);
1664 fail_unless (removed == NULL);
1666 gst_object_ref (e); /* keep e alive */
1667 gst_bin_remove (GST_BIN (bin1), e);
1668 fail_unless (element_was_removed (e));
1669 fail_unless (added == NULL);
1670 fail_unless (removed == NULL);
1672 /* now add existing bin hierarchy to pipeline (first remove it so we can re-add it) */
1673 gst_object_ref (bin0); /* keep bin0 alive */
1674 gst_bin_remove (GST_BIN (pipe), bin0);
1675 fail_unless (element_was_removed (bin0));
1676 fail_unless (element_was_removed (bin1));
1677 fail_unless (added == NULL);
1678 fail_unless (removed == NULL);
1680 /* re-adding element to removed bin should not trigger our callbacks */
1681 gst_bin_add (GST_BIN (bin1), e);
1682 fail_unless (added == NULL);
1683 fail_unless (removed == NULL);
1685 gst_bin_add (GST_BIN (pipe), bin0);
1686 fail_unless (element_was_added (bin0));
1687 fail_unless (element_was_added (bin1));
1688 fail_unless (element_was_added (e));
1689 fail_unless (added == NULL);
1690 fail_unless (removed == NULL);
1691 gst_object_unref (bin0);
1692 gst_object_unref (e);
1694 /* disconnect signals, unref will trigger remove callbacks otherwise */
1695 g_signal_handler_disconnect (pipe, id_added);
1696 g_signal_handler_disconnect (pipe, id_removed);
1698 gst_object_unref (pipe);
1703 #define _GST_CHECK_BIN_SUPPRESSED_FLAGS(element_flags, suppressed_flags, \
1706 GstBin *bin = GST_BIN (gst_bin_new ("test-bin")); \
1707 GstElement *element = gst_element_factory_make ("identity", "test-i"); \
1708 GstElementFlags natural_flags = GST_OBJECT_FLAGS (bin); \
1709 GST_OBJECT_FLAG_SET (element, element_flags); \
1710 gst_bin_set_suppressed_flags (bin, suppressed_flags); \
1711 gst_bin_add (bin, element); \
1712 fail_unless ((natural_flags | GST_OBJECT_FLAGS (bin)) \
1713 == expected_flags); \
1714 gst_object_unref (bin); \
1717 GST_START_TEST (test_suppressed_flags)
1719 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_SOURCE,
1720 0, GST_ELEMENT_FLAG_SOURCE);
1721 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_SOURCE,
1722 GST_ELEMENT_FLAG_SOURCE, 0);
1723 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_SOURCE,
1724 GST_ELEMENT_FLAG_SINK, GST_ELEMENT_FLAG_SOURCE);
1725 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_SOURCE |
1726 GST_ELEMENT_FLAG_PROVIDE_CLOCK,
1727 GST_ELEMENT_FLAG_PROVIDE_CLOCK, GST_ELEMENT_FLAG_SOURCE);
1729 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_SINK,
1730 0, GST_ELEMENT_FLAG_SINK);
1731 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_SINK,
1732 GST_ELEMENT_FLAG_SINK, 0);
1733 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_SINK,
1734 GST_ELEMENT_FLAG_SOURCE, GST_ELEMENT_FLAG_SINK);
1736 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_PROVIDE_CLOCK,
1737 0, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
1738 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_PROVIDE_CLOCK,
1739 GST_ELEMENT_FLAG_PROVIDE_CLOCK, 0);
1740 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_PROVIDE_CLOCK,
1741 GST_ELEMENT_FLAG_REQUIRE_CLOCK, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
1743 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_REQUIRE_CLOCK,
1744 0, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
1745 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_REQUIRE_CLOCK,
1746 GST_ELEMENT_FLAG_REQUIRE_CLOCK, 0);
1747 _GST_CHECK_BIN_SUPPRESSED_FLAGS (GST_ELEMENT_FLAG_REQUIRE_CLOCK,
1748 GST_ELEMENT_FLAG_PROVIDE_CLOCK, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
1754 #define _GST_CHECK_BIN_SUPPRESSED_FLAGS_REMOVAL(suppressed_flags) \
1756 GstBin *bin = GST_BIN (gst_bin_new ("test-bin")); \
1757 GstElement *element = gst_element_factory_make ("identity", "test-i"); \
1758 GST_OBJECT_FLAG_SET (bin, suppressed_flags); \
1759 gst_bin_set_suppressed_flags (bin, suppressed_flags); \
1760 GST_OBJECT_FLAG_SET (element, suppressed_flags); \
1761 fail_unless ((suppressed_flags & GST_OBJECT_FLAGS (bin)) \
1762 == suppressed_flags); \
1763 gst_bin_add (bin, element); \
1764 fail_unless ((suppressed_flags & GST_OBJECT_FLAGS (bin)) \
1765 == suppressed_flags); \
1766 gst_bin_remove (bin, element); \
1767 fail_unless ((suppressed_flags & GST_OBJECT_FLAGS (bin)) \
1768 == suppressed_flags); \
1769 gst_object_unref (bin); \
1772 GST_START_TEST (test_suppressed_flags_when_removing)
1774 _GST_CHECK_BIN_SUPPRESSED_FLAGS_REMOVAL (GST_ELEMENT_FLAG_SOURCE);
1775 _GST_CHECK_BIN_SUPPRESSED_FLAGS_REMOVAL (GST_ELEMENT_FLAG_SINK);
1776 _GST_CHECK_BIN_SUPPRESSED_FLAGS_REMOVAL (GST_ELEMENT_FLAG_REQUIRE_CLOCK);
1777 _GST_CHECK_BIN_SUPPRESSED_FLAGS_REMOVAL (GST_ELEMENT_FLAG_PROVIDE_CLOCK);
1783 gst_bin_suite (void)
1785 Suite *s = suite_create ("GstBin");
1786 TCase *tc_chain = tcase_create ("bin tests");
1788 tcase_set_timeout (tc_chain, 0);
1790 suite_add_tcase (s, tc_chain);
1791 tcase_add_test (tc_chain, test_interface);
1792 tcase_add_test (tc_chain, test_eos);
1793 tcase_add_test (tc_chain, test_stream_start);
1794 tcase_add_test (tc_chain, test_children_state_change_order_flagged_sink);
1795 tcase_add_test (tc_chain, test_children_state_change_order_semi_sink);
1796 tcase_add_test (tc_chain, test_children_state_change_order_two_sink);
1797 tcase_add_test (tc_chain, test_message_state_changed);
1798 tcase_add_test (tc_chain, test_message_state_changed_child);
1799 tcase_add_test (tc_chain, test_message_state_changed_children);
1800 tcase_add_test (tc_chain, test_watch_for_state_change);
1801 tcase_add_test (tc_chain, test_state_change_error_message);
1802 tcase_add_test (tc_chain, test_add_linked);
1803 tcase_add_test (tc_chain, test_add_self);
1804 tcase_add_test (tc_chain, test_iterate_sorted);
1805 tcase_add_test (tc_chain, test_iterate_sorted_unlinked);
1806 tcase_add_test (tc_chain, test_link_structure_change);
1807 tcase_add_test (tc_chain, test_state_failure_remove);
1808 tcase_add_test (tc_chain, test_state_failure_unref);
1809 tcase_add_test (tc_chain, test_state_change_skip);
1810 tcase_add_test (tc_chain, test_duration_is_max);
1811 tcase_add_test (tc_chain, test_duration_unknown_overrides);
1812 tcase_add_test (tc_chain, test_deep_added_removed);
1813 tcase_add_test (tc_chain, test_suppressed_flags);
1814 tcase_add_test (tc_chain, test_suppressed_flags_when_removing);
1816 /* fails on OSX build bot for some reason, and is a bit silly anyway */
1818 tcase_add_test (tc_chain, test_many_bins);
1823 GST_CHECK_MAIN (gst_bin);