GstStructureField *field;
GString *s;
guint i;
+ const gchar *name;
+ gchar *name_esc;
/* NOTE: This function is potentially called by the debug system,
* so any calls to gst_log() (and GST_DEBUG(), GST_LOG(), etc.)
g_return_val_if_fail (structure != NULL, NULL);
s = g_string_new ("");
- /* FIXME this string may need to be escaped */
- g_string_append_printf (s, "\"%s\"", g_quark_to_string (structure->name));
+ /* this string may need to be escaped */
+ name = g_quark_to_string (structure->name);
+ name_esc = g_strescape (name, NULL);
+ if ((strlen (name) < strlen (name_esc)) || strchr (name, ' ')) {
+ g_string_append_printf (s, "\"%s\"", name);
+ } else {
+ g_string_append_printf (s, "%s", name);
+ }
+ g_free (name_esc);
for (i = 0; i < structure->fields->len; i++) {
char *t;
GType type;
t = gst_value_serialize (&field->value);
type = gst_structure_value_get_generic_type (&field->value);
+ /* FIXME: do we need to escape fieldnames? */
g_string_append_printf (s, ", %s=(%s)%s", g_quark_to_string (field->name),
gst_structure_to_abbr (type), GST_STR_NULL (t));
g_free (t);
GST_END_TEST;
+
+GST_START_TEST (test_to_string)
+{
+ GstStructure *st1, *st2;
+ gchar *str;
+
+ /* use structure name and string with spaces, to test escaping/unescaping */
+ st1 = gst_structure_new ("Foo Bar\nwith newline", "num", G_TYPE_INT, 9173,
+ "string", G_TYPE_STRING, "Something Like Face/Off", NULL);
+ str = gst_structure_to_string (st1);
+ st2 = gst_structure_from_string (str, NULL);
+ g_free (str);
+
+ fail_unless (st2 != NULL);
+ fail_unless (!strcmp ("Foo Bar\nwith newline", gst_structure_get_name (st2)));
+
+ gst_structure_free (st2);
+ gst_structure_free (st1);
+}
+
+GST_END_TEST;
+
+
GST_START_TEST (test_to_from_string)
{
GstCaps *caps1, *caps2;
GstStructure *st1, *st2;
- gchar *str, *res1, *res2;;
+ gchar *str, *res1, *res2;
/* use structure name and string with spaces, to test escaping/unescaping */
st1 = gst_structure_new ("Foo Bar", "num", G_TYPE_INT, 9173,
st2 = gst_structure_from_string (str, NULL);
g_free (str);
+ fail_unless (st2 != NULL);
+
/* need to put stuctures into caps to compare */
caps1 = gst_caps_new_empty ();
gst_caps_append_structure (caps1, st1);
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_from_string_int);
tcase_add_test (tc_chain, test_from_string);
+ tcase_add_test (tc_chain, test_to_string);
tcase_add_test (tc_chain, test_to_from_string);
tcase_add_test (tc_chain, test_complete_structure);
tcase_add_test (tc_chain, test_structure_new);