3 * unit testing helper lib
5 * Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * SECTION:gstcheckconsistencychecker
25 * @short_description: Data flow consistency checker for GStreamer unit tests.
27 * These macros and functions are for internal use of the unit tests found
28 * inside the 'check' directories of various GStreamer packages.
33 #include "gstconsistencychecker.h"
35 struct _GstStreamConsistency
45 source_pad_data_cb (GstPad * pad, GstPadProbeType type, GstMiniObject * data,
46 GstStreamConsistency * consist)
48 if (GST_IS_BUFFER (data)) {
49 GST_DEBUG_OBJECT (pad,
50 "Buffer pts %" GST_TIME_FORMAT ", dts %" GST_TIME_FORMAT,
51 GST_TIME_ARGS (GST_BUFFER_PTS (GST_BUFFER_CAST (data))),
52 GST_TIME_ARGS (GST_BUFFER_DTS (GST_BUFFER_CAST (data))));
53 /* If an EOS went through, a buffer would be invalid */
54 fail_if (consist->eos, "Buffer received after EOS");
55 /* Buffers need to be preceded by a segment event */
56 fail_unless (consist->segment, "Buffer received without segment");
57 } else if (GST_IS_EVENT (data)) {
58 GstEvent *event = (GstEvent *) data;
60 GST_DEBUG_OBJECT (pad, "%s", GST_EVENT_TYPE_NAME (event));
61 switch (GST_EVENT_TYPE (event)) {
62 case GST_EVENT_FLUSH_START:
63 consist->flushing = TRUE;
65 case GST_EVENT_FLUSH_STOP:
66 /* Receiving a flush-stop is only valid after receiving a flush-start */
67 fail_unless (consist->flushing,
68 "Received a FLUSH_STOP without a FLUSH_START");
69 fail_if (consist->eos, "Received a FLUSH_STOP after an EOS");
70 consist->flushing = FALSE;
72 case GST_EVENT_SEGMENT:
73 consist->segment = TRUE;
77 /* FIXME : not 100% sure about whether two eos in a row is valid */
78 fail_if (consist->eos, "Received EOS just after another EOS");
80 consist->segment = FALSE;
83 GST_DEBUG_OBJECT (pad, "tag %" GST_PTR_FORMAT,
84 gst_event_get_structure (event));
87 if (GST_EVENT_IS_SERIALIZED (event) && GST_EVENT_IS_DOWNSTREAM (event)) {
88 fail_if (consist->eos, "Event received after EOS");
89 fail_unless (consist->segment, "Event received before segment");
91 /* FIXME : Figure out what to do for other events */
100 * gst_consistency_checker_new:
101 * @pad: The #GstPad on which the dataflow will be checked.
103 * Sets up a data probe on the given pad which will raise assertions if the
104 * data flow is inconsistent.
106 * Currently only works for source pads.
108 * Returns: A #GstStreamConsistency structure used to track data flow.
113 GstStreamConsistency *
114 gst_consistency_checker_new (GstPad * pad)
116 GstStreamConsistency *consist;
118 g_return_val_if_fail (pad != NULL, NULL);
120 consist = g_new0 (GstStreamConsistency, 1);
121 consist->pad = g_object_ref (pad);
123 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_DATA,
124 (GstPadProbeCallback) source_pad_data_cb, consist, NULL);
130 * gst_consistency_checker_reset:
131 * @consist: The #GstStreamConsistency to reset.
133 * Reset the stream checker's internal variables.
139 gst_consistency_checker_reset (GstStreamConsistency * consist)
141 consist->eos = FALSE;
142 consist->flushing = FALSE;
143 consist->segment = FALSE;
147 * gst_consistency_checker_free:
148 * @consist: The #GstStreamConsistency to free.
150 * Frees the allocated data and probe associated with @consist.
156 gst_consistency_checker_free (GstStreamConsistency * consist)
158 /* Remove the data probe */
159 gst_pad_remove_probe (consist->pad, consist->probeid);
160 g_object_unref (consist->pad);