tests: port some more unit tests

This commit is contained in:
Wim Taymans 2012-01-04 11:28:36 +01:00
parent acfa55df6c
commit a58ecc50e0
7 changed files with 73 additions and 66 deletions

View file

@ -312,13 +312,13 @@ elements_kate_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS)
elements_kate_LDADD = $(GST_BASE_LIBS) $(LDADD)
elements_rtpmux_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS)
elements_rtpmux_LDADD = $(GST_PLUGINS_BASE_LIBS) -lgstrtp-0.10 $(GST_BASE_LIBS) $(LDADD)
elements_rtpmux_LDADD = $(GST_PLUGINS_BASE_LIBS) -lgstrtp-$(GST_MAJORMINOR) $(GST_BASE_LIBS) $(LDADD)
elements_assrender_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS)
elements_assrender_LDADD = $(GST_PLUGINS_BASE_LIBS) -lgstvideo-0.10 -lgstapp-0.10 $(GST_BASE_LIBS) $(LDADD)
elements_assrender_LDADD = $(GST_PLUGINS_BASE_LIBS) -lgstvideo-$(GST_MAJORMINOR) -lgstapp-$(GST_MAJORMINOR) $(GST_BASE_LIBS) $(LDADD)
elements_mpegtsmux_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS)
elements_mpegtsmux_LDADD = $(GST_PLUGINS_BASE_LIBS) -lgstvideo-0.10 $(GST_BASE_LIBS) $(LDADD)
elements_mpegtsmux_LDADD = $(GST_PLUGINS_BASE_LIBS) -lgstvideo-$(GST_MAJORMINOR) $(GST_BASE_LIBS) $(LDADD)
EXTRA_DIST = gst-plugins-bad.supp

View file

@ -163,7 +163,7 @@ check_asfmux_pad (GstStaticPadTemplate * srctemplate,
inbuffer = gst_buffer_new_and_alloc (1);
caps = gst_caps_from_string (src_caps_string);
gst_buffer_set_caps (inbuffer, caps);
gst_pad_set_caps (mysrcpad, caps);
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);

View file

