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 <sys/types.h>
30 #include "gdbus-tests.h"
32 /* all tests rely on a shared mainloop */
33 static GMainLoop *loop = NULL;
36 test_connection_quit_mainloop (gpointer user_data)
38 gboolean *quit_mainloop_fired = user_data;
39 *quit_mainloop_fired = TRUE;
40 g_main_loop_quit (loop);
44 /* ---------------------------------------------------------------------------------------------------- */
45 /* Connection life-cycle testing */
46 /* ---------------------------------------------------------------------------------------------------- */
48 static const GDBusInterfaceInfo boo_interface_info =
52 (GDBusMethodInfo **) NULL,
53 (GDBusSignalInfo **) NULL,
54 (GDBusPropertyInfo **) NULL,
58 static const GDBusInterfaceVTable boo_vtable =
60 NULL, /* _method_call */
61 NULL, /* _get_property */
62 NULL /* _set_property */
66 some_filter_func (GDBusConnection *connection,
67 GDBusMessage *message,
75 on_name_owner_changed (GDBusConnection *connection,
76 const gchar *sender_name,
77 const gchar *object_path,
78 const gchar *interface_name,
79 const gchar *signal_name,
86 a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop (gpointer user_data)
88 gboolean *val = user_data;
91 g_main_loop_quit (loop);
95 test_connection_life_cycle (void)
101 gboolean on_signal_registration_freed_called;
102 gboolean on_filter_freed_called;
103 gboolean on_register_object_freed_called;
104 gboolean quit_mainloop_fired;
105 guint quit_mainloop_id;
106 guint registration_id;
111 * Check for correct behavior when no bus is present
114 c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
115 _g_assert_error_domain (error, G_IO_ERROR);
116 g_assert (!g_dbus_error_is_remote_error (error));
117 g_assert (c == NULL);
118 g_error_free (error);
121 * Check for correct behavior when a bus is present
126 c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
127 g_assert_no_error (error);
128 g_assert (c != NULL);
129 g_assert (!g_dbus_connection_is_closed (c));
132 * Check that singleton handling work
135 c2 = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
136 g_assert_no_error (error);
137 g_assert (c2 != NULL);
142 * Check that private connections work
144 c2 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, &error);
145 g_assert_no_error (error);
146 g_assert (c2 != NULL);
150 c2 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, &error);
151 g_assert_no_error (error);
152 g_assert (c2 != NULL);
153 g_assert (!g_dbus_connection_is_closed (c2));
154 ret = g_dbus_connection_close_sync (c2, NULL, &error);
155 g_assert_no_error (error);
157 _g_assert_signal_received (c2, "closed");
158 g_assert (g_dbus_connection_is_closed (c2));
159 ret = g_dbus_connection_close_sync (c2, NULL, &error);
160 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED);
161 g_error_free (error);
166 * Check that the finalization code works
168 * (and that the GDestroyNotify for filters and objects and signal
169 * registrations are run as expected)
172 c2 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, &error);
173 g_assert_no_error (error);
174 g_assert (c2 != NULL);
175 /* signal registration */
176 on_signal_registration_freed_called = FALSE;
177 g_dbus_connection_signal_subscribe (c2,
178 "org.freedesktop.DBus", /* bus name */
179 "org.freedesktop.DBus", /* interface */
180 "NameOwnerChanged", /* member */
181 "/org/freesktop/DBus", /* path */
183 G_DBUS_SIGNAL_FLAGS_NONE,
184 on_name_owner_changed,
185 &on_signal_registration_freed_called,
186 a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop);
188 on_filter_freed_called = FALSE;
189 g_dbus_connection_add_filter (c2,
191 &on_filter_freed_called,
192 a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop);
193 /* object registration */
194 on_register_object_freed_called = FALSE;
196 registration_id = g_dbus_connection_register_object (c2,
198 (GDBusInterfaceInfo *) &boo_interface_info,
200 &on_register_object_freed_called,
201 a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop,
203 g_assert_no_error (error);
204 g_assert (registration_id > 0);
205 /* ok, finalize the connection and check that all the GDestroyNotify functions are invoked as expected */
207 quit_mainloop_fired = FALSE;
208 quit_mainloop_id = g_timeout_add (30000, test_connection_quit_mainloop, &quit_mainloop_fired);
211 if (on_signal_registration_freed_called &&
212 on_filter_freed_called &&
213 on_register_object_freed_called)
215 if (quit_mainloop_fired)
217 g_main_loop_run (loop);
219 g_source_remove (quit_mainloop_id);
220 g_assert (on_signal_registration_freed_called);
221 g_assert (on_filter_freed_called);
222 g_assert (on_register_object_freed_called);
223 g_assert (!quit_mainloop_fired);
226 * Check for correct behavior when the bus goes away
229 g_assert (!g_dbus_connection_is_closed (c));
230 g_dbus_connection_set_exit_on_close (c, FALSE);
232 if (!g_dbus_connection_is_closed (c))
233 _g_assert_signal_received (c, "closed");
234 g_assert (g_dbus_connection_is_closed (c));
236 _g_object_wait_for_single_ref (c);
240 /* ---------------------------------------------------------------------------------------------------- */
241 /* Test that sending and receiving messages work as expected */
242 /* ---------------------------------------------------------------------------------------------------- */
245 msg_cb_expect_error_disconnected (GDBusConnection *connection,
253 result = g_dbus_connection_call_finish (connection,
256 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED);
257 g_assert (!g_dbus_error_is_remote_error (error));
258 g_error_free (error);
259 g_assert (result == NULL);
261 g_main_loop_quit (loop);
265 msg_cb_expect_error_unknown_method (GDBusConnection *connection,
273 result = g_dbus_connection_call_finish (connection,
276 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
277 g_assert (g_dbus_error_is_remote_error (error));
278 g_error_free (error);
279 g_assert (result == NULL);
281 g_main_loop_quit (loop);
285 msg_cb_expect_success (GDBusConnection *connection,
293 result = g_dbus_connection_call_finish (connection,
296 g_assert_no_error (error);
297 g_assert (result != NULL);
298 g_variant_unref (result);
300 g_main_loop_quit (loop);
304 msg_cb_expect_error_cancelled (GDBusConnection *connection,
312 result = g_dbus_connection_call_finish (connection,
315 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
316 g_assert (!g_dbus_error_is_remote_error (error));
317 g_error_free (error);
318 g_assert (result == NULL);
320 g_main_loop_quit (loop);
324 msg_cb_expect_error_cancelled_2 (GDBusConnection *connection,
332 result = g_dbus_connection_call_finish (connection,
335 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
336 g_assert (!g_dbus_error_is_remote_error (error));
337 g_error_free (error);
338 g_assert (result == NULL);
340 g_main_loop_quit (loop);
343 /* ---------------------------------------------------------------------------------------------------- */
346 test_connection_send (void)
353 /* First, get an unopened connection */
354 c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
355 g_assert (c != NULL);
356 g_assert (!g_dbus_connection_is_closed (c));
359 * Check that we never actually send a message if the GCancellable
360 * is already cancelled - i.e. we should get #G_IO_ERROR_CANCELLED
361 * when the actual connection is not up.
363 ca = g_cancellable_new ();
364 g_cancellable_cancel (ca);
365 g_dbus_connection_call (c,
366 "org.freedesktop.DBus", /* bus_name */
367 "/org/freedesktop/DBus", /* object path */
368 "org.freedesktop.DBus", /* interface name */
369 "GetId", /* method name */
371 G_DBUS_CALL_FLAGS_NONE,
374 (GAsyncReadyCallback) msg_cb_expect_error_cancelled,
376 g_main_loop_run (loop);
380 * Check that we get a reply to the GetId() method call.
382 g_dbus_connection_call (c,
383 "org.freedesktop.DBus", /* bus_name */
384 "/org/freedesktop/DBus", /* object path */
385 "org.freedesktop.DBus", /* interface name */
386 "GetId", /* method name */
388 G_DBUS_CALL_FLAGS_NONE,
391 (GAsyncReadyCallback) msg_cb_expect_success,
393 g_main_loop_run (loop);
396 * Check that we get an error reply to the NonExistantMethod() method call.
398 g_dbus_connection_call (c,
399 "org.freedesktop.DBus", /* bus_name */
400 "/org/freedesktop/DBus", /* object path */
401 "org.freedesktop.DBus", /* interface name */
402 "NonExistantMethod", /* method name */
404 G_DBUS_CALL_FLAGS_NONE,
407 (GAsyncReadyCallback) msg_cb_expect_error_unknown_method,
409 g_main_loop_run (loop);
412 * Check that cancellation works when the message is already in flight.
414 ca = g_cancellable_new ();
415 g_dbus_connection_call (c,
416 "org.freedesktop.DBus", /* bus_name */
417 "/org/freedesktop/DBus", /* object path */
418 "org.freedesktop.DBus", /* interface name */
419 "GetId", /* method name */
421 G_DBUS_CALL_FLAGS_NONE,
424 (GAsyncReadyCallback) msg_cb_expect_error_cancelled_2,
426 g_cancellable_cancel (ca);
427 g_main_loop_run (loop);
431 * Check that we get an error when sending to a connection that is disconnected.
433 g_dbus_connection_set_exit_on_close (c, FALSE);
435 _g_assert_signal_received (c, "closed");
436 g_assert (g_dbus_connection_is_closed (c));
438 g_dbus_connection_call (c,
439 "org.freedesktop.DBus", /* bus_name */
440 "/org/freedesktop/DBus", /* object path */
441 "org.freedesktop.DBus", /* interface name */
442 "GetId", /* method name */
444 G_DBUS_CALL_FLAGS_NONE,
447 (GAsyncReadyCallback) msg_cb_expect_error_disconnected,
449 g_main_loop_run (loop);
451 _g_object_wait_for_single_ref (c);
455 /* ---------------------------------------------------------------------------------------------------- */
456 /* Connection signal tests */
457 /* ---------------------------------------------------------------------------------------------------- */
460 test_connection_signal_handler (GDBusConnection *connection,
461 const gchar *sender_name,
462 const gchar *object_path,
463 const gchar *interface_name,
464 const gchar *signal_name,
465 GVariant *parameters,
468 gint *counter = user_data;
471 /*g_debug ("in test_connection_signal_handler (sender=%s path=%s interface=%s member=%s)",
477 g_main_loop_quit (loop);
481 test_connection_signals (void)
493 gint count_name_owner_changed;
501 * Bring up first separate connections
504 /* if running with dbus-monitor, it claims the name :1.0 - so if we don't run with the monitor
507 if (g_getenv ("G_DBUS_MONITOR") == NULL)
509 c1 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, NULL);
510 g_assert (c1 != NULL);
511 g_assert (!g_dbus_connection_is_closed (c1));
514 c1 = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
515 g_assert (c1 != NULL);
516 g_assert (!g_dbus_connection_is_closed (c1));
517 g_assert_cmpstr (g_dbus_connection_get_unique_name (c1), ==, ":1.1");
520 * Install two signal handlers for the first connection
522 * - Listen to the signal "Foo" from :1.2 (e.g. c2)
523 * - Listen to the signal "Foo" from anyone (e.g. both c2 and c3)
525 * and then count how many times this signal handler was invoked.
527 s1 = g_dbus_connection_signal_subscribe (c1,
529 "org.gtk.GDBus.ExampleInterface",
531 "/org/gtk/GDBus/ExampleInterface",
533 G_DBUS_SIGNAL_FLAGS_NONE,
534 test_connection_signal_handler,
537 s2 = g_dbus_connection_signal_subscribe (c1,
538 NULL, /* match any sender */
539 "org.gtk.GDBus.ExampleInterface",
541 "/org/gtk/GDBus/ExampleInterface",
543 G_DBUS_SIGNAL_FLAGS_NONE,
544 test_connection_signal_handler,
547 s3 = g_dbus_connection_signal_subscribe (c1,
548 "org.freedesktop.DBus", /* sender */
549 "org.freedesktop.DBus", /* interface */
550 "NameOwnerChanged", /* member */
551 "/org/freedesktop/DBus", /* path */
553 G_DBUS_SIGNAL_FLAGS_NONE,
554 test_connection_signal_handler,
555 &count_name_owner_changed,
557 /* Note that s1b is *just like* s1 - this is to catch a bug where N
558 * subscriptions of the same rule causes N calls to each of the N
559 * subscriptions instead of just 1 call to each of the N subscriptions.
561 s1b = g_dbus_connection_signal_subscribe (c1,
563 "org.gtk.GDBus.ExampleInterface",
565 "/org/gtk/GDBus/ExampleInterface",
567 G_DBUS_SIGNAL_FLAGS_NONE,
568 test_connection_signal_handler,
579 count_name_owner_changed = 0;
582 * Bring up two other connections
584 c2 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, NULL);
585 g_assert (c2 != NULL);
586 g_assert (!g_dbus_connection_is_closed (c2));
587 g_assert_cmpstr (g_dbus_connection_get_unique_name (c2), ==, ":1.2");
588 c3 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, NULL);
589 g_assert (c3 != NULL);
590 g_assert (!g_dbus_connection_is_closed (c3));
591 g_assert_cmpstr (g_dbus_connection_get_unique_name (c3), ==, ":1.3");
594 * Make c2 emit "Foo" - we should catch it twice
596 * Note that there is no way to be sure that the signal subscriptions
597 * on c1 are effective yet - for all we know, the AddMatch() messages
598 * could sit waiting in a buffer somewhere between this process and
599 * the message bus. And emitting signals on c2 (a completely other
600 * socket!) will not necessarily change this.
602 * To ensure this is not the case, do a synchronous call on c1.
604 result = g_dbus_connection_call_sync (c1,
605 "org.freedesktop.DBus", /* bus name */
606 "/org/freedesktop/DBus", /* object path */
607 "org.freedesktop.DBus", /* interface name */
608 "GetId", /* method name */
609 NULL, /* parameters */
610 NULL, /* return type */
611 G_DBUS_CALL_FLAGS_NONE,
615 g_assert_no_error (error);
616 g_assert (result != NULL);
617 g_variant_unref (result);
618 /* now, emit the signal on c2 */
619 ret = g_dbus_connection_emit_signal (c2,
620 NULL, /* destination bus name */
621 "/org/gtk/GDBus/ExampleInterface",
622 "org.gtk.GDBus.ExampleInterface",
626 g_assert_no_error (error);
628 while (!(count_s1 >= 1 && count_s2 >= 1))
629 g_main_loop_run (loop);
630 g_assert_cmpint (count_s1, ==, 1);
631 g_assert_cmpint (count_s2, ==, 1);
634 * Make c3 emit "Foo" - we should catch it only once
636 ret = g_dbus_connection_emit_signal (c3,
637 NULL, /* destination bus name */
638 "/org/gtk/GDBus/ExampleInterface",
639 "org.gtk.GDBus.ExampleInterface",
643 g_assert_no_error (error);
645 while (!(count_s1 == 1 && count_s2 == 2))
646 g_main_loop_run (loop);
647 g_assert_cmpint (count_s1, ==, 1);
648 g_assert_cmpint (count_s2, ==, 2);
651 * Also to check the total amount of NameOwnerChanged signals - use a 5 second ceiling
652 * to avoid spinning forever
654 gboolean quit_mainloop_fired;
655 guint quit_mainloop_id;
656 quit_mainloop_fired = FALSE;
657 quit_mainloop_id = g_timeout_add (30000, test_connection_quit_mainloop, &quit_mainloop_fired);
658 while (count_name_owner_changed < 2 && !quit_mainloop_fired)
659 g_main_loop_run (loop);
660 g_source_remove (quit_mainloop_id);
661 g_assert_cmpint (count_s1, ==, 1);
662 g_assert_cmpint (count_s2, ==, 2);
663 g_assert_cmpint (count_name_owner_changed, ==, 2);
665 g_dbus_connection_signal_unsubscribe (c1, s1);
666 g_dbus_connection_signal_unsubscribe (c1, s2);
667 g_dbus_connection_signal_unsubscribe (c1, s3);
668 g_dbus_connection_signal_unsubscribe (c1, s1b);
670 _g_object_wait_for_single_ref (c1);
671 _g_object_wait_for_single_ref (c2);
672 _g_object_wait_for_single_ref (c3);
681 /* ---------------------------------------------------------------------------------------------------- */
690 static GDBusMessage *
691 filter_func (GDBusConnection *connection,
692 GDBusMessage *message,
696 FilterData *data = user_data;
697 guint32 reply_serial;
701 reply_serial = g_dbus_message_get_reply_serial (message);
702 if (reply_serial == data->serial)
703 data->num_handled += 1;
707 data->num_outgoing += 1;
716 gboolean alter_incoming;
717 gboolean alter_outgoing;
720 static GDBusMessage *
721 other_filter_func (GDBusConnection *connection,
722 GDBusMessage *message,
726 FilterEffects *effects = user_data;
731 alter = effects->alter_incoming;
733 alter = effects->alter_outgoing;
742 copy = g_dbus_message_copy (message, NULL);
743 g_object_unref (message);
745 body = g_dbus_message_get_body (copy);
746 g_variant_get (body, "(s)", &s);
747 s2 = g_strdup_printf ("MOD: %s", s);
748 g_dbus_message_set_body (copy, g_variant_new ("(s)", s2));
763 test_connection_filter_name_owner_changed_signal_handler (GDBusConnection *connection,
764 const gchar *sender_name,
765 const gchar *object_path,
766 const gchar *interface_name,
767 const gchar *signal_name,
768 GVariant *parameters,
772 const gchar *old_owner;
773 const gchar *new_owner;
775 g_variant_get (parameters,
781 if (g_strcmp0 (name, "com.example.TestService") == 0 && strlen (new_owner) > 0)
783 g_main_loop_quit (loop);
788 test_connection_filter_on_timeout (gpointer user_data)
790 g_printerr ("Timeout waiting 30 sec on service\n");
791 g_assert_not_reached ();
796 test_connection_filter (void)
805 guint timeout_mainloop_id;
806 guint signal_handler_id;
807 FilterEffects effects;
811 memset (&data, '\0', sizeof (FilterData));
816 c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
817 g_assert_no_error (error);
818 g_assert (c != NULL);
820 filter_id = g_dbus_connection_add_filter (c,
825 m = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
826 "/org/freedesktop/DBus", /* path */
827 "org.freedesktop.DBus", /* interface */
829 g_dbus_message_set_body (m, g_variant_new ("(s)", "org.freedesktop.DBus"));
831 g_dbus_connection_send_message (c, m, G_DBUS_SEND_MESSAGE_FLAGS_NONE, &data.serial, &error);
832 g_assert_no_error (error);
834 while (data.num_handled == 0)
837 m2 = g_dbus_message_copy (m, &error);
838 g_assert_no_error (error);
839 g_dbus_connection_send_message (c, m2, G_DBUS_SEND_MESSAGE_FLAGS_NONE, &data.serial, &error);
841 g_assert_no_error (error);
843 while (data.num_handled == 1)
846 m2 = g_dbus_message_copy (m, &error);
847 g_assert_no_error (error);
848 r = g_dbus_connection_send_message_with_reply_sync (c,
850 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
853 NULL, /* GCancellable */
856 g_assert_no_error (error);
857 g_assert (r != NULL);
859 g_assert_cmpint (data.num_handled, ==, 3);
861 g_dbus_connection_remove_filter (c, filter_id);
863 m2 = g_dbus_message_copy (m, &error);
864 g_assert_no_error (error);
865 r = g_dbus_connection_send_message_with_reply_sync (c,
867 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
870 NULL, /* GCancellable */
873 g_assert_no_error (error);
874 g_assert (r != NULL);
876 g_assert_cmpint (data.num_handled, ==, 3);
877 g_assert_cmpint (data.num_outgoing, ==, 3);
879 /* this is safe; testserver will exit once the bus goes away */
880 g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL));
881 /* wait for service to be available */
882 signal_handler_id = g_dbus_connection_signal_subscribe (c,
883 "org.freedesktop.DBus", /* sender */
884 "org.freedesktop.DBus",
886 "/org/freedesktop/DBus",
888 G_DBUS_SIGNAL_FLAGS_NONE,
889 test_connection_filter_name_owner_changed_signal_handler,
892 g_assert_cmpint (signal_handler_id, !=, 0);
893 timeout_mainloop_id = g_timeout_add (30000, test_connection_filter_on_timeout, NULL);
894 g_main_loop_run (loop);
895 g_source_remove (timeout_mainloop_id);
896 g_dbus_connection_signal_unsubscribe (c, signal_handler_id);
898 /* now test some combinations... */
899 filter_id = g_dbus_connection_add_filter (c,
904 effects.alter_incoming = FALSE;
905 effects.alter_outgoing = FALSE;
907 result = g_dbus_connection_call_sync (c,
908 "com.example.TestService", /* bus name */
909 "/com/example/TestObject", /* object path */
910 "com.example.Frob", /* interface name */
911 "HelloWorld", /* method name */
912 g_variant_new ("(s)", "Cat"), /* parameters */
913 G_VARIANT_TYPE ("(s)"), /* return type */
914 G_DBUS_CALL_FLAGS_NONE,
918 g_assert_no_error (error);
919 g_variant_get (result, "(&s)", &s);
920 g_assert_cmpstr (s, ==, "You greeted me with 'Cat'. Thanks!");
921 g_variant_unref (result);
923 effects.alter_incoming = TRUE;
924 effects.alter_outgoing = TRUE;
926 result = g_dbus_connection_call_sync (c,
927 "com.example.TestService", /* bus name */
928 "/com/example/TestObject", /* object path */
929 "com.example.Frob", /* interface name */
930 "HelloWorld", /* method name */
931 g_variant_new ("(s)", "Cat"), /* parameters */
932 G_VARIANT_TYPE ("(s)"), /* return type */
933 G_DBUS_CALL_FLAGS_NONE,
937 g_assert_no_error (error);
938 g_variant_get (result, "(&s)", &s);
939 g_assert_cmpstr (s, ==, "MOD: You greeted me with 'MOD: Cat'. Thanks!");
940 g_variant_unref (result);
943 g_dbus_connection_remove_filter (c, filter_id);
945 _g_object_wait_for_single_ref (c);
953 test_connection_basic (void)
955 GDBusConnection *connection;
957 GDBusCapabilityFlags flags;
961 gboolean exit_on_close;
963 GCredentials *credentials;
968 connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
969 g_assert_no_error (error);
970 g_assert (connection != NULL);
972 flags = g_dbus_connection_get_capabilities (connection);
973 g_assert (flags == G_DBUS_CAPABILITY_FLAGS_NONE ||
974 flags == G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
976 credentials = g_dbus_connection_get_peer_credentials (connection);
977 g_assert (credentials == NULL);
979 g_object_get (connection,
982 "unique-name", &name,
984 "exit-on-close", &exit_on_close,
985 "capabilities", &flags,
988 g_assert (G_IS_IO_STREAM (stream));
989 g_assert (g_dbus_is_guid (guid));
990 g_assert (g_dbus_is_unique_name (name));
992 g_assert (exit_on_close);
993 g_assert (flags == G_DBUS_CAPABILITY_FLAGS_NONE ||
994 flags == G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
995 g_object_unref (stream);
999 _g_object_wait_for_single_ref (connection);
1000 g_object_unref (connection);
1002 session_bus_down ();
1005 /* ---------------------------------------------------------------------------------------------------- */
1012 g_test_init (&argc, &argv, NULL);
1014 /* all the tests rely on a shared main loop */
1015 loop = g_main_loop_new (NULL, FALSE);
1017 /* all the tests use a session bus with a well-known address that we can bring up and down
1018 * using session_bus_up() and session_bus_down().
1020 g_unsetenv ("DISPLAY");
1021 g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
1023 g_test_add_func ("/gdbus/connection/basic", test_connection_basic);
1024 g_test_add_func ("/gdbus/connection/life-cycle", test_connection_life_cycle);
1025 g_test_add_func ("/gdbus/connection/send", test_connection_send);
1026 g_test_add_func ("/gdbus/connection/signals", test_connection_signals);
1027 g_test_add_func ("/gdbus/connection/filter", test_connection_filter);
1028 return g_test_run();