2005-07-08 16:41:45 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
|
|
|
|
*
|
|
|
|
* gstelement.c: Unit test for GstElement
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2005-08-20 12:14:28 +00:00
|
|
|
#include <gst/check/gstcheck.h>
|
2005-07-08 16:41:45 +00:00
|
|
|
|
2005-07-09 16:36:18 +00:00
|
|
|
GST_START_TEST (test_add_remove_pad)
|
2005-07-08 16:41:45 +00:00
|
|
|
{
|
|
|
|
GstElement *e;
|
|
|
|
GstPad *p;
|
|
|
|
|
|
|
|
/* getting an existing element class is cheating, but easier */
|
|
|
|
e = gst_element_factory_make ("fakesrc", "source");
|
|
|
|
|
|
|
|
/* create a new floating pad with refcount 1 */
|
|
|
|
p = gst_pad_new ("source", GST_PAD_SRC);
|
|
|
|
ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
|
|
|
|
/* ref it for ourselves */
|
|
|
|
gst_object_ref (p);
|
|
|
|
ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
|
|
|
|
/* adding it sinks the pad -> not floating, same refcount */
|
|
|
|
gst_element_add_pad (e, p);
|
|
|
|
ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
|
|
|
|
|
|
|
|
/* removing it reduces the refcount */
|
|
|
|
gst_element_remove_pad (e, p);
|
|
|
|
ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
|
|
|
|
|
|
|
|
/* clean up our own reference */
|
|
|
|
gst_object_unref (p);
|
2006-01-28 00:59:37 +00:00
|
|
|
gst_object_unref (e);
|
2005-07-08 16:41:45 +00:00
|
|
|
}
|
|
|
|
|
2005-07-09 16:36:18 +00:00
|
|
|
GST_END_TEST;
|
2005-07-08 16:41:45 +00:00
|
|
|
|
2005-07-09 16:36:18 +00:00
|
|
|
GST_START_TEST (test_add_pad_unref_element)
|
2005-07-09 15:18:53 +00:00
|
|
|
{
|
|
|
|
GstElement *e;
|
|
|
|
GstPad *p;
|
|
|
|
|
|
|
|
/* getting an existing element class is cheating, but easier */
|
|
|
|
e = gst_element_factory_make ("fakesrc", "source");
|
|
|
|
|
|
|
|
/* create a new floating pad with refcount 1 */
|
|
|
|
p = gst_pad_new ("source", GST_PAD_SRC);
|
|
|
|
ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
|
|
|
|
/* ref it for ourselves */
|
|
|
|
gst_object_ref (p);
|
|
|
|
ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
|
|
|
|
/* adding it sinks the pad -> not floating, same refcount */
|
|
|
|
gst_element_add_pad (e, p);
|
|
|
|
ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
|
|
|
|
|
|
|
|
/* unreffing the element should clean it up */
|
|
|
|
gst_object_unref (GST_OBJECT (e));
|
|
|
|
|
|
|
|
ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
|
|
|
|
|
|
|
|
/* clean up our own reference */
|
|
|
|
gst_object_unref (p);
|
|
|
|
}
|
|
|
|
|
2005-07-09 16:36:18 +00:00
|
|
|
GST_END_TEST;
|
2005-07-09 15:18:53 +00:00
|
|
|
|
2005-07-12 16:28:36 +00:00
|
|
|
GST_START_TEST (test_error_no_bus)
|
|
|
|
{
|
|
|
|
GstElement *e;
|
2006-08-28 08:35:31 +00:00
|
|
|
GstBus *bus;
|
2005-07-12 16:28:36 +00:00
|
|
|
|
|
|
|
e = gst_element_factory_make ("fakesrc", "source");
|
|
|
|
|
2006-08-28 08:35:31 +00:00
|
|
|
/* get the bus, should be NULL */
|
|
|
|
bus = gst_element_get_bus (e);
|
|
|
|
fail_if (bus != NULL);
|
|
|
|
|
2005-07-12 16:28:36 +00:00
|
|
|
/* I don't want errors shown */
|
|
|
|
gst_debug_set_default_threshold (GST_LEVEL_NONE);
|
|
|
|
|
|
|
|
GST_ELEMENT_ERROR (e, RESOURCE, OPEN_READ, ("I could not read"), ("debug"));
|
|
|
|
|
|
|
|
gst_object_unref (e);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
2005-07-09 15:18:53 +00:00
|
|
|
|
2005-10-05 21:34:42 +00:00
|
|
|
/* link and run two elements without putting them in a pipeline */
|
2005-07-28 15:38:46 +00:00
|
|
|
GST_START_TEST (test_link)
|
|
|
|
{
|
|
|
|
GstElement *src, *sink;
|
|
|
|
|
|
|
|
src = gst_element_factory_make ("fakesrc", "source");
|
|
|
|
sink = gst_element_factory_make ("fakesink", "sink");
|
|
|
|
|
|
|
|
fail_unless (gst_element_link_pads (src, "src", sink, "sink"));
|
|
|
|
|
|
|
|
/* do sink to source state change */
|
|
|
|
gst_element_set_state (sink, GST_STATE_PAUSED);
|
|
|
|
gst_element_set_state (src, GST_STATE_PAUSED);
|
|
|
|
|
|
|
|
/* wait for preroll */
|
Use GstClockTime in _get_state() instead of GTimeVal.
Original commit message from CVS:
* check/gst/gstbin.c: (GST_START_TEST):
* check/gst/gstelement.c: (GST_START_TEST):
* check/gst/gstevent.c: (GST_START_TEST), (test_event):
* check/gst/gstghostpad.c: (GST_START_TEST):
* check/gst/gstpipeline.c: (GST_START_TEST):
* check/pipelines/simple_launch_lines.c: (run_pipeline):
* check/states/sinks.c: (GST_START_TEST):
* gst/elements/gsttypefindelement.c: (stop_typefinding):
* gst/gstbin.c: (gst_bin_provide_clock_func), (gst_bin_add_func),
(gst_bin_remove_func), (gst_bin_get_state_func),
(gst_bin_recalc_state), (gst_bin_change_state_func),
(bin_bus_handler):
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_get_state), (gst_element_abort_state),
(gst_element_commit_state), (gst_element_set_state),
(gst_element_change_state), (gst_element_change_state_func):
* gst/gstelement.h:
* gst/gstpipeline.c: (gst_pipeline_class_init), (do_pipeline_seek),
(gst_pipeline_provide_clock_func):
* gst/gstutils.c: (gst_element_link_pads_filtered):
* tools/gst-launch.c: (main):
* tools/gst-typefind.c: (main):
Use GstClockTime in _get_state() instead of GTimeVal.
Remove old code in gstutils.c
2005-10-12 12:18:48 +00:00
|
|
|
gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
|
2005-07-28 15:38:46 +00:00
|
|
|
|
|
|
|
/* play some more */
|
|
|
|
gst_element_set_state (sink, GST_STATE_PLAYING);
|
|
|
|
gst_element_set_state (src, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
g_usleep (G_USEC_PER_SEC);
|
|
|
|
|
|
|
|
/* and stop */
|
|
|
|
gst_element_set_state (sink, GST_STATE_PAUSED);
|
|
|
|
gst_element_set_state (src, GST_STATE_PAUSED);
|
|
|
|
|
|
|
|
/* wait for preroll */
|
Use GstClockTime in _get_state() instead of GTimeVal.
Original commit message from CVS:
* check/gst/gstbin.c: (GST_START_TEST):
* check/gst/gstelement.c: (GST_START_TEST):
* check/gst/gstevent.c: (GST_START_TEST), (test_event):
* check/gst/gstghostpad.c: (GST_START_TEST):
* check/gst/gstpipeline.c: (GST_START_TEST):
* check/pipelines/simple_launch_lines.c: (run_pipeline):
* check/states/sinks.c: (GST_START_TEST):
* gst/elements/gsttypefindelement.c: (stop_typefinding):
* gst/gstbin.c: (gst_bin_provide_clock_func), (gst_bin_add_func),
(gst_bin_remove_func), (gst_bin_get_state_func),
(gst_bin_recalc_state), (gst_bin_change_state_func),
(bin_bus_handler):
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_get_state), (gst_element_abort_state),
(gst_element_commit_state), (gst_element_set_state),
(gst_element_change_state), (gst_element_change_state_func):
* gst/gstelement.h:
* gst/gstpipeline.c: (gst_pipeline_class_init), (do_pipeline_seek),
(gst_pipeline_provide_clock_func):
* gst/gstutils.c: (gst_element_link_pads_filtered):
* tools/gst-launch.c: (main):
* tools/gst-typefind.c: (main):
Use GstClockTime in _get_state() instead of GTimeVal.
Remove old code in gstutils.c
2005-10-12 12:18:48 +00:00
|
|
|
gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
|
2005-07-28 15:38:46 +00:00
|
|
|
|
|
|
|
gst_element_set_state (sink, GST_STATE_NULL);
|
|
|
|
gst_element_set_state (src, GST_STATE_NULL);
|
2006-01-14 14:12:26 +00:00
|
|
|
|
2006-01-28 00:59:37 +00:00
|
|
|
gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
|
|
g_usleep (G_USEC_PER_SEC / 2);
|
|
|
|
|
2006-01-14 14:12:26 +00:00
|
|
|
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
|
|
|
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
|
|
|
gst_element_unlink_pads (src, "src", sink, "sink");
|
|
|
|
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
|
|
|
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
2006-01-28 00:59:37 +00:00
|
|
|
|
|
|
|
gst_object_unref (src);
|
|
|
|
gst_object_unref (sink);
|
2005-07-28 15:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2005-10-05 21:34:42 +00:00
|
|
|
/* linking two elements without pads should fail */
|
|
|
|
GST_START_TEST (test_link_no_pads)
|
|
|
|
{
|
|
|
|
GstElement *src, *sink;
|
|
|
|
|
|
|
|
src = gst_bin_new ("src");
|
|
|
|
sink = gst_bin_new ("sink");
|
|
|
|
|
|
|
|
fail_if (gst_element_link (src, sink));
|
|
|
|
|
|
|
|
gst_object_unref (src);
|
|
|
|
gst_object_unref (sink);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2006-04-11 11:47:39 +00:00
|
|
|
|
2008-02-29 13:59:24 +00:00
|
|
|
static Suite *
|
2005-07-08 16:41:45 +00:00
|
|
|
gst_element_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("GstElement");
|
|
|
|
TCase *tc_chain = tcase_create ("element tests");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
2005-07-09 15:18:53 +00:00
|
|
|
tcase_add_test (tc_chain, test_add_remove_pad);
|
|
|
|
tcase_add_test (tc_chain, test_add_pad_unref_element);
|
2005-07-12 16:28:36 +00:00
|
|
|
tcase_add_test (tc_chain, test_error_no_bus);
|
2005-07-28 15:38:46 +00:00
|
|
|
tcase_add_test (tc_chain, test_link);
|
2005-10-05 21:34:42 +00:00
|
|
|
tcase_add_test (tc_chain, test_link_no_pads);
|
2005-07-08 16:41:45 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2006-07-01 20:56:56 +00:00
|
|
|
GST_CHECK_MAIN (gst_element);
|