2 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
4 * gstbin.c: Unit test for GstBin
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 "../gstcheck.h"
24 START_TEST (test_interface)
31 bin = GST_BIN (gst_bin_new (NULL));
32 fail_unless (bin != NULL, "Could not create bin");
34 filesrc = gst_element_factory_make ("filesrc", NULL);
35 fail_unless (filesrc != NULL, "Could not create filesrc");
36 fail_unless (GST_IS_URI_HANDLER (filesrc), "Filesrc not a URI handler");
37 gst_bin_add (bin, filesrc);
39 fail_unless (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
40 it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
41 fail_unless (it != NULL);
42 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
43 fail_unless (item == (gpointer) filesrc);
44 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
45 gst_iterator_free (it);
47 gst_bin_add_many (bin,
48 gst_element_factory_make ("identity", NULL),
49 gst_element_factory_make ("identity", NULL),
50 gst_element_factory_make ("identity", NULL), NULL);
51 fail_unless (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
52 it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
53 fail_unless (it != NULL);
54 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
55 fail_unless (item == (gpointer) filesrc);
56 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
57 gst_iterator_free (it);
60 bin = GST_BIN (gst_bin_new (NULL));
61 fail_unless (bin != NULL);
62 gst_bin_add_many (bin,
63 gst_element_factory_make ("identity", NULL),
64 gst_element_factory_make ("identity", NULL),
65 GST_ELEMENT (bin2), gst_element_factory_make ("identity", NULL), NULL);
66 fail_unless (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
67 it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
68 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
69 fail_unless (item == (gpointer) filesrc);
70 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
71 gst_iterator_free (it);
73 gst_bin_add (bin, gst_element_factory_make ("filesrc", NULL));
74 gst_bin_add (bin2, gst_element_factory_make ("filesrc", NULL));
75 it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
76 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
77 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
78 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
79 fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
80 gst_iterator_free (it);
82 gst_object_unref (GST_OBJECT (bin));
86 START_TEST (test_ghost_pads)
88 GstElement *b1, *b2, *src, *i1, *sink;
90 b1 = gst_element_factory_make ("pipeline", NULL);
91 b2 = gst_element_factory_make ("bin", NULL);
92 src = gst_element_factory_make ("fakesrc", NULL);
93 i1 = gst_element_factory_make ("identity", NULL);
94 sink = gst_element_factory_make ("fakesink", NULL);
96 fail_unless (gst_bin_add (GST_BIN (b2), i1));
97 fail_unless (gst_bin_add (GST_BIN (b1), src));
98 fail_unless (gst_bin_add (GST_BIN (b1), b2));
99 fail_unless (gst_bin_add (GST_BIN (b1), sink));
100 fail_unless (gst_element_link_pads (src, NULL, i1, NULL));
101 fail_unless (gst_element_link_pads (i1, NULL, sink, NULL));
103 fail_unless (b2->numsinkpads == 1);
104 fail_unless (GST_IS_GHOST_PAD (b2->sinkpads->data));
105 fail_unless (b2->numsrcpads == 1);
106 fail_unless (GST_IS_GHOST_PAD (b2->srcpads->data));
109 fail_unless (gst_element_set_state (b1,
110 GST_STATE_PLAYING) == GST_STATE_SUCCESS);
111 fail_unless (gst_element_set_state (b1, GST_STATE_NULL) == GST_STATE_SUCCESS);
113 gst_object_unref (GST_OBJECT (b1));
115 END_TEST Suite * gst_bin_suite (void)
117 Suite *s = suite_create ("GstBin");
118 TCase *tc_chain = tcase_create ("bin tests");
120 suite_add_tcase (s, tc_chain);
121 tcase_add_test (tc_chain, test_interface);
122 tcase_add_test (tc_chain, test_ghost_pads);
128 main (int argc, char **argv)
132 Suite *s = gst_bin_suite ();
133 SRunner *sr = srunner_create (s);
135 gst_check_init (&argc, &argv);
137 srunner_run_all (sr, CK_NORMAL);
138 nf = srunner_ntests_failed (sr);