diff options
| author | Robert McQueen <robot101@debian.org> | 2006-01-27 15:40:36 +0000 | 
|---|---|---|
| committer | Robert McQueen <robot101@debian.org> | 2006-01-27 15:40:36 +0000 | 
| commit | 8e00b10d134e4fb844cdc961e5c3230edf194b57 (patch) | |
| tree | 916ef4ae22231cf4cd6d320fc23a97137ac2a2d6 /test/glib/test-dbus-glib.c | |
| parent | ce13b5dff7208beade01ac06235c263872201c80 (diff) | |
2006-01-27  Robert McQueen  <robot101@debian.org>
	* glib/dbus-gtype-specialized.[ch], glib/dbus-gvalue-utils.c: Patch
	by me and Rob Taylor to add a simple_free function to D-Bus map
	and collection types, which allows those types which can be freed
	with a GDestroyNotify (such as GHashTables and GArrays, but not
	GPtrArrays) to be stored as the values in hashtables.
	* test/glib/test-dbus-glib.c, test/glib/test-service-glib.{c,xml}:
	Patch by Rob Taylor to add nested dicts to the glib tests to check
	the above code works, and appears not to leak when called repeatedly.
Diffstat (limited to 'test/glib/test-dbus-glib.c')
| -rw-r--r-- | test/glib/test-dbus-glib.c | 89 | 
1 files changed, 89 insertions, 0 deletions
diff --git a/test/glib/test-dbus-glib.c b/test/glib/test-dbus-glib.c index 03a1a736..0a99eda2 100644 --- a/test/glib/test-dbus-glib.c +++ b/test/glib/test-dbus-glib.c @@ -1164,6 +1164,95 @@ main (int argc, char **argv)      g_value_unset (variant);    } + +  for (i=0; i<3; i++) +  { +    gchar *val; +    GHashTable *table; +    GHashTable *subtable; +    GHashTable *ret_table; + +    table = g_hash_table_new_full (g_str_hash, g_str_equal, +				   (GDestroyNotify) (g_free), +                                   (GDestroyNotify) (g_hash_table_destroy)); + +    subtable = g_hash_table_new_full (g_str_hash, g_str_equal, +                                      (GDestroyNotify) (g_free), +                                      (GDestroyNotify) (g_free)); +    g_hash_table_insert (subtable, g_strdup ("foo"), g_strdup("1")); +    g_hash_table_insert (subtable, g_strdup ("bar"), g_strdup("2")); +    g_hash_table_insert (subtable, g_strdup ("baz"), g_strdup("3")); + +    g_hash_table_insert (table, g_strdup("dict1"), subtable); + +    subtable = g_hash_table_new_full (g_str_hash, g_str_equal, +                                      (GDestroyNotify) (g_free), +                                      (GDestroyNotify) (g_free)); +    g_hash_table_insert (subtable, g_strdup ("foo"), g_strdup("4")); +    g_hash_table_insert (subtable, g_strdup ("bar"), g_strdup("5")); +    g_hash_table_insert (subtable, g_strdup ("baz"), g_strdup("6")); + +    g_hash_table_insert (table, g_strdup("dict2"), subtable); + +    subtable = NULL; + +    ret_table = NULL; + +    g_print ("Calling DictOfDicts\n"); +    if (!dbus_g_proxy_call (proxy, "DictOfDicts", &error, +			    dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, +                              dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, +                                G_TYPE_STRING)), table, +			    G_TYPE_INVALID, +			    dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, +                              dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, +                                G_TYPE_STRING)), &ret_table, +			    G_TYPE_INVALID)) +      lose_gerror ("Failed to complete DictOfDicts call", error); + +    g_assert (ret_table != NULL); +    g_assert (g_hash_table_size (ret_table) == 2); + +    subtable = g_hash_table_lookup (ret_table, "dict1"); +    g_assert(subtable); +    g_assert (g_hash_table_size (subtable) == 3); + +    val = g_hash_table_lookup (subtable, "foo"); +    g_assert (val != NULL); +    g_assert (!strcmp ("dict1 1", val)); + +    val = g_hash_table_lookup (subtable, "bar"); +    g_assert (val != NULL); +    g_assert (!strcmp ("dict1 2", val)); + +    val = g_hash_table_lookup (subtable, "baz"); +    g_assert (val != NULL); +    g_assert (!strcmp ("dict1 3", val)); + +    subtable = g_hash_table_lookup (ret_table, "dict2"); +    g_assert(subtable); +    g_assert (g_hash_table_size (subtable) == 3); + +    val = g_hash_table_lookup (subtable, "foo"); +    g_assert (val != NULL); +    g_assert (!strcmp ("dict2 4", val)); + +    val = g_hash_table_lookup (subtable, "bar"); +    g_assert (val != NULL); +    g_assert (!strcmp ("dict2 5", val)); + +    val = g_hash_table_lookup (subtable, "baz"); +    g_assert (val != NULL); +    g_assert (!strcmp ("dict2 6", val)); + +    g_hash_table_destroy (table); +    g_hash_table_destroy (ret_table); + +    g_mem_profile (); +  } + + +    /* Signal handling tests */    g_print ("Testing signal handling\n");  | 
