diff options
author | Tim-Philipp Müller <tim@centricular.net> | 2008-02-29 18:38:54 +0000 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.net> | 2008-02-29 18:38:54 +0000 |
commit | 97bf2d2d78ef64619418527cf03e6960bab69467 (patch) | |
tree | 54974c4cf47245ecc267773ec3194e4904dd8bc7 | |
parent | f3850aca810d61c28ec7c7e197123b6f4ace6a8d (diff) | |
download | gstreamer-97bf2d2d78ef64619418527cf03e6960bab69467.tar.gz |
gst/gstinterface.c: Don't crash if the element supports the interface queried, but does not implement GstImplementsIn...
Original commit message from CVS:
* gst/gstinterface.c: (gst_element_implements_interface):
Don't crash if the element supports the interface queried, but does
not implement GstImplementsInterface. Fixes #519584.
* tests/check/Makefile.am:
* tests/check/gst/.cvsignore:
* tests/check/gst/gstinterface.c:
Add unit test for the above.
-rw-r--r-- | ChangeLog | 11 | ||||
m--------- | common | 0 | ||||
-rw-r--r-- | gst/gstinterface.c | 7 | ||||
-rw-r--r-- | tests/check/Makefile.am | 1 | ||||
-rw-r--r-- | tests/check/gst/.gitignore | 1 | ||||
-rw-r--r-- | tests/check/gst/gstinterface.c | 62 |
6 files changed, 82 insertions, 0 deletions
@@ -1,3 +1,14 @@ +2008-02-29 Tim-Philipp Müller <tim at centricular dot net> + + * gst/gstinterface.c: (gst_element_implements_interface): + Don't crash if the element supports the interface queried, but does + not implement GstImplementsInterface. Fixes #519584. + + * tests/check/Makefile.am: + * tests/check/gst/.cvsignore: + * tests/check/gst/gstinterface.c: + Add unit test for the above. + 2008-02-29 Wim Taymans <wim.taymans@collabora.co.uk> * libs/gst/base/gstbasesink.c: (gst_base_sink_class_init): diff --git a/common b/common -Subproject e746d20ef536a73aea9964666c7d5f6d5c9465d +Subproject 4fa1159996900100f3a1cd3b43d7f0f027310cd diff --git a/gst/gstinterface.c b/gst/gstinterface.c index 3f8c347ad9..1aedd2b52e 100644 --- a/gst/gstinterface.c +++ b/gst/gstinterface.c @@ -102,6 +102,8 @@ gst_implements_interface_supported_default (GstImplementsInterface * interface, gboolean gst_element_implements_interface (GstElement * element, GType iface_type) { + g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE); + if (G_TYPE_CHECK_INSTANCE_TYPE (G_OBJECT (element), iface_type)) { GstImplementsInterface *iface; GstImplementsInterfaceClass *ifclass; @@ -110,6 +112,11 @@ gst_element_implements_interface (GstElement * element, GType iface_type) iface_type, GstImplementsInterface); ifclass = GST_IMPLEMENTS_INTERFACE_GET_CLASS (iface); + /* element implements iface_type but not GstImplementsInterface, so + * just assume the other interface is implemented unconditionally */ + if (ifclass == NULL) + return TRUE; + if (ifclass->supported != NULL && ifclass->supported (iface, iface_type) == TRUE) { return TRUE; diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 57b59a933e..bcc652322d 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -49,6 +49,7 @@ REGISTRY_CHECKS = \ gst/gstelement \ gst/gstevent \ gst/gstghostpad \ + gst/gstinterface \ gst/gstplugin \ gst/gstquery \ gst/gstregistry \ diff --git a/tests/check/gst/.gitignore b/tests/check/gst/.gitignore index 69f34121d8..2a93de752f 100644 --- a/tests/check/gst/.gitignore +++ b/tests/check/gst/.gitignore @@ -10,6 +10,7 @@ gstelement gstevent gstghostpad gstiterator +gstinterface gstmessage gstminiobject gstobject diff --git a/tests/check/gst/gstinterface.c b/tests/check/gst/gstinterface.c new file mode 100644 index 0000000000..4697a1f375 --- /dev/null +++ b/tests/check/gst/gstinterface.c @@ -0,0 +1,62 @@ +/* GStreamer GstImplementsInterface check + * Copyright (C) 2008 Tim-Philipp Müller <tim centricular net> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#include <gst/check/gstcheck.h> + +GST_START_TEST (test_without_implements_interface) +{ + GstElement *element; + + /* we shouldn't crash if someone tries to use + * gst_element_implements_interface() on an element which doesn't implement + * the GstImplementsInterface (neither if the element does implement the + * requested interface, nor if it doesn't) */ + element = gst_element_factory_make ("filesrc", "filesrc"); + fail_unless (element != NULL, "Could not create filesrc element"); + + /* does not implement GstImplementsInterface, but does implement the + * GstUriHandler interface, so should just return TRUE */ + fail_if (!gst_element_implements_interface (element, GST_TYPE_URI_HANDLER)); + fail_if (gst_element_implements_interface (element, + GST_TYPE_IMPLEMENTS_INTERFACE)); + gst_object_unref (element); + + element = gst_element_factory_make ("identity", "identity"); + fail_unless (element != NULL, "Could not create identity element"); + fail_if (gst_element_implements_interface (element, GST_TYPE_URI_HANDLER)); + fail_if (gst_element_implements_interface (element, + GST_TYPE_IMPLEMENTS_INTERFACE)); + gst_object_unref (element); +} + +GST_END_TEST; + +static Suite * +gst_interface_suite (void) +{ + Suite *s = suite_create ("GstImplementsInterface"); + TCase *tc_chain = tcase_create ("correctness"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_without_implements_interface); + return s; +} + +GST_CHECK_MAIN (gst_interface); |