1 /* GLib testing framework examples and tests
3 * Copyright (C) 2008-2010 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: David Zeuthen <davidz@redhat.com>
27 #include "gdbus-tests.h"
29 /* all tests rely on a shared mainloop */
30 static GMainLoop *loop = NULL;
32 static GDBusConnection *c = NULL;
34 /* ---------------------------------------------------------------------------------------------------- */
35 /* Test that we can export objects, the hierarchy is correct and the right handlers are invoked */
36 /* ---------------------------------------------------------------------------------------------------- */
38 static const GDBusArgInfo foo_method1_in_args =
45 static const GDBusArgInfo * const foo_method1_in_arg_pointers[] = {&foo_method1_in_args, NULL};
47 static const GDBusArgInfo foo_method1_out_args =
54 static const GDBusArgInfo * const foo_method1_out_arg_pointers[] = {&foo_method1_out_args, NULL};
56 static const GDBusMethodInfo foo_method_info_method1 =
60 (GDBusArgInfo **) &foo_method1_in_arg_pointers,
61 (GDBusArgInfo **) &foo_method1_out_arg_pointers,
64 static const GDBusMethodInfo foo_method_info_method2 =
72 static const GDBusMethodInfo * const foo_method_info_pointers[] = {&foo_method_info_method1, &foo_method_info_method2, NULL};
74 static const GDBusSignalInfo foo_signal_info =
81 static const GDBusSignalInfo * const foo_signal_info_pointers[] = {&foo_signal_info, NULL};
83 static const GDBusPropertyInfo foo_property_info[] =
89 G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE,
96 G_DBUS_PROPERTY_INFO_FLAGS_READABLE,
103 G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE,
107 static const GDBusPropertyInfo * const foo_property_info_pointers[] =
109 &foo_property_info[0],
110 &foo_property_info[1],
111 &foo_property_info[2],
115 static const GDBusInterfaceInfo foo_interface_info =
119 (GDBusMethodInfo **) &foo_method_info_pointers,
120 (GDBusSignalInfo **) &foo_signal_info_pointers,
121 (GDBusPropertyInfo **)&foo_property_info_pointers,
126 foo_method_call (GDBusConnection *connection,
128 const gchar *object_path,
129 const gchar *interface_name,
130 const gchar *method_name,
131 GVariant *parameters,
132 GDBusMethodInvocation *invocation,
135 if (g_strcmp0 (method_name, "Method1") == 0)
139 g_variant_get (parameters, "(&s)", &input);
140 output = g_strdup_printf ("You passed the string '%s'. Jolly good!", input);
141 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", output));
146 g_dbus_method_invocation_return_dbus_error (invocation,
147 "org.example.SomeError",
148 "How do you like them apples, buddy!");
153 foo_get_property (GDBusConnection *connection,
155 const gchar *object_path,
156 const gchar *interface_name,
157 const gchar *property_name,
163 s = g_strdup_printf ("Property '%s' Is What It Is!", property_name);
164 ret = g_variant_new_string (s);
170 foo_set_property (GDBusConnection *connection,
172 const gchar *object_path,
173 const gchar *interface_name,
174 const gchar *property_name,
180 s = g_variant_print (value, TRUE);
183 G_DBUS_ERROR_SPAWN_FILE_INVALID,
184 "Returning some error instead of writing the value '%s' to the property '%s'",
190 static const GDBusInterfaceVTable foo_vtable =
197 /* -------------------- */
199 static const GDBusMethodInfo bar_method_info[] =
216 static const GDBusMethodInfo * const bar_method_info_pointers[] = {&bar_method_info[0], &bar_method_info[1], NULL};
218 static const GDBusSignalInfo bar_signal_info[] =
227 static const GDBusSignalInfo * const bar_signal_info_pointers[] = {&bar_signal_info[0], NULL};
229 static const GDBusPropertyInfo bar_property_info[] =
235 G_DBUS_PROPERTY_INFO_FLAGS_READABLE,
239 static const GDBusPropertyInfo * const bar_property_info_pointers[] = {&bar_property_info[0], NULL};
241 static const GDBusInterfaceInfo bar_interface_info =
245 (GDBusMethodInfo **) bar_method_info_pointers,
246 (GDBusSignalInfo **) bar_signal_info_pointers,
247 (GDBusPropertyInfo **) bar_property_info_pointers,
251 /* -------------------- */
253 static const GDBusMethodInfo dyna_method_info[] =
263 static const GDBusMethodInfo * const dyna_method_info_pointers[] = {&dyna_method_info[0], NULL};
265 static const GDBusInterfaceInfo dyna_interface_info =
269 (GDBusMethodInfo **) dyna_method_info_pointers,
270 NULL, /* no signals */
271 NULL, /* no properties */
276 dyna_cyber (GDBusConnection *connection,
278 const gchar *object_path,
279 const gchar *interface_name,
280 const gchar *method_name,
281 GVariant *parameters,
282 GDBusMethodInvocation *invocation,
285 GPtrArray *data = user_data;
289 node_name = strrchr (object_path, '/') + 1;
291 /* Add new node if it is not already known */
292 for (n = 0; n < data->len ; n++)
294 if (g_strcmp0 (g_ptr_array_index (data, n), node_name) == 0)
297 g_ptr_array_add (data, g_strdup(node_name));
300 g_dbus_method_invocation_return_value (invocation, NULL);
303 static const GDBusInterfaceVTable dyna_interface_vtable =
310 /* ---------------------------------------------------------------------------------------------------- */
313 introspect_callback (GDBusProxy *proxy,
317 gchar **xml_data = user_data;
322 result = g_dbus_proxy_call_finish (proxy,
325 g_assert_no_error (error);
326 g_assert (result != NULL);
327 g_variant_get (result, "(s)", xml_data);
328 g_variant_unref (result);
330 g_main_loop_quit (loop);
334 get_nodes_at (GDBusConnection *c,
335 const gchar *object_path)
341 GDBusNodeInfo *node_info;
345 proxy = g_dbus_proxy_new_sync (c,
346 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
347 G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
349 g_dbus_connection_get_unique_name (c),
351 "org.freedesktop.DBus.Introspectable",
354 g_assert_no_error (error);
355 g_assert (proxy != NULL);
357 /* do this async to avoid libdbus-1 deadlocks */
359 g_dbus_proxy_call (proxy,
362 G_DBUS_CALL_FLAGS_NONE,
365 (GAsyncReadyCallback) introspect_callback,
367 g_main_loop_run (loop);
368 g_assert (xml_data != NULL);
370 node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
371 g_assert_no_error (error);
372 g_assert (node_info != NULL);
374 p = g_ptr_array_new ();
375 for (n = 0; node_info->nodes != NULL && node_info->nodes[n] != NULL; n++)
377 const GDBusNodeInfo *sub_node_info = node_info->nodes[n];
378 g_ptr_array_add (p, g_strdup (sub_node_info->path));
380 g_ptr_array_add (p, NULL);
382 g_object_unref (proxy);
384 g_dbus_node_info_unref (node_info);
386 return (gchar **) g_ptr_array_free (p, FALSE);
390 has_interface (GDBusConnection *c,
391 const gchar *object_path,
392 const gchar *interface_name)
397 GDBusNodeInfo *node_info;
401 proxy = g_dbus_proxy_new_sync (c,
402 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
403 G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
405 g_dbus_connection_get_unique_name (c),
407 "org.freedesktop.DBus.Introspectable",
410 g_assert_no_error (error);
411 g_assert (proxy != NULL);
413 /* do this async to avoid libdbus-1 deadlocks */
415 g_dbus_proxy_call (proxy,
418 G_DBUS_CALL_FLAGS_NONE,
421 (GAsyncReadyCallback) introspect_callback,
423 g_main_loop_run (loop);
424 g_assert (xml_data != NULL);
426 node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
427 g_assert_no_error (error);
428 g_assert (node_info != NULL);
430 ret = (g_dbus_node_info_lookup_interface (node_info, interface_name) != NULL);
432 g_object_unref (proxy);
434 g_dbus_node_info_unref (node_info);
440 count_interfaces (GDBusConnection *c,
441 const gchar *object_path)
446 GDBusNodeInfo *node_info;
450 proxy = g_dbus_proxy_new_sync (c,
451 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
452 G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
454 g_dbus_connection_get_unique_name (c),
456 "org.freedesktop.DBus.Introspectable",
459 g_assert_no_error (error);
460 g_assert (proxy != NULL);
462 /* do this async to avoid libdbus-1 deadlocks */
464 g_dbus_proxy_call (proxy,
467 G_DBUS_CALL_FLAGS_NONE,
470 (GAsyncReadyCallback) introspect_callback,
472 g_main_loop_run (loop);
473 g_assert (xml_data != NULL);
475 node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
476 g_assert_no_error (error);
477 g_assert (node_info != NULL);
480 while (node_info->interfaces != NULL && node_info->interfaces[ret] != NULL)
483 g_object_unref (proxy);
485 g_dbus_node_info_unref (node_info);
491 dyna_create_callback (GDBusProxy *proxy,
499 result = g_dbus_proxy_call_finish (proxy,
502 g_assert_no_error (error);
503 g_assert (result != NULL);
504 g_variant_unref (result);
506 g_main_loop_quit (loop);
509 /* Dynamically create @object_name under /foo/dyna */
511 dyna_create (GDBusConnection *c,
512 const gchar *object_name)
518 object_path = g_strconcat ("/foo/dyna/", object_name, NULL);
521 proxy = g_dbus_proxy_new_sync (c,
522 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
523 G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
525 g_dbus_connection_get_unique_name (c),
530 g_assert_no_error (error);
531 g_assert (proxy != NULL);
533 /* do this async to avoid libdbus-1 deadlocks */
534 g_dbus_proxy_call (proxy,
536 g_variant_new ("()"),
537 G_DBUS_CALL_FLAGS_NONE,
540 (GAsyncReadyCallback) dyna_create_callback,
542 g_main_loop_run (loop);
544 g_assert_no_error (error);
546 g_object_unref (proxy);
547 g_free (object_path);
554 guint num_unregistered_calls;
555 guint num_unregistered_subtree_calls;
556 guint num_subtree_nodes;
557 } ObjectRegistrationData;
560 on_object_unregistered (gpointer user_data)
562 ObjectRegistrationData *data = user_data;
564 data->num_unregistered_calls++;
568 on_subtree_unregistered (gpointer user_data)
570 ObjectRegistrationData *data = user_data;
572 data->num_unregistered_subtree_calls++;
576 _g_strv_has_string (const gchar* const * haystack,
581 for (n = 0; haystack != NULL && haystack[n] != NULL; n++)
583 if (g_strcmp0 (haystack[n], needle) == 0)
589 /* -------------------- */
592 subtree_enumerate (GDBusConnection *connection,
594 const gchar *object_path,
597 ObjectRegistrationData *data = user_data;
602 p = g_ptr_array_new ();
604 for (n = 0; n < data->num_subtree_nodes; n++)
606 g_ptr_array_add (p, g_strdup_printf ("vp%d", n));
607 g_ptr_array_add (p, g_strdup_printf ("evp%d", n));
609 g_ptr_array_add (p, NULL);
611 nodes = (gchar **) g_ptr_array_free (p, FALSE);
616 /* Only allows certain objects, and aborts on unknowns */
617 static GDBusInterfaceInfo **
618 subtree_introspect (GDBusConnection *connection,
620 const gchar *object_path,
624 const GDBusInterfaceInfo *interfaces[2] = {
625 NULL /* filled in below */, NULL
628 /* VPs implement the Foo interface, EVPs implement the Bar interface. The root
629 * does not implement any interfaces
635 else if (g_str_has_prefix (node, "vp"))
637 interfaces[0] = &foo_interface_info;
639 else if (g_str_has_prefix (node, "evp"))
641 interfaces[0] = &bar_interface_info;
645 g_assert_not_reached ();
648 return g_memdup (interfaces, 2 * sizeof (void *));
651 static const GDBusInterfaceVTable *
652 subtree_dispatch (GDBusConnection *connection,
654 const gchar *object_path,
655 const gchar *interface_name,
657 gpointer *out_user_data,
660 if (g_strcmp0 (interface_name, "org.example.Foo") == 0)
666 static const GDBusSubtreeVTable subtree_vtable =
673 /* -------------------- */
676 dynamic_subtree_enumerate (GDBusConnection *connection,
678 const gchar *object_path,
681 GPtrArray *data = user_data;
682 gchar **nodes = g_new (gchar*, data->len + 1);
685 for (n = 0; n < data->len; n++)
687 nodes[n] = g_strdup (g_ptr_array_index (data, n));
689 nodes[data->len] = NULL;
694 /* Allow all objects to be introspected */
695 static GDBusInterfaceInfo **
696 dynamic_subtree_introspect (GDBusConnection *connection,
698 const gchar *object_path,
702 const GDBusInterfaceInfo *interfaces[2] = { &dyna_interface_info, NULL };
704 return g_memdup (interfaces, 2 * sizeof (void *));
707 static const GDBusInterfaceVTable *
708 dynamic_subtree_dispatch (GDBusConnection *connection,
710 const gchar *object_path,
711 const gchar *interface_name,
713 gpointer *out_user_data,
716 *out_user_data = user_data;
717 return &dyna_interface_vtable;
720 static const GDBusSubtreeVTable dynamic_subtree_vtable =
722 dynamic_subtree_enumerate,
723 dynamic_subtree_introspect,
724 dynamic_subtree_dispatch
727 /* -------------------- */
730 test_dispatch_thread_func (gpointer user_data)
732 const gchar *object_path = user_data;
733 GDBusProxy *foo_proxy;
738 const gchar *value_str;
740 foo_proxy = g_dbus_proxy_new_sync (c,
741 G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
742 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
744 g_dbus_connection_get_unique_name (c),
749 g_assert (foo_proxy != NULL);
751 /* generic interfaces */
753 value = g_dbus_proxy_call_sync (foo_proxy,
754 "org.freedesktop.DBus.Peer.Ping",
756 G_DBUS_CALL_FLAGS_NONE,
760 g_assert_no_error (error);
761 g_assert (value != NULL);
762 g_variant_unref (value);
766 value = g_dbus_proxy_call_sync (foo_proxy,
768 g_variant_new ("(s)", "winwinwin"),
769 G_DBUS_CALL_FLAGS_NONE,
773 g_assert_no_error (error);
774 g_assert (value != NULL);
775 g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(s)")));
776 g_variant_get (value, "(&s)", &value_str);
777 g_assert_cmpstr (value_str, ==, "You passed the string 'winwinwin'. Jolly good!");
778 g_variant_unref (value);
781 value = g_dbus_proxy_call_sync (foo_proxy,
784 G_DBUS_CALL_FLAGS_NONE,
788 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR);
789 g_assert_cmpstr (error->message, ==, "GDBus.Error:org.example.SomeError: How do you like them apples, buddy!");
790 g_error_free (error);
791 g_assert (value == NULL);
794 value = g_dbus_proxy_call_sync (foo_proxy,
796 g_variant_new ("(s)", "failfailfail"),
797 G_DBUS_CALL_FLAGS_NONE,
801 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
802 g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Type of message, '(s)', does not match expected type '()'");
803 g_error_free (error);
804 g_assert (value == NULL);
807 value = g_dbus_proxy_call_sync (foo_proxy,
810 G_DBUS_CALL_FLAGS_NONE,
814 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
815 g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such method 'NonExistantMethod'");
816 g_error_free (error);
817 g_assert (value == NULL);
820 value = g_dbus_proxy_call_sync (foo_proxy,
821 "org.example.FooXYZ.NonExistant",
823 G_DBUS_CALL_FLAGS_NONE,
827 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
828 g_error_free (error);
829 g_assert (value == NULL);
831 /* user properties */
833 value = g_dbus_proxy_call_sync (foo_proxy,
834 "org.freedesktop.DBus.Properties.Get",
835 g_variant_new ("(ss)",
838 G_DBUS_CALL_FLAGS_NONE,
842 g_assert_no_error (error);
843 g_assert (value != NULL);
844 g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(v)")));
845 g_variant_get (value, "(v)", &inner);
846 g_assert (g_variant_is_of_type (inner, G_VARIANT_TYPE_STRING));
847 g_assert_cmpstr (g_variant_get_string (inner, NULL), ==, "Property 'PropertyUno' Is What It Is!");
848 g_variant_unref (value);
849 g_variant_unref (inner);
852 value = g_dbus_proxy_call_sync (foo_proxy,
853 "org.freedesktop.DBus.Properties.Get",
854 g_variant_new ("(ss)",
857 G_DBUS_CALL_FLAGS_NONE,
861 g_assert (value == NULL);
862 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
863 g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: No such property 'ThisDoesntExist'");
864 g_error_free (error);
867 value = g_dbus_proxy_call_sync (foo_proxy,
868 "org.freedesktop.DBus.Properties.Get",
869 g_variant_new ("(ss)",
872 G_DBUS_CALL_FLAGS_NONE,
876 g_assert (value == NULL);
877 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
878 g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Property 'NotReadable' is not readable");
879 g_error_free (error);
882 value = g_dbus_proxy_call_sync (foo_proxy,
883 "org.freedesktop.DBus.Properties.Set",
884 g_variant_new ("(ssv)",
887 g_variant_new_string ("But Writable you are!")),
888 G_DBUS_CALL_FLAGS_NONE,
892 g_assert (value == NULL);
893 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FILE_INVALID);
894 g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.Spawn.FileInvalid: Returning some error instead of writing the value 'NotReadable' to the property ''But Writable you are!''");
895 g_error_free (error);
898 value = g_dbus_proxy_call_sync (foo_proxy,
899 "org.freedesktop.DBus.Properties.Set",
900 g_variant_new ("(ssv)",
903 g_variant_new_uint32 (42)),
904 G_DBUS_CALL_FLAGS_NONE,
908 g_assert (value == NULL);
909 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
910 g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Property 'NotWritable' is not writable");
911 g_error_free (error);
914 value = g_dbus_proxy_call_sync (foo_proxy,
915 "org.freedesktop.DBus.Properties.GetAll",
916 g_variant_new ("(s)",
918 G_DBUS_CALL_FLAGS_NONE,
922 g_assert_no_error (error);
923 g_assert (value != NULL);
924 g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(a{sv})")));
925 s = g_variant_print (value, TRUE);
926 g_assert_cmpstr (s, ==, "({'PropertyUno': <\"Property 'PropertyUno' Is What It Is!\">, 'NotWritable': <\"Property 'NotWritable' Is What It Is!\">},)");
928 g_variant_unref (value);
930 g_object_unref (foo_proxy);
932 g_main_loop_quit (loop);
937 test_dispatch (const gchar *object_path)
941 /* run this in a thread to avoid deadlocks */
942 thread = g_thread_new ("test_dispatch",
943 test_dispatch_thread_func,
944 (gpointer) object_path);
945 g_main_loop_run (loop);
946 g_thread_join (thread);
950 test_object_registration (void)
953 ObjectRegistrationData data;
954 GPtrArray *dyna_data;
956 guint boss_foo_reg_id;
957 guint boss_bar_reg_id;
958 guint worker1_foo_reg_id;
959 guint worker1p1_foo_reg_id;
960 guint worker2_bar_reg_id;
961 guint intern1_foo_reg_id;
962 guint intern2_bar_reg_id;
963 guint intern2_foo_reg_id;
964 guint intern3_bar_reg_id;
965 guint registration_id;
966 guint subtree_registration_id;
967 guint non_subtree_object_path_foo_reg_id;
968 guint non_subtree_object_path_bar_reg_id;
969 guint dyna_subtree_registration_id;
970 guint num_successful_registrations;
972 data.num_unregistered_calls = 0;
973 data.num_unregistered_subtree_calls = 0;
974 data.num_subtree_nodes = 0;
976 num_successful_registrations = 0;
979 c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
980 g_assert_no_error (error);
981 g_assert (c != NULL);
983 registration_id = g_dbus_connection_register_object (c,
985 (GDBusInterfaceInfo *) &foo_interface_info,
988 on_object_unregistered,
990 g_assert_no_error (error);
991 g_assert (registration_id > 0);
992 boss_foo_reg_id = registration_id;
993 num_successful_registrations++;
995 registration_id = g_dbus_connection_register_object (c,
997 (GDBusInterfaceInfo *) &bar_interface_info,
1000 on_object_unregistered,
1002 g_assert_no_error (error);
1003 g_assert (registration_id > 0);
1004 boss_bar_reg_id = registration_id;
1005 num_successful_registrations++;
1007 registration_id = g_dbus_connection_register_object (c,
1008 "/foo/boss/worker1",
1009 (GDBusInterfaceInfo *) &foo_interface_info,
1012 on_object_unregistered,
1014 g_assert_no_error (error);
1015 g_assert (registration_id > 0);
1016 worker1_foo_reg_id = registration_id;
1017 num_successful_registrations++;
1019 registration_id = g_dbus_connection_register_object (c,
1020 "/foo/boss/worker1p1",
1021 (GDBusInterfaceInfo *) &foo_interface_info,
1024 on_object_unregistered,
1026 g_assert_no_error (error);
1027 g_assert (registration_id > 0);
1028 worker1p1_foo_reg_id = registration_id;
1029 num_successful_registrations++;
1031 registration_id = g_dbus_connection_register_object (c,
1032 "/foo/boss/worker2",
1033 (GDBusInterfaceInfo *) &bar_interface_info,
1036 on_object_unregistered,
1038 g_assert_no_error (error);
1039 g_assert (registration_id > 0);
1040 worker2_bar_reg_id = registration_id;
1041 num_successful_registrations++;
1043 registration_id = g_dbus_connection_register_object (c,
1044 "/foo/boss/interns/intern1",
1045 (GDBusInterfaceInfo *) &foo_interface_info,
1048 on_object_unregistered,
1050 g_assert_no_error (error);
1051 g_assert (registration_id > 0);
1052 intern1_foo_reg_id = registration_id;
1053 num_successful_registrations++;
1055 /* ... and try again at another path */
1056 registration_id = g_dbus_connection_register_object (c,
1057 "/foo/boss/interns/intern2",
1058 (GDBusInterfaceInfo *) &bar_interface_info,
1061 on_object_unregistered,
1063 g_assert_no_error (error);
1064 g_assert (registration_id > 0);
1065 intern2_bar_reg_id = registration_id;
1066 num_successful_registrations++;
1068 /* register at the same path/interface - this should fail */
1069 registration_id = g_dbus_connection_register_object (c,
1070 "/foo/boss/interns/intern2",
1071 (GDBusInterfaceInfo *) &bar_interface_info,
1074 on_object_unregistered,
1076 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS);
1077 g_assert (!g_dbus_error_is_remote_error (error));
1078 g_error_free (error);
1080 g_assert (registration_id == 0);
1082 /* register at different interface - shouldn't fail */
1083 registration_id = g_dbus_connection_register_object (c,
1084 "/foo/boss/interns/intern2",
1085 (GDBusInterfaceInfo *) &foo_interface_info,
1088 on_object_unregistered,
1090 g_assert_no_error (error);
1091 g_assert (registration_id > 0);
1092 intern2_foo_reg_id = registration_id;
1093 num_successful_registrations++;
1095 /* unregister it via the id */
1096 g_assert (g_dbus_connection_unregister_object (c, registration_id));
1097 g_main_context_iteration (NULL, FALSE);
1098 g_assert_cmpint (data.num_unregistered_calls, ==, 1);
1099 intern2_foo_reg_id = 0;
1101 /* register it back */
1102 registration_id = g_dbus_connection_register_object (c,
1103 "/foo/boss/interns/intern2",
1104 (GDBusInterfaceInfo *) &foo_interface_info,
1107 on_object_unregistered,
1109 g_assert_no_error (error);
1110 g_assert (registration_id > 0);
1111 intern2_foo_reg_id = registration_id;
1112 num_successful_registrations++;
1114 registration_id = g_dbus_connection_register_object (c,
1115 "/foo/boss/interns/intern3",
1116 (GDBusInterfaceInfo *) &bar_interface_info,
1119 on_object_unregistered,
1121 g_assert_no_error (error);
1122 g_assert (registration_id > 0);
1123 intern3_bar_reg_id = registration_id;
1124 num_successful_registrations++;
1126 /* now register a whole subtree at /foo/boss/executives */
1127 subtree_registration_id = g_dbus_connection_register_subtree (c,
1128 "/foo/boss/executives",
1130 G_DBUS_SUBTREE_FLAGS_NONE,
1132 on_subtree_unregistered,
1134 g_assert_no_error (error);
1135 g_assert (subtree_registration_id > 0);
1136 /* try registering it again.. this should fail */
1137 registration_id = g_dbus_connection_register_subtree (c,
1138 "/foo/boss/executives",
1140 G_DBUS_SUBTREE_FLAGS_NONE,
1142 on_subtree_unregistered,
1144 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS);
1145 g_assert (!g_dbus_error_is_remote_error (error));
1146 g_error_free (error);
1148 g_assert (registration_id == 0);
1150 /* unregister it, then register it again */
1151 g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 0);
1152 g_assert (g_dbus_connection_unregister_subtree (c, subtree_registration_id));
1153 g_main_context_iteration (NULL, FALSE);
1154 g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 1);
1155 subtree_registration_id = g_dbus_connection_register_subtree (c,
1156 "/foo/boss/executives",
1158 G_DBUS_SUBTREE_FLAGS_NONE,
1160 on_subtree_unregistered,
1162 g_assert_no_error (error);
1163 g_assert (subtree_registration_id > 0);
1165 /* try to register something under /foo/boss/executives - this should work
1166 * because registered subtrees and registered objects can coexist.
1168 * Make the exported object implement *two* interfaces so we can check
1169 * that the right introspection handler is invoked.
1171 registration_id = g_dbus_connection_register_object (c,
1172 "/foo/boss/executives/non_subtree_object",
1173 (GDBusInterfaceInfo *) &bar_interface_info,
1176 on_object_unregistered,
1178 g_assert_no_error (error);
1179 g_assert (registration_id > 0);
1180 non_subtree_object_path_bar_reg_id = registration_id;
1181 num_successful_registrations++;
1182 registration_id = g_dbus_connection_register_object (c,
1183 "/foo/boss/executives/non_subtree_object",
1184 (GDBusInterfaceInfo *) &foo_interface_info,
1187 on_object_unregistered,
1189 g_assert_no_error (error);
1190 g_assert (registration_id > 0);
1191 non_subtree_object_path_foo_reg_id = registration_id;
1192 num_successful_registrations++;
1194 /* now register a dynamic subtree, spawning objects as they are called */
1195 dyna_data = g_ptr_array_new ();
1196 dyna_subtree_registration_id = g_dbus_connection_register_subtree (c,
1198 &dynamic_subtree_vtable,
1199 G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES,
1201 (GDestroyNotify)g_ptr_array_unref,
1203 g_assert_no_error (error);
1204 g_assert (dyna_subtree_registration_id > 0);
1206 /* First assert that we have no nodes in the dynamic subtree */
1207 nodes = get_nodes_at (c, "/foo/dyna");
1208 g_assert (nodes != NULL);
1209 g_assert_cmpint (g_strv_length (nodes), ==, 0);
1211 g_assert_cmpint (count_interfaces (c, "/foo/dyna"), ==, 4);
1213 /* Install three nodes in the dynamic subtree via the dyna_data backdoor and
1214 * assert that they show up correctly in the introspection data */
1215 g_ptr_array_add (dyna_data, "lol");
1216 g_ptr_array_add (dyna_data, "cat");
1217 g_ptr_array_add (dyna_data, "cheezburger");
1218 nodes = get_nodes_at (c, "/foo/dyna");
1219 g_assert (nodes != NULL);
1220 g_assert_cmpint (g_strv_length (nodes), ==, 3);
1221 g_assert_cmpstr (nodes[0], ==, "lol");
1222 g_assert_cmpstr (nodes[1], ==, "cat");
1223 g_assert_cmpstr (nodes[2], ==, "cheezburger");
1225 g_assert_cmpint (count_interfaces (c, "/foo/dyna/lol"), ==, 4);
1226 g_assert_cmpint (count_interfaces (c, "/foo/dyna/cat"), ==, 4);
1227 g_assert_cmpint (count_interfaces (c, "/foo/dyna/cheezburger"), ==, 4);
1229 /* Call a non-existing object path and assert that it has been created */
1230 dyna_create (c, "dynamicallycreated");
1231 nodes = get_nodes_at (c, "/foo/dyna");
1232 g_assert (nodes != NULL);
1233 g_assert_cmpint (g_strv_length (nodes), ==, 4);
1234 g_assert_cmpstr (nodes[0], ==, "lol");
1235 g_assert_cmpstr (nodes[1], ==, "cat");
1236 g_assert_cmpstr (nodes[2], ==, "cheezburger");
1237 g_assert_cmpstr (nodes[3], ==, "dynamicallycreated");
1239 g_assert_cmpint (count_interfaces (c, "/foo/dyna/dynamicallycreated"), ==, 4);
1241 /* now check that the object hierarachy is properly generated... yes, it's a bit
1242 * perverse that we round-trip to the bus to introspect ourselves ;-)
1244 nodes = get_nodes_at (c, "/");
1245 g_assert (nodes != NULL);
1246 g_assert_cmpint (g_strv_length (nodes), ==, 1);
1247 g_assert_cmpstr (nodes[0], ==, "foo");
1249 g_assert_cmpint (count_interfaces (c, "/"), ==, 0);
1251 nodes = get_nodes_at (c, "/foo");
1252 g_assert (nodes != NULL);
1253 g_assert_cmpint (g_strv_length (nodes), ==, 2);
1254 g_assert_cmpstr (nodes[0], ==, "boss");
1255 g_assert_cmpstr (nodes[1], ==, "dyna");
1257 g_assert_cmpint (count_interfaces (c, "/foo"), ==, 0);
1259 nodes = get_nodes_at (c, "/foo/boss");
1260 g_assert (nodes != NULL);
1261 g_assert_cmpint (g_strv_length (nodes), ==, 5);
1262 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "worker1"));
1263 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "worker1p1"));
1264 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "worker2"));
1265 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "interns"));
1266 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "executives"));
1268 /* any registered object always implement org.freedesktop.DBus.[Peer,Introspectable,Properties] */
1269 g_assert_cmpint (count_interfaces (c, "/foo/boss"), ==, 5);
1270 g_assert (has_interface (c, "/foo/boss", foo_interface_info.name));
1271 g_assert (has_interface (c, "/foo/boss", bar_interface_info.name));
1273 /* check subtree nodes - we should have only non_subtree_object in /foo/boss/executives
1274 * because data.num_subtree_nodes is 0
1276 nodes = get_nodes_at (c, "/foo/boss/executives");
1277 g_assert (nodes != NULL);
1278 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "non_subtree_object"));
1279 g_assert_cmpint (g_strv_length (nodes), ==, 1);
1281 g_assert_cmpint (count_interfaces (c, "/foo/boss/executives"), ==, 0);
1283 /* now change data.num_subtree_nodes and check */
1284 data.num_subtree_nodes = 2;
1285 nodes = get_nodes_at (c, "/foo/boss/executives");
1286 g_assert (nodes != NULL);
1287 g_assert_cmpint (g_strv_length (nodes), ==, 5);
1288 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "non_subtree_object"));
1289 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "vp0"));
1290 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "vp1"));
1291 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "evp0"));
1292 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "evp1"));
1293 /* check that /foo/boss/executives/non_subtree_object is not handled by the
1294 * subtree handlers - we can do this because objects from subtree handlers
1295 * has exactly one interface and non_subtree_object has two
1297 g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/non_subtree_object"), ==, 5);
1298 g_assert (has_interface (c, "/foo/boss/executives/non_subtree_object", foo_interface_info.name));
1299 g_assert (has_interface (c, "/foo/boss/executives/non_subtree_object", bar_interface_info.name));
1300 /* check that the vp and evp objects are handled by the subtree handlers */
1301 g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/vp0"), ==, 4);
1302 g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/vp1"), ==, 4);
1303 g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/evp0"), ==, 4);
1304 g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/evp1"), ==, 4);
1305 g_assert (has_interface (c, "/foo/boss/executives/vp0", foo_interface_info.name));
1306 g_assert (has_interface (c, "/foo/boss/executives/vp1", foo_interface_info.name));
1307 g_assert (has_interface (c, "/foo/boss/executives/evp0", bar_interface_info.name));
1308 g_assert (has_interface (c, "/foo/boss/executives/evp1", bar_interface_info.name));
1310 data.num_subtree_nodes = 3;
1311 nodes = get_nodes_at (c, "/foo/boss/executives");
1312 g_assert (nodes != NULL);
1313 g_assert_cmpint (g_strv_length (nodes), ==, 7);
1314 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "non_subtree_object"));
1315 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "vp0"));
1316 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "vp1"));
1317 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "vp2"));
1318 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "evp0"));
1319 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "evp1"));
1320 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "evp2"));
1323 /* This is to check that a bug (rather, class of bugs) in gdbusconnection.c's
1325 * g_dbus_connection_list_registered_unlocked()
1327 * where /foo/boss/worker1 reported a child '1', is now fixed.
1329 nodes = get_nodes_at (c, "/foo/boss/worker1");
1330 g_assert (nodes != NULL);
1331 g_assert_cmpint (g_strv_length (nodes), ==, 0);
1334 /* check that calls are properly dispatched to the functions in foo_vtable for objects
1335 * implementing the org.example.Foo interface
1337 * We do this for both a regular registered object (/foo/boss) and also for an object
1338 * registered through the subtree mechanism.
1340 test_dispatch ("/foo/boss");
1341 test_dispatch ("/foo/boss/executives/vp0");
1343 /* To prevent from exiting and attaching a D-Bus tool like D-Feet; uncomment: */
1345 g_debug ("Point D-feet or other tool at: %s", g_test_dbus_get_temporary_address());
1346 g_main_loop_run (loop);
1349 /* check that unregistering the subtree handler works */
1350 g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 1);
1351 g_assert (g_dbus_connection_unregister_subtree (c, subtree_registration_id));
1352 g_main_context_iteration (NULL, FALSE);
1353 g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 2);
1354 nodes = get_nodes_at (c, "/foo/boss/executives");
1355 g_assert (nodes != NULL);
1356 g_assert_cmpint (g_strv_length (nodes), ==, 1);
1357 g_assert (_g_strv_has_string ((const gchar* const *) nodes, "non_subtree_object"));
1360 g_assert (g_dbus_connection_unregister_object (c, boss_foo_reg_id));
1361 g_assert (g_dbus_connection_unregister_object (c, boss_bar_reg_id));
1362 g_assert (g_dbus_connection_unregister_object (c, worker1_foo_reg_id));
1363 g_assert (g_dbus_connection_unregister_object (c, worker1p1_foo_reg_id));
1364 g_assert (g_dbus_connection_unregister_object (c, worker2_bar_reg_id));
1365 g_assert (g_dbus_connection_unregister_object (c, intern1_foo_reg_id));
1366 g_assert (g_dbus_connection_unregister_object (c, intern2_bar_reg_id));
1367 g_assert (g_dbus_connection_unregister_object (c, intern2_foo_reg_id));
1368 g_assert (g_dbus_connection_unregister_object (c, intern3_bar_reg_id));
1369 g_assert (g_dbus_connection_unregister_object (c, non_subtree_object_path_bar_reg_id));
1370 g_assert (g_dbus_connection_unregister_object (c, non_subtree_object_path_foo_reg_id));
1372 g_main_context_iteration (NULL, FALSE);
1373 g_assert_cmpint (data.num_unregistered_calls, ==, num_successful_registrations);
1375 /* check that we no longer export any objects - TODO: it looks like there's a bug in
1376 * libdbus-1 here: libdbus still reports the '/foo' object; so disable the test for now
1379 nodes = get_nodes_at (c, "/");
1380 g_assert (nodes != NULL);
1381 g_assert_cmpint (g_strv_length (nodes), ==, 0);
1388 static const GDBusInterfaceInfo test_interface_info1 =
1392 (GDBusMethodInfo **) NULL,
1393 (GDBusSignalInfo **) NULL,
1394 (GDBusPropertyInfo **) NULL,
1398 static const GDBusInterfaceInfo test_interface_info2 =
1401 "org.freedesktop.DBus.Properties",
1402 (GDBusMethodInfo **) NULL,
1403 (GDBusSignalInfo **) NULL,
1404 (GDBusPropertyInfo **) NULL,
1409 check_interfaces (GDBusConnection *c,
1410 const gchar *object_path,
1411 const gchar **interfaces)
1416 GDBusNodeInfo *node_info;
1420 proxy = g_dbus_proxy_new_sync (c,
1421 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
1422 G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
1424 g_dbus_connection_get_unique_name (c),
1426 "org.freedesktop.DBus.Introspectable",
1429 g_assert_no_error (error);
1430 g_assert (proxy != NULL);
1432 /* do this async to avoid libdbus-1 deadlocks */
1434 g_dbus_proxy_call (proxy,
1437 G_DBUS_CALL_FLAGS_NONE,
1440 (GAsyncReadyCallback) introspect_callback,
1442 g_main_loop_run (loop);
1443 g_assert (xml_data != NULL);
1445 node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
1446 g_assert_no_error (error);
1447 g_assert (node_info != NULL);
1449 g_assert (node_info->interfaces != NULL);
1450 for (i = 0; node_info->interfaces[i]; i++) ;
1452 if (g_strv_length ((gchar**)interfaces) != i - 1)
1454 g_print ("expected ");
1455 for (i = 0; interfaces[i]; i++)
1456 g_print ("%s ", interfaces[i]);
1458 for (i = 0; node_info->interfaces[i]; i++)
1459 g_print ("%s ", node_info->interfaces[i]->name);
1463 g_assert_cmpint (g_strv_length ((gchar**)interfaces), ==, i - 1);
1465 for (i = 0; interfaces[i]; i++)
1467 for (j = 0; node_info->interfaces[j]; j++)
1469 if (strcmp (interfaces[i], node_info->interfaces[j]->name) == 0)
1473 g_assert_not_reached ();
1478 g_object_unref (proxy);
1480 g_dbus_node_info_unref (node_info);
1484 test_registered_interfaces (void)
1488 const gchar *interfaces[] = {
1490 "org.freedesktop.DBus.Properties",
1491 "org.freedesktop.DBus.Introspectable",
1496 c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
1497 g_assert_no_error (error);
1498 g_assert (c != NULL);
1500 id1 = g_dbus_connection_register_object (c,
1502 (GDBusInterfaceInfo *) &test_interface_info1,
1507 g_assert_no_error (error);
1509 id2 = g_dbus_connection_register_object (c,
1511 (GDBusInterfaceInfo *) &test_interface_info2,
1516 g_assert_no_error (error);
1519 check_interfaces (c, "/test", interfaces);
1521 g_assert (g_dbus_connection_unregister_object (c, id1));
1522 g_assert (g_dbus_connection_unregister_object (c, id2));
1527 /* ---------------------------------------------------------------------------------------------------- */
1530 test_async_method_call (GDBusConnection *connection,
1531 const gchar *sender,
1532 const gchar *object_path,
1533 const gchar *interface_name,
1534 const gchar *method_name,
1535 GVariant *parameters,
1536 GDBusMethodInvocation *invocation,
1539 const GDBusPropertyInfo *property;
1541 /* Strictly speaking, this function should also expect to receive
1542 * method calls not on the org.freedesktop.DBus.Properties interface,
1543 * but we don't do any during this testcase, so assert that.
1545 g_assert_cmpstr (interface_name, ==, "org.freedesktop.DBus.Properties");
1546 g_assert (g_dbus_method_invocation_get_method_info (invocation) == NULL);
1548 property = g_dbus_method_invocation_get_property_info (invocation);
1550 /* Do a whole lot of asserts to make sure that invalid calls are still
1551 * getting properly rejected by GDBusConnection and that our
1552 * environment is as we expect it to be.
1554 if (g_str_equal (method_name, "Get"))
1556 const gchar *iface_name, *prop_name;
1558 g_variant_get (parameters, "(&s&s)", &iface_name, &prop_name);
1559 g_assert_cmpstr (iface_name, ==, "org.example.Foo");
1560 g_assert (property != NULL);
1561 g_assert_cmpstr (prop_name, ==, property->name);
1562 g_assert (property->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE);
1563 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", g_variant_new_string (prop_name)));
1566 else if (g_str_equal (method_name, "Set"))
1568 const gchar *iface_name, *prop_name;
1571 g_variant_get (parameters, "(&s&sv)", &iface_name, &prop_name, &value);
1572 g_assert_cmpstr (iface_name, ==, "org.example.Foo");
1573 g_assert (property != NULL);
1574 g_assert_cmpstr (prop_name, ==, property->name);
1575 g_assert (property->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE);
1576 g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE (property->signature)));
1577 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
1578 g_variant_unref (value);
1581 else if (g_str_equal (method_name, "GetAll"))
1583 const gchar *iface_name;
1585 g_variant_get (parameters, "(&s)", &iface_name);
1586 g_assert_cmpstr (iface_name, ==, "org.example.Foo");
1587 g_assert (property == NULL);
1588 g_dbus_method_invocation_return_value (invocation,
1589 g_variant_new_parsed ("({ 'PropertyUno': < 'uno' >,"
1590 " 'NotWritable': < 'notwrite' > },)"));
1594 g_assert_not_reached ();
1597 static gint outstanding_cases;
1600 ensure_result_cb (GObject *source,
1601 GAsyncResult *result,
1604 GDBusConnection *connection = G_DBUS_CONNECTION (source);
1607 reply = g_dbus_connection_call_finish (connection, result, NULL);
1609 if (user_data == NULL)
1611 /* Expected an error */
1612 g_assert (reply == NULL);
1616 /* Expected a reply of a particular format. */
1619 g_assert (reply != NULL);
1620 str = g_variant_print (reply, TRUE);
1621 g_assert_cmpstr (str, ==, (const gchar *) user_data);
1624 g_variant_unref (reply);
1627 g_assert_cmpint (outstanding_cases, >, 0);
1628 outstanding_cases--;
1632 test_async_case (GDBusConnection *connection,
1633 const gchar *expected_reply,
1634 const gchar *method,
1635 const gchar *format_string,
1640 va_start (ap, format_string);
1642 g_dbus_connection_call (connection, g_dbus_connection_get_unique_name (connection), "/foo",
1643 "org.freedesktop.DBus.Properties", method, g_variant_new_va (format_string, NULL, &ap),
1644 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, ensure_result_cb, (gpointer) expected_reply);
1648 outstanding_cases++;
1652 test_async_properties (void)
1654 GError *error = NULL;
1655 guint registration_id;
1656 static const GDBusInterfaceVTable vtable = {
1657 test_async_method_call, NULL, NULL
1660 c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
1661 g_assert_no_error (error);
1662 g_assert (c != NULL);
1664 registration_id = g_dbus_connection_register_object (c,
1666 (GDBusInterfaceInfo *) &foo_interface_info,
1667 &vtable, NULL, NULL, &error);
1668 g_assert_no_error (error);
1669 g_assert (registration_id);
1671 test_async_case (c, NULL, "random", "()");
1673 /* Test a variety of error cases */
1674 test_async_case (c, NULL, "Get", "(si)", "wrong signature", 5);
1675 test_async_case (c, NULL, "Get", "(ss)", "org.example.WrongInterface", "zzz");
1676 test_async_case (c, NULL, "Get", "(ss)", "org.example.Foo", "NoSuchProperty");
1677 test_async_case (c, NULL, "Get", "(ss)", "org.example.Foo", "NotReadable");
1679 test_async_case (c, NULL, "Set", "(si)", "wrong signature", 5);
1680 test_async_case (c, NULL, "Set", "(ssv)", "org.example.WrongInterface", "zzz", g_variant_new_string (""));
1681 test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo", "NoSuchProperty", g_variant_new_string (""));
1682 test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo", "NotWritable", g_variant_new_string (""));
1683 test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo", "PropertyUno", g_variant_new_object_path ("/wrong"));
1685 test_async_case (c, NULL, "GetAll", "(si)", "wrong signature", 5);
1686 test_async_case (c, NULL, "GetAll", "(s)", "org.example.WrongInterface");
1688 /* Now do the proper things */
1689 test_async_case (c, "(<'PropertyUno'>,)", "Get", "(ss)", "org.example.Foo", "PropertyUno");
1690 test_async_case (c, "(<'NotWritable'>,)", "Get", "(ss)", "org.example.Foo", "NotWritable");
1691 test_async_case (c, "()", "Set", "(ssv)", "org.example.Foo", "PropertyUno", g_variant_new_string (""));
1692 test_async_case (c, "()", "Set", "(ssv)", "org.example.Foo", "NotReadable", g_variant_new_string (""));
1693 test_async_case (c, "({'PropertyUno': <'uno'>, 'NotWritable': <'notwrite'>},)", "GetAll", "(s)", "org.example.Foo");
1695 while (outstanding_cases)
1696 g_main_context_iteration (NULL, TRUE);
1698 g_dbus_connection_unregister_object (c, registration_id);
1702 /* ---------------------------------------------------------------------------------------------------- */
1710 g_test_init (&argc, &argv, NULL);
1712 /* all the tests rely on a shared main loop */
1713 loop = g_main_loop_new (NULL, FALSE);
1717 g_test_add_func ("/gdbus/object-registration", test_object_registration);
1718 g_test_add_func ("/gdbus/registered-interfaces", test_registered_interfaces);
1719 g_test_add_func ("/gdbus/async-properties", test_async_properties);
1721 /* TODO: check that we spit out correct introspection data */
1722 /* TODO: check that registering a whole subtree works */
1727 session_bus_down ();