adder: cleanup the tests

Take a first stab at cleaning up the tests. Extract common code. Make sure
we actually verify things.
This commit is contained in:
Stefan Sauer 2017-03-17 21:39:58 +01:00
parent 0b6a933e01
commit d759eb46dc

View file

@ -37,95 +37,91 @@
static GMainLoop *main_loop; static GMainLoop *main_loop;
/* make sure downstream gets a CAPS event before buffers are sent */ /* fixtures */
GST_START_TEST (test_caps)
static void
test_setup (void)
{ {
GstElement *pipeline, *src, *adder, *sink; main_loop = g_main_loop_new (NULL, FALSE);
GstStateChangeReturn state_res; }
static void
test_teardown (void)
{
g_main_loop_unref (main_loop);
main_loop = NULL;
}
/* some test helpers */
static GstElement *
setup_pipeline (GstElement * adder, gint num_srcs)
{
GstElement *pipeline, *src, *sink;
gint i;
pipeline = gst_pipeline_new ("pipeline");
if (!adder) {
adder = gst_element_factory_make ("adder", "adder");
}
sink = gst_element_factory_make ("fakesink", "sink");
gst_bin_add_many (GST_BIN (pipeline), adder, sink, NULL);
gst_element_link (adder, sink);
for (i = 0; i < num_srcs; i++) {
src = gst_element_factory_make ("audiotestsrc", NULL);
g_object_set (src, "wave", 4, NULL); /* silence */
gst_bin_add (GST_BIN (pipeline), src);
gst_element_link (src, adder);
}
return pipeline;
}
static GstCaps *
get_element_sink_pad_caps (GstElement * pipeline, const gchar * element_name)
{
GstElement *sink;
GstCaps *caps; GstCaps *caps;
GstPad *pad; GstPad *pad;
/* build pipeline */ sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
pipeline = gst_pipeline_new ("pipeline");
src = gst_element_factory_make ("audiotestsrc", "src1");
g_object_set (src, "wave", 4, NULL); /* silence */
adder = gst_element_factory_make ("adder", "adder");
sink = gst_element_factory_make ("fakesink", "sink");
gst_bin_add_many (GST_BIN (pipeline), src, adder, sink, NULL);
fail_unless (gst_element_link_many (src, adder, sink, NULL));
/* prepare playing */
state_res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
fail_unless_equals_int (state_res, GST_STATE_CHANGE_ASYNC);
/* wait for preroll */
state_res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
fail_unless_equals_int (state_res, GST_STATE_CHANGE_SUCCESS);
/* check caps on fakesink */
pad = gst_element_get_static_pad (sink, "sink"); pad = gst_element_get_static_pad (sink, "sink");
caps = gst_pad_get_current_caps (pad); caps = gst_pad_get_current_caps (pad);
fail_unless (caps != NULL);
gst_caps_unref (caps);
gst_object_unref (pad); gst_object_unref (pad);
gst_object_unref (sink);
gst_element_set_state (pipeline, GST_STATE_NULL); return caps;
gst_object_unref (pipeline);
} }
GST_END_TEST; static void
set_state_and_wait (GstElement * pipeline, GstState state)
/* check that caps set on the property are honoured */
GST_START_TEST (test_filter_caps)
{ {
GstElement *pipeline, *src, *adder, *sink;
GstStateChangeReturn state_res; GstStateChangeReturn state_res;
GstCaps *filter_caps, *caps;
GstPad *pad;
filter_caps = gst_caps_new_simple ("audio/x-raw", /* prepare paused/playing */
"format", G_TYPE_STRING, GST_AUDIO_NE (F32), state_res = gst_element_set_state (pipeline, state);
"layout", G_TYPE_STRING, "interleaved", ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
"rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 1, NULL);
/* build pipeline */
pipeline = gst_pipeline_new ("pipeline");
src = gst_element_factory_make ("audiotestsrc", NULL);
g_object_set (src, "wave", 4, NULL); /* silence */
adder = gst_element_factory_make ("adder", NULL);
g_object_set (adder, "caps", filter_caps, NULL);
sink = gst_element_factory_make ("fakesink", "sink");
gst_bin_add_many (GST_BIN (pipeline), src, adder, sink, NULL);
fail_unless (gst_element_link_many (src, adder, sink, NULL));
/* prepare playing */
state_res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
fail_unless_equals_int (state_res, GST_STATE_CHANGE_ASYNC);
/* wait for preroll */ /* wait for preroll */
state_res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); state_res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
fail_unless_equals_int (state_res, GST_STATE_CHANGE_SUCCESS); ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* check caps on fakesink */
pad = gst_element_get_static_pad (sink, "sink");
caps = gst_pad_get_current_caps (pad);
fail_unless (caps != NULL);
GST_INFO_OBJECT (pipeline, "received caps: %" GST_PTR_FORMAT, caps);
fail_unless (gst_caps_is_equal_fixed (caps, filter_caps));
gst_caps_unref (caps);
gst_object_unref (pad);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
gst_caps_unref (filter_caps);
} }
GST_END_TEST; static void
play_and_wait (GstElement * pipeline)
{
GstStateChangeReturn state_res;
state_res = gst_element_set_state (pipeline, GST_STATE_PLAYING);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
g_main_loop_run (main_loop);
state_res = gst_element_set_state (pipeline, GST_STATE_NULL);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
}
static void static void
message_received (GstBus * bus, GstMessage * message, GstPipeline * bin) message_received (GstBus * bus, GstMessage * message, GstPipeline * bin)
@ -164,6 +160,63 @@ message_received (GstBus * bus, GstMessage * message, GstPipeline * bin)
} }
/* make sure downstream gets a CAPS event before buffers are sent */
GST_START_TEST (test_caps)
{
GstElement *pipeline;
GstCaps *caps;
/* build pipeline */
pipeline = setup_pipeline (NULL, 1);
/* prepare playing */
set_state_and_wait (pipeline, GST_STATE_PAUSED);
/* check caps on fakesink */
caps = get_element_sink_pad_caps (pipeline, "sink");
fail_unless (caps != NULL);
gst_caps_unref (caps);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
}
GST_END_TEST;
/* check that caps set on the property are honoured */
GST_START_TEST (test_filter_caps)
{
GstElement *pipeline, *adder;
GstCaps *filter_caps, *caps;
filter_caps = gst_caps_new_simple ("audio/x-raw",
"format", G_TYPE_STRING, GST_AUDIO_NE (F32),
"layout", G_TYPE_STRING, "interleaved",
"rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 1, NULL);
/* build pipeline */
adder = gst_element_factory_make ("adder", "adder");
g_object_set (adder, "caps", filter_caps, NULL);
pipeline = setup_pipeline (adder, 1);
/* prepare playing */
set_state_and_wait (pipeline, GST_STATE_PAUSED);
/* check caps on fakesink */
caps = get_element_sink_pad_caps (pipeline, "sink");
fail_unless (caps != NULL);
GST_INFO_OBJECT (pipeline, "received caps: %" GST_PTR_FORMAT, caps);
fail_unless (gst_caps_is_equal_fixed (caps, filter_caps));
gst_caps_unref (caps);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
gst_caps_unref (filter_caps);
}
GST_END_TEST;
static GstFormat format = GST_FORMAT_UNDEFINED; static GstFormat format = GST_FORMAT_UNDEFINED;
static gint64 position = -1; static gint64 position = -1;
@ -186,7 +239,6 @@ test_event_message_received (GstBus * bus, GstMessage * message,
} }
} }
GST_START_TEST (test_event) GST_START_TEST (test_event)
{ {
GstElement *bin, *src1, *src2, *adder, *sink; GstElement *bin, *src1, *src2, *adder, *sink;
@ -246,7 +298,6 @@ GST_START_TEST (test_event)
format = GST_FORMAT_UNDEFINED; format = GST_FORMAT_UNDEFINED;
position = -1; position = -1;
main_loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (bus, "message::segment-done", g_signal_connect (bus, "message::segment-done",
(GCallback) test_event_message_received, bin); (GCallback) test_event_message_received, bin);
g_signal_connect (bus, "message::error", (GCallback) message_received, bin); g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
@ -256,12 +307,7 @@ GST_START_TEST (test_event)
GST_INFO ("starting test"); GST_INFO ("starting test");
/* prepare playing */ /* prepare playing */
state_res = gst_element_set_state (bin, GST_STATE_PAUSED); set_state_and_wait (bin, GST_STATE_PAUSED);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* wait for completion */
state_res = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
res = gst_element_send_event (bin, seek_event); res = gst_element_send_event (bin, seek_event);
fail_unless (res == TRUE, NULL); fail_unless (res == TRUE, NULL);
@ -279,7 +325,6 @@ GST_START_TEST (test_event)
ck_assert_int_eq (position, 2 * GST_SECOND); ck_assert_int_eq (position, 2 * GST_SECOND);
/* cleanup */ /* cleanup */
g_main_loop_unref (main_loop);
gst_consistency_checker_free (chk_1); gst_consistency_checker_free (chk_1);
gst_consistency_checker_free (chk_2); gst_consistency_checker_free (chk_2);
gst_consistency_checker_free (chk_3); gst_consistency_checker_free (chk_3);
@ -295,7 +340,7 @@ static GstEvent *play_seek_event = NULL;
static void static void
test_play_twice_message_received (GstBus * bus, GstMessage * message, test_play_twice_message_received (GstBus * bus, GstMessage * message,
GstPipeline * bin) GstElement * bin)
{ {
gboolean res; gboolean res;
GstStateChangeReturn state_res; GstStateChangeReturn state_res;
@ -307,25 +352,16 @@ test_play_twice_message_received (GstBus * bus, GstMessage * message,
case GST_MESSAGE_SEGMENT_DONE: case GST_MESSAGE_SEGMENT_DONE:
play_count++; play_count++;
if (play_count == 1) { if (play_count == 1) {
state_res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY); state_res = gst_element_set_state (bin, GST_STATE_READY);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE); ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* prepare playing again */ /* prepare playing again */
state_res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED); set_state_and_wait (bin, GST_STATE_PAUSED);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* wait for completion */ res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
state_res =
gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
GST_CLOCK_TIME_NONE);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
res = gst_element_send_event (GST_ELEMENT (bin),
gst_event_ref (play_seek_event));
fail_unless (res == TRUE, NULL); fail_unless (res == TRUE, NULL);
state_res = state_res = gst_element_set_state (bin, GST_STATE_PLAYING);
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE); ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
} else { } else {
g_main_loop_quit (main_loop); g_main_loop_quit (main_loop);
@ -340,35 +376,20 @@ test_play_twice_message_received (GstBus * bus, GstMessage * message,
GST_START_TEST (test_play_twice) GST_START_TEST (test_play_twice)
{ {
GstElement *bin, *src1, *src2, *adder, *sink; GstElement *bin, *adder;
GstBus *bus; GstBus *bus;
gboolean res; gboolean res;
GstStateChangeReturn state_res;
GstPad *srcpad; GstPad *srcpad;
GstStreamConsistency *consist; GstStreamConsistency *consist;
GST_INFO ("preparing test"); GST_INFO ("preparing test");
/* build pipeline */ /* build pipeline */
bin = gst_pipeline_new ("pipeline"); adder = gst_element_factory_make ("adder", "adder");
bin = setup_pipeline (adder, 2);
bus = gst_element_get_bus (bin); bus = gst_element_get_bus (bin);
gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
src1 = gst_element_factory_make ("audiotestsrc", "src1");
g_object_set (src1, "wave", 4, NULL); /* silence */
src2 = gst_element_factory_make ("audiotestsrc", "src2");
g_object_set (src2, "wave", 4, NULL); /* silence */
adder = gst_element_factory_make ("adder", "adder");
sink = gst_element_factory_make ("fakesink", "sink");
gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
res = gst_element_link (src1, adder);
fail_unless (res == TRUE, NULL);
res = gst_element_link (src2, adder);
fail_unless (res == TRUE, NULL);
res = gst_element_link (adder, sink);
fail_unless (res == TRUE, NULL);
srcpad = gst_element_get_static_pad (adder, "src"); srcpad = gst_element_get_static_pad (adder, "src");
consist = gst_consistency_checker_new (srcpad); consist = gst_consistency_checker_new (srcpad);
gst_object_unref (srcpad); gst_object_unref (srcpad);
@ -380,7 +401,6 @@ GST_START_TEST (test_play_twice)
play_count = 0; play_count = 0;
main_loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (bus, "message::segment-done", g_signal_connect (bus, "message::segment-done",
(GCallback) test_play_twice_message_received, bin); (GCallback) test_play_twice_message_received, bin);
g_signal_connect (bus, "message::error", (GCallback) message_received, bin); g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
@ -390,14 +410,7 @@ GST_START_TEST (test_play_twice)
GST_INFO ("starting test"); GST_INFO ("starting test");
/* prepare playing */ /* prepare playing */
state_res = gst_element_set_state (bin, GST_STATE_PAUSED); set_state_and_wait (bin, GST_STATE_PAUSED);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* wait for completion */
state_res =
gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
GST_CLOCK_TIME_NONE);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
res = gst_element_send_event (bin, gst_event_ref (play_seek_event)); res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
fail_unless (res == TRUE, NULL); fail_unless (res == TRUE, NULL);
@ -405,18 +418,11 @@ GST_START_TEST (test_play_twice)
GST_INFO ("seeked"); GST_INFO ("seeked");
/* run pipeline */ /* run pipeline */
state_res = gst_element_set_state (bin, GST_STATE_PLAYING); play_and_wait (bin);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
g_main_loop_run (main_loop);
state_res = gst_element_set_state (bin, GST_STATE_NULL);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
ck_assert_int_eq (play_count, 2); ck_assert_int_eq (play_count, 2);
/* cleanup */ /* cleanup */
g_main_loop_unref (main_loop);
gst_consistency_checker_free (consist); gst_consistency_checker_free (consist);
gst_event_unref (play_seek_event); gst_event_unref (play_seek_event);
gst_bus_remove_signal_watch (bus); gst_bus_remove_signal_watch (bus);
@ -428,7 +434,7 @@ GST_END_TEST;
GST_START_TEST (test_play_twice_then_add_and_play_again) GST_START_TEST (test_play_twice_then_add_and_play_again)
{ {
GstElement *bin, *src1, *src2, *src3, *adder, *sink; GstElement *bin, *src, *adder;
GstBus *bus; GstBus *bus;
gboolean res; gboolean res;
GstStateChangeReturn state_res; GstStateChangeReturn state_res;
@ -439,35 +445,20 @@ GST_START_TEST (test_play_twice_then_add_and_play_again)
GST_INFO ("preparing test"); GST_INFO ("preparing test");
/* build pipeline */ /* build pipeline */
bin = gst_pipeline_new ("pipeline"); adder = gst_element_factory_make ("adder", "adder");
bin = setup_pipeline (adder, 2);
bus = gst_element_get_bus (bin); bus = gst_element_get_bus (bin);
gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
src1 = gst_element_factory_make ("audiotestsrc", "src1");
g_object_set (src1, "wave", 4, NULL); /* silence */
src2 = gst_element_factory_make ("audiotestsrc", "src2");
g_object_set (src2, "wave", 4, NULL); /* silence */
adder = gst_element_factory_make ("adder", "adder");
sink = gst_element_factory_make ("fakesink", "sink");
gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
srcpad = gst_element_get_static_pad (adder, "src"); srcpad = gst_element_get_static_pad (adder, "src");
consist = gst_consistency_checker_new (srcpad); consist = gst_consistency_checker_new (srcpad);
gst_object_unref (srcpad); gst_object_unref (srcpad);
res = gst_element_link (src1, adder);
fail_unless (res == TRUE, NULL);
res = gst_element_link (src2, adder);
fail_unless (res == TRUE, NULL);
res = gst_element_link (adder, sink);
fail_unless (res == TRUE, NULL);
play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME, play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH, GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
GST_SEEK_TYPE_SET, (GstClockTime) 0, GST_SEEK_TYPE_SET, (GstClockTime) 0,
GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND); GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
main_loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (bus, "message::segment-done", g_signal_connect (bus, "message::segment-done",
(GCallback) test_play_twice_message_received, bin); (GCallback) test_play_twice_message_received, bin);
g_signal_connect (bus, "message::error", (GCallback) message_received, bin); g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
@ -481,14 +472,7 @@ GST_START_TEST (test_play_twice_then_add_and_play_again)
GST_INFO ("starting test-loop %d", i); GST_INFO ("starting test-loop %d", i);
/* prepare playing */ /* prepare playing */
state_res = gst_element_set_state (bin, GST_STATE_PAUSED); set_state_and_wait (bin, GST_STATE_PAUSED);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* wait for completion */
state_res =
gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
GST_CLOCK_TIME_NONE);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
res = gst_element_send_event (bin, gst_event_ref (play_seek_event)); res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
fail_unless (res == TRUE, NULL); fail_unless (res == TRUE, NULL);
@ -496,23 +480,17 @@ GST_START_TEST (test_play_twice_then_add_and_play_again)
GST_INFO ("seeked"); GST_INFO ("seeked");
/* run pipeline */ /* run pipeline */
state_res = gst_element_set_state (bin, GST_STATE_PLAYING); play_and_wait (bin);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
g_main_loop_run (main_loop);
state_res = gst_element_set_state (bin, GST_STATE_READY);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
ck_assert_int_eq (play_count, 2); ck_assert_int_eq (play_count, 2);
/* plug another source */ /* plug another source */
if (i == 0) { if (i == 0) {
src3 = gst_element_factory_make ("audiotestsrc", "src3"); src = gst_element_factory_make ("audiotestsrc", NULL);
g_object_set (src3, "wave", 4, NULL); /* silence */ g_object_set (src, "wave", 4, NULL); /* silence */
gst_bin_add (GST_BIN (bin), src3); gst_bin_add (GST_BIN (bin), src);
res = gst_element_link (src3, adder); res = gst_element_link (src, adder);
fail_unless (res == TRUE, NULL); fail_unless (res == TRUE, NULL);
} }
@ -523,7 +501,6 @@ GST_START_TEST (test_play_twice_then_add_and_play_again)
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE); ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* cleanup */ /* cleanup */
g_main_loop_unref (main_loop);
gst_event_unref (play_seek_event); gst_event_unref (play_seek_event);
gst_consistency_checker_free (consist); gst_consistency_checker_free (consist);
gst_bus_remove_signal_watch (bus); gst_bus_remove_signal_watch (bus);
@ -534,23 +511,6 @@ GST_START_TEST (test_play_twice_then_add_and_play_again)
GST_END_TEST; GST_END_TEST;
static void
test_live_seeking_eos_message_received (GstBus * bus, GstMessage * message,
GstPipeline * bin)
{
GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
GST_MESSAGE_SRC (message), message);
switch (message->type) {
case GST_MESSAGE_EOS:
g_main_loop_quit (main_loop);
break;
default:
g_assert_not_reached ();
break;
}
}
static GstElement * static GstElement *
test_live_seeking_try_audiosrc (const gchar * factory_name) test_live_seeking_try_audiosrc (const gchar * factory_name)
{ {
@ -583,7 +543,6 @@ GST_START_TEST (test_live_seeking)
gboolean res; gboolean res;
GstPad *srcpad; GstPad *srcpad;
gint i; gint i;
GstStateChangeReturn state_res;
GstStreamConsistency *consist; GstStreamConsistency *consist;
/* don't use autoaudiosrc, as then we can't set anything here */ /* don't use autoaudiosrc, as then we can't set anything here */
const gchar *audio_src_factories[] = { const gchar *audio_src_factories[] = {
@ -591,10 +550,6 @@ GST_START_TEST (test_live_seeking)
"pulseaudiosrc" "pulseaudiosrc"
}; };
GST_INFO ("preparing test");
main_loop = NULL;
play_seek_event = NULL;
/* build pipeline */ /* build pipeline */
bin = gst_pipeline_new ("pipeline"); bin = gst_pipeline_new ("pipeline");
bus = gst_element_get_bus (bin); bus = gst_element_get_bus (bin);
@ -622,13 +577,9 @@ GST_START_TEST (test_live_seeking)
sink = gst_element_factory_make ("fakesink", "sink"); sink = gst_element_factory_make ("fakesink", "sink");
gst_bin_add_many (GST_BIN (bin), src1, ac1, src2, ac2, adder, sink, NULL); gst_bin_add_many (GST_BIN (bin), src1, ac1, src2, ac2, adder, sink, NULL);
res = gst_element_link (src1, ac1); res = gst_element_link_many (src1, ac1, adder, NULL);
fail_unless (res == TRUE, NULL); fail_unless (res == TRUE, NULL);
res = gst_element_link (ac1, adder); res = gst_element_link_many (src2, ac2, adder, NULL);
fail_unless (res == TRUE, NULL);
res = gst_element_link (src2, ac2);
fail_unless (res == TRUE, NULL);
res = gst_element_link (ac2, adder);
fail_unless (res == TRUE, NULL); fail_unless (res == TRUE, NULL);
res = gst_element_link (adder, sink); res = gst_element_link (adder, sink);
fail_unless (res == TRUE, NULL); fail_unless (res == TRUE, NULL);
@ -638,11 +589,9 @@ GST_START_TEST (test_live_seeking)
GST_SEEK_TYPE_SET, (GstClockTime) 0, GST_SEEK_TYPE_SET, (GstClockTime) 0,
GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND); GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
main_loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (bus, "message::error", (GCallback) message_received, bin); g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
g_signal_connect (bus, "message::warning", (GCallback) message_received, bin); g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
g_signal_connect (bus, "message::eos", g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
(GCallback) test_live_seeking_eos_message_received, bin);
srcpad = gst_element_get_static_pad (adder, "src"); srcpad = gst_element_get_static_pad (adder, "src");
consist = gst_consistency_checker_new (srcpad); consist = gst_consistency_checker_new (srcpad);
@ -656,14 +605,7 @@ GST_START_TEST (test_live_seeking)
GST_INFO ("starting test-loop %d", i); GST_INFO ("starting test-loop %d", i);
/* prepare playing */ /* prepare playing */
state_res = gst_element_set_state (bin, GST_STATE_PAUSED); set_state_and_wait (bin, GST_STATE_PAUSED);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* wait for completion */
state_res =
gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
GST_CLOCK_TIME_NONE);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
res = gst_element_send_event (bin, gst_event_ref (play_seek_event)); res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
fail_unless (res == TRUE, NULL); fail_unless (res == TRUE, NULL);
@ -671,15 +613,7 @@ GST_START_TEST (test_live_seeking)
GST_INFO ("seeked"); GST_INFO ("seeked");
/* run pipeline */ /* run pipeline */
state_res = gst_element_set_state (bin, GST_STATE_PLAYING); play_and_wait (bin);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
GST_INFO ("playing");
g_main_loop_run (main_loop);
state_res = gst_element_set_state (bin, GST_STATE_NULL);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
gst_consistency_checker_reset (consist); gst_consistency_checker_reset (consist);
} }
@ -687,10 +621,7 @@ GST_START_TEST (test_live_seeking)
/* cleanup */ /* cleanup */
GST_INFO ("cleaning up"); GST_INFO ("cleaning up");
gst_consistency_checker_free (consist); gst_consistency_checker_free (consist);
if (main_loop) gst_event_unref (play_seek_event);
g_main_loop_unref (main_loop);
if (play_seek_event)
gst_event_unref (play_seek_event);
gst_bus_remove_signal_watch (bus); gst_bus_remove_signal_watch (bus);
gst_object_unref (bus); gst_object_unref (bus);
gst_object_unref (bin); gst_object_unref (bin);
@ -733,7 +664,6 @@ GST_START_TEST (test_add_pad)
srcpad = gst_element_get_static_pad (adder, "src"); srcpad = gst_element_get_static_pad (adder, "src");
gst_object_unref (srcpad); gst_object_unref (srcpad);
main_loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (bus, "message::segment-done", (GCallback) message_received, g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
bin); bin);
g_signal_connect (bus, "message::error", (GCallback) message_received, bin); g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
@ -743,14 +673,7 @@ GST_START_TEST (test_add_pad)
GST_INFO ("starting test"); GST_INFO ("starting test");
/* prepare playing */ /* prepare playing */
state_res = gst_element_set_state (bin, GST_STATE_PAUSED); set_state_and_wait (bin, GST_STATE_PAUSED);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* wait for completion */
state_res =
gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
GST_CLOCK_TIME_NONE);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* add other element */ /* add other element */
gst_bin_add_many (GST_BIN (bin), src2, NULL); gst_bin_add_many (GST_BIN (bin), src2, NULL);
@ -764,16 +687,9 @@ GST_START_TEST (test_add_pad)
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE); ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* now play all */ /* now play all */
state_res = gst_element_set_state (bin, GST_STATE_PLAYING); play_and_wait (bin);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
g_main_loop_run (main_loop);
state_res = gst_element_set_state (bin, GST_STATE_NULL);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* cleanup */ /* cleanup */
g_main_loop_unref (main_loop);
gst_bus_remove_signal_watch (bus); gst_bus_remove_signal_watch (bus);
gst_object_unref (bus); gst_object_unref (bus);
gst_object_unref (bin); gst_object_unref (bin);
@ -816,7 +732,6 @@ GST_START_TEST (test_remove_pad)
srcpad = gst_element_get_static_pad (adder, "src"); srcpad = gst_element_get_static_pad (adder, "src");
gst_object_unref (srcpad); gst_object_unref (srcpad);
main_loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (bus, "message::segment-done", (GCallback) message_received, g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
bin); bin);
g_signal_connect (bus, "message::error", (GCallback) message_received, bin); g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
@ -846,16 +761,9 @@ GST_START_TEST (test_remove_pad)
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE); ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* now play all */ /* now play all */
state_res = gst_element_set_state (bin, GST_STATE_PLAYING); play_and_wait (bin);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
g_main_loop_run (main_loop);
state_res = gst_element_set_state (bin, GST_STATE_NULL);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* cleanup */ /* cleanup */
g_main_loop_unref (main_loop);
gst_bus_remove_signal_watch (bus); gst_bus_remove_signal_watch (bus);
gst_object_unref (G_OBJECT (bus)); gst_object_unref (G_OBJECT (bus));
gst_object_unref (G_OBJECT (bin)); gst_object_unref (G_OBJECT (bin));
@ -1023,14 +931,7 @@ GST_START_TEST (test_duration_is_max)
GST_BASE_SRC (src[2])->segment.duration = 2000; GST_BASE_SRC (src[2])->segment.duration = 2000;
/* set to playing */ /* set to playing */
state_res = gst_element_set_state (bin, GST_STATE_PLAYING); set_state_and_wait (bin, GST_STATE_PLAYING);
fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
/* wait for completion */
state_res =
gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
GST_CLOCK_TIME_NONE);
fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
res = gst_element_query_duration (GST_ELEMENT (bin), format, &duration); res = gst_element_query_duration (GST_ELEMENT (bin), format, &duration);
fail_unless (res, NULL); fail_unless (res, NULL);
@ -1079,14 +980,7 @@ GST_START_TEST (test_duration_unknown_overrides)
GST_BASE_SRC (src[2])->segment.duration = 2000; GST_BASE_SRC (src[2])->segment.duration = 2000;
/* set to playing */ /* set to playing */
state_res = gst_element_set_state (bin, GST_STATE_PLAYING); set_state_and_wait (bin, GST_STATE_PLAYING);
fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
/* wait for completion */
state_res =
gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
GST_CLOCK_TIME_NONE);
fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
res = gst_element_query_duration (GST_ELEMENT (bin), format, &duration); res = gst_element_query_duration (GST_ELEMENT (bin), format, &duration);
fail_unless (res, NULL); fail_unless (res, NULL);
@ -1127,40 +1021,23 @@ loop_segment_done (GstBus * bus, GstMessage * message, GstElement * bin)
GST_START_TEST (test_loop) GST_START_TEST (test_loop)
{ {
GstElement *bin, *src1, *src2, *adder, *sink; GstElement *bin;
GstBus *bus; GstBus *bus;
GstEvent *seek_event; GstEvent *seek_event;
GstStateChangeReturn state_res;
gboolean res; gboolean res;
GST_INFO ("preparing test"); GST_INFO ("preparing test");
/* build pipeline */ /* build pipeline */
bin = gst_pipeline_new ("pipeline"); bin = setup_pipeline (NULL, 2);
bus = gst_element_get_bus (bin); bus = gst_element_get_bus (bin);
gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
src1 = gst_element_factory_make ("audiotestsrc", "src1");
g_object_set (src1, "wave", 4, NULL); /* silence */
src2 = gst_element_factory_make ("audiotestsrc", "src2");
g_object_set (src2, "wave", 4, NULL); /* silence */
adder = gst_element_factory_make ("adder", "adder");
sink = gst_element_factory_make ("fakesink", "sink");
gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
res = gst_element_link (src1, adder);
fail_unless (res == TRUE, NULL);
res = gst_element_link (src2, adder);
fail_unless (res == TRUE, NULL);
res = gst_element_link (adder, sink);
fail_unless (res == TRUE, NULL);
seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME, seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH, GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
GST_SEEK_TYPE_SET, (GstClockTime) 0, GST_SEEK_TYPE_SET, (GstClockTime) 0,
GST_SEEK_TYPE_SET, (GstClockTime) 1 * GST_SECOND); GST_SEEK_TYPE_SET, (GstClockTime) 1 * GST_SECOND);
main_loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (bus, "message::segment-done", g_signal_connect (bus, "message::segment-done",
(GCallback) loop_segment_done, bin); (GCallback) loop_segment_done, bin);
g_signal_connect (bus, "message::error", (GCallback) message_received, bin); g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
@ -1170,27 +1047,17 @@ GST_START_TEST (test_loop)
GST_INFO ("starting test"); GST_INFO ("starting test");
/* prepare playing */ /* prepare playing */
state_res = gst_element_set_state (bin, GST_STATE_PAUSED); set_state_and_wait (bin, GST_STATE_PAUSED);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
/* wait for completion */
state_res = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
res = gst_element_send_event (bin, seek_event); res = gst_element_send_event (bin, seek_event);
fail_unless (res == TRUE, NULL); fail_unless (res == TRUE, NULL);
/* run pipeline */ /* run pipeline */
state_res = gst_element_set_state (bin, GST_STATE_PLAYING); play_and_wait (bin);
ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
GST_INFO ("running main loop"); fail_unless (looped);
g_main_loop_run (main_loop);
state_res = gst_element_set_state (bin, GST_STATE_NULL);
/* cleanup */ /* cleanup */
g_main_loop_unref (main_loop);
gst_bus_remove_signal_watch (bus); gst_bus_remove_signal_watch (bus);
gst_object_unref (bus); gst_object_unref (bus);
gst_object_unref (bin); gst_object_unref (bin);
@ -1233,9 +1100,8 @@ GST_START_TEST (test_flush_start_flush_stop)
gst_element_link (adder, sink); gst_element_link (adder, sink);
gst_element_set_state (pipeline, GST_STATE_PLAYING); /* prepare playing */
fail_unless (gst_element_get_state (pipeline, NULL, NULL, set_state_and_wait (bin, GST_STATE_PLAYING);
GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_SUCCESS);
adder_src = gst_element_get_static_pad (adder, "src"); adder_src = gst_element_get_static_pad (adder, "src");
fail_if (GST_PAD_IS_FLUSHING (adder_src)); fail_if (GST_PAD_IS_FLUSHING (adder_src));
@ -1283,6 +1149,7 @@ adder_suite (void)
#if 0 #if 0
tcase_add_test (tc_chain, test_flush_start_flush_stop); tcase_add_test (tc_chain, test_flush_start_flush_stop);
#endif #endif
tcase_add_checked_fixture (tc_chain, test_setup, test_teardown);
/* Use a longer timeout */ /* Use a longer timeout */
#ifdef HAVE_VALGRIND #ifdef HAVE_VALGRIND