adding an element test

Original commit message from CVS:
adding an element test
This commit is contained in:
Thomas Vander Stichele 2005-07-07 11:59:37 +00:00
parent a1457cff29
commit 48cef19743
11 changed files with 281 additions and 35 deletions

View file

@ -1,3 +1,15 @@
2005-07-07 Thomas Vander Stichele <thomas at apestaart dot org>
* 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 <wingo@pobox.com>
* gst/gstbus.c (gst_bus_have_pending): Remove intensely irritating
@ -112,7 +124,7 @@
2005-07-05 Stefan Kost <ensonic@users.sf.net>
* Makefile.am:
better report genration target (lcov needs a patch)
better report generation target (lcov needs a patch)
2005-07-05 Andy Wingo <wingo@pobox.com>

View file

@ -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 \

2
check/elements/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.dirstamp
gstfakesrc

127
check/elements/gstfakesrc.c Normal file
View file

@ -0,0 +1,127 @@
/* GStreamer
*
* unit test for fakesrc
*
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
*
* 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 <unistd.h>
#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;
}

View file

@ -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;

View file

@ -79,7 +79,6 @@ struct _GstFakeSrc {
/*< private >*/
gboolean has_loop;
gboolean has_getrange;
gboolean eos;
GstFakeSrcOutputType output;
GstFakeSrcDataType data;

View file

@ -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;

View file

@ -79,7 +79,6 @@ struct _GstFakeSrc {
/*< private >*/
gboolean has_loop;
gboolean has_getrange;
gboolean eos;
GstFakeSrcOutputType output;
GstFakeSrcDataType data;

View file

@ -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 \

2
tests/check/elements/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.dirstamp
gstfakesrc

View file

@ -0,0 +1,127 @@
/* GStreamer
*
* unit test for fakesrc
*
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
*
* 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 <unistd.h>
#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;
}