structure: add mapping for (uint) to allow deserialisation of unsigned integers
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Tue, 23 Mar 2010 19:23:22 +0000 (19:23 +0000)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Tue, 23 Mar 2010 19:23:22 +0000 (19:23 +0000)
Unsigned ints are used in taglists, would be nice to be able to
deserialise them, esp. in connection with the taginject API.

gst/gststructure.c
tests/check/gst/gststructure.c

index 521def4..83eb96b 100644 (file)
@@ -1514,6 +1514,10 @@ gst_structure_get_abbrs (gint * n_abbrs)
       ,
       {"i", G_TYPE_INT}
       ,
+      {"uint", G_TYPE_UINT}
+      ,
+      {"u", G_TYPE_UINT}
+      ,
       {"float", G_TYPE_FLOAT}
       ,
       {"f", G_TYPE_FLOAT}
index 8d7b00c..b37bd24 100644 (file)
@@ -73,6 +73,49 @@ GST_START_TEST (test_from_string_int)
 
 GST_END_TEST;
 
+GST_START_TEST (test_from_string_uint)
+{
+  const char *strings[] = {
+    "taglist, bar = (uint) 123456",
+    "taglist, bar = (uint) 0xFFFF",
+    "taglist, bar = (uint) 0x0000FFFF",
+    "taglist, bar = (uint) 0x7FFFFFFF",
+    "taglist, bar = (uint) 0x80000000",
+    "taglist, bar = (uint) 0xFF000000"
+  };
+  guint results[] = {
+    123456,
+    0xFFFF,
+    0xFFFF,
+    0x7FFFFFFF,
+    0x80000000,
+    0xFF000000,
+  };
+  GstStructure *structure;
+  int i;
+
+  for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
+    const char *s;
+    const gchar *name;
+    guint value;
+
+    s = strings[i];
+
+    structure = gst_structure_from_string (s, NULL);
+    fail_if (structure == NULL, "Could not get structure from string %s", s);
+    name = gst_structure_nth_field_name (structure, 0);
+    fail_unless (gst_structure_get_uint (structure, name, &value));
+    fail_unless (value == results[i],
+        "Value %u is not the expected result %u for string %s",
+        value, results[i], s);
+
+    /* cleanup */
+    gst_structure_free (structure);
+  }
+}
+
+GST_END_TEST;
+
 /* Test type conversions from string */
 GST_START_TEST (test_from_string)
 {
@@ -566,6 +609,7 @@ gst_structure_suite (void)
 
   suite_add_tcase (s, tc_chain);
   tcase_add_test (tc_chain, test_from_string_int);
+  tcase_add_test (tc_chain, test_from_string_uint);
   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);