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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "../gstcheck.h"
24 START_TEST (test_link)
32 src = gst_pad_new ("source", GST_PAD_SRC);
33 fail_if (src == NULL);
35 name = gst_pad_get_name (src);
36 fail_unless (strcmp (name, "source") == 0);
38 sink = gst_pad_new ("sink", GST_PAD_SINK);
39 fail_if (sink == NULL);
41 /* linking without templates or caps should fail */
42 ret = gst_pad_link (src, sink);
43 fail_unless (ret == GST_PAD_LINK_NOFORMAT);
45 ASSERT_CRITICAL (gst_pad_get_pad_template (NULL));
47 srct = gst_pad_get_pad_template (src);
48 fail_unless (srct == NULL);
52 /* threaded link/unlink */
57 thread_link_unlink (gpointer data)
61 while (THREAD_TEST_RUNNING ()) {
62 gst_pad_link (src, sink);
63 gst_pad_unlink (src, sink);
68 START_TEST (test_link_unlink_threaded)
73 src = gst_pad_new ("source", GST_PAD_SRC);
74 fail_if (src == NULL);
75 sink = gst_pad_new ("sink", GST_PAD_SINK);
76 fail_if (sink == NULL);
78 caps = gst_caps_new_any ();
79 gst_pad_set_caps (src, caps);
80 gst_pad_set_caps (sink, caps);
82 MAIN_START_THREADS (5, thread_link_unlink, NULL);
83 for (i = 0; i < 1000; ++i) {
84 gst_pad_is_linked (src);
85 gst_pad_is_linked (sink);
92 START_TEST (test_refcount)
98 sink = gst_pad_new ("sink", GST_PAD_SINK);
99 fail_if (sink == NULL);
101 src = gst_pad_new ("src", GST_PAD_SRC);
102 fail_if (src == NULL);
104 caps = gst_caps_new_any ();
106 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
108 gst_pad_set_caps (src, caps);
109 gst_caps_unref (caps);
110 gst_pad_set_caps (sink, caps);
111 gst_caps_unref (caps);
112 /* one for me and one for each set_caps */
113 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
115 plr = gst_pad_link (src, sink);
116 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
117 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
119 gst_pad_unlink (src, sink);
120 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
123 gst_object_unref (GST_OBJECT (src));
124 gst_object_unref (GST_OBJECT (sink));
125 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
127 gst_caps_unref (caps);
131 START_TEST (test_get_allowed_caps)
134 GstCaps *caps, *gotcaps;
136 GstPadLinkReturn plr;
139 ASSERT_CRITICAL (gst_pad_get_allowed_caps (NULL));
141 buffer = gst_buffer_new ();
142 ASSERT_CRITICAL (gst_pad_get_allowed_caps ((GstPad *) buffer));
143 gst_buffer_unref (buffer);
145 sink = gst_pad_new ("sink", GST_PAD_SINK);
146 ASSERT_CRITICAL (gst_pad_get_allowed_caps (sink));
148 src = gst_pad_new ("src", GST_PAD_SRC);
149 fail_if (src == NULL);
150 caps = gst_pad_get_allowed_caps (src);
151 fail_unless (caps == NULL);
153 caps = gst_caps_new_any ();
154 rc = GST_MINI_OBJECT_REFCOUNT_VALUE (caps);
156 gst_pad_set_caps (src, caps);
157 gst_caps_unref (caps);
158 gst_pad_set_caps (sink, caps);
159 gst_caps_unref (caps);
160 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
162 plr = gst_pad_link (src, sink);
163 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
165 gotcaps = gst_pad_get_allowed_caps (src);
166 fail_if (gotcaps == NULL);
167 fail_unless (gst_caps_is_equal (gotcaps, caps));
169 ASSERT_CAPS_REFCOUNT (gotcaps, "gotcaps", 1);
170 gst_caps_unref (gotcaps);
172 gst_pad_unlink (src, sink);
175 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
176 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
177 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
179 gst_object_unref (GST_OBJECT (src));
180 gst_object_unref (GST_OBJECT (sink));
182 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
183 gst_caps_unref (caps);
186 END_TEST Suite * gst_pad_suite (void)
188 Suite *s = suite_create ("GstPad");
189 TCase *tc_chain = tcase_create ("general");
191 /* turn off timeout */
192 tcase_set_timeout (tc_chain, 60);
194 suite_add_tcase (s, tc_chain);
195 tcase_add_test (tc_chain, test_link);
196 tcase_add_test (tc_chain, test_refcount);
197 tcase_add_test (tc_chain, test_get_allowed_caps);
198 tcase_add_test (tc_chain, test_link_unlink_threaded);
203 main (int argc, char **argv)
207 Suite *s = gst_pad_suite ();
208 SRunner *sr = srunner_create (s);
210 gst_check_init (&argc, &argv);
212 srunner_run_all (sr, CK_NORMAL);
213 nf = srunner_ntests_failed (sr);