diff --git a/ChangeLog b/ChangeLog index f1b4f1ba52..aa6aca0b73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-07-07 Thomas Vander Stichele + + * check/Makefile.am: + * check/elements/.cvsignore: + * check/elements/gstfakesrc.c: (chain_func), (event_func), + (START_TEST), (fakesrc_suite), (main): + * gst/elements/gstfakesrc.c: (gst_fakesrc_class_init), + (gst_fakesrc_set_property), (gst_fakesrc_get_property), + (gst_fakesrc_create), (gst_fakesrc_start): + * gst/elements/gstfakesrc.h: + adding a first element test + 2005-07-07 Andy Wingo * gst/gstbus.c (gst_bus_have_pending): Remove intensely irritating @@ -112,7 +124,7 @@ 2005-07-05 Stefan Kost * Makefile.am: - better report genration target (lcov needs a patch) + better report generation target (lcov needs a patch) 2005-07-05 Andy Wingo diff --git a/check/Makefile.am b/check/Makefile.am index 98e719687e..4cfbc17aa0 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -37,6 +37,7 @@ TESTS = $(top_builddir)/tools/gst-register \ gst/gststructure \ gst/gsttag \ gst/gstvalue \ + elements/gstfakesrc \ pipelines/simple_launch_lines \ pipelines/cleanup \ states/sinks \ diff --git a/check/elements/.gitignore b/check/elements/.gitignore new file mode 100644 index 0000000000..a10e4f5188 --- /dev/null +++ b/check/elements/.gitignore @@ -0,0 +1,2 @@ +.dirstamp +gstfakesrc diff --git a/check/elements/gstfakesrc.c b/check/elements/gstfakesrc.c new file mode 100644 index 0000000000..e5a400afde --- /dev/null +++ b/check/elements/gstfakesrc.c @@ -0,0 +1,127 @@ +/* GStreamer + * + * unit test for fakesrc + * + * Copyright (C) <2005> Thomas Vander Stichele + * + * 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 + +#include "../gstcheck.h" + +GList *buffers = NULL; +gboolean have_eos = FALSE; + +static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + +GstFlowReturn +chain_func (GstPad * pad, GstBuffer * buffer) +{ + buffers = g_list_append (buffers, buffer); + + return GST_FLOW_OK; +} + +gboolean +event_func (GstPad * pad, GstEvent * event) +{ + if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) { + /* we take the lock here because it's good practice to so, even though + * no buffers will be pushed anymore anyway */ + GST_STREAM_LOCK (pad); + have_eos = TRUE; + GST_STREAM_UNLOCK (pad); + return TRUE; + } + + return FALSE; +} + +START_TEST (test_num_buffers) +{ + GstElement *src; + GstScheduler *scheduler; + GstPad *srcpad, *sinkpad; + + src = gst_element_factory_make ("fakesrc", "src"); + fail_if (src == NULL, "Could not create a fakesrc"); + + sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get (&sinktemplate), + "sink"); + fail_if (sinkpad == NULL, "Could not create a sinkpad"); + + g_object_set (G_OBJECT (src), "num-buffers", 3, NULL); + + scheduler = gst_scheduler_factory_make (NULL, src); + gst_element_set_scheduler (src, scheduler); + + srcpad = gst_element_get_pad (src, "src"); + fail_if (srcpad == NULL, "Could not get source pad from fakesrc"); + gst_pad_set_caps (sinkpad, NULL); + gst_pad_set_chain_function (sinkpad, chain_func); + gst_pad_set_event_function (sinkpad, event_func); + + fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK, + "Could not link source and sink pads"); + + fail_unless (gst_element_set_state (src, + GST_STATE_PLAYING) == GST_STATE_SUCCESS, "could not set to playing"); + + while (!have_eos) { + g_usleep (1000); + } + + fail_unless (g_list_length (buffers) == 3); + g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); + g_list_free (buffers); +} + +END_TEST; + +Suite * +fakesrc_suite (void) +{ + Suite *s = suite_create ("fakesrc"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_num_buffers); + + return s; +} + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = fakesrc_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/elements/gstfakesrc.c b/gst/elements/gstfakesrc.c index 8b33420c9d..8bddf81dfe 100644 --- a/gst/elements/gstfakesrc.c +++ b/gst/elements/gstfakesrc.c @@ -222,9 +222,13 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass) gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_fakesrc_set_property); gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_fakesrc_get_property); +/* + FIXME: this is not implemented; would make sense once basesrc and fakesrc + support multiple pads g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_OUTPUT, g_param_spec_enum ("output", "output", "Output method (currently unused)", GST_TYPE_FAKESRC_OUTPUT, DEFAULT_OUTPUT, G_PARAM_READWRITE)); +*/ g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DATA, g_param_spec_enum ("data", "data", "Data allocation method", GST_TYPE_FAKESRC_DATA, DEFAULT_DATA, G_PARAM_READWRITE)); @@ -260,9 +264,6 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass) g_param_spec_int ("num-buffers", "num-buffers", "Number of buffers to output before sending EOS", -1, G_MAXINT, DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_EOS, - g_param_spec_boolean ("eos", "eos", "Send out the EOS event?", - DEFAULT_EOS, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LAST_MESSAGE, g_param_spec_string ("last-message", "last-message", "The last status message", NULL, G_PARAM_READABLE)); @@ -414,10 +415,6 @@ gst_fakesrc_set_property (GObject * object, guint prop_id, const GValue * value, case PROP_NUM_BUFFERS: src->num_buffers = g_value_get_int (value); break; - case PROP_EOS: - src->eos = g_value_get_boolean (value); - GST_INFO ("will EOS on next buffer"); - break; case PROP_SILENT: src->silent = g_value_get_boolean (value); break; @@ -490,9 +487,6 @@ gst_fakesrc_get_property (GObject * object, guint prop_id, GValue * value, case PROP_NUM_BUFFERS: g_value_set_int (value, src->num_buffers); break; - case PROP_EOS: - g_value_set_boolean (value, src->eos); - break; case PROP_SILENT: g_value_set_boolean (value, src->silent); break; @@ -680,11 +674,6 @@ gst_fakesrc_create (GstBaseSrc * basesrc, guint64 offset, guint length, src->rt_num_buffers--; } - if (src->eos) { - GST_INFO ("fakesrc is setting eos on pad"); - return GST_FLOW_UNEXPECTED; - } - buf = gst_fakesrc_create_buffer (src); GST_BUFFER_OFFSET (buf) = src->buffer_count++; @@ -737,7 +726,6 @@ gst_fakesrc_start (GstBaseSrc * basesrc) src->buffer_count = 0; src->pattern_byte = 0x00; - src->eos = FALSE; src->bytes_sent = 0; src->rt_num_buffers = src->num_buffers; diff --git a/gst/elements/gstfakesrc.h b/gst/elements/gstfakesrc.h index 1c7c288a1b..4b5dc24dcf 100644 --- a/gst/elements/gstfakesrc.h +++ b/gst/elements/gstfakesrc.h @@ -79,7 +79,6 @@ struct _GstFakeSrc { /*< private >*/ gboolean has_loop; gboolean has_getrange; - gboolean eos; GstFakeSrcOutputType output; GstFakeSrcDataType data; diff --git a/plugins/elements/gstfakesrc.c b/plugins/elements/gstfakesrc.c index 8b33420c9d..8bddf81dfe 100644 --- a/plugins/elements/gstfakesrc.c +++ b/plugins/elements/gstfakesrc.c @@ -222,9 +222,13 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass) gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_fakesrc_set_property); gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_fakesrc_get_property); +/* + FIXME: this is not implemented; would make sense once basesrc and fakesrc + support multiple pads g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_OUTPUT, g_param_spec_enum ("output", "output", "Output method (currently unused)", GST_TYPE_FAKESRC_OUTPUT, DEFAULT_OUTPUT, G_PARAM_READWRITE)); +*/ g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DATA, g_param_spec_enum ("data", "data", "Data allocation method", GST_TYPE_FAKESRC_DATA, DEFAULT_DATA, G_PARAM_READWRITE)); @@ -260,9 +264,6 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass) g_param_spec_int ("num-buffers", "num-buffers", "Number of buffers to output before sending EOS", -1, G_MAXINT, DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_EOS, - g_param_spec_boolean ("eos", "eos", "Send out the EOS event?", - DEFAULT_EOS, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LAST_MESSAGE, g_param_spec_string ("last-message", "last-message", "The last status message", NULL, G_PARAM_READABLE)); @@ -414,10 +415,6 @@ gst_fakesrc_set_property (GObject * object, guint prop_id, const GValue * value, case PROP_NUM_BUFFERS: src->num_buffers = g_value_get_int (value); break; - case PROP_EOS: - src->eos = g_value_get_boolean (value); - GST_INFO ("will EOS on next buffer"); - break; case PROP_SILENT: src->silent = g_value_get_boolean (value); break; @@ -490,9 +487,6 @@ gst_fakesrc_get_property (GObject * object, guint prop_id, GValue * value, case PROP_NUM_BUFFERS: g_value_set_int (value, src->num_buffers); break; - case PROP_EOS: - g_value_set_boolean (value, src->eos); - break; case PROP_SILENT: g_value_set_boolean (value, src->silent); break; @@ -680,11 +674,6 @@ gst_fakesrc_create (GstBaseSrc * basesrc, guint64 offset, guint length, src->rt_num_buffers--; } - if (src->eos) { - GST_INFO ("fakesrc is setting eos on pad"); - return GST_FLOW_UNEXPECTED; - } - buf = gst_fakesrc_create_buffer (src); GST_BUFFER_OFFSET (buf) = src->buffer_count++; @@ -737,7 +726,6 @@ gst_fakesrc_start (GstBaseSrc * basesrc) src->buffer_count = 0; src->pattern_byte = 0x00; - src->eos = FALSE; src->bytes_sent = 0; src->rt_num_buffers = src->num_buffers; diff --git a/plugins/elements/gstfakesrc.h b/plugins/elements/gstfakesrc.h index 1c7c288a1b..4b5dc24dcf 100644 --- a/plugins/elements/gstfakesrc.h +++ b/plugins/elements/gstfakesrc.h @@ -79,7 +79,6 @@ struct _GstFakeSrc { /*< private >*/ gboolean has_loop; gboolean has_getrange; - gboolean eos; GstFakeSrcOutputType output; GstFakeSrcDataType data; diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 98e719687e..4cfbc17aa0 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -37,6 +37,7 @@ TESTS = $(top_builddir)/tools/gst-register \ gst/gststructure \ gst/gsttag \ gst/gstvalue \ + elements/gstfakesrc \ pipelines/simple_launch_lines \ pipelines/cleanup \ states/sinks \ diff --git a/tests/check/elements/.gitignore b/tests/check/elements/.gitignore new file mode 100644 index 0000000000..a10e4f5188 --- /dev/null +++ b/tests/check/elements/.gitignore @@ -0,0 +1,2 @@ +.dirstamp +gstfakesrc diff --git a/tests/check/elements/gstfakesrc.c b/tests/check/elements/gstfakesrc.c new file mode 100644 index 0000000000..e5a400afde --- /dev/null +++ b/tests/check/elements/gstfakesrc.c @@ -0,0 +1,127 @@ +/* GStreamer + * + * unit test for fakesrc + * + * Copyright (C) <2005> Thomas Vander Stichele + * + * 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 + +#include "../gstcheck.h" + +GList *buffers = NULL; +gboolean have_eos = FALSE; + +static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + +GstFlowReturn +chain_func (GstPad * pad, GstBuffer * buffer) +{ + buffers = g_list_append (buffers, buffer); + + return GST_FLOW_OK; +} + +gboolean +event_func (GstPad * pad, GstEvent * event) +{ + if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) { + /* we take the lock here because it's good practice to so, even though + * no buffers will be pushed anymore anyway */ + GST_STREAM_LOCK (pad); + have_eos = TRUE; + GST_STREAM_UNLOCK (pad); + return TRUE; + } + + return FALSE; +} + +START_TEST (test_num_buffers) +{ + GstElement *src; + GstScheduler *scheduler; + GstPad *srcpad, *sinkpad; + + src = gst_element_factory_make ("fakesrc", "src"); + fail_if (src == NULL, "Could not create a fakesrc"); + + sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get (&sinktemplate), + "sink"); + fail_if (sinkpad == NULL, "Could not create a sinkpad"); + + g_object_set (G_OBJECT (src), "num-buffers", 3, NULL); + + scheduler = gst_scheduler_factory_make (NULL, src); + gst_element_set_scheduler (src, scheduler); + + srcpad = gst_element_get_pad (src, "src"); + fail_if (srcpad == NULL, "Could not get source pad from fakesrc"); + gst_pad_set_caps (sinkpad, NULL); + gst_pad_set_chain_function (sinkpad, chain_func); + gst_pad_set_event_function (sinkpad, event_func); + + fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK, + "Could not link source and sink pads"); + + fail_unless (gst_element_set_state (src, + GST_STATE_PLAYING) == GST_STATE_SUCCESS, "could not set to playing"); + + while (!have_eos) { + g_usleep (1000); + } + + fail_unless (g_list_length (buffers) == 3); + g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); + g_list_free (buffers); +} + +END_TEST; + +Suite * +fakesrc_suite (void) +{ + Suite *s = suite_create ("fakesrc"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_num_buffers); + + return s; +} + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = fakesrc_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; +}