tests: port wavpack tests to 0.11

This commit is contained in:
Mark Nauwelaerts 2012-03-05 12:20:07 +01:00
parent 2f7d8f55a4
commit e637cfb212
5 changed files with 86 additions and 123 deletions

View file

@ -83,7 +83,6 @@ endif
if USE_WAVPACK
check_wavpack = \
elements/wavpackparse \
elements/wavpackdec \
elements/wavpackenc \
pipelines/wavpack
@ -150,6 +149,7 @@ check_PROGRAMS = \
elements/udpsrc \
elements/videocrop \
elements/videofilter \
elements/wavpackparse \
elements/y4menc \
pipelines/simple-launch-lines \
pipelines/effectv \

View file

@ -29,6 +29,12 @@
* get_peer, and then remove references in every test function */
static GstPad *mysrcpad, *mysinkpad;
#if G_BYTE_ORDER == G_BIG_ENDIAN
#define AUDIO_FORMAT "S16BE"
#else
#define AUDIO_FORMAT "S16LE"
#endif
guint8 test_frame[] = {
0x77, 0x76, 0x70, 0x6B, /* "wvpk" */
0x2E, 0x00, 0x00, 0x00, /* ckSize */
@ -51,13 +57,12 @@ guint8 test_frame[] = {
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, "
"width = (int) 16, "
"depth = (int) 16, "
"channels = (int) 1, "
"rate = (int) 44100, "
"endianness = (int) BYTE_ORDER, " "signed = (boolean) true")
GST_STATIC_CAPS ("audio/x-raw, "
"format = (string) " AUDIO_FORMAT ", "
"layout = (string) interleaved, "
"channels = (int) 1, " "rate = (int) 44100")
);
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
@ -73,8 +78,8 @@ setup_wavpackdec (void)
GST_DEBUG ("setup_wavpackdec");
wavpackdec = gst_check_setup_element ("wavpackdec");
mysrcpad = gst_check_setup_src_pad (wavpackdec, &srctemplate, NULL);
mysinkpad = gst_check_setup_sink_pad (wavpackdec, &sinktemplate, NULL);
mysrcpad = gst_check_setup_src_pad (wavpackdec, &srctemplate);
mysinkpad = gst_check_setup_sink_pad (wavpackdec, &sinktemplate);
gst_pad_set_active (mysrcpad, TRUE);
gst_pad_set_active (mysinkpad, TRUE);
@ -100,6 +105,7 @@ GST_START_TEST (test_decode_frame)
GstBuffer *inbuffer, *outbuffer;
GstBus *bus;
int i;
GstMapInfo map;
wavpackdec = setup_wavpackdec ();
@ -109,7 +115,7 @@ GST_START_TEST (test_decode_frame)
bus = gst_bus_new ();
inbuffer = gst_buffer_new_and_alloc (sizeof (test_frame));
memcpy (GST_BUFFER_DATA (inbuffer), test_frame, sizeof (test_frame));
gst_buffer_fill (inbuffer, 0, test_frame, sizeof (test_frame));
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
@ -121,12 +127,17 @@ GST_START_TEST (test_decode_frame)
outbuffer = GST_BUFFER (buffers->data);
fail_if (outbuffer == NULL);
gst_buffer_map (outbuffer, &map, GST_MAP_READ);
/* uncompressed data should be 102400 bytes */
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), 51200);
fail_unless_equals_int (map.size, 51200);
/* and all bytes must be 0, i.e. silence */
for (i = 0; i < 51200; i++)
fail_unless_equals_int (GST_BUFFER_DATA (outbuffer)[i], 0);
fail_unless_equals_int (map.data[i], 0);
gst_buffer_unmap (outbuffer, &map);
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
gst_buffer_unref (outbuffer);
@ -158,9 +169,9 @@ GST_START_TEST (test_decode_frame_with_broken_header)
bus = gst_bus_new ();
inbuffer = gst_buffer_new_and_alloc (sizeof (test_frame));
memcpy (GST_BUFFER_DATA (inbuffer), test_frame, sizeof (test_frame));
gst_buffer_fill (inbuffer, 0, test_frame, sizeof (test_frame));
/* break header */
GST_BUFFER_DATA (inbuffer)[2] = 'e';
gst_buffer_memset (inbuffer, 2, 'e', 1);
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
@ -195,7 +206,7 @@ GST_START_TEST (test_decode_frame_with_incomplete_frame)
bus = gst_bus_new ();
inbuffer = gst_buffer_new_and_alloc (sizeof (test_frame) - 2);
memcpy (GST_BUFFER_DATA (inbuffer), test_frame, sizeof (test_frame) - 2);
gst_buffer_fill (inbuffer, 0, test_frame, sizeof (test_frame) - 2);
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;

