summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2005-07-09 01:46:51 +0000
committerColin Walters <walters@verbum.org>2005-07-09 01:46:51 +0000
commit0ccef79d7e9d1b19cdb10b3a147b64b41686905d (patch)
tree78df63d544586877804afe2cdef873f20771ce0d /test
parentd8e7405eb35974518b0b579e2e2789fd065cb477 (diff)
2005-07-08 Colin Walters <walters@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.
Diffstat (limited to 'test')
-rw-r--r--test/glib/test-dbus-glib.c60
-rw-r--r--test/glib/test-service-glib.c34
-rw-r--r--test/glib/test-service-glib.xml5
3 files changed, 99 insertions, 0 deletions
diff --git a/test/glib/test-dbus-glib.c b/test/glib/test-dbus-glib.c
index 15cd769a..4fbe797e 100644
--- a/test/glib/test-dbus-glib.c
+++ b/test/glib/test-dbus-glib.c
@@ -26,6 +26,13 @@ static gboolean proxy_destroy_and_nameowner_complete = FALSE;
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_cb (DBusGProxy *proxy, gpointer user_data)
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 @@ name_owner_changed (DBusGProxy *proxy,
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 @@ main (int argc, char **argv)
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 @@ main (int argc, char **argv)
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 @@ main (int argc, char **argv)
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);
diff --git a/test/glib/test-service-glib.c b/test/glib/test-service-glib.c
index a9e57926..580eb107 100644
--- a/test/glib/test-service-glib.c
+++ b/test/glib/test-service-glib.c
@@ -63,6 +63,8 @@ gboolean my_object_many_return (MyObject *obj, guint32 *arg0, char **arg1, gint3
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 @@ my_object_many_uppercase (MyObject *obj, const char * const *in, char ***out, GE
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)
{
diff --git a/test/glib/test-service-glib.xml b/test/glib/test-service-glib.xml
index 272f7b23..c299a80c 100644
--- a/test/glib/test-service-glib.xml
+++ b/test/glib/test-service-glib.xml
@@ -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>