3 * unit test for GstPlugin
5 * Copyright 2004 Thomas Vander Stichele <thomas at apestaart dot org>
6 * Copyright 2005 David Schleef <ds@schleef.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 #include <gst/check/gstcheck.h>
30 register_check_elements (GstPlugin * plugin)
35 GST_START_TEST (test_register_static)
39 fail_unless (gst_plugin_register_static (GST_VERSION_MAJOR,
40 GST_VERSION_MINOR, "more-elements", "more-elements",
41 register_check_elements, VERSION, GST_LICENSE, PACKAGE,
42 GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN));
44 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
46 gst_object_unref (plugin);
51 GST_START_TEST (test_registry)
54 GstRegistry *registry;
56 registry = gst_registry_get ();
58 list = gst_registry_get_plugin_list (registry);
59 for (g = list; g; g = g->next) {
60 GstPlugin *plugin = GST_PLUGIN (g->data);
62 /* one for the registry, one for the list */
63 GST_DEBUG ("refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (plugin),
65 ASSERT_OBJECT_REFCOUNT (plugin, "plugin in registry", 2);
67 gst_object_unref (plugin);
71 list = gst_registry_feature_filter (registry, NULL, FALSE, NULL);
72 for (g = list; g; g = g->next) {
73 GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
75 /* one for the registry, one for the list */
76 GST_DEBUG ("refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (feature),
77 GST_OBJECT_NAME (feature));
78 ASSERT_OBJECT_REFCOUNT (feature, "feature in registry", 2);
79 gst_object_unref (feature);
86 GST_START_TEST (test_load_coreelements)
88 GstPlugin *unloaded_plugin;
89 GstPlugin *loaded_plugin;
91 unloaded_plugin = gst_registry_find_plugin (gst_registry_get (),
93 fail_if (unloaded_plugin == NULL, "Failed to find coreelements plugin");
94 fail_if (GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin) != 2,
95 "Refcount of unloaded plugin in registry initially should be 2");
96 GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin));
98 loaded_plugin = gst_plugin_load (unloaded_plugin);
99 fail_if (loaded_plugin == NULL, "Failed to load plugin");
101 if (loaded_plugin != unloaded_plugin) {
102 fail_if (GST_OBJECT_REFCOUNT_VALUE (loaded_plugin) != 2,
103 "Refcount of loaded plugin in registry should be 2");
104 GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (loaded_plugin));
105 fail_if (GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin) != 1,
106 "Refcount of replaced plugin should be 1");
107 GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin));
110 gst_object_unref (unloaded_plugin);
111 gst_object_unref (loaded_plugin);
116 GST_START_TEST (test_registry_get_plugin_list)
121 plugin = gst_registry_find_plugin (gst_registry_get (), "coreelements");
122 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
123 "Refcount of plugin in registry should be 2");
125 list = gst_registry_get_plugin_list (gst_registry_get ());
127 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
128 "Refcount of plugin in registry+list should be 3");
130 gst_plugin_list_free (list);
132 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
133 "Refcount of plugin in after list free should be 2");
135 gst_object_unref (plugin);
140 GST_START_TEST (test_find_plugin)
144 plugin = gst_registry_find_plugin (gst_registry_get (), "coreelements");
145 fail_if (plugin == NULL, "Failed to find coreelements plugin");
146 ASSERT_OBJECT_REFCOUNT (plugin, "plugin", 2);
148 fail_unless_equals_string (plugin->desc.version, VERSION);
149 fail_unless_equals_string (plugin->desc.license, "LGPL");
150 fail_unless_equals_string (plugin->desc.source, "gstreamer");
151 fail_unless_equals_string (plugin->desc.package, GST_PACKAGE_NAME);
152 fail_unless_equals_string (plugin->desc.origin, GST_PACKAGE_ORIGIN);
154 gst_object_unref (plugin);
160 GST_START_TEST (test_find_feature)
162 GstPluginFeature *feature;
164 feature = gst_registry_find_feature (gst_registry_get (),
165 "identity", GST_TYPE_ELEMENT_FACTORY);
166 fail_if (feature == NULL, "Failed to find identity element factory");
167 fail_if (strcmp (feature->plugin_name, "coreelements"),
168 "Expected identity to be from coreelements plugin");
170 fail_if (GST_OBJECT_REFCOUNT_VALUE (feature) != 2,
171 "Refcount of feature should be 2");
172 GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (feature));
174 gst_object_unref (feature);
179 GST_START_TEST (test_find_element)
181 GstElementFactory *element_factory;
183 element_factory = gst_element_factory_find ("identity");
184 fail_if (element_factory == NULL, "Failed to find identity element factory");
186 fail_if (GST_OBJECT_REFCOUNT_VALUE (element_factory) != 2,
187 "Refcount of plugin in registry+feature should be 2");
189 gst_object_unref (element_factory);
196 peek (gpointer data, gint64 offset, guint size)
202 suggest (gpointer data, guint probability, const GstCaps * caps)
207 GST_START_TEST (test_typefind)
210 GstPluginFeature *feature;
211 GstTypeFind typefind = {
219 plugin = gst_default_registry_find_plugin ("typefindfunctions");
220 fail_if (plugin == NULL, "Failed to find typefind functions");
221 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
222 "Refcount of plugin in registry should be 2");
223 fail_if (gst_plugin_is_loaded (plugin), "Expected plugin to be unloaded");
225 feature = gst_registry_find_feature (gst_registry_get (),
226 "audio/x-au", GST_TYPE_TYPE_FIND_FACTORY);
227 fail_if (feature == NULL, "Failed to find audio/x-aw typefind factory");
228 fail_if (feature->plugin != plugin,
229 "Expected identity to be from coreelements plugin");
231 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
232 "Refcount of plugin in registry+feature should be 3");
234 gst_type_find_factory_call_function (GST_TYPE_FIND_FACTORY (feature),
237 gst_object_unref (feature->plugin);
239 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 1,
240 "Refcount of plugin in after list free should be 1");
242 gst_object_unref (plugin);
248 #define gst_default_registry_check_feature_version(name,a,b,c) \
249 gst_registry_check_feature_version(gst_registry_get(),(name),(a),(b),(c))
251 GST_START_TEST (test_version_checks)
253 fail_if (gst_default_registry_check_feature_version ("identity",
254 GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == FALSE,
255 "Unexpected version check result");
257 fail_if (gst_default_registry_check_feature_version ("identity",
258 GST_VERSION_MAJOR + 1, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
259 "Unexpected version check result");
261 fail_if (gst_default_registry_check_feature_version ("identity",
262 GST_VERSION_MAJOR, GST_VERSION_MINOR + 1, GST_VERSION_MICRO) == TRUE,
263 "Unexpected version check result");
265 /* If the nano is set, then we expect that X.Y.Z-1.x >= X.Y.Z, so that a
266 * devel plugin is valid against an upcoming release */
267 if (GST_VERSION_NANO > 0) {
268 fail_unless (gst_default_registry_check_feature_version ("identity",
269 GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) ==
270 TRUE, "Unexpected version check result");
272 fail_if (gst_default_registry_check_feature_version ("identity",
273 GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) ==
274 TRUE, "Unexpected version check result");
277 if (GST_VERSION_MAJOR > 0) {
278 fail_if (gst_default_registry_check_feature_version ("identity",
279 GST_VERSION_MAJOR - 1, GST_VERSION_MINOR,
280 GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
283 if (GST_VERSION_MINOR > 0) {
284 fail_if (gst_default_registry_check_feature_version ("identity",
285 GST_VERSION_MAJOR, GST_VERSION_MINOR - 1,
286 GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
289 if (GST_VERSION_MICRO > 0) {
290 fail_if (gst_default_registry_check_feature_version ("identity",
291 GST_VERSION_MAJOR, GST_VERSION_MINOR,
292 GST_VERSION_MICRO - 1) == FALSE, "Unexpected version check result");
295 fail_if (gst_default_registry_check_feature_version ("entityid",
296 GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
297 "Unexpected version check result");
303 gst_plugin_suite (void)
305 Suite *s = suite_create ("GstPlugin");
306 TCase *tc_chain = tcase_create ("general");
308 /* turn off timeout */
309 tcase_set_timeout (tc_chain, 60);
311 suite_add_tcase (s, tc_chain);
312 #ifdef GST_GNUC_CONSTRUCTOR_DEFINED
313 tcase_add_test (tc_chain, test_old_register_static);
315 tcase_add_test (tc_chain, test_register_static);
316 tcase_add_test (tc_chain, test_registry);
317 tcase_add_test (tc_chain, test_load_coreelements);
318 tcase_add_test (tc_chain, test_registry_get_plugin_list);
319 tcase_add_test (tc_chain, test_find_plugin);
320 tcase_add_test (tc_chain, test_find_feature);
321 tcase_add_test (tc_chain, test_find_element);
322 tcase_add_test (tc_chain, test_version_checks);
323 //tcase_add_test (tc_chain, test_typefind);
328 GST_CHECK_MAIN (gst_plugin);