2 * Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
4 * gstelement.c: Unit test for GstElement
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_add_remove_pad)
29 /* getting an existing element class is cheating, but easier */
30 e = gst_element_factory_make ("fakesrc", "source");
32 /* create a new floating pad with refcount 1 */
33 p = gst_pad_new ("source", GST_PAD_SRC);
34 ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
35 /* ref it for ourselves */
37 ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
38 /* adding it sinks the pad -> not floating, same refcount */
39 gst_element_add_pad (e, p);
40 ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
42 /* removing it reduces the refcount */
43 gst_element_remove_pad (e, p);
44 ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
46 /* clean up our own reference */
53 GST_START_TEST (test_add_pad_unref_element)
58 /* getting an existing element class is cheating, but easier */
59 e = gst_element_factory_make ("fakesrc", "source");
61 /* create a new floating pad with refcount 1 */
62 p = gst_pad_new ("source", GST_PAD_SRC);
63 ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
64 /* ref it for ourselves */
66 ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
67 /* adding it sinks the pad -> not floating, same refcount */
68 gst_element_add_pad (e, p);
69 ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
71 /* unreffing the element should clean it up */
72 gst_object_unref (GST_OBJECT (e));
74 ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
76 /* clean up our own reference */
82 GST_START_TEST (test_error_no_bus)
87 e = gst_element_factory_make ("fakesrc", "source");
89 /* get the bus, should be NULL */
90 bus = gst_element_get_bus (e);
91 fail_if (bus != NULL);
93 /* I don't want errors shown */
94 gst_debug_set_default_threshold (GST_LEVEL_NONE);
96 GST_ELEMENT_ERROR (e, RESOURCE, OPEN_READ, ("I could not read"), ("debug"));
103 /* link and run two elements without putting them in a pipeline */
104 GST_START_TEST (test_link)
106 GstElement *src, *sink;
108 src = gst_element_factory_make ("fakesrc", "source");
109 sink = gst_element_factory_make ("fakesink", "sink");
111 fail_unless (gst_element_link_pads (src, "src", sink, "sink"));
113 /* do sink to source state change */
114 gst_element_set_state (sink, GST_STATE_PAUSED);
115 gst_element_set_state (src, GST_STATE_PAUSED);
117 /* wait for preroll */
118 gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
121 gst_element_set_state (sink, GST_STATE_PLAYING);
122 gst_element_set_state (src, GST_STATE_PLAYING);
124 g_usleep (G_USEC_PER_SEC);
127 gst_element_set_state (sink, GST_STATE_PAUSED);
128 gst_element_set_state (src, GST_STATE_PAUSED);
130 /* wait for preroll */
131 gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
133 gst_element_set_state (sink, GST_STATE_NULL);
134 gst_element_set_state (src, GST_STATE_NULL);
136 gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
137 g_usleep (G_USEC_PER_SEC / 2);
139 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
140 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
141 gst_element_unlink_pads (src, "src", sink, "sink");
142 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
143 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
145 gst_object_unref (src);
146 gst_object_unref (sink);
151 /* linking two elements without pads should fail */
152 GST_START_TEST (test_link_no_pads)
154 GstElement *src, *sink;
156 src = gst_bin_new ("src");
157 sink = gst_bin_new ("sink");
159 fail_if (gst_element_link (src, sink));
161 gst_object_unref (src);
162 gst_object_unref (sink);
167 /* check if the elementfactory of a class is filled (see #131079) */
168 GST_START_TEST (test_class)
170 GstElementClass *klass;
171 GstElementFactory *factory, *tmp;
174 GST_DEBUG ("finding factory for queue");
175 factory = gst_element_factory_find ("queue");
176 fail_if (factory == NULL);
178 GST_DEBUG ("getting the type");
179 /* feature is not loaded, should return 0 as the type */
180 type = gst_element_factory_get_element_type (factory);
183 GST_DEBUG ("now loading the plugin");
185 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
187 fail_if (tmp == NULL);
189 gst_object_unref (factory);
192 /* feature is now loaded */
193 type = gst_element_factory_get_element_type (factory);
196 klass = g_type_class_ref (factory->type);
197 fail_if (klass == NULL);
199 GST_DEBUG ("checking the element factory class field");
200 /* and elementfactory is filled in */
201 fail_if (klass->elementfactory == NULL);
202 fail_if (klass->elementfactory != factory);
209 gst_element_suite (void)
211 Suite *s = suite_create ("GstElement");
212 TCase *tc_chain = tcase_create ("element tests");
214 suite_add_tcase (s, tc_chain);
215 tcase_add_test (tc_chain, test_add_remove_pad);
216 tcase_add_test (tc_chain, test_add_pad_unref_element);
217 tcase_add_test (tc_chain, test_error_no_bus);
218 tcase_add_test (tc_chain, test_link);
219 tcase_add_test (tc_chain, test_link_no_pads);
220 tcase_add_test (tc_chain, test_class);
225 GST_CHECK_MAIN (gst_element);