adding basic tests for fakesrc fakesink and tee
authorThomas Vander Stichele <thomas@apestaart.org>
Tue, 5 Feb 2002 11:48:36 +0000 (11:48 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Tue, 5 Feb 2002 11:48:36 +0000 (11:48 +0000)
Original commit message from CVS:
adding basic tests for fakesrc fakesink and tee

tests/old/testsuite/elements/Makefile.am
tests/old/testsuite/elements/events.h [new file with mode: 0644]
tests/old/testsuite/elements/fake.c [new file with mode: 0644]
tests/old/testsuite/elements/tee.c
testsuite/elements/Makefile.am
testsuite/elements/events.h [new file with mode: 0644]
testsuite/elements/fake.c [new file with mode: 0644]
testsuite/elements/tee.c

index 33ee8e9..7631e70 100644 (file)
@@ -1,9 +1,9 @@
-testprogs = tee
+testprogs = tee fake
 
 TESTS = $(testprogs)
 
 check_PROGRAMS = $(testprogs)
 
-tee_LDADD = $(GST_LIBS) 
-tee_CFLAGS = $(GST_CFLAGS)
+LDADD = $(GST_LIBS) 
+CFLAGS = $(GST_CFLAGS)
 
diff --git a/tests/old/testsuite/elements/events.h b/tests/old/testsuite/elements/events.h
new file mode 100644 (file)
index 0000000..a50b6ac
--- /dev/null
@@ -0,0 +1,45 @@
+#include <gst/gst.h>
+#include <gst/gstpropsprivate.h>
+
+/*
+ * no need to librify this simple function set
+ */
+
+static void
+print_props (gpointer data, gpointer user_data)
+{
+  GstPropsEntry *entry = (GstPropsEntry *)data;
+  GstElement *element = GST_ELEMENT (user_data);
+
+  g_print ("%s: %s: ", gst_element_get_name (element),
+                  g_quark_to_string (entry->propid));
+  switch (entry->propstype) {
+    case GST_PROPS_INT_ID:
+      g_print ("%d\n", entry->data.int_data);
+      break;
+    case GST_PROPS_STRING_ID:
+      g_print ("%s\n", entry->data.string_data.string);
+      break;
+    case GST_PROPS_FLOAT_ID:
+      g_print ("%f\n", entry->data.float_data);
+      break;
+    default:
+      g_print ("unknown\n");
+  }
+}
+
+static void
+event_func (GstElement *element, GstEvent *event)
+{
+  GstProps *props;
+
+  if (event == NULL)
+    return;
+
+  if (GST_EVENT_TYPE (event) == GST_EVENT_INFO) {
+    props = GST_EVENT_INFO_PROPS (event);
+
+    g_list_foreach (props->properties, print_props, GST_EVENT_SRC (event));
+  }
+}
+
diff --git a/tests/old/testsuite/elements/fake.c b/tests/old/testsuite/elements/fake.c
new file mode 100644 (file)
index 0000000..6af93b0
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * test for fakesrc and fakesink element
+ * this tests for proxying of caps
+ * thomas@apestaart.org
+ */
+
+#include <gst/gst.h>
+#include "events.h"
+
+GstElement *
+element_create (char *name, char *element)
+  /*
+   * create the element
+   * print an error if it can't be created
+   * return NULL if it couldn't be created
+   * return element if it did work
+   */
+{
+  GstElement *el = NULL;
+
+  el = (GstElement *) gst_elementfactory_make (element, name);
+  if (el == NULL)
+  {
+    fprintf (stderr, "Could not create element %s (%s) !\n", name, element);
+    return NULL;
+  }
+  else
+    return el;
+}
+
+int
+main (int argc, char *argv[])
+{
+  GstElement *pipeline = NULL;
+  GstElement *src, *sink;
+
+  /* init */
+  gst_init (&argc, &argv);
+
+  /* create */
+  g_print ("Creating pipeline\n");
+  pipeline = gst_pipeline_new ("pipeline");
+
+  g_signal_connect (G_OBJECT (pipeline), "event", G_CALLBACK (event_func), NULL);
+ g_print ("Creating elements\n");
+  if (!(src = element_create ("src", "fakesrc"))) return 1;
+  g_object_set (G_OBJECT (src), "sizetype", 2, NULL);
+  if (!(sink = element_create ("sink", "fakesink"))) return 1;
+  /* add */
+  g_print ("Adding elements to bin\n");
+  gst_bin_add (GST_BIN (pipeline), src);
+  gst_bin_add (GST_BIN (pipeline), sink);
+
+  /* connect */
+  g_print ("Connecting elements\n");
+  gst_pad_connect (gst_element_get_pad (src, "src"),
+                  gst_element_get_pad (sink, "sink"));
+   
+  /* set to play */
+  g_print ("Doing 1 iteration\n");
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);
+  gst_bin_iterate (GST_BIN (pipeline));
+
+  g_print ("Done !\n");
+  return 0;
+}
+
index b81346f..83d12da 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <gst/gst.h>
+#include "events.h"
 
 GstElement *
 element_create (char *name, char *element)
