validate:tests: Fix race in `validate_padmonitor.buffer_outside_segment`
[platform/upstream/gstreamer.git] / validate / tests / check / validate / padmonitor.c
1 /* GstValidate
2  * Copyright (C) 2014 Thibault Saunier <thibault.saunier@collabora.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include <gio/gio.h>
21 #include <gst/validate/validate.h>
22 #include <gst/validate/gst-validate-pad-monitor.h>
23 #include <gst/validate/media-descriptor-parser.h>
24 #include <gst/check/gstcheck.h>
25 #include "test-utils.h"
26
27 static GstValidateRunner *
28 _start_monitoring_bin (GstBin * bin)
29 {
30   GstValidateRunner *runner;
31   GstValidateMonitor *monitor;
32
33   runner = gst_validate_runner_new ();
34   monitor =
35       gst_validate_monitor_factory_create (GST_OBJECT (bin), runner, NULL);
36
37   gst_validate_reporter_set_handle_g_logs (GST_VALIDATE_REPORTER (monitor));
38   return runner;
39 }
40
41 static void
42 _stop_monitoring_bin (GstBin * bin, GstValidateRunner * runner)
43 {
44   GstValidateMonitor *monitor;
45
46   monitor =
47       (GstValidateMonitor *) g_object_get_data (G_OBJECT (bin),
48       "validate-monitor");
49   gst_object_unref (bin);
50   ASSERT_OBJECT_REFCOUNT (monitor, "monitor", 1);
51   gst_object_unref (monitor);
52   ASSERT_OBJECT_REFCOUNT (runner, "runner", 2);
53   gst_object_unref (runner);
54 }
55
56 static GstValidateMonitor *
57 _start_monitoring_element (GstElement * element, GstValidateRunner * runner)
58 {
59   GstValidateMonitor *monitor;
60
61   monitor = gst_validate_monitor_factory_create (GST_OBJECT (element),
62       runner, NULL);
63
64   return monitor;
65 }
66
67 static void
68 _check_reports_refcount (GstPad * pad, gint refcount)
69 {
70   GList *tmp, *reports;
71   GstValidateReporter *reporter =
72       (GstValidateReporter *) g_object_get_data (G_OBJECT (pad),
73       "validate-monitor");
74
75   reports = gst_validate_reporter_get_reports (reporter);
76   /* We take a ref here */
77   refcount += 1;
78
79   for (tmp = reports; tmp; tmp = tmp->next)
80     fail_unless_equals_int (((GstMiniObject *) tmp->data)->refcount, refcount);
81
82   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
83 }
84
85 static GstBuffer *
86 gst_discont_buffer_new (void)
87 {
88   GstBuffer *buffer = gst_buffer_new ();
89
90   GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
91
92   return buffer;
93 }
94
95 GST_START_TEST (buffer_before_segment)
96 {
97   GstPad *srcpad, *sinkpad;
98   GstElement *sink;
99   GstValidateRunner *runner;
100   GstValidateReport *report;
101   GstValidateMonitor *monitor;
102   GList *reports;
103
104   /* getting an existing element class is cheating, but easier */
105   sink = gst_element_factory_make ("fakesink", "fakesink");
106
107   srcpad = gst_pad_new ("src", GST_PAD_SRC);
108   sinkpad = gst_element_get_static_pad (sink, "sink");
109   fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK);
110   gst_clear_object (&sinkpad);
111
112   fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE));
113   runner = gst_validate_runner_new ();
114   monitor =
115       gst_validate_monitor_factory_create (GST_OBJECT (srcpad), runner, NULL);
116   fail_unless (GST_IS_VALIDATE_PAD_MONITOR (monitor));
117
118
119   /* We want to handle the src behaviour ourself */
120   fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE));
121   fail_unless_equals_int (gst_element_set_state (sink, GST_STATE_PLAYING),
122       GST_STATE_CHANGE_ASYNC);
123
124   /* Send a buffer before pushing any segment (FAILS) */
125   {
126     _gst_check_expecting_log = TRUE;
127     fail_unless_equals_int (gst_pad_push (srcpad,
128             gst_discont_buffer_new ()), GST_FLOW_OK);
129
130     reports = gst_validate_runner_get_reports (runner);
131     assert_equals_int (g_list_length (reports), 1);
132     report = reports->data;
133     fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_WARNING);
134     fail_unless_equals_int (report->issue->issue_id, BUFFER_BEFORE_SEGMENT);
135     g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
136   }
137
138   /* Setup all needed event and push a new buffer (WORKS) */
139   {
140     _gst_check_expecting_log = FALSE;
141     gst_check_setup_events (srcpad, sink, NULL, GST_FORMAT_TIME);
142     fail_unless_equals_int (gst_pad_push (srcpad, gst_discont_buffer_new ()),
143         GST_FLOW_OK);
144     reports = gst_validate_runner_get_reports (runner);
145     assert_equals_int (g_list_length (reports), 1);
146     g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
147   }
148
149   /* clean up */
150   fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, FALSE));
151   fail_unless_equals_int (gst_element_set_state (sink, GST_STATE_NULL),
152       GST_STATE_CHANGE_SUCCESS);
153
154   _check_reports_refcount (srcpad, 2);
155   gst_object_unref (srcpad);
156   gst_check_object_destroyed_on_unref (sink);
157   ASSERT_OBJECT_REFCOUNT (runner, "runner", 2);
158   gst_object_unref (runner);
159 }
160
161 GST_END_TEST;
162
163 GST_START_TEST (buffer_outside_segment)
164 {
165   GstPad *srcpad, *pad;
166   GstBuffer *buffer;
167   GstSegment segment;
168   GstElement *sink, *identity;
169   gchar *identity_klass;
170   GstValidateReport *report;
171   GstValidateRunner *runner;
172   GstValidateMonitor *monitor;
173   GList *reports;
174
175   srcpad = gst_pad_new ("src", GST_PAD_SRC);
176   identity = gst_element_factory_make ("identity", NULL);
177   sink = gst_element_factory_make ("fakesink", "fakesink");
178
179   identity_klass =
180       g_strdup (gst_element_class_get_metadata (GST_ELEMENT_GET_CLASS
181           (identity), "klass"));
182
183   /* Testing if a buffer is outside a segment is only done for buffer outputed
184    * from decoders for the moment, fake a Decoder so that the test is properly
185    * executed */
186   gst_element_class_add_metadata (GST_ELEMENT_GET_CLASS (identity), "klass",
187       "Decoder");
188
189   pad = gst_element_get_static_pad (identity, "sink");
190   fail_unless (gst_pad_link (srcpad, pad) == GST_PAD_LINK_OK);
191   gst_clear_object (&pad);
192
193   fail_unless (gst_element_link (identity, sink));
194
195   fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE));
196   runner = gst_validate_runner_new ();
197   monitor =
198       gst_validate_monitor_factory_create (GST_OBJECT (identity), runner, NULL);
199   gst_validate_reporter_set_handle_g_logs (GST_VALIDATE_REPORTER (monitor));
200
201   pad = gst_element_get_static_pad (identity, "src");
202   fail_unless (GST_IS_VALIDATE_PAD_MONITOR (g_object_get_data ((GObject *)
203               pad, "validate-monitor")));
204   gst_clear_object (&pad);
205
206   fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE));
207   fail_unless_equals_int (gst_element_set_state (identity, GST_STATE_PLAYING),
208       GST_STATE_CHANGE_SUCCESS);
209   fail_unless_equals_int (gst_element_set_state (sink, GST_STATE_PLAYING),
210       GST_STATE_CHANGE_ASYNC);
211
212   gst_segment_init (&segment, GST_FORMAT_TIME);
213   segment.start = 0;
214   segment.stop = GST_SECOND;
215   fail_unless (gst_pad_push_event (srcpad,
216           gst_event_new_stream_start ("the-stream")));
217   fail_unless (gst_pad_push_event (srcpad, gst_event_new_segment (&segment)));
218
219   /*  Pushing a buffer that is outside the segment */
220   {
221     buffer = gst_discont_buffer_new ();
222     GST_BUFFER_PTS (buffer) = 10 * GST_SECOND;
223     GST_BUFFER_DURATION (buffer) = GST_SECOND;
224     fail_if (GST_PAD_IS_FLUSHING (gst_element_get_static_pad (identity,
225                 "sink")));
226     fail_if (GST_PAD_IS_FLUSHING (gst_element_get_static_pad (identity,
227                 "src")));
228     fail_if (GST_PAD_IS_FLUSHING (gst_element_get_static_pad (sink, "sink")));
229     fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
230
231     reports = gst_validate_runner_get_reports (runner);
232     assert_equals_int (g_list_length (reports), 1);
233     report = reports->data;
234     fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_ISSUE);
235     fail_unless_equals_int (report->issue->issue_id, BUFFER_IS_OUT_OF_SEGMENT);
236     g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
237   }
238
239   /* Pushing a buffer inside the segment */
240   {
241     fail_unless_equals_int (gst_pad_push (srcpad, gst_discont_buffer_new ()),
242         GST_FLOW_OK);
243     reports = gst_validate_runner_get_reports (runner);
244     assert_equals_int (g_list_length (reports), 1);
245     g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
246   }
247
248
249   /* clean up */
250   fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, FALSE));
251   gst_object_unref (srcpad);
252
253   gst_element_class_add_metadata (GST_ELEMENT_GET_CLASS (identity), "klass",
254       identity_klass);
255   g_free (identity_klass);
256   gst_object_unref (runner);
257
258   fail_unless_equals_int (gst_element_set_state (identity, GST_STATE_NULL),
259       GST_STATE_CHANGE_SUCCESS);
260   gst_element_unlink (identity, sink);
261   fail_unless_equals_int (gst_element_set_state (sink, GST_STATE_NULL),
262       GST_STATE_CHANGE_SUCCESS);
263   gst_object_unref (identity);
264   gst_object_unref (sink);
265   gst_object_unref (monitor);
266 }
267
268 GST_END_TEST;
269
270 static void
271 fake_demuxer_prepare_pads (GstBin * pipeline, GstElement * demux,
272     GstValidateRunner * runner)
273 {
274   gint i = 0;
275   GList *tmp;
276
277   fail_unless (g_list_length (demux->srcpads), 3);
278
279   for (tmp = demux->srcpads; tmp; tmp = tmp->next) {
280     GstPad *new_peer;
281     gchar *name = g_strdup_printf ("sink-%d", i++);
282     GstElement *sink = gst_element_factory_make ("fakesink", name);
283
284     gst_bin_add (pipeline, sink);
285
286     new_peer = sink->sinkpads->data;
287     gst_pad_link (tmp->data, new_peer);
288     gst_element_set_state (sink, GST_STATE_PLAYING);
289     gst_pad_activate_mode (tmp->data, GST_PAD_MODE_PUSH, TRUE);
290
291     g_free (name);
292   }
293
294   fail_unless (gst_pad_activate_mode (demux->sinkpads->data, GST_PAD_MODE_PUSH,
295           TRUE));
296 }
297
298 static GstValidatePadMonitor *
299 _get_pad_monitor (GstPad * pad)
300 {
301   GstValidatePadMonitor *m = get_pad_monitor (pad);
302
303   gst_object_unref (pad);
304
305   return m;
306 }
307
308 static void
309 _test_flow_aggregation (GstFlowReturn flow, GstFlowReturn flow1,
310     GstFlowReturn flow2, GstFlowReturn demux_flow, gboolean should_fail)
311 {
312   GstPad *srcpad;
313   GstValidateReport *report;
314   GstValidatePadMonitor *pmonitor, *pmonitor1, *pmonitor2;
315   GstElement *demuxer = fake_demuxer_new ();
316   GstBin *pipeline = GST_BIN (gst_pipeline_new ("validate-pipeline"));
317   GList *reports;
318   GstValidateRunner *runner;
319
320   fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE));
321   runner = _start_monitoring_bin (pipeline);
322
323   gst_bin_add (pipeline, demuxer);
324   fake_demuxer_prepare_pads (pipeline, demuxer, runner);
325
326   srcpad = gst_pad_new ("srcpad1", GST_PAD_SRC);
327   gst_pad_link (srcpad, demuxer->sinkpads->data);
328   fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE));
329   gst_check_setup_events_with_stream_id (srcpad, demuxer, NULL,
330       GST_FORMAT_TIME, "the-stream");
331
332   pmonitor = _get_pad_monitor (gst_pad_get_peer (demuxer->srcpads->data));
333   pmonitor1 =
334       _get_pad_monitor (gst_pad_get_peer (demuxer->srcpads->next->data));
335   pmonitor2 =
336       _get_pad_monitor (gst_pad_get_peer (demuxer->srcpads->next->next->data));
337
338   pmonitor->last_flow_return = flow;
339   pmonitor1->last_flow_return = flow1;
340   pmonitor2->last_flow_return = flow2;
341   FAKE_DEMUXER (demuxer)->return_value = demux_flow;
342
343   fail_unless_equals_int (gst_pad_push (srcpad, gst_discont_buffer_new ()),
344       demux_flow);
345
346   reports = gst_validate_runner_get_reports (runner);
347   if (should_fail) {
348     assert_equals_int (g_list_length (reports), 1);
349     report = reports->data;
350     fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_CRITICAL);
351     fail_unless_equals_int (report->issue->issue_id, WRONG_FLOW_RETURN);
352   } else {
353     assert_equals_int (g_list_length (reports), 0);
354
355   }
356
357   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
358   clean_bus (GST_ELEMENT (pipeline));
359
360   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
361   ASSERT_OBJECT_REFCOUNT (pipeline, "ours", 1);
362   gst_object_ref (demuxer);
363   gst_object_ref (pmonitor);
364   _stop_monitoring_bin (pipeline, runner);
365
366   ASSERT_OBJECT_REFCOUNT (demuxer, "plop", 1);
367   gst_object_unref (demuxer);
368   ASSERT_OBJECT_REFCOUNT (pmonitor, "plop", 1);
369   gst_object_unref (pmonitor);
370   gst_object_unref (srcpad);
371 }
372
373 #define FLOW_TEST(name, flow1, flow2, flow3, demux_flow, fails) \
374 GST_START_TEST(flow_aggregation_##name) { \
375   _test_flow_aggregation (GST_FLOW_##flow1, GST_FLOW_##flow2, \
376       GST_FLOW_##flow3, GST_FLOW_##demux_flow, fails); \
377 } GST_END_TEST
378
379 FLOW_TEST (ok_ok_error_ok, OK, OK, ERROR, OK, TRUE);
380 FLOW_TEST (eos_eos_eos_ok, EOS, EOS, EOS, OK, TRUE);
381 FLOW_TEST (flushing_ok_ok_ok, FLUSHING, OK, OK, OK, TRUE);
382 FLOW_TEST (not_neg_ok_ok_ok, NOT_NEGOTIATED, OK, OK, OK, TRUE);
383 /*[> Passing cases: <]*/
384 FLOW_TEST (eos_eos_eos_eos, EOS, EOS, EOS, EOS, FALSE);
385 FLOW_TEST (eos_eos_ok_ok, EOS, EOS, OK, OK, FALSE);
386 FLOW_TEST (ok_ok_ok_eos, OK, OK, OK, EOS, FALSE);
387 FLOW_TEST (not_neg_ok_ok_not_neg, NOT_NEGOTIATED, OK, OK, NOT_NEGOTIATED,
388     FALSE);
389 #undef FLOW_TEST
390
391 GST_START_TEST (issue_concatenation)
392 {
393   GstPad *srcpad1, *srcpad2, *sinkpad, *fakemixer_sink1, *fakemixer_sink2;
394   GstElement *src1, *src2, *sink, *fakemixer;
395   GstValidateRunner *runner;
396   GstValidatePadMonitor *srcpad_monitor1, *srcpad_monitor2, *sinkpad_monitor;
397   GstValidatePadMonitor *fakemixer_sink_monitor1, *fakemixer_sink_monitor2;
398   GList *reports;
399   gint n_reports;
400
401   fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "subchain", TRUE));
402   runner = gst_validate_runner_new ();
403
404   src1 = create_and_monitor_element ("fakesrc2", NULL, runner);
405   src2 = create_and_monitor_element ("fakesrc2", NULL, runner);
406   fakemixer = create_and_monitor_element ("fakemixer", "fakemixer", runner);
407   sink = create_and_monitor_element ("fakesink", "fakesink", runner);
408
409   srcpad1 = gst_element_get_static_pad (src1, "src");
410   srcpad_monitor1 = g_object_get_data (G_OBJECT (srcpad1), "validate-monitor");
411   srcpad2 = gst_element_get_static_pad (src2, "src");
412   srcpad_monitor2 = g_object_get_data (G_OBJECT (srcpad2), "validate-monitor");
413   fakemixer_sink1 = gst_element_get_request_pad (fakemixer, "sink_%u");
414   fakemixer_sink_monitor1 =
415       g_object_get_data (G_OBJECT (fakemixer_sink1), "validate-monitor");
416   fakemixer_sink2 = gst_element_get_request_pad (fakemixer, "sink_%u");
417   fakemixer_sink_monitor2 =
418       g_object_get_data (G_OBJECT (fakemixer_sink2), "validate-monitor");
419   sinkpad = gst_element_get_static_pad (sink, "sink");
420   sinkpad_monitor = g_object_get_data (G_OBJECT (sinkpad), "validate-monitor");
421
422   fail_unless (gst_element_link (fakemixer, sink));
423   fail_unless (gst_pad_link (srcpad1, fakemixer_sink1) == GST_PAD_LINK_OK);
424   fail_unless (gst_pad_link (srcpad2, fakemixer_sink2) == GST_PAD_LINK_OK);
425
426   /* We want to handle the src behaviour ourselves */
427   fail_unless (gst_pad_activate_mode (srcpad1, GST_PAD_MODE_PUSH, TRUE));
428   fail_unless (gst_pad_activate_mode (srcpad2, GST_PAD_MODE_PUSH, TRUE));
429
430   gst_check_setup_events_with_stream_id (srcpad1, fakemixer, NULL,
431       GST_FORMAT_TIME, "stream1");
432   gst_check_setup_events_with_stream_id (srcpad2, fakemixer, NULL,
433       GST_FORMAT_TIME, "stream2");
434
435   fail_unless_equals_int (gst_element_set_state (fakemixer, GST_STATE_PLAYING),
436       GST_STATE_CHANGE_SUCCESS);
437   fail_unless_equals_int (gst_element_set_state (sink, GST_STATE_PLAYING),
438       GST_STATE_CHANGE_ASYNC);
439
440
441   /* Send an unexpected flush stop */
442   _gst_check_expecting_log = TRUE;
443   fail_unless (gst_pad_push_event (srcpad1, gst_event_new_flush_stop (TRUE)));
444
445   /* The runner only sees one report */
446   reports = gst_validate_runner_get_reports (runner);
447   assert_equals_int (g_list_length (reports), 1);
448   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
449
450   /* Each pad monitor on the way actually holds a report */
451   n_reports = gst_validate_reporter_get_reports_count ((GstValidateReporter *)
452       srcpad_monitor1);
453   fail_unless_equals_int (n_reports, 1);
454   n_reports = gst_validate_reporter_get_reports_count ((GstValidateReporter *)
455       sinkpad_monitor);
456   fail_unless_equals_int (n_reports, 1);
457   n_reports = gst_validate_reporter_get_reports_count ((GstValidateReporter *)
458       fakemixer_sink_monitor1);
459   fail_unless_equals_int (n_reports, 1);
460
461   /* But not the pad monitor of the other fakemixer sink */
462   n_reports = gst_validate_reporter_get_reports_count ((GstValidateReporter *)
463       fakemixer_sink_monitor2);
464   fail_unless_equals_int (n_reports, 0);
465   n_reports = gst_validate_reporter_get_reports_count ((GstValidateReporter *)
466       srcpad_monitor2);
467   fail_unless_equals_int (n_reports, 0);
468
469   /* Once again but on the other fakemixer sink */
470   fail_unless (gst_pad_push_event (srcpad2, gst_event_new_flush_stop (TRUE)));
471
472   /* The runner now sees two reports */
473   reports = gst_validate_runner_get_reports (runner);
474   assert_equals_int (g_list_length (reports), 2);
475   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
476
477   /* These monitors already saw that issue */
478   n_reports = gst_validate_reporter_get_reports_count ((GstValidateReporter *)
479       srcpad_monitor1);
480   fail_unless_equals_int (n_reports, 1);
481   n_reports = gst_validate_reporter_get_reports_count ((GstValidateReporter *)
482       sinkpad_monitor);
483   fail_unless_equals_int (n_reports, 1);
484   n_reports = gst_validate_reporter_get_reports_count ((GstValidateReporter *)
485       fakemixer_sink_monitor1);
486   fail_unless_equals_int (n_reports, 1);
487
488   n_reports = gst_validate_reporter_get_reports_count ((GstValidateReporter *)
489       fakemixer_sink_monitor2);
490   fail_unless_equals_int (n_reports, 1);
491   n_reports = gst_validate_reporter_get_reports_count ((GstValidateReporter *)
492       srcpad_monitor2);
493   fail_unless_equals_int (n_reports, 1);
494
495   /* clean up */
496   fail_unless (gst_pad_activate_mode (srcpad1, GST_PAD_MODE_PUSH, FALSE));
497   fail_unless (gst_pad_activate_mode (srcpad2, GST_PAD_MODE_PUSH, FALSE));
498   fail_unless_equals_int (gst_element_set_state (fakemixer, GST_STATE_NULL),
499       GST_STATE_CHANGE_SUCCESS);
500   fail_unless_equals_int (gst_element_set_state (sink, GST_STATE_NULL),
501       GST_STATE_CHANGE_SUCCESS);
502
503   /* The reporter, the runner */
504   _check_reports_refcount (srcpad1, 2);
505   /* The reporter, the master report */
506   _check_reports_refcount (fakemixer_sink1, 2);
507   free_element_monitor (src1);
508   free_element_monitor (src2);
509   free_element_monitor (fakemixer);
510   free_element_monitor (sink);
511   gst_object_unref (srcpad1);
512   gst_object_unref (srcpad2);
513   gst_object_unref (sinkpad);
514   gst_object_unref (fakemixer_sink1);
515   gst_object_unref (fakemixer_sink2);
516   gst_check_objects_destroyed_on_unref (fakemixer, fakemixer_sink1,
517       fakemixer_sink2, NULL);
518   gst_check_objects_destroyed_on_unref (src1, srcpad1, NULL);
519   gst_check_objects_destroyed_on_unref (src2, srcpad2, NULL);
520   gst_check_objects_destroyed_on_unref (sink, sinkpad, NULL);
521   ASSERT_OBJECT_REFCOUNT (runner, "runner", 2);
522   gst_object_unref (runner);
523 }
524
525 GST_END_TEST;
526
527 /* *INDENT-OFF* */
528 static const gchar * media_info =
529 "<file duration='10031000000' frame-detection='1' uri='file:///I/am/so/fake.fakery' seekable='true'>"
530 "  <streams caps='video/quicktime'>"
531 "    <stream type='video' caps='video/x-raw'>"
532 "       <frame duration='1' id='0' is-keyframe='true'  offset='18446744073709551615' offset-end='18446744073709551615' pts='0'  dts='0' checksum='cfeb9b47da2bb540cd3fa84cffea4df9'/>"  /* buffer1 */
533 "       <frame duration='1' id='1' is-keyframe='false' offset='18446744073709551615' offset-end='18446744073709551615' pts='1'  dts='1' checksum='e40d7cd997bd14462468d201f1e1a3d4'/>" /* buffer2 */
534 "       <frame duration='1' id='2' is-keyframe='false' offset='18446744073709551615' offset-end='18446744073709551615' pts='2'  dts='2' checksum='4136320f0da0738a06c787dce827f034'/>" /* buffer3 */
535 "       <frame duration='1' id='3' is-keyframe='false' offset='18446744073709551615' offset-end='18446744073709551615' pts='3'  dts='3' checksum='sure my dear'/>" /* gonna fail */
536 "       <frame duration='1' id='4' is-keyframe='true'  offset='18446744073709551615' offset-end='18446744073709551615' pts='4'  dts='4' checksum='569d8927835c44fd4ff40b8408657f9e'/>"  /* buffer4 */
537 "       <frame duration='1' id='5' is-keyframe='false' offset='18446744073709551615' offset-end='18446744073709551615' pts='5'  dts='5' checksum='fcea4caed9b2c610fac1f2a6b38b1d5f'/>" /* buffer5 */
538 "       <frame duration='1' id='6' is-keyframe='false' offset='18446744073709551615' offset-end='18446744073709551615' pts='6'  dts='6' checksum='c7536747446a1503b1d9b02744144fa9'/>" /* buffer6 */
539 "       <frame duration='1' id='7' is-keyframe='false' offset='18446744073709551615' offset-end='18446744073709551615' pts='7'  dts='7' checksum='sure my dear'/>" /* gonna fail */
540 "      <tags>"
541 "      </tags>"
542 "    </stream>"
543 "  </streams>"
544 "</file>";
545 /* *INDENT-ON* */
546
547 typedef struct _BufferDesc
548 {
549   const gchar *content;
550   GstClockTime pts;
551   GstClockTime dts;
552   GstClockTime duration;
553   gboolean keyframe;
554
555   gint num_issues;
556 } BufferDesc;
557
558 static GstBuffer *
559 _create_buffer (BufferDesc * bdesc)
560 {
561   gchar *tmp = g_strdup (bdesc->content);
562   GstBuffer *buffer =
563       gst_buffer_new_wrapped (tmp, strlen (tmp) * sizeof (gchar));
564
565   GST_BUFFER_DTS (buffer) = bdesc->dts;
566   GST_BUFFER_PTS (buffer) = bdesc->pts;
567   GST_BUFFER_DURATION (buffer) = bdesc->duration;
568
569   if (bdesc->keyframe)
570     GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
571   else
572     GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
573
574   GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
575
576   return buffer;
577 }
578
579 static void
580 _check_media_info (GstSegment * segment, BufferDesc * bufs)
581 {
582   GstEvent *segev;
583   GstBuffer *buffer;
584   GstElement *decoder;
585   GstPad *srcpad, *sinkpad;
586   GstValidateReport *report;
587   GstValidateMonitor *monitor;
588   GstValidateRunner *runner;
589   GstValidateMediaDescriptor *mdesc;
590   GstCaps *caps;
591
592   GError *err = NULL;
593   gint i, num_issues = 0;
594
595   fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE));
596   runner = gst_validate_runner_new ();
597
598   mdesc = (GstValidateMediaDescriptor *)
599       gst_validate_media_descriptor_parser_new_from_xml (runner, media_info,
600       &err);
601
602   decoder = fake_decoder_new ();
603   monitor = _start_monitoring_element (decoder, runner);
604   gst_validate_monitor_set_media_descriptor (monitor, mdesc);
605   gst_object_unref (mdesc);
606
607   srcpad = gst_pad_new ("src", GST_PAD_SRC);
608   sinkpad = decoder->sinkpads->data;
609   ASSERT_OBJECT_REFCOUNT (sinkpad, "decoder ref", 1);
610   fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE));
611   fail_unless_equals_int (gst_element_set_state (decoder, GST_STATE_PLAYING),
612       GST_STATE_CHANGE_SUCCESS);
613
614   assert_equals_string (gst_pad_link_get_name (gst_pad_link (srcpad, sinkpad)),
615       gst_pad_link_get_name (GST_PAD_LINK_OK));
616
617   caps =
618       gst_caps_from_string
619       ("video/x-raw, width=360, height=42, framerate=24/1, pixel-aspect-ratio =1/1, format=AYUV");
620   gst_check_setup_events_with_stream_id (srcpad, decoder, caps, GST_FORMAT_TIME,
621       "the-stream");
622   gst_caps_unref (caps);
623
624   if (segment) {
625     segev = gst_event_new_segment (segment);
626     fail_unless (gst_pad_push_event (srcpad, segev));
627   }
628
629   for (i = 0; bufs[i].content != NULL; i++) {
630     GList *reports;
631     BufferDesc *buf = &bufs[i];
632     buffer = _create_buffer (buf);
633
634     assert_equals_string (gst_flow_get_name (gst_pad_push (srcpad, buffer)),
635         gst_flow_get_name (GST_FLOW_OK));
636     reports = gst_validate_runner_get_reports (runner);
637
638     num_issues += buf->num_issues;
639     assert_equals_int (g_list_length (reports), num_issues);
640
641     if (buf->num_issues) {
642       GList *tmp = g_list_nth (reports, num_issues - buf->num_issues);
643
644       while (tmp) {
645         report = tmp->data;
646
647         fail_unless_equals_int (report->level,
648             GST_VALIDATE_REPORT_LEVEL_WARNING);
649         fail_unless_equals_int (report->issue->issue_id, WRONG_BUFFER);
650         tmp = tmp->next;
651       }
652     }
653     g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
654   }
655
656   /* clean up */
657   fail_unless (gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PUSH, FALSE));
658   fail_unless_equals_int (gst_element_set_state (decoder, GST_STATE_NULL),
659       GST_STATE_CHANGE_SUCCESS);
660
661   gst_object_unref (srcpad);
662   gst_check_objects_destroyed_on_unref (decoder, sinkpad, NULL);
663   ASSERT_OBJECT_REFCOUNT (runner, "runner", 2);
664   gst_object_unref (runner);
665   gst_object_unref (monitor);
666 }
667
668 #define MEDIA_INFO_TEST(name,segment_start,bufs) \
669 GST_START_TEST(media_info_##name) { \
670   if (segment_start >= 0) { \
671     GstSegment segment; \
672     gst_segment_init (&segment, GST_FORMAT_TIME); \
673     segment.start = segment_start; \
674      _check_media_info (&segment, (bufs)); \
675   } else \
676      _check_media_info (NULL, (bufs)); \
677 } GST_END_TEST
678
679 /* *INDENT-OFF* */
680 MEDIA_INFO_TEST (1, -1,
681       ((BufferDesc []) {
682       {
683         .content = "buffer1",
684         .pts = 0,
685         .dts = 0,
686         .duration = 1,
687         .keyframe = TRUE,
688         .num_issues = 0
689       },
690       {
691         .content = "buffer2",
692         .pts = 1,
693         .dts = 1,
694         .duration = 1,
695         .keyframe = FALSE,
696         .num_issues = 0
697       },
698       {
699         .content = "buffer3",
700         .pts = 2,
701         .dts = 2,
702         .duration = 1,
703         .keyframe = FALSE,
704         .num_issues = 0
705       },
706       {
707         .content = "fail please",
708         .pts = 3,
709         .dts = 3,
710         .duration = 1,
711         .keyframe = FALSE,
712         .num_issues = 1
713       },
714       { NULL}
715     }));
716
717 /* Segment start is 2, the first buffer is expected (first Keyframe) */
718 MEDIA_INFO_TEST (2, 2,
719       ((BufferDesc []) {
720       {
721         .content = "buffer2", /* Wrong checksum */
722         .pts = 0,
723         .dts = 0,
724         .duration = 1,
725         .keyframe = TRUE,
726         .num_issues = 1
727       },
728       { NULL}
729     }));
730
731 /* Segment start is 2, the first buffer is expected (first Keyframe) */
732 MEDIA_INFO_TEST (3, 2,
733       ((BufferDesc []) {
734       { /*  The right first buffer */
735         .content = "buffer1",
736         .pts = 0,
737         .dts = 0,
738         .duration = 1,
739         .keyframe = TRUE,
740         .num_issues = 0
741       },
742       { NULL}
743     }));
744
745 /* Segment start is 6, the 4th buffer is expected (first Keyframe) */
746 MEDIA_INFO_TEST (4, 6,
747       ((BufferDesc []) {
748       { /*  The right fourth buffer */
749         .content = "buffer4",
750         .pts = 4,
751         .dts = 4,
752         .duration = 1,
753         .keyframe = TRUE,
754         .num_issues = 0
755       },
756       { NULL}
757     }));
758
759 /* Segment start is 6, the 4th buffer is expected (first Keyframe) */
760 MEDIA_INFO_TEST (5, 6,
761       ((BufferDesc []) {
762       { /*  The sixth buffer... all wrong! */
763         .content = "buffer6",
764         .pts = 6,
765         .dts = 6,
766         .duration = 1,
767         .keyframe = FALSE,
768         .num_issues = 1
769       },
770       { NULL}
771     }));
772 /* *INDENT-ON* */
773
774 GST_START_TEST (caps_events)
775 {
776   GstPad *srcpad, *sinkpad;
777   GstElement *decoder = fake_decoder_new ();
778   GstElement *sink = gst_element_factory_make ("fakesink", NULL);
779   GstBin *pipeline = GST_BIN (gst_pipeline_new ("validate-pipeline"));
780   GList *reports;
781   GstValidateReport *report;
782   GstValidateRunner *runner;
783   GstCaps *caps;
784
785   fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE));
786   runner = _start_monitoring_bin (pipeline);
787
788   gst_bin_add_many (pipeline, decoder, sink, NULL);
789   srcpad = gst_pad_new ("srcpad1", GST_PAD_SRC);
790   sinkpad = decoder->sinkpads->data;
791   gst_pad_link (srcpad, sinkpad);
792
793   gst_element_link (decoder, sink);
794   fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
795           GST_STATE_PLAYING), GST_STATE_CHANGE_ASYNC);
796   fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE));
797
798   reports = gst_validate_runner_get_reports (runner);
799   assert_equals_int (g_list_length (reports), 0);
800   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
801
802   caps =
803       gst_caps_from_string
804       ("video/x-raw, format=AYUV, width=320, height=240, pixel-aspect-ratio=1/1");
805   fail_unless (gst_pad_push_event (srcpad, gst_event_new_caps (caps)));
806   gst_caps_unref (caps);
807   reports = gst_validate_runner_get_reports (runner);
808
809   /* Our caps didn't have a framerate, the decoder sink should complain about
810    * that */
811   assert_equals_int (g_list_length (reports), 1);
812   report = reports->data;
813   fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_ISSUE);
814   fail_unless_equals_int (report->issue->issue_id, CAPS_IS_MISSING_FIELD);
815   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
816
817   caps =
818       gst_caps_from_string
819       ("video/x-raw, format=AYUV, framerate=24/1, width=(fraction)320, height=240, pixel-aspect-ratio=1/1");
820   fail_unless (gst_pad_push_event (srcpad, gst_event_new_caps (caps)));
821   gst_caps_unref (caps);
822
823   reports = gst_validate_runner_get_reports (runner);
824   assert_equals_int (g_list_length (reports), 2);
825   report = reports->next->data;
826   /* A width isn't supposed to be a fraction */
827   fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_WARNING);
828   fail_unless_equals_int (report->issue->issue_id, CAPS_FIELD_HAS_BAD_TYPE);
829   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
830
831   caps =
832       gst_caps_from_string
833       ("video/x-raw, format=AYUV, framerate=24/1, width=320, height=240, pixel-aspect-ratio=1/1");
834   fail_unless (gst_pad_push_event (srcpad, gst_event_new_caps (caps)));
835   gst_caps_unref (caps);
836
837   caps =
838       gst_caps_from_string
839       ("video/x-raw, format=AYUV, framerate=24/1, width=320, height=240, pixel-aspect-ratio=1/1");
840   fail_unless (gst_pad_push_event (srcpad, gst_event_new_caps (caps)));
841   gst_caps_unref (caps);
842
843   reports = gst_validate_runner_get_reports (runner);
844   assert_equals_int (g_list_length (reports), 3);
845   report = reports->next->next->data;
846   /* A width isn't supposed to be a fraction */
847   fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_WARNING);
848   /* Pushing the same twice isn't very useful */
849   fail_unless_equals_int (report->issue->issue_id, EVENT_CAPS_DUPLICATE);
850
851
852   clean_bus (GST_ELEMENT (pipeline));
853
854   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
855
856   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
857   _stop_monitoring_bin (pipeline, runner);
858
859   gst_object_unref (srcpad);
860 }
861
862 GST_END_TEST;
863
864 GST_START_TEST (eos_without_segment)
865 {
866   GstPad *srcpad, *sinkpad;
867   GstValidateReport *report;
868   GstElement *decoder = fake_decoder_new ();
869   GstElement *sink = gst_element_factory_make ("fakesink", NULL);
870   GstBin *pipeline = GST_BIN (gst_pipeline_new ("validate-pipeline"));
871   GList *reports;
872   GstValidateRunner *runner;
873
874   fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE));
875   runner = _start_monitoring_bin (pipeline);
876
877   gst_bin_add_many (pipeline, decoder, sink, NULL);
878   srcpad = gst_pad_new ("srcpad1", GST_PAD_SRC);
879   sinkpad = decoder->sinkpads->data;
880   gst_pad_link (srcpad, sinkpad);
881
882   gst_element_link (decoder, sink);
883   fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
884           GST_STATE_PLAYING), GST_STATE_CHANGE_ASYNC);
885   fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE));
886
887   reports = gst_validate_runner_get_reports (runner);
888   assert_equals_int (g_list_length (reports), 0);
889   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
890
891   fail_unless (gst_pad_push_event (srcpad, gst_event_new_eos ()));
892   reports = gst_validate_runner_get_reports (runner);
893
894   /* Getting the issue on the srcpad -> decoder.sinkpad -> decoder->srcpad */
895   assert_equals_int (g_list_length (reports), 3);
896   report = reports->data;
897   fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_WARNING);
898   fail_unless_equals_int (report->issue->issue_id, EVENT_EOS_WITHOUT_SEGMENT);
899   clean_bus (GST_ELEMENT (pipeline));
900
901   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
902
903   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
904   _stop_monitoring_bin (pipeline, runner);
905
906   gst_object_unref (srcpad);
907 }
908
909 GST_END_TEST;
910
911 GST_START_TEST (buffer_timestamp_out_of_received_range)
912 {
913   GstPad *srcpad, *sinkpad;
914   GstElement *decoder = fake_decoder_new ();
915   GstElement *sink = gst_element_factory_make ("fakesink", NULL);
916   GstBin *pipeline = GST_BIN (gst_pipeline_new ("validate-pipeline"));
917   GList *reports;
918   GstValidateRunner *runner;
919   GstSegment segment;
920   GstBuffer *buffer;
921   GstPad *decoder_srcpad;
922   GstValidateReport *report;
923
924   fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE));
925   runner = _start_monitoring_bin (pipeline);
926
927   gst_bin_add_many (pipeline, decoder, sink, NULL);
928   srcpad = gst_pad_new ("srcpad1", GST_PAD_SRC);
929   sinkpad = decoder->sinkpads->data;
930   gst_pad_link (srcpad, sinkpad);
931
932   gst_element_link (decoder, sink);
933   ASSERT_SET_STATE (GST_ELEMENT (pipeline), GST_STATE_PLAYING,
934       GST_STATE_CHANGE_ASYNC);
935   fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE));
936
937   gst_segment_init (&segment, GST_FORMAT_TIME);
938   segment.start = 0;
939   segment.stop = GST_SECOND;
940   fail_unless (gst_pad_push_event (srcpad,
941           gst_event_new_stream_start ("the-stream")));
942   fail_unless (gst_pad_push_event (srcpad, gst_event_new_segment (&segment)));
943
944   {
945     buffer = gst_discont_buffer_new ();
946     GST_BUFFER_PTS (buffer) = 0 * GST_SECOND;
947     GST_BUFFER_DURATION (buffer) = 0.1 * GST_SECOND;
948     fail_unless (gst_pad_push (srcpad, buffer) == GST_FLOW_OK);
949   }
950
951   decoder_srcpad = gst_element_get_static_pad (decoder, "src");
952
953   {
954     buffer = gst_discont_buffer_new ();
955     GST_BUFFER_PTS (buffer) = 0.9 * GST_SECOND;
956     GST_BUFFER_DURATION (buffer) = 0.1 * GST_SECOND;
957     fail_unless (gst_pad_push (decoder_srcpad, buffer) == GST_FLOW_OK);
958   }
959
960   reports = gst_validate_runner_get_reports (runner);
961
962   assert_equals_int (g_list_length (reports), 1);
963   report = reports->data;
964   fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_WARNING);
965   fail_unless_equals_int (report->issue->issue_id,
966       BUFFER_TIMESTAMP_OUT_OF_RECEIVED_RANGE);
967   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
968
969   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
970
971   gst_object_unref (decoder_srcpad);
972   gst_object_unref (srcpad);
973
974   _stop_monitoring_bin (pipeline, runner);
975 }
976
977 GST_END_TEST;
978
979
980 GST_START_TEST (flow_error_without_message)
981 {
982   GstElement *decoder = fake_decoder_new ();
983   GstElement *src = gst_element_factory_make ("fakesrc", NULL);
984   GstElement *sink = gst_element_factory_make ("fakesink", NULL);
985   GstBin *pipeline = GST_BIN (gst_pipeline_new ("validate-pipeline"));
986   GList *reports;
987   GstValidateRunner *runner;
988   GstValidateReport *report;
989
990   fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE));
991   runner = _start_monitoring_bin (pipeline);
992
993   gst_bin_add_many (pipeline, src, decoder, sink, NULL);
994   fail_unless (gst_element_link_many (src, decoder, sink, NULL));
995
996   FAKE_DECODER (decoder)->return_value = GST_FLOW_ERROR;
997   ASSERT_SET_STATE (GST_ELEMENT (pipeline), GST_STATE_PLAYING,
998       GST_STATE_CHANGE_ASYNC);
999
1000   gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL,
1001       GST_CLOCK_TIME_NONE);
1002
1003   reports = gst_validate_runner_get_reports (runner);
1004
1005   fail_unless (g_list_length (reports) >= 1);
1006   report = reports->data;
1007   fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_WARNING);
1008   fail_unless_equals_int (report->issue->issue_id,
1009       FLOW_ERROR_WITHOUT_ERROR_MESSAGE);
1010   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
1011
1012   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
1013
1014   _stop_monitoring_bin (pipeline, runner);
1015 }
1016
1017 GST_END_TEST;
1018
1019
1020 GST_START_TEST (flow_error_with_message)
1021 {
1022   GstElement *decoder = fake_decoder_new ();
1023   GstElement *src = gst_element_factory_make ("fakesrc", NULL);
1024   GstElement *sink = gst_element_factory_make ("fakesink", NULL);
1025   GstBin *pipeline = GST_BIN (gst_pipeline_new ("validate-pipeline"));
1026   GList *reports;
1027   GstValidateRunner *runner;
1028   GstValidateReport *report;
1029   const GError gerror =
1030       { G_IO_ERROR, G_IO_ERROR_FAILED, (gchar *) "fake error" };
1031
1032   fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE));
1033   runner = _start_monitoring_bin (pipeline);
1034
1035   gst_bin_add_many (pipeline, src, decoder, sink, NULL);
1036   fail_unless (gst_element_link_many (src, decoder, sink, NULL));
1037
1038   g_object_set (src, "is-live", TRUE, NULL);
1039
1040   FAKE_DECODER (decoder)->return_value = GST_FLOW_ERROR;
1041
1042   ASSERT_SET_STATE (GST_ELEMENT (pipeline), GST_STATE_PAUSED,
1043       GST_STATE_CHANGE_NO_PREROLL);
1044
1045   gst_element_post_message (decoder,
1046       gst_message_new_error (GST_OBJECT (decoder),
1047           (GError *) & gerror, "This is a fake error"));
1048
1049   ASSERT_SET_STATE (GST_ELEMENT (pipeline), GST_STATE_PLAYING,
1050       GST_STATE_CHANGE_ASYNC);
1051
1052   gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL,
1053       GST_CLOCK_TIME_NONE);
1054
1055   reports = gst_validate_runner_get_reports (runner);
1056
1057   assert_equals_int (g_list_length (reports), 1);
1058   report = reports->data;
1059   fail_unless_equals_int (report->issue->issue_id, ERROR_ON_BUS);
1060   g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
1061
1062   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
1063
1064   _stop_monitoring_bin (pipeline, runner);
1065 }
1066
1067 GST_END_TEST;
1068
1069
1070
1071 static Suite *
1072 gst_validate_suite (void)
1073 {
1074   Suite *s = suite_create ("padmonitor");
1075   TCase *tc_chain = tcase_create ("padmonitor");
1076   suite_add_tcase (s, tc_chain);
1077
1078   if (atexit (gst_validate_deinit) != 0) {
1079     GST_ERROR ("failed to set gst_validate_deinit as exit function");
1080   }
1081
1082   fake_elements_register ();
1083
1084   tcase_add_test (tc_chain, buffer_before_segment);
1085   tcase_add_test (tc_chain, buffer_outside_segment);
1086   tcase_add_test (tc_chain, buffer_timestamp_out_of_received_range);
1087
1088   tcase_add_test (tc_chain, media_info_1);
1089   tcase_add_test (tc_chain, media_info_2);
1090   tcase_add_test (tc_chain, media_info_3);
1091   tcase_add_test (tc_chain, media_info_4);
1092   tcase_add_test (tc_chain, media_info_5);
1093
1094   tcase_add_test (tc_chain, flow_aggregation_ok_ok_error_ok);
1095   tcase_add_test (tc_chain, flow_aggregation_eos_eos_eos_ok);
1096   tcase_add_test (tc_chain, flow_aggregation_flushing_ok_ok_ok);
1097   tcase_add_test (tc_chain, flow_aggregation_not_neg_ok_ok_ok);
1098   tcase_add_test (tc_chain, flow_aggregation_eos_eos_eos_eos);
1099   tcase_add_test (tc_chain, flow_aggregation_eos_eos_ok_ok);
1100   tcase_add_test (tc_chain, flow_aggregation_ok_ok_ok_eos);
1101   tcase_add_test (tc_chain, flow_aggregation_not_neg_ok_ok_not_neg);
1102
1103   tcase_add_test (tc_chain, issue_concatenation);
1104   tcase_add_test (tc_chain, eos_without_segment);
1105   tcase_add_test (tc_chain, caps_events);
1106   tcase_add_test (tc_chain, flow_error_without_message);
1107   tcase_add_test (tc_chain, flow_error_with_message);
1108
1109   return s;
1110 }
1111
1112 GST_CHECK_MAIN (gst_validate);