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)
86 e = gst_element_factory_make ("fakesrc", "source");
88 /* I don't want errors shown */
89 gst_debug_set_default_threshold (GST_LEVEL_NONE);
91 GST_ELEMENT_ERROR (e, RESOURCE, OPEN_READ, ("I could not read"), ("debug"));
98 /* link and run two elements without putting them in a pipeline */
99 GST_START_TEST (test_link)
101 GstElement *src, *sink;
103 src = gst_element_factory_make ("fakesrc", "source");
104 sink = gst_element_factory_make ("fakesink", "sink");
106 fail_unless (gst_element_link_pads (src, "src", sink, "sink"));
108 /* do sink to source state change */
109 gst_element_set_state (sink, GST_STATE_PAUSED);
110 gst_element_set_state (src, GST_STATE_PAUSED);
112 /* wait for preroll */
113 gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
116 gst_element_set_state (sink, GST_STATE_PLAYING);
117 gst_element_set_state (src, GST_STATE_PLAYING);
119 g_usleep (G_USEC_PER_SEC);
122 gst_element_set_state (sink, GST_STATE_PAUSED);
123 gst_element_set_state (src, GST_STATE_PAUSED);
125 /* wait for preroll */
126 gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
128 gst_element_set_state (sink, GST_STATE_NULL);
129 gst_element_set_state (src, GST_STATE_NULL);
131 gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
132 g_usleep (G_USEC_PER_SEC / 2);
134 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
135 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
136 gst_element_unlink_pads (src, "src", sink, "sink");
137 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
138 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
140 gst_object_unref (src);
141 gst_object_unref (sink);
146 /* linking two elements without pads should fail */
147 GST_START_TEST (test_link_no_pads)
149 GstElement *src, *sink;
151 src = gst_bin_new ("src");
152 sink = gst_bin_new ("sink");
154 fail_if (gst_element_link (src, sink));
156 gst_object_unref (src);
157 gst_object_unref (sink);
162 /* check if the elementfactory of a class is filled (see #131079) */
163 GST_START_TEST (test_class)
165 GstElementClass *klass;
166 GstElementFactory *factory, *tmp;
169 GST_DEBUG ("finding factory for queue");
170 factory = gst_element_factory_find ("queue");
171 fail_if (factory == NULL);
173 GST_DEBUG ("getting the type");
174 /* feature is not loaded, should return 0 as the type */
175 type = gst_element_factory_get_element_type (factory);
178 GST_DEBUG ("now loading the plugin");
180 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
182 fail_if (tmp == NULL);
184 gst_object_unref (factory);
187 /* feature is now loaded */
188 type = gst_element_factory_get_element_type (factory);
191 klass = g_type_class_ref (factory->type);
192 fail_if (klass == NULL);
194 GST_DEBUG ("checking the element factory class field");
195 /* and elementfactory is filled in */
196 fail_if (klass->elementfactory == NULL);
197 fail_if (klass->elementfactory != factory);
204 gst_element_suite (void)
206 Suite *s = suite_create ("GstElement");
207 TCase *tc_chain = tcase_create ("element tests");
209 suite_add_tcase (s, tc_chain);
210 tcase_add_test (tc_chain, test_add_remove_pad);
211 tcase_add_test (tc_chain, test_add_pad_unref_element);
212 tcase_add_test (tc_chain, test_error_no_bus);
213 tcase_add_test (tc_chain, test_link);
214 tcase_add_test (tc_chain, test_link_no_pads);
215 tcase_add_test (tc_chain, test_class);
220 GST_CHECK_MAIN (gst_element);