validate: Add support to replace variables in deeply nested structures

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5713>
This commit is contained in:
Thibault Saunier 2023-11-23 15:50:08 -03:00
parent 66835031f1
commit ce661c3b99
2 changed files with 45 additions and 7 deletions

View file

@ -1372,6 +1372,19 @@ _structure_set_variables (GQuark field_id, GValue * value, ReplaceData * data)
return TRUE;
}
if (GST_VALUE_HOLDS_STRUCTURE (value)) {
GstStructure *s = gst_structure_copy (gst_value_get_structure (value));
gst_validate_structure_resolve_variables (data->source,
s, data->local_vars, data->flags);
gst_value_set_structure (value, s);
gst_structure_free (s);
return TRUE;
}
if (!G_VALUE_HOLDS_STRING (value))
return TRUE;

View file

@ -1,17 +1,42 @@
#include <gst/check/gstcheck.h>
#include <gst/validate/validate.h>
#include <gst/validate/gst-validate-utils.h>
#include "gst/gststructure.h"
GST_START_TEST (test_resolve_variables)
{
GstStructure *s1 =
gst_structure_from_string ("vars, a=(string)1, b=(string)2", NULL);
GstStructure *s2 = gst_structure_from_string ("test, n=\"$(a)/$(b)\"", NULL);
GstStructure *expected, *variables =
gst_structure_from_string
("vars, a=(string)1, b=(string)2, c=the_c_value", NULL);
GstStructure *struct_with_vars =
gst_structure_from_string ("test, n=\"$(a)/$(b)\"", NULL);
gst_validate_structure_resolve_variables (NULL, s2, s1, 0);
fail_unless_equals_string (gst_structure_get_string (s2, "n"), "1/2");
gst_structure_free (s1);
gst_structure_free (s2);
gst_validate_structure_resolve_variables (NULL, struct_with_vars, variables,
0);
fail_unless_equals_string (gst_structure_get_string (struct_with_vars, "n"),
"1/2");
gst_structure_free (struct_with_vars);
struct_with_vars =
gst_structure_from_string
("test, sub_field=[sub, sub_field=\"$(a)\", subsub_field=[subsub, b_field=\"$(b)\", subsubsub_field=[subsubsub, subsubsubsub_field=\"$(c)\"]]]",
NULL);
gst_validate_structure_resolve_variables (NULL, struct_with_vars, variables,
0);
expected =
gst_structure_from_string
("test, sub_field=[sub, sub_field=(string)1, subsub_field=[subsub, b_field=(string)2, subsubsub_field=[subsubsub, subsubsubsub_field=the_c_value]]]",
NULL);
fail_unless (gst_structure_is_equal (struct_with_vars, expected),
"\nReplaced: `%s`\n!=\nExpected: `%s`",
gst_structure_serialize (struct_with_vars, GST_SERIALIZE_FLAG_NONE),
gst_structure_serialize (expected, GST_SERIALIZE_FLAG_NONE));
gst_structure_free (variables);
gst_structure_free (struct_with_vars);
gst_structure_free (expected);
}
GST_END_TEST;