{"sample", GST_TYPE_SAMPLE}
,
{"taglist", GST_TYPE_TAG_LIST}
+ ,
+ {"type", G_TYPE_GTYPE}
};
_num = G_N_ELEMENTS (dyn_abbrs);
/* permanently allocate and copy the array now */
g_string_append (s, "%" GST_WRAPPED_PTR_FORMAT);
} else if (g_type_is_a (type, G_TYPE_ENUM)
|| g_type_is_a (type, G_TYPE_FLAGS)) {
- g_string_append (s, "%i");
+ g_string_append_len (s, "%i", 2);
+ } else if (type == G_TYPE_GTYPE) {
+ g_string_append_len (s, "%s", 2);
} else if (type == G_TYPE_POINTER) {
g_string_append_len (s, "%p", 2);
} else {
return res;
}
+/*********
+ * gtype *
+ *********/
+
+static gint
+gst_value_compare_gtype (const GValue * value1, const GValue * value2)
+{
+ if (value1->data[0].v_pointer == value2->data[0].v_pointer)
+ return GST_VALUE_EQUAL;
+ return GST_VALUE_UNORDERED;
+}
+
+static gchar *
+gst_value_serialize_gtype (const GValue * value)
+{
+ return g_strdup (g_type_name (g_value_get_gtype (value)));
+}
+
+static gboolean
+gst_value_deserialize_gtype (GValue * dest, const gchar * s)
+{
+ GType t = g_type_from_name (s);
+ gboolean ret = TRUE;
+
+ if (t == G_TYPE_INVALID)
+ ret = FALSE;
+ if (ret) {
+ g_value_set_gtype (dest, t);
+ }
+ return ret;
+}
+
/****************
* subset *
****************/
/* These initial sizes are used for the tables
* below, and save a couple of reallocs at startup */
-static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 34;
+static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 35;
static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 3;
static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 10;
static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
+ REGISTER_SERIALIZATION (G_TYPE_GTYPE, gtype);
+
g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
gst_value_transform_int_range_string);
g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
GST_END_TEST;
+GST_START_TEST (test_deserialize_gtype)
+{
+ GValue value = { 0 };
+ const char *strings[] = {
+ "gchararray",
+ "gint",
+ };
+ GType results[] = {
+ G_TYPE_STRING,
+ G_TYPE_INT,
+ };
+ int i;
+
+ g_value_init (&value, G_TYPE_GTYPE);
+
+ for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
+ fail_unless (gst_value_deserialize (&value, strings[i]),
+ "could not deserialize %s (%d)", strings[i], i);
+ fail_unless (g_value_get_gtype (&value) == results[i],
+ "resulting value is %" G_GSIZE_FORMAT ", not %" G_GSIZE_FORMAT
+ ", for string %s (%d)",
+ g_value_get_gtype (&value), results[i], strings[i], i);
+ }
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_deserialize_gtype_failures)
+{
+ GValue value = { 0 };
+ const char *strings[] = {
+ "-", /* not a gtype */
+ };
+ int i;
+
+ g_value_init (&value, G_TYPE_GTYPE);
+
+ for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
+ fail_if (gst_value_deserialize (&value, strings[i]),
+ "deserialized %s (%d), while it should have failed", strings[i], i);
+ }
+}
+
+GST_END_TEST;
+
GST_START_TEST (test_deserialize_bitmask)
{
GValue value = { 0 };
tcase_add_test (tc_chain, test_deserialize_guint64);
tcase_add_test (tc_chain, test_deserialize_guchar);
tcase_add_test (tc_chain, test_deserialize_gstfraction);
+ tcase_add_test (tc_chain, test_deserialize_gtype);
+ tcase_add_test (tc_chain, test_deserialize_gtype_failures);
tcase_add_test (tc_chain, test_deserialize_bitmask);
tcase_add_test (tc_chain, test_serialize_flags);
tcase_add_test (tc_chain, test_deserialize_flags);