check: Unit test for EOS message
authorEdward Hervey <edward.hervey@collabora.co.uk>
Mon, 9 Jul 2012 17:59:33 +0000 (19:59 +0200)
committerEdward Hervey <edward.hervey@collabora.co.uk>
Mon, 9 Jul 2012 18:31:45 +0000 (20:31 +0200)
Make sure we get the aggregated message if and only if all sinks
received an EOS event

tests/check/gst/gstbin.c

index cdd4dc2..92cbd87 100644 (file)
@@ -56,6 +56,20 @@ pop_messages (GstBus * bus, int count)
   GST_DEBUG ("popped %d messages", count);
 }
 
+static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS_ANY);
+
+static gpointer
+push_one_eos (GstPad * pad)
+{
+  GST_DEBUG_OBJECT (pad, "Pushing EOS event");
+  gst_pad_push_event (pad, gst_event_new_eos ());
+
+  return NULL;
+}
+
 GST_START_TEST (test_interface)
 {
   GstBin *bin, *bin2;
@@ -126,6 +140,62 @@ GST_START_TEST (test_interface)
 
 GST_END_TEST;
 
+GST_START_TEST (test_eos)
+{
+  GstBus *bus;
+  GstElement *pipeline, *sink1, *sink2;
+  GstMessage *message;
+  GstPad *pad1, *pad2;
+  GThread *thread1, *thread2;
+
+  pipeline = gst_pipeline_new ("test_eos");
+  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
+
+  sink1 = gst_element_factory_make ("fakesink", "sink1");
+  sink2 = gst_element_factory_make ("fakesink", "sink2");
+
+  gst_bin_add_many (GST_BIN (pipeline), sink1, sink2, NULL);
+
+  pad1 = gst_check_setup_src_pad_by_name (sink1, &srctemplate, "sink");
+  pad2 = gst_check_setup_src_pad_by_name (sink2, &srctemplate, "sink");
+
+  gst_pad_set_active (pad1, TRUE);
+  gst_pad_set_active (pad2, TRUE);
+
+  fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
+          GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
+
+  /* Send one EOS to sink1 */
+  thread1 = g_thread_new ("thread1", (GThreadFunc) push_one_eos, pad1);
+
+  /* Make sure the EOS message is not sent */
+  message =
+      gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS, 2 * GST_SECOND);
+  fail_if (message != NULL);
+
+  /* Send one EOS to sink2 */
+  thread2 = g_thread_new ("thread2", (GThreadFunc) push_one_eos, pad2);
+
+  /* Make sure the EOS message is sent then */
+  message = gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS, -1);
+  fail_if (message == NULL);
+  fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS);
+  gst_message_unref (message);
+
+  /* Cleanup */
+  g_thread_join (thread1);
+  g_thread_join (thread2);
+
+  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
+  gst_pad_set_active (pad1, FALSE);
+  gst_pad_set_active (pad2, FALSE);
+  gst_check_teardown_src_pad (sink1);
+  gst_check_teardown_src_pad (sink2);
+  gst_object_unref (pipeline);
+}
+
+GST_END_TEST;
+
 GST_START_TEST (test_message_state_changed)
 {
   GstBin *bin;
@@ -1280,6 +1350,7 @@ gst_bin_suite (void)
 
   suite_add_tcase (s, tc_chain);
   tcase_add_test (tc_chain, test_interface);
+  tcase_add_test (tc_chain, test_eos);
   tcase_add_test (tc_chain, test_children_state_change_order_flagged_sink);
   tcase_add_test (tc_chain, test_children_state_change_order_semi_sink);
   tcase_add_test (tc_chain, test_children_state_change_order_two_sink);