From c0849df4aca6b51cc8c79f502bfcdb2171a377f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= <olivier.crete@collabora.com>
Date: Wed, 6 Jul 2016 17:28:11 -0400
Subject: [PATCH] tests: Test caps using query

Sending an event can accepted event if the caps were rejected
because the event could be queued and processed later.

Also send a drain query in the caps test to make sure that the
event has been processed.

https://bugzilla.gnome.org/show_bug.cgi?id=781673
---
 tests/check/elements/compositor.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/tests/check/elements/compositor.c b/tests/check/elements/compositor.c
index 97211493d9..95c518f04b 100644
--- a/tests/check/elements/compositor.c
+++ b/tests/check/elements/compositor.c
@@ -385,6 +385,7 @@ GST_START_TEST (test_caps_query_interlaced)
   GstCaps *caps;
   GstCaps *caps_mixed, *caps_progressive, *caps_interleaved;
   GstEvent *caps_event;
+  GstQuery *drain;
 
   caps_interleaved =
       gst_caps_from_string ("video/x-raw, interlace-mode=interleaved");
@@ -420,6 +421,11 @@ GST_START_TEST (test_caps_query_interlaced)
   gst_caps_unref (caps);
   fail_unless (gst_pad_send_event (sinkpad, caps_event));
 
+  /* Send drain query to make sure this is processed */
+  drain = gst_query_new_drain ();
+  gst_pad_query (sinkpad, drain);
+  gst_query_unref (drain);
+
   /* now recheck the interlace-mode */
   gst_object_unref (sinkpad);
   sinkpad = gst_element_get_request_pad (compositor, "sink_%u");
@@ -565,7 +571,6 @@ run_late_caps_set_test (GstCaps * first_caps, GstCaps * expected_query_caps,
   GstStateChangeReturn state_res;
   GstPad *sinkpad_2;
   GstCaps *caps;
-  GstEvent *caps_event;
   GstBus *bus;
   GstMessage *msg;
 
@@ -596,8 +601,9 @@ run_late_caps_set_test (GstCaps * first_caps, GstCaps * expected_query_caps,
   sinkpad_2 = gst_element_get_request_pad (compositor, "sink_%u");
   caps = gst_pad_query_caps (sinkpad_2, NULL);
   fail_unless (gst_caps_is_subset (expected_query_caps, caps));
-  caps_event = gst_event_new_caps (second_caps);
-  fail_unless (gst_pad_send_event (sinkpad_2, caps_event) == accept_caps);
+  gst_caps_unref (caps);
+  caps = gst_pad_query_caps (sinkpad_2, second_caps);
+  fail_unless (gst_caps_is_empty (caps) != accept_caps);
   gst_caps_unref (caps);
   gst_object_unref (sinkpad_2);