aboutsummaryrefslogtreecommitdiff
path: root/tests/check/gst/gstcontext.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/check/gst/gstcontext.c')
-rw-r--r--tests/check/gst/gstcontext.c90
1 files changed, 20 insertions, 70 deletions
diff --git a/tests/check/gst/gstcontext.c b/tests/check/gst/gstcontext.c
index 702cd03..efdf45f 100644
--- a/tests/check/gst/gstcontext.c
+++ b/tests/check/gst/gstcontext.c
@@ -1,6 +1,7 @@
/* GStreamer
* Copyright (C) 2013 Collabora Ltd.
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ * Copyright (C) 2013 Sebastian Dröge <slomo@circular-chaos.org>
*
* gstcontext.c: Unit test for GstContext
*
@@ -28,7 +29,7 @@ GST_START_TEST (test_basic)
GstStructure *s1;
const GstStructure *s2;
- c1 = gst_context_new ();
+ c1 = gst_context_new ("test", FALSE);
fail_unless (c1 != NULL);
fail_unless (GST_IS_CONTEXT (c1));
s1 = gst_context_writable_structure (c1);
@@ -38,6 +39,8 @@ GST_START_TEST (test_basic)
c2 = gst_context_copy (c1);
fail_unless (c2 != NULL);
fail_unless (GST_IS_CONTEXT (c2));
+ fail_unless (strcmp (gst_context_get_context_type (c1),
+ gst_context_get_context_type (c2)) == 0);
s2 = gst_context_get_structure (c2);
fail_unless (s2 != NULL);
fail_unless (gst_structure_is_equal (s1, s2));
@@ -54,6 +57,8 @@ typedef struct
gboolean set_before_ready;
gboolean set_from_need_context;
gboolean create_self;
+
+ gboolean have_foobar;
} GstContextElement;
typedef struct
@@ -68,8 +73,8 @@ G_DEFINE_TYPE (GstContextElement, gst_context_element, GST_TYPE_ELEMENT);
static void
gst_context_element_set_context (GstElement * element, GstContext * context)
{
- GST_ELEMENT_CLASS (gst_context_element_parent_class)->set_context (element,
- context);
+ if (strcmp (gst_context_get_context_type (context), "foobar") == 0)
+ ((GstContextElement *) element)->have_foobar = TRUE;
}
static GstStateChangeReturn
@@ -80,17 +85,8 @@ gst_context_element_change_state (GstElement * element,
if (transition == GST_STATE_CHANGE_NULL_TO_READY) {
GstContext *context;
- const GstStructure *s;
GstMessage *msg;
- gboolean have_foobar = FALSE;
-
- context = gst_element_get_context (element);
- if (context) {
- s = gst_context_get_structure (context);
- if (gst_structure_has_field (s, "foobar"))
- have_foobar = TRUE;
- gst_context_unref (context);
- }
+ gboolean have_foobar = celement->have_foobar;
if (celement->set_before_ready && !have_foobar)
return GST_STATE_CHANGE_FAILURE;
@@ -104,17 +100,10 @@ gst_context_element_change_state (GstElement * element,
if (!have_foobar) {
/* Here we would first query downstream for a context but we have no pads */
- msg = gst_message_new_need_context (GST_OBJECT (element));
- gst_message_add_context_type (msg, "foobar");
+ msg = gst_message_new_need_context (GST_OBJECT (element), "foobar");
gst_element_post_message (element, msg);
- context = gst_element_get_context (element);
- if (context) {
- s = gst_context_get_structure (context);
- if (gst_structure_has_field (s, "foobar"))
- have_foobar = TRUE;
- gst_context_unref (context);
- }
+ have_foobar = celement->have_foobar;
}
if (celement->set_from_need_context && !have_foobar)
@@ -128,14 +117,7 @@ gst_context_element_change_state (GstElement * element,
return GST_STATE_CHANGE_FAILURE;
if (!have_foobar) {
- GstStructure *s2;
- context = gst_element_get_context (element);
- if (context)
- context = gst_context_make_writable (context);
- else
- context = gst_context_new ();
- s2 = gst_context_writable_structure (context);
- gst_structure_set (s2, "foobar", G_TYPE_INT, 123, NULL);
+ context = gst_context_new ("foobar", FALSE);
gst_element_set_context (element, context);
msg =
gst_message_new_have_context (GST_OBJECT (element),
@@ -172,9 +154,7 @@ GST_START_TEST (test_element_set_before_ready)
{
GstBus *bus;
GstElement *element;
- GstContext *context, *context2;
- GstStructure *s;
- const GstStructure *s2;
+ GstContext *context;
GstMessage *msg;
element = g_object_new (gst_context_element_get_type (), NULL);
@@ -187,9 +167,7 @@ GST_START_TEST (test_element_set_before_ready)
GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS);
fail_if (gst_bus_pop (bus) != NULL);
- context = gst_context_new ();
- s = gst_context_writable_structure (context);
- gst_structure_set (s, "foobar", G_TYPE_INT, 123, NULL);
+ context = gst_context_new ("foobar", FALSE);
gst_element_set_context (element, context);
fail_unless (gst_element_set_state (element,
GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS);
@@ -198,13 +176,9 @@ GST_START_TEST (test_element_set_before_ready)
gst_message_unref (msg);
fail_if (gst_bus_pop (bus) != NULL);
- context2 = gst_element_get_context (element);
- fail_unless (GST_IS_CONTEXT (context2));
- s2 = gst_context_get_structure (context2);
- fail_unless (gst_structure_is_equal (s, s2));
+ fail_unless (((GstContextElement *) element)->have_foobar);
gst_context_unref (context);
- gst_context_unref (context2);
gst_element_set_bus (element, NULL);
fail_unless (gst_element_set_state (element,
@@ -220,23 +194,13 @@ static GstBusSyncReply
sync_handler (GstBus * bus, GstMessage * message, gpointer user_data)
{
if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEED_CONTEXT) {
- guint n;
const gchar *type;
GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
GstContext *context;
- GstStructure *s;
- n = gst_message_get_n_context_types (message);
- fail_unless (n == 1);
- fail_unless (gst_message_parse_nth_context_type (message, 0, &type));
+ fail_unless (gst_message_parse_context_type (message, &type));
fail_unless_equals_string (type, "foobar");
- context = gst_element_get_context (element);
- if (context)
- context = gst_context_make_writable (context);
- else
- context = gst_context_new ();
- s = gst_context_writable_structure (context);
- gst_structure_set (s, "foobar", G_TYPE_INT, 123, NULL);
+ context = gst_context_new ("foobar", FALSE);
gst_element_set_context (element, context);
gst_context_unref (context);
}
@@ -248,8 +212,6 @@ GST_START_TEST (test_element_set_from_need_context)
{
GstBus *bus;
GstElement *element;
- GstContext *context;
- const GstStructure *s;
GstMessage *msg;
element = g_object_new (gst_context_element_get_type (), NULL);
@@ -269,12 +231,7 @@ GST_START_TEST (test_element_set_from_need_context)
gst_message_unref (msg);
fail_if (gst_bus_pop (bus) != NULL);
- context = gst_element_get_context (element);
- fail_unless (GST_IS_CONTEXT (context));
- s = gst_context_get_structure (context);
- fail_unless (gst_structure_has_field (s, "foobar"));
-
- gst_context_unref (context);
+ fail_unless (((GstContextElement *) element)->have_foobar);
gst_element_set_bus (element, NULL);
fail_unless (gst_element_set_state (element,
@@ -291,7 +248,6 @@ GST_START_TEST (test_element_create_self)
GstBus *bus;
GstElement *element;
GstContext *context;
- const GstStructure *s;
GstMessage *msg;
element = g_object_new (gst_context_element_get_type (), NULL);
@@ -309,8 +265,7 @@ GST_START_TEST (test_element_create_self)
gst_bus_pop_filtered (bus, GST_MESSAGE_HAVE_CONTEXT)) != NULL);
gst_message_parse_have_context (msg, &context);
fail_unless (GST_IS_CONTEXT (context));
- s = gst_context_get_structure (context);
- fail_unless (gst_structure_has_field (s, "foobar"));
+ fail_unless_equals_string (gst_context_get_context_type (context), "foobar");
gst_context_unref (context);
gst_message_unref (msg);
fail_unless ((msg =
@@ -318,12 +273,7 @@ GST_START_TEST (test_element_create_self)
gst_message_unref (msg);
fail_if (gst_bus_pop (bus) != NULL);
- context = gst_element_get_context (element);
- fail_unless (GST_IS_CONTEXT (context));
- s = gst_context_get_structure (context);
- fail_unless (gst_structure_has_field (s, "foobar"));
-
- gst_context_unref (context);
+ fail_unless (((GstContextElement *) element)->have_foobar);
gst_element_set_bus (element, NULL);
fail_unless (gst_element_set_state (element,