@@ -32,7 +33,7 @@ main (int argc, char *argv[])
 {
   GstElement *pipeline = NULL;
   GstElement *tee, *src, *sink1, *sink2;
-  GstPad *tee_src;
+  GstPad *tee_src1, *tee_src2;
 
   /* init */
   gst_init (&argc, &argv);
@@ -40,26 +41,57 @@ main (int argc, char *argv[])
   /* create */
   g_print ("Creating pipeline\n");
   pipeline = gst_pipeline_new ("pipeline");
-  //g_assert (GST_IS_PIPELINE (pipeline));
+  g_signal_connect (G_OBJECT (pipeline), "event", G_CALLBACK (event_func), NULL);
 
   g_print ("Creating elements\n");
   if (!(tee = element_create ("tee", "tee"))) return 1;
   if (!(src = element_create ("src", "fakesrc"))) return 1;
+  g_object_set (G_OBJECT (src), "sizetype", 2, NULL);
   if (!(sink1 = element_create ("sink1", "fakesink"))) return 1;
   if (!(sink2 = element_create ("sink2", "fakesink"))) return 1;
-
   /* add */
   g_print ("Adding elements to bin\n");
   gst_bin_add (GST_BIN (pipeline), src);
   gst_bin_add (GST_BIN (pipeline), tee);
-  
-  /* request one pad from tee */
-  tee_src = gst_element_request_pad_by_name (tee, "src%d");
 
-  /* connect */
-  gst_pad_connect (tee_src, gst_element_get_pad (sink1, "sink"));
+  /* connect input part */
+  g_print ("Connecting input elements\n");
+  gst_pad_connect (gst_element_get_pad (src, "src"),
+                  gst_element_get_pad (tee, "sink"));
+   
+  /* request one pad from tee */
+  g_print ("Requesting first pad\n");
+  tee_src1 = gst_element_request_pad_by_name (tee, "src%d");
+  gst_bin_add (GST_BIN (pipeline), sink1);
+  gst_pad_connect (tee_src1, gst_element_get_pad (sink1, "sink"));
 
   /* set to play */
+  g_print ("Doing 1 iteration\n");
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);
+  gst_bin_iterate (GST_BIN (pipeline));
+
+  /* pause and request another pad */
+  g_print ("Requesting second pad\n");
+  gst_element_set_state (pipeline, GST_STATE_PAUSED);
+  tee_src2 = gst_element_request_pad_by_name (tee, "src%d");
+  gst_bin_add (GST_BIN (pipeline), sink2);
+  gst_pad_connect (tee_src2, gst_element_get_pad (sink2, "sink"));
+  
+  /* now we have two fakesinks connected, iterate */
+  g_print ("Doing 1 iteration\n");
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);
+  gst_bin_iterate (GST_BIN (pipeline));
+
+  /* remove the first one, iterate */
+  g_print ("Removing first sink\n");
+  gst_element_set_state (pipeline, GST_STATE_PAUSED);
+  gst_pad_disconnect (tee_src1, gst_element_get_pad (sink1, "sink"));
+  gst_pad_destroy (tee_src1);
+  gst_bin_remove (GST_BIN (pipeline), sink1);
+
+  /* only second fakesink connected, iterate */
+  g_print ("Doing 1 iteration\n");
   gst_element_set_state (pipeline, GST_STATE_PLAYING);
   gst_bin_iterate (GST_BIN (pipeline));
 
