gstreamer/tests/check/elements/identity.c

200 lines
6 KiB
C
Raw Normal View History

/* GStreamer
*
* unit test for identity
*
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
* Copyright (C) <2015> Havard Graff <havard@pexip.com>
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <gst/check/gstcheck.h>
#include <gst/check/gstharness.h>
GST_START_TEST (test_one_buffer)
{
GstHarness *h = gst_harness_new ("identity");
GstBuffer *buffer_in;
GstBuffer *buffer_out;
gst_harness_set_src_caps_str (h, "mycaps");
buffer_in = gst_buffer_new_and_alloc (4);
ASSERT_BUFFER_REFCOUNT (buffer_in, "buffer", 1);
gst_buffer_fill (buffer_in, 0, "data", 4);
/* pushing gives away my reference ... */
fail_unless_equals_int (GST_FLOW_OK, gst_harness_push (h, buffer_in));
/* ... but it should end up being collected on GstHarness queue */
fail_unless_equals_int (1, gst_harness_buffers_in_queue (h));
buffer_out = gst_harness_pull (h);
fail_unless (buffer_in == buffer_out);
ASSERT_BUFFER_REFCOUNT (buffer_out, "buffer", 1);
/* cleanup */
gst_buffer_unref (buffer_out);
gst_harness_teardown (h);
}
2016-02-19 14:41:55 +00:00
GST_END_TEST;
static void
2016-02-19 14:41:55 +00:00
handoff_func (GstElement * identity, GstBuffer * buf, GstBuffer ** ret)
{
2016-02-19 14:41:55 +00:00
(void) identity;
*ret = buf;
}
GST_START_TEST (test_signal_handoffs)
{
GstHarness *h = gst_harness_new ("identity");
GstBuffer *buffer_in;
GstBuffer *buffer_signaled = NULL;
gst_harness_set_src_caps_str (h, "mycaps");
/* connect to the handoff signal */
g_signal_connect (h->element, "handoff",
G_CALLBACK (handoff_func), &buffer_signaled);
/* first, turn off signal-handoffs */
g_object_set (h->element, "signal-handoffs", FALSE, NULL);
/* then push a buffer */
buffer_in = gst_buffer_new_and_alloc (4);
fail_unless_equals_int (GST_FLOW_OK, gst_harness_push (h, buffer_in));
/* verify that we got no buffer signaled */
fail_unless (buffer_signaled == NULL);
/* now turn on signal-handoffs */
g_object_set (h->element, "signal-handoffs", TRUE, NULL);
/* then push another buffer */
buffer_in = gst_buffer_new_and_alloc (4);
fail_unless_equals_int (GST_FLOW_OK, gst_harness_push (h, buffer_in));
/* verify the buffer signaled is equal to the one pushed in */
fail_unless (buffer_signaled == buffer_in);
ASSERT_BUFFER_REFCOUNT (buffer_signaled, "buffer", 1);
/* cleanup */
gst_harness_teardown (h);
}
2016-02-19 14:41:55 +00:00
GST_END_TEST;
GST_START_TEST (test_sync_on_timestamp)
{
/* the reason to use the queue in front of the identity element
is to effectively make gst_harness_push asynchronous, not locking
up the test, waiting for gst_clock_id_wait */
2016-02-19 14:41:55 +00:00
GstHarness *h = gst_harness_new_parse ("queue ! identity sync=1");
GstBuffer *buf;
GstClock *clock;
GstClockTime timestamp = 123456789;
/* use testclock */
gst_harness_use_testclock (h);
gst_harness_set_src_caps_str (h, "mycaps");
/* make a buffer and set the timestamp */
buf = gst_buffer_new ();
GST_BUFFER_PTS (buf) = timestamp;
/* push the buffer, and verify it does *not* make it through */
gst_harness_push (h, buf);
fail_unless_equals_int (0, gst_harness_buffers_in_queue (h));
/* verify the identity element has registered exactly one GstClockID */
fail_unless (gst_harness_wait_for_clock_id_waits (h, 1, 42));
/* crank the clock and pull the buffer */
gst_harness_crank_single_clock_wait (h);
buf = gst_harness_pull (h);
/* verify that the buffer has the right timestamp, and that the time on
the clock is equal to the timestamp */
fail_unless_equals_int64 (timestamp, GST_BUFFER_PTS (buf));
clock = gst_element_get_clock (h->element);
fail_unless_equals_int64 (timestamp, gst_clock_get_time (clock));
/* cleanup */
gst_object_unref (clock);
gst_buffer_unref (buf);
gst_harness_teardown (h);
}
2016-02-19 14:41:55 +00:00
GST_END_TEST;
GST_START_TEST (test_stopping_element_unschedules_sync)
{
/* the reason to use the queue in front of the identity element
is to effectively make gst_harness_push asynchronous, not locking
up the test, waiting for gst_clock_id_wait */
2016-02-19 14:41:55 +00:00
GstHarness *h = gst_harness_new_parse ("queue ! identity sync=1");
GstBuffer *buf;
GstClockTime timestamp = 123456789;
/* use testclock */
gst_harness_use_testclock (h);
gst_harness_set_src_caps_str (h, "mycaps");
/* make a buffer and set the timestamp */
buf = gst_buffer_new ();
GST_BUFFER_PTS (buf) = timestamp;
/* push the buffer, and verify it does *not* make it through */
gst_harness_push (h, buf);
fail_unless_equals_int (0, gst_harness_buffers_in_queue (h));
2011-03-21 18:15:27 +00:00
/* verify the identity element has registered exactly one GstClockID */
fail_unless (gst_harness_wait_for_clock_id_waits (h, 1, 42));
/* setting identity to READY should unschedule the sync */
gst_element_set_state (h->element, GST_STATE_READY);
/* verify the identity element no longer waits on the clock */
fail_unless (gst_harness_wait_for_clock_id_waits (h, 0, 42));
/* and that the waiting buffer was dropped */
fail_unless_equals_int (0, gst_harness_buffers_received (h));
gst_harness_teardown (h);
}
2016-02-19 14:41:55 +00:00
GST_END_TEST;
And correct even more valid sparse warnings. Original commit message from CVS: * gst/gstelementfactory.h: * tests/check/elements/fakesink.c: * tests/check/elements/fakesrc.c: (setup_fakesrc): * tests/check/elements/fdsrc.c: (setup_fdsrc): * tests/check/elements/filesink.c: (setup_filesink): * tests/check/elements/filesrc.c: (setup_filesrc): * tests/check/elements/identity.c: (setup_identity): * tests/check/elements/tee.c: * tests/check/generic/sinks.c: * tests/check/generic/states.c: (setup), (teardown): * tests/check/gst/gst.c: * tests/check/gst/gstabi.c: * tests/check/gst/gstbin.c: * tests/check/gst/gstbus.c: (pull_messages): * tests/check/gst/gstcaps.c: * tests/check/gst/gstelement.c: * tests/check/gst/gstevent.c: * tests/check/gst/gstghostpad.c: * tests/check/gst/gstiterator.c: * tests/check/gst/gstmessage.c: * tests/check/gst/gstminiobject.c: (my_foo_init): * tests/check/gst/gstobject.c: (thread_name_object), (gst_object_suite): * tests/check/gst/gstpad.c: * tests/check/gst/gstplugin.c: * tests/check/gst/gstpoll.c: * tests/check/gst/gstquery.c: * tests/check/gst/gstsegment.c: * tests/check/gst/gststructure.c: * tests/check/gst/gstsystemclock.c: * tests/check/gst/gsttask.c: * tests/check/gst/gstutils.c: * tests/check/gst/gstvalue.c: * tests/check/gst/struct_hppa.h: * tests/check/gst/struct_i386.h: * tests/check/gst/struct_ppc32.h: * tests/check/gst/struct_ppc64.h: * tests/check/gst/struct_x86_64.h: * tests/check/libs/adapter.c: (create_and_fill_adapter): * tests/check/libs/basesrc.c: * tests/check/libs/controller.c: (GST_START_TEST): * tests/check/libs/gdp.c: * tests/check/libs/gstnetclientclock.c: * tests/check/libs/gstnettimeprovider.c: * tests/check/libs/libsabi.c: * tests/check/libs/struct_hppa.h: * tests/check/libs/struct_i386.h: * tests/check/libs/struct_ppc32.h: * tests/check/libs/struct_ppc64.h: * tests/check/libs/struct_x86_64.h: * tests/check/pipelines/cleanup.c: * tests/check/pipelines/simple-launch-lines.c: * tests/check/pipelines/stress.c: And correct even more valid sparse warnings. * win32/common/libgstreamer.def: Add gst_poll_fd_init to the list of symbols.
2008-02-29 13:59:24 +00:00
static Suite *
identity_suite (void)
{
Suite *s = suite_create ("identity");
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_one_buffer);
tcase_add_test (tc_chain, test_signal_handoffs);
tcase_add_test (tc_chain, test_sync_on_timestamp);
tcase_add_test (tc_chain, test_stopping_element_unschedules_sync);
return s;
}
tests/check/: use the new macro Original commit message from CVS: * tests/check/elements/fakesink.c: * tests/check/elements/fakesrc.c: * tests/check/elements/fdsrc.c: * tests/check/elements/identity.c: * tests/check/generic/sinks.c: (gst_sinks_suite): * tests/check/generic/states.c: * tests/check/gst/gst.c: * tests/check/gst/gstabi.c: * tests/check/gst/gstbin.c: * tests/check/gst/gstbuffer.c: (gst_buffer_suite): * tests/check/gst/gstbus.c: (gst_bus_suite): * tests/check/gst/gstcaps.c: (GST_START_TEST): * tests/check/gst/gstelement.c: * tests/check/gst/gstevent.c: (gst_event_suite): * tests/check/gst/gstghostpad.c: * tests/check/gst/gstiterator.c: (gst_iterator_suite): * tests/check/gst/gstmessage.c: (gst_message_suite): * tests/check/gst/gstminiobject.c: * tests/check/gst/gstobject.c: * tests/check/gst/gstpad.c: * tests/check/gst/gstpipeline.c: * tests/check/gst/gstplugin.c: * tests/check/gst/gstquery.c: (gst_query_suite): * tests/check/gst/gstsegment.c: (gst_segment_suite): * tests/check/gst/gststructure.c: * tests/check/gst/gstsystemclock.c: * tests/check/gst/gsttag.c: * tests/check/gst/gsttask.c: (gst_task_suite): * tests/check/gst/gstutils.c: * tests/check/gst/gstvalue.c: * tests/check/libs/adapter.c: * tests/check/libs/basesrc.c: * tests/check/libs/collectpads.c: * tests/check/libs/controller.c: * tests/check/libs/gdp.c: (gst_dp_suite): * tests/check/libs/gstnetclientclock.c: * tests/check/libs/gstnettimeprovider.c: * tests/check/libs/libsabi.c: (libsabi_suite): * tests/check/libs/typefindhelper.c: * tests/check/pipelines/cleanup.c: * tests/check/pipelines/parse-launch.c: * tests/check/pipelines/simple-launch-lines.c: * tests/check/pipelines/stress.c: (stress_suite): use the new macro
2006-07-01 20:56:56 +00:00
GST_CHECK_MAIN (identity);