summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2005-09-09 12:02:41 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2005-09-09 12:02:41 +0000
commit8b61247c78ed7205a0b9a5152043b2410783a1c7 (patch)
tree9b4d50499c6dfee8e30ade0926e825fd132ea946
parent4e78d6183f4d817c7a7fe4ae286000848cb25b2c (diff)
check/: adding a test for pipelines and state changes
Original commit message from CVS: * check/Makefile.am: * check/gst/.cvsignore: * check/gst/gstpipeline.c: (pop_messages), (GST_START_TEST), (gst_pipeline_suite), (main): adding a test for pipelines and state changes * gst/gstutils.c: (get_state_func): add some debugging * gstreamer.spec.in: fix up spec file
-rw-r--r--ChangeLog12
-rw-r--r--check/Makefile.am1
-rw-r--r--check/gst/.gitignore1
-rw-r--r--check/gst/gstpipeline.c173
-rw-r--r--gst/gstutils.c7
-rw-r--r--gstreamer.spec.in2
-rw-r--r--tests/check/Makefile.am1
-rw-r--r--tests/check/gst/.gitignore1
-rw-r--r--tests/check/gst/gstpipeline.c173
9 files changed, 368 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 21faad452..c77be19a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2005-09-09 Thomas Vander Stichele <thomas at apestaart dot org>
+
+ * check/Makefile.am:
+ * check/gst/.cvsignore:
+ * check/gst/gstpipeline.c: (pop_messages), (GST_START_TEST),
+ (gst_pipeline_suite), (main):
+ adding a test for pipelines and state changes
+ * gst/gstutils.c: (get_state_func):
+ add some debugging
+ * gstreamer.spec.in:
+ fix up spec file
+
2005-09-08 Michael Smith <msmith@fluendo.com>
* gst/elements/gstfilesrc.c: (gst_file_src_map_region),
diff --git a/check/Makefile.am b/check/Makefile.am
index cd23a70ba..ca7b60c2f 100644
--- a/check/Makefile.am
+++ b/check/Makefile.am
@@ -46,6 +46,7 @@ check_PROGRAMS = \
gst/gstminiobject \
gst/gstobject \
gst/gstpad \
+ gst/gstpipeline \
gst/gstsystemclock \
gst/gststructure \
gst/gsttag \
diff --git a/check/gst/.gitignore b/check/gst/.gitignore
index c8990c54f..170321ce0 100644
--- a/check/gst/.gitignore
+++ b/check/gst/.gitignore
@@ -13,6 +13,7 @@ gstmessage
gstminiobject
gstobject
gstpad
+gstpipeline
gststructure
gstsystemclock
gsttag
diff --git a/check/gst/gstpipeline.c b/check/gst/gstpipeline.c
new file mode 100644
index 000000000..21b93a337
--- /dev/null
+++ b/check/gst/gstpipeline.c
@@ -0,0 +1,173 @@
+/* GStreamer
+ * Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
+ *
+ * gstpipeline.c: Unit test for GstPipeline
+ *
+ * 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>
+
+#if 0
+static void
+pop_messages (GstBus * bus, int count)
+{
+ GstMessage *message;
+
+ int i;
+
+ GST_DEBUG ("popping %d messages", count);
+ for (i = 0; i < count; ++i) {
+ fail_unless (gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1)
+ == GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
+
+ message = gst_bus_pop (bus);
+ gst_message_unref (message);
+ }
+ GST_DEBUG ("popped %d messages", count);
+}
+#endif
+
+/* FIXME: even though this is a pathological case, it would make sense
+ * to have it return ASYNC as well */
+GST_START_TEST (test_async_state_change_empty)
+{
+ GstPipeline *pipeline;
+
+ pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
+ fail_unless (pipeline != NULL, "Could not create pipeline");
+ g_object_set (G_OBJECT (pipeline), "play-timeout", 0LL, NULL);
+
+/*
+ fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
+ GST_STATE_PLAYING), GST_STATE_CHANGE_ASYNC);
+*/
+
+ gst_object_unref (pipeline);
+}
+
+GST_END_TEST;
+
+/* FIXME: this is less of a pathological case, it would make sense
+ * to have it return ASYNC as well */
+GST_START_TEST (test_async_state_change_fake_ready)
+{
+ GstPipeline *pipeline;
+ GstElement *src, *sink;
+
+ pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
+ fail_unless (pipeline != NULL, "Could not create pipeline");
+ g_object_set (G_OBJECT (pipeline), "play-timeout", 0LL, NULL);
+
+ src = gst_element_factory_make ("fakesrc", NULL);
+ sink = gst_element_factory_make ("fakesink", NULL);
+
+ gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
+ gst_element_link (src, sink);
+
+/*
+ fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
+ GST_STATE_READY), GST_STATE_CHANGE_ASYNC);
+*/
+
+ gst_object_unref (pipeline);
+}
+
+GST_END_TEST;
+
+
+#if 0
+GST_START_TEST (test_async_state_change_fake)
+{
+ GstPipeline *pipeline;
+ GstElement *src, *sink;
+ GstBus *bus;
+ GstMessageType type;
+
+ pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
+ fail_unless (pipeline != NULL, "Could not create pipeline");
+ g_object_set (G_OBJECT (pipeline), "play-timeout", 0LL, NULL);
+
+ src = gst_element_factory_make ("fakesrc", NULL);
+ sink = gst_element_factory_make ("fakesink", NULL);
+
+ gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
+ gst_element_link (src, sink);
+
+ bus = gst_pipeline_get_bus (pipeline);
+
+ fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
+ GST_STATE_PLAYING), GST_STATE_CHANGE_ASYNC);
+
+ gst_bin_watch_for_state_change (GST_BIN (pipeline));
+
+ while ((type = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1))) {
+ GstMessage *message;
+ GstState old, new;
+ GstState state, pending;
+ GstStateChange ret;
+ GTimeVal timeval;
+
+ message = gst_bus_pop (bus);
+ gst_message_parse_state_changed (message, &old, &new);
+ GST_DEBUG_OBJECT (message->src, "state change from %d to %d", old, new);
+ g_print ("message\n");
+ g_print ("%s: %d -> %d\n", GST_OBJECT_NAME (message->src), old, new);
+ gst_message_unref (message);
+
+ timeval.tv_sec = 0;
+ timeval.tv_usec = 0;
+ ret = gst_element_get_state (GST_ELEMENT (pipeline), &state, &pending,
+ &timeval);
+ }
+ gst_object_unref (pipeline);
+}
+
+GST_END_TEST;
+#endif
+
+Suite *
+gst_pipeline_suite (void)
+{
+ Suite *s = suite_create ("GstPipeline");
+ TCase *tc_chain = tcase_create ("pipeline tests");
+
+ suite_add_tcase (s, tc_chain);
+ tcase_add_test (tc_chain, test_async_state_change_empty);
+ tcase_add_test (tc_chain, test_async_state_change_fake_ready);
+#if 0
+ tcase_add_test (tc_chain, test_async_state_change_fake);
+#endif
+
+ return s;
+}
+
+int
+main (int argc, char **argv)
+{
+ int nf;
+
+ Suite *s = gst_pipeline_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/gstutils.c b/gst/gstutils.c
index 5723f4bf8..447bf9a0e 100644
--- a/gst/gstutils.c
+++ b/gst/gstutils.c
@@ -1850,6 +1850,9 @@ get_state_func (GstElement * element, gpointer unused)
while (ret == GST_STATE_CHANGE_ASYNC)
ret = gst_element_get_state (element, NULL, NULL, NULL);
+ GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
+ "thread done waiting on state change");
+
gst_object_unref (element);
}
@@ -1859,8 +1862,8 @@ get_state_func (GstElement * element, gpointer unused)
*
* Spawns a thread calling gst_element_get_state on @bin with infinite timeout.
*
- * In practice this is done because if a bin returns %GST_STATE_CHANGE_ASYNC from a
- * state change it will not commit its state until someone calls
+ * In practice this is done because if a bin returns %GST_STATE_CHANGE_ASYNC
+ * from a state change, it will not commit its state until someone calls
* gst_element_get_state() on it. Thus having another thread checking the bin's
* state will ensure that a state-changed message gets posted on the bus
* eventually.
diff --git a/gstreamer.spec.in b/gstreamer.spec.in
index 6f43631aa..bb5dbc84c 100644
--- a/gstreamer.spec.in
+++ b/gstreamer.spec.in
@@ -190,8 +190,8 @@ rm -rf $RPM_BUILD_ROOT
%{_includedir}/gstreamer-%{majorminor}/gst/dataprotocol
%{_includedir}/gstreamer-%{majorminor}/gst/getbits
-%{_libdir}/libgstdataprotocol-%{majorminor}.so
%{_libdir}/libgstreamer-%{majorminor}.so
+%{_libdir}/libgstdataprotocol-%{majorminor}.so
%{_libdir}/libgstbase-%{majorminor}.so
%{_libdir}/libgstcontroller-%{majorminor}.so
diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am
index cd23a70ba..ca7b60c2f 100644
--- a/tests/check/Makefile.am
+++ b/tests/check/Makefile.am
@@ -46,6 +46,7 @@ check_PROGRAMS = \
gst/gstminiobject \
gst/gstobject \
gst/gstpad \
+ gst/gstpipeline \
gst/gstsystemclock \
gst/gststructure \
gst/gsttag \
diff --git a/tests/check/gst/.gitignore b/tests/check/gst/.gitignore
index c8990c54f..170321ce0 100644
--- a/tests/check/gst/.gitignore
+++ b/tests/check/gst/.gitignore
@@ -13,6 +13,7 @@ gstmessage
gstminiobject
gstobject
gstpad
+gstpipeline
gststructure
gstsystemclock
gsttag
diff --git a/tests/check/gst/gstpipeline.c b/tests/check/gst/gstpipeline.c
new file mode 100644
index 000000000..21b93a337
--- /dev/null
+++ b/tests/check/gst/gstpipeline.c
@@ -0,0 +1,173 @@
+/* GStreamer
+ * Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
+ *
+ * gstpipeline.c: Unit test for GstPipeline
+ *
+ * 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>
+
+#if 0
+static void
+pop_messages (GstBus * bus, int count)
+{
+ GstMessage *message;
+
+ int i;
+
+ GST_DEBUG ("popping %d messages", count);
+ for (i = 0; i < count; ++i) {
+ fail_unless (gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1)
+ == GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
+
+ message = gst_bus_pop (bus);
+ gst_message_unref (message);
+ }
+ GST_DEBUG ("popped %d messages", count);
+}
+#endif
+
+/* FIXME: even though this is a pathological case, it would make sense
+ * to have it return ASYNC as well */
+GST_START_TEST (test_async_state_change_empty)
+{
+ GstPipeline *pipeline;
+
+ pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
+ fail_unless (pipeline != NULL, "Could not create pipeline");
+ g_object_set (G_OBJECT (pipeline), "play-timeout", 0LL, NULL);
+
+/*
+ fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
+ GST_STATE_PLAYING), GST_STATE_CHANGE_ASYNC);
+*/
+
+ gst_object_unref (pipeline);
+}
+
+GST_END_TEST;
+
+/* FIXME: this is less of a pathological case, it would make sense
+ * to have it return ASYNC as well */
+GST_START_TEST (test_async_state_change_fake_ready)
+{
+ GstPipeline *pipeline;
+ GstElement *src, *sink;
+
+ pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
+ fail_unless (pipeline != NULL, "Could not create pipeline");
+ g_object_set (G_OBJECT (pipeline), "play-timeout", 0LL, NULL);
+
+ src = gst_element_factory_make ("fakesrc", NULL);
+ sink = gst_element_factory_make ("fakesink", NULL);
+
+ gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
+ gst_element_link (src, sink);
+
+/*
+ fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
+ GST_STATE_READY), GST_STATE_CHANGE_ASYNC);
+*/
+
+ gst_object_unref (pipeline);
+}
+
+GST_END_TEST;
+
+
+#if 0
+GST_START_TEST (test_async_state_change_fake)
+{
+ GstPipeline *pipeline;
+ GstElement *src, *sink;
+ GstBus *bus;
+ GstMessageType type;
+
+ pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
+ fail_unless (pipeline != NULL, "Could not create pipeline");
+ g_object_set (G_OBJECT (pipeline), "play-timeout", 0LL, NULL);
+
+ src = gst_element_factory_make ("fakesrc", NULL);
+ sink = gst_element_factory_make ("fakesink", NULL);
+
+ gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
+ gst_element_link (src, sink);
+
+ bus = gst_pipeline_get_bus (pipeline);
+
+ fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
+ GST_STATE_PLAYING), GST_STATE_CHANGE_ASYNC);
+
+ gst_bin_watch_for_state_change (GST_BIN (pipeline));
+
+ while ((type = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1))) {
+ GstMessage *message;
+ GstState old, new;
+ GstState state, pending;
+ GstStateChange ret;
+ GTimeVal timeval;
+
+ message = gst_bus_pop (bus);
+ gst_message_parse_state_changed (message, &old, &new);
+ GST_DEBUG_OBJECT (message->src, "state change from %d to %d", old, new);
+ g_print ("message\n");
+ g_print ("%s: %d -> %d\n", GST_OBJECT_NAME (message->src), old, new);
+ gst_message_unref (message);
+
+ timeval.tv_sec = 0;
+ timeval.tv_usec = 0;
+ ret = gst_element_get_state (GST_ELEMENT (pipeline), &state, &pending,
+ &timeval);
+ }
+ gst_object_unref (pipeline);
+}
+
+GST_END_TEST;
+#endif
+
+Suite *
+gst_pipeline_suite (void)
+{
+ Suite *s = suite_create ("GstPipeline");
+ TCase *tc_chain = tcase_create ("pipeline tests");
+
+ suite_add_tcase (s, tc_chain);
+ tcase_add_test (tc_chain, test_async_state_change_empty);
+ tcase_add_test (tc_chain, test_async_state_change_fake_ready);
+#if 0
+ tcase_add_test (tc_chain, test_async_state_change_fake);
+#endif
+
+ return s;
+}
+
+int
+main (int argc, char **argv)
+{
+ int nf;
+
+ Suite *s = gst_pipeline_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;
+}