tests: additional parameterization for parser test helper

Allow context callbacks to perform custom buffer verification
and custom element setup.  Also move some static tracking variables
into helper struct and expose the latter struct for use by unit test
(callbacks).
This commit is contained in:
Mark Nauwelaerts 2011-05-25 20:48:38 +02:00
parent e5d5ff4394
commit 91dd0a4f91
2 changed files with 53 additions and 33 deletions

View file

@ -36,6 +36,9 @@ GstCaps *ctx_output_caps;
guint ctx_discard = 0; guint ctx_discard = 0;
datablob ctx_headers[MAX_HEADERS] = { {NULL, 0}, }; datablob ctx_headers[MAX_HEADERS] = { {NULL, 0}, };
VerifyBuffer ctx_verify_buffer = NULL;
ElementSetup ctx_setup = NULL;
gboolean ctx_no_metadata = FALSE; gboolean ctx_no_metadata = FALSE;
/* helper variables */ /* helper variables */
@ -43,20 +46,6 @@ GList *current_buf = NULL;
GstPad *srcpad, *sinkpad; GstPad *srcpad, *sinkpad;
guint dataoffset = 0; guint dataoffset = 0;
GstClockTime ts_counter = 0;
gint64 offset_counter = 0;
guint buffer_counter = 0;
typedef struct
{
guint discard;
guint buffers_before_offset_skip;
guint offset_skip_amount;
const guint8 *data_to_verify;
guint data_to_verify_size;
GstCaps *caps;
gboolean no_metadata;
} buffer_verify_data_s;
/* takes a copy of the passed buffer data */ /* takes a copy of the passed buffer data */
static GstBuffer * static GstBuffer *
@ -107,28 +96,32 @@ buffer_verify_data (void *buffer, void *user_data)
GST_DEBUG ("discard: %d", vdata->discard); GST_DEBUG ("discard: %d", vdata->discard);
if (vdata->discard) { if (vdata->discard) {
buffer_counter++; if (ctx_verify_buffer)
if (buffer_counter == vdata->discard) { ctx_verify_buffer (vdata, buffer);
buffer_counter = 0; vdata->buffer_counter++;
if (vdata->buffer_counter == vdata->discard) {
vdata->buffer_counter = 0;
vdata->discard = 0; vdata->discard = 0;
} }
return; return;
} }
if (!ctx_verify_buffer || !ctx_verify_buffer (vdata, buffer)) {
fail_unless (GST_BUFFER_SIZE (buffer) == vdata->data_to_verify_size); fail_unless (GST_BUFFER_SIZE (buffer) == vdata->data_to_verify_size);
fail_unless (memcmp (GST_BUFFER_DATA (buffer), vdata->data_to_verify, fail_unless (memcmp (GST_BUFFER_DATA (buffer), vdata->data_to_verify,
vdata->data_to_verify_size) == 0); vdata->data_to_verify_size) == 0);
}
if (vdata->buffers_before_offset_skip) { if (vdata->buffers_before_offset_skip) {
/* This is for skipping the garbage in some test cases */ /* This is for skipping the garbage in some test cases */
if (buffer_counter == vdata->buffers_before_offset_skip) { if (vdata->buffer_counter == vdata->buffers_before_offset_skip) {
offset_counter += vdata->offset_skip_amount; vdata->offset_counter += vdata->offset_skip_amount;
} }
} }
if (!vdata->no_metadata) { if (!vdata->no_metadata) {
fail_unless (GST_BUFFER_TIMESTAMP (buffer) == ts_counter); fail_unless (GST_BUFFER_TIMESTAMP (buffer) == vdata->ts_counter);
fail_unless (GST_BUFFER_DURATION (buffer) != 0); fail_unless (GST_BUFFER_DURATION (buffer) != 0);
fail_unless (GST_BUFFER_OFFSET (buffer) == offset_counter); fail_unless (GST_BUFFER_OFFSET (buffer) == vdata->offset_counter);
} }
if (vdata->caps) { if (vdata->caps) {
@ -137,20 +130,25 @@ buffer_verify_data (void *buffer, void *user_data)
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), vdata->caps)); fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), vdata->caps));
} }
ts_counter += GST_BUFFER_DURATION (buffer); vdata->ts_counter += GST_BUFFER_DURATION (buffer);
offset_counter += GST_BUFFER_SIZE (buffer); vdata->offset_counter += GST_BUFFER_SIZE (buffer);
buffer_counter++; vdata->buffer_counter++;
} }
static GstElement * static GstElement *
setup_element (const gchar * factory, GstStaticPadTemplate * sink_template, setup_element (const gchar * factory, ElementSetup setup,
GstStaticPadTemplate * sink_template,
GstCaps * sink_caps, GstStaticPadTemplate * src_template, GstCaps * sink_caps, GstStaticPadTemplate * src_template,
GstCaps * src_caps) GstCaps * src_caps)
{ {
GstElement *element; GstElement *element;
GstBus *bus; GstBus *bus;
if (setup) {
element = setup (factory);
} else {
element = gst_check_setup_element (factory); element = gst_check_setup_element (factory);
}
srcpad = gst_check_setup_src_pad (element, src_template, src_caps); srcpad = gst_check_setup_src_pad (element, src_template, src_caps);
sinkpad = gst_check_setup_sink_pad (element, sink_template, sink_caps); sinkpad = gst_check_setup_sink_pad (element, sink_template, sink_caps);
gst_pad_set_active (srcpad, TRUE); gst_pad_set_active (srcpad, TRUE);
@ -163,7 +161,6 @@ setup_element (const gchar * factory, GstStaticPadTemplate * sink_template,
GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE, GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
"could not set to playing"); "could not set to playing");
ts_counter = offset_counter = buffer_counter = 0;
buffers = NULL; buffers = NULL;
return element; return element;
} }
@ -200,6 +197,7 @@ gst_parser_test_init (GstParserTest * ptest, guint8 * data, guint size,
/* basics */ /* basics */
memset (ptest, 0, sizeof (*ptest)); memset (ptest, 0, sizeof (*ptest));
ptest->factory = ctx_factory; ptest->factory = ctx_factory;
ptest->factory_setup = ctx_setup;
ptest->sink_template = ctx_sink_template; ptest->sink_template = ctx_sink_template;
ptest->src_template = ctx_src_template; ptest->src_template = ctx_src_template;
ptest->framed = TRUE; ptest->framed = TRUE;
@ -224,15 +222,15 @@ gst_parser_test_init (GstParserTest * ptest, guint8 * data, guint size,
void void
gst_parser_test_run (GstParserTest * test, GstCaps ** out_caps) gst_parser_test_run (GstParserTest * test, GstCaps ** out_caps)
{ {
buffer_verify_data_s vdata = { 0, 0, 0, NULL, 0, NULL, FALSE }; buffer_verify_data_s vdata = { 0, 0, 0, NULL, 0, NULL, FALSE, 0, 0, 0 };
GstElement *element; GstElement *element;
GstBuffer *buffer = NULL; GstBuffer *buffer = NULL;
GstCaps *src_caps; GstCaps *src_caps;
guint i, j, k; guint i, j, k;
guint frames = 0, size = 0; guint frames = 0, size = 0;
element = setup_element (test->factory, test->sink_template, NULL, element = setup_element (test->factory, test->factory_setup,
test->src_template, test->src_caps); test->sink_template, NULL, test->src_template, test->src_caps);
/* push some setup headers */ /* push some setup headers */
for (j = 0; j < G_N_ELEMENTS (test->headers) && test->headers[j].data; j++) { for (j = 0; j < G_N_ELEMENTS (test->headers) && test->headers[j].data; j++) {

View file

@ -27,11 +27,29 @@
#define MAX_HEADERS 10 #define MAX_HEADERS 10
typedef struct
{
guint discard;
guint buffers_before_offset_skip;
guint offset_skip_amount;
const guint8 *data_to_verify;
guint data_to_verify_size;
GstCaps *caps;
gboolean no_metadata;
GstClockTime ts_counter;
gint64 offset_counter;
guint buffer_counter;
} buffer_verify_data_s;
typedef struct { typedef struct {
guint8 *data; guint8 *data;
guint size; guint size;
} datablob; } datablob;
typedef gboolean (*VerifyBuffer) (buffer_verify_data_s * vdata, GstBuffer * buf);
typedef GstElement* (*ElementSetup) (const gchar * desc);
/* context state variables; to be set by test using this helper */ /* context state variables; to be set by test using this helper */
/* mandatory */ /* mandatory */
extern const gchar *ctx_factory; extern const gchar *ctx_factory;
@ -44,10 +62,14 @@ extern guint ctx_discard;
extern datablob ctx_headers[MAX_HEADERS]; extern datablob ctx_headers[MAX_HEADERS];
extern gboolean ctx_no_metadata; extern gboolean ctx_no_metadata;
extern VerifyBuffer ctx_verify_buffer;
extern ElementSetup ctx_setup;
/* no refs taken/kept, all up to caller */ /* no refs taken/kept, all up to caller */
typedef struct typedef struct
{ {
const gchar *factory; const gchar *factory;
ElementSetup factory_setup;
GstStaticPadTemplate *sink_template; GstStaticPadTemplate *sink_template;
GstStaticPadTemplate *src_template; GstStaticPadTemplate *src_template;
/* caps that go into element */ /* caps that go into element */