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

Revision 21005, 8.5 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21004, which included commits to RCS files with non-trunk default branches.
RevLine 
[18713]1#include <gst/gst.h>
2
[21004]3#define ITERS 100
[18713]4#include <stdlib.h>
5
[21004]6static GstElement *
[18713]7create_bin (void)
8{
9  GstElement *bin;
10  GstElement *element;
11
12  bin = gst_bin_new ("testbin");
[21004]13  g_assert (GST_IS_BIN (bin));
[18713]14  element = gst_element_factory_make ("fakesrc", NULL);
[21004]15  g_assert (GST_IS_ELEMENT (element));
[18713]16  gst_element_set_name (element, "test1");
17  gst_bin_add (GST_BIN (bin), element);
18  element = gst_element_factory_make ("fakesrc", NULL);
[21004]19  g_assert (GST_IS_ELEMENT (element));
[18713]20  gst_element_set_name (element, "test2");
21  gst_bin_add (GST_BIN (bin), element);
22
23  return bin;
24}
25
[21004]26static GstElement *
[18713]27create_bin_ghostpads (void)
28{
29  GstElement *bin;
30  GstElement *element1, *element2;
31
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");
[21004]38  gst_element_add_ghost_pad (bin, gst_element_get_pad (element1, "sink"),
39      "ghost_sink");
[18713]40
41  return bin;
42}
43
44static void
45add_remove_test1 (void)
46{
47  GstElement *bin;
48  GstElement *element;
49
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_FLOATING (element));
54  gst_bin_add (GST_BIN (bin), element);
55  g_assert (!GST_OBJECT_FLOATING (element));
56  gst_bin_remove (GST_BIN (bin), element);
57
58  gst_object_unref (GST_OBJECT (bin));
59}
60
61static void
62add_remove_test2 (void)
63{
64  GstElement *bin;
65  GstElement *element;
66
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_FLOATING (element));
72  gst_bin_add (GST_BIN (bin), element);
73  g_assert (!GST_OBJECT_FLOATING (element));
74  gst_bin_remove (GST_BIN (bin), element);
75  g_assert (!GST_OBJECT_FLOATING (element));
76  g_assert (!GST_OBJECT_DESTROYED (element));
77
[21004]78  gst_object_unref (GST_OBJECT (element));
79#if 0
[18713]80  g_assert (GST_OBJECT_DESTROYED (element));
81  gst_object_unref (GST_OBJECT (element));
[21004]82#endif
[18713]83
84  gst_object_unref (GST_OBJECT (bin));
85}
86
[21004]87#if 0
88/* This code is bogus */
[18713]89static void
90add_remove_test3 (void)
91{
92  GstElement *bin;
93  GstElement *element;
94
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));
101
[21004]102  gst_object_unref (GST_OBJECT (element));
[18713]103  g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL);
104
105  gst_object_unref (GST_OBJECT (bin));
106}
[21004]107#endif
[18713]108
[21004]109#if 0
110/* This code is bogus */
[18713]111static void
112add_remove_test4 (void)
113{
114  GstElement *bin, *bin2;
115  GstElement *element;
116
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));
123
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));
128
[21004]129  gst_object_unref (GST_OBJECT (bin2));
[18713]130  g_assert (gst_bin_get_by_name (GST_BIN (bin), "testbin") == NULL);
[21004]131  gst_object_unref (GST_OBJECT (element));
[18713]132  g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL);
133
134  gst_object_unref (GST_OBJECT (bin));
135}
[21004]136#endif
[18713]137
138int
[21004]139main (int argc, gchar * argv[])
[18713]140{
141  GstElement *bin;
[21004]142  int usage1;
[18713]143  gint i, iters;
144
[21004]145  gst_alloc_trace_set_flags_all (GST_ALLOC_TRACE_LIVE);
146
[18713]147  gst_init (&argc, &argv);
148
149  if (argc == 2)
150    iters = atoi (argv[1]);
151  else
152    iters = ITERS;
153
[21004]154
[18713]155  g_print ("starting test\n");
156
[21004]157  usage1 = gst_alloc_trace_live_all ();
158  //gst_alloc_trace_print_all ();
159
[18713]160  bin = gst_bin_new ("somebin");
161  gst_object_unref (GST_OBJECT (bin));
[21004]162  g_print ("create/unref new bin %d\n", gst_alloc_trace_live_all () - usage1);
[18713]163
[21004]164  for (i = 0; i < iters; i++) {
[18713]165    bin = gst_bin_new ("somebin");
166    gst_object_unref (GST_OBJECT (bin));
167  }
[21004]168  g_print ("create/unref %d bins %d\n", iters,
169      gst_alloc_trace_live_all () - usage1);
[18713]170
171  bin = gst_bin_new ("somebin");
172  g_assert (GST_OBJECT_FLOATING (bin));
173  gst_object_ref (GST_OBJECT (bin));
174  gst_object_sink (GST_OBJECT (bin));
175  g_assert (!GST_OBJECT_FLOATING (bin));
176  gst_object_unref (GST_OBJECT (bin));
[21004]177  g_print ("create/ref/sink/unref new bin %d\n",
178      gst_alloc_trace_live_all () - usage1);
[18713]179
180
[21004]181  for (i = 0; i < iters; i++) {
[18713]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));
186  }
[21004]187  g_print ("create/ref/sink/unref %d bins %d\n", iters,
188      gst_alloc_trace_live_all () - usage1);
[18713]189
190  bin = gst_bin_new ("somebin");
191  g_assert (!GST_OBJECT_DESTROYED (bin));
[21004]192  gst_object_unref (GST_OBJECT (bin));
193#if 0
[18713]194  g_assert (GST_OBJECT_DESTROYED (bin));
195  gst_object_unref (GST_OBJECT (bin));
[21004]196#endif
197  g_print ("create/destroy/unref new bin %d\n",
198      gst_alloc_trace_live_all () - usage1);
199
200  for (i = 0; i < iters; i++) {
[18713]201    bin = gst_bin_new ("somebin");
202    gst_object_unref (GST_OBJECT (bin));
[21004]203#if 0
204    gst_object_unref (GST_OBJECT (bin));
205#endif
[18713]206  }
[21004]207  g_print ("create/destroy/unref %d bin %d\n", iters,
208      gst_alloc_trace_live_all () - usage1);
[18713]209
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));
[21004]214  g_print ("create/ref/unref/unref new bin %d\n",
215      gst_alloc_trace_live_all () - usage1);
216
217  for (i = 0; i < iters; i++) {
[18713]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));
222  }
[21004]223  g_print ("create/ref/unref/unref %d bin %d\n", iters,
224      gst_alloc_trace_live_all () - usage1);
[18713]225
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));
[21004]230#if 0
231  gst_object_unref (GST_OBJECT (bin));
232#endif
233  g_print ("craete/ref/destroy/unref/unref new bin %d\n",
234      gst_alloc_trace_live_all () - usage1);
235
236  for (i = 0; i < iters; i++) {
[18713]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));
[21004]241#if 0
242    gst_object_unref (GST_OBJECT (bin));
243#endif
[18713]244  }
[21004]245  g_print ("craete/ref/destroy/unref/unref %d bins %d\n", iters,
246      gst_alloc_trace_live_all () - usage1);
[18713]247
[21004]248  for (i = 0; i < iters; i++) {
[18713]249    bin = gst_bin_new ("somebin");
250    gst_object_ref (GST_OBJECT (bin));
251    gst_element_set_name (bin, "testing123");
[21004]252    gst_object_unref (GST_OBJECT (bin));
[18713]253    gst_element_set_name (bin, "testing123");
254    gst_object_unref (GST_OBJECT (bin));
[21004]255#if 0
[18713]256    gst_object_unref (GST_OBJECT (bin));
[21004]257#endif
[18713]258  }
[21004]259  g_print ("craete/ref/destroy/unref/unref %d bins with name %d\n", iters,
260      gst_alloc_trace_live_all () - usage1);
[18713]261
262  bin = gst_bin_new ("somebin");
[21004]263  for (i = 0; i < iters; i++) {
[18713]264    gst_element_set_name (bin, "testing");
265  }
266  gst_object_unref (GST_OBJECT (bin));
[21004]267  g_print ("set name %d times %d\n", iters,
268      gst_alloc_trace_live_all () - usage1);
[18713]269
[21004]270  for (i = 0; i < iters; i++) {
271    bin = create_bin ();
[18713]272    gst_object_unref (GST_OBJECT (bin));
273  }
[21004]274  g_print ("create/unref %d bin with children %d\n", iters,
275      gst_alloc_trace_live_all () - usage1);
[18713]276
[21004]277  for (i = 0; i < iters / 2; i++) {
278    bin = create_bin_ghostpads ();
[18713]279    gst_object_unref (GST_OBJECT (bin));
280  }
[21004]281  g_print ("create/unref %d bin with children and ghostpads %d\n", iters / 2,
282      gst_alloc_trace_live_all () - usage1);
[18713]283
[21004]284  for (i = 0; i < iters; i++) {
285    add_remove_test1 ();
[18713]286  }
[21004]287  g_print ("add/remove test1 %d in bin %d\n", iters,
288      gst_alloc_trace_live_all () - usage1);
[18713]289
[21004]290  for (i = 0; i < iters; i++) {
291    add_remove_test2 ();
[18713]292  }
[21004]293  g_print ("add/remove test2 %d in bin %d\n", iters,
294      gst_alloc_trace_live_all () - usage1);
[18713]295
[21004]296#if 0
297  for (i = 0; i < iters; i++) {
298    add_remove_test3 ();
[18713]299  }
[21004]300  g_print ("add/destroy/remove test3 %d in bin %d\n", iters,
301      gst_alloc_trace_live_all () - usage1);
302#endif
[18713]303
[21004]304#if 0
305  for (i = 0; i < iters; i++) {
306    add_remove_test4 ();
[18713]307  }
[21004]308  g_print ("add/destroy/remove test4 %d in bin %d\n", iters,
309      gst_alloc_trace_live_all () - usage1);
310#endif
[18713]311
[21004]312  g_print ("leaked: %d\n", gst_alloc_trace_live_all () - usage1);
[18713]313
[21004]314  //gst_alloc_trace_print_all ();
315
316  //return (gst_alloc_trace_live_all () - usage1 ? -1 : 0);
317  return 0;
[18713]318}
Note: See TracBrowser for help on using the repository browser.