View file

@ -30,13 +30,17 @@
static GstPad *mysrcpad, *mysinkpad;
static GstBus *bus;
#define RAW_CAPS_STRING "audio/x-raw-int, " \
"width = (int) 32, " \
"depth = (int) 32, " \
#if G_BYTE_ORDER == G_BIG_ENDIAN
#define AUDIO_FORMAT "S32BE"
#else
#define AUDIO_FORMAT "S32LE"
#endif
#define RAW_CAPS_STRING "audio/x-raw, " \
"format = (string) " AUDIO_FORMAT ", " \
"layout = (string) interleaved, " \
"channels = (int) 1, " \
"rate = (int) 44100, " \
"endianness = (int) BYTE_ORDER, " \
"signed = (boolean) true"
"rate = (int) 44100"
#define WAVPACK_CAPS_STRING "audio/x-wavpack, " \
"width = (int) 32, " \
@ -55,12 +59,10 @@ static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, "
"width = (int) 32, "
"depth = (int) 32, "
"channels = (int) 1, "
"rate = (int) 44100, "
"endianness = (int) BYTE_ORDER, " "signed = (boolean) true"));
GST_STATIC_CAPS ("audio/x-raw, "
"format = (string) " AUDIO_FORMAT ", "
"layout = (string) interleaved, "
"channels = (int) 1, " "rate = (int) 44100"));
static GstElement *
setup_wavpackenc (void)
@ -69,8 +71,8 @@ setup_wavpackenc (void)
GST_DEBUG ("setup_wavpackenc");
wavpackenc = gst_check_setup_element ("wavpackenc");
mysrcpad = gst_check_setup_src_pad (wavpackenc, &srctemplate, NULL);
mysinkpad = gst_check_setup_sink_pad (wavpackenc, &sinktemplate, NULL);
mysrcpad = gst_check_setup_src_pad (wavpackenc, &srctemplate);
mysinkpad = gst_check_setup_sink_pad (wavpackenc, &sinktemplate);
gst_pad_set_active (mysrcpad, TRUE);
gst_pad_set_active (mysinkpad, TRUE);
@ -111,10 +113,9 @@ GST_START_TEST (test_encode_silence)
wavpackenc = setup_wavpackenc ();
inbuffer = gst_buffer_new_and_alloc (1000);
for (i = 0; i < 1000; i++)
GST_BUFFER_DATA (inbuffer)[i] = 0;
gst_buffer_memset (inbuffer, 0, 0, 1000);
caps = gst_caps_from_string (RAW_CAPS_STRING);
gst_buffer_set_caps (inbuffer, caps);
fail_unless (gst_pad_set_caps (mysrcpad, caps));
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
@ -133,7 +134,7 @@ GST_START_TEST (test_encode_silence)
fail_unless_equals_int (GST_BUFFER_TIMESTAMP (outbuffer), 0);
fail_unless_equals_int (GST_BUFFER_DURATION (outbuffer), 5668934);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), "wvpk", 4) == 0,
fail_unless (gst_buffer_memcmp (outbuffer, 0, "wvpk", 4) == 0,
"Failed to encode to valid Wavpack frames");
/* free all buffers */

View file

