diff --git a/subprojects/gstreamer/tests/check/tools/gstinspect.c b/subprojects/gstreamer/tests/check/tools/gstinspect.c index 72e23a4225..1ea6ee2bee 100644 --- a/subprojects/gstreamer/tests/check/tools/gstinspect.c +++ b/subprojects/gstreamer/tests/check/tools/gstinspect.c @@ -30,10 +30,27 @@ static int gst_inspect_main (int argc, char **argv); #include "../../tools/gst-inspect.c" #undef main +// A plugin whose version does not match the gstreamer major/minor +// see https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6191 +#define TEST_PLUGIN_VERSION "0.1.0" +#define TEST_ELEMENT_NAME "local_test_bin" +static gboolean +test_plugin_init (G_GNUC_UNUSED GstPlugin * plugin) +{ + gst_element_register (plugin, TEST_ELEMENT_NAME, GST_RANK_NONE, GST_TYPE_BIN); + return TRUE; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, + test_plugin, "Test Plugin", test_plugin_init, TEST_PLUGIN_VERSION, + "LGPL", "gsttestplugin", "testing"); + GST_START_TEST (test_exists) { #define ARGV_LEN (G_N_ELEMENTS (argv) - 1) + gst_plugin_test_plugin_register (); + { const gchar *argv[] = { "gst-inspect-1.0", "--exists", "foo", NULL }; @@ -44,6 +61,16 @@ GST_START_TEST (test_exists) fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 0); } + { + // --exists should work even if the plugin's version does not equal + // the gstreamer version (i.e., the --atleast-version check is not + // implicitly enforced when not present). + const gchar *argv[] = { "gst-inspect-1.0", "--exists", + TEST_ELEMENT_NAME, NULL + }; + + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 0); + } { const gchar *argv[] = { "gst-inspect-1.0", "--exists", "--atleast-version=" VERSION, "bin", NULL @@ -77,28 +104,41 @@ GST_START_TEST (test_exists) "--atleast-version=2.0", "bin", NULL }; - fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 1); + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 2); } { const gchar *argv[] = { "gst-inspect-1.0", "--exists", "--atleast-version=2.0.0", "bin", NULL }; - fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 1); + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 2); } { const gchar *argv[] = { "gst-inspect-1.0", "--exists", "--atleast-version=1.44", "bin", NULL }; - fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 1); + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 2); } { const gchar *argv[] = { "gst-inspect-1.0", "--exists", "--atleast-version=1.60.4", "bin", NULL }; - fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 1); + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 2); + } + { + // The 'atleast-version' supplied here will not match the test plugin's + // version, above, so the test case should return "2" because the test + // plugin's 0.1.0 will not meet the minimum version specified by the arg. + gchar *atleast = g_strdup_printf ("--atleast-version=%d.%d", + GST_VERSION_MAJOR, GST_VERSION_MINOR); + const gchar *argv[] = { "gst-inspect-1.0", "--exists", + atleast, TEST_ELEMENT_NAME, NULL + }; + + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 2); + g_free (atleast); } { /* check for plugin should fail like this */ diff --git a/subprojects/gstreamer/tools/gst-inspect.c b/subprojects/gstreamer/tools/gst-inspect.c index 7edd8634a5..18b260b129 100644 --- a/subprojects/gstreamer/tools/gst-inspect.c +++ b/subprojects/gstreamer/tools/gst-inspect.c @@ -2171,6 +2171,7 @@ real_main (int argc, char *argv[]) gboolean print_aii = FALSE; gboolean uri_handlers = FALSE; gboolean check_exists = FALSE; + gboolean check_version = FALSE; gboolean color_always = FALSE; gchar *min_version = NULL; guint minver_maj = GST_VERSION_MAJOR; @@ -2285,6 +2286,7 @@ real_main (int argc, char *argv[]) } g_free (min_version); check_exists = TRUE; + check_version = TRUE; } if (check_exists) { @@ -2296,9 +2298,13 @@ real_main (int argc, char *argv[]) GstPluginFeature *feature; feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]); - if (feature != NULL && gst_plugin_feature_check_version (feature, - minver_maj, minver_min, minver_micro)) { - exit_code = 0; + if (feature != NULL) { + if (check_version && !gst_plugin_feature_check_version (feature, + minver_maj, minver_min, minver_micro)) { + exit_code = 2; + } else { + exit_code = 0; + } } else { exit_code = 1; }