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>
30 #include <sys/types.h>
36 #include <glib/gstdio.h>
38 #include <gio/gnetworkingprivate.h>
39 #include <gio/gunixsocketaddress.h>
40 #include <gio/gunixfdlist.h>
42 /* used in test_overflow */
44 #include <gio/gunixconnection.h>
48 #include "gdbus-tests.h"
50 #include "gdbus-example-objectmanager-generated.h"
53 static gboolean is_unix = TRUE;
55 static gboolean is_unix = FALSE;
58 static gchar *tmp_address = NULL;
59 static gchar *test_guid = NULL;
60 static GMainLoop *service_loop = NULL;
61 static GDBusServer *server = NULL;
62 static GMainLoop *loop = NULL;
64 /* ---------------------------------------------------------------------------------------------------- */
65 /* Test that peer-to-peer connections work */
66 /* ---------------------------------------------------------------------------------------------------- */
71 gboolean accept_connection;
72 gint num_connection_attempts;
73 GPtrArray *current_connections;
74 guint num_method_calls;
75 gboolean signal_received;
78 static const gchar *test_interface_introspection_xml =
80 " <interface name='org.gtk.GDBus.PeerTestInterface'>"
81 " <method name='HelloPeer'>"
82 " <arg type='s' name='greeting' direction='in'/>"
83 " <arg type='s' name='response' direction='out'/>"
85 " <method name='EmitSignal'/>"
86 " <method name='EmitSignalWithNameSet'/>"
87 " <method name='OpenFile'>"
88 " <arg type='s' name='path' direction='in'/>"
90 " <signal name='PeerSignal'>"
91 " <arg type='s' name='a_string'/>"
93 " <property type='s' name='PeerProperty' access='read'/>"
96 static GDBusInterfaceInfo *test_interface_introspection_data = NULL;
99 test_interface_method_call (GDBusConnection *connection,
101 const gchar *object_path,
102 const gchar *interface_name,
103 const gchar *method_name,
104 GVariant *parameters,
105 GDBusMethodInvocation *invocation,
108 PeerData *data = user_data;
109 const GDBusMethodInfo *info;
111 data->num_method_calls++;
113 g_assert_cmpstr (object_path, ==, "/org/gtk/GDBus/PeerTestObject");
114 g_assert_cmpstr (interface_name, ==, "org.gtk.GDBus.PeerTestInterface");
116 info = g_dbus_method_invocation_get_method_info (invocation);
117 g_assert_cmpstr (info->name, ==, method_name);
119 if (g_strcmp0 (method_name, "HelloPeer") == 0)
121 const gchar *greeting;
124 g_variant_get (parameters, "(&s)", &greeting);
126 response = g_strdup_printf ("You greeted me with '%s'.",
128 g_dbus_method_invocation_return_value (invocation,
129 g_variant_new ("(s)", response));
132 else if (g_strcmp0 (method_name, "EmitSignal") == 0)
137 g_dbus_connection_emit_signal (connection,
139 "/org/gtk/GDBus/PeerTestObject",
140 "org.gtk.GDBus.PeerTestInterface",
144 g_assert_no_error (error);
145 g_dbus_method_invocation_return_value (invocation, NULL);
147 else if (g_strcmp0 (method_name, "EmitSignalWithNameSet") == 0)
151 GDBusMessage *message;
153 message = g_dbus_message_new_signal ("/org/gtk/GDBus/PeerTestObject",
154 "org.gtk.GDBus.PeerTestInterface",
155 "PeerSignalWithNameSet");
156 g_dbus_message_set_sender (message, ":1.42");
159 ret = g_dbus_connection_send_message (connection, message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error);
160 g_assert_no_error (error);
162 g_object_unref (message);
164 g_dbus_method_invocation_return_value (invocation, NULL);
166 else if (g_strcmp0 (method_name, "OpenFile") == 0)
173 GUnixFDList *fd_list;
175 g_variant_get (parameters, "(&s)", &path);
177 fd_list = g_unix_fd_list_new ();
181 fd = open (path, O_RDONLY);
182 g_unix_fd_list_append (fd_list, fd, &error);
183 g_assert_no_error (error);
186 reply = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
187 g_dbus_message_set_unix_fd_list (reply, fd_list);
188 g_object_unref (fd_list);
189 g_object_unref (invocation);
192 g_dbus_connection_send_message (connection,
194 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
195 NULL, /* out_serial */
197 g_assert_no_error (error);
198 g_object_unref (reply);
200 g_dbus_method_invocation_return_dbus_error (invocation,
201 "org.gtk.GDBus.NotOnUnix",
202 "Your OS does not support file descriptor passing");
207 g_assert_not_reached ();
212 test_interface_get_property (GDBusConnection *connection,
214 const gchar *object_path,
215 const gchar *interface_name,
216 const gchar *property_name,
220 g_assert_cmpstr (object_path, ==, "/org/gtk/GDBus/PeerTestObject");
221 g_assert_cmpstr (interface_name, ==, "org.gtk.GDBus.PeerTestInterface");
222 g_assert_cmpstr (property_name, ==, "PeerProperty");
224 return g_variant_new_string ("ThePropertyValue");
228 static const GDBusInterfaceVTable test_interface_vtable =
230 test_interface_method_call,
231 test_interface_get_property,
232 NULL /* set_property */
236 on_proxy_signal_received (GDBusProxy *proxy,
239 GVariant *parameters,
242 PeerData *data = user_data;
244 data->signal_received = TRUE;
246 g_assert (sender_name == NULL);
247 g_assert_cmpstr (signal_name, ==, "PeerSignal");
248 g_main_loop_quit (loop);
252 on_proxy_signal_received_with_name_set (GDBusProxy *proxy,
255 GVariant *parameters,
258 PeerData *data = user_data;
260 data->signal_received = TRUE;
262 g_assert_cmpstr (sender_name, ==, ":1.42");
263 g_assert_cmpstr (signal_name, ==, "PeerSignalWithNameSet");
264 g_main_loop_quit (loop);
267 /* ---------------------------------------------------------------------------------------------------- */
270 on_authorize_authenticated_peer (GDBusAuthObserver *observer,
272 GCredentials *credentials,
275 PeerData *data = user_data;
278 data->num_connection_attempts++;
281 if (!data->accept_connection)
284 g_main_loop_quit (loop);
290 /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
292 on_new_connection (GDBusServer *server,
293 GDBusConnection *connection,
296 PeerData *data = user_data;
300 //g_print ("Client connected.\n"
301 // "Negotiated capabilities: unix-fd-passing=%d\n",
302 // g_dbus_connection_get_capabilities (connection) & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
304 g_ptr_array_add (data->current_connections, g_object_ref (connection));
306 /* export object on the newly established connection */
308 reg_id = g_dbus_connection_register_object (connection,
309 "/org/gtk/GDBus/PeerTestObject",
310 test_interface_introspection_data,
311 &test_interface_vtable,
313 NULL, /* GDestroyNotify for data */
315 g_assert_no_error (error);
316 g_assert (reg_id > 0);
318 g_main_loop_quit (loop);
324 service_thread_func (gpointer user_data)
326 PeerData *data = user_data;
327 GMainContext *service_context;
328 GDBusAuthObserver *observer;
331 service_context = g_main_context_new ();
332 g_main_context_push_thread_default (service_context);
335 observer = g_dbus_auth_observer_new ();
336 server = g_dbus_server_new_sync (tmp_address,
337 G_DBUS_SERVER_FLAGS_NONE,
340 NULL, /* cancellable */
342 g_assert_no_error (error);
344 g_signal_connect (server,
346 G_CALLBACK (on_new_connection),
348 g_signal_connect (observer,
349 "authorize-authenticated-peer",
350 G_CALLBACK (on_authorize_authenticated_peer),
352 g_object_unref (observer);
354 g_dbus_server_start (server);
356 service_loop = g_main_loop_new (service_context, FALSE);
357 g_main_loop_run (service_loop);
359 g_main_context_pop_thread_default (service_context);
361 g_main_loop_unref (service_loop);
362 g_main_context_unref (service_context);
364 /* test code specifically unrefs the server - see below */
365 g_assert (server == NULL);
372 on_incoming_connection (GSocketService *service,
373 GSocketConnection *socket_connection,
374 GObject *source_object,
377 PeerData *data = user_data;
379 if (data->accept_connection)
383 GDBusConnection *connection;
386 connection = g_dbus_connection_new_sync (G_IO_STREAM (socket_connection),
388 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER,
389 NULL, /* cancellable */
391 g_assert_no_error (error);
393 g_ptr_array_add (data->current_connections, connection);
395 /* export object on the newly established connection */
397 reg_id = g_dbus_connection_register_object (connection,
398 "/org/gtk/GDBus/PeerTestObject",
399 &test_interface_introspection_data,
400 &test_interface_vtable,
402 NULL, /* GDestroyNotify for data */
404 g_assert_no_error (error);
405 g_assert (reg_id > 0);
410 /* don't do anything */
413 data->num_connection_attempts++;
415 g_main_loop_quit (loop);
417 /* stops other signal handlers from being invoked */
422 service_thread_func (gpointer data)
424 GMainContext *service_context;
426 GSocketAddress *address;
429 service_context = g_main_context_new ();
430 g_main_context_push_thread_default (service_context);
432 socket_path = g_strdup_printf ("/tmp/gdbus-test-pid-%d", getpid ());
433 address = g_unix_socket_address_new (socket_path);
435 service = g_socket_service_new ();
437 g_socket_listener_add_address (G_SOCKET_LISTENER (service),
439 G_SOCKET_TYPE_STREAM,
440 G_SOCKET_PROTOCOL_DEFAULT,
441 NULL, /* source_object */
442 NULL, /* effective_address */
444 g_assert_no_error (error);
445 g_signal_connect (service,
447 G_CALLBACK (on_incoming_connection),
449 g_socket_service_start (service);
451 service_loop = g_main_loop_new (service_context, FALSE);
452 g_main_loop_run (service_loop);
454 g_main_context_pop_thread_default (service_context);
456 g_main_loop_unref (service_loop);
457 g_main_context_unref (service_context);
459 g_object_unref (address);
460 g_free (socket_path);
465 /* ---------------------------------------------------------------------------------------------------- */
469 check_connection (gpointer user_data)
471 PeerData *data = user_data;
474 for (n = 0; n < data->current_connections->len; n++)
479 c = G_DBUS_CONNECTION (data->current_connections->pdata[n]);
480 stream = g_dbus_connection_get_stream (c);
482 g_debug ("In check_connection for %d: connection %p, stream %p", n, c, stream);
483 g_debug ("closed = %d", g_io_stream_is_closed (stream));
486 socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (stream));
487 g_debug ("socket_closed = %d", g_socket_is_closed (socket));
488 g_debug ("socket_condition_check = %d", g_socket_condition_check (socket, G_IO_IN|G_IO_OUT|G_IO_ERR|G_IO_HUP));
494 num_read = g_input_stream_read (g_io_stream_get_input_stream (stream),
501 g_debug ("error: %s", error->message);
502 g_error_free (error);
506 g_debug ("no error, read %d bytes", (gint) num_read);
514 on_do_disconnect_in_idle (gpointer data)
516 GDBusConnection *c = G_DBUS_CONNECTION (data);
517 g_debug ("GDC %p has ref_count %d", c, G_OBJECT (c)->ref_count);
518 g_dbus_connection_disconnect (c);
526 read_all_from_fd (gint fd, gsize *out_len, GError **error)
532 str = g_string_new (NULL);
536 num_read = read (fd, buf, sizeof (buf));
539 if (errno == EAGAIN || errno == EWOULDBLOCK)
543 g_io_error_from_errno (errno),
544 "Failed reading %d bytes into offset %d: %s",
550 else if (num_read > 0)
552 g_string_append_len (str, buf, num_read);
554 else if (num_read == 0)
563 return g_string_free (str, FALSE);
568 g_string_free (str, TRUE);
584 GThread *service_thread;
585 gulong signal_handler_id;
587 memset (&data, '\0', sizeof (PeerData));
588 data.current_connections = g_ptr_array_new_with_free_func (g_object_unref);
590 /* first try to connect when there is no server */
592 c = g_dbus_connection_new_for_address_sync (is_unix ? "unix:path=/tmp/gdbus-test-does-not-exist-pid" :
593 /* NOTE: Even if something is listening on port 12345 the connection
594 * will fail because the nonce file doesn't exist */
595 "nonce-tcp:host=localhost,port=12345,noncefile=this-does-not-exist-gdbus",
596 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
597 NULL, /* GDBusAuthObserver */
598 NULL, /* cancellable */
600 _g_assert_error_domain (error, G_IO_ERROR);
601 g_assert (!g_dbus_error_is_remote_error (error));
602 g_clear_error (&error);
603 g_assert (c == NULL);
605 /* bring up a server - we run the server in a different thread to avoid deadlocks */
607 service_thread = g_thread_new ("test_peer",
610 while (service_loop == NULL)
612 g_assert (server != NULL);
614 /* bring up a connection and accept it */
615 data.accept_connection = TRUE;
617 c = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
618 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
619 NULL, /* GDBusAuthObserver */
620 NULL, /* cancellable */
622 g_assert_no_error (error);
623 g_assert (c != NULL);
624 while (data.current_connections->len < 1)
625 g_main_loop_run (loop);
626 g_assert_cmpint (data.current_connections->len, ==, 1);
627 g_assert_cmpint (data.num_connection_attempts, ==, 1);
628 g_assert (g_dbus_connection_get_unique_name (c) == NULL);
629 g_assert_cmpstr (g_dbus_connection_get_guid (c), ==, test_guid);
631 /* check that we create a proxy, read properties, receive signals and invoke
632 * the HelloPeer() method. Since the server runs in another thread it's fine
633 * to use synchronous blocking API here.
636 proxy = g_dbus_proxy_new_sync (c,
637 G_DBUS_PROXY_FLAGS_NONE,
640 "/org/gtk/GDBus/PeerTestObject",
641 "org.gtk.GDBus.PeerTestInterface",
642 NULL, /* GCancellable */
644 g_assert_no_error (error);
645 g_assert (proxy != NULL);
647 value = g_dbus_proxy_get_cached_property (proxy, "PeerProperty");
648 g_assert_cmpstr (g_variant_get_string (value, NULL), ==, "ThePropertyValue");
650 /* try invoking a method */
652 result = g_dbus_proxy_call_sync (proxy,
654 g_variant_new ("(s)", "Hey Peer!"),
655 G_DBUS_CALL_FLAGS_NONE,
657 NULL, /* GCancellable */
659 g_assert_no_error (error);
660 g_variant_get (result, "(&s)", &s);
661 g_assert_cmpstr (s, ==, "You greeted me with 'Hey Peer!'.");
662 g_variant_unref (result);
663 g_assert_cmpint (data.num_method_calls, ==, 1);
665 /* make the other peer emit a signal - catch it */
666 signal_handler_id = g_signal_connect (proxy,
668 G_CALLBACK (on_proxy_signal_received),
670 g_assert (!data.signal_received);
671 g_dbus_proxy_call (proxy,
673 NULL, /* no arguments */
674 G_DBUS_CALL_FLAGS_NONE,
676 NULL, /* GCancellable */
677 NULL, /* GAsyncReadyCallback - we don't care about the result */
678 NULL); /* user_data */
679 g_main_loop_run (loop);
680 g_assert (data.signal_received);
681 g_assert_cmpint (data.num_method_calls, ==, 2);
682 g_signal_handler_disconnect (proxy, signal_handler_id);
684 /* Also ensure that messages with the sender header-field set gets
685 * delivered to the proxy - note that this doesn't really make sense
686 * e.g. names are meaning-less in a peer-to-peer case... but we
687 * support it because it makes sense in certain bridging
688 * applications - see e.g. #623815.
690 signal_handler_id = g_signal_connect (proxy,
692 G_CALLBACK (on_proxy_signal_received_with_name_set),
694 data.signal_received = FALSE;
695 g_dbus_proxy_call (proxy,
696 "EmitSignalWithNameSet",
697 NULL, /* no arguments */
698 G_DBUS_CALL_FLAGS_NONE,
700 NULL, /* GCancellable */
701 NULL, /* GAsyncReadyCallback - we don't care about the result */
702 NULL); /* user_data */
703 g_main_loop_run (loop);
704 g_assert (data.signal_received);
705 g_assert_cmpint (data.num_method_calls, ==, 3);
706 g_signal_handler_disconnect (proxy, signal_handler_id);
708 /* check for UNIX fd passing */
711 GDBusMessage *method_call_message;
712 GDBusMessage *method_reply_message;
713 GUnixFDList *fd_list;
720 method_call_message = g_dbus_message_new_method_call (NULL, /* name */
721 "/org/gtk/GDBus/PeerTestObject",
722 "org.gtk.GDBus.PeerTestInterface",
724 g_dbus_message_set_body (method_call_message, g_variant_new ("(s)", "/etc/hosts"));
726 method_reply_message = g_dbus_connection_send_message_with_reply_sync (c,
728 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
730 NULL, /* out_serial */
731 NULL, /* cancellable */
733 g_assert_no_error (error);
734 g_assert (g_dbus_message_get_message_type (method_reply_message) == G_DBUS_MESSAGE_TYPE_METHOD_RETURN);
735 fd_list = g_dbus_message_get_unix_fd_list (method_reply_message);
736 g_assert (fd_list != NULL);
737 g_assert_cmpint (g_unix_fd_list_get_length (fd_list), ==, 1);
739 fd = g_unix_fd_list_get (fd_list, 0, &error);
740 g_assert_no_error (error);
741 g_object_unref (method_call_message);
742 g_object_unref (method_reply_message);
746 buf = read_all_from_fd (fd, &len, &error);
747 g_assert_no_error (error);
748 g_assert (buf != NULL);
752 g_file_get_contents ("/etc/hosts",
756 g_assert_no_error (error);
757 g_assert_cmpint (len, ==, len2);
758 g_assert (memcmp (buf, buf2, len) == 0);
764 result = g_dbus_proxy_call_sync (proxy,
766 g_variant_new ("(s)", "boo"),
767 G_DBUS_CALL_FLAGS_NONE,
769 NULL, /* GCancellable */
771 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR);
772 g_assert (result == NULL);
773 g_error_free (error);
774 #endif /* G_OS_UNIX */
776 /* Check that g_socket_get_credentials() work - this really should
777 * be in a GSocket-specific test suite but no such test suite exists
782 GCredentials *credentials;
783 socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (g_dbus_connection_get_stream (c)));
784 g_assert (G_IS_SOCKET (socket));
786 credentials = g_socket_get_credentials (socket, &error);
789 struct ucred *native_creds;
790 g_assert_no_error (error);
791 g_assert (G_IS_CREDENTIALS (credentials));
792 native_creds = g_credentials_get_native (credentials, G_CREDENTIALS_TYPE_LINUX_UCRED);
793 g_assert (native_creds != NULL);
794 g_assert (native_creds->uid == getuid ());
795 g_assert (native_creds->gid == getgid ());
796 g_assert (native_creds->pid == getpid ());
798 g_object_unref (credentials);
799 #elif defined (__OpenBSD__)
801 struct sockpeercred *native_creds;
802 g_assert_no_error (error);
803 g_assert (G_IS_CREDENTIALS (credentials));
804 native_creds = g_credentials_get_native (credentials, G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED);
805 g_assert (native_creds != NULL);
806 g_assert (native_creds->uid == getuid ());
807 g_assert (native_creds->gid == getgid ());
808 g_assert (native_creds->pid == getpid ());
810 g_object_unref (credentials);
812 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
813 g_assert (credentials == NULL);
818 /* bring up a connection - don't accept it - this should fail
820 data.accept_connection = FALSE;
822 c2 = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
823 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
824 NULL, /* GDBusAuthObserver */
825 NULL, /* cancellable */
827 _g_assert_error_domain (error, G_IO_ERROR);
828 g_error_free (error);
829 g_assert (c2 == NULL);
832 /* TODO: THIS TEST DOESN'T WORK YET */
834 /* bring up a connection - accept it.. then disconnect from the client side - check
835 * that the server side gets the disconnect signal.
838 data.accept_connection = TRUE;
839 c2 = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
840 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
841 NULL, /* GDBusAuthObserver */
842 NULL, /* cancellable */
844 g_assert_no_error (error);
845 g_assert (c2 != NULL);
846 g_assert (!g_dbus_connection_get_is_disconnected (c2));
847 while (data.num_connection_attempts < 3)
848 g_main_loop_run (loop);
849 g_assert_cmpint (data.current_connections->len, ==, 2);
850 g_assert_cmpint (data.num_connection_attempts, ==, 3);
851 g_assert (!g_dbus_connection_get_is_disconnected (G_DBUS_CONNECTION (data.current_connections->pdata[1])));
852 g_idle_add (on_do_disconnect_in_idle, c2);
853 g_debug ("==================================================");
854 g_debug ("==================================================");
855 g_debug ("==================================================");
856 g_debug ("waiting for disconnect on connection %p, stream %p",
857 data.current_connections->pdata[1],
858 g_dbus_connection_get_stream (data.current_connections->pdata[1]));
860 g_timeout_add (2000, check_connection, &data);
861 //_g_assert_signal_received (G_DBUS_CONNECTION (data.current_connections->pdata[1]), "closed");
862 g_main_loop_run (loop);
863 g_assert (g_dbus_connection_get_is_disconnected (G_DBUS_CONNECTION (data.current_connections->pdata[1])));
864 g_ptr_array_set_size (data.current_connections, 1); /* remove disconnected connection object */
867 /* unref the server and stop listening for new connections
869 * This won't bring down the established connections - check that c is still connected
870 * by invoking a method
872 //g_socket_service_stop (service);
873 //g_object_unref (service);
874 g_dbus_server_stop (server);
875 g_object_unref (server);
879 result = g_dbus_proxy_call_sync (proxy,
881 g_variant_new ("(s)", "Hey Again Peer!"),
882 G_DBUS_CALL_FLAGS_NONE,
884 NULL, /* GCancellable */
886 g_assert_no_error (error);
887 g_variant_get (result, "(&s)", &s);
888 g_assert_cmpstr (s, ==, "You greeted me with 'Hey Again Peer!'.");
889 g_variant_unref (result);
890 g_assert_cmpint (data.num_method_calls, ==, 5);
893 /* TODO: THIS TEST DOESN'T WORK YET */
895 /* now disconnect from the server side - check that the client side gets the signal */
896 g_assert_cmpint (data.current_connections->len, ==, 1);
897 g_assert (G_DBUS_CONNECTION (data.current_connections->pdata[0]) != c);
898 g_dbus_connection_disconnect (G_DBUS_CONNECTION (data.current_connections->pdata[0]));
899 if (!g_dbus_connection_get_is_disconnected (c))
900 _g_assert_signal_received (c, "closed");
901 g_assert (g_dbus_connection_get_is_disconnected (c));
905 g_ptr_array_unref (data.current_connections);
906 g_object_unref (proxy);
908 g_main_loop_quit (service_loop);
909 g_thread_join (service_thread);
912 /* ---------------------------------------------------------------------------------------------------- */
917 GMainContext *context;
924 dmp_data_free (DmpData *data)
926 g_main_loop_unref (data->loop);
927 g_main_context_unref (data->context);
928 g_object_unref (data->server);
929 g_list_free_full (data->connections, g_object_unref);
934 dmp_on_method_call (GDBusConnection *connection,
936 const gchar *object_path,
937 const gchar *interface_name,
938 const gchar *method_name,
939 GVariant *parameters,
940 GDBusMethodInvocation *invocation,
943 //DmpData *data = user_data;
946 g_variant_get (parameters,
950 g_dbus_method_invocation_return_value (invocation,
951 g_variant_new ("(i)", first + second));
954 static const GDBusInterfaceVTable dmp_interface_vtable =
957 NULL, /* get_property */
958 NULL /* set_property */
962 /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
964 dmp_on_new_connection (GDBusServer *server,
965 GDBusConnection *connection,
968 DmpData *data = user_data;
972 /* accept the connection */
973 data->connections = g_list_prepend (data->connections, g_object_ref (connection));
976 node = g_dbus_node_info_new_for_xml ("<node>"
977 " <interface name='org.gtk.GDBus.DmpInterface'>"
978 " <method name='AddPair'>"
979 " <arg type='i' name='first' direction='in'/>"
980 " <arg type='i' name='second' direction='in'/>"
981 " <arg type='i' name='sum' direction='out'/>"
986 g_assert_no_error (error);
988 /* sleep 100ms before exporting an object - this is to test that
989 * G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING really works
990 * (GDBusServer uses this feature).
994 /* export an object */
996 g_dbus_connection_register_object (connection,
999 &dmp_interface_vtable,
1003 g_dbus_node_info_unref (node);
1009 dmp_thread_func (gpointer user_data)
1011 DmpData *data = user_data;
1015 data->context = g_main_context_new ();
1016 g_main_context_push_thread_default (data->context);
1019 guid = g_dbus_generate_guid ();
1020 data->server = g_dbus_server_new_sync (tmp_address,
1021 G_DBUS_SERVER_FLAGS_NONE,
1023 NULL, /* GDBusAuthObserver */
1024 NULL, /* GCancellable */
1026 g_assert_no_error (error);
1027 g_signal_connect (data->server,
1029 G_CALLBACK (dmp_on_new_connection),
1032 g_dbus_server_start (data->server);
1034 data->loop = g_main_loop_new (data->context, FALSE);
1035 g_main_loop_run (data->loop);
1037 g_main_context_pop_thread_default (data->context);
1044 delayed_message_processing (void)
1048 GThread *service_thread;
1051 data = g_new0 (DmpData, 1);
1053 service_thread = g_thread_new ("dmp",
1056 while (data->server == NULL || !g_dbus_server_is_active (data->server))
1059 for (n = 0; n < 5; n++)
1066 c = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (data->server),
1067 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1068 NULL, /* GDBusAuthObserver */
1069 NULL, /* GCancellable */
1071 g_assert_no_error (error);
1074 res = g_dbus_connection_call_sync (c,
1075 NULL, /* bus name */
1077 "org.gtk.GDBus.DmpInterface",
1079 g_variant_new ("(ii)", 2, n),
1080 G_VARIANT_TYPE ("(i)"),
1081 G_DBUS_CALL_FLAGS_NONE,
1082 -1, /* timeout_msec */
1083 NULL, /* GCancellable */
1085 g_assert_no_error (error);
1086 g_variant_get (res, "(i)", &val);
1087 g_assert_cmpint (val, ==, 2 + n);
1088 g_variant_unref (res);
1092 g_main_loop_quit (data->loop);
1093 g_thread_join (service_thread);
1094 dmp_data_free (data);
1097 /* ---------------------------------------------------------------------------------------------------- */
1100 nonce_tcp_on_authorize_authenticated_peer (GDBusAuthObserver *observer,
1102 GCredentials *credentials,
1105 PeerData *data = user_data;
1106 gboolean authorized;
1108 data->num_connection_attempts++;
1111 if (!data->accept_connection)
1114 g_main_loop_quit (loop);
1120 /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
1122 nonce_tcp_on_new_connection (GDBusServer *server,
1123 GDBusConnection *connection,
1126 PeerData *data = user_data;
1128 g_ptr_array_add (data->current_connections, g_object_ref (connection));
1130 g_main_loop_quit (loop);
1136 nonce_tcp_service_thread_func (gpointer user_data)
1138 PeerData *data = user_data;
1139 GMainContext *service_context;
1140 GDBusAuthObserver *observer;
1143 service_context = g_main_context_new ();
1144 g_main_context_push_thread_default (service_context);
1147 observer = g_dbus_auth_observer_new ();
1148 server = g_dbus_server_new_sync ("nonce-tcp:",
1149 G_DBUS_SERVER_FLAGS_NONE,
1152 NULL, /* cancellable */
1154 g_assert_no_error (error);
1156 g_signal_connect (server,
1158 G_CALLBACK (nonce_tcp_on_new_connection),
1160 g_signal_connect (observer,
1161 "authorize-authenticated-peer",
1162 G_CALLBACK (nonce_tcp_on_authorize_authenticated_peer),
1164 g_object_unref (observer);
1166 g_dbus_server_start (server);
1168 service_loop = g_main_loop_new (service_context, FALSE);
1169 g_main_loop_run (service_loop);
1171 g_main_context_pop_thread_default (service_context);
1173 g_main_loop_unref (service_loop);
1174 g_main_context_unref (service_context);
1176 /* test code specifically unrefs the server - see below */
1177 g_assert (server == NULL);
1183 test_nonce_tcp (void)
1187 GThread *service_thread;
1192 const gchar *address;
1194 memset (&data, '\0', sizeof (PeerData));
1195 data.current_connections = g_ptr_array_new_with_free_func (g_object_unref);
1199 service_loop = NULL;
1200 service_thread = g_thread_new ("nonce-tcp-service",
1201 nonce_tcp_service_thread_func,
1203 while (service_loop == NULL)
1205 g_assert (server != NULL);
1208 /* bring up a connection and accept it */
1209 data.accept_connection = TRUE;
1211 c = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
1212 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1213 NULL, /* GDBusAuthObserver */
1214 NULL, /* cancellable */
1216 g_assert_no_error (error);
1217 g_assert (c != NULL);
1218 while (data.current_connections->len < 1)
1220 g_assert_cmpint (data.current_connections->len, ==, 1);
1221 g_assert_cmpint (data.num_connection_attempts, ==, 1);
1222 g_assert (g_dbus_connection_get_unique_name (c) == NULL);
1223 g_assert_cmpstr (g_dbus_connection_get_guid (c), ==, test_guid);
1226 /* now, try to subvert the nonce file (this assumes noncefile is the last key/value pair)
1229 address = g_dbus_server_get_client_address (server);
1231 s = strstr (address, "noncefile=");
1232 g_assert (s != NULL);
1233 s += sizeof "noncefile=" - 1;
1234 nonce_file = g_strdup (s);
1236 /* First try invalid data in the nonce file - this will actually
1237 * make the client send this and the server will reject it. The way
1238 * it works is that if the nonce doesn't match, the server will
1239 * simply close the connection. So, from the client point of view,
1240 * we can see a variety of errors.
1243 res = g_file_set_contents (nonce_file,
1247 g_assert_no_error (error);
1249 c = g_dbus_connection_new_for_address_sync (address,
1250 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1251 NULL, /* GDBusAuthObserver */
1252 NULL, /* cancellable */
1254 _g_assert_error_domain (error, G_IO_ERROR);
1255 g_error_free (error);
1256 g_assert (c == NULL);
1258 /* Then try with a nonce-file of incorrect length - this will make
1259 * the client complain - we won't even try connecting to the server
1263 res = g_file_set_contents (nonce_file,
1264 "0123456789012345_",
1267 g_assert_no_error (error);
1269 c = g_dbus_connection_new_for_address_sync (address,
1270 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1271 NULL, /* GDBusAuthObserver */
1272 NULL, /* cancellable */
1274 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
1275 g_error_free (error);
1276 g_assert (c == NULL);
1278 /* Finally try with no nonce-file at all */
1279 g_assert_cmpint (g_unlink (nonce_file), ==, 0);
1281 c = g_dbus_connection_new_for_address_sync (address,
1282 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1283 NULL, /* GDBusAuthObserver */
1284 NULL, /* cancellable */
1286 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
1287 g_error_free (error);
1288 g_assert (c == NULL);
1290 g_free (nonce_file);
1292 g_dbus_server_stop (server);
1293 g_object_unref (server);
1296 g_main_loop_quit (service_loop);
1297 g_thread_join (service_thread);
1301 test_credentials (void)
1303 GCredentials *c1, *c2;
1307 c1 = g_credentials_new ();
1308 c2 = g_credentials_new ();
1311 if (g_credentials_set_unix_user (c2, getuid (), &error))
1312 g_assert_no_error (error);
1314 g_clear_error (&error);
1315 g_assert (g_credentials_is_same_user (c1, c2, &error));
1316 g_assert_no_error (error);
1318 desc = g_credentials_to_string (c1);
1319 g_assert (desc != NULL);
1322 g_object_unref (c1);
1323 g_object_unref (c2);
1326 /* ---------------------------------------------------------------------------------------------------- */
1330 /* Chosen to be big enough to overflow the socket buffer */
1331 #define OVERFLOW_NUM_SIGNALS 5000
1332 #define OVERFLOW_TIMEOUT_SEC 10
1334 static GDBusMessage *
1335 overflow_filter_func (GDBusConnection *connection,
1336 GDBusMessage *message,
1340 volatile gint *counter = user_data;
1346 overflow_on_500ms_later_func (gpointer user_data)
1348 g_main_loop_quit (loop);
1349 return FALSE; /* don't keep the idle */
1353 test_overflow (void)
1358 GSocketConnection *socket_connection;
1359 GDBusConnection *producer, *consumer;
1362 volatile gint n_messages_received;
1363 volatile gint n_messages_sent;
1365 g_assert_cmpint (socketpair (AF_UNIX, SOCK_STREAM, 0, sv), ==, 0);
1368 socket = g_socket_new_from_fd (sv[0], &error);
1369 g_assert_no_error (error);
1370 socket_connection = g_socket_connection_factory_create_connection (socket);
1371 g_assert (socket_connection != NULL);
1372 g_object_unref (socket);
1373 producer = g_dbus_connection_new_sync (G_IO_STREAM (socket_connection),
1375 G_DBUS_CONNECTION_FLAGS_NONE,
1376 NULL, /* GDBusAuthObserver */
1377 NULL, /* GCancellable */
1379 g_dbus_connection_set_exit_on_close (producer, TRUE);
1380 g_assert_no_error (error);
1381 g_object_unref (socket_connection);
1382 n_messages_sent = 0;
1383 g_dbus_connection_add_filter (producer, overflow_filter_func, (gpointer) &n_messages_sent, NULL);
1385 /* send enough data that we get an EAGAIN */
1386 for (n = 0; n < OVERFLOW_NUM_SIGNALS; n++)
1389 g_dbus_connection_emit_signal (producer,
1390 NULL, /* destination */
1392 "org.foo.Interface",
1394 g_variant_new ("(s)", "a string"),
1396 g_assert_no_error (error);
1399 /* sleep for 0.5 sec (to allow the GDBus IO thread to fill up the
1400 * kernel buffers) and verify that n_messages_sent <
1401 * OVERFLOW_NUM_SIGNALS
1403 * This is to verify that not all the submitted messages have been
1404 * sent to the underlying transport.
1406 g_timeout_add (500, overflow_on_500ms_later_func, NULL);
1407 g_main_loop_run (loop);
1408 g_assert_cmpint (n_messages_sent, <, OVERFLOW_NUM_SIGNALS);
1410 /* now suck it all out as a client, and add it up */
1411 socket = g_socket_new_from_fd (sv[1], &error);
1412 g_assert_no_error (error);
1413 socket_connection = g_socket_connection_factory_create_connection (socket);
1414 g_assert (socket_connection != NULL);
1415 g_object_unref (socket);
1416 consumer = g_dbus_connection_new_sync (G_IO_STREAM (socket_connection),
1418 G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING,
1419 NULL, /* GDBusAuthObserver */
1420 NULL, /* GCancellable */
1422 g_assert_no_error (error);
1423 g_object_unref (socket_connection);
1424 n_messages_received = 0;
1425 g_dbus_connection_add_filter (consumer, overflow_filter_func, (gpointer) &n_messages_received, NULL);
1426 g_dbus_connection_start_message_processing (consumer);
1428 timer = g_timer_new ();
1429 g_timer_start (timer);
1431 while (n_messages_received < OVERFLOW_NUM_SIGNALS && g_timer_elapsed (timer, NULL) < OVERFLOW_TIMEOUT_SEC)
1432 g_main_context_iteration (NULL, FALSE);
1434 g_assert_cmpint (n_messages_sent, ==, OVERFLOW_NUM_SIGNALS);
1435 g_assert_cmpint (n_messages_received, ==, OVERFLOW_NUM_SIGNALS);
1437 g_timer_destroy (timer);
1438 g_object_unref (consumer);
1439 g_object_unref (producer);
1443 test_overflow (void)
1445 /* TODO: test this with e.g. GWin32InputStream/GWin32OutputStream */
1449 /* ---------------------------------------------------------------------------------------------------- */
1452 tcp_anonymous_on_new_connection (GDBusServer *server,
1453 GDBusConnection *connection,
1456 gboolean *seen_connection = user_data;
1457 *seen_connection = TRUE;
1462 tcp_anonymous_service_thread_func (gpointer user_data)
1464 gboolean *seen_connection = user_data;
1465 GMainContext *service_context;
1468 service_context = g_main_context_new ();
1469 g_main_context_push_thread_default (service_context);
1472 server = g_dbus_server_new_sync ("tcp:",
1473 G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS,
1475 NULL, /* GDBusObserver* */
1476 NULL, /* GCancellable* */
1478 g_assert_no_error (error);
1480 g_signal_connect (server,
1482 G_CALLBACK (tcp_anonymous_on_new_connection),
1485 g_dbus_server_start (server);
1487 service_loop = g_main_loop_new (service_context, FALSE);
1488 g_main_loop_run (service_loop);
1490 g_main_context_pop_thread_default (service_context);
1492 g_main_loop_unref (service_loop);
1493 g_main_context_unref (service_context);
1499 test_tcp_anonymous (void)
1501 gboolean seen_connection;
1502 GThread *service_thread;
1503 GDBusConnection *connection;
1506 seen_connection = FALSE;
1507 service_loop = NULL;
1508 service_thread = g_thread_new ("tcp-anon-service",
1509 tcp_anonymous_service_thread_func,
1511 while (service_loop == NULL)
1513 g_assert (server != NULL);
1516 connection = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
1517 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1518 NULL, /* GDBusAuthObserver* */
1519 NULL, /* GCancellable */
1521 g_assert_no_error (error);
1522 g_assert (connection != NULL);
1524 while (!seen_connection)
1527 g_object_unref (connection);
1529 g_main_loop_quit (service_loop);
1530 g_dbus_server_stop (server);
1531 g_object_unref (server);
1534 g_thread_join (service_thread);
1537 /* ---------------------------------------------------------------------------------------------------- */
1539 static GDBusServer *codegen_server = NULL;
1542 codegen_on_animal_poke (ExampleAnimal *animal,
1543 GDBusMethodInvocation *invocation,
1545 gboolean make_happy,
1548 if ((make_sad && make_happy) || (!make_sad && !make_happy))
1550 g_main_loop_quit (service_loop);
1552 g_dbus_method_invocation_return_dbus_error (invocation,
1553 "org.gtk.GDBus.Examples.ObjectManager.Error.Failed",
1554 "Exactly one of make_sad or make_happy must be TRUE");
1560 if (g_strcmp0 (example_animal_get_mood (animal), "Sad") == 0)
1562 g_dbus_method_invocation_return_dbus_error (invocation,
1563 "org.gtk.GDBus.Examples.ObjectManager.Error.SadAnimalIsSad",
1564 "Sad animal is already sad");
1568 example_animal_set_mood (animal, "Sad");
1569 example_animal_complete_poke (animal, invocation);
1575 if (g_strcmp0 (example_animal_get_mood (animal), "Happy") == 0)
1577 g_dbus_method_invocation_return_dbus_error (invocation,
1578 "org.gtk.GDBus.Examples.ObjectManager.Error.HappyAnimalIsHappy",
1579 "Happy animal is already happy");
1583 example_animal_set_mood (animal, "Happy");
1584 example_animal_complete_poke (animal, invocation);
1588 g_assert_not_reached ();
1591 return TRUE; /* to indicate that the method was handled */
1594 /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
1596 codegen_on_new_connection (GDBusServer *server,
1597 GDBusConnection *connection,
1600 ExampleAnimal *animal = user_data;
1601 GError *error = NULL;
1603 /* g_print ("Client connected.\n" */
1604 /* "Negotiated capabilities: unix-fd-passing=%d\n", */
1605 /* g_dbus_connection_get_capabilities (connection) & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING); */
1607 g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (animal), connection,
1608 "/Example/Animals/000", &error);
1609 g_assert_no_error (error);
1615 codegen_service_thread_func (gpointer user_data)
1617 GMainContext *service_context;
1618 ExampleAnimal *animal;
1619 GError *error = NULL;
1621 service_context = g_main_context_new ();
1622 g_main_context_push_thread_default (service_context);
1624 /* Create the animal in the right thread context */
1625 animal = example_animal_skeleton_new ();
1627 /* Handle Poke() D-Bus method invocations on the .Animal interface */
1628 g_signal_connect (animal, "handle-poke",
1629 G_CALLBACK (codegen_on_animal_poke),
1630 NULL); /* user_data */
1632 codegen_server = g_dbus_server_new_sync (tmp_address,
1633 G_DBUS_SERVER_FLAGS_NONE,
1635 NULL, /* observer */
1636 NULL, /* cancellable */
1638 g_assert_no_error (error);
1639 g_dbus_server_start (codegen_server);
1641 g_signal_connect (codegen_server, "new-connection",
1642 G_CALLBACK (codegen_on_new_connection),
1645 service_loop = g_main_loop_new (service_context, FALSE);
1646 g_main_loop_run (service_loop);
1648 g_object_unref (animal);
1650 g_main_context_pop_thread_default (service_context);
1652 g_main_loop_unref (service_loop);
1653 g_main_context_unref (service_context);
1655 g_dbus_server_stop (codegen_server);
1656 g_object_unref (codegen_server);
1657 codegen_server = NULL;
1664 codegen_quit_mainloop_timeout (gpointer data)
1666 g_main_loop_quit (loop);
1671 codegen_test_peer (void)
1673 GDBusConnection *connection;
1674 ExampleAnimal *animal1, *animal2;
1675 GThread *service_thread;
1676 GError *error = NULL;
1679 /* bring up a server - we run the server in a different thread to avoid deadlocks */
1680 service_loop = NULL;
1681 service_thread = g_thread_new ("codegen_test_peer",
1682 codegen_service_thread_func,
1684 while (service_loop == NULL)
1686 g_assert (codegen_server != NULL);
1688 /* Get an animal 1 ... */
1689 connection = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (codegen_server),
1690 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1691 NULL, /* GDBusAuthObserver */
1692 NULL, /* cancellable */
1694 g_assert_no_error (error);
1695 g_assert (connection != NULL);
1697 animal1 = example_animal_proxy_new_sync (connection, 0, NULL,
1698 "/Example/Animals/000", NULL, &error);
1699 g_assert_no_error (error);
1700 g_assert (animal1 != NULL);
1701 g_object_unref (connection);
1703 /* Get animal 2 ... */
1704 connection = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (codegen_server),
1705 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1706 NULL, /* GDBusAuthObserver */
1707 NULL, /* cancellable */
1709 g_assert_no_error (error);
1710 g_assert (connection != NULL);
1712 animal2 = example_animal_proxy_new_sync (connection, 0, NULL,
1713 "/Example/Animals/000", NULL, &error);
1714 g_assert_no_error (error);
1715 g_assert (animal2 != NULL);
1716 g_object_unref (connection);
1718 /* Make animal sad via animal1 */
1719 example_animal_call_poke_sync (animal1, TRUE, FALSE, NULL, &error);
1720 g_assert_no_error (error);
1722 /* Poke server and make sure animal is updated */
1723 value = g_dbus_proxy_call_sync (G_DBUS_PROXY (animal1),
1724 "org.freedesktop.DBus.Peer.Ping",
1725 NULL, G_DBUS_CALL_FLAGS_NONE, -1,
1727 g_assert_no_error (error);
1728 g_assert (value != NULL);
1729 g_variant_unref (value);
1731 /* Give the proxies a chance to refresh in the defaul main loop */
1732 g_timeout_add (100, codegen_quit_mainloop_timeout, NULL);
1733 g_main_loop_run (loop);
1735 /* Assert animals are sad */
1736 g_assert_cmpstr (example_animal_get_mood (animal1), ==, "Sad");
1737 g_assert_cmpstr (example_animal_get_mood (animal2), ==, "Sad");
1739 /* Make animal happy via animal2 */
1740 example_animal_call_poke_sync (animal2, FALSE, TRUE, NULL, &error);
1741 g_assert_no_error (error);
1743 /* Poke server and make sure animal is updated */
1744 value = g_dbus_proxy_call_sync (G_DBUS_PROXY (animal2),
1745 "org.freedesktop.DBus.Peer.Ping",
1746 NULL, G_DBUS_CALL_FLAGS_NONE, -1,
1748 g_assert_no_error (error);
1749 g_assert (value != NULL);
1750 g_variant_unref (value);
1752 /* Give the proxies a chance to refresh in the defaul main loop */
1753 g_timeout_add (1000, codegen_quit_mainloop_timeout, NULL);
1754 g_main_loop_run (loop);
1756 /* Assert animals are happy */
1757 g_assert_cmpstr (example_animal_get_mood (animal1), ==, "Happy");
1758 g_assert_cmpstr (example_animal_get_mood (animal2), ==, "Happy");
1760 /* This final call making the animal happy and sad will cause
1761 * the server to quit, when the server quits we dont get property
1762 * change notifications anyway because those are done from an idle handler
1764 example_animal_call_poke_sync (animal2, TRUE, TRUE, NULL, &error);
1766 g_object_unref (animal1);
1767 g_object_unref (animal2);
1768 g_thread_join (service_thread);
1771 /* ---------------------------------------------------------------------------------------------------- */
1779 GDBusNodeInfo *introspection_data = NULL;
1780 gchar *tmpdir = NULL;
1783 g_test_init (&argc, &argv, NULL);
1785 g_unsetenv ("DBUS_SESSION_BUS_ADDRESS");
1787 introspection_data = g_dbus_node_info_new_for_xml (test_interface_introspection_xml, NULL);
1788 g_assert (introspection_data != NULL);
1789 test_interface_introspection_data = introspection_data->interfaces[0];
1791 test_guid = g_dbus_generate_guid ();
1795 if (g_unix_socket_address_abstract_names_supported ())
1796 tmp_address = g_strdup ("unix:tmpdir=/tmp/gdbus-test-");
1799 tmpdir = g_dir_make_tmp ("gdbus-test-XXXXXX", NULL);
1800 tmp_address = g_strdup_printf ("unix:tmpdir=%s", tmpdir);
1804 tmp_address = g_strdup ("nonce-tcp:");
1806 /* all the tests rely on a shared main loop */
1807 loop = g_main_loop_new (NULL, FALSE);
1809 g_test_add_func ("/gdbus/peer-to-peer", test_peer);
1810 g_test_add_func ("/gdbus/delayed-message-processing", delayed_message_processing);
1811 g_test_add_func ("/gdbus/nonce-tcp", test_nonce_tcp);
1812 g_test_add_func ("/gdbus/tcp-anonymous", test_tcp_anonymous);
1813 g_test_add_func ("/gdbus/credentials", test_credentials);
1814 g_test_add_func ("/gdbus/overflow", test_overflow);
1815 g_test_add_func ("/gdbus/codegen-peer-to-peer", codegen_test_peer);
1819 g_main_loop_unref (loop);
1821 g_dbus_node_info_unref (introspection_data);
1823 g_free (tmp_address);