@ -28,8 +28,6 @@
* src and sink pads we create; otherwise we always have to do get_pad,
* get_peer, and then remove references in every test function */
static GstPad *mysrcpad, *mysinkpad;
static GstBus *bus;
static GstElement *wavpackparse;
/* Wavpack file with 2 frames of silence */
guint8 test_file[] = {
@ -69,99 +67,53 @@ static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-wavpack"));
static void
wavpackparse_found_pad (GstElement * src, GstPad * pad, gpointer data)
{
GstPad *srcpad;
mysinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
fail_if (mysinkpad == NULL, "Couldn't create sinkpad");
srcpad = gst_element_get_static_pad (wavpackparse, "src");
fail_if (srcpad == NULL, "Failed to get srcpad from wavpackparse");
gst_pad_set_chain_function (mysinkpad, gst_check_chain_func);
fail_unless (gst_pad_link (srcpad, mysinkpad) == GST_PAD_LINK_OK,
"Failed to link pads");
gst_pad_set_active (mysinkpad, TRUE);
gst_object_unref (srcpad);
}
static void
static GstElement *
setup_wavpackparse (void)
{
GstPad *sinkpad;
GstElement *wavpackparse;
GST_DEBUG ("setup_wavpackparse");
wavpackparse = gst_element_factory_make ("wavpackparse", "wavpackparse");
fail_if (wavpackparse == NULL, "Could not create wavpackparse");
wavpackparse = gst_check_setup_element ("wavpackparse");
mysrcpad = gst_check_setup_src_pad (wavpackparse, &srctemplate);
mysinkpad = gst_check_setup_sink_pad (wavpackparse, &sinktemplate);
gst_pad_set_active (mysrcpad, TRUE);
gst_pad_set_active (mysinkpad, TRUE);
mysrcpad = gst_pad_new_from_static_template (&srctemplate, "src");
fail_if (mysrcpad == NULL, "Could not create srcpad");
sinkpad = gst_element_get_static_pad (wavpackparse, "sink");
fail_if (sinkpad == NULL, "Failed to get sinkpad from wavpackparse");
fail_unless (gst_pad_link (mysrcpad, sinkpad) == GST_PAD_LINK_OK,
"Failed to link pads");
gst_object_unref (sinkpad);
g_signal_connect (wavpackparse, "pad-added",
G_CALLBACK (wavpackparse_found_pad), NULL);
bus = gst_bus_new ();
gst_element_set_bus (wavpackparse, bus);
fail_unless (gst_element_set_state (wavpackparse,
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
"could not set to playing");
return wavpackparse;
}
static void
cleanup_wavpackparse (void)
cleanup_wavpackparse (GstElement * wavpackparse)
{
GstPad *sinkpad, *srcpad;
GST_DEBUG ("cleanup_wavpackparse");
gst_element_set_state (wavpackparse, GST_STATE_NULL);
gst_bus_set_flushing (bus, TRUE);
gst_element_set_bus (wavpackparse, NULL);
gst_object_unref (GST_OBJECT (bus));
sinkpad = gst_element_get_static_pad (wavpackparse, "sink");
fail_if (sinkpad == NULL, "Failed to get sinkpad from wavpackparse");
fail_unless (gst_pad_unlink (mysrcpad, sinkpad), "Failed to unlink pads");
gst_pad_set_caps (mysrcpad, NULL);
gst_object_unref (sinkpad);
gst_object_unref (mysrcpad);
srcpad = gst_element_get_static_pad (wavpackparse, "src");
fail_if (srcpad == NULL, "Failed to get srcpad from wavpackparse");
fail_unless (gst_pad_unlink (srcpad, mysinkpad), "Failed to unlink pads");
gst_pad_set_caps (mysinkpad, NULL);
gst_object_unref (srcpad);
gst_object_unref (mysinkpad);
fail_unless (gst_element_set_state (wavpackparse, GST_STATE_NULL) ==
GST_STATE_CHANGE_SUCCESS, "could not set to null");
gst_object_unref (wavpackparse);
gst_pad_set_active (mysrcpad, FALSE);
gst_pad_set_active (mysinkpad, FALSE);
gst_check_teardown_src_pad (wavpackparse);
gst_check_teardown_sink_pad (wavpackparse);
gst_check_teardown_element (wavpackparse);
}
GST_START_TEST (test_parsing_valid_frames)
{
GstElement *wavpackparse;
GstBuffer *inbuffer, *outbuffer;
int i, num_buffers;
GstFormat format = GST_FORMAT_DEFAULT;
GstFormat format = GST_FORMAT_TIME;
gint64 pos;
setup_wavpackparse ();
wavpackparse = setup_wavpackparse ();
fail_unless (gst_element_set_state (wavpackparse,
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
"could not set to playing");
inbuffer = gst_buffer_new_and_alloc (sizeof (test_file));
memcpy (GST_BUFFER_DATA (inbuffer), test_file, sizeof (test_file));
gst_buffer_ref (inbuffer);
gst_buffer_fill (inbuffer, 0, test_file, sizeof (test_file));
/* should decode the buffer without problems */
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
gst_buffer_unref (inbuffer);
num_buffers = g_list_length (buffers);
/* should get 2 buffers, each one complete wavpack frame */
@ -171,21 +123,17 @@ GST_START_TEST (test_parsing_valid_frames)
outbuffer = GST_BUFFER (buffers->data);
fail_if (outbuffer == NULL);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), "wvpk", 4) == 0,
fail_unless (gst_buffer_memcmp (outbuffer, 0, "wvpk", 4) == 0,
"Buffer contains no Wavpack frame");
fail_unless_equals_int (GST_BUFFER_DURATION (outbuffer), 580498866);
switch (i) {
case 0:{
fail_unless_equals_int (GST_BUFFER_TIMESTAMP (outbuffer), 0);
fail_unless_equals_int (GST_BUFFER_OFFSET (outbuffer), 0);
fail_unless_equals_int (GST_BUFFER_OFFSET_END (outbuffer), 25600);
break;
}
case 1:{
fail_unless_equals_int (GST_BUFFER_TIMESTAMP (outbuffer), 580498866);
fail_unless_equals_int (GST_BUFFER_OFFSET (outbuffer), 25600);
fail_unless_equals_int (GST_BUFFER_OFFSET_END (outbuffer), 51200);
break;
}
}
@ -196,35 +144,37 @@ GST_START_TEST (test_parsing_valid_frames)
outbuffer = NULL;
}
fail_unless (gst_element_query_position (wavpackparse, &format, &pos),
fail_unless (gst_element_query_position (wavpackparse, format, &pos),
"Position query failed");
fail_unless_equals_int (pos, 51200);
fail_unless (gst_element_query_duration (wavpackparse, &format, NULL),
fail_unless_equals_int64 (pos, 580498866 * 2);
fail_unless (gst_element_query_duration (wavpackparse, format, NULL),
"Duration query failed");
g_list_free (buffers);
buffers = NULL;
cleanup_wavpackparse ();
cleanup_wavpackparse (wavpackparse);
}
GST_END_TEST;
GST_START_TEST (test_parsing_invalid_first_header)
{
GstElement *wavpackparse;
GstBuffer *inbuffer, *outbuffer;
int i, num_buffers;
setup_wavpackparse ();
wavpackparse = setup_wavpackparse ();
fail_unless (gst_element_set_state (wavpackparse,
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
"could not set to playing");
inbuffer = gst_buffer_new_and_alloc (sizeof (test_file));
memcpy (GST_BUFFER_DATA (inbuffer), test_file, sizeof (test_file));
GST_BUFFER_DATA (inbuffer)[0] = 'k';
gst_buffer_ref (inbuffer);
gst_buffer_fill (inbuffer, 0, test_file, sizeof (test_file));
gst_buffer_memset (inbuffer, 0, 'k', 1);
/* should decode the buffer without problems */
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
gst_buffer_unref (inbuffer);
num_buffers = g_list_length (buffers);
@ -235,14 +185,13 @@ GST_START_TEST (test_parsing_invalid_first_header)
outbuffer = GST_BUFFER (buffers->data);
fail_if (outbuffer == NULL);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), "wvpk", 4) == 0,
fail_unless (gst_buffer_memcmp (outbuffer, 0, "wvpk", 4) == 0,
"Buffer contains no Wavpack frame");
fail_unless_equals_int (GST_BUFFER_DURATION (outbuffer), 580498866);
switch (i) {
case 0:{
fail_unless_equals_int (GST_BUFFER_TIMESTAMP (outbuffer), 580498866);
fail_unless_equals_int (GST_BUFFER_OFFSET (outbuffer), 25600);
break;
}
}
@ -256,7 +205,7 @@ GST_START_TEST (test_parsing_invalid_first_header)
g_list_free (buffers);
buffers = NULL;
cleanup_wavpackparse ();
cleanup_wavpackparse (wavpackparse);
}
GST_END_TEST;

View file

@ -96,6 +96,7 @@ GST_START_TEST (test_encode_decode)
GMainLoop *loop;
GstBuffer *in, *out;
guint bus_watch = 0;
GstMapInfo map;
srcadapter = gst_adapter_new ();
fail_unless (srcadapter != NULL);
@ -170,9 +171,10 @@ GST_START_TEST (test_encode_decode)
gst_adapter_available (sinkadapter));
fail_unless (out != NULL);
fail_unless_equals_int (GST_BUFFER_SIZE (in), GST_BUFFER_SIZE (out));
fail_unless (memcmp (GST_BUFFER_DATA (in), GST_BUFFER_DATA (out),
GST_BUFFER_SIZE (in)) == 0);
fail_unless_equals_int (gst_buffer_get_size (in), gst_buffer_get_size (out));
gst_buffer_map (out, &map, GST_MAP_READ);
fail_unless (gst_buffer_memcmp (in, 0, map.data, map.size) == 0);
gst_buffer_unmap (out, &map);
gst_buffer_unref (in);
gst_buffer_unref (out);