From 4649d28e873ad96833c03c8aa31dbf3da84f0a56 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Sat, 20 Dec 2008 10:55:50 -0500 Subject: bring back test_hash_table_of_hash_tables_of_structures() --- src/eggdbus/eggdbusmessage.c | 9 ++++-- src/tests/testclient.c | 65 ++++++++++++++++++++++++-------------------- src/tests/testfrobimpl.c | 58 +++++++++++++++++++++++++++++++++------ 3 files changed, 90 insertions(+), 42 deletions(-) diff --git a/src/eggdbus/eggdbusmessage.c b/src/eggdbus/eggdbusmessage.c index 8f455d0..6188bc1 100644 --- a/src/eggdbus/eggdbusmessage.c +++ b/src/eggdbus/eggdbusmessage.c @@ -36,6 +36,8 @@ #include #include +#include + typedef struct { EggDBusConnection *connection; @@ -2099,7 +2101,7 @@ egg_dbus_append_value_to_iter (DBusMessageIter *iter, { gboolean ret; - //g_warning ("_append_value_to_iter: sig=%s -> value=%s", sig, g_strdup_value_contents (value)); + //g_debug ("_append_value_to_iter: signature=%s -> value=%s", signature, g_strdup_value_contents (value)); ret = FALSE; @@ -2232,7 +2234,7 @@ egg_dbus_append_value_to_iter (DBusMessageIter *iter, hash_map = EGG_DBUS_HASH_MAP (g_value_get_object (value)); hash_table = hash_map->data; - //g_debug ("value_signature='%s'", value_signature); + //g_debug ("signature='%s' value_signature='%s'", signature, value_signature); dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, signature + 1, &array_iter); g_hash_table_iter_init (&hash_iter, hash_table); @@ -2272,6 +2274,7 @@ egg_dbus_append_value_to_iter (DBusMessageIter *iter, break; } + //g_debug ("value_signature='%s'", value_signature); switch (value_signature[0]) { case DBUS_TYPE_STRING: @@ -2348,7 +2351,7 @@ egg_dbus_append_value_to_iter (DBusMessageIter *iter, } else if (value_signature[1] == DBUS_DICT_ENTRY_BEGIN_CHAR) { - g_value_init (&val, EGG_DBUS_TYPE_ARRAY_SEQ); + g_value_init (&val, EGG_DBUS_TYPE_HASH_MAP); g_value_take_object (&val, hash_value); /* recurse */ if (!egg_dbus_append_value_to_iter (&dict_iter, value_signature, &val, error)) diff --git a/src/tests/testclient.c b/src/tests/testclient.c index e58d6f4..b781821 100644 --- a/src/tests/testclient.c +++ b/src/tests/testclient.c @@ -1304,63 +1304,68 @@ test_hash_table_of_structures (void) /* ---------------------------------------------------------------------------------------------------- */ -#if 0 static void test_hash_table_of_hash_table_of_structures (void) { GError *error; - GHashTable *hash_of_points; - GHashTable *hash_of_hash_of_points; - GHashTable *res_hash_of_hash_of_points; + EggDBusHashMap *hash_of_points; + EggDBusHashMap *hash_of_hash_of_points; + EggDBusHashMap *ret_hash_of_hash_of_points; TestPoint *point; error = NULL; - hash_of_hash_of_points = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_hash_table_unref); - hash_of_points = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); - g_hash_table_insert (hash_of_points, "alpha", test_point_new (10, 10)); - g_hash_table_insert (hash_of_points, "beta", test_point_new (12, 12)); - g_hash_table_insert (hash_of_points, "gamma", test_point_new (14, 14)); - g_hash_table_insert (hash_of_hash_of_points, "org1", hash_of_points); - hash_of_points = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); - g_hash_table_insert (hash_of_points, "rip", test_point_new (1, 1)); - g_hash_table_insert (hash_of_points, "rap", test_point_new (2, 2)); - g_hash_table_insert (hash_of_points, "rup", test_point_new (3, 3)); - g_hash_table_insert (hash_of_hash_of_points, "org2", hash_of_points); - g_assert (test_frob_invoke_test_hash_table_of_hash_tables_of_structures_sync (TEST_QUERY_INTERFACE_FROB (object_proxy), 0, /* flags */ + hash_of_hash_of_points = egg_dbus_hash_map_new (G_TYPE_STRING, NULL, EGG_DBUS_TYPE_HASH_MAP, g_object_unref); + + hash_of_points = egg_dbus_hash_map_new (G_TYPE_STRING, NULL, TEST_TYPE_POINT, g_object_unref); + egg_dbus_hash_map_insert (hash_of_points, "alpha", test_point_new (10, 10)); + egg_dbus_hash_map_insert (hash_of_points, "beta", test_point_new (12, 12)); + egg_dbus_hash_map_insert (hash_of_points, "gamma", test_point_new (14, 14)); + egg_dbus_hash_map_insert (hash_of_hash_of_points, "org1", hash_of_points); + + hash_of_points = egg_dbus_hash_map_new (G_TYPE_STRING, NULL, TEST_TYPE_POINT, g_object_unref); + egg_dbus_hash_map_insert (hash_of_points, "rip", test_point_new (1, 1)); + egg_dbus_hash_map_insert (hash_of_points, "rap", test_point_new (2, 2)); + egg_dbus_hash_map_insert (hash_of_points, "rup", test_point_new (3, 3)); + egg_dbus_hash_map_insert (hash_of_hash_of_points, "org2", hash_of_points); + + g_assert (test_frob_invoke_test_hash_table_of_hash_tables_of_structures_sync (TEST_QUERY_INTERFACE_FROB (object_proxy), + 0, /* flags */ hash_of_hash_of_points, - &res_hash_of_hash_of_points, + &ret_hash_of_hash_of_points, NULL, &error)); g_assert_no_error (error); - g_hash_table_unref (hash_of_hash_of_points); + g_object_unref (hash_of_hash_of_points); - hash_of_points = g_hash_table_lookup (res_hash_of_hash_of_points, "org1_new"); - point = g_hash_table_lookup (hash_of_points, "alpha_new_new"); + hash_of_points = egg_dbus_hash_map_lookup (ret_hash_of_hash_of_points, "org1_new"); + point = egg_dbus_hash_map_lookup (hash_of_points, "alpha_new_new"); g_assert_cmpint (test_point_get_x (point), ==, 10 + 100); g_assert_cmpint (test_point_get_y (point), ==, 10 + 200); - point = g_hash_table_lookup (hash_of_points, "beta_new_new"); + point = egg_dbus_hash_map_lookup (hash_of_points, "beta_new_new"); g_assert_cmpint (test_point_get_x (point), ==, 12 + 100); g_assert_cmpint (test_point_get_y (point), ==, 12 + 200); - point = g_hash_table_lookup (hash_of_points, "gamma_new_new"); + point = egg_dbus_hash_map_lookup (hash_of_points, "gamma_new_new"); g_assert_cmpint (test_point_get_x (point), ==, 14 + 100); g_assert_cmpint (test_point_get_y (point), ==, 14 + 200); - hash_of_points = g_hash_table_lookup (res_hash_of_hash_of_points, "org2_new"); - point = g_hash_table_lookup (hash_of_points, "rip_new_new"); + + hash_of_points = egg_dbus_hash_map_lookup (ret_hash_of_hash_of_points, "org2_new"); + point = egg_dbus_hash_map_lookup (hash_of_points, "rip_new_new"); g_assert_cmpint (test_point_get_x (point), ==, 1 + 100); g_assert_cmpint (test_point_get_y (point), ==, 1 + 200); - point = g_hash_table_lookup (hash_of_points, "rap_new_new"); + point = egg_dbus_hash_map_lookup (hash_of_points, "rap_new_new"); g_assert_cmpint (test_point_get_x (point), ==, 2 + 100); g_assert_cmpint (test_point_get_y (point), ==, 2 + 200); - point = g_hash_table_lookup (hash_of_points, "rup_new_new"); + point = egg_dbus_hash_map_lookup (hash_of_points, "rup_new_new"); g_assert_cmpint (test_point_get_x (point), ==, 3 + 100); g_assert_cmpint (test_point_get_y (point), ==, 3 + 200); - egg_dbus_hash_table_unref (res_hash_of_hash_of_points); + g_object_unref (ret_hash_of_hash_of_points); } /* ---------------------------------------------------------------------------------------------------- */ +#if 0 static void test_array_of_hash_table_of_structures (void) { @@ -4348,8 +4353,8 @@ main (int argc, char *argv[]) */ /* Test collection classes */ - test_egg_dbus_array_seq (); - test_egg_dbus_hash_map (); + //test_egg_dbus_array_seq (); + //test_egg_dbus_hash_map (); /* Tests for code generator * @@ -4386,7 +4391,7 @@ main (int argc, char *argv[]) test_hash_tables (); test_hash_tables_of_arrays (); test_hash_table_of_structures (); - /*test_hash_table_of_hash_table_of_structures ();*/ + test_hash_table_of_hash_table_of_structures (); /*test_array_of_hash_table_of_structures ();*/ /*test_array_of_arrays ();*/ /*test_variant_return ();*/ diff --git a/src/tests/testfrobimpl.c b/src/tests/testfrobimpl.c index 71424f0..5c9b4c4 100644 --- a/src/tests/testfrobimpl.c +++ b/src/tests/testfrobimpl.c @@ -875,17 +875,57 @@ frob_iface_handle_test_hash_table_of_structures (TestFrob *instance, g_object_unref (hash_of_dpoints); } +static gboolean +thtohtos_cb (EggDBusHashMap *hash_map, + const gchar *key, + TestPoint *point, + EggDBusHashMap *new_hash_map) +{ + egg_dbus_hash_map_insert (new_hash_map, + g_strdup_printf ("%s_new_new", key), + test_point_new (test_point_get_x (point) + 100, + test_point_get_y (point) + 200)); + return FALSE; +} + +static void +frob_iface_test_hash_table_of_hash_tables_of_structures (TestFrob *instance, + EggDBusHashMap *hash_of_hash_of_points, + EggDBusMethodInvocation *method_invocation) +{ + EggDBusHashMap *ret_hash_of_hash_of_points; + EggDBusHashMap *hash_of_points; + EggDBusHashMap *new_hash_of_points; + + ret_hash_of_hash_of_points = egg_dbus_hash_map_new (G_TYPE_STRING, NULL, EGG_DBUS_TYPE_HASH_MAP, g_object_unref); + + hash_of_points = egg_dbus_hash_map_lookup (hash_of_hash_of_points, "org1"); + new_hash_of_points = egg_dbus_hash_map_new (G_TYPE_STRING, g_free, TEST_TYPE_POINT, g_object_unref); + egg_dbus_hash_map_foreach (hash_of_points, (EggDBusHashMapForeachFunc) thtohtos_cb, new_hash_of_points); + egg_dbus_hash_map_insert (ret_hash_of_hash_of_points, "org1_new", new_hash_of_points); + + hash_of_points = egg_dbus_hash_map_lookup (hash_of_hash_of_points, "org2"); + new_hash_of_points = egg_dbus_hash_map_new (G_TYPE_STRING, NULL, TEST_TYPE_POINT, g_object_unref); + egg_dbus_hash_map_foreach (hash_of_points, (EggDBusHashMapForeachFunc) thtohtos_cb, new_hash_of_points); + egg_dbus_hash_map_insert (ret_hash_of_hash_of_points, "org2_new", new_hash_of_points); + + test_frob_handle_test_hash_table_of_hash_tables_of_structures_finish (method_invocation, + ret_hash_of_hash_of_points); + + g_object_unref (ret_hash_of_hash_of_points); +} static void test_frob_impl_frob_iface_init (TestFrobIface *iface) { - iface->handle_hello_world = frob_iface_handle_hello_world; - iface->handle_test_primitive_types = frob_iface_handle_test_primitive_types; - iface->handle_test_array_of_primitive_types = frob_iface_handle_test_array_of_primitive_types; - iface->handle_emit_test_signals = frob_iface_handle_emit_test_signals; - iface->handle_test_structure_types = frob_iface_handle_test_structure_types; - iface->handle_test_array_of_structure_types = frob_iface_handle_test_array_of_structure_types; - iface->handle_test_hash_tables = frob_iface_handle_test_hash_tables; - iface->handle_test_hash_tables_of_arrays = frob_iface_handle_test_hash_tables_of_arrays; - iface->handle_test_hash_table_of_structures = frob_iface_handle_test_hash_table_of_structures; + iface->handle_hello_world = frob_iface_handle_hello_world; + iface->handle_test_primitive_types = frob_iface_handle_test_primitive_types; + iface->handle_test_array_of_primitive_types = frob_iface_handle_test_array_of_primitive_types; + iface->handle_emit_test_signals = frob_iface_handle_emit_test_signals; + iface->handle_test_structure_types = frob_iface_handle_test_structure_types; + iface->handle_test_array_of_structure_types = frob_iface_handle_test_array_of_structure_types; + iface->handle_test_hash_tables = frob_iface_handle_test_hash_tables; + iface->handle_test_hash_tables_of_arrays = frob_iface_handle_test_hash_tables_of_arrays; + iface->handle_test_hash_table_of_structures = frob_iface_handle_test_hash_table_of_structures; + iface->handle_test_hash_table_of_hash_tables_of_structures = frob_iface_test_hash_table_of_hash_tables_of_structures; } -- cgit v1.2.3