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 <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 fail */
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_NOFORMAT);
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 */
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_caps (src, caps);
92 gst_pad_set_caps (sink, caps);
94 MAIN_START_THREADS (5, thread_link_unlink, NULL);
95 for (i = 0; i < 1000; ++i) {
96 gst_pad_is_linked (src);
97 gst_pad_is_linked (sink);
100 MAIN_STOP_THREADS ();
105 GST_START_TEST (test_refcount)
109 GstPadLinkReturn plr;
111 sink = gst_pad_new ("sink", GST_PAD_SINK);
112 fail_if (sink == NULL);
114 src = gst_pad_new ("src", GST_PAD_SRC);
115 fail_if (src == NULL);
117 caps = gst_caps_from_string ("foo/bar");
119 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
121 gst_pad_set_caps (src, caps);
122 gst_pad_set_caps (sink, caps);
123 /* one for me and one for each set_caps */
124 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
126 plr = gst_pad_link (src, sink);
127 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
128 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
130 gst_pad_unlink (src, sink);
131 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
134 gst_object_unref (src);
135 gst_object_unref (sink);
136 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
138 gst_caps_unref (caps);
143 GST_START_TEST (test_get_allowed_caps)
146 GstCaps *caps, *gotcaps;
148 GstPadLinkReturn plr;
150 ASSERT_CRITICAL (gst_pad_get_allowed_caps (NULL));
152 buffer = gst_buffer_new ();
153 ASSERT_CRITICAL (gst_pad_get_allowed_caps ((GstPad *) buffer));
154 gst_buffer_unref (buffer);
156 sink = gst_pad_new ("sink", GST_PAD_SINK);
157 ASSERT_CRITICAL (gst_pad_get_allowed_caps (sink));
159 src = gst_pad_new ("src", GST_PAD_SRC);
160 fail_if (src == NULL);
161 caps = gst_pad_get_allowed_caps (src);
162 fail_unless (caps == NULL);
164 caps = gst_caps_from_string ("foo/bar");
166 gst_pad_set_caps (src, caps);
167 gst_pad_set_caps (sink, caps);
168 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
170 plr = gst_pad_link (src, sink);
171 fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
173 gotcaps = gst_pad_get_allowed_caps (src);
174 fail_if (gotcaps == NULL);
175 fail_unless (gst_caps_is_equal (gotcaps, caps));
177 ASSERT_CAPS_REFCOUNT (gotcaps, "gotcaps", 1);
178 gst_caps_unref (gotcaps);
180 gst_pad_unlink (src, sink);
183 ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
184 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
185 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
187 gst_object_unref (src);
188 gst_object_unref (sink);
190 ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
191 gst_caps_unref (caps);
199 Suite *s = suite_create ("GstPad");
200 TCase *tc_chain = tcase_create ("general");
202 /* turn off timeout */
203 tcase_set_timeout (tc_chain, 60);
205 suite_add_tcase (s, tc_chain);
206 tcase_add_test (tc_chain, test_link);
207 tcase_add_test (tc_chain, test_refcount);
208 tcase_add_test (tc_chain, test_get_allowed_caps);
209 tcase_add_test (tc_chain, test_link_unlink_threaded);
214 main (int argc, char **argv)
218 Suite *s = gst_pad_suite ();
219 SRunner *sr = srunner_create (s);
221 gst_check_init (&argc, &argv);
223 srunner_run_all (sr, CK_NORMAL);
224 nf = srunner_ntests_failed (sr);