dbus/test/glib test-service-glib.xml, 1.9, 1.10 test-service-glib.c, 1.19, 1.20 test-dbus-glib.c, 1.27, 1.28

Colin Walters walters at freedesktop.org
Sat Jul 9 11:46:53 EST 2005


Update of /cvs/dbus/dbus/test/glib
In directory gabe:/tmp/cvs-serv9015/test/glib

Modified Files:
	test-service-glib.xml test-service-glib.c test-dbus-glib.c 
Log Message:
2005-07-08  Colin Walters  <walters at verbum.org>

	* test/glib/test-service-glib.xml: 
	* test/glib/test-service-glib.c:
	* test/glib/test-dbus-glib.c: Test a{sv}.

	* glib/examples/statemachine/statemachine.c:
	* glib/examples/statemachine/statemachine-server.c:
	* glib/examples/statemachine/statemachine-client.c: Fix some bugs,
	add progress bar, etc.

	* glib/dbus-gvalue.c (register_array, register_dict): Delete; not
	needed anymore due to generic array/map marshalling.
	(dbus_g_value_types_init): Don't register basic arrays or the
	string/string hash.
	(dbus_gtype_from_signature_iter): Don't try to recurse into
	variants.
	(dbus_gtype_to_signature): Check collection/map before type
	metadata.
	(demarshal_garray_basic): Renamed to demarshal_collection_array.
	(demarshal_ghashtable): Renamed to demarshal_map; fix to use new
	generic map creation/append functions instead of hash table
	specifically.
	(get_type_demarshaller): Handle maps.
	(demarshal_collection): Dispatch on collection type to either
	demarshal_collection_ptrarray or demarshal_collection_array.
	(get_type_marshaller): Handle maps.
	(marshal_collection): Dispatch collection type to either
	marshal_collection_ptrarray or marshal_collection_array.
	(_dbus_gvalue_test): New test.

	* glib/dbus-gvalue-utils.c (unset_and_free_g_value): New function.
	(hash_free_from_gtype): Use it to free GValues.
	(hashtable_append): New function.
	(ptrarray_append): Fix prototype.
	(slist_append): Ditto.
	(_dbus_gvalue_utils_test): Extend tests.

	* glib/dbus-gtype-specialized.c
	(dbus_g_type_specialized_init_append): Renamed from
	dbus_g_type_specialized_collection_init_append.  Remove const from
	value, since we steal it.
	(dbus_g_type_specialized_map_append): New function.

	* glib/dbus-gtype-specialized.h: Update prototypes.
	Add DBusGTypeSpecializedMapAppendFunc.

	* glib/dbus-gtest.c (dbus_glib_internal_do_not_use_run_tests): Run
	_dbus_gvalue_test.
	
	* glib/dbus-gtest.h: Prototype it.


Index: test-service-glib.xml
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/test-service-glib.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- test-service-glib.xml	8 Jul 2005 16:25:30 -0000	1.9
+++ test-service-glib.xml	9 Jul 2005 01:46:51 -0000	1.10
@@ -95,6 +95,11 @@
       <arg type="u" direction="out" />
     </method>
 
+    <method name="ManyStringify">
+      <arg type="a{sv}" direction="in"/>
+      <arg type="a{sv}" direction="out"/>
+    </method>
+
     <method name="EmitFrobnicate">
     </method>
 

Index: test-service-glib.c
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/test-service-glib.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- test-service-glib.c	8 Jul 2005 16:25:30 -0000	1.19
+++ test-service-glib.c	9 Jul 2005 01:46:51 -0000	1.20
@@ -63,6 +63,8 @@
 gboolean my_object_recursive1 (MyObject *obj, GArray *array, guint32 *len_ret, GError **error);
 gboolean my_object_recursive2 (MyObject *obj, guint32 reqlen, GArray **array, GError **error);
 
+gboolean my_object_many_stringify (MyObject *obj, GHashTable *vals, GHashTable **ret, GError **error);
+
 gboolean my_object_objpath (MyObject *obj, const char *in, char **arg1, GError **error);
 
 gboolean my_object_get_objs (MyObject *obj, GPtrArray **objs, GError **error);
@@ -397,6 +399,38 @@
   return TRUE;
 }
 
