|
Packit |
f546b1 |
/* GStreamer
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* unit test for GstPlugin
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* Copyright 2004 Thomas Vander Stichele <thomas at apestaart dot org>
|
|
Packit |
f546b1 |
* Copyright 2005 David Schleef <ds@schleef.org>
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
f546b1 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
f546b1 |
* License as published by the Free Software Foundation; either
|
|
Packit |
f546b1 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
f546b1 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
f546b1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
f546b1 |
* Library General Public License for more details.
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
f546b1 |
* License along with this library; if not, write to the
|
|
Packit |
f546b1 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit |
f546b1 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
f546b1 |
*/
|
|
Packit |
f546b1 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
f546b1 |
#include "config.h"
|
|
Packit |
f546b1 |
#endif
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
#include <gst/check/gstcheck.h>
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
static gboolean
|
|
Packit |
f546b1 |
register_check_elements (GstPlugin * plugin)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
return TRUE;
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_START_TEST (test_register_static)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
GstPlugin *plugin;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_unless (gst_plugin_register_static (GST_VERSION_MAJOR,
|
|
Packit |
f546b1 |
GST_VERSION_MINOR, "more-elements", "more-elements",
|
|
Packit |
f546b1 |
register_check_elements, VERSION, GST_LICENSE, PACKAGE,
|
|
Packit |
f546b1 |
GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN));
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_object_unref (plugin);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_END_TEST;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_START_TEST (test_registry)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
GList *list, *g;
|
|
Packit |
f546b1 |
GstRegistry *registry;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
registry = gst_registry_get ();
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
list = gst_registry_get_plugin_list (registry);
|
|
Packit |
f546b1 |
for (g = list; g; g = g->next) {
|
|
Packit |
f546b1 |
GstPlugin *plugin = GST_PLUGIN (g->data);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/* one for the registry, one for the list */
|
|
Packit |
f546b1 |
GST_DEBUG ("Plugin refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (plugin),
|
|
Packit |
f546b1 |
gst_plugin_get_name (plugin));
|
|
Packit |
f546b1 |
ASSERT_OBJECT_REFCOUNT (plugin, "plugin in registry", 2);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_object_unref (plugin);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
g_list_free (list);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
list = gst_registry_feature_filter (registry, NULL, FALSE, NULL);
|
|
Packit |
f546b1 |
for (g = list; g; g = g->next) {
|
|
Packit |
f546b1 |
GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/* one for the registry, one for the list */
|
|
Packit |
f546b1 |
GST_DEBUG ("Feature refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (feature),
|
|
Packit |
f546b1 |
GST_OBJECT_NAME (feature));
|
|
Packit |
f546b1 |
gst_object_unref (feature);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
g_list_free (list);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_END_TEST;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_START_TEST (test_load_coreelements)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
GstPlugin *unloaded_plugin;
|
|
Packit |
f546b1 |
GstPlugin *loaded_plugin;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
unloaded_plugin = gst_registry_find_plugin (gst_registry_get (),
|
|
Packit |
f546b1 |
"coreelements");
|
|
Packit |
f546b1 |
fail_if (unloaded_plugin == NULL, "Failed to find coreelements plugin");
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin) != 2,
|
|
Packit |
f546b1 |
"Refcount of unloaded plugin in registry initially should be 2");
|
|
Packit |
f546b1 |
GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin));
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
loaded_plugin = gst_plugin_load (unloaded_plugin);
|
|
Packit |
f546b1 |
fail_if (loaded_plugin == NULL, "Failed to load plugin");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
if (loaded_plugin != unloaded_plugin) {
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (loaded_plugin) != 2,
|
|
Packit |
f546b1 |
"Refcount of loaded plugin in registry should be 2");
|
|
Packit |
f546b1 |
GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (loaded_plugin));
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin) != 1,
|
|
Packit |
f546b1 |
"Refcount of replaced plugin should be 1");
|
|
Packit |
f546b1 |
GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin));
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_object_unref (unloaded_plugin);
|
|
Packit |
f546b1 |
gst_object_unref (loaded_plugin);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_END_TEST;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_START_TEST (test_registry_get_plugin_list)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
GList *list;
|
|
Packit |
f546b1 |
GstPlugin *plugin;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
plugin = gst_registry_find_plugin (gst_registry_get (), "coreelements");
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
|
|
Packit |
f546b1 |
"Refcount of plugin in registry should be 2");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
list = gst_registry_get_plugin_list (gst_registry_get ());
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
|
|
Packit |
f546b1 |
"Refcount of plugin in registry+list should be 3");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_plugin_list_free (list);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
|
|
Packit |
f546b1 |
"Refcount of plugin in after list free should be 2");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_object_unref (plugin);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_END_TEST;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_START_TEST (test_find_plugin)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
GstPlugin *plugin;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
plugin = gst_registry_find_plugin (gst_registry_get (), "coreelements");
|
|
Packit |
f546b1 |
fail_if (plugin == NULL, "Failed to find coreelements plugin");
|
|
Packit |
f546b1 |
ASSERT_OBJECT_REFCOUNT (plugin, "plugin", 2);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_unless_equals_string (gst_plugin_get_version (plugin), VERSION);
|
|
Packit |
f546b1 |
fail_unless_equals_string (gst_plugin_get_license (plugin), "LGPL");
|
|
Packit |
f546b1 |
fail_unless_equals_string (gst_plugin_get_source (plugin), "gstreamer");
|
|
Packit |
f546b1 |
fail_unless_equals_string (gst_plugin_get_package (plugin), GST_PACKAGE_NAME);
|
|
Packit |
f546b1 |
fail_unless_equals_string (gst_plugin_get_origin (plugin),
|
|
Packit |
f546b1 |
GST_PACKAGE_ORIGIN);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_object_unref (plugin);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_END_TEST;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_START_TEST (test_find_feature)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
GstPluginFeature *feature;
|
|
Packit |
f546b1 |
GstPlugin *plugin;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
feature = gst_registry_find_feature (gst_registry_get (),
|
|
Packit |
f546b1 |
"identity", GST_TYPE_ELEMENT_FACTORY);
|
|
Packit |
f546b1 |
fail_if (feature == NULL, "Failed to find identity element factory");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
plugin = gst_plugin_feature_get_plugin (feature);
|
|
Packit |
f546b1 |
fail_unless (plugin != NULL);
|
|
Packit |
f546b1 |
fail_unless_equals_string (gst_plugin_get_name (plugin), "coreelements");
|
|
Packit |
f546b1 |
gst_object_unref (plugin);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (feature) != 2,
|
|
Packit |
f546b1 |
"Refcount of feature should be 2");
|
|
Packit |
f546b1 |
GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (feature));
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_object_unref (feature);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_END_TEST;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_START_TEST (test_find_element)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
GstElementFactory *element_factory;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
element_factory = gst_element_factory_find ("identity");
|
|
Packit |
f546b1 |
fail_if (element_factory == NULL, "Failed to find identity element factory");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (element_factory) != 2,
|
|
Packit |
f546b1 |
"Refcount of plugin in registry+feature should be 2");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_object_unref (element_factory);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_END_TEST;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
#if 0
|
|
Packit |
f546b1 |
guint8 *
|
|
Packit |
f546b1 |
peek (gpointer data, gint64 offset, guint size)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
return NULL;
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
void
|
|
Packit |
f546b1 |
suggest (gpointer data, guint probability, const GstCaps * caps)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_START_TEST (test_typefind)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
GstPlugin *plugin;
|
|
Packit |
f546b1 |
GstPluginFeature *feature;
|
|
Packit |
f546b1 |
GstTypeFind typefind = {
|
|
Packit |
f546b1 |
peek,
|
|
Packit |
f546b1 |
suggest,
|
|
Packit |
f546b1 |
NULL,
|
|
Packit |
f546b1 |
NULL,
|
|
Packit |
f546b1 |
GST_PADDING_INIT
|
|
Packit |
f546b1 |
};
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
plugin = gst_default_registry_find_plugin ("typefindfunctions");
|
|
Packit |
f546b1 |
fail_if (plugin == NULL, "Failed to find typefind functions");
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
|
|
Packit |
f546b1 |
"Refcount of plugin in registry should be 2");
|
|
Packit |
f546b1 |
fail_if (gst_plugin_is_loaded (plugin), "Expected plugin to be unloaded");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
feature = gst_registry_find_feature (gst_registry_get (),
|
|
Packit |
f546b1 |
"audio/x-au", GST_TYPE_TYPE_FIND_FACTORY);
|
|
Packit |
f546b1 |
fail_if (feature == NULL, "Failed to find audio/x-aw typefind factory");
|
|
Packit |
f546b1 |
fail_if (feature->plugin != plugin,
|
|
Packit |
f546b1 |
"Expected identity to be from coreelements plugin");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
|
|
Packit |
f546b1 |
"Refcount of plugin in registry+feature should be 3");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_type_find_factory_call_function (GST_TYPE_FIND_FACTORY (feature),
|
|
Packit |
f546b1 |
&typefind);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_object_unref (feature->plugin);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 1,
|
|
Packit |
f546b1 |
"Refcount of plugin in after list free should be 1");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_object_unref (plugin);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_END_TEST;
|
|
Packit |
f546b1 |
#endif
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
#define gst_default_registry_check_feature_version(name,a,b,c) \
|
|
Packit |
f546b1 |
gst_registry_check_feature_version(gst_registry_get(),(name),(a),(b),(c))
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_START_TEST (test_version_checks)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
fail_if (gst_default_registry_check_feature_version ("identity",
|
|
Packit |
f546b1 |
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == FALSE,
|
|
Packit |
f546b1 |
"Unexpected version check result");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_if (gst_default_registry_check_feature_version ("identity",
|
|
Packit |
f546b1 |
GST_VERSION_MAJOR + 1, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
|
|
Packit |
f546b1 |
"Unexpected version check result");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_if (gst_default_registry_check_feature_version ("identity",
|
|
Packit |
f546b1 |
GST_VERSION_MAJOR, GST_VERSION_MINOR + 1, GST_VERSION_MICRO) == TRUE,
|
|
Packit |
f546b1 |
"Unexpected version check result");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/* If the nano is set, then we expect that X.Y.Z-1.x >= X.Y.Z, so that a
|
|
Packit |
f546b1 |
* devel plugin is valid against an upcoming release */
|
|
Packit |
f546b1 |
if (GST_VERSION_NANO > 0) {
|
|
Packit |
f546b1 |
fail_unless (gst_default_registry_check_feature_version ("identity",
|
|
Packit |
f546b1 |
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) ==
|
|
Packit |
f546b1 |
TRUE, "Unexpected version check result");
|
|
Packit |
f546b1 |
} else {
|
|
Packit |
f546b1 |
fail_if (gst_default_registry_check_feature_version ("identity",
|
|
Packit |
f546b1 |
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) ==
|
|
Packit |
f546b1 |
TRUE, "Unexpected version check result");
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
if (GST_VERSION_MAJOR > 0) {
|
|
Packit |
f546b1 |
fail_if (gst_default_registry_check_feature_version ("identity",
|
|
Packit |
f546b1 |
GST_VERSION_MAJOR - 1, GST_VERSION_MINOR,
|
|
Packit |
f546b1 |
GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
if (GST_VERSION_MINOR > 0) {
|
|
Packit |
f546b1 |
fail_if (gst_default_registry_check_feature_version ("identity",
|
|
Packit |
f546b1 |
GST_VERSION_MAJOR, GST_VERSION_MINOR - 1,
|
|
Packit |
f546b1 |
GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
if (GST_VERSION_MICRO > 0) {
|
|
Packit |
f546b1 |
fail_if (gst_default_registry_check_feature_version ("identity",
|
|
Packit |
f546b1 |
GST_VERSION_MAJOR, GST_VERSION_MINOR,
|
|
Packit |
f546b1 |
GST_VERSION_MICRO - 1) == FALSE, "Unexpected version check result");
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
fail_if (gst_default_registry_check_feature_version ("entityid",
|
|
Packit |
f546b1 |
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
|
|
Packit |
f546b1 |
"Unexpected version check result");
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_END_TEST;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
static Suite *
|
|
Packit |
f546b1 |
gst_plugin_suite (void)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
Suite *s = suite_create ("GstPlugin");
|
|
Packit |
f546b1 |
TCase *tc_chain = tcase_create ("general");
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/* turn off timeout */
|
|
Packit |
f546b1 |
tcase_set_timeout (tc_chain, 60);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
suite_add_tcase (s, tc_chain);
|
|
Packit |
f546b1 |
#ifdef GST_GNUC_CONSTRUCTOR_DEFINED
|
|
Packit |
f546b1 |
tcase_add_test (tc_chain, test_old_register_static);
|
|
Packit |
f546b1 |
#endif
|
|
Packit |
f546b1 |
tcase_add_test (tc_chain, test_register_static);
|
|
Packit |
f546b1 |
tcase_add_test (tc_chain, test_registry);
|
|
Packit |
f546b1 |
tcase_add_test (tc_chain, test_load_coreelements);
|
|
Packit |
f546b1 |
tcase_add_test (tc_chain, test_registry_get_plugin_list);
|
|
Packit |
f546b1 |
tcase_add_test (tc_chain, test_find_plugin);
|
|
Packit |
f546b1 |
tcase_add_test (tc_chain, test_find_feature);
|
|
Packit |
f546b1 |
tcase_add_test (tc_chain, test_find_element);
|
|
Packit |
f546b1 |
tcase_add_test (tc_chain, test_version_checks);
|
|
Packit |
f546b1 |
//tcase_add_test (tc_chain, test_typefind);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
return s;
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_CHECK_MAIN (gst_plugin);
|