13 thread = gst_thread_new ("testthread");
14 element = gst_element_new ();
15 gst_element_set_name (element, "test1");
16 gst_bin_add (GST_BIN (thread), element);
17 element = gst_element_new ();
18 gst_element_set_name (element, "test2");
19 gst_bin_add (GST_BIN (thread), element);
25 create_thread_ghostpads (void)
28 GstElement *element1, *element2;
30 thread = gst_thread_new ("testthread");
31 element1 = gst_element_new ();
32 gst_element_set_name (element1, "test1");
33 gst_element_add_pad (element1, gst_pad_new ("src1", GST_PAD_SRC));
34 gst_bin_add (GST_BIN (thread), element1);
35 element2 = gst_element_new ();
36 gst_element_set_name (element2, "test2");
37 gst_element_add_pad (element2, gst_pad_new ("sink1", GST_PAD_SINK));
38 gst_bin_add (GST_BIN (thread), element2);
39 gst_element_link (element1, "src1", element2, "sink1");
40 gst_element_add_ghost_pad (thread, gst_element_get_pad (element2, "sink1"), "sink1");
46 add_remove_test1 (void)
51 thread = gst_thread_new ("testthread");
52 element = gst_element_new ();
53 gst_element_set_name (element, "test1");
54 g_assert (GST_OBJECT_FLOATING (element));
55 gst_bin_add (GST_BIN (thread), element);
56 g_assert (!GST_OBJECT_FLOATING (element));
57 gst_bin_remove (GST_BIN (thread), element);
59 gst_object_unref (GST_OBJECT (thread));
63 add_remove_test2 (void)
68 thread = gst_thread_new ("testthread");
69 element = gst_element_new ();
70 gst_element_set_name (element, "test1");
71 gst_object_ref (GST_OBJECT (element));
72 g_assert (GST_OBJECT_FLOATING (element));
73 gst_bin_add (GST_BIN (thread), element);
74 g_assert (!GST_OBJECT_FLOATING (element));
75 gst_bin_remove (GST_BIN (thread), element);
76 g_assert (!GST_OBJECT_FLOATING (element));
77 g_assert (!GST_OBJECT_DESTROYED (element));
79 gst_object_unref (GST_OBJECT (element));
80 g_assert (GST_OBJECT_DESTROYED (element));
81 gst_object_unref (GST_OBJECT (element));
83 gst_object_unref (GST_OBJECT (thread));
87 add_remove_test3 (void)
92 thread = gst_thread_new ("testthread");
93 element = gst_element_new ();
94 gst_element_set_name (element, "test1");
95 g_assert (GST_OBJECT_FLOATING (element));
96 gst_bin_add (GST_BIN (thread), element);
97 g_assert (!GST_OBJECT_FLOATING (element));
99 gst_object_unref (GST_OBJECT (element));
100 g_assert (gst_bin_get_by_name (GST_BIN (thread), "test1") == NULL);
102 gst_object_unref (GST_OBJECT (thread));
106 add_remove_test4 (void)
108 GstElement *thread, *thread2;
111 thread = gst_thread_new ("testthread");
112 element = gst_element_new ();
113 gst_element_set_name (element, "test1");
114 g_assert (GST_OBJECT_FLOATING (element));
115 gst_bin_add (GST_BIN (thread), element);
116 g_assert (!GST_OBJECT_FLOATING (element));
118 thread2 = create_thread ();
119 g_assert (GST_OBJECT_FLOATING (thread2));
120 gst_bin_add (GST_BIN (thread), thread2);
121 g_assert (!GST_OBJECT_FLOATING (thread2));
123 gst_object_unref (GST_OBJECT (thread2));
124 g_assert (gst_bin_get_by_name (GST_BIN (thread), "testthread") == NULL);
125 gst_object_unref (GST_OBJECT (element));
126 g_assert (gst_bin_get_by_name (GST_BIN (thread), "test1") == NULL);
128 gst_object_unref (GST_OBJECT (thread));
132 main (int argc, gchar *argv[])
134 GstElement *thread, *element;
138 gst_init (&argc, &argv);
141 iters = atoi (argv[1]);
145 g_print ("starting test\n");
148 thread = gst_thread_new ("somethread");
149 gst_object_unref (GST_OBJECT (thread));
150 g_print ("create/unref new thread %ld\n", vmsize()-usage1);
152 for (i=0; i<iters;i++) {
153 thread = gst_thread_new ("somethread");
154 gst_object_unref (GST_OBJECT (thread));
156 g_print ("create/unref %d threads %ld\n", iters, vmsize()-usage1);
158 thread = gst_thread_new ("somethread");
159 g_assert (GST_OBJECT_FLOATING (thread));
160 gst_object_ref (GST_OBJECT (thread));
161 gst_object_sink (GST_OBJECT (thread));
162 g_assert (!GST_OBJECT_FLOATING (thread));
163 gst_object_unref (GST_OBJECT (thread));
164 g_print ("create/ref/sink/unref new thread %ld\n", vmsize()-usage1);
167 for (i=0; i<iters;i++) {
168 thread = gst_thread_new ("somethread");
169 gst_object_ref (GST_OBJECT (thread));
170 gst_object_sink (GST_OBJECT (thread));
171 gst_object_unref (GST_OBJECT (thread));
173 g_print ("create/ref/sink/unref %d threads %ld\n", iters, vmsize()-usage1);
175 thread = gst_thread_new ("somethread");
176 g_assert (!GST_OBJECT_DESTROYED (thread));
177 gst_object_unref (GST_OBJECT (thread));
178 g_assert (GST_OBJECT_DESTROYED (thread));
179 gst_object_unref (GST_OBJECT (thread));
180 g_print ("create/destroy/unref new thread %ld\n", vmsize()-usage1);
182 for (i=0; i<iters;i++) {
183 thread = gst_thread_new ("somethread");
184 gst_object_unref (GST_OBJECT (thread));
185 gst_object_unref (GST_OBJECT (thread));
187 g_print ("create/destroy/unref %d thread %ld\n", iters, vmsize()-usage1);
189 thread = gst_thread_new ("somethread");
190 gst_object_ref (GST_OBJECT (thread));
191 gst_object_unref (GST_OBJECT (thread));
192 gst_object_unref (GST_OBJECT (thread));
193 g_print ("create/ref/unref/unref new thread %ld\n", vmsize()-usage1);
195 for (i=0; i<iters;i++) {
196 thread = gst_thread_new ("somethread");
197 gst_object_ref (GST_OBJECT (thread));
198 gst_object_unref (GST_OBJECT (thread));
199 gst_object_unref (GST_OBJECT (thread));
201 g_print ("create/ref/unref/unref %d thread %ld\n", iters, vmsize()-usage1);
203 thread = gst_thread_new ("somethread");
204 gst_object_ref (GST_OBJECT (thread));
205 gst_object_unref (GST_OBJECT (thread));
206 gst_object_unref (GST_OBJECT (thread));
207 gst_object_unref (GST_OBJECT (thread));
208 g_print ("craete/ref/destroy/unref/unref new thread %ld\n", vmsize()-usage1);
210 for (i=0; i<iters;i++) {
211 thread = gst_thread_new ("somethread");
212 gst_object_ref (GST_OBJECT (thread));
213 gst_object_unref (GST_OBJECT (thread));
214 gst_object_unref (GST_OBJECT (thread));
215 gst_object_unref (GST_OBJECT (thread));
217 g_print ("craete/ref/destroy/unref/unref %d threads %ld\n", iters, vmsize()-usage1);
219 for (i=0; i<iters;i++) {
220 thread = gst_thread_new ("somethread");
221 gst_object_ref (GST_OBJECT (thread));
222 gst_element_set_name (thread, "testing123");
223 gst_object_unref (GST_OBJECT (thread));
224 gst_element_set_name (thread, "testing123");
225 gst_object_unref (GST_OBJECT (thread));
226 gst_object_unref (GST_OBJECT (thread));
228 g_print ("craete/ref/destroy/unref/unref %d threads with name %ld\n", iters, vmsize()-usage1);
230 thread = gst_thread_new ("somethread");
231 for (i=0; i<iters;i++) {
232 gst_element_set_name (thread, "testing");
234 gst_object_unref (GST_OBJECT (thread));
235 g_print ("set name %d times %ld\n", iters, vmsize()-usage1);
237 for (i=0; i<iters;i++) {
238 thread = gst_thread_new ("somethread");
239 element = gst_element_new ();
240 gst_element_set_name (element, "test1");
241 gst_bin_add (GST_BIN (thread), element);
242 gst_object_unref (GST_OBJECT (thread));
244 g_print ("create/unref %d thread with one element %ld\n", iters, vmsize()-usage1);
246 for (i=0; i<iters;i++) {
247 thread = create_thread();
248 gst_object_unref (GST_OBJECT (thread));
250 g_print ("create/unref %d thread with children %ld\n", iters, vmsize()-usage1);
252 for (i=0; i<iters/2;i++) {
253 thread = create_thread_ghostpads();
254 gst_object_unref (GST_OBJECT (thread));
256 g_print ("create/unref %d thread with children and ghostpads %ld\n", iters/2, vmsize()-usage1);
258 for (i=0; i<iters;i++) {
261 g_print ("add/remove test1 %d in thread %ld\n", iters, vmsize()-usage1);
263 for (i=0; i<iters;i++) {
266 g_print ("add/remove test2 %d in thread %ld\n", iters, vmsize()-usage1);
268 for (i=0; i<iters;i++) {
271 g_print ("add/destroy/remove test3 %d in thread %ld\n", iters, vmsize()-usage1);
273 for (i=0; i<iters;i++) {
276 g_print ("add/destroy/remove test4 %d in thread %ld\n", iters, vmsize()-usage1);
278 g_print ("leaked: %ld\n", vmsize()-usage1);
280 return (vmsize()-usage1 ? -1 : 0);