From 8c230e08f5125a1031266c7be1320490c10b60f4 Mon Sep 17 00:00:00 2001 From: Tim-Philipp Müller Date: Sat, 1 Aug 2009 12:19:41 +0100 Subject: checks: add basic unit test for flvmux, but disable it for now Basic unit test for flvmux. Fails miserably, hence disabled for now. --- tests/check/Makefile.am | 2 + tests/check/elements/.gitignore | 1 + tests/check/elements/flvmux.c | 158 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 tests/check/elements/flvmux.c (limited to 'tests') diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index faff1f09..f765386f 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -126,6 +126,7 @@ check_PROGRAMS = \ $(check_wavpack) VALGRIND_TO_FIX = \ + elements/flvmux \ elements/rtp-payloading TESTS = $(check_PROGRAMS) @@ -133,6 +134,7 @@ TESTS = $(check_PROGRAMS) # these tests don't even pass # autodetect: temporarily disabled because of broken videosinks in -bad noinst_PROGRAMS = \ + elements/flvmux \ elements/autodetect AM_CFLAGS = $(GST_OBJ_CFLAGS) $(GST_CHECK_CFLAGS) $(CHECK_CFLAGS) \ diff --git a/tests/check/elements/.gitignore b/tests/check/elements/.gitignore index e6dde233..88218ae7 100644 --- a/tests/check/elements/.gitignore +++ b/tests/check/elements/.gitignore @@ -22,6 +22,7 @@ deinterleave equalizer gdkpixbufsink flvdemux +flvmux icydemux id3demux id3v2mux diff --git a/tests/check/elements/flvmux.c b/tests/check/elements/flvmux.c new file mode 100644 index 00000000..58810717 --- /dev/null +++ b/tests/check/elements/flvmux.c @@ -0,0 +1,158 @@ +/* GStreamer unit tests for flvmux + * + * Copyright (C) 2009 Tim-Philipp Müller + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#include + +static GstBusSyncReply +error_cb (GstBus * bus, GstMessage * msg, gpointer user_data) +{ + if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) { + GError *err = NULL; + gchar *dbg = NULL; + + gst_message_parse_error (msg, &err, &dbg); + g_error ("ERROR: %s\n%s\n", err->message, dbg); + } + + return GST_BUS_PASS; +} + +static void +handoff_cb (GstElement * element, GstBuffer * buf, GstPad * pad, + gint * p_counter) +{ + *p_counter += 1; + GST_LOG ("counter = %d", *p_counter); + + fail_unless (GST_BUFFER_CAPS (buf) != NULL); +} + +static void +mux_pcm_audio (guint num_buffers, guint repeat) +{ + GstElement *src, *sink, *flvmux, *pipeline; + GstPad *sinkpad, *srcpad; + gint counter; + + GST_LOG ("num_buffers = %u", num_buffers); + + pipeline = gst_pipeline_new ("pipeline"); + fail_unless (pipeline != NULL, "Failed to create pipeline!"); + + /* kids, don't use a sync handler for this at home, really; we do because + * we just want to abort and nothing else */ + gst_bus_set_sync_handler (GST_ELEMENT_BUS (pipeline), error_cb, NULL); + + src = gst_element_factory_make ("audiotestsrc", "audiotestsrc"); + fail_unless (src != NULL, "Failed to create 'audiotestsrc' element!"); + + g_object_set (src, "num-buffers", num_buffers, NULL); + + flvmux = gst_element_factory_make ("flvmux", "flvmux"); + fail_unless (flvmux != NULL, "Failed to create 'flvmux' element!"); + + sink = gst_element_factory_make ("fakesink", "fakesink"); + fail_unless (sink != NULL, "Failed to create 'fakesink' element!"); + + g_object_set (sink, "signal-handoffs", TRUE, NULL); + g_signal_connect (sink, "handoff", G_CALLBACK (handoff_cb), &counter); + + gst_bin_add_many (GST_BIN (pipeline), src, flvmux, sink, NULL); + + /* now link the elements */ + sinkpad = gst_element_get_request_pad (flvmux, "audio"); + fail_unless (sinkpad != NULL, "Could not get audio request pad"); + + srcpad = gst_element_get_static_pad (src, "src"); + fail_unless (srcpad != NULL, "Could not get audiotestsrc's source pad"); + + fail_unless_equals_int (gst_pad_link (srcpad, sinkpad), GST_PAD_LINK_OK); + fail_unless (gst_element_link (flvmux, sink)); + + do { + GstStateChangeReturn state_ret; + GstMessage *msg; + + GST_LOG ("repeat=%d", repeat); + + counter = 0; + + state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED); + fail_unless (state_ret != GST_STATE_CHANGE_FAILURE); + + if (state_ret == GST_STATE_CHANGE_ASYNC) { + GST_LOG ("waiting for pipeline to reach PAUSED state"); + state_ret = gst_element_get_state (pipeline, NULL, NULL, -1); + fail_unless_equals_int (state_ret, GST_STATE_CHANGE_SUCCESS); + } + + GST_LOG ("PAUSED, let's do the rest of it"); + + state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); + fail_unless (state_ret != GST_STATE_CHANGE_FAILURE); + + msg = gst_bus_poll (GST_ELEMENT_BUS (pipeline), GST_MESSAGE_EOS, -1); + fail_unless (msg != NULL, "Expected EOS message on bus!"); + + GST_LOG ("EOS"); + gst_message_unref (msg); + + /* should have some output */ + fail_unless (counter > 2); + + fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL), + GST_STATE_CHANGE_SUCCESS); + + /* repeat = test re-usability */ + --repeat; + } while (repeat > 0); + + gst_object_unref (pipeline); +} + +GST_START_TEST (test_index_writing) +{ + guint bufs; + + /* note: there's a magic 128 value in flvmux when doing index writing */ + for (bufs = 1; bufs < 500; bufs += 33) { + mux_pcm_audio (bufs, 2); + } + + gst_task_cleanup_all (); +} + +GST_END_TEST; + +static Suite * +flvmux_suite (void) +{ + Suite *s = suite_create ("flvmux"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_index_writing); + + return s; +} + +GST_CHECK_MAIN (flvmux) -- cgit