2 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
4 * gstpad.c: Unit test for GstPad
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #include <gst/check/gstcheck.h>
24 GST_START_TEST (test_link)
32 src = gst_pad_new ("source", GST_PAD_SRC);
33 fail_if (src == NULL);
34 ASSERT_OBJECT_REFCOUNT (src, "source pad", 1);
36 name = gst_pad_get_name (src);
37 fail_unless (strcmp (name, "source") == 0);
38 ASSERT_OBJECT_REFCOUNT (src, "source pad", 1);
41 sink = gst_pad_new ("sink", GST_PAD_SINK);
42 fail_if (sink == NULL);
44 /* linking without templates or caps should work */
45 ret = gst_pad_link (src, sink);
46 ASSERT_OBJECT_REFCOUNT (src, "source pad", 1);
47 ASSERT_OBJECT_REFCOUNT (sink, "sink pad", 1);
48 fail_unless (ret == GST_PAD_LINK_OK);
50 ASSERT_CRITICAL (gst_pad_get_pad_template (NULL));
52 srct = gst_pad_get_pad_template (src);
53 fail_unless (srct == NULL);
54 ASSERT_OBJECT_REFCOUNT (src, "source pad", 1);
57 ASSERT_OBJECT_REFCOUNT (src, "source pad", 1);
58 gst_object_unref (src);
59 gst_object_unref (sink);
64 /* threaded link/unlink */
66 static GstPad *src, *sink;
69 thread_link_unlink (gpointer data)
73 while (THREAD_TEST_RUNNING ()) {
74 gst_pad_link (src, sink);
75 gst_pad_unlink (src, sink);
80 GST_START_TEST (test_link_unlink_threaded)
85 src = gst_pad_new ("source", GST_PAD_SRC);
86 fail_if (src == NULL);
87 sink = gst_pad_new ("sink", GST_PAD_SINK);
88 fail_if (sink == NULL);
90 caps = gst_caps_from_string ("foo/bar");
91 gst_pad_set_active (src, TRUE);
92 gst_pad_set_caps (src, caps);
93 gst_pad_set_active (sink, TRUE);
94 gst_pad_set_caps (sink, caps);
95 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
97 MAIN_START_THREADS (5, thread_link_unlink, NULL);
98 for (i = 0; i < 1000; ++i) {
99 gst_pad_is_linked (src);
100 gst_pad_is_linked (sink);
103 MAIN_STOP_THREADS ();
105 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
106 gst_caps_unref (caps);
108 ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
109 gst_object_unref (src);
110 gst_object_unref (sink);
115 GST_START_TEST (test_refcount)
119 GstPadLinkReturn plr;
121 sink = gst_pad_new ("sink", GST_PAD_SINK);
122 fail_if (sink == NULL);
124 src = gst_pad_new ("src", GST_PAD_SRC);
125 fail_if (src == NULL);
127 caps = gst_caps_from_string ("foo/bar");
129 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
131 /* can't set caps on flushing sinkpad */
132 fail_if (gst_pad_set_caps (src, caps) == TRUE);
133 fail_if (gst_pad_set_caps (sink, caps) == TRUE);
134 /* one for me and one for each set_caps */
135 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
137 gst_pad_set_active (src, TRUE);
138 fail_unless (gst_pad_set_caps (src, caps) == TRUE);
139 ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
141 gst_pad_set_active (sink, TRUE);
142 fail_unless (gst_pad_set_caps (sink, caps) == TRUE);
143 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
145 plr = gst_pad_link (src, sink);
146 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
147 /* src caps added to pending caps on sink */
148 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
150 gst_pad_unlink (src, sink);
151 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
154 gst_object_unref (src);
155 gst_object_unref (sink);
156 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
158 gst_caps_unref (caps);
163 GST_START_TEST (test_get_allowed_caps)
166 GstCaps *caps, *gotcaps;
168 GstPadLinkReturn plr;
170 ASSERT_CRITICAL (gst_pad_get_allowed_caps (NULL));
172 buffer = gst_buffer_new ();
173 ASSERT_CRITICAL (gst_pad_get_allowed_caps ((GstPad *) buffer));
174 gst_buffer_unref (buffer);
176 src = gst_pad_new ("src", GST_PAD_SRC);
177 fail_if (src == NULL);
178 caps = gst_pad_get_allowed_caps (src);
179 fail_unless (caps == NULL);
181 caps = gst_caps_from_string ("foo/bar");
183 sink = gst_pad_new ("sink", GST_PAD_SINK);
184 gst_pad_set_active (src, TRUE);
185 /* source pad is active and will accept the caps event */
186 fail_unless (gst_pad_set_caps (src, caps) == TRUE);
187 /* sink pad is not active and will refuse the caps event */
188 fail_if (gst_pad_set_caps (sink, caps) == TRUE);
189 ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
191 gst_pad_set_active (sink, TRUE);
192 /* sink pad is now active and will accept the caps event */
193 fail_unless (gst_pad_set_caps (sink, caps) == TRUE);
194 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
196 plr = gst_pad_link (src, sink);
197 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
199 gotcaps = gst_pad_get_allowed_caps (src);
200 fail_if (gotcaps == NULL);
201 fail_unless (gst_caps_is_equal (gotcaps, caps));
203 ASSERT_CAPS_REFCOUNT (gotcaps, "gotcaps", 4);
204 gst_caps_unref (gotcaps);
206 gst_pad_unlink (src, sink);
209 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
210 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
211 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
213 gst_object_unref (src);
214 gst_object_unref (sink);
216 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
217 gst_caps_unref (caps);
222 static GstCaps *event_caps = NULL;
225 sticky_event (GstPad * pad, GstObject * parent, GstEvent * event)
229 fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_CAPS);
231 /* Ensure we get here just once: */
232 fail_unless (event_caps == NULL);
234 /* The event must arrive before any buffer: */
235 fail_unless_equals_int (g_list_length (buffers), 0);
237 gst_event_parse_caps (event, &caps);
238 event_caps = gst_caps_ref (caps);
240 gst_event_unref (event);
245 /* Tests whether caps get properly forwarded when pads
246 are initially unlinked */
247 GST_START_TEST (test_sticky_caps_unlinked)
250 GstPadTemplate *src_template, *sink_template;
254 caps = gst_caps_from_string ("foo/bar, dummy=(int){1, 2}");
255 src_template = gst_pad_template_new ("src", GST_PAD_SRC,
256 GST_PAD_ALWAYS, caps);
257 sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
258 GST_PAD_ALWAYS, caps);
259 gst_caps_unref (caps);
261 src = gst_pad_new_from_template (src_template, "src");
262 fail_if (src == NULL);
263 sink = gst_pad_new_from_template (sink_template, "sink");
264 fail_if (sink == NULL);
265 gst_pad_set_event_function (sink, sticky_event);
266 gst_pad_set_chain_function (sink, gst_check_chain_func);
268 gst_object_unref (src_template);
269 gst_object_unref (sink_template);
271 caps = gst_caps_from_string ("foo/bar, dummy=(int)1");
272 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
274 event = gst_event_new_caps (caps);
275 gst_pad_set_active (src, TRUE);
276 fail_unless (gst_pad_push_event (src, event) == TRUE);
277 fail_unless (event_caps == NULL);
279 /* Linking and activating will not forward the sticky event yet... */
280 fail_unless (GST_PAD_LINK_SUCCESSFUL (gst_pad_link (src, sink)));
281 gst_pad_set_active (sink, TRUE);
282 fail_unless (event_caps == NULL);
284 /* ...but the first buffer will: */
285 fail_unless (gst_pad_push (src, gst_buffer_new ()) == GST_FLOW_OK);
286 fail_unless (event_caps == caps);
287 fail_unless_equals_int (g_list_length (buffers), 1);
289 gst_caps_replace (&caps, NULL);
290 gst_caps_replace (&event_caps, NULL);
292 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
293 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
294 gst_object_unref (src);
295 gst_object_unref (sink);
300 /* Same as test_sticky_caps_unlinked except that the source pad
301 * has a template of ANY and we will attempt to push
302 * incompatible caps */
303 GST_START_TEST (test_sticky_caps_unlinked_incompatible)
305 GstCaps *caps, *failcaps;
306 GstPadTemplate *src_template, *sink_template;
310 /* Source pad has ANY caps
311 * Sink pad has foobar caps
312 * We will push the pony express caps (which should fail)
314 caps = gst_caps_new_any ();
315 src_template = gst_pad_template_new ("src", GST_PAD_SRC,
316 GST_PAD_ALWAYS, caps);
317 gst_caps_unref (caps);
318 caps = gst_caps_from_string ("foo/bar, dummy=(int){1, 2}");
319 sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
320 GST_PAD_ALWAYS, caps);
321 gst_caps_unref (caps);
323 src = gst_pad_new_from_template (src_template, "src");
324 fail_if (src == NULL);
325 sink = gst_pad_new_from_template (sink_template, "sink");
326 fail_if (sink == NULL);
327 gst_pad_set_event_function (sink, sticky_event);
328 gst_pad_set_chain_function (sink, gst_check_chain_func);
330 gst_object_unref (src_template);
331 gst_object_unref (sink_template);
333 failcaps = gst_caps_from_string ("pony/express, failure=(boolean)true");
334 ASSERT_CAPS_REFCOUNT (failcaps, "caps", 1);
336 event = gst_event_new_caps (failcaps);
337 gst_caps_unref (failcaps);
338 gst_pad_set_active (src, TRUE);
339 /* The pad isn't linked yet, and anything matches the source pad template
341 fail_unless (gst_pad_push_event (src, event) == TRUE);
342 fail_unless (event_caps == NULL);
344 /* Linking and activating will not forward the sticky event yet... */
345 fail_unless (GST_PAD_LINK_SUCCESSFUL (gst_pad_link (src, sink)));
346 gst_pad_set_active (sink, TRUE);
347 fail_unless (event_caps == NULL);
349 /* ...but the first buffer will and should FAIL since the caps
350 * are not compatible */
351 fail_unless (gst_pad_push (src,
352 gst_buffer_new ()) == GST_FLOW_NOT_NEGOTIATED);
353 /* We shouldn't have received the caps event since it's incompatible */
354 fail_unless (event_caps == NULL);
355 /* We shouldn't have received any buffers since caps are incompatible */
356 fail_unless_equals_int (g_list_length (buffers), 0);
358 gst_caps_replace (&event_caps, NULL);
360 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
361 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
362 gst_object_unref (src);
363 gst_object_unref (sink);
368 /* Like test_sticky_caps_unlinked, but link before caps: */
370 GST_START_TEST (test_sticky_caps_flushing)
373 GstPadTemplate *src_template, *sink_template;
377 caps = gst_caps_from_string ("foo/bar, dummy=(int){1, 2}");
378 src_template = gst_pad_template_new ("src", GST_PAD_SRC,
379 GST_PAD_ALWAYS, caps);
380 sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
381 GST_PAD_ALWAYS, caps);
382 gst_caps_unref (caps);
384 src = gst_pad_new_from_template (src_template, "src");
385 fail_if (src == NULL);
386 sink = gst_pad_new_from_template (sink_template, "sink");
387 fail_if (sink == NULL);
388 gst_pad_set_event_function (sink, sticky_event);
389 gst_pad_set_chain_function (sink, gst_check_chain_func);
391 gst_object_unref (src_template);
392 gst_object_unref (sink_template);
394 fail_unless (GST_PAD_LINK_SUCCESSFUL (gst_pad_link (src, sink)));
396 caps = gst_caps_from_string ("foo/bar, dummy=(int)1");
397 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
399 event = gst_event_new_caps (caps);
400 gst_pad_set_active (src, TRUE);
401 /* The caps event gets accepted by the source pad (and stored) */
402 fail_unless (gst_pad_push_event (src, event) == TRUE);
403 /* But wasn't forwarded since the sink pad is flushing (not activated) */
404 fail_unless (event_caps == NULL);
406 /* Activating will not forward the sticky event yet... */
407 gst_pad_set_active (sink, TRUE);
408 fail_unless (event_caps == NULL);
410 /* ...but the first buffer will: */
411 fail_unless (gst_pad_push (src, gst_buffer_new ()) == GST_FLOW_OK);
412 fail_unless (event_caps == caps);
413 fail_unless_equals_int (g_list_length (buffers), 1);
415 gst_caps_replace (&caps, NULL);
416 gst_caps_replace (&event_caps, NULL);
418 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
419 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
420 gst_object_unref (src);
421 gst_object_unref (sink);
427 name_is_valid (const gchar * name, GstPadPresence presence)
430 GstCaps *any = gst_caps_new_any ();
432 new = gst_pad_template_new (name, GST_PAD_SRC, presence, any);
433 gst_caps_unref (any);
435 gst_object_unref (GST_OBJECT (new));
441 GST_START_TEST (test_name_is_valid)
443 gboolean result = FALSE;
445 fail_unless (name_is_valid ("src", GST_PAD_ALWAYS));
446 ASSERT_WARNING (name_is_valid ("src%", GST_PAD_ALWAYS));
447 ASSERT_WARNING (result = name_is_valid ("src%d", GST_PAD_ALWAYS));
450 fail_unless (name_is_valid ("src", GST_PAD_REQUEST));
451 ASSERT_WARNING (name_is_valid ("src%s%s", GST_PAD_REQUEST));
452 ASSERT_WARNING (name_is_valid ("src%c", GST_PAD_REQUEST));
453 ASSERT_WARNING (name_is_valid ("src%", GST_PAD_REQUEST));
454 ASSERT_WARNING (name_is_valid ("src%dsrc", GST_PAD_REQUEST));
456 fail_unless (name_is_valid ("src", GST_PAD_SOMETIMES));
457 fail_unless (name_is_valid ("src%c", GST_PAD_SOMETIMES));
462 static GstPadProbeReturn
463 _probe_handler (GstPad * pad, GstPadProbeInfo * info, gpointer userdata)
465 gint ret = GPOINTER_TO_INT (userdata);
468 return GST_PAD_PROBE_OK;
470 return GST_PAD_PROBE_DROP;
473 GST_START_TEST (test_push_unlinked)
480 src = gst_pad_new ("src", GST_PAD_SRC);
481 fail_if (src == NULL);
482 caps = gst_pad_get_allowed_caps (src);
483 fail_unless (caps == NULL);
485 caps = gst_caps_from_string ("foo/bar");
487 /* pushing on an inactive pad will return wrong state */
488 GST_DEBUG ("push buffer inactive");
489 buffer = gst_buffer_new ();
490 gst_buffer_ref (buffer);
491 fail_unless (gst_pad_push (src, buffer) == GST_FLOW_FLUSHING);
492 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
493 gst_buffer_unref (buffer);
495 gst_pad_set_active (src, TRUE);
496 GST_DEBUG ("push caps event inactive");
497 gst_pad_set_caps (src, caps);
498 ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
500 /* pushing on an unlinked pad will drop the buffer */
501 GST_DEBUG ("push buffer unlinked");
502 buffer = gst_buffer_new ();
503 gst_buffer_ref (buffer);
504 fail_unless (gst_pad_push (src, buffer) == GST_FLOW_NOT_LINKED);
505 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
506 gst_buffer_unref (buffer);
508 /* adding a probe that returns _DROP will drop the buffer without trying
510 GST_DEBUG ("push buffer drop");
511 id = gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_BUFFER,
512 _probe_handler, GINT_TO_POINTER (0), NULL);
513 buffer = gst_buffer_new ();
514 gst_buffer_ref (buffer);
515 fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
516 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
517 gst_buffer_unref (buffer);
518 gst_pad_remove_probe (src, id);
520 /* adding a probe that returns _OK will still chain the buffer,
521 * and hence drop because pad is unlinked */
522 GST_DEBUG ("push buffer ok");
523 id = gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_BUFFER,
524 _probe_handler, GINT_TO_POINTER (1), NULL);
525 buffer = gst_buffer_new ();
526 gst_buffer_ref (buffer);
527 fail_unless (gst_pad_push (src, buffer) == GST_FLOW_NOT_LINKED);
528 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
529 gst_buffer_unref (buffer);
530 gst_pad_remove_probe (src, id);
534 ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
535 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
537 gst_object_unref (src);
539 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
540 gst_caps_unref (caps);
545 GST_START_TEST (test_push_linked)
548 GstPadLinkReturn plr;
554 sink = gst_pad_new ("sink", GST_PAD_SINK);
555 fail_if (sink == NULL);
556 gst_pad_set_chain_function (sink, gst_check_chain_func);
558 src = gst_pad_new ("src", GST_PAD_SRC);
559 fail_if (src == NULL);
561 caps = gst_caps_from_string ("foo/bar");
563 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
565 gst_pad_set_active (src, TRUE);
566 gst_pad_set_caps (src, caps);
567 gst_pad_set_active (sink, TRUE);
568 gst_pad_set_caps (sink, caps);
569 /* one for me and one for each set_caps */
570 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
572 plr = gst_pad_link (src, sink);
573 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
574 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
576 buffer = gst_buffer_new ();
579 /* pushing on a linked pad will drop the ref to the buffer */
580 gst_buffer_ref (buffer);
581 fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
582 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 2);
583 gst_buffer_unref (buffer);
584 fail_unless_equals_int (g_list_length (buffers), 1);
585 buffer = GST_BUFFER (buffers->data);
586 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
587 gst_buffer_unref (buffer);
588 g_list_free (buffers);
591 /* adding a probe that returns FALSE will drop the buffer without trying
593 id = gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_BUFFER,
594 _probe_handler, GINT_TO_POINTER (0), NULL);
595 buffer = gst_buffer_new ();
596 gst_buffer_ref (buffer);
597 fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
598 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
599 gst_buffer_unref (buffer);
600 gst_pad_remove_probe (src, id);
601 fail_unless_equals_int (g_list_length (buffers), 0);
603 /* adding a probe that returns TRUE will still chain the buffer */
604 id = gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_BUFFER,
605 _probe_handler, GINT_TO_POINTER (1), NULL);
606 buffer = gst_buffer_new ();
607 gst_buffer_ref (buffer);
608 fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
609 gst_pad_remove_probe (src, id);
611 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 2);
612 gst_buffer_unref (buffer);
613 fail_unless_equals_int (g_list_length (buffers), 1);
614 buffer = GST_BUFFER (buffers->data);
615 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
616 gst_buffer_unref (buffer);
617 g_list_free (buffers);
621 gst_pad_unlink (src, sink);
622 ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
623 gst_object_unref (src);
624 gst_object_unref (sink);
625 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
627 gst_caps_unref (caps);
632 GST_START_TEST (test_push_linked_flushing)
636 GstPadLinkReturn plr;
641 src = gst_pad_new ("src", GST_PAD_SRC);
642 fail_if (src == NULL);
643 sink = gst_pad_new ("sink", GST_PAD_SINK);
644 fail_if (sink == NULL);
645 gst_pad_set_chain_function (sink, gst_check_chain_func);
647 caps = gst_pad_get_allowed_caps (src);
648 fail_unless (caps == NULL);
649 caps = gst_pad_get_allowed_caps (sink);
650 fail_unless (caps == NULL);
652 caps = gst_caps_from_string ("foo/bar");
654 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
656 gst_pad_set_active (src, TRUE);
657 gst_pad_set_caps (src, caps);
658 /* need to activate to make it accept the caps */
659 gst_pad_set_active (sink, TRUE);
660 gst_pad_set_caps (sink, caps);
661 /* one for me and one for each set_caps */
662 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
664 plr = gst_pad_link (src, sink);
665 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
666 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
668 /* not activating the pads here, which keeps them flushing */
669 gst_pad_set_active (src, FALSE);
670 gst_pad_set_active (sink, FALSE);
672 /* pushing on a flushing pad will drop the buffer */
673 buffer = gst_buffer_new ();
674 gst_buffer_ref (buffer);
675 fail_unless (gst_pad_push (src, buffer) == GST_FLOW_FLUSHING);
676 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
677 fail_unless_equals_int (g_list_length (buffers), 0);
678 gst_buffer_unref (buffer);
680 gst_pad_set_active (src, TRUE);
681 gst_pad_set_active (sink, FALSE);
683 /* adding a probe that returns FALSE will drop the buffer without trying
685 id = gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_BUFFER, _probe_handler,
686 GINT_TO_POINTER (0), NULL);
687 buffer = gst_buffer_new ();
688 gst_buffer_ref (buffer);
689 fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
690 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
691 fail_unless_equals_int (g_list_length (buffers), 0);
692 gst_buffer_unref (buffer);
693 gst_pad_remove_probe (src, id);
695 /* adding a probe that returns TRUE will still chain the buffer,
696 * and hence drop because pad is flushing */
697 id = gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_BUFFER, _probe_handler,
698 GINT_TO_POINTER (1), NULL);
699 buffer = gst_buffer_new ();
700 gst_buffer_ref (buffer);
701 fail_unless (gst_pad_push (src, buffer) == GST_FLOW_FLUSHING);
702 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
703 fail_unless_equals_int (g_list_length (buffers), 0);
704 gst_buffer_unref (buffer);
705 gst_pad_remove_probe (src, id);
708 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
709 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
710 gst_pad_link (src, sink);
711 gst_object_unref (src);
712 gst_object_unref (sink);
713 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
714 gst_caps_unref (caps);
720 buffer_from_string (const gchar * str)
726 buf = gst_buffer_new_and_alloc (size);
728 gst_buffer_fill (buf, 0, str, size);
734 buffer_compare (GstBuffer * buf, const gchar * str, gsize size)
739 fail_unless (gst_buffer_map (buf, &info, GST_MAP_READ));
740 res = memcmp (info.data, str, size) == 0;
741 GST_DEBUG ("%s <-> %s: %d", (gchar *) info.data, str, res);
742 gst_buffer_unmap (buf, &info);
747 GST_START_TEST (test_push_buffer_list_compat)
750 GstPadLinkReturn plr;
756 sink = gst_pad_new ("sink", GST_PAD_SINK);
757 fail_if (sink == NULL);
758 gst_pad_set_chain_function (sink, gst_check_chain_func);
759 /* leave chainlistfunc unset */
761 src = gst_pad_new ("src", GST_PAD_SRC);
762 fail_if (src == NULL);
764 caps = gst_caps_from_string ("foo/bar");
766 gst_pad_set_active (src, TRUE);
767 gst_pad_set_caps (src, caps);
768 gst_pad_set_active (sink, TRUE);
769 gst_pad_set_caps (sink, caps);
771 plr = gst_pad_link (src, sink);
772 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
774 list = gst_buffer_list_new ();
777 /* adding to a buffer list will drop the ref to the buffer */
778 gst_buffer_list_add (list, buffer_from_string ("ListGroup"));
779 gst_buffer_list_add (list, buffer_from_string ("AnotherListGroup"));
781 fail_unless (gst_pad_push_list (src, list) == GST_FLOW_OK);
782 fail_unless_equals_int (g_list_length (buffers), 2);
783 buffer = GST_BUFFER (buffers->data);
784 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
785 fail_unless (buffer_compare (buffer, "ListGroup", 9));
786 gst_buffer_unref (buffer);
787 buffers = g_list_delete_link (buffers, buffers);
788 buffer = GST_BUFFER (buffers->data);
789 ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
790 fail_unless (buffer_compare (buffer, "AnotherListGroup", 16));
791 gst_buffer_unref (buffer);
792 buffers = g_list_delete_link (buffers, buffers);
793 fail_unless (buffers == NULL);
796 gst_pad_unlink (src, sink);
797 gst_object_unref (src);
798 gst_object_unref (sink);
799 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
800 gst_caps_unref (caps);
805 GST_START_TEST (test_flowreturn)
810 /* test some of the macros */
812 fail_if (strcmp (gst_flow_get_name (ret), "eos"));
813 quark = gst_flow_to_quark (ret);
814 fail_if (strcmp (g_quark_to_string (quark), "eos"));
817 ret = GST_FLOW_CUSTOM_SUCCESS;
818 fail_if (strcmp (gst_flow_get_name (ret), "custom-success"));
819 quark = gst_flow_to_quark (ret);
820 fail_if (strcmp (g_quark_to_string (quark), "custom-success"));
822 ret = GST_FLOW_CUSTOM_ERROR;
823 fail_if (strcmp (gst_flow_get_name (ret), "custom-error"));
824 quark = gst_flow_to_quark (ret);
825 fail_if (strcmp (g_quark_to_string (quark), "custom-error"));
827 /* custom returns clamping */
828 ret = GST_FLOW_CUSTOM_SUCCESS + 2;
829 fail_if (strcmp (gst_flow_get_name (ret), "custom-success"));
830 quark = gst_flow_to_quark (ret);
831 fail_if (strcmp (g_quark_to_string (quark), "custom-success"));
833 ret = GST_FLOW_CUSTOM_ERROR - 2;
834 fail_if (strcmp (gst_flow_get_name (ret), "custom-error"));
835 quark = gst_flow_to_quark (ret);
836 fail_if (strcmp (g_quark_to_string (quark), "custom-error"));
839 ret = GST_FLOW_CUSTOM_ERROR + 2;
840 fail_if (strcmp (gst_flow_get_name (ret), "unknown"));
841 quark = gst_flow_to_quark (ret);
842 fail_unless (quark == 0);
847 GST_START_TEST (test_push_negotiation)
850 GstPadLinkReturn plr;
852 gst_caps_from_string ("audio/x-raw,width={16,32},depth={16,32}");
854 gst_caps_from_string ("audio/x-raw,width=32,depth={16,32}");
855 GstPadTemplate *src_template;
856 GstPadTemplate *sink_template;
860 src_template = gst_pad_template_new ("src", GST_PAD_SRC,
861 GST_PAD_ALWAYS, srccaps);
862 sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
863 GST_PAD_ALWAYS, sinkcaps);
864 gst_caps_unref (srccaps);
865 gst_caps_unref (sinkcaps);
867 sink = gst_pad_new_from_template (sink_template, "sink");
868 fail_if (sink == NULL);
869 gst_pad_set_chain_function (sink, gst_check_chain_func);
871 src = gst_pad_new_from_template (src_template, "src");
872 fail_if (src == NULL);
874 plr = gst_pad_link (src, sink);
875 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
878 gst_pad_set_active (src, TRUE);
879 gst_pad_set_active (sink, TRUE);
881 caps = gst_caps_from_string ("audio/x-raw,width=16,depth=16");
883 /* Should fail if src pad caps are incompatible with sink pad caps */
884 gst_pad_set_caps (src, caps);
885 fail_unless (gst_pad_set_caps (sink, caps) == FALSE);
888 gst_pad_unlink (src, sink);
889 gst_object_unref (src);
890 gst_object_unref (sink);
891 gst_caps_unref (caps);
892 gst_object_unref (sink_template);
893 gst_object_unref (src_template);
898 /* see that an unref also unlinks the pads */
899 GST_START_TEST (test_src_unref_unlink)
903 GstPadLinkReturn plr;
905 sink = gst_pad_new ("sink", GST_PAD_SINK);
906 fail_if (sink == NULL);
908 src = gst_pad_new ("src", GST_PAD_SRC);
909 fail_if (src == NULL);
911 caps = gst_caps_from_string ("foo/bar");
913 gst_pad_set_active (src, TRUE);
914 gst_pad_set_caps (src, caps);
915 gst_pad_set_active (sink, TRUE);
916 gst_pad_set_caps (sink, caps);
918 plr = gst_pad_link (src, sink);
919 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
921 /* unref the srcpad */
922 gst_object_unref (src);
924 /* sink should be unlinked now */
925 fail_if (gst_pad_is_linked (sink));
928 gst_object_unref (sink);
929 gst_caps_unref (caps);
934 /* see that an unref also unlinks the pads */
935 GST_START_TEST (test_sink_unref_unlink)
939 GstPadLinkReturn plr;
941 sink = gst_pad_new ("sink", GST_PAD_SINK);
942 fail_if (sink == NULL);
944 src = gst_pad_new ("src", GST_PAD_SRC);
945 fail_if (src == NULL);
947 caps = gst_caps_from_string ("foo/bar");
949 gst_pad_set_active (src, TRUE);
950 gst_pad_set_caps (src, caps);
951 gst_pad_set_active (sink, TRUE);
952 gst_pad_set_caps (sink, caps);
954 plr = gst_pad_link (src, sink);
955 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
957 /* unref the sinkpad */
958 gst_object_unref (sink);
960 /* src should be unlinked now */
961 fail_if (gst_pad_is_linked (src));
964 gst_object_unref (src);
965 gst_caps_unref (caps);
972 static GstPadProbeReturn
973 block_async_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
975 gboolean *bool_user_data = (gboolean *) user_data;
977 fail_unless ((info->type & GST_PAD_PROBE_TYPE_BLOCK) != 0);
979 /* here we should have blocked == 0 unblocked == 0 */
980 fail_unless (bool_user_data[0] == FALSE);
981 fail_unless (bool_user_data[1] == FALSE);
983 bool_user_data[0] = TRUE;
985 gst_pad_remove_probe (pad, id);
986 bool_user_data[1] = TRUE;
988 return GST_PAD_PROBE_OK;
991 GST_START_TEST (test_block_async)
994 /* we set data[0] = TRUE when the pad is blocked, data[1] = TRUE when it's
996 gboolean data[2] = { FALSE, FALSE };
998 pad = gst_pad_new ("src", GST_PAD_SRC);
999 fail_unless (pad != NULL);
1001 gst_pad_set_active (pad, TRUE);
1002 id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BLOCK, block_async_cb, &data,
1005 fail_unless (data[0] == FALSE);
1006 fail_unless (data[1] == FALSE);
1007 gst_pad_push (pad, gst_buffer_new ());
1009 gst_object_unref (pad);
1014 static GstPadProbeReturn
1015 block_async_cb_return_ok (GstPad * pad, GstPadProbeInfo * info,
1018 return GST_PAD_PROBE_OK;
1022 push_buffer_async (GstPad * pad)
1024 return GINT_TO_POINTER (gst_pad_push (pad, gst_buffer_new ()));
1028 test_pad_blocking_with_type (GstPadProbeType type)
1034 pad = gst_pad_new ("src", GST_PAD_SRC);
1035 fail_unless (pad != NULL);
1037 gst_pad_set_active (pad, TRUE);
1038 id = gst_pad_add_probe (pad, type, block_async_cb_return_ok, NULL, NULL);
1041 thread = g_thread_try_new ("gst-check", (GThreadFunc) push_buffer_async,
1044 /* wait for the block */
1045 while (!gst_pad_is_blocking (pad)) {
1049 /* stop with flushing */
1050 gst_pad_push_event (pad, gst_event_new_flush_start ());
1052 /* get return value from push */
1053 ret = GPOINTER_TO_INT (g_thread_join (thread));
1055 gst_pad_push_event (pad, gst_event_new_flush_stop (FALSE));
1056 /* must be wrong state */
1057 fail_unless (ret == GST_FLOW_FLUSHING);
1059 gst_object_unref (pad);
1062 GST_START_TEST (test_pad_blocking_with_probe_type_block)
1064 test_pad_blocking_with_type (GST_PAD_PROBE_TYPE_BLOCK);
1069 GST_START_TEST (test_pad_blocking_with_probe_type_blocking)
1071 test_pad_blocking_with_type (GST_PAD_PROBE_TYPE_BLOCKING);
1076 static gboolean pad_probe_remove_notifiy_called = FALSE;
1078 static GstPadProbeReturn
1079 probe_remove_self_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
1081 gst_pad_remove_probe (pad, info->id);
1083 fail_unless (pad->num_probes == 0);
1084 fail_unless (pad->num_blocked == 0);
1086 return GST_PAD_PROBE_REMOVE;
1090 probe_remove_notify_cb (gpointer data)
1092 fail_unless (pad_probe_remove_notifiy_called == FALSE);
1093 pad_probe_remove_notifiy_called = TRUE;
1096 GST_START_TEST (test_pad_probe_remove)
1100 pad = gst_pad_new ("src", GST_PAD_SRC);
1101 fail_unless (pad != NULL);
1103 gst_pad_set_active (pad, TRUE);
1104 fail_unless (pad->num_probes == 0);
1105 fail_unless (pad->num_blocked == 0);
1106 gst_pad_add_probe (pad,
1107 GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
1108 probe_remove_self_cb, NULL, probe_remove_notify_cb);
1109 fail_unless (pad->num_probes == 1);
1110 fail_unless (pad->num_blocked == 1);
1112 pad_probe_remove_notifiy_called = FALSE;
1113 gst_pad_push_event (pad, gst_event_new_stream_start ("asda"));
1115 fail_unless (pad->num_probes == 0);
1116 fail_unless (pad->num_blocked == 0);
1118 gst_object_unref (pad);
1123 static gboolean got_notify;
1126 caps_notify (GstPad * pad, GParamSpec * spec, gpointer data)
1132 test_queue_src_caps_notify (gboolean link_queue)
1135 GstPad *src, *sink, *another_pad;
1138 queue = gst_element_factory_make ("queue", NULL);
1139 fail_unless (queue != NULL);
1141 src = gst_element_get_static_pad (queue, "src");
1142 fail_unless (src != NULL);
1144 sink = gst_element_get_static_pad (queue, "sink");
1145 fail_unless (sink != NULL);
1148 another_pad = gst_pad_new ("sink", GST_PAD_SINK);
1149 fail_unless (another_pad != NULL);
1150 gst_pad_set_active (another_pad, TRUE);
1152 gst_pad_link_full (src, another_pad, GST_PAD_LINK_CHECK_NOTHING);
1157 gst_element_set_state (queue, GST_STATE_PLAYING);
1161 g_signal_connect (src, "notify::caps", G_CALLBACK (caps_notify), NULL);
1163 caps = gst_caps_from_string ("caps");
1164 gst_pad_send_event (sink, gst_event_new_caps (caps));
1165 gst_caps_unref (caps);
1167 while (got_notify == FALSE)
1170 gst_element_set_state (queue, GST_STATE_NULL);
1172 gst_object_unref (src);
1173 gst_object_unref (sink);
1174 gst_object_unref (queue);
1176 gst_object_unref (another_pad);
1180 GST_START_TEST (test_queue_src_caps_notify_linked)
1182 test_queue_src_caps_notify (TRUE);
1186 GST_START_TEST (test_queue_src_caps_notify_not_linked)
1188 /* This test will fail because queue doesn't set the caps
1189 on src pad unless it is linked */
1190 test_queue_src_caps_notify (FALSE);
1197 block_async_second (GstPad * pad, gboolean blocked, gpointer user_data)
1199 gst_pad_set_blocked (pad, FALSE, unblock_async_cb, NULL, NULL);
1203 block_async_first (GstPad * pad, gboolean blocked, gpointer user_data)
1205 static int n_calls = 0;
1206 gboolean *bool_user_data = (gboolean *) user_data;
1209 /* we expect this callback to be called only once */
1210 g_warn_if_reached ();
1212 *bool_user_data = blocked;
1214 /* replace block_async_first with block_async_second so next time the pad is
1215 * blocked the latter should be called */
1216 gst_pad_set_blocked (pad, TRUE, block_async_second, NULL, NULL);
1218 /* unblock temporarily, in the next push block_async_second should be called
1220 gst_pad_push_event (pad, gst_event_new_flush_start ());
1223 GST_START_TEST (test_block_async_replace_callback)
1228 pad = gst_pad_new ("src", GST_PAD_SRC);
1229 fail_unless (pad != NULL);
1230 gst_pad_set_active (pad, TRUE);
1232 gst_pad_set_blocked (pad, TRUE, block_async_first, &blocked, NULL);
1235 gst_pad_push (pad, gst_buffer_new ());
1236 fail_unless (blocked == TRUE);
1237 /* block_async_first flushes to unblock */
1238 gst_pad_push_event (pad, gst_event_new_flush_stop ());
1240 /* push again, this time block_async_second should be called */
1241 gst_pad_push (pad, gst_buffer_new ());
1242 fail_unless (blocked == TRUE);
1244 gst_object_unref (pad);
1251 block_async_full_destroy (gpointer user_data)
1253 gint *state = (gint *) user_data;
1255 fail_unless (*state < 2);
1257 GST_DEBUG ("setting state to 2");
1261 static GstPadProbeReturn
1262 block_async_full_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
1264 *(gint *) user_data = (gint) TRUE;
1266 gst_pad_push_event (pad, gst_event_new_flush_start ());
1267 GST_DEBUG ("setting state to 1");
1269 return GST_PAD_PROBE_OK;
1272 GST_START_TEST (test_block_async_full_destroy)
1275 /* 0 = unblocked, 1 = blocked, 2 = destroyed */
1279 pad = gst_pad_new ("src", GST_PAD_SRC);
1280 fail_unless (pad != NULL);
1281 gst_pad_set_active (pad, TRUE);
1283 id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BLOCK, block_async_full_cb,
1284 &state, block_async_full_destroy);
1285 fail_unless (state == 0);
1287 gst_pad_push (pad, gst_buffer_new ());
1288 /* block_async_full_cb sets state to 1 and then flushes to unblock temporarily
1290 fail_unless (state == 1);
1291 gst_pad_push_event (pad, gst_event_new_flush_stop (TRUE));
1293 /* unblock callback is called */
1294 gst_pad_remove_probe (pad, id);
1295 fail_unless (state == 2);
1297 gst_object_unref (pad);
1302 GST_START_TEST (test_block_async_full_destroy_dispose)
1305 /* 0 = unblocked, 1 = blocked, 2 = destroyed */
1308 pad = gst_pad_new ("src", GST_PAD_SRC);
1309 fail_unless (pad != NULL);
1310 gst_pad_set_active (pad, TRUE);
1312 (void) gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BLOCK, block_async_full_cb,
1313 &state, block_async_full_destroy);
1315 gst_pad_push (pad, gst_buffer_new ());
1316 /* block_async_full_cb sets state to 1 and then flushes to unblock temporarily
1318 fail_unless_equals_int (state, 1);
1319 gst_pad_push_event (pad, gst_event_new_flush_stop (TRUE));
1321 /* gst_BLOCK calls the destroy_notify function if necessary */
1322 gst_object_unref (pad);
1324 fail_unless_equals_int (state, 2);
1332 unblock_async_no_flush_cb (GstPad * pad, gboolean blocked, gpointer user_data)
1334 gboolean *bool_user_data = (gboolean *) user_data;
1336 /* here we should have blocked == 1 unblocked == 0 */
1338 fail_unless (blocked == FALSE);
1340 fail_unless (bool_user_data[0] == TRUE);
1341 fail_unless (bool_user_data[1] == TRUE);
1342 fail_unless (bool_user_data[2] == FALSE);
1344 bool_user_data[2] = TRUE;
1351 unblock_async_not_called (GstPad * pad, gboolean blocked, gpointer user_data)
1353 g_warn_if_reached ();
1357 static GstPadProbeReturn
1358 block_async_second_no_flush (GstPad * pad, GstPadProbeInfo * info,
1361 gboolean *bool_user_data = (gboolean *) user_data;
1363 GST_DEBUG ("second probe called");
1365 fail_unless (info->type & GST_PAD_PROBE_TYPE_BLOCK);
1367 fail_unless (bool_user_data[0] == TRUE);
1368 fail_unless (bool_user_data[1] == FALSE);
1369 fail_unless (bool_user_data[2] == FALSE);
1371 bool_user_data[1] = TRUE;
1373 GST_DEBUG ("removing second probe with id %lu", id);
1374 gst_pad_remove_probe (pad, id);
1376 return GST_PAD_PROBE_OK;
1379 static GstPadProbeReturn
1380 block_async_first_no_flush (GstPad * pad, GstPadProbeInfo * info,
1383 static int n_calls = 0;
1384 gboolean *bool_user_data = (gboolean *) user_data;
1386 fail_unless (info->type & GST_PAD_PROBE_TYPE_BLOCK);
1388 GST_DEBUG ("first probe called");
1391 /* we expect this callback to be called only once */
1392 g_warn_if_reached ();
1394 *bool_user_data = TRUE;
1396 fail_unless (bool_user_data[0] == TRUE);
1397 fail_unless (bool_user_data[1] == FALSE);
1398 fail_unless (bool_user_data[2] == FALSE);
1400 GST_DEBUG ("removing first probe with id %lu", id);
1401 gst_pad_remove_probe (pad, id);
1403 GST_DEBUG ("adding second probe");
1404 /* replace block_async_first with block_async_second so next time the pad is
1405 * blocked the latter should be called */
1406 id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BLOCK,
1407 block_async_second_no_flush, user_data, NULL);
1408 GST_DEBUG ("added probe with id %lu", id);
1410 return GST_PAD_PROBE_OK;
1413 GST_START_TEST (test_block_async_replace_callback_no_flush)
1416 gboolean bool_user_data[3] = { FALSE, FALSE, FALSE };
1418 pad = gst_pad_new ("src", GST_PAD_SRC);
1419 fail_unless (pad != NULL);
1420 gst_pad_set_active (pad, TRUE);
1422 GST_DEBUG ("adding probe");
1423 id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BLOCK,
1424 block_async_first_no_flush, bool_user_data, NULL);
1425 GST_DEBUG ("added probe with id %lu", id);
1428 GST_DEBUG ("pushing buffer");
1429 gst_pad_push (pad, gst_buffer_new ());
1430 fail_unless (bool_user_data[0] == TRUE);
1431 fail_unless (bool_user_data[1] == TRUE);
1432 fail_unless (bool_user_data[2] == FALSE);
1434 gst_object_unref (pad);
1439 static gint sticky_count;
1442 test_sticky_events_handler (GstPad * pad, GstObject * parent, GstEvent * event)
1444 GST_DEBUG_OBJECT (pad, "received event %" GST_PTR_FORMAT, event);
1446 switch (sticky_count) {
1448 fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1455 fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_CAPS);
1457 gst_event_parse_caps (event, &caps);
1458 fail_unless (gst_caps_get_size (caps) == 1);
1459 s = gst_caps_get_structure (caps, 0);
1460 fail_unless (gst_structure_has_name (s, "foo/baz"));
1464 fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT);
1467 fail_unless (FALSE);
1471 gst_event_unref (event);
1477 GST_START_TEST (test_sticky_events)
1479 GstPad *srcpad, *sinkpad;
1483 /* make unlinked srcpad */
1484 srcpad = gst_pad_new ("src", GST_PAD_SRC);
1485 fail_unless (srcpad != NULL);
1486 gst_pad_set_active (srcpad, TRUE);
1488 /* push an event, it should be sticky on the srcpad */
1489 gst_pad_push_event (srcpad, gst_event_new_stream_start ("test"));
1491 /* make a caps event */
1492 caps = gst_caps_new_empty_simple ("foo/bar");
1493 gst_pad_push_event (srcpad, gst_event_new_caps (caps));
1494 gst_caps_unref (caps);
1496 /* make segment event */
1497 gst_segment_init (&seg, GST_FORMAT_TIME);
1498 gst_pad_push_event (srcpad, gst_event_new_segment (&seg));
1500 /* now make a sinkpad */
1501 sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
1502 fail_unless (sinkpad != NULL);
1504 gst_pad_set_event_function (sinkpad, test_sticky_events_handler);
1505 fail_unless (sticky_count == 0);
1506 gst_pad_set_active (sinkpad, TRUE);
1509 gst_pad_link (srcpad, sinkpad);
1510 /* should not trigger events */
1511 fail_unless (sticky_count == 0);
1513 /* caps replaces old caps event at position 2, the pushes all
1515 caps = gst_caps_new_empty_simple ("foo/baz");
1516 gst_pad_push_event (srcpad, gst_event_new_caps (caps));
1517 gst_caps_unref (caps);
1519 /* should have triggered 2 events */
1520 fail_unless (sticky_count == 3);
1522 gst_object_unref (srcpad);
1523 gst_object_unref (sinkpad);
1529 gst_pad_suite (void)
1531 Suite *s = suite_create ("GstPad");
1532 TCase *tc_chain = tcase_create ("general");
1534 /* turn off timeout */
1535 tcase_set_timeout (tc_chain, 60);
1537 suite_add_tcase (s, tc_chain);
1538 tcase_add_test (tc_chain, test_link);
1539 tcase_add_test (tc_chain, test_refcount);
1540 tcase_add_test (tc_chain, test_get_allowed_caps);
1541 tcase_add_test (tc_chain, test_sticky_caps_unlinked);
1542 tcase_add_test (tc_chain, test_sticky_caps_unlinked_incompatible);
1543 tcase_add_test (tc_chain, test_sticky_caps_flushing);
1544 tcase_add_test (tc_chain, test_link_unlink_threaded);
1545 tcase_add_test (tc_chain, test_name_is_valid);
1546 tcase_add_test (tc_chain, test_push_unlinked);
1547 tcase_add_test (tc_chain, test_push_linked);
1548 tcase_add_test (tc_chain, test_push_linked_flushing);
1549 tcase_add_test (tc_chain, test_push_buffer_list_compat);
1550 tcase_add_test (tc_chain, test_flowreturn);
1551 tcase_add_test (tc_chain, test_push_negotiation);
1552 tcase_add_test (tc_chain, test_src_unref_unlink);
1553 tcase_add_test (tc_chain, test_sink_unref_unlink);
1554 tcase_add_test (tc_chain, test_block_async);
1555 tcase_add_test (tc_chain, test_pad_blocking_with_probe_type_block);
1556 tcase_add_test (tc_chain, test_pad_blocking_with_probe_type_blocking);
1557 tcase_add_test (tc_chain, test_pad_probe_remove);
1558 tcase_add_test (tc_chain, test_queue_src_caps_notify_linked);
1559 tcase_add_test (tc_chain, test_queue_src_caps_notify_not_linked);
1561 tcase_add_test (tc_chain, test_block_async_replace_callback);
1563 tcase_add_test (tc_chain, test_block_async_full_destroy);
1564 tcase_add_test (tc_chain, test_block_async_full_destroy_dispose);
1565 tcase_add_test (tc_chain, test_block_async_replace_callback_no_flush);
1566 tcase_add_test (tc_chain, test_sticky_events);
1571 GST_CHECK_MAIN (gst_pad);