tests: qtdemux: Avoid using data beyond array and improve error msg
authorThiago Santos <thiagossantos@gmail.com>
Mon, 28 May 2018 17:59:14 +0000 (10:59 -0700)
committerThiago Santos <thiagossantos@gmail.com>
Mon, 28 May 2018 18:25:13 +0000 (11:25 -0700)
Makes it easier to debug the failures as well as prevents problems
reading out of bounds data.

tests/check/elements/qtdemux.c

index 0f9c61a..07acbfc 100644 (file)
@@ -197,11 +197,19 @@ qtdemux_probe_for_reconfig (GstPad * pad, GstPadProbeInfo * info,
     ReconfigTestData * data)
 {
   GstEvent *event = GST_PAD_PROBE_INFO_EVENT (info);
-  GstEventType expected = data->expected_events[data->step];
+  GstEventType expected;
+
+  if (data->step < data->total_step) {
+    expected = data->expected_events[data->step];
+  } else {
+    expected = GST_EVENT_UNKNOWN;
+  }
 
   GST_DEBUG ("Got event %p %s", event, GST_EVENT_TYPE_NAME (event));
 
-  fail_unless (GST_EVENT_TYPE (event) == expected);
+  fail_unless (GST_EVENT_TYPE (event) == expected,
+      "Received unexpected event: %s (expected: %s)",
+      GST_EVENT_TYPE_NAME (event), gst_event_type_get_name (expected));
   data->step++;
 
   if (GST_EVENT_TYPE (event) == GST_EVENT_EOS && data->step < data->total_step) {
@@ -259,7 +267,7 @@ GST_START_TEST (test_qtdemux_duplicated_moov)
 
   data.expected_events = expected;
   data.expected_num_srcpad = 1;
-  data.total_step = G_N_ELEMENTS (expected);;
+  data.total_step = G_N_ELEMENTS (expected);
 
   /* The goal of this test is to check that qtdemux can properly handle
    * duplicated moov without redundant events and pad exposing