@ -99,10 +99,14 @@ sink_handoff_cb_xRGB (GstElement * object, GstBuffer * buffer, GstPad * pad,
guint *sink_pos = (guint *) user_data;
gboolean contains_text = (*sink_pos == 1 || *sink_pos == 2);
guint i, j;
guint8 *data = GST_BUFFER_DATA (buffer);
guint8 *data;
gsize size;
gboolean all_red = TRUE;
fail_unless_equals_int (GST_BUFFER_SIZE (buffer), 640 * 480 * 4);
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
fail_unless_equals_int (size, 640 * 480 * 4);
for (i = 0; i < 640; i++) {
for (j = 0; j < 480; j++) {
all_red = all_red && (data[i * 480 * 4 + j * 4 + 1] == 255 &&
@ -110,6 +114,7 @@ sink_handoff_cb_xRGB (GstElement * object, GstBuffer * buffer, GstPad * pad,
data[i * 480 * 4 + j * 4 + 3] == 0);
}
}
gst_buffer_unmap (buffer, data, size);
fail_unless (contains_text != all_red,
"Frame %d is incorrect (all red %d, contains text %d)", *sink_pos,
@ -124,25 +129,23 @@ sink_handoff_cb_I420 (GstElement * object, GstBuffer * buffer, GstPad * pad,
guint *sink_pos = (guint *) user_data;
gboolean contains_text = (*sink_pos == 1 || *sink_pos == 2);
guint c, i, j;
guint8 *data = GST_BUFFER_DATA (buffer);
gboolean all_red = TRUE;
guint8 *comp;
gint comp_stride, comp_width, comp_height;
const guint8 color[] = { 81, 90, 240 };
GstVideoInfo info;
GstVideoFrame frame;
fail_unless_equals_int (GST_BUFFER_SIZE (buffer),
gst_video_format_get_size (GST_VIDEO_FORMAT_I420, 640, 480));
gst_video_info_init (&info);
gst_video_info_set_format (&info, GST_VIDEO_FORMAT_I420, 640, 480);
gst_video_frame_map (&frame, &info, buffer, GST_MAP_READ);
for (c = 0; c < 3; c++) {
comp =
data + gst_video_format_get_component_offset (GST_VIDEO_FORMAT_I420, c,
640, 480);
comp_stride =
gst_video_format_get_row_stride (GST_VIDEO_FORMAT_I420, c, 640);
comp_width =
gst_video_format_get_component_width (GST_VIDEO_FORMAT_I420, c, 640);
comp_height =
gst_video_format_get_component_height (GST_VIDEO_FORMAT_I420, c, 480);
comp = GST_VIDEO_FRAME_COMP_DATA (&frame, c);
comp_stride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, c);
comp_width = GST_VIDEO_FRAME_COMP_WIDTH (&frame, c);
comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (&frame, c);
for (i = 0; i < comp_height; i++) {
for (j = 0; j < comp_width; j++) {
@ -150,6 +153,7 @@ sink_handoff_cb_I420 (GstElement * object, GstBuffer * buffer, GstPad * pad,
}
}
}
gst_video_frame_unmap (&frame);
fail_unless (contains_text != all_red,
"Frame %d is incorrect (all red %d, contains text %d)", *sink_pos,
@ -157,20 +161,18 @@ sink_handoff_cb_I420 (GstElement * object, GstBuffer * buffer, GstPad * pad,
*sink_pos = *sink_pos + 1;
}
static void
_dummy_blocked_cb (GstPad * pad, gboolean blocked, gpointer user_data)
{
GST_LOG_OBJECT (pad, "pad blocked: %d", blocked);
}
static gulong probe_id = 0;
static gboolean
src_buffer_probe_cb (GstPad * pad, GstBuffer * buffer, gpointer user_data)
static GstPadProbeReturn
src_buffer_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
{
GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
GstPad *otherpad = GST_PAD (user_data);
if (GST_BUFFER_TIMESTAMP (buffer) == buf1.ts)
gst_pad_set_blocked_async (otherpad, FALSE, _dummy_blocked_cb, NULL);
return TRUE;
gst_pad_remove_probe (otherpad, probe_id);
return GST_PAD_PROBE_OK;
}
#define CREATE_BASIC_TEST(format) \
@ -186,23 +188,27 @@ GST_START_TEST (test_assrender_basic_##format) \
GMainLoop *loop; \
GstPad *pad, *blocked_pad; \
guint bus_watch = 0; \
GstVideoInfo info; \
\
pipeline = gst_pipeline_new ("pipeline"); \
fail_unless (pipeline != NULL); \
\
capsfilter = gst_element_factory_make ("capsfilter", NULL); \
fail_unless (capsfilter != NULL); \
video_caps = \
gst_video_format_new_caps (GST_VIDEO_FORMAT_##format, 640, 480, 25, 1, 1, 1); \
gst_video_info_init (&info); \
gst_video_info_set_format (&info, GST_VIDEO_FORMAT_##format, 640, 480); \
info.fps_n = 25; \
info.fps_d = 1; \
video_caps = gst_video_info_to_caps (&info); \
g_object_set (capsfilter, "caps", video_caps, NULL); \
gst_caps_unref (video_caps); \
blocked_pad = gst_element_get_static_pad (capsfilter, "src"); \
gst_pad_set_blocked_async (blocked_pad, TRUE, _dummy_blocked_cb, NULL); \
gst_pad_add_probe (blocked_pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, NULL, NULL, NULL); \
\
appsrc = gst_element_factory_make ("appsrc", NULL); \
fail_unless (appsrc != NULL); \
buf = gst_buffer_new_and_alloc (strlen (buf0.buf) + 1); \
memcpy (GST_BUFFER_DATA (buf), buf0.buf, GST_BUFFER_SIZE (buf)); \
gst_buffer_fill (buf, 0, buf0.buf, strlen (buf0.buf) + 1); \
GST_BUFFER_TIMESTAMP (buf) = buf0.ts; \
GST_BUFFER_DURATION (buf) = buf0.duration; \
text_caps = \
@ -212,7 +218,7 @@ GST_START_TEST (test_assrender_basic_##format) \
gst_app_src_set_caps (GST_APP_SRC (appsrc), text_caps); \
g_object_set (appsrc, "format", GST_FORMAT_TIME, NULL); \
pad = gst_element_get_static_pad (appsrc, "src"); \
gst_pad_add_buffer_probe_full (pad, G_CALLBACK (src_buffer_probe_cb), \
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER, src_buffer_probe_cb, \
gst_object_ref (blocked_pad), (GDestroyNotify) gst_object_unref); \
gst_object_unref (blocked_pad); \
gst_object_unref (pad); \
@ -251,8 +257,7 @@ GST_START_TEST (test_assrender_basic_##format) \
GST_STATE_CHANGE_SUCCESS); \
\
buf = gst_buffer_new_and_alloc (strlen (buf1.buf) + 1); \
memcpy (GST_BUFFER_DATA (buf), buf1.buf, GST_BUFFER_SIZE (buf)); \
gst_buffer_set_caps (buf, text_caps); \
gst_buffer_fill (buf, 0, buf1.buf, strlen (buf1.buf) + 1); \
GST_BUFFER_TIMESTAMP (buf) = buf1.ts; \
GST_BUFFER_DURATION (buf) = buf1.duration; \
gst_app_src_push_buffer (GST_APP_SRC (appsrc), buf); \

View file

@ -69,8 +69,8 @@ set_autoconvert_factories (GstElement * autoconvert)
for (i = 0; i < G_N_ELEMENTS (desired_features); i++) {
feature =
GST_ELEMENT_FACTORY_CAST (gst_default_registry_find_feature
(desired_features[i], GST_TYPE_ELEMENT_FACTORY));
GST_ELEMENT_FACTORY_CAST (gst_registry_find_feature
(gst_registry_get (), desired_features[i], GST_TYPE_ELEMENT_FACTORY));
fail_if (feature == NULL, "Test element %s was not found in registry",
desired_features[i]);
factories = g_list_prepend (factories, feature);
@ -100,7 +100,7 @@ generate_test_buffer (GstPad * src, TestContext * ctx)
}
buf = gst_buffer_new_and_alloc (4096);
gst_buffer_set_caps (buf, ctx->caps);
gst_pad_set_caps (src, ctx->caps);
GST_LOG ("Pushing test buffer, caps %" GST_PTR_FORMAT, ctx->caps);
fail_unless (gst_pad_push (src, buf) == GST_FLOW_OK);

View file

@ -74,12 +74,12 @@ setup_faac (gboolean adts)
GST_DEBUG ("setup_faac");
faac = gst_check_setup_element ("faac");
mysrcpad = gst_check_setup_src_pad (faac, &srctemplate, NULL);
mysrcpad = gst_check_setup_src_pad (faac, &srctemplate);
if (adts)
mysinkpad = gst_check_setup_sink_pad (faac, &sinktemplate_adts, NULL);
mysinkpad = gst_check_setup_sink_pad (faac, &sinktemplate_adts);
else
mysinkpad = gst_check_setup_sink_pad (faac, &sinktemplate_raw, NULL);
mysinkpad = gst_check_setup_sink_pad (faac, &sinktemplate_raw);
gst_pad_set_active (mysrcpad, TRUE);
gst_pad_set_active (mysinkpad, TRUE);
@ -117,9 +117,9 @@ do_test (gboolean adts)
/* corresponds to audio buffer mentioned in the caps */
inbuffer = gst_buffer_new_and_alloc (1024 * nbuffers * 2 * 2);
/* makes valgrind's memcheck happier */
memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
gst_buffer_memset (inbuffer, 0, 0, 1024 * nbuffers * 2 * 2);
caps = gst_caps_from_string (AUDIO_CAPS_STRING);
gst_buffer_set_caps (inbuffer, caps);
gst_pad_set_caps (mysrcpad, caps);
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
@ -133,14 +133,14 @@ do_test (gboolean adts)
/* clean up buffers */
for (i = 0; i < num_buffers; ++i) {
gint size, header = 0, id;
gint header = 0, id;
gsize size;
guint8 *data;
outbuffer = GST_BUFFER (buffers->data);
fail_if (outbuffer == NULL);
data = GST_BUFFER_DATA (outbuffer);
size = GST_BUFFER_SIZE (outbuffer);
data = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
if (adts) {
gboolean protection;
@ -175,8 +175,10 @@ do_test (gboolean adts)
const GValue *value;
GstBuffer *buf;
gint k;
gsize csize;
guint8 *cdata;
caps = gst_buffer_get_caps (outbuffer);
caps = gst_pad_get_current_caps (mysinkpad);
fail_if (caps == NULL);
s = gst_caps_get_structure (caps, 0);
fail_if (s == NULL);
@ -184,10 +186,10 @@ do_test (gboolean adts)
fail_if (value == NULL);
buf = gst_value_get_buffer (value);
fail_if (buf == NULL);
data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
fail_if (size < 2);
k = GST_READ_UINT16_BE (data);
cdata = gst_buffer_map (buf, &csize, NULL, GST_MAP_READ);
fail_if (csize < 2);
k = GST_READ_UINT16_BE (cdata);
gst_buffer_unmap (buf, cdata, csize);
/* profile, rate, channels */
fail_unless ((k & 0xFFF8) == ((0x02 << 11) | (0x3 << 7) | (0x02 << 3)));
gst_caps_unref (caps);
@ -197,6 +199,7 @@ do_test (gboolean adts)
id = data[header] & (0x7 << 5);
/* allow all but ID_END or ID_LFE */
fail_if (id == 7 || id == 3);
gst_buffer_unmap (outbuffer, data, size);
buffers = g_list_remove (buffers, outbuffer);

View file

@ -61,8 +61,8 @@ setup_faad (void)
GST_DEBUG ("setup_faad");
faad = gst_check_setup_element ("faad");
mysrcpad = gst_check_setup_src_pad (faad, &srctemplate, NULL);
mysinkpad = gst_check_setup_sink_pad (faad, &sinktemplate, NULL);
mysrcpad = gst_check_setup_src_pad (faad, &srctemplate);
mysinkpad = gst_check_setup_sink_pad (faad, &sinktemplate);
gst_pad_set_active (mysrcpad, TRUE);
gst_pad_set_active (mysinkpad, TRUE);
@ -83,7 +83,7 @@ cleanup_faad (GstElement * faad)
}
static void
do_test (GstBuffer * inbuffer)
do_test (GstBuffer * inbuffer, GstCaps * caps)
{
GstElement *faad;
GstBuffer *outbuffer;
@ -97,6 +97,8 @@ do_test (GstBuffer * inbuffer)
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
gst_pad_set_caps (mysrcpad, caps);
/* need to push twice to get faad output */
gst_buffer_ref (inbuffer);
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
@ -115,7 +117,7 @@ do_test (GstBuffer * inbuffer)
outbuffer = GST_BUFFER (buffers->data);
fail_if (outbuffer == NULL);
size = GST_BUFFER_SIZE (outbuffer);
size = gst_buffer_get_size (outbuffer);
/* 2 16-bit channels */
fail_unless (size == 1024 * 2 * 2);
@ -152,18 +154,16 @@ GST_START_TEST (test_adts)
size = sizeof (adts_header);
header_buf = gst_buffer_new_and_alloc (size);
memcpy (GST_BUFFER_DATA (header_buf), adts_header, size);
gst_buffer_fill (header_buf, 0, adts_header, size);
size = sizeof (raw_data_block);
buf = gst_buffer_new_and_alloc (size);
memcpy (GST_BUFFER_DATA (buf), raw_data_block, size);
gst_buffer_fill (buf, 0, raw_data_block, size);
buf = gst_buffer_join (header_buf, buf);
caps = gst_caps_from_string (AAC_CAPS_STRING);
gst_buffer_set_caps (buf, caps);
do_test (buf, caps);
gst_caps_unref (caps);
do_test (buf);
}
GST_END_TEST;
@ -176,18 +176,17 @@ GST_START_TEST (test_raw)
size = sizeof (codec_data);
codec_buf = gst_buffer_new_and_alloc (size);
memcpy (GST_BUFFER_DATA (codec_buf), codec_data, size);
gst_buffer_fill (codec_buf, 0, codec_data, size);
size = sizeof (raw_data_block);
buf = gst_buffer_new_and_alloc (size);
memcpy (GST_BUFFER_DATA (buf), raw_data_block, size);
gst_buffer_fill (buf, 0, raw_data_block, size);
caps = gst_caps_from_string (AAC_CAPS_STRING);
gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, codec_buf, NULL);
gst_buffer_unref (codec_buf);
gst_buffer_set_caps (buf, caps);
gst_caps_unref (caps);
do_test (buf);
do_test (buf, caps);
gst_caps_unref (caps);
}
GST_END_TEST;

View file

@ -45,7 +45,7 @@ setup (void)
ignorelist = g_strsplit (STATE_IGNORE_ELEMENTS, " ", 0);
}
plugins = gst_registry_get_plugin_list (gst_registry_get_default ());
plugins = gst_registry_get_plugin_list (gst_registry_get ());
for (p = plugins; p; p = p->next) {
GstPlugin *plugin = p->data;
@ -54,7 +54,7 @@ setup (void)
continue;
features =
gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
gst_registry_get_feature_list_by_plugin (gst_registry_get (),
gst_plugin_get_name (plugin));
for (f = features; f; f = f->next) {