From f0f0662d9d982fc48409734233e39cb68c324d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Fri, 9 Oct 2020 11:54:19 +0200 Subject: [PATCH] gst-full: add way to test features presence This test allows to test a list of features to be registered in the library (or not). Part-of: --- tests/static-plugins/meson.build | 6 +- tests/static-plugins/test-gst-full-features.c | 108 ++++++++++++++++++ 2 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 tests/static-plugins/test-gst-full-features.c diff --git a/tests/static-plugins/meson.build b/tests/static-plugins/meson.build index 37b133672f..227e9e4af9 100644 --- a/tests/static-plugins/meson.build +++ b/tests/static-plugins/meson.build @@ -1,6 +1,8 @@ dep = dependency('gstreamer-full-1.0', required: get_option('default_library') == 'static') if dep.found() - test_elements = executable('test-gst-full', 'test-gst-full.c', dependencies : gst_full_dep) - test('test-gst-full', test_elements) + test_gst_full_features = executable('test-gst-full-features', 'test-gst-full-features.c', dependencies : gst_full_dep) + test('test-gst-full-features', test_gst_full_features) + test_gst_full = executable('test-gst-full', 'test-gst-full.c', dependencies : gst_full_dep) + test('test-gst-full', test_gst_full) endif diff --git a/tests/static-plugins/test-gst-full-features.c b/tests/static-plugins/test-gst-full-features.c new file mode 100644 index 0000000000..5e8afbe14f --- /dev/null +++ b/tests/static-plugins/test-gst-full-features.c @@ -0,0 +1,108 @@ +#include + + +void +assert_feature_names (gchar * names, GType feature_type, gboolean spook) +{ + GstPluginFeature *feature = NULL; + gchar **split = NULL; + int i; + + if (names) + split = g_strsplit (names, ",", 0); + if (split) { + for (i = 0; split[i]; i++) { + feature = gst_registry_find_feature (gst_registry_get (), + split[i], feature_type); + if (spook) + g_assert_null (feature); + else + g_assert_nonnull (feature); + if (feature) + gst_object_unref (feature); + } + g_strfreev (split); + } +} + +int +main (int argc, char *argv[]) +{ + GOptionContext *ctx; + GError *err = NULL; + gchar *elements, *typefinds, *deviceproviders, *dynamictypes; + gchar *spook_elements, *spook_typefinds, *spook_deviceproviders, + *spook_dynamictypes; + + elements = typefinds = deviceproviders = dynamictypes = NULL; + spook_elements = spook_typefinds = spook_deviceproviders = + spook_dynamictypes = NULL; + + GOptionEntry options[] = { + {"elements", 'e', 0, G_OPTION_ARG_STRING, &elements, + "Element(s) which should be available. Specify multiple ones using ',' as separator", + NULL}, + {"spook-elements", 'E', 0, G_OPTION_ARG_STRING, &spook_elements, + "Element(s) which should NOT be available. Specify multiple ones using ',' as separator", + NULL}, + {"typefinds", 't', 0, G_OPTION_ARG_STRING, &typefinds, + "Typefind(s) which should be available. Specify multiple ones using ',' as separator", + NULL}, + {"spook-typefinds", 'T', 0, G_OPTION_ARG_STRING, &spook_typefinds, + "Typefind(s) which should NOT be available. Specify multiple ones using ',' as separator", + NULL}, + {"deviceproviders", 'd', 0, G_OPTION_ARG_STRING, &deviceproviders, + "Deviceprovider(s) which should be available. Specify multiple ones using ',' as separator", + NULL}, + {"spook-deviceproviders", 'D', 0, G_OPTION_ARG_STRING, + &spook_deviceproviders, + "Deviceprovider(s) which should NOT be available. Specify multiple ones using ',' as separator", + NULL}, + {"dynamictypes", 'l', 0, G_OPTION_ARG_STRING, &dynamictypes, + "Dynamictype(s) which should be available. Specify multiple ones using ',' as separator", + NULL}, + {"spook-dynamictypes", 'L', 0, G_OPTION_ARG_STRING, &spook_dynamictypes, + "Dynamictype(s) which should NOT be available. Specify multiple ones using ',' as separator", + NULL}, + {NULL} + }; + ctx = g_option_context_new ("elements ..."); + g_option_context_add_main_entries (ctx, options, NULL); + g_option_context_add_group (ctx, gst_init_get_option_group ()); + if (!g_option_context_parse (ctx, &argc, &argv, &err)) { + g_print ("Error initializing: %s\n", GST_STR_NULL (err->message)); + g_clear_error (&err); + g_option_context_free (ctx); + return 1; + } + g_option_context_free (ctx); + + gst_init (&argc, &argv); + + /* Test that elements are instanciable. */ + assert_feature_names (elements, GST_TYPE_ELEMENT_FACTORY, FALSE); + /* Test that elements are NOT instanciable. */ + assert_feature_names (spook_elements, GST_TYPE_ELEMENT_FACTORY, TRUE); + + /* Test that typefinds are instanciable. */ + assert_feature_names (typefinds, GST_TYPE_TYPE_FIND_FACTORY, FALSE); + /* Test that typefinds are NOT instanciable. */ + assert_feature_names (spook_typefinds, GST_TYPE_TYPE_FIND_FACTORY, TRUE); + + /* Test that device providers are instanciable. */ + assert_feature_names (deviceproviders, GST_TYPE_DEVICE_PROVIDER_FACTORY, + FALSE); + /* Test that device providers are NOT instanciable. */ + assert_feature_names (spook_deviceproviders, GST_TYPE_DEVICE_PROVIDER_FACTORY, + TRUE); + + /* Test that dynamic types are instanciable. */ + assert_feature_names (dynamictypes, GST_TYPE_DYNAMIC_TYPE_FACTORY, FALSE); + /* Test that dynamic types are NOT instanciable. */ + assert_feature_names (spook_dynamictypes, GST_TYPE_DYNAMIC_TYPE_FACTORY, + TRUE); + + gst_deinit (); + + return 0; +}