source: trunk/third/gstreamer/testsuite/refcounting/bin.c @ 18714

Revision 18714, 7.5 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18713, which included commits to RCS files with non-trunk default branches.
Line 
1#include <gst/gst.h>
2
3#define ITERS 100000
4#include <stdlib.h>
5#include "mem.h"
6
7static GstElement*
8create_bin (void)
9{
10  GstElement *bin;
11  GstElement *element;
12
13  bin = gst_bin_new ("testbin");
14  element = gst_element_factory_make ("fakesrc", NULL);
15  gst_element_set_name (element, "test1");
16  gst_bin_add (GST_BIN (bin), element);
17  element = gst_element_factory_make ("fakesrc", NULL);
18  gst_element_set_name (element, "test2");
19  gst_bin_add (GST_BIN (bin), element);
20
21  return bin;
22}
23
24static GstElement*
25create_bin_ghostpads (void)
26{
27  GstElement *bin;
28  GstElement *element1, *element2;
29
30  bin = gst_bin_new ("testbin");
31  element1 = gst_element_factory_make ("identity", NULL);
32  gst_bin_add (GST_BIN (bin), element1);
33  element2 = gst_element_factory_make ("fakesink", NULL);
34  gst_bin_add (GST_BIN (bin), element2);
35  gst_element_link_pads (element1, "src", element2, "sink");
36  gst_element_add_ghost_pad (bin, gst_element_get_pad (element1, "sink"), "ghost_sink");
37
38  return bin;
39}
40
41static void
42add_remove_test1 (void)
43{
44  GstElement *bin;
45  GstElement *element;
46
47  bin = gst_bin_new ("testbin");
48  element = gst_element_factory_make ("fakesrc", NULL);
49  gst_element_set_name (element, "test1");
50  g_assert (GST_OBJECT_FLOATING (element));
51  gst_bin_add (GST_BIN (bin), element);
52  g_assert (!GST_OBJECT_FLOATING (element));
53  gst_bin_remove (GST_BIN (bin), element);
54
55  gst_object_unref (GST_OBJECT (bin));
56}
57
58static void
59add_remove_test2 (void)
60{
61  GstElement *bin;
62  GstElement *element;
63
64  bin = gst_bin_new ("testbin");
65  element = gst_element_factory_make ("fakesrc", NULL);
66  gst_element_set_name (element, "test1");
67  gst_object_ref (GST_OBJECT (element));
68  g_assert (GST_OBJECT_FLOATING (element));
69  gst_bin_add (GST_BIN (bin), element);
70  g_assert (!GST_OBJECT_FLOATING (element));
71  gst_bin_remove (GST_BIN (bin), element);
72  g_assert (!GST_OBJECT_FLOATING (element));
73  g_assert (!GST_OBJECT_DESTROYED (element));
74
75  gst_object_destroy (GST_OBJECT (element));
76  g_assert (GST_OBJECT_DESTROYED (element));
77  gst_object_unref (GST_OBJECT (element));
78
79  gst_object_unref (GST_OBJECT (bin));
80}
81
82static void
83add_remove_test3 (void)
84{
85  GstElement *bin;
86  GstElement *element;
87
88  bin = gst_bin_new ("testbin");
89  element = gst_element_factory_make ("fakesrc", NULL);
90  gst_element_set_name (element, "test1");
91  g_assert (GST_OBJECT_FLOATING (element));
92  gst_bin_add (GST_BIN (bin), element);
93  g_assert (!GST_OBJECT_FLOATING (element));
94
95  gst_object_destroy (GST_OBJECT (element));
96  g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL);
97
98  gst_object_unref (GST_OBJECT (bin));
99}
100
101static void
102add_remove_test4 (void)
103{
104  GstElement *bin, *bin2;
105  GstElement *element;
106
107  bin = gst_bin_new ("testbin");
108  element = gst_element_factory_make ("fakesrc", NULL);
109  gst_element_set_name (element, "test1");
110  g_assert (GST_OBJECT_FLOATING (element));
111  gst_bin_add (GST_BIN (bin), element);
112  g_assert (!GST_OBJECT_FLOATING (element));
113
114  bin2 = create_bin ();
115  g_assert (GST_OBJECT_FLOATING (bin2));
116  gst_bin_add (GST_BIN (bin), bin2);
117  g_assert (!GST_OBJECT_FLOATING (bin2));
118
119  gst_object_destroy (GST_OBJECT (bin2));
120  g_assert (gst_bin_get_by_name (GST_BIN (bin), "testbin") == NULL);
121  gst_object_destroy (GST_OBJECT (element));
122  g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL);
123
124  gst_object_unref (GST_OBJECT (bin));
125}
126
127int
128main (int argc, gchar *argv[])
129{
130  GstElement *bin;
131  long usage1;
132  gint i, iters;
133
134  gst_init (&argc, &argv);
135
136  if (argc == 2)
137    iters = atoi (argv[1]);
138  else
139    iters = ITERS;
140
141  g_print ("starting test\n");
142  usage1 = vmsize();
143
144  bin = gst_bin_new ("somebin");
145  gst_object_unref (GST_OBJECT (bin));
146  g_print ("create/unref new bin %ld\n", vmsize()-usage1);
147
148  for (i=0; i<iters;i++) {
149    bin = gst_bin_new ("somebin");
150    gst_object_unref (GST_OBJECT (bin));
151  }
152  g_print ("create/unref %d bins %ld\n", iters, vmsize()-usage1);
153
154  bin = gst_bin_new ("somebin");
155  g_assert (GST_OBJECT_FLOATING (bin));
156  gst_object_ref (GST_OBJECT (bin));
157  gst_object_sink (GST_OBJECT (bin));
158  g_assert (!GST_OBJECT_FLOATING (bin));
159  gst_object_unref (GST_OBJECT (bin));
160  g_print ("create/ref/sink/unref new bin %ld\n", vmsize()-usage1);
161
162
163  for (i=0; i<iters;i++) {
164    bin = gst_bin_new ("somebin");
165    gst_object_ref (GST_OBJECT (bin));
166    gst_object_sink (GST_OBJECT (bin));
167    gst_object_unref (GST_OBJECT (bin));
168  }
169  g_print ("create/ref/sink/unref %d bins %ld\n", iters, vmsize()-usage1);
170
171  bin = gst_bin_new ("somebin");
172  g_assert (!GST_OBJECT_DESTROYED (bin));
173  gst_object_destroy (GST_OBJECT (bin));
174  g_assert (GST_OBJECT_DESTROYED (bin));
175  gst_object_unref (GST_OBJECT (bin));
176  g_print ("create/destroy/unref new bin %ld\n", vmsize()-usage1);
177 
178  for (i=0; i<iters;i++) {
179    bin = gst_bin_new ("somebin");
180    gst_object_destroy (GST_OBJECT (bin));
181    gst_object_unref (GST_OBJECT (bin));
182  }
183  g_print ("create/destroy/unref %d bin %ld\n", iters, vmsize()-usage1);
184
185  bin = gst_bin_new ("somebin");
186  gst_object_ref (GST_OBJECT (bin));
187  gst_object_unref (GST_OBJECT (bin));
188  gst_object_unref (GST_OBJECT (bin));
189  g_print ("create/ref/unref/unref new bin %ld\n", vmsize()-usage1);
190 
191  for (i=0; i<iters;i++) {
192    bin = gst_bin_new ("somebin");
193    gst_object_ref (GST_OBJECT (bin));
194    gst_object_unref (GST_OBJECT (bin));
195    gst_object_unref (GST_OBJECT (bin));
196  }
197  g_print ("create/ref/unref/unref %d bin %ld\n", iters, vmsize()-usage1);
198
199  bin = gst_bin_new ("somebin");
200  gst_object_ref (GST_OBJECT (bin));
201  gst_object_destroy (GST_OBJECT (bin));
202  gst_object_unref (GST_OBJECT (bin));
203  gst_object_unref (GST_OBJECT (bin));
204  g_print ("craete/ref/destroy/unref/unref new bin %ld\n", vmsize()-usage1);
205 
206  for (i=0; i<iters;i++) {
207    bin = gst_bin_new ("somebin");
208    gst_object_ref (GST_OBJECT (bin));
209    gst_object_destroy (GST_OBJECT (bin));
210    gst_object_unref (GST_OBJECT (bin));
211    gst_object_unref (GST_OBJECT (bin));
212  }
213  g_print ("craete/ref/destroy/unref/unref %d bins %ld\n", iters, vmsize()-usage1);
214
215  for (i=0; i<iters;i++) {
216    bin = gst_bin_new ("somebin");
217    gst_object_ref (GST_OBJECT (bin));
218    gst_element_set_name (bin, "testing123");
219    gst_object_destroy (GST_OBJECT (bin));
220    gst_element_set_name (bin, "testing123");
221    gst_object_unref (GST_OBJECT (bin));
222    gst_object_unref (GST_OBJECT (bin));
223  }
224  g_print ("craete/ref/destroy/unref/unref %d bins with name %ld\n", iters, vmsize()-usage1);
225
226  bin = gst_bin_new ("somebin");
227  for (i=0; i<iters;i++) {
228    gst_element_set_name (bin, "testing");
229  }
230  gst_object_unref (GST_OBJECT (bin));
231  g_print ("set name %d times %ld\n", iters, vmsize()-usage1);
232
233  for (i=0; i<iters;i++) {
234    bin = create_bin();
235    gst_object_unref (GST_OBJECT (bin));
236  }
237  g_print ("create/unref %d bin with children %ld\n", iters, vmsize()-usage1);
238
239  for (i=0; i<iters/2;i++) {
240    bin = create_bin_ghostpads();
241    gst_object_unref (GST_OBJECT (bin));
242  }
243  g_print ("create/unref %d bin with children and ghostpads %ld\n", iters/2, vmsize()-usage1);
244
245  for (i=0; i<iters;i++) {
246    add_remove_test1();
247  }
248  g_print ("add/remove test1 %d in bin %ld\n", iters, vmsize()-usage1);
249
250  for (i=0; i<iters;i++) {
251    add_remove_test2();
252  }
253  g_print ("add/remove test2 %d in bin %ld\n", iters, vmsize()-usage1);
254
255  for (i=0; i<iters;i++) {
256    add_remove_test3();
257  }
258  g_print ("add/destroy/remove test3 %d in bin %ld\n", iters, vmsize()-usage1);
259
260  for (i=0; i<iters;i++) {
261    add_remove_test4();
262  }
263  g_print ("add/destroy/remove test4 %d in bin %ld\n", iters, vmsize()-usage1);
264
265  g_print ("leaked: %ld\n", vmsize()-usage1);
266
267  return (vmsize()-usage1 ? -1 : 0);
268}
Note: See TracBrowser for help on using the repository browser.