From ffa9f04bb2072c0a257cbb50177dd208b9ea367b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Mon, 18 Jul 2016 17:26:26 +0100 Subject: [PATCH] tests: appsink: add minimal test for new pull with timeout functions https://bugzilla.gnome.org/show_bug.cgi?id=768852 --- tests/check/elements/appsink.c | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/check/elements/appsink.c b/tests/check/elements/appsink.c index 1c9feed..aabeb00 100644 --- a/tests/check/elements/appsink.c +++ b/tests/check/elements/appsink.c @@ -348,6 +348,68 @@ GST_START_TEST (test_segment) GST_END_TEST; +GST_START_TEST (test_pull_with_timeout) +{ + GstElement *sink; + GstBuffer *buffer; + GstSample *s; + guint64 t1, tdiff; + + sink = setup_appsink (); + + ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); + + /* Check that it actually waits for a bit */ + t1 = gst_util_get_timestamp (); + s = gst_app_sink_try_pull_preroll (GST_APP_SINK (sink), GST_SECOND / 20); + tdiff = gst_util_get_timestamp () - t1; + GST_LOG ("tdiff: %" GST_TIME_FORMAT, GST_TIME_ARGS (tdiff)); + fail_unless (s == NULL); + fail_unless (tdiff > (GST_SECOND / (20 * 2))); + + buffer = gst_buffer_new_and_alloc (4); + fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); + + s = gst_app_sink_try_pull_preroll (GST_APP_SINK (sink), GST_SECOND / 20); + fail_unless (s != NULL); + gst_sample_unref (s); + + s = gst_app_sink_try_pull_sample (GST_APP_SINK (sink), 500 * GST_SECOND); + fail_unless (s != NULL); + gst_sample_unref (s); + + /* No waiting */ + s = gst_app_sink_try_pull_sample (GST_APP_SINK (sink), 0); + fail_unless (s == NULL); + + /* Check that it actually waits for a bit */ + t1 = gst_util_get_timestamp (); + s = gst_app_sink_try_pull_sample (GST_APP_SINK (sink), GST_SECOND / 20); + tdiff = gst_util_get_timestamp () - t1; + GST_LOG ("tdiff: %" GST_TIME_FORMAT, GST_TIME_ARGS (tdiff)); + fail_unless (s == NULL); + fail_unless (tdiff > (GST_SECOND / (20 * 2))); + + /* No waiting, with buffer pending */ + buffer = gst_buffer_new_and_alloc (5); + fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); + s = gst_app_sink_try_pull_sample (GST_APP_SINK (sink), 0); + fail_unless (s != NULL); + gst_sample_unref (s); + + /* With timeout, with buffer pending */ + buffer = gst_buffer_new_and_alloc (6); + fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); + s = gst_app_sink_try_pull_sample (GST_APP_SINK (sink), GST_SECOND / 20); + fail_unless (s != NULL); + gst_sample_unref (s); + + ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); + cleanup_appsink (sink); +} + +GST_END_TEST; + static Suite * appsink_suite (void) { @@ -362,6 +424,7 @@ appsink_suite (void) tcase_add_test (tc_chain, test_buffer_list_fallback); tcase_add_test (tc_chain, test_buffer_list_fallback_signal); tcase_add_test (tc_chain, test_segment); + tcase_add_test (tc_chain, test_pull_with_timeout); return s; } -- 2.7.4