gst/gstbin.c (sink_iterator_filter): Err... um...
[platform/upstream/gstreamer.git] / tests / check / gst / gstbin.c
1 /* GStreamer
2  * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
3  *
4  * gstbin.c: Unit test for GstBin
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 "../gstcheck.h"
23
24 START_TEST (test_interface)
25 {
26   GstBin *bin, *bin2;
27   GstElement *filesrc;
28   GstIterator *it;
29   gpointer item;
30
31   bin = GST_BIN (gst_bin_new (NULL));
32   fail_unless (bin != NULL, "Could not create bin");
33
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);
38
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);
46
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);
58
59   bin2 = bin;
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);
72
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);
81
82   gst_object_unref (GST_OBJECT (bin));
83 }
84
85 END_TEST
86 START_TEST (test_ghost_pads)
87 {
88   GstElement *b1, *b2, *src, *i1, *sink;
89
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);
95
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));
102   GST_LOCK (b2);
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));
107   GST_UNLOCK (b2);
108
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);
112
113   gst_object_unref (GST_OBJECT (b1));
114 }
115 END_TEST Suite * gst_bin_suite (void)
116 {
117   Suite *s = suite_create ("GstBin");
118   TCase *tc_chain = tcase_create ("bin tests");
119
120   suite_add_tcase (s, tc_chain);
121   tcase_add_test (tc_chain, test_interface);
122   tcase_add_test (tc_chain, test_ghost_pads);
123
124   return s;
125 }
126
127 int
128 main (int argc, char **argv)
129 {
130   int nf;
131
132   Suite *s = gst_bin_suite ();
133   SRunner *sr = srunner_create (s);
134
135   gst_check_init (&argc, &argv);
136
137   srunner_run_all (sr, CK_NORMAL);
138   nf = srunner_ntests_failed (sr);
139   srunner_free (sr);
140
141   return nf;
142 }