summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.com>2018-02-19 17:50:51 +0000
committerTim-Philipp Müller <tim@centricular.com>2018-02-19 17:50:51 +0000
commitfb77e4db303291b4383e3f3cae4f8c95a00dfd80 (patch)
treea56b458d09f7fb2067521b73da807017385fe911
parent4fe51789578e92ca399de3dfaf8c5f5c808f59ae (diff)
tests: videoscale: simplify test and make it more robust
test_negotiation would occasionally time out, for unknown reasons. Simplify the test setup and get rid of the main loop, busses, and notify signals. With this I can no longer easily reproduce the timeout. Fingers crossed.
-rw-r--r--tests/check/elements/videoscale.c135
1 files changed, 31 insertions, 104 deletions
diff --git a/tests/check/elements/videoscale.c b/tests/check/elements/videoscale.c
index 334664747..190e54368 100644
--- a/tests/check/elements/videoscale.c
+++ b/tests/check/elements/videoscale.c
@@ -499,89 +499,13 @@ CREATE_TEST (test_upscale_1x240_640x480_method_3, 3, 1, 240, 640, 480);
#ifndef VSCALE_TEST_GROUP
-typedef struct
-{
- gint width, height;
- gint par_n, par_d;
- gboolean ok;
- GMainLoop *loop;
-} TestNegotiationData;
-
-static void
-_test_negotiation_message (GstBus * bus, GstMessage * message,
- TestNegotiationData * data)
-{
- GError *err = NULL;
- gchar *debug;
-
- switch (GST_MESSAGE_TYPE (message)) {
- case GST_MESSAGE_ERROR:
- gst_message_parse_error (message, &err, &debug);
- gst_object_default_error (GST_MESSAGE_SRC (message), err, debug);
- g_error_free (err);
- g_free (debug);
- g_assert_not_reached ();
- break;
- case GST_MESSAGE_WARNING:
- gst_message_parse_warning (message, &err, &debug);
- gst_object_default_error (GST_MESSAGE_SRC (message), err, debug);
- g_error_free (err);
- g_free (debug);
- g_assert_not_reached ();
- break;
- case GST_MESSAGE_EOS:
- g_main_loop_quit (data->loop);
- break;
- default:
- break;
- }
-}
-
-static void
-_test_negotiation_notify_caps (GObject * src, GParamSpec * pspec,
- TestNegotiationData * data)
-{
- GstCaps *caps;
- GstStructure *s;
- gint width, height;
- gint par_n = 0, par_d = 0;
-
- g_object_get (src, "caps", &caps, NULL);
- if (caps == NULL)
- return;
-
- s = gst_caps_get_structure (caps, 0);
-
- fail_unless (gst_structure_get_int (s, "width", &width));
- fail_unless (gst_structure_get_int (s, "height", &height));
- fail_unless (gst_structure_get_fraction (s, "pixel-aspect-ratio", &par_n,
- &par_d) || (data->par_n == 1 && data->par_d == 1));
-
- gst_caps_unref (caps);
-
- fail_unless_equals_int (width, data->width);
- fail_unless_equals_int (height, data->height);
- if (par_n != 0 || par_d != 0) {
- fail_unless_equals_int (par_n, data->par_n);
- fail_unless_equals_int (par_d, data->par_d);
- }
-
- data->ok = (width == data->width) && (height == data->height)
- && (par_n == data->par_n) && (par_d == data->par_d);
-
- g_main_loop_quit (data->loop);
-}
-
static void
_test_negotiation (const gchar * src_templ, const gchar * sink_templ,
gint width, gint height, gint par_n, gint par_d)
{
GstElement *pipeline;
GstElement *src, *capsfilter1, *scale, *capsfilter2, *sink;
- GstBus *bus;
- GMainLoop *loop;
GstCaps *caps;
- TestNegotiationData data = { 0, 0, 0, 0, FALSE, NULL };
GstPad *pad;
GST_DEBUG ("Running test for src templ caps '%s' and sink templ caps '%s'",
@@ -592,7 +516,7 @@ _test_negotiation (const gchar * src_templ, const gchar * sink_templ,
src = gst_element_factory_make ("videotestsrc", "src");
fail_unless (src != NULL);
- g_object_set (G_OBJECT (src), "num-buffers", 1, NULL);
+ g_object_set (G_OBJECT (src), "num-buffers", 1, "pattern", 2, NULL);
capsfilter1 = gst_element_factory_make ("capsfilter", "filter1");
fail_unless (capsfilter1 != NULL);
@@ -611,15 +535,8 @@ _test_negotiation (const gchar * src_templ, const gchar * sink_templ,
g_object_set (G_OBJECT (capsfilter2), "caps", caps, NULL);
gst_caps_unref (caps);
- pad = gst_element_get_static_pad (capsfilter2, "sink");
- fail_unless (pad != NULL);
- g_signal_connect (pad, "notify::caps",
- G_CALLBACK (_test_negotiation_notify_caps), &data);
- gst_object_unref (pad);
-
sink = gst_element_factory_make ("fakesink", "sink");
fail_unless (sink != NULL);
- g_object_set (sink, "async", FALSE, NULL);
gst_bin_add_many (GST_BIN (pipeline), src, capsfilter1, scale, capsfilter2,
sink, NULL);
@@ -633,37 +550,47 @@ _test_negotiation (const gchar * src_templ, const gchar * sink_templ,
fail_unless (gst_element_link_pads_full (capsfilter2, "src", sink, "sink",
LINK_CHECK_FLAGS));
- loop = g_main_loop_new (NULL, FALSE);
-
- bus = gst_element_get_bus (pipeline);
- fail_unless (bus != NULL);
- gst_bus_add_signal_watch (bus);
+ fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PAUSED),
+ GST_STATE_CHANGE_ASYNC);
- data.loop = loop;
- data.width = width;
- data.height = height;
- data.par_n = par_n;
- data.par_d = par_d;
- data.ok = FALSE;
+ /* Wait for pipeline to preroll, at which point negotiation is finished */
+ fail_unless_equals_int (gst_element_get_state (pipeline, NULL, NULL, -1),
+ GST_STATE_CHANGE_SUCCESS);
- g_signal_connect (bus, "message", G_CALLBACK (_test_negotiation_message),
- &data);
+ /* Get negotiated caps */
+ pad = gst_element_get_static_pad (capsfilter2, "sink");
+ fail_unless (pad != NULL);
+ caps = gst_pad_get_current_caps (pad);
+ fail_unless (caps != NULL);
+ gst_object_unref (pad);
- gst_bus_remove_signal_watch (bus);
- gst_object_unref (bus);
+ /* Check negotiated caps */
+ {
+ gint out_par_n = 0, out_par_d = 0;
+ gint out_width, out_height;
+ GstStructure *s;
- fail_unless (gst_element_set_state (pipeline,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
+ s = gst_caps_get_structure (caps, 0);
- g_main_loop_run (loop);
+ fail_unless (gst_structure_get_int (s, "width", &out_width));
+ fail_unless (gst_structure_get_int (s, "height", &out_height));
+ fail_unless (gst_structure_get_fraction (s, "pixel-aspect-ratio",
+ &out_par_n, &out_par_d) || (par_n == 1 && par_d == 1));
- fail_unless (data.ok == TRUE);
+ fail_unless_equals_int (width, out_width);
+ fail_unless_equals_int (height, out_height);
+ if (par_n != 0 || par_d != 0) {
+ fail_unless_equals_int (par_n, out_par_n);
+ fail_unless_equals_int (par_d, out_par_d);
+ }
+ }
+ gst_caps_unref (caps);
+ /* clean up */
fail_unless (gst_element_set_state (pipeline,
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
gst_object_unref (pipeline);
- g_main_loop_unref (loop);
}
GST_START_TEST (test_negotiation)