From 240c8e10cfeed12331af60cb6f1ff39d3d55c95a Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Fri, 8 Jul 2005 16:41:45 +0000 Subject: [PATCH] adding tests for elements Original commit message from CVS: adding tests for elements --- ChangeLog | 8 +++++ check/Makefile.am | 1 + check/gst/gstelement.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ gst/gstelement.c | 2 +- tests/check/Makefile.am | 1 + tests/check/gst/gstelement.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 check/gst/gstelement.c create mode 100644 tests/check/gst/gstelement.c diff --git a/ChangeLog b/ChangeLog index abb5fa0..3d4aa16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2005-07-08 Thomas Vander Stichele + * check/Makefile.am: + * check/gst/gstelement.c: (START_TEST), (gst_element_suite), + (main): + adding tests for elements + * gst/gstelement.c: (gst_element_dispose): + +2005-07-08 Thomas Vander Stichele + * gst/registries/gstlibxmlregistry.c: (load_feature): plug more leaks. A simple gst_init() now is leakfree, yay. diff --git a/check/Makefile.am b/check/Makefile.am index 4cfbc17..9b8f907 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -28,6 +28,7 @@ TESTS = $(top_builddir)/tools/gst-register \ gst/gstbuffer \ gst/gstbus \ gst/gstcaps \ + gst/gstelement \ gst/gstghostpad \ gst/gstiterator \ gst/gstmessage \ diff --git a/check/gst/gstelement.c b/check/gst/gstelement.c new file mode 100644 index 0000000..807678b --- /dev/null +++ b/check/gst/gstelement.c @@ -0,0 +1,79 @@ +/* GStreamer + * Copyright (C) 2005 Thomas Vander Stichele + * + * gstelement.c: Unit test for GstElement + * + * 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 "../gstcheck.h" + +START_TEST (test_add_pad) +{ + GstElement *e; + GstPad *p; + + /* getting an existing element class is cheating, but easier */ + e = gst_element_factory_make ("fakesrc", "source"); + + /* create a new floating pad with refcount 1 */ + p = gst_pad_new ("source", GST_PAD_SRC); + ASSERT_OBJECT_REFCOUNT (p, "pad", 1); + /* ref it for ourselves */ + gst_object_ref (p); + ASSERT_OBJECT_REFCOUNT (p, "pad", 2); + /* adding it sinks the pad -> not floating, same refcount */ + gst_element_add_pad (e, p); + ASSERT_OBJECT_REFCOUNT (p, "pad", 2); + + /* removing it reduces the refcount */ + gst_element_remove_pad (e, p); + ASSERT_OBJECT_REFCOUNT (p, "pad", 1); + + /* clean up our own reference */ + gst_object_unref (p); +} + +END_TEST; + +Suite * +gst_element_suite (void) +{ + Suite *s = suite_create ("GstElement"); + TCase *tc_chain = tcase_create ("element tests"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_add_pad); + + return s; +} + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = gst_element_suite (); + SRunner *sr = srunner_create (s); + + gst_check_init (&argc, &argv); + + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed (sr); + srunner_free (sr); + + return nf; +} diff --git a/gst/gstelement.c b/gst/gstelement.c index 66aa672..14c4879 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -2010,7 +2010,7 @@ gst_element_dispose (GObject * object) /* ref so we don't hit 0 again */ gst_object_ref (object); - /* first we break all our links with the ouside */ + /* first we break all our links with the outside */ while (element->pads) { gst_element_remove_pad (element, GST_PAD (element->pads->data)); } diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 4cfbc17..9b8f907 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -28,6 +28,7 @@ TESTS = $(top_builddir)/tools/gst-register \ gst/gstbuffer \ gst/gstbus \ gst/gstcaps \ + gst/gstelement \ gst/gstghostpad \ gst/gstiterator \ gst/gstmessage \ diff --git a/tests/check/gst/gstelement.c b/tests/check/gst/gstelement.c new file mode 100644 index 0000000..807678b --- /dev/null +++ b/tests/check/gst/gstelement.c @@ -0,0 +1,79 @@ +/* GStreamer + * Copyright (C) 2005 Thomas Vander Stichele + * + * gstelement.c: Unit test for GstElement + * + * 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 "../gstcheck.h" + +START_TEST (test_add_pad) +{ + GstElement *e; + GstPad *p; + + /* getting an existing element class is cheating, but easier */ + e = gst_element_factory_make ("fakesrc", "source"); + + /* create a new floating pad with refcount 1 */ + p = gst_pad_new ("source", GST_PAD_SRC); + ASSERT_OBJECT_REFCOUNT (p, "pad", 1); + /* ref it for ourselves */ + gst_object_ref (p); + ASSERT_OBJECT_REFCOUNT (p, "pad", 2); + /* adding it sinks the pad -> not floating, same refcount */ + gst_element_add_pad (e, p); + ASSERT_OBJECT_REFCOUNT (p, "pad", 2); + + /* removing it reduces the refcount */ + gst_element_remove_pad (e, p); + ASSERT_OBJECT_REFCOUNT (p, "pad", 1); + + /* clean up our own reference */ + gst_object_unref (p); +} + +END_TEST; + +Suite * +gst_element_suite (void) +{ + Suite *s = suite_create ("GstElement"); + TCase *tc_chain = tcase_create ("element tests"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_add_pad); + + return s; +} + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = gst_element_suite (); + SRunner *sr = srunner_create (s); + + gst_check_init (&argc, &argv); + + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed (sr); + srunner_free (sr); + + return nf; +} -- 2.7.4