+static void
+hash_foreach_stringify (gpointer key, gpointer val, gpointer user_data)
+{
+  const char *keystr = key;
+  const GValue *value = val;
+  GValue *sval;
+  GHashTable *ret = user_data;
+
+  sval = g_new0 (GValue, 1);
+  g_value_init (sval, G_TYPE_STRING);
+  if (!g_value_transform (value, sval))
+    g_assert_not_reached ();
+
+  g_hash_table_insert (ret, g_strdup (keystr), sval);
+}
+
+static void
+unset_and_free_gvalue (gpointer val)
+{
+  g_value_unset (val);
+  g_free (val);
+}
+
+gboolean
+my_object_many_stringify (MyObject *obj, GHashTable /* char * -> GValue * */ *vals, GHashTable /* char * -> GValue * */ **ret, GError **error)
+{
+  *ret = g_hash_table_new_full (g_str_hash, g_str_equal,
+				g_free, unset_and_free_gvalue);
+  g_hash_table_foreach (vals, hash_foreach_stringify, *ret);
+  return TRUE;
+}
+
 gboolean
 my_object_objpath (MyObject *obj, const char *incoming, char **outgoing, GError **error)
 {

Index: test-dbus-glib.c
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/test-dbus-glib.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- test-dbus-glib.c	8 Jul 2005 17:02:42 -0000	1.27
+++ test-dbus-glib.c	9 Jul 2005 01:46:51 -0000	1.28
@@ -26,6 +26,13 @@
 static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
 static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
 
+static void
+unset_and_free_gvalue (gpointer val)
+{
+  g_value_unset (val);
+  g_free (val);
+}
+
 static gboolean
 timed_exit (gpointer loop)
 {
@@ -40,6 +47,7 @@
   proxy_destroyed = TRUE;
   if (proxy_destroy_and_nameowner && !proxy_destroy_and_nameowner_complete && await_terminating_service == NULL)
     {
+      g_source_remove (exit_timeout);
       g_main_loop_quit (loop);
       proxy_destroy_and_nameowner_complete = TRUE;
     } 
@@ -62,11 +70,13 @@
       await_terminating_service = NULL;
       if (proxy_destroy_and_nameowner && !proxy_destroy_and_nameowner_complete && proxy_destroyed)
 	{
+	  g_source_remove (exit_timeout);
 	  g_main_loop_quit (loop);
 	  proxy_destroy_and_nameowner_complete = TRUE;
 	} 
       else if (!proxy_destroy_and_nameowner)
 	{
+	  g_source_remove (exit_timeout);
 	  g_main_loop_quit (loop);
 	}
     }
@@ -838,6 +848,50 @@
   run_mainloop ();
 
   {
+    GValue *val;
+    GHashTable *table;
+    GHashTable *ret_table;
+
+    table = g_hash_table_new_full (g_str_hash, g_str_equal,
+				   g_free, unset_and_free_gvalue);
+    
+    val = g_new0 (GValue, 1);
+    g_value_init (val, G_TYPE_UINT);
+    g_value_set_uint (val, 42);
+    g_hash_table_insert (table, g_strdup ("foo"), val);
+
+    val = g_new0 (GValue, 1);
+    g_value_init (val, G_TYPE_STRING);
+    g_value_set_string (val, "hello");
+    g_hash_table_insert (table, g_strdup ("bar"), val);
+
+    ret_table = NULL;
+    g_print ("Calling ManyStringify\n");
+    if (!dbus_g_proxy_call (proxy, "ManyStringify", &error,
+			    dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), table,
+			    G_TYPE_INVALID,
+			    dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &ret_table,
+			    G_TYPE_INVALID))
+      lose_gerror ("Failed to complete ManyStringify call", error);
+
+    g_assert (ret_table != NULL);
+    g_assert (g_hash_table_size (ret_table) == 2);
+
+    val = g_hash_table_lookup (ret_table, "foo");
+    g_assert (val != NULL);
+    g_assert (G_VALUE_HOLDS_STRING (val));
+    g_assert (!strcmp ("42", g_value_get_string (val)));
+
+    val = g_hash_table_lookup (ret_table, "bar");
+    g_assert (val != NULL);
+    g_assert (G_VALUE_HOLDS_STRING (val));
+    g_assert (!strcmp ("hello", g_value_get_string (val)));
+
+    g_hash_table_destroy (table);
+    g_hash_table_destroy (ret_table);
+  }
+
+  {
     guint val;
     char *ret_path;
     DBusGProxy *ret_proxy;
@@ -1135,6 +1189,9 @@
     lose_gerror ("Failed to complete Uppercase call", error);
   g_free (v_STRING_2);
 
+  if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION1"))
+    g_usleep (8 * G_USEC_PER_SEC);
+
   dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
   
   dbus_g_proxy_connect_signal (proxy, "Frobnicate",
@@ -1175,6 +1232,9 @@
 			  G_TYPE_INVALID, G_TYPE_INVALID))
     lose_gerror ("Failed to complete EmitFrobnicate call", error);
 
+  if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION2"))
+    g_usleep (8 * G_USEC_PER_SEC);
+
   dbus_g_connection_flush (connection);
   exit_timeout = g_timeout_add (5000, timed_exit, loop);
   g_main_loop_run (loop);



More information about the dbus-commit mailing list