Added missing tests
authorWim Taymans <wim.taymans@gmail.com>
Thu, 9 Sep 2004 08:56:51 +0000 (08:56 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Thu, 9 Sep 2004 08:56:51 +0000 (08:56 +0000)
Original commit message from CVS:
Added missing tests

tests/old/testsuite/threads/staticrec.c [new file with mode: 0644]
tests/old/testsuite/threads/threadh.c [new file with mode: 0644]
testsuite/threads/staticrec.c [new file with mode: 0644]
testsuite/threads/threadh.c [new file with mode: 0644]

diff --git a/tests/old/testsuite/threads/staticrec.c b/tests/old/testsuite/threads/staticrec.c
new file mode 100644 (file)
index 0000000..c77dff8
--- /dev/null
@@ -0,0 +1,49 @@
+#include <glib.h>
+
+GStaticRecMutex mutex = G_STATIC_REC_MUTEX_INIT;
+
+static void *
+thread1 (void *t)
+{
+  gint i = 0;
+
+  while (TRUE) {
+    g_static_rec_mutex_lock (&mutex);
+    if (i++ % 100000 == 0)
+      g_print ("*");
+    g_static_rec_mutex_unlock (&mutex);
+    if (i++ % 100000 == 0)
+      g_print ("*");
+  }
+  return NULL;
+}
+
+static void *
+thread2 (void *t)
+{
+  gint i = 0;
+
+  while (TRUE) {
+    g_static_rec_mutex_lock (&mutex);
+    if (i++ % 100000 == 0)
+      g_print (".");
+    g_static_rec_mutex_unlock (&mutex);
+    if (i++ % 100000 == 0)
+      g_print (".");
+  }
+  return NULL;
+}
+
+int
+main (gint argc, gchar * argv[])
+{
+  g_thread_init (NULL);
+  g_thread_create_full (thread1,
+      NULL, 0x200000, FALSE, TRUE, G_THREAD_PRIORITY_NORMAL, NULL);
+  g_thread_create_full (thread2,
+      NULL, 0x200000, FALSE, TRUE, G_THREAD_PRIORITY_NORMAL, NULL);
+
+  g_usleep (G_MAXLONG);
+
+  return 0;
+}
diff --git a/tests/old/testsuite/threads/threadh.c b/tests/old/testsuite/threads/threadh.c
new file mode 100644 (file)
index 0000000..45f6323
--- /dev/null
@@ -0,0 +1,51 @@
+#include <unistd.h>
+#include <gst/gst.h>
+
+static GstElement *thread, *pipeline;
+static GstElement *src, *sink;
+
+static void
+handoff_src (GstElement * element)
+{
+  g_print ("identity handoff\n");
+
+  if (gst_element_set_state (thread, GST_STATE_PAUSED) != GST_STATE_SUCCESS)
+    g_assert_not_reached ();
+
+  if (gst_element_set_state (sink, GST_STATE_READY) != GST_STATE_SUCCESS)
+    g_assert_not_reached ();
+
+  gst_bin_remove (GST_BIN (thread), src);
+}
+
+int
+main (int argc, char **argv)
+{
+  gst_init (&argc, &argv);
+
+  pipeline = gst_element_factory_make ("pipeline", "pipeline");
+
+  thread = gst_element_factory_make ("thread", "thread");
+  g_assert (thread);
+
+  src = gst_element_factory_make ("fakesrc", "src");
+  g_assert (src);
+  g_signal_connect (G_OBJECT (src), "handoff", (GCallback) handoff_src, NULL);
+  g_object_set (G_OBJECT (src), "signal-handoffs", TRUE, NULL);
+  sink = gst_element_factory_make ("fakesink", "sink");
+  g_assert (sink);
+
+  gst_bin_add (GST_BIN (pipeline), thread);
+
+  gst_bin_add_many (GST_BIN (thread), src, sink, NULL);
+  if (!gst_element_link_many (src, sink, NULL))
+    g_assert_not_reached ();
+
+  /* run a bit */
+  if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
+    g_assert_not_reached ();
+
+  sleep (2);
+
+  return 0;
+}
diff --git a/testsuite/threads/staticrec.c b/testsuite/threads/staticrec.c
new file mode 100644 (file)
index 0000000..c77dff8
--- /dev/null
@@ -0,0 +1,49 @@
+#include <glib.h>
+
+GStaticRecMutex mutex = G_STATIC_REC_MUTEX_INIT;
+
+static void *
+thread1 (void *t)
+{
+  gint i = 0;
+
+  while (TRUE) {
+    g_static_rec_mutex_lock (&mutex);
+    if (i++ % 100000 == 0)
+      g_print ("*");
+    g_static_rec_mutex_unlock (&mutex);
+    if (i++ % 100000 == 0)
+      g_print ("*");
+  }
+  return NULL;
+}
+
+static void *
+thread2 (void *t)
+{
+  gint i = 0;
+
+  while (TRUE) {
+    g_static_rec_mutex_lock (&mutex);
+    if (i++ % 100000 == 0)
+      g_print (".");
+    g_static_rec_mutex_unlock (&mutex);
+    if (i++ % 100000 == 0)
+      g_print (".");
+  }
+  return NULL;
+}
+
+int
+main (gint argc, gchar * argv[])
+{
+  g_thread_init (NULL);
+  g_thread_create_full (thread1,
+      NULL, 0x200000, FALSE, TRUE, G_THREAD_PRIORITY_NORMAL, NULL);
+  g_thread_create_full (thread2,
+      NULL, 0x200000, FALSE, TRUE, G_THREAD_PRIORITY_NORMAL, NULL);
+
+  g_usleep (G_MAXLONG);
+
+  return 0;
+}
diff --git a/testsuite/threads/threadh.c b/testsuite/threads/threadh.c
new file mode 100644 (file)
index 0000000..45f6323
--- /dev/null
@@ -0,0 +1,51 @@
+#include <unistd.h>
+#include <gst/gst.h>
+
+static GstElement *thread, *pipeline;
+static GstElement *src, *sink;
+
+static void
+handoff_src (GstElement * element)
+{
+  g_print ("identity handoff\n");
+
+  if (gst_element_set_state (thread, GST_STATE_PAUSED) != GST_STATE_SUCCESS)
+    g_assert_not_reached ();
+
+  if (gst_element_set_state (sink, GST_STATE_READY) != GST_STATE_SUCCESS)
+    g_assert_not_reached ();
+
+  gst_bin_remove (GST_BIN (thread), src);
+}
+
+int
+main (int argc, char **argv)
+{
+  gst_init (&argc, &argv);
+
+  pipeline = gst_element_factory_make ("pipeline", "pipeline");
+
+  thread = gst_element_factory_make ("thread", "thread");
+  g_assert (thread);
+
+  src = gst_element_factory_make ("fakesrc", "src");
+  g_assert (src);
+  g_signal_connect (G_OBJECT (src), "handoff", (GCallback) handoff_src, NULL);
+  g_object_set (G_OBJECT (src), "signal-handoffs", TRUE, NULL);
+  sink = gst_element_factory_make ("fakesink", "sink");
+  g_assert (sink);
+
+  gst_bin_add (GST_BIN (pipeline), thread);
+
+  gst_bin_add_many (GST_BIN (thread), src, sink, NULL);
+  if (!gst_element_link_many (src, sink, NULL))
+    g_assert_not_reached ();
+
+  /* run a bit */
+  if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
+    g_assert_not_reached ();
+
+  sleep (2);
+
+  return 0;
+}