[farsight2/master] Add test for the recursive element adding notification

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:20:41 PST 2008


---
 .gitignore                       |    1 +
 gst-libs/gst/farsight/fs-utils.c |    9 ++-
 gst-libs/gst/farsight/fs-utils.h |    2 +-
 tests/check/Makefile.am          |   12 ++-
 tests/check/utils/binadded.c     |  203 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 224 insertions(+), 3 deletions(-)
 create mode 100644 tests/check/utils/binadded.c

diff --git a/.gitignore b/.gitignore
index 5096dc3..b1379f6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,6 +39,7 @@ tests/check/base/fstransmitter
 tests/check/transmitter/rawudp
 tests/check/main/rtpconference
 tests/check/main/rtpcodecs
+tests/check/utils/binadded
 tests/rtp/codec-discovery
 
 aclocal.m4
diff --git a/gst-libs/gst/farsight/fs-utils.c b/gst-libs/gst/farsight/fs-utils.c
index 1d9cc18..929e7b5 100644
--- a/gst-libs/gst/farsight/fs-utils.c
+++ b/gst-libs/gst/farsight/fs-utils.c
@@ -218,8 +218,10 @@ fs_utils_add_recursive_element_added_notification (GstBin *bin,
  *
  * This function will remove the callback added by
  * #fs_utils_add_recursive_element_added_notification
+ *
+ * Returns: TRUE if the notification could be removed, FALSE otherwise
  */
-void
+gboolean
 fs_utils_remove_recursive_element_added_notification (GstBin *bin,
     gpointer handle)
 {
@@ -232,5 +234,10 @@ fs_utils_remove_recursive_element_added_notification (GstBin *bin,
  {
    g_assert (data->head == bin);
    _bin_unparented_cb (GST_OBJECT (data->head), NULL, data);
+   return TRUE;
+ }
+ else
+ {
+   return FALSE;
  }
 }
diff --git a/gst-libs/gst/farsight/fs-utils.h b/gst-libs/gst/farsight/fs-utils.h
index b40c79e..fb4fe3a 100644
--- a/gst-libs/gst/farsight/fs-utils.h
+++ b/gst-libs/gst/farsight/fs-utils.h
@@ -50,7 +50,7 @@ gpointer fs_utils_add_recursive_element_added_notification (GstBin *bin,
     FsElementAddedCallback callback,
     gpointer user_data);
 
-void fs_utils_remove_recursive_element_added_notification (GstBin *bin,
+gboolean fs_utils_remove_recursive_element_added_notification (GstBin *bin,
     gpointer handle);
 
 
diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am
index 04fd9f6..d1a3bc3 100644
--- a/tests/check/Makefile.am
+++ b/tests/check/Makefile.am
@@ -36,7 +36,8 @@ check_PROGRAMS = \
 	base/fstransmitter \
 	transmitter/rawudp \
 	main/rtpconference \
-	main/rtpcodecs
+	main/rtpcodecs \
+	utils/binadded
 
 
 AM_CFLAGS =  $(FS2_CFLAGS) $(GST_CFLAGS) $(GST_CHECK_CFLAGS)
@@ -77,3 +78,12 @@ main_rtpcodecs_SOURCES = \
 	main/generic.h \
 	main/rtpcodecs.c
 
+
+
+
+utils_binadded_LDADD = $(LDADD) \
+	$(top_builddir)/gst-libs/gst/farsight/libgstfarsight-0.10.la
+utils_binadded_CFLAGS = $(FS2_INTERNAL_CFLAGS) $(CFLAGS) $(AM_CFLAGS)
+utils_binadded_SOURCES = \
+	utils/binadded.c
+
diff --git a/tests/check/utils/binadded.c b/tests/check/utils/binadded.c
new file mode 100644
index 0000000..e21df7f
--- /dev/null
+++ b/tests/check/utils/binadded.c
@@ -0,0 +1,203 @@
+/* Farsigh2 unit tests for FsCodec
+ *
+ * Copyright (C) 2007 Collabora, Nokia
+ * @author: Olivier Crete <olivier.crete at collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gst/check/gstcheck.h>
+#include <gst/farsight/fs-utils.h>
+
+gboolean called = FALSE;
+gpointer last_added = NULL;
+gpointer last_bin = NULL;
+
+static void
+_added_cb (GstBin *bin, GstElement *element, gpointer user_data)
+{
+  GstObject *parent = NULL;
+
+  fail_unless (user_data == &last_added, "Pass user_data is incorrect");
+  called = TRUE;
+  last_added = element;
+  last_bin = bin;
+
+  if (bin)
+  {
+    parent = gst_object_get_parent (GST_OBJECT (element));
+    fail_if (GST_OBJECT_CAST (bin) != parent,
+        "The bin passed to use is not the right parent");
+    gst_object_unref (parent);
+  }
+}
+
+
+GST_START_TEST (test_bin_added_simple)
+{
+  GstElement *pipeline = NULL;
+  GstElement *identity = NULL;
+  gpointer handle = NULL;
+
+  pipeline = gst_pipeline_new (NULL);
+
+  identity = gst_element_factory_make ("identity", NULL);
+  gst_object_ref (identity);
+
+  handle = fs_utils_add_recursive_element_added_notification (
+      GST_BIN (pipeline),
+      _added_cb, &last_added);
+
+  fail_if (handle == NULL, "Could not add notification to pipeline");
+
+  fail_unless (gst_bin_add (GST_BIN (pipeline), identity),
+      "Could not add identity to pipeline");
+
+  fail_if (called == FALSE, "AddedCallback not called");
+  fail_unless (last_added == identity,
+      "The element passed to the callback was wrong"
+      " (it was %p, should have been %p",
+      last_added, identity);
+  fail_unless (last_bin == pipeline,
+      "The bin passed to the callback was wrong"
+      " (it was %p, should have been %p",
+      last_bin, pipeline);
+
+  fail_unless (gst_bin_remove (GST_BIN (pipeline), identity),
+      "Could not remove identity from pipeline");
+
+  called = FALSE;
+  last_added = last_bin = NULL;
+
+
+  fail_unless (
+      fs_utils_remove_recursive_element_added_notification (GST_BIN (pipeline),
+          handle),
+      "Could not remove notification handle %p", handle);
+
+  fail_unless (gst_bin_add (GST_BIN (pipeline), identity),
+      "Could not add identity to pipeline");
+
+  fail_if (called == TRUE, "AddedCallback was removed, but was still called");
+
+  called = FALSE;
+  last_added = last_bin = NULL;
+
+  gst_object_unref (identity);
+  gst_object_unref (pipeline);
+}
+GST_END_TEST;
+
+
+GST_START_TEST (test_bin_added_recursive)
+{
+  GstElement *pipeline = NULL;
+  GstElement *bin = NULL;
+  GstElement *identity = NULL;
+  gpointer handle = NULL;
+
+  pipeline = gst_pipeline_new (NULL);
+
+  bin = gst_bin_new (NULL);
+  gst_object_ref (bin);
+
+  gst_bin_add (GST_BIN (pipeline), bin);
+
+  identity = gst_element_factory_make ("identity", NULL);
+  gst_object_ref (identity);
+
+  handle = fs_utils_add_recursive_element_added_notification (
+      GST_BIN (pipeline),
+      _added_cb, &last_added);
+
+  fail_if (handle == NULL, "Could not add notification to bin");
+
+  fail_unless (gst_bin_add (GST_BIN (bin), identity),
+      "Could not add identity to bin");
+
+  fail_if (called == FALSE, "AddedCallback not called");
+  fail_unless (last_added == identity,
+      "The element passed to the callback was wrong"
+      " (it was %p, should have been %p",
+      last_added, identity);
+  fail_unless (last_bin == bin,
+      "The bin passed to the callback was wrong"
+      " (it was %p, should have been %p",
+      last_bin, bin);
+
+  fail_unless (gst_bin_remove (GST_BIN (bin), identity),
+      "Could not remove identity from bin");
+
+  called = FALSE;
+  last_added = last_bin = NULL;
+
+
+  fail_unless (
+      fs_utils_remove_recursive_element_added_notification (GST_BIN (pipeline),
+          handle),
+      "Could not remove notification handle %p", handle);
+
+  fail_unless (gst_bin_add (GST_BIN (bin), identity),
+      "Could not add identity to bin");
+
+  fail_if (called == TRUE, "AddedCallback was removed, but was still called");
+
+  fail_unless (gst_bin_remove (GST_BIN (bin), identity),
+      "Could not remove identity from bin");
+
+  handle = fs_utils_add_recursive_element_added_notification (
+      GST_BIN (pipeline),
+      _added_cb, &last_added);
+
+  fail_if (handle == NULL, "Could not re-add notification to bin");
+
+  called = FALSE;
+  last_added = last_bin = NULL;
+
+  gst_bin_remove (GST_BIN (pipeline), bin);
+
+  fail_unless (gst_bin_add (GST_BIN (bin), identity),
+      "Could not add identity to bin");
+
+  fail_if (called == TRUE, "The bin was removed from the pipeline,"
+      " but the callback was still called");
+
+
+  gst_object_unref (identity);
+  gst_object_unref (bin);
+  gst_object_unref (pipeline);
+}
+GST_END_TEST;
+
+
+static Suite *
+binadded_suite (void)
+{
+  Suite *s = suite_create ("binadded");
+  TCase *tc_chain = tcase_create ("binadded");
+
+  suite_add_tcase (s, tc_chain);
+  tcase_add_test (tc_chain, test_bin_added_simple);
+  tcase_add_test (tc_chain, test_bin_added_recursive);
+
+  return s;
+}
+
+GST_CHECK_MAIN (binadded);
-- 
1.5.6.5




More information about the farsight-commits mailing list