From ce661c3b990130129cd5eb30b40321d886e9e025 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Thu, 23 Nov 2023 15:50:08 -0300 Subject: [PATCH] validate: Add support to replace variables in deeply nested structures Part-of: --- .../gst/validate/gst-validate-utils.c | 13 +++++++ .../validate/tests/check/validate/utilities.c | 39 +++++++++++++++---- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c b/subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c index b91e5dd97d..60ae1f906e 100644 --- a/subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c +++ b/subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c @@ -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; diff --git a/subprojects/gst-devtools/validate/tests/check/validate/utilities.c b/subprojects/gst-devtools/validate/tests/check/validate/utilities.c index e6c420a626..5335da2c62 100644 --- a/subprojects/gst-devtools/validate/tests/check/validate/utilities.c +++ b/subprojects/gst-devtools/validate/tests/check/validate/utilities.c @@ -1,17 +1,42 @@ #include #include #include +#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;