index 33ee8e9..7631e70 100644 (file)
@@ -1,9 +1,9 @@
-testprogs = tee
+testprogs = tee fake
 
 TESTS = $(testprogs)
 
 check_PROGRAMS = $(testprogs)
 
-tee_LDADD = $(GST_LIBS) 
-tee_CFLAGS = $(GST_CFLAGS)
+LDADD = $(GST_LIBS) 
+CFLAGS = $(GST_CFLAGS)
 
diff --git a/testsuite/elements/events.h b/testsuite/elements/events.h
new file mode 100644 (file)
index 0000000..a50b6ac
--- /dev/null
@@ -0,0 +1,45 @@
+#include <gst/gst.h>
+#include <gst/gstpropsprivate.h>
+
+/*
+ * no need to librify this simple function set
+ */
+
+static void
+print_props (gpointer data, gpointer user_data)
+{
+  GstPropsEntry *entry = (GstPropsEntry *)data;
+  GstElement *element = GST_ELEMENT (user_data);
+
+  g_print ("%s: %s: ", gst_element_get_name (element),
+                  g_quark_to_string (entry->propid));
+  switch (entry->propstype) {
+    case GST_PROPS_INT_ID:
+      g_print ("%d\n", entry->data.int_data);
+      break;
+    case GST_PROPS_STRING_ID:
+      g_print ("%s\n", entry->data.string_data.string);
+      break;
+    case GST_PROPS_FLOAT_ID:
+      g_print ("%f\n", entry->data.float_data);
+      break;
+    default:
+      g_print ("unknown\n");
+  }
+}
+
+static void
+event_func (GstElement *element, GstEvent *event)
+{
+  GstProps *props;
+
+  if (event == NULL)
+    return;
+
+  if (GST_EVENT_TYPE (event) == GST_EVENT_INFO) {
+    props = GST_EVENT_INFO_PROPS (event);
+
+    g_list_foreach (props->properties, print_props, GST_EVENT_SRC (event));
+  }
+}
+
diff --git a/testsuite/elements/fake.c b/testsuite/elements/fake.c
new file mode 100644 (file)
index 0000000..6af93b0
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * test for fakesrc and fakesink element
+ * this tests for proxying of caps
+ * thomas@apestaart.org
+ */
+
+#include <gst/gst.h>
+#include "events.h"
+
+GstElement *
+element_create (char *name, char *element)
+  /*
+   * create the element
+   * print an error if it can't be created
+   * return NULL if it couldn't be created
+   * return element if it did work
+   */
+{
+  GstElement *el = NULL;
+
+  el = (GstElement *) gst_elementfactory_make (element, name);
+  if (el == NULL)
+  {
+    fprintf (stderr, "Could not create element %s (%s) !\n", name, element);
+    return NULL;
+  }
+  else
+    return el;
+}
+
+int
+main (int argc, char *argv[])
+{
+  GstElement *pipeline = NULL;
+  GstElement *src, *sink;
+
+  /* init */
+  gst_init (&argc, &argv);
+
+  /* create */
+  g_print ("Creating pipeline\n");
+  pipeline = gst_pipeline_new ("pipeline");
+
+  g_signal_connect (G_OBJECT (pipeline), "event", G_CALLBACK (event_func), NULL);
+ g_print ("Creating elements\n");
+  if (!(src = element_create ("src", "fakesrc"))) return 1;
+  g_object_set (G_OBJECT (src), "sizetype", 2, NULL);
+  if (!(sink = element_create ("sink", "fakesink"))) return 1;
+  /* add */
+  g_print ("Adding elements to bin\n");
+  gst_bin_add (GST_BIN (pipeline), src);
+  gst_bin_add (GST_BIN (pipeline), sink);
+
+  /* connect */
+  g_print ("Connecting elements\n");
+  gst_pad_connect (gst_element_get_pad (src, "src"),
+                  gst_element_get_pad (sink, "sink"));
+   
+  /* set to play */
+  g_print ("Doing 1 iteration\n");
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);
+  gst_bin_iterate (GST_BIN (pipeline));
+
+  g_print ("Done !\n");
+  return 0;
+}
+
index b81346f..83d12da 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <gst/gst.h>
+#include "events.h"
 
 GstElement *
 element_create (char *name, char *element)
@@ -32,7 +33,7 @@ main (int argc, char *argv[])
 {
   GstElement *pipeline = NULL;
   GstElement *tee, *src, *sink1, *sink2;
-  GstPad *tee_src;
+  GstPad *tee_src1, *tee_src2;
 
   /* init */
   gst_init (&argc, &argv);
@@ -40,26 +41,57 @@ main (int argc, char *argv[])
   /* create */
   g_print ("Creating pipeline\n");
   pipeline = gst_pipeline_new ("pipeline");
-  //g_assert (GST_IS_PIPELINE (pipeline));
+  g_signal_connect (G_OBJECT (pipeline), "event", G_CALLBACK (event_func), NULL);
 
   g_print ("Creating elements\n");
   if (!(tee = element_create ("tee", "tee"))) return 1;
   if (!(src = element_create ("src", "fakesrc"))) return 1;
+  g_object_set (G_OBJECT (src), "sizetype", 2, NULL);
   if (!(sink1 = element_create ("sink1", "fakesink"))) return 1;
   if (!(sink2 = element_create ("sink2", "fakesink"))) return 1;
-
   /* add */
   g_print ("Adding elements to bin\n");
   gst_bin_add (GST_BIN (pipeline), src);
   gst_bin_add (GST_BIN (pipeline), tee);
-  
-  /* request one pad from tee */
-  tee_src = gst_element_request_pad_by_name (tee, "src%d");
 
-  /* connect */
-  gst_pad_connect (tee_src, gst_element_get_pad (sink1, "sink"));
+  /* connect input part */
+  g_print ("Connecting input elements\n");
+  gst_pad_connect (gst_element_get_pad (src, "src"),
+                  gst_element_get_pad (tee, "sink"));
+   
+  /* request one pad from tee */
+  g_print ("Requesting first pad\n");
+  tee_src1 = gst_element_request_pad_by_name (tee, "src%d");
+  gst_bin_add (GST_BIN (pipeline), sink1);
+  gst_pad_connect (tee_src1, gst_element_get_pad (sink1, "sink"));
 
   /* set to play */
+  g_print ("Doing 1 iteration\n");
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);
+  gst_bin_iterate (GST_BIN (pipeline));
+
+  /* pause and request another pad */
+  g_print ("Requesting second pad\n");
+  gst_element_set_state (pipeline, GST_STATE_PAUSED);
+  tee_src2 = gst_element_request_pad_by_name (tee, "src%d");
+  gst_bin_add (GST_BIN (pipeline), sink2);
+  gst_pad_connect (tee_src2, gst_element_get_pad (sink2, "sink"));
+  
+  /* now we have two fakesinks connected, iterate */
+  g_print ("Doing 1 iteration\n");
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);
+  gst_bin_iterate (GST_BIN (pipeline));
+
+  /* remove the first one, iterate */
+  g_print ("Removing first sink\n");
+  gst_element_set_state (pipeline, GST_STATE_PAUSED);
+  gst_pad_disconnect (tee_src1, gst_element_get_pad (sink1, "sink"));
+  gst_pad_destroy (tee_src1);
+  gst_bin_remove (GST_BIN (pipeline), sink1);
+
+  /* only second fakesink connected, iterate */
+  g_print ("Doing 1 iteration\n");
   gst_element_set_state (pipeline, GST_STATE_PLAYING);
   gst_bin_iterate (GST_BIN (pipeline));