tests: cleanup libs/audio test
authorStefan Sauer <ensonic@users.sf.net>
Sat, 15 Oct 2016 19:30:22 +0000 (21:30 +0200)
committerStefan Sauer <ensonic@users.sf.net>
Sat, 15 Oct 2016 19:32:33 +0000 (21:32 +0200)
Split large tests into small tests and name them specifically. Use helpers to
avoid repetition. Make sure the order in the file is the same as we add the to
the suite.

tests/check/libs/audio.c

index e19fd62..95b4600 100644 (file)
 #include <gst/audio/audio.h>
 #include <string.h>
 
-GST_START_TEST (test_buffer_clipping_time)
+static GstBuffer *
+make_buffer (guint8 ** _data)
+{
+  GstBuffer *buf = gst_buffer_new ();
+  guint8 *data = (guint8 *) g_malloc (1000);
+
+  gst_buffer_append_memory (buf,
+      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
+  if (_data)
+    *_data = data;
+  return buf;
+}
+
+static void
+setup_segment (GstSegment * s, GstFormat fmt, guint64 start, guint64 stop,
+    guint64 stream_time)
+{
+  gst_segment_init (s, fmt);
+  s->start = start;
+  s->stop = stop;
+  s->time = stream_time;
+}
+
+GST_START_TEST (test_buffer_clip_unsupported_format)
+{
+  GstSegment s;
+  GstBuffer *buf;
+  guint8 *data;
+
+  /* If the format is not TIME or DEFAULT it should assert()
+   * FIXME: check if return value is the same as the input buffer.
+   *        probably can't be done because the assert() does a SIGABRT.
+   */
+  buf = make_buffer (&data);
+  setup_segment (&s, GST_FORMAT_PERCENT, 0, 10, 0);
+
+  GST_BUFFER_TIMESTAMP (buf) = 0 * GST_SECOND;
+  GST_BUFFER_DURATION (buf) = 0;
+  GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE;
+  GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE;
+
+  ASSERT_CRITICAL (gst_audio_buffer_clip (buf, &s, 100, 1));
+
+  gst_buffer_unref (buf);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_buffer_clip_time_start_and_stop)
 {
   GstSegment s;
   GstBuffer *buf;
@@ -39,15 +87,9 @@ GST_START_TEST (test_buffer_clipping_time)
   guint8 *data;
 
   /* Clip start and end */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
-
-  gst_segment_init (&s, GST_FORMAT_TIME);
-  s.start = 4 * GST_SECOND;
-  s.stop = 8 * GST_SECOND;
-  s.time = 4 * GST_SECOND;
+  buf = make_buffer (&data);
+  setup_segment (&s, GST_FORMAT_TIME, 4 * GST_SECOND, 8 * GST_SECOND,
+      4 * GST_SECOND);
 
   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = 10 * GST_SECOND;
@@ -67,17 +109,22 @@ GST_START_TEST (test_buffer_clipping_time)
   gst_buffer_unmap (ret, &map);
 
   gst_buffer_unref (ret);
+}
 
-  /* Clip only start */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
+GST_END_TEST;
+
+GST_START_TEST (test_buffer_clip_time_start)
+{
+  GstSegment s;
+  GstBuffer *buf;
+  GstBuffer *ret;
+  GstMapInfo map;
+  guint8 *data;
 
-  gst_segment_init (&s, GST_FORMAT_TIME);
-  s.start = 4 * GST_SECOND;
-  s.stop = 12 * GST_SECOND;
-  s.time = 4 * GST_SECOND;
+  /* Clip only start */
+  buf = make_buffer (&data);
+  setup_segment (&s, GST_FORMAT_TIME, 4 * GST_SECOND, 12 * GST_SECOND,
+      4 * GST_SECOND);
 
   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = 10 * GST_SECOND;
@@ -97,17 +144,22 @@ GST_START_TEST (test_buffer_clipping_time)
   gst_buffer_unmap (ret, &map);
 
   gst_buffer_unref (ret);
+}
 
-  /* Clip only stop */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
+GST_END_TEST;
 
-  gst_segment_init (&s, GST_FORMAT_TIME);
-  s.start = 2 * GST_SECOND;
-  s.stop = 10 * GST_SECOND;
-  s.time = 2 * GST_SECOND;
+GST_START_TEST (test_buffer_clip_time_stop)
+{
+  GstSegment s;
+  GstBuffer *buf;
+  GstBuffer *ret;
+  GstMapInfo map;
+  guint8 *data;
+
+  /* Clip only stop */
+  buf = make_buffer (&data);
+  setup_segment (&s, GST_FORMAT_TIME, 2 * GST_SECOND, 10 * GST_SECOND,
+      2 * GST_SECOND);
 
   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = 10 * GST_SECOND;
@@ -127,17 +179,20 @@ GST_START_TEST (test_buffer_clipping_time)
   gst_buffer_unmap (ret, &map);
 
   gst_buffer_unref (ret);
+}
 
-  /* Buffer outside segment */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
+GST_END_TEST;
 
-  gst_segment_init (&s, GST_FORMAT_TIME);
-  s.start = 12 * GST_SECOND;
-  s.stop = 20 * GST_SECOND;
-  s.time = 12 * GST_SECOND;
+GST_START_TEST (test_buffer_clip_time_outside)
+{
+  GstSegment s;
+  GstBuffer *buf;
+  GstBuffer *ret;
+
+  /* Buffer outside segment */
+  buf = make_buffer (NULL);
+  setup_segment (&s, GST_FORMAT_TIME, 12 * GST_SECOND, 20 * GST_SECOND,
+      12 * GST_SECOND);
 
   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = 10 * GST_SECOND;
@@ -146,17 +201,22 @@ GST_START_TEST (test_buffer_clipping_time)
 
   ret = gst_audio_buffer_clip (buf, &s, 100, 1);
   fail_unless (ret == NULL);
+}
 
-  /* Clip start and end but don't touch duration and offset_end */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
+GST_END_TEST;
+
+GST_START_TEST (test_buffer_clip_time_start_and_stop_no_meta)
+{
+  GstSegment s;
+  GstBuffer *buf;
+  GstBuffer *ret;
+  GstMapInfo map;
+  guint8 *data;
 
-  gst_segment_init (&s, GST_FORMAT_TIME);
-  s.start = 4 * GST_SECOND;
-  s.stop = 8 * GST_SECOND;
-  s.time = 4 * GST_SECOND;
+  /* Clip start and end but don't touch duration and offset_end */
+  buf = make_buffer (&data);
+  setup_segment (&s, GST_FORMAT_TIME, 4 * GST_SECOND, 8 * GST_SECOND,
+      4 * GST_SECOND);
 
   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = GST_CLOCK_TIME_NONE;
@@ -176,20 +236,23 @@ GST_START_TEST (test_buffer_clipping_time)
   gst_buffer_unmap (ret, &map);
 
   gst_buffer_unref (ret);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_buffer_clip_time_no_timestamp)
+{
+  GstSegment s;
+  GstBuffer *buf;
+  GstBuffer *ret;
 
   /* If the buffer has no timestamp it should assert()
    * FIXME: check if return value is the same as the input buffer.
    *        probably can't be done because the assert() does a SIGABRT.
    */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
-
-  gst_segment_init (&s, GST_FORMAT_TIME);
-  s.start = 0 * GST_SECOND;
-  s.stop = 10 * GST_SECOND;
-  s.time = 0 * GST_SECOND;
+  buf = make_buffer (NULL);
+  setup_segment (&s, GST_FORMAT_TIME, 0 * GST_SECOND, 10 * GST_SECOND,
+      0 * GST_SECOND);
 
   GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE;
   GST_BUFFER_DURATION (buf) = GST_CLOCK_TIME_NONE;
@@ -200,35 +263,11 @@ GST_START_TEST (test_buffer_clipping_time)
   fail_unless (ret == buf);
 
   gst_buffer_unref (buf);
-
-  /* If the format is not TIME or DEFAULT it should assert()
-   * FIXME: check if return value is the same as the input buffer.
-   *        probably can't be done because the assert() does a SIGABRT.
-   */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
-
-  gst_segment_init (&s, GST_FORMAT_PERCENT);
-  s.start = 0;
-  s.stop = 10;
-  s.time = 0;
-
-  GST_BUFFER_TIMESTAMP (buf) = 0 * GST_SECOND;
-  GST_BUFFER_DURATION (buf) = 0;
-  GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE;
-  GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE;
-
-  ASSERT_CRITICAL (ret = gst_audio_buffer_clip (buf, &s, 100, 1));
-
-  gst_buffer_unref (buf);
-
 }
 
 GST_END_TEST;
 
-GST_START_TEST (test_buffer_clipping_samples)
+GST_START_TEST (test_buffer_clip_samples_start_and_stop)
 {
   GstSegment s;
   GstBuffer *buf;
@@ -237,15 +276,8 @@ GST_START_TEST (test_buffer_clipping_samples)
   guint8 *data;
 
   /* Clip start and end */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
-
-  gst_segment_init (&s, GST_FORMAT_DEFAULT);
-  s.start = 400;
-  s.stop = 800;
-  s.time = 400;
+  buf = make_buffer (&data);
+  setup_segment (&s, GST_FORMAT_DEFAULT, 400, 800, 400);
 
   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = 10 * GST_SECOND;
@@ -265,17 +297,21 @@ GST_START_TEST (test_buffer_clipping_samples)
   gst_buffer_unmap (ret, &map);
 
   gst_buffer_unref (ret);
+}
 
-  /* Clip only start */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
+GST_END_TEST;
+
+GST_START_TEST (test_buffer_clip_samples_start)
+{
+  GstSegment s;
+  GstBuffer *buf;
+  GstBuffer *ret;
+  GstMapInfo map;
+  guint8 *data;
 
-  gst_segment_init (&s, GST_FORMAT_DEFAULT);
-  s.start = 400;
-  s.stop = 1200;
-  s.time = 400;
+  /* Clip only start */
+  buf = make_buffer (&data);
+  setup_segment (&s, GST_FORMAT_DEFAULT, 400, 1200, 400);
 
   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = 10 * GST_SECOND;
@@ -295,17 +331,21 @@ GST_START_TEST (test_buffer_clipping_samples)
   gst_buffer_unmap (ret, &map);
 
   gst_buffer_unref (ret);
+}
 
-  /* Clip only stop */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
+GST_END_TEST;
+
+GST_START_TEST (test_buffer_clip_samples_stop)
+{
+  GstSegment s;
+  GstBuffer *buf;
+  GstBuffer *ret;
+  GstMapInfo map;
+  guint8 *data;
 
-  gst_segment_init (&s, GST_FORMAT_DEFAULT);
-  s.start = 200;
-  s.stop = 1000;
-  s.time = 200;
+  /* Clip only stop */
+  buf = make_buffer (&data);
+  setup_segment (&s, GST_FORMAT_DEFAULT, 200, 1000, 200);
 
   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = 10 * GST_SECOND;
@@ -325,17 +365,19 @@ GST_START_TEST (test_buffer_clipping_samples)
   gst_buffer_unmap (ret, &map);
 
   gst_buffer_unref (ret);
+}
 
-  /* Buffer outside segment */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
+GST_END_TEST;
 
-  gst_segment_init (&s, GST_FORMAT_DEFAULT);
-  s.start = 1200;
-  s.stop = 2000;
-  s.time = 1200;
+GST_START_TEST (test_buffer_clip_samples_outside)
+{
+  GstSegment s;
+  GstBuffer *buf;
+  GstBuffer *ret;
+
+  /* Buffer outside segment */
+  buf = make_buffer (NULL);
+  setup_segment (&s, GST_FORMAT_DEFAULT, 1200, 2000, 1200);
 
   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = 10 * GST_SECOND;
@@ -344,17 +386,21 @@ GST_START_TEST (test_buffer_clipping_samples)
 
   ret = gst_audio_buffer_clip (buf, &s, 100, 1);
   fail_unless (ret == NULL);
+}
 
-  /* Clip start and end but don't touch duration and offset_end */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
+GST_END_TEST;
 
-  gst_segment_init (&s, GST_FORMAT_DEFAULT);
-  s.start = 400;
-  s.stop = 800;
-  s.time = 400;
+GST_START_TEST (test_buffer_clip_samples_start_and_stop_no_meta)
+{
+  GstSegment s;
+  GstBuffer *buf;
+  GstBuffer *ret;
+  GstMapInfo map;
+  guint8 *data;
+
+  /* Clip start and end but don't touch duration and offset_end */
+  buf = make_buffer (&data);
+  setup_segment (&s, GST_FORMAT_DEFAULT, 400, 800, 400);
 
   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = GST_CLOCK_TIME_NONE;
@@ -374,27 +420,28 @@ GST_START_TEST (test_buffer_clipping_samples)
   gst_buffer_unmap (ret, &map);
 
   gst_buffer_unref (ret);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_buffer_clip_samples_no_timestamp)
+{
+  GstSegment s;
+  GstBuffer *buf;
 
   /* If the buffer has no offset it should assert()
    * FIXME: check if return value is the same as the input buffer.
    *        probably can't be done because the assert() does a SIGABRT.
    */
-  buf = gst_buffer_new ();
-  data = (guint8 *) g_malloc (1000);
-  gst_buffer_append_memory (buf,
-      gst_memory_new_wrapped (0, data, 1000, 0, 1000, data, g_free));
-
-  gst_segment_init (&s, GST_FORMAT_DEFAULT);
-  s.start = 0;
-  s.stop = 10;
-  s.time = 0;
+  buf = make_buffer (NULL);
+  setup_segment (&s, GST_FORMAT_DEFAULT, 0, 10, 0);
 
   GST_BUFFER_TIMESTAMP (buf) = 0 * GST_SECOND;
   GST_BUFFER_DURATION (buf) = GST_CLOCK_TIME_NONE;
   GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE;
   GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE;
 
-  ASSERT_CRITICAL (ret = gst_audio_buffer_clip (buf, &s, 100, 1));
+  ASSERT_CRITICAL (gst_audio_buffer_clip (buf, &s, 100, 1));
 
   gst_buffer_unref (buf);
 }
@@ -578,13 +625,20 @@ GST_START_TEST (test_multichannel_reorder)
 
 GST_END_TEST;
 
-GST_START_TEST (test_audio_info)
+GST_START_TEST (test_audio_format_s8)
 {
   GstAudioFormat fmt;
 
   fmt = gst_audio_format_build_integer (TRUE, G_BYTE_ORDER, 8, 8);
   fail_unless (fmt == GST_AUDIO_FORMAT_S8);
 
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_audio_format_u8)
+{
+  GstAudioFormat fmt;
   fmt = gst_audio_format_build_integer (FALSE, G_BYTE_ORDER, 8, 8);
   fail_unless (fmt == GST_AUDIO_FORMAT_U8);
 }
@@ -620,11 +674,23 @@ audio_suite (void)
   TCase *tc_chain = tcase_create ("general");
 
   suite_add_tcase (s, tc_chain);
-  tcase_add_test (tc_chain, test_audio_info);
-  tcase_add_test (tc_chain, test_buffer_clipping_time);
-  tcase_add_test (tc_chain, test_buffer_clipping_samples);
+  tcase_add_test (tc_chain, test_buffer_clip_unsupported_format);
+  tcase_add_test (tc_chain, test_buffer_clip_time_start_and_stop);
+  tcase_add_test (tc_chain, test_buffer_clip_time_start);
+  tcase_add_test (tc_chain, test_buffer_clip_time_stop);
+  tcase_add_test (tc_chain, test_buffer_clip_time_outside);
+  tcase_add_test (tc_chain, test_buffer_clip_time_start_and_stop_no_meta);
+  tcase_add_test (tc_chain, test_buffer_clip_time_no_timestamp);
+  tcase_add_test (tc_chain, test_buffer_clip_samples_start_and_stop);
+  tcase_add_test (tc_chain, test_buffer_clip_samples_start);
+  tcase_add_test (tc_chain, test_buffer_clip_samples_stop);
+  tcase_add_test (tc_chain, test_buffer_clip_samples_outside);
+  tcase_add_test (tc_chain, test_buffer_clip_samples_start_and_stop_no_meta);
+  tcase_add_test (tc_chain, test_buffer_clip_samples_no_timestamp);
   tcase_add_test (tc_chain, test_multichannel_checks);
   tcase_add_test (tc_chain, test_multichannel_reorder);
+  tcase_add_test (tc_chain, test_audio_format_s8);
+  tcase_add_test (tc_chain, test_audio_format_u8);
   tcase_add_test (tc_chain, test_fill_silence);
 
   return s;