12 bin = gst_bin_new ("testbin");
13 g_assert (GST_IS_BIN (bin));
14 element = gst_element_factory_make ("fakesrc", NULL);
15 g_assert (GST_IS_ELEMENT (element));
16 gst_element_set_name (element, "test1");
17 gst_bin_add (GST_BIN (bin), element);
18 element = gst_element_factory_make ("fakesrc", NULL);
19 g_assert (GST_IS_ELEMENT (element));
20 gst_element_set_name (element, "test2");
21 gst_bin_add (GST_BIN (bin), element);
27 create_bin_ghostpads (void)
30 GstElement *element1, *element2;
32 bin = gst_bin_new ("testbin");
33 element1 = gst_element_factory_make ("identity", NULL);
34 gst_bin_add (GST_BIN (bin), element1);
35 element2 = gst_element_factory_make ("fakesink", NULL);
36 gst_bin_add (GST_BIN (bin), element2);
37 gst_element_link_pads (element1, "src", element2, "sink");
38 gst_element_add_ghost_pad (bin, gst_element_get_pad (element1, "sink"),
45 add_remove_test1 (void)
50 bin = gst_bin_new ("testbin");
51 element = gst_element_factory_make ("fakesrc", NULL);
52 gst_element_set_name (element, "test1");
53 g_assert (GST_OBJECT_IS_FLOATING (element));
54 gst_bin_add (GST_BIN (bin), element);
55 g_assert (!GST_OBJECT_IS_FLOATING (element));
56 gst_bin_remove (GST_BIN (bin), element);
58 gst_object_unref (GST_OBJECT (bin));
62 add_remove_test2 (void)
67 bin = gst_bin_new ("testbin");
68 element = gst_element_factory_make ("fakesrc", NULL);
69 gst_element_set_name (element, "test1");
70 gst_object_ref (GST_OBJECT (element));
71 g_assert (GST_OBJECT_IS_FLOATING (element));
72 gst_bin_add (GST_BIN (bin), element);
73 g_assert (!GST_OBJECT_IS_FLOATING (element));
74 gst_bin_remove (GST_BIN (bin), element);
75 g_assert (!GST_OBJECT_IS_FLOATING (element));
76 g_assert (!GST_OBJECT_IS_DESTROYED (element));
78 gst_object_unref (GST_OBJECT (element));
80 g_assert (GST_OBJECT_IS_DESTROYED (element));
81 gst_object_unref (GST_OBJECT (element));
84 gst_object_unref (GST_OBJECT (bin));
88 /* This code is bogus */
90 add_remove_test3 (void)
95 bin = gst_bin_new ("testbin");
96 element = gst_element_factory_make ("fakesrc", NULL);
97 gst_element_set_name (element, "test1");
98 g_assert (GST_OBJECT_FLOATING (element));
99 gst_bin_add (GST_BIN (bin), element);
100 g_assert (!GST_OBJECT_FLOATING (element));
102 gst_object_unref (GST_OBJECT (element));
103 g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL);
105 gst_object_unref (GST_OBJECT (bin));
110 /* This code is bogus */
112 add_remove_test4 (void)
114 GstElement *bin, *bin2;
117 bin = gst_bin_new ("testbin");
118 element = gst_element_factory_make ("fakesrc", NULL);
119 gst_element_set_name (element, "test1");
120 g_assert (GST_OBJECT_FLOATING (element));
121 gst_bin_add (GST_BIN (bin), element);
122 g_assert (!GST_OBJECT_FLOATING (element));
124 bin2 = create_bin ();
125 g_assert (GST_OBJECT_FLOATING (bin2));
126 gst_bin_add (GST_BIN (bin), bin2);
127 g_assert (!GST_OBJECT_FLOATING (bin2));
129 gst_object_unref (GST_OBJECT (bin2));
130 g_assert (gst_bin_get_by_name (GST_BIN (bin), "testbin") == NULL);
131 gst_object_unref (GST_OBJECT (element));
132 g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL);
134 gst_object_unref (GST_OBJECT (bin));
139 main (int argc, gchar * argv[])
145 gst_alloc_trace_set_flags_all (GST_ALLOC_TRACE_LIVE);
147 gst_init (&argc, &argv);
150 iters = atoi (argv[1]);
155 g_print ("starting test\n");
157 usage1 = gst_alloc_trace_live_all ();
158 //gst_alloc_trace_print_all ();
160 bin = gst_bin_new ("somebin");
161 gst_object_unref (GST_OBJECT (bin));
162 g_print ("create/unref new bin %d\n", gst_alloc_trace_live_all () - usage1);
164 for (i = 0; i < iters; i++) {
165 bin = gst_bin_new ("somebin");
166 gst_object_unref (GST_OBJECT (bin));
168 g_print ("create/unref %d bins %d\n", iters,
169 gst_alloc_trace_live_all () - usage1);
171 bin = gst_bin_new ("somebin");
172 g_assert (GST_OBJECT_IS_FLOATING (bin));
173 gst_object_ref (GST_OBJECT (bin));
174 gst_object_sink (GST_OBJECT (bin));
175 g_assert (!GST_OBJECT_IS_FLOATING (bin));
176 gst_object_unref (GST_OBJECT (bin));
177 g_print ("create/ref/sink/unref new bin %d\n",
178 gst_alloc_trace_live_all () - usage1);
181 for (i = 0; i < iters; i++) {
182 bin = gst_bin_new ("somebin");
183 gst_object_ref (GST_OBJECT (bin));
184 gst_object_sink (GST_OBJECT (bin));
185 gst_object_unref (GST_OBJECT (bin));
187 g_print ("create/ref/sink/unref %d bins %d\n", iters,
188 gst_alloc_trace_live_all () - usage1);
190 bin = gst_bin_new ("somebin");
191 g_assert (!GST_OBJECT_IS_DESTROYED (bin));
192 gst_object_unref (GST_OBJECT (bin));
194 g_assert (GST_OBJECT_IS_DESTROYED (bin));
195 gst_object_unref (GST_OBJECT (bin));
197 g_print ("create/destroy/unref new bin %d\n",
198 gst_alloc_trace_live_all () - usage1);
200 for (i = 0; i < iters; i++) {
201 bin = gst_bin_new ("somebin");
202 gst_object_unref (GST_OBJECT (bin));
204 gst_object_unref (GST_OBJECT (bin));
207 g_print ("create/destroy/unref %d bin %d\n", iters,
208 gst_alloc_trace_live_all () - usage1);
210 bin = gst_bin_new ("somebin");
211 gst_object_ref (GST_OBJECT (bin));
212 gst_object_unref (GST_OBJECT (bin));
213 gst_object_unref (GST_OBJECT (bin));
214 g_print ("create/ref/unref/unref new bin %d\n",
215 gst_alloc_trace_live_all () - usage1);
217 for (i = 0; i < iters; i++) {
218 bin = gst_bin_new ("somebin");
219 gst_object_ref (GST_OBJECT (bin));
220 gst_object_unref (GST_OBJECT (bin));
221 gst_object_unref (GST_OBJECT (bin));
223 g_print ("create/ref/unref/unref %d bin %d\n", iters,
224 gst_alloc_trace_live_all () - usage1);
226 bin = gst_bin_new ("somebin");
227 gst_object_ref (GST_OBJECT (bin));
228 gst_object_unref (GST_OBJECT (bin));
229 gst_object_unref (GST_OBJECT (bin));
231 gst_object_unref (GST_OBJECT (bin));
233 g_print ("craete/ref/destroy/unref/unref new bin %d\n",
234 gst_alloc_trace_live_all () - usage1);
236 for (i = 0; i < iters; i++) {
237 bin = gst_bin_new ("somebin");
238 gst_object_ref (GST_OBJECT (bin));
239 gst_object_unref (GST_OBJECT (bin));
240 gst_object_unref (GST_OBJECT (bin));
242 gst_object_unref (GST_OBJECT (bin));
245 g_print ("craete/ref/destroy/unref/unref %d bins %d\n", iters,
246 gst_alloc_trace_live_all () - usage1);
248 for (i = 0; i < iters; i++) {
249 bin = gst_bin_new ("somebin");
250 gst_object_ref (GST_OBJECT (bin));
251 gst_element_set_name (bin, "testing123");
252 gst_object_unref (GST_OBJECT (bin));
253 gst_element_set_name (bin, "testing123");
254 gst_object_unref (GST_OBJECT (bin));
256 gst_object_unref (GST_OBJECT (bin));
259 g_print ("craete/ref/destroy/unref/unref %d bins with name %d\n", iters,
260 gst_alloc_trace_live_all () - usage1);
262 bin = gst_bin_new ("somebin");
263 for (i = 0; i < iters; i++) {
264 gst_element_set_name (bin, "testing");
266 gst_object_unref (GST_OBJECT (bin));
267 g_print ("set name %d times %d\n", iters,
268 gst_alloc_trace_live_all () - usage1);
270 for (i = 0; i < iters; i++) {
272 gst_object_unref (GST_OBJECT (bin));
274 g_print ("create/unref %d bin with children %d\n", iters,
275 gst_alloc_trace_live_all () - usage1);
277 for (i = 0; i < iters / 2; i++) {
278 bin = create_bin_ghostpads ();
279 gst_object_unref (GST_OBJECT (bin));
281 g_print ("create/unref %d bin with children and ghostpads %d\n", iters / 2,
282 gst_alloc_trace_live_all () - usage1);
284 for (i = 0; i < iters; i++) {
287 g_print ("add/remove test1 %d in bin %d\n", iters,
288 gst_alloc_trace_live_all () - usage1);
290 for (i = 0; i < iters; i++) {
293 g_print ("add/remove test2 %d in bin %d\n", iters,
294 gst_alloc_trace_live_all () - usage1);
297 for (i = 0; i < iters; i++) {
300 g_print ("add/destroy/remove test3 %d in bin %d\n", iters,
301 gst_alloc_trace_live_all () - usage1);
305 for (i = 0; i < iters; i++) {
308 g_print ("add/destroy/remove test4 %d in bin %d\n", iters,
309 gst_alloc_trace_live_all () - usage1);
312 g_print ("leaked: %d\n", gst_alloc_trace_live_all () - usage1);
314 //gst_alloc_trace_print_all ();
316 //return (gst_alloc_trace_live_all () - usage1 ? -1 : 0);