summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-05-13 16:48:38 +0200
committerWim Taymans <wim.taymans@collabora.co.uk>2009-05-13 16:48:38 +0200
commit0d9ba7c7fe7e18f492dee6deb1a3d74b6de39396 (patch)
treee76b90ddabdbd27ff9e9ccc9563ba7e5afa22145
parentbf8cbbc74df8adcb7cdc2d04facedb4f1f279072 (diff)
tests: add new timestamp unit test
-rw-r--r--tests/check/libs/adapter.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/tests/check/libs/adapter.c b/tests/check/libs/adapter.c
index 41924c7fa2..96305d6d57 100644
--- a/tests/check/libs/adapter.c
+++ b/tests/check/libs/adapter.c
@@ -282,6 +282,123 @@ GST_START_TEST (test_take_buf_order)
GST_END_TEST;
+GST_START_TEST (test_timestamp)
+{
+ GstAdapter *adapter;
+ GstBuffer *buffer;
+ guint avail;
+ GstClockTime timestamp;
+ guint64 dist;
+
+ adapter = gst_adapter_new ();
+ fail_unless (adapter != NULL);
+
+ buffer = gst_buffer_new_and_alloc (100);
+
+ /* push in the adapter */
+ gst_adapter_push (adapter, buffer);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 100);
+
+ /* timestamp is now undefined */
+ timestamp = gst_adapter_prev_timestamp (adapter, &dist);
+ fail_unless (timestamp == GST_CLOCK_TIME_NONE);
+ fail_unless (dist == 0);
+
+ gst_adapter_flush (adapter, 50);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 50);
+
+ /* still undefined, dist changed, though */
+ timestamp = gst_adapter_prev_timestamp (adapter, &dist);
+ fail_unless (timestamp == GST_CLOCK_TIME_NONE);
+ fail_unless (dist == 50);
+
+ buffer = gst_buffer_new_and_alloc (100);
+ GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
+
+ /* push in the adapter */
+ gst_adapter_push (adapter, buffer);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 150);
+
+ /* timestamp is still undefined */
+ timestamp = gst_adapter_prev_timestamp (adapter, &dist);
+ fail_unless (timestamp == GST_CLOCK_TIME_NONE);
+ fail_unless (dist == 50);
+
+ /* flush out first buffer we are now at the second buffer timestamp */
+ gst_adapter_flush (adapter, 50);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 100);
+
+ timestamp = gst_adapter_prev_timestamp (adapter, &dist);
+ fail_unless (timestamp == 1 * GST_SECOND);
+ fail_unless (dist == 0);
+
+ /* move some more, still the same timestamp but further away */
+ gst_adapter_flush (adapter, 50);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 50);
+
+ timestamp = gst_adapter_prev_timestamp (adapter, &dist);
+ fail_unless (timestamp == 1 * GST_SECOND);
+ fail_unless (dist == 50);
+
+ /* push a buffer without timestamp in the adapter */
+ buffer = gst_buffer_new_and_alloc (100);
+ gst_adapter_push (adapter, buffer);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 150);
+ /* push a buffer with timestamp in the adapter */
+ buffer = gst_buffer_new_and_alloc (100);
+ GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND;
+ gst_adapter_push (adapter, buffer);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 250);
+
+ /* timestamp still as it was before the push */
+ timestamp = gst_adapter_prev_timestamp (adapter, &dist);
+ fail_unless (timestamp == 1 * GST_SECOND);
+ fail_unless (dist == 50);
+
+ /* flush away buffer with the timestamp */
+ gst_adapter_flush (adapter, 50);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 200);
+ timestamp = gst_adapter_prev_timestamp (adapter, &dist);
+ fail_unless (timestamp == 1 * GST_SECOND);
+ fail_unless (dist == 100);
+
+ /* move into the second buffer */
+ gst_adapter_flush (adapter, 50);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 150);
+ timestamp = gst_adapter_prev_timestamp (adapter, &dist);
+ fail_unless (timestamp == 1 * GST_SECOND);
+ fail_unless (dist == 150);
+
+ /* move to third buffer we move to the new timestamp */
+ gst_adapter_flush (adapter, 50);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 100);
+ timestamp = gst_adapter_prev_timestamp (adapter, &dist);
+ fail_unless (timestamp == 2 * GST_SECOND);
+ fail_unless (dist == 0);
+
+ /* move everything out */
+ gst_adapter_flush (adapter, 100);
+ avail = gst_adapter_available (adapter);
+ fail_unless (avail == 0);
+ timestamp = gst_adapter_prev_timestamp (adapter, &dist);
+ fail_unless (timestamp == 2 * GST_SECOND);
+ fail_unless (dist == 100);
+
+ g_object_unref (adapter);
+}
+
+GST_END_TEST;
+
static Suite *
gst_adapter_suite (void)
{
@@ -297,6 +414,7 @@ gst_adapter_suite (void)
tcase_add_test (tc_chain, test_take3);
tcase_add_test (tc_chain, test_take_order);
tcase_add_test (tc_chain, test_take_buf_order);
+ tcase_add_test (tc_chain, test_timestamp);
return s;
}