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

Revision 21005, 4.6 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.
Line 
1#include <gst/gst.h>
2
3#define ITERS 100000
4#include <stdlib.h>
5#include "mem.h"
6
7int
8main (int argc, gchar * argv[])
9{
10  GstObject *object, *object2;
11  long usage1;
12  gint i, iters;
13
14  gst_init (&argc, &argv);
15
16  if (argc == 2)
17    iters = atoi (argv[1]);
18  else
19    iters = ITERS;
20
21  g_print ("starting test with %d iterations\n", iters);
22  usage1 = vmsize ();
23  object = gst_object_new ();
24  gst_object_unref (object);
25  g_print ("create/unref new object %ld\n", vmsize () - usage1);
26
27  for (i = 0; i < iters; i++) {
28    object = gst_object_new ();
29    gst_object_unref (object);
30
31  }
32  g_print ("create/unref %d object %ld\n", iters, vmsize () - usage1);
33
34  object = gst_object_new ();
35  g_assert (GST_OBJECT_FLOATING (object));
36  gst_object_ref (object);
37  gst_object_sink (object);
38  g_assert (!GST_OBJECT_FLOATING (object));
39  gst_object_unref (object);
40  g_print ("create/ref/sink/unref new object %ld\n", vmsize () - usage1);
41
42  for (i = 0; i < iters; i++) {
43    object = gst_object_new ();
44    gst_object_ref (object);
45    gst_object_sink (object);
46    gst_object_unref (object);
47  }
48  g_print ("create/ref/sink/unref %d object %ld\n", iters, vmsize () - usage1);
49
50  object = gst_object_new ();
51  g_assert (!GST_OBJECT_DESTROYED (object));
52  gst_object_unref (object);
53  g_assert (GST_OBJECT_DESTROYED (object));
54  gst_object_unref (object);
55  g_print ("create/destroy/unref new object %ld\n", vmsize () - usage1);
56
57  for (i = 0; i < iters; i++) {
58    object = gst_object_new ();
59    gst_object_unref (object);
60    gst_object_unref (object);
61  }
62  g_print ("destroy/unref %d object %ld\n", iters, vmsize () - usage1);
63
64  object = gst_object_new ();
65  gst_object_ref (object);
66  gst_object_unref (object);
67  gst_object_unref (object);
68  g_print ("create/ref/unref/unref new object %ld\n", vmsize () - usage1);
69
70  for (i = 0; i < iters; i++) {
71    object = gst_object_new ();
72    gst_object_ref (object);
73    gst_object_unref (object);
74    gst_object_unref (object);
75  }
76  g_print ("create/ref/unref/unref %d object %ld\n", iters, vmsize () - usage1);
77
78  object = gst_object_new ();
79  gst_object_ref (object);
80  gst_object_unref (object);
81  gst_object_unref (object);
82  gst_object_unref (object);
83  g_print ("create/ref/destroy/unref/unref new object %ld\n",
84      vmsize () - usage1);
85
86  for (i = 0; i < iters; i++) {
87    object = gst_object_new ();
88    gst_object_ref (object);
89    gst_object_unref (object);
90    gst_object_unref (object);
91    gst_object_unref (object);
92  }
93  g_print ("create/ref/destroy/unref/unref %d object %ld\n", iters,
94      vmsize () - usage1);
95
96  for (i = 0; i < iters; i++) {
97    object = gst_object_new ();
98    gst_object_ref (object);
99    gst_object_set_name (object, "testing123");
100    gst_object_unref (object);
101    gst_object_set_name (object, "testing123");
102    gst_object_unref (object);
103    gst_object_unref (object);
104  }
105  g_print ("create/ref/destroy/unref/unref %d object  with name %ld\n", iters,
106      vmsize () - usage1);
107
108  object = gst_object_new ();
109  for (i = 0; i < iters; i++) {
110    gst_object_set_name (object, "testing");
111  }
112  gst_object_unref (object);
113  g_print ("create/set name/unref %d object %ld\n", iters, vmsize () - usage1);
114
115  object = gst_object_new ();
116  object2 = gst_object_new ();
117  g_assert (GST_OBJECT_FLOATING (object));
118  g_assert (GST_OBJECT_FLOATING (object2));
119
120  gst_object_set_parent (object, object2);
121  g_assert (GST_OBJECT_FLOATING (object2));
122  g_assert (!GST_OBJECT_FLOATING (object));
123
124  g_print ("parentage flags set_parent ok %ld\n", vmsize () - usage1);
125
126  gst_object_ref (object);
127  gst_object_unparent (object);
128  g_assert (GST_OBJECT_FLOATING (object2));
129  g_assert (!GST_OBJECT_FLOATING (object));
130  g_assert (gst_object_get_parent (object) == NULL);
131
132  g_print ("parentage flags unparent ok %ld\n", vmsize () - usage1);
133
134  gst_object_set_parent (object, object2);
135  g_assert (GST_OBJECT_FLOATING (object2));
136  g_assert (!GST_OBJECT_FLOATING (object));
137  g_assert (gst_object_get_parent (object) == object2);
138
139  gst_object_unref (object);
140  g_assert (GST_OBJECT_DESTROYED (object));
141  g_assert (!GST_OBJECT_FLOATING (object));
142  g_assert (gst_object_get_parent (object) == NULL);
143  gst_object_unref (object);
144
145  g_print ("parentage flags destroy ok %ld\n", vmsize () - usage1);
146
147  for (i = 0; i < iters; i++) {
148    object = gst_object_new ();
149    object2 = gst_object_new ();
150    gst_object_set_parent (object2, object);
151    gst_object_unref (object);
152    gst_object_unref (object2);
153  }
154  g_print ("create/unref %d 2 parented objects %ld\n", iters,
155      vmsize () - usage1);
156
157  g_print ("leaked: %ld\n", vmsize () - usage1);
158
159  return (vmsize () - usage1 ? -1 : 0);
160}
Note: See TracBrowser for help on using the repository browser.