context: use context on buffers instead of caps
[platform/upstream/gstreamer.git] / tests / check / gst / gstpad.c
index 2c40379..58988ed 100644 (file)
@@ -399,6 +399,100 @@ GST_START_TEST (test_push_linked)
 
 GST_END_TEST;
 
+static GstBuffer *
+buffer_from_string (const gchar * str)
+{
+  guint size;
+  GstBuffer *buf;
+  gpointer data;
+
+  size = strlen (str);
+  buf = gst_buffer_new_and_alloc (size);
+
+  data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
+  memcpy (data, str, size);
+  gst_buffer_unmap (buf, data, size);
+
+  return buf;
+}
+
+static gboolean
+buffer_compare (GstBuffer * buf, const gchar * str, gsize size)
+{
+  gboolean res;
+  gpointer data;
+
+  data = gst_buffer_map (buf, NULL, NULL, GST_MAP_READ);
+  res = memcmp (data, str, size) == 0;
+  GST_DEBUG ("%s <-> %s: %d", (gchar *) data, str, res);
+  gst_buffer_unmap (buf, data, size);
+
+  return res;
+}
+
+GST_START_TEST (test_push_buffer_list_compat)
+{
+  GstPad *src, *sink;
+  GstPadLinkReturn plr;
+  GstCaps *caps;
+  GstBufferList *list;
+  GstBuffer *buffer;
+  guint len;
+
+  /* setup */
+  sink = gst_pad_new ("sink", GST_PAD_SINK);
+  fail_if (sink == NULL);
+  gst_pad_set_chain_function (sink, gst_check_chain_func);
+  /* leave chainlistfunc unset */
+
+  src = gst_pad_new ("src", GST_PAD_SRC);
+  fail_if (src == NULL);
+
+  caps = gst_caps_from_string ("foo/bar");
+
+  gst_pad_set_caps (src, caps);
+  gst_pad_set_caps (sink, caps);
+
+  plr = gst_pad_link (src, sink);
+  fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
+
+  list = gst_buffer_list_new ();
+
+  /* activate pads */
+  gst_pad_set_active (src, TRUE);
+  gst_pad_set_active (sink, TRUE);
+
+  /* test */
+  /* adding to a buffer list will drop the ref to the buffer */
+  len = gst_buffer_list_len (list);
+
+  gst_buffer_list_add (list, buffer_from_string ("ListGroup"));
+  gst_buffer_list_add (list, buffer_from_string ("AnotherListGroup"));
+
+  fail_unless (gst_pad_push_list (src, list) == GST_FLOW_OK);
+  fail_unless_equals_int (g_list_length (buffers), 2);
+  buffer = GST_BUFFER (buffers->data);
+  ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
+  fail_unless (buffer_compare (buffer, "ListGroup", 9));
+  gst_buffer_unref (buffer);
+  buffers = g_list_delete_link (buffers, buffers);
+  buffer = GST_BUFFER (buffers->data);
+  ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
+  fail_unless (buffer_compare (buffer, "AnotherListGroup", 16));
+  gst_buffer_unref (buffer);
+  buffers = g_list_delete_link (buffers, buffers);
+  fail_unless (buffers == NULL);
+
+  /* teardown */
+  gst_pad_unlink (src, sink);
+  gst_object_unref (src);
+  gst_object_unref (sink);
+  ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
+  gst_caps_unref (caps);
+}
+
+GST_END_TEST;
+
 GST_START_TEST (test_flowreturn)
 {
   GstFlowReturn ret;
@@ -406,53 +500,39 @@ GST_START_TEST (test_flowreturn)
 
   /* test some of the macros */
   ret = GST_FLOW_UNEXPECTED;
-  fail_unless (GST_FLOW_IS_FATAL (ret));
-  fail_if (GST_FLOW_IS_SUCCESS (ret));
   fail_if (strcmp (gst_flow_get_name (ret), "unexpected"));
   quark = gst_flow_to_quark (ret);
   fail_if (strcmp (g_quark_to_string (quark), "unexpected"));
 
   ret = GST_FLOW_RESEND;
-  fail_if (GST_FLOW_IS_FATAL (ret));
-  fail_unless (GST_FLOW_IS_SUCCESS (ret));
   fail_if (strcmp (gst_flow_get_name (ret), "resend"));
   quark = gst_flow_to_quark (ret);
   fail_if (strcmp (g_quark_to_string (quark), "resend"));
 
   /* custom returns */
   ret = GST_FLOW_CUSTOM_SUCCESS;
-  fail_if (GST_FLOW_IS_FATAL (ret));
-  fail_unless (GST_FLOW_IS_SUCCESS (ret));
   fail_if (strcmp (gst_flow_get_name (ret), "custom-success"));
   quark = gst_flow_to_quark (ret);
   fail_if (strcmp (g_quark_to_string (quark), "custom-success"));
 
   ret = GST_FLOW_CUSTOM_ERROR;
-  fail_unless (GST_FLOW_IS_FATAL (ret));
-  fail_if (GST_FLOW_IS_SUCCESS (ret));
   fail_if (strcmp (gst_flow_get_name (ret), "custom-error"));
   quark = gst_flow_to_quark (ret);
   fail_if (strcmp (g_quark_to_string (quark), "custom-error"));
 
   /* custom returns clamping */
   ret = GST_FLOW_CUSTOM_SUCCESS + 2;
-  fail_if (GST_FLOW_IS_FATAL (ret));
-  fail_unless (GST_FLOW_IS_SUCCESS (ret));
   fail_if (strcmp (gst_flow_get_name (ret), "custom-success"));
   quark = gst_flow_to_quark (ret);
   fail_if (strcmp (g_quark_to_string (quark), "custom-success"));
 
   ret = GST_FLOW_CUSTOM_ERROR - 2;
-  fail_unless (GST_FLOW_IS_FATAL (ret));
-  fail_if (GST_FLOW_IS_SUCCESS (ret));
   fail_if (strcmp (gst_flow_get_name (ret), "custom-error"));
   quark = gst_flow_to_quark (ret);
   fail_if (strcmp (g_quark_to_string (quark), "custom-error"));
 
   /* unknown values */
   ret = GST_FLOW_CUSTOM_ERROR + 2;
-  fail_unless (GST_FLOW_IS_FATAL (ret));
-  fail_if (GST_FLOW_IS_SUCCESS (ret));
   fail_if (strcmp (gst_flow_get_name (ret), "unknown"));
   quark = gst_flow_to_quark (ret);
   fail_unless (quark == 0);
@@ -500,7 +580,6 @@ GST_START_TEST (test_push_negotiation)
   /* Should fail if src pad caps are incompatible with sink pad caps */
   gst_pad_set_caps (src, caps);
   gst_buffer_ref (buffer);
-  gst_buffer_set_caps (buffer, caps);
   fail_unless (gst_pad_push (src, buffer) == GST_FLOW_NOT_NEGOTIATED);
   ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
   gst_buffer_unref (buffer);
@@ -584,33 +663,6 @@ GST_START_TEST (test_sink_unref_unlink)
 
 GST_END_TEST;
 
-/* gst_pad_get_caps should return a copy of the caps */
-GST_START_TEST (test_get_caps_must_be_copy)
-{
-  GstPad *pad;
-  GstCaps *caps;
-  GstPadTemplate *templ;
-
-  caps = gst_caps_new_any ();
-  templ =
-      gst_pad_template_new ("test_templ", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
-
-  pad = gst_pad_new_from_template (templ, NULL);
-  fail_unless (GST_PAD_CAPS (pad) == NULL, "caps present on pad");
-  /* This is a writable copy ! */
-  caps = gst_pad_get_caps (pad);
-
-  /* we must own the caps */
-  ASSERT_OBJECT_REFCOUNT (caps, "caps", 1);
-
-  /* cleanup */
-  gst_object_unref (templ);
-  gst_caps_unref (caps);
-  gst_object_unref (pad);
-}
-
-GST_END_TEST;
-
 static void
 unblock_async_cb (GstPad * pad, gboolean blocked, gpointer user_data)
 {
@@ -721,6 +773,7 @@ block_async_full_destroy (gpointer user_data)
 
   fail_unless (*state < 2);
 
+  GST_DEBUG ("setting state to 2");
   *state = 2;
 }
 
@@ -730,6 +783,7 @@ block_async_full_cb (GstPad * pad, gboolean blocked, gpointer user_data)
   *(gint *) user_data = (gint) blocked;
 
   gst_pad_push_event (pad, gst_event_new_flush_start ());
+  GST_DEBUG ("setting state to 1");
 }
 
 GST_START_TEST (test_block_async_full_destroy)
@@ -752,14 +806,25 @@ GST_START_TEST (test_block_async_full_destroy)
   fail_unless (state == 1);
   gst_pad_push_event (pad, gst_event_new_flush_stop ());
 
-  /* call with the same user_data, should not call the destroy_notify function
-   */
+  /* pad was already blocked so nothing happens */
   gst_pad_set_blocked_async_full (pad, TRUE, block_async_full_cb,
       &state, block_async_full_destroy);
   fail_unless (state == 1);
 
+  /* unblock with the same data, callback is called */
+  gst_pad_set_blocked_async_full (pad, FALSE, block_async_full_cb,
+      &state, block_async_full_destroy);
+  fail_unless (state == 2);
+
+  /* block with the same data, callback is called */
+  state = 1;
+  gst_pad_set_blocked_async_full (pad, TRUE, block_async_full_cb,
+      &state, block_async_full_destroy);
+  fail_unless (state == 2);
+
   /* now change user_data (to NULL in this case) so destroy_notify should be
    * called */
+  state = 1;
   gst_pad_set_blocked_async_full (pad, FALSE, block_async_full_cb,
       NULL, block_async_full_destroy);
   fail_unless (state == 2);
@@ -904,11 +969,11 @@ gst_pad_suite (void)
   tcase_add_test (tc_chain, test_name_is_valid);
   tcase_add_test (tc_chain, test_push_unlinked);
   tcase_add_test (tc_chain, test_push_linked);
+  tcase_add_test (tc_chain, test_push_buffer_list_compat);
   tcase_add_test (tc_chain, test_flowreturn);
   tcase_add_test (tc_chain, test_push_negotiation);
   tcase_add_test (tc_chain, test_src_unref_unlink);
   tcase_add_test (tc_chain, test_sink_unref_unlink);
-  tcase_add_test (tc_chain, test_get_caps_must_be_copy);
   tcase_add_test (tc_chain, test_block_async);
 #if 0
   tcase_add_test (tc_chain, test_block_async_replace_callback);