From cd9a3640b2a2551c30d858cb5430797c01f10f31 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Thu, 2 Oct 2014 11:27:30 +0200 Subject: [PATCH] validate:media-descriptor-parser: Add a way to create from a string So it is simple to make use of it from the testsuite https://bugzilla.gnome.org/show_bug.cgi?id=736138 --- .../gst/validate/media-descriptor-parser.c | 51 ++++++++++++++++--- .../gst/validate/media-descriptor-parser.h | 4 ++ 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/validate/gst/validate/media-descriptor-parser.c b/validate/gst/validate/media-descriptor-parser.c index 09bb25551a..27163d4fa3 100644 --- a/validate/gst/validate/media-descriptor-parser.c +++ b/validate/gst/validate/media-descriptor-parser.c @@ -263,26 +263,42 @@ static const GMarkupParser content_parser = { &on_error_cb }; +static gboolean +_set_content (GstMediaDescriptorParser * parser, + const gchar * content, gsize size, GError ** error) +{ + GError *err = NULL; + GstMediaDescriptorParserPrivate *priv = parser->priv; + + priv->parsecontext = g_markup_parse_context_new (&content_parser, + G_MARKUP_TREAT_CDATA_AS_TEXT, parser, NULL); + + if (g_markup_parse_context_parse (priv->parsecontext, content, + size, &err) == FALSE) + goto failed; + + return TRUE; + +failed: + g_propagate_error (error, err); + return FALSE; +} + static gboolean set_xml_path (GstMediaDescriptorParser * parser, const gchar * path, GError ** error) { gsize xmlsize; + gchar *content; GError *err = NULL; GstMediaDescriptorParserPrivate *priv = parser->priv; - if (!g_file_get_contents (path, &priv->xmlcontent, &xmlsize, &err)) + if (!g_file_get_contents (path, &content, &xmlsize, &err)) goto failed; priv->xmlpath = g_strdup (path); - priv->parsecontext = g_markup_parse_context_new (&content_parser, - G_MARKUP_TREAT_CDATA_AS_TEXT, parser, NULL); - if (g_markup_parse_context_parse (priv->parsecontext, priv->xmlcontent, - xmlsize, &err) == FALSE) - goto failed; - - return TRUE; + return _set_content (parser, content, xmlsize, error); failed: g_propagate_error (error, err); @@ -381,6 +397,25 @@ gst_media_descriptor_parser_new (GstValidateRunner * runner, return parser; } +GstMediaDescriptorParser * +gst_media_descriptor_parser_new_from_xml (GstValidateRunner * runner, + const gchar * xml, GError ** error) +{ + GstMediaDescriptorParser *parser; + + parser = g_object_new (GST_TYPE_MEDIA_DESCRIPTOR_PARSER, "validate-runner", + runner, NULL); + if (_set_content (parser, g_strdup (xml), strlen (xml) * sizeof (gchar), + error) == FALSE) { + g_object_unref (parser); + + return NULL; + } + + + return parser; +} + gchar * gst_media_descriptor_parser_get_xml_path (GstMediaDescriptorParser * parser) { diff --git a/validate/gst/validate/media-descriptor-parser.h b/validate/gst/validate/media-descriptor-parser.h index 98c1480821..df35e7862b 100644 --- a/validate/gst/validate/media-descriptor-parser.h +++ b/validate/gst/validate/media-descriptor-parser.h @@ -58,6 +58,10 @@ typedef struct { GstMediaDescriptorParser * gst_media_descriptor_parser_new (GstValidateRunner *runner, const gchar * xmlpath, GError **error); +GstMediaDescriptorParser * +gst_media_descriptor_parser_new_from_xml (GstValidateRunner * runner, + const gchar * xml, + GError ** error); gchar * gst_media_descriptor_parser_get_xml_path (GstMediaDescriptorParser *parser); gboolean gst_media_descriptor_parser_add_stream (GstMediaDescriptorParser *parser, GstPad *pad);