[glib/GVariantType] document and expand GVariantType test case
- From: Ryan Lortie <ryanl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib/GVariantType] document and expand GVariantType test case
- Date: Sat, 23 Jan 2010 01:12:45 +0000 (UTC)
commit cffd508b8906656b0917def0ef46ba8764979c14
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Jan 22 19:31:11 2010 -0500
document and expand GVariantType test case
glib/tests/gvarianttype.c | 43 ++++++++++++++++++++++++++++++++++++-------
1 files changed, 36 insertions(+), 7 deletions(-)
---
diff --git a/glib/tests/gvarianttype.c b/glib/tests/gvarianttype.c
index dc71837..3a49f81 100644
--- a/glib/tests/gvarianttype.c
+++ b/glib/tests/gvarianttype.c
@@ -26,6 +26,10 @@ randomly (gdouble prob)
return g_test_rand_double_range (0, 1) < prob;
}
+/* append a random GVariantType to a GString
+ * append a description of the type to another GString
+ * return what the type is
+ */
static GVariantType *
append_type_string (GString *string,
GString *description,
@@ -310,6 +314,9 @@ invalid_mutation (const gchar *type_string)
}
}
+/* describe a type using the same language as is generated
+ * while generating the type with append_type_string
+ */
static gchar *
describe_type (const GVariantType *type)
{
@@ -448,32 +455,54 @@ test_gvarianttype (void)
for (i = 0; i < 10000; i++)
{
GString *type_string, *description;
+ GVariantType *type, *other_type;
const GVariantType *ctype;
- GVariantType *type;
gchar *invalid;
gchar *desc;
type_string = g_string_new (NULL);
description = g_string_new (NULL);
+ /* generate a random type, its type string and a description
+ *
+ * exercises type constructor functions and g_variant_type_copy()
+ */
type = append_type_string (type_string, description, 6);
+
+ /* convert the type string to a type and ensure that it is equal
+ * to the one produced with the type constructor routines
+ */
+ ctype = G_VARIANT_TYPE (type_string->str);
+ g_assert (g_variant_type_equal (ctype, type));
+ g_assert (g_variant_type_is_subtype_of (ctype, type));
+ g_assert (g_variant_type_is_subtype_of (type, ctype));
+
+ /* describe the type.
+ *
+ * exercises the type iterator interface
+ */
desc = describe_type (type);
+
+ /* make sure the description matches */
g_assert_cmpstr (desc, ==, description->str);
+ g_free (desc);
+ /* make an invalid mutation to the type and make sure the type
+ * validation routines catch it */
invalid = invalid_mutation (type_string->str);
g_assert (g_variant_type_string_is_valid (type_string->str));
g_assert (!g_variant_type_string_is_valid (invalid));
+ g_free (invalid);
- ctype = G_VARIANT_TYPE (type_string->str);
- g_assert (g_variant_type_equal (ctype, type));
- g_assert (g_variant_type_is_subtype_of (ctype, type));
- g_assert (g_variant_type_is_subtype_of (type, ctype));
+ /* concatenate another type to the type string and ensure that
+ * the result is recognised as being invalid
+ */
+ other_type = append_type_string (type_string, description, 2);
g_string_free (description, TRUE);
g_string_free (type_string, TRUE);
+ g_variant_type_free (other_type);
g_variant_type_free (type);
- g_free (invalid);
- g_free (desc);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]