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>
28 #ifdef GST_DISABLE_DEPRECATED
29 void _gst_plugin_register_static (GstPluginDesc * desc);
32 /* keep in sync with GST_GNUC_CONSTRUCTOR in gstmacros.h (ideally we'd just
33 * do it there, but I don't want to touch that now, and also we really want
34 * to deprecate this macro in the long run, I think) */
35 #if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))
36 #define GST_GNUC_CONSTRUCTOR_DEFINED
38 #undef GST_GNUC_CONSTRUCTOR_DEFINED
41 #ifdef GST_GNUC_CONSTRUCTOR_DEFINED
42 /* ------------------------------------------------------------------------- */
43 /* To make sure the old and deprecated GST_PLUGIN_DEFINE_STATIC still works */
45 static guint plugin_init_counter; /* 0 */
48 plugin1_init (GstPlugin * plugin)
50 ++plugin_init_counter;
55 plugin2_init (GstPlugin * plugin)
57 ++plugin_init_counter;
62 plugin3_init (GstPlugin * plugin)
64 ++plugin_init_counter;
68 GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR, GST_VERSION_MINOR, "plugin-1",
69 "some static elements 1", plugin1_init, VERSION, GST_LICENSE, PACKAGE,
72 GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR, GST_VERSION_MINOR, "plugin-2",
73 "some static elements 2", plugin2_init, VERSION, GST_LICENSE, PACKAGE,
76 GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR, GST_VERSION_MINOR, "plugin-3",
77 "some static elements 3", plugin3_init, VERSION, GST_LICENSE, PACKAGE,
80 GST_START_TEST (test_old_register_static)
82 fail_unless (plugin_init_counter == 3);
87 #endif /* GST_GNUC_CONSTRUCTOR_DEFINED */
91 register_check_elements (GstPlugin * plugin)
96 static GstPluginDesc plugin_desc = {
101 register_check_elements,
111 GST_START_TEST (test_register_static)
115 _gst_plugin_register_static (&plugin_desc);
116 fail_unless (gst_plugin_register_static (GST_VERSION_MAJOR,
117 GST_VERSION_MINOR, "more-elements", "more-elements",
118 register_check_elements, VERSION, GST_LICENSE, PACKAGE,
119 GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN));
121 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
123 gst_object_unref (plugin);
128 GST_START_TEST (test_registry)
131 GstRegistry *registry;
133 registry = gst_registry_get_default ();
135 for (g = registry->plugins; g; g = g->next) {
136 GstPlugin *plugin = GST_PLUGIN (g->data);
138 ASSERT_OBJECT_REFCOUNT (plugin, "plugin in registry", 1);
139 GST_DEBUG ("refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (plugin),
142 for (g = registry->features; g; g = g->next) {
143 GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
145 fail_if (GST_OBJECT_REFCOUNT_VALUE (feature) != 1,
146 "Feature in registry should have refcount of 1");
147 GST_DEBUG ("refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (feature),
154 GST_START_TEST (test_load_coreelements)
156 GstPlugin *unloaded_plugin;
157 GstPlugin *loaded_plugin;
159 unloaded_plugin = gst_default_registry_find_plugin ("coreelements");
160 fail_if (unloaded_plugin == NULL, "Failed to find coreelements plugin");
161 fail_if (GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin) != 2,
162 "Refcount of unloaded plugin in registry initially should be 2");
163 GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin));
165 loaded_plugin = gst_plugin_load (unloaded_plugin);
166 fail_if (loaded_plugin == NULL, "Failed to load plugin");
168 if (loaded_plugin != unloaded_plugin) {
169 fail_if (GST_OBJECT_REFCOUNT_VALUE (loaded_plugin) != 2,
170 "Refcount of loaded plugin in registry should be 2");
171 GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (loaded_plugin));
172 fail_if (GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin) != 1,
173 "Refcount of replaced plugin should be 1");
174 GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin));
177 gst_object_unref (unloaded_plugin);
178 gst_object_unref (loaded_plugin);
183 GST_START_TEST (test_registry_get_plugin_list)
188 plugin = gst_default_registry_find_plugin ("coreelements");
189 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
190 "Refcount of plugin in registry should be 2");
192 list = gst_registry_get_plugin_list (gst_registry_get_default ());
194 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
195 "Refcount of plugin in registry+list should be 3");
197 gst_plugin_list_free (list);
199 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
200 "Refcount of plugin in after list free should be 2");
202 gst_object_unref (plugin);
207 GST_START_TEST (test_find_plugin)
211 plugin = gst_registry_find_plugin (gst_registry_get_default (),
213 fail_if (plugin == NULL, "Failed to find coreelements plugin");
214 ASSERT_OBJECT_REFCOUNT (plugin, "plugin", 2);
216 fail_unless_equals_string (plugin->desc.version, VERSION);
217 fail_unless_equals_string (plugin->desc.license, "LGPL");
218 fail_unless_equals_string (plugin->desc.source, "gstreamer");
219 fail_unless_equals_string (plugin->desc.package, GST_PACKAGE_NAME);
220 fail_unless_equals_string (plugin->desc.origin, GST_PACKAGE_ORIGIN);
222 gst_object_unref (plugin);
228 GST_START_TEST (test_find_feature)
230 GstPluginFeature *feature;
232 feature = gst_registry_find_feature (gst_registry_get_default (),
233 "identity", GST_TYPE_ELEMENT_FACTORY);
234 fail_if (feature == NULL, "Failed to find identity element factory");
235 fail_if (strcmp (feature->plugin_name, "coreelements"),
236 "Expected identity to be from coreelements plugin");
238 fail_if (GST_OBJECT_REFCOUNT_VALUE (feature) != 2,
239 "Refcount of feature should be 2");
240 GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (feature));
242 gst_object_unref (feature);
247 GST_START_TEST (test_find_element)
249 GstElementFactory *element_factory;
251 element_factory = gst_element_factory_find ("identity");
252 fail_if (element_factory == NULL, "Failed to find identity element factory");
254 fail_if (GST_OBJECT_REFCOUNT_VALUE (element_factory) != 2,
255 "Refcount of plugin in registry+feature should be 2");
257 gst_object_unref (element_factory);
264 peek (gpointer data, gint64 offset, guint size)
270 suggest (gpointer data, guint probability, const GstCaps * caps)
275 GST_START_TEST (test_typefind)
278 GstPluginFeature *feature;
279 GstTypeFind typefind = {
287 plugin = gst_default_registry_find_plugin ("typefindfunctions");
288 fail_if (plugin == NULL, "Failed to find typefind functions");
289 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
290 "Refcount of plugin in registry should be 2");
291 fail_if (gst_plugin_is_loaded (plugin), "Expected plugin to be unloaded");
293 feature = gst_registry_find_feature (gst_registry_get_default (),
294 "audio/x-au", GST_TYPE_TYPE_FIND_FACTORY);
295 fail_if (feature == NULL, "Failed to find audio/x-aw typefind factory");
296 fail_if (feature->plugin != plugin,
297 "Expected identity to be from coreelements plugin");
299 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
300 "Refcount of plugin in registry+feature should be 3");
302 gst_type_find_factory_call_function (GST_TYPE_FIND_FACTORY (feature),
305 gst_object_unref (feature->plugin);
307 fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 1,
308 "Refcount of plugin in after list free should be 1");
310 gst_object_unref (plugin);
316 GST_START_TEST (test_version_checks)
318 fail_if (gst_default_registry_check_feature_version ("identity",
319 GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == FALSE,
320 "Unexpected version check result");
322 fail_if (gst_default_registry_check_feature_version ("identity",
323 GST_VERSION_MAJOR + 1, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
324 "Unexpected version check result");
326 fail_if (gst_default_registry_check_feature_version ("identity",
327 GST_VERSION_MAJOR, GST_VERSION_MINOR + 1, GST_VERSION_MICRO) == TRUE,
328 "Unexpected version check result");
330 fail_if (gst_default_registry_check_feature_version ("identity",
331 GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) == TRUE,
332 "Unexpected version check result");
334 if (GST_VERSION_MAJOR > 0) {
335 fail_if (gst_default_registry_check_feature_version ("identity",
336 GST_VERSION_MAJOR - 1, GST_VERSION_MINOR,
337 GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
340 if (GST_VERSION_MINOR > 0) {
341 fail_if (gst_default_registry_check_feature_version ("identity",
342 GST_VERSION_MAJOR, GST_VERSION_MINOR - 1,
343 GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
346 if (GST_VERSION_MICRO > 0) {
347 fail_if (gst_default_registry_check_feature_version ("identity",
348 GST_VERSION_MAJOR, GST_VERSION_MINOR,
349 GST_VERSION_MICRO - 1) == FALSE, "Unexpected version check result");
352 fail_if (gst_default_registry_check_feature_version ("entityid",
353 GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
354 "Unexpected version check result");
360 gst_plugin_suite (void)
362 Suite *s = suite_create ("GstPlugin");
363 TCase *tc_chain = tcase_create ("general");
365 /* turn off timeout */
366 tcase_set_timeout (tc_chain, 60);
368 suite_add_tcase (s, tc_chain);
369 #ifdef GST_GNUC_CONSTRUCTOR_DEFINED
370 tcase_add_test (tc_chain, test_old_register_static);
372 tcase_add_test (tc_chain, test_register_static);
373 tcase_add_test (tc_chain, test_registry);
374 tcase_add_test (tc_chain, test_load_coreelements);
375 tcase_add_test (tc_chain, test_registry_get_plugin_list);
376 tcase_add_test (tc_chain, test_find_plugin);
377 tcase_add_test (tc_chain, test_find_feature);
378 tcase_add_test (tc_chain, test_find_element);
379 tcase_add_test (tc_chain, test_version_checks);
380 //tcase_add_test (tc_chain, test_typefind);
385 GST_CHECK_MAIN (gst_plugin);