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_foreach (data->connections, (GFunc) g_object_unref, NULL);
930 g_list_free (data->connections);
935 dmp_on_method_call (GDBusConnection *connection,
937 const gchar *object_path,
938 const gchar *interface_name,
939 const gchar *method_name,
940 GVariant *parameters,
941 GDBusMethodInvocation *invocation,
944 //DmpData *data = user_data;
947 g_variant_get (parameters,
951 g_dbus_method_invocation_return_value (invocation,
952 g_variant_new ("(i)", first + second));
955 static const GDBusInterfaceVTable dmp_interface_vtable =
958 NULL, /* get_property */
959 NULL /* set_property */
963 /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
965 dmp_on_new_connection (GDBusServer *server,
966 GDBusConnection *connection,
969 DmpData *data = user_data;
973 /* accept the connection */
974 data->connections = g_list_prepend (data->connections, g_object_ref (connection));
977 node = g_dbus_node_info_new_for_xml ("<node>"
978 " <interface name='org.gtk.GDBus.DmpInterface'>"
979 " <method name='AddPair'>"
980 " <arg type='i' name='first' direction='in'/>"
981 " <arg type='i' name='second' direction='in'/>"
982 " <arg type='i' name='sum' direction='out'/>"
987 g_assert_no_error (error);
989 /* sleep 100ms before exporting an object - this is to test that
990 * G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING really works
991 * (GDBusServer uses this feature).
995 /* export an object */
997 g_dbus_connection_register_object (connection,
1000 &dmp_interface_vtable,
1004 g_dbus_node_info_unref (node);
1010 dmp_thread_func (gpointer user_data)
1012 DmpData *data = user_data;
1016 data->context = g_main_context_new ();
1017 g_main_context_push_thread_default (data->context);
1020 guid = g_dbus_generate_guid ();
1021 data->server = g_dbus_server_new_sync (tmp_address,
1022 G_DBUS_SERVER_FLAGS_NONE,
1024 NULL, /* GDBusAuthObserver */
1025 NULL, /* GCancellable */
1027 g_assert_no_error (error);
1028 g_signal_connect (data->server,
1030 G_CALLBACK (dmp_on_new_connection),
1033 g_dbus_server_start (data->server);
1035 data->loop = g_main_loop_new (data->context, FALSE);
1036 g_main_loop_run (data->loop);
1038 g_main_context_pop_thread_default (data->context);
1045 delayed_message_processing (void)
1049 GThread *service_thread;
1052 data = g_new0 (DmpData, 1);
1054 service_thread = g_thread_new ("dmp",
1057 while (data->server == NULL || !g_dbus_server_is_active (data->server))
1060 for (n = 0; n < 5; n++)
1067 c = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (data->server),
1068 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1069 NULL, /* GDBusAuthObserver */
1070 NULL, /* GCancellable */
1072 g_assert_no_error (error);
1075 res = g_dbus_connection_call_sync (c,
1076 NULL, /* bus name */
1078 "org.gtk.GDBus.DmpInterface",
1080 g_variant_new ("(ii)", 2, n),
1081 G_VARIANT_TYPE ("(i)"),
1082 G_DBUS_CALL_FLAGS_NONE,
1083 -1, /* timeout_msec */
1084 NULL, /* GCancellable */
1086 g_assert_no_error (error);
1087 g_variant_get (res, "(i)", &val);
1088 g_assert_cmpint (val, ==, 2 + n);
1089 g_variant_unref (res);
1093 g_main_loop_quit (data->loop);
1094 g_thread_join (service_thread);
1095 dmp_data_free (data);
1098 /* ---------------------------------------------------------------------------------------------------- */
1101 nonce_tcp_on_authorize_authenticated_peer (GDBusAuthObserver *observer,
1103 GCredentials *credentials,
1106 PeerData *data = user_data;
1107 gboolean authorized;
1109 data->num_connection_attempts++;
1112 if (!data->accept_connection)
1115 g_main_loop_quit (loop);
1121 /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
1123 nonce_tcp_on_new_connection (GDBusServer *server,
1124 GDBusConnection *connection,
1127 PeerData *data = user_data;
1129 g_ptr_array_add (data->current_connections, g_object_ref (connection));
1131 g_main_loop_quit (loop);
1137 nonce_tcp_service_thread_func (gpointer user_data)
1139 PeerData *data = user_data;
1140 GMainContext *service_context;
1141 GDBusAuthObserver *observer;
1144 service_context = g_main_context_new ();
1145 g_main_context_push_thread_default (service_context);
1148 observer = g_dbus_auth_observer_new ();
1149 server = g_dbus_server_new_sync ("nonce-tcp:",
1150 G_DBUS_SERVER_FLAGS_NONE,
1153 NULL, /* cancellable */
1155 g_assert_no_error (error);
1157 g_signal_connect (server,
1159 G_CALLBACK (nonce_tcp_on_new_connection),
1161 g_signal_connect (observer,
1162 "authorize-authenticated-peer",
1163 G_CALLBACK (nonce_tcp_on_authorize_authenticated_peer),
1165 g_object_unref (observer);
1167 g_dbus_server_start (server);
1169 service_loop = g_main_loop_new (service_context, FALSE);
1170 g_main_loop_run (service_loop);
1172 g_main_context_pop_thread_default (service_context);
1174 g_main_loop_unref (service_loop);
1175 g_main_context_unref (service_context);
1177 /* test code specifically unrefs the server - see below */
1178 g_assert (server == NULL);
1184 test_nonce_tcp (void)
1188 GThread *service_thread;
1193 const gchar *address;
1195 memset (&data, '\0', sizeof (PeerData));
1196 data.current_connections = g_ptr_array_new_with_free_func (g_object_unref);
1200 service_loop = NULL;
1201 service_thread = g_thread_new ("nonce-tcp-service",
1202 nonce_tcp_service_thread_func,
1204 while (service_loop == NULL)
1206 g_assert (server != NULL);
1209 /* bring up a connection and accept it */
1210 data.accept_connection = TRUE;
1212 c = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
1213 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1214 NULL, /* GDBusAuthObserver */
1215 NULL, /* cancellable */
1217 g_assert_no_error (error);
1218 g_assert (c != NULL);
1219 while (data.current_connections->len < 1)
1221 g_assert_cmpint (data.current_connections->len, ==, 1);
1222 g_assert_cmpint (data.num_connection_attempts, ==, 1);
1223 g_assert (g_dbus_connection_get_unique_name (c) == NULL);
1224 g_assert_cmpstr (g_dbus_connection_get_guid (c), ==, test_guid);
1227 /* now, try to subvert the nonce file (this assumes noncefile is the last key/value pair)
1230 address = g_dbus_server_get_client_address (server);
1232 s = strstr (address, "noncefile=");
1233 g_assert (s != NULL);
1234 s += sizeof "noncefile=" - 1;
1235 nonce_file = g_strdup (s);
1237 /* First try invalid data in the nonce file - this will actually
1238 * make the client send this and the server will reject it. The way
1239 * it works is that if the nonce doesn't match, the server will
1240 * simply close the connection. So, from the client point of view,
1241 * we can see a variety of errors.
1244 res = g_file_set_contents (nonce_file,
1248 g_assert_no_error (error);
1250 c = g_dbus_connection_new_for_address_sync (address,
1251 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1252 NULL, /* GDBusAuthObserver */
1253 NULL, /* cancellable */
1255 _g_assert_error_domain (error, G_IO_ERROR);
1256 g_error_free (error);
1257 g_assert (c == NULL);
1259 /* Then try with a nonce-file of incorrect length - this will make
1260 * the client complain - we won't even try connecting to the server
1264 res = g_file_set_contents (nonce_file,
1265 "0123456789012345_",
1268 g_assert_no_error (error);
1270 c = g_dbus_connection_new_for_address_sync (address,
1271 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1272 NULL, /* GDBusAuthObserver */
1273 NULL, /* cancellable */
1275 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
1276 g_error_free (error);
1277 g_assert (c == NULL);
1279 /* Finally try with no nonce-file at all */
1280 g_assert_cmpint (g_unlink (nonce_file), ==, 0);
1282 c = g_dbus_connection_new_for_address_sync (address,
1283 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1284 NULL, /* GDBusAuthObserver */
1285 NULL, /* cancellable */
1287 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
1288 g_error_free (error);
1289 g_assert (c == NULL);
1291 g_free (nonce_file);
1293 g_dbus_server_stop (server);
1294 g_object_unref (server);
1297 g_main_loop_quit (service_loop);
1298 g_thread_join (service_thread);
1302 test_credentials (void)
1304 GCredentials *c1, *c2;
1308 c1 = g_credentials_new ();
1309 c2 = g_credentials_new ();
1312 if (g_credentials_set_unix_user (c2, getuid (), &error))
1313 g_assert_no_error (error);
1315 g_clear_error (&error);
1316 g_assert (g_credentials_is_same_user (c1, c2, &error));
1317 g_assert_no_error (error);
1319 desc = g_credentials_to_string (c1);
1320 g_assert (desc != NULL);
1323 g_object_unref (c1);
1324 g_object_unref (c2);
1327 /* ---------------------------------------------------------------------------------------------------- */
1331 /* Chosen to be big enough to overflow the socket buffer */
1332 #define OVERFLOW_NUM_SIGNALS 5000
1333 #define OVERFLOW_TIMEOUT_SEC 10
1335 static GDBusMessage *
1336 overflow_filter_func (GDBusConnection *connection,
1337 GDBusMessage *message,
1341 volatile gint *counter = user_data;
1347 overflow_on_500ms_later_func (gpointer user_data)
1349 g_main_loop_quit (loop);
1350 return FALSE; /* don't keep the idle */
1354 test_overflow (void)
1359 GSocketConnection *socket_connection;
1360 GDBusConnection *producer, *consumer;
1363 volatile gint n_messages_received;
1364 volatile gint n_messages_sent;
1366 g_assert_cmpint (socketpair (AF_UNIX, SOCK_STREAM, 0, sv), ==, 0);
1369 socket = g_socket_new_from_fd (sv[0], &error);
1370 g_assert_no_error (error);
1371 socket_connection = g_socket_connection_factory_create_connection (socket);
1372 g_assert (socket_connection != NULL);
1373 g_object_unref (socket);
1374 producer = g_dbus_connection_new_sync (G_IO_STREAM (socket_connection),
1376 G_DBUS_CONNECTION_FLAGS_NONE,
1377 NULL, /* GDBusAuthObserver */
1378 NULL, /* GCancellable */
1380 g_dbus_connection_set_exit_on_close (producer, TRUE);
1381 g_assert_no_error (error);
1382 g_object_unref (socket_connection);
1383 n_messages_sent = 0;
1384 g_dbus_connection_add_filter (producer, overflow_filter_func, (gpointer) &n_messages_sent, NULL);
1386 /* send enough data that we get an EAGAIN */
1387 for (n = 0; n < OVERFLOW_NUM_SIGNALS; n++)
1390 g_dbus_connection_emit_signal (producer,
1391 NULL, /* destination */
1393 "org.foo.Interface",
1395 g_variant_new ("(s)", "a string"),
1397 g_assert_no_error (error);
1400 /* sleep for 0.5 sec (to allow the GDBus IO thread to fill up the
1401 * kernel buffers) and verify that n_messages_sent <
1402 * OVERFLOW_NUM_SIGNALS
1404 * This is to verify that not all the submitted messages have been
1405 * sent to the underlying transport.
1407 g_timeout_add (500, overflow_on_500ms_later_func, NULL);
1408 g_main_loop_run (loop);
1409 g_assert_cmpint (n_messages_sent, <, OVERFLOW_NUM_SIGNALS);
1411 /* now suck it all out as a client, and add it up */
1412 socket = g_socket_new_from_fd (sv[1], &error);
1413 g_assert_no_error (error);
1414 socket_connection = g_socket_connection_factory_create_connection (socket);
1415 g_assert (socket_connection != NULL);
1416 g_object_unref (socket);
1417 consumer = g_dbus_connection_new_sync (G_IO_STREAM (socket_connection),
1419 G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING,
1420 NULL, /* GDBusAuthObserver */
1421 NULL, /* GCancellable */
1423 g_assert_no_error (error);
1424 g_object_unref (socket_connection);
1425 n_messages_received = 0;
1426 g_dbus_connection_add_filter (consumer, overflow_filter_func, (gpointer) &n_messages_received, NULL);
1427 g_dbus_connection_start_message_processing (consumer);
1429 timer = g_timer_new ();
1430 g_timer_start (timer);
1432 while (n_messages_received < OVERFLOW_NUM_SIGNALS && g_timer_elapsed (timer, NULL) < OVERFLOW_TIMEOUT_SEC)
1433 g_main_context_iteration (NULL, FALSE);
1435 g_assert_cmpint (n_messages_sent, ==, OVERFLOW_NUM_SIGNALS);
1436 g_assert_cmpint (n_messages_received, ==, OVERFLOW_NUM_SIGNALS);
1438 g_timer_destroy (timer);
1439 g_object_unref (consumer);
1440 g_object_unref (producer);
1444 test_overflow (void)
1446 /* TODO: test this with e.g. GWin32InputStream/GWin32OutputStream */
1450 /* ---------------------------------------------------------------------------------------------------- */
1453 tcp_anonymous_on_new_connection (GDBusServer *server,
1454 GDBusConnection *connection,
1457 gboolean *seen_connection = user_data;
1458 *seen_connection = TRUE;
1463 tcp_anonymous_service_thread_func (gpointer user_data)
1465 gboolean *seen_connection = user_data;
1466 GMainContext *service_context;
1469 service_context = g_main_context_new ();
1470 g_main_context_push_thread_default (service_context);
1473 server = g_dbus_server_new_sync ("tcp:",
1474 G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS,
1476 NULL, /* GDBusObserver* */
1477 NULL, /* GCancellable* */
1479 g_assert_no_error (error);
1481 g_signal_connect (server,
1483 G_CALLBACK (tcp_anonymous_on_new_connection),
1486 g_dbus_server_start (server);
1488 service_loop = g_main_loop_new (service_context, FALSE);
1489 g_main_loop_run (service_loop);
1491 g_main_context_pop_thread_default (service_context);
1493 g_main_loop_unref (service_loop);
1494 g_main_context_unref (service_context);
1500 test_tcp_anonymous (void)
1502 gboolean seen_connection;
1503 GThread *service_thread;
1504 GDBusConnection *connection;
1507 seen_connection = FALSE;
1508 service_loop = NULL;
1509 service_thread = g_thread_new ("tcp-anon-service",
1510 tcp_anonymous_service_thread_func,
1512 while (service_loop == NULL)
1514 g_assert (server != NULL);
1517 connection = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
1518 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1519 NULL, /* GDBusAuthObserver* */
1520 NULL, /* GCancellable */
1522 g_assert_no_error (error);
1523 g_assert (connection != NULL);
1525 while (!seen_connection)
1528 g_object_unref (connection);
1530 g_main_loop_quit (service_loop);
1531 g_dbus_server_stop (server);
1532 g_object_unref (server);
1535 g_thread_join (service_thread);
1538 /* ---------------------------------------------------------------------------------------------------- */
1540 static GDBusServer *codegen_server = NULL;
1543 codegen_on_animal_poke (ExampleAnimal *animal,
1544 GDBusMethodInvocation *invocation,
1546 gboolean make_happy,
1549 if ((make_sad && make_happy) || (!make_sad && !make_happy))
1551 g_main_loop_quit (service_loop);
1553 g_dbus_method_invocation_return_dbus_error (invocation,
1554 "org.gtk.GDBus.Examples.ObjectManager.Error.Failed",
1555 "Exactly one of make_sad or make_happy must be TRUE");
1561 if (g_strcmp0 (example_animal_get_mood (animal), "Sad") == 0)
1563 g_dbus_method_invocation_return_dbus_error (invocation,
1564 "org.gtk.GDBus.Examples.ObjectManager.Error.SadAnimalIsSad",
1565 "Sad animal is already sad");
1569 example_animal_set_mood (animal, "Sad");
1570 example_animal_complete_poke (animal, invocation);
1576 if (g_strcmp0 (example_animal_get_mood (animal), "Happy") == 0)
1578 g_dbus_method_invocation_return_dbus_error (invocation,
1579 "org.gtk.GDBus.Examples.ObjectManager.Error.HappyAnimalIsHappy",
1580 "Happy animal is already happy");
1584 example_animal_set_mood (animal, "Happy");
1585 example_animal_complete_poke (animal, invocation);
1589 g_assert_not_reached ();
1592 return TRUE; /* to indicate that the method was handled */
1595 /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
1597 codegen_on_new_connection (GDBusServer *server,
1598 GDBusConnection *connection,
1601 ExampleAnimal *animal = user_data;
1602 GError *error = NULL;
1604 /* g_print ("Client connected.\n" */
1605 /* "Negotiated capabilities: unix-fd-passing=%d\n", */
1606 /* g_dbus_connection_get_capabilities (connection) & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING); */
1608 g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (animal), connection,
1609 "/Example/Animals/000", &error);
1610 g_assert_no_error (error);
1616 codegen_service_thread_func (gpointer user_data)
1618 GMainContext *service_context;
1619 ExampleAnimal *animal;
1620 GError *error = NULL;
1622 service_context = g_main_context_new ();
1623 g_main_context_push_thread_default (service_context);
1625 /* Create the animal in the right thread context */
1626 animal = example_animal_skeleton_new ();
1628 /* Handle Poke() D-Bus method invocations on the .Animal interface */
1629 g_signal_connect (animal, "handle-poke",
1630 G_CALLBACK (codegen_on_animal_poke),
1631 NULL); /* user_data */
1633 codegen_server = g_dbus_server_new_sync (tmp_address,
1634 G_DBUS_SERVER_FLAGS_NONE,
1636 NULL, /* observer */
1637 NULL, /* cancellable */
1639 g_assert_no_error (error);
1640 g_dbus_server_start (codegen_server);
1642 g_signal_connect (codegen_server, "new-connection",
1643 G_CALLBACK (codegen_on_new_connection),
1646 service_loop = g_main_loop_new (service_context, FALSE);
1647 g_main_loop_run (service_loop);
1649 g_object_unref (animal);
1651 g_main_context_pop_thread_default (service_context);
1653 g_main_loop_unref (service_loop);
1654 g_main_context_unref (service_context);
1656 g_dbus_server_stop (codegen_server);
1657 g_object_unref (codegen_server);
1658 codegen_server = NULL;
1665 codegen_quit_mainloop_timeout (gpointer data)
1667 g_main_loop_quit (loop);
1672 codegen_test_peer (void)
1674 GDBusConnection *connection;
1675 ExampleAnimal *animal1, *animal2;
1676 GThread *service_thread;
1677 GError *error = NULL;
1680 /* bring up a server - we run the server in a different thread to avoid deadlocks */
1681 service_loop = NULL;
1682 service_thread = g_thread_new ("codegen_test_peer",
1683 codegen_service_thread_func,
1685 while (service_loop == NULL)
1687 g_assert (codegen_server != NULL);
1689 /* Get an animal 1 ... */
1690 connection = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (codegen_server),
1691 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1692 NULL, /* GDBusAuthObserver */
1693 NULL, /* cancellable */
1695 g_assert_no_error (error);
1696 g_assert (connection != NULL);
1698 animal1 = example_animal_proxy_new_sync (connection, 0, NULL,
1699 "/Example/Animals/000", NULL, &error);
1700 g_assert_no_error (error);
1701 g_assert (animal1 != NULL);
1702 g_object_unref (connection);
1704 /* Get animal 2 ... */
1705 connection = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (codegen_server),
1706 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1707 NULL, /* GDBusAuthObserver */
1708 NULL, /* cancellable */
1710 g_assert_no_error (error);
1711 g_assert (connection != NULL);
1713 animal2 = example_animal_proxy_new_sync (connection, 0, NULL,
1714 "/Example/Animals/000", NULL, &error);
1715 g_assert_no_error (error);
1716 g_assert (animal2 != NULL);
1717 g_object_unref (connection);
1719 /* Make animal sad via animal1 */
1720 example_animal_call_poke_sync (animal1, TRUE, FALSE, NULL, &error);
1721 g_assert_no_error (error);
1723 /* Poke server and make sure animal is updated */
1724 value = g_dbus_proxy_call_sync (G_DBUS_PROXY (animal1),
1725 "org.freedesktop.DBus.Peer.Ping",
1726 NULL, G_DBUS_CALL_FLAGS_NONE, -1,
1728 g_assert_no_error (error);
1729 g_assert (value != NULL);
1730 g_variant_unref (value);
1732 /* Give the proxies a chance to refresh in the defaul main loop */
1733 g_timeout_add (100, codegen_quit_mainloop_timeout, NULL);
1734 g_main_loop_run (loop);
1736 /* Assert animals are sad */
1737 g_assert_cmpstr (example_animal_get_mood (animal1), ==, "Sad");
1738 g_assert_cmpstr (example_animal_get_mood (animal2), ==, "Sad");
1740 /* Make animal happy via animal2 */
1741 example_animal_call_poke_sync (animal2, FALSE, TRUE, NULL, &error);
1742 g_assert_no_error (error);
1744 /* Poke server and make sure animal is updated */
1745 value = g_dbus_proxy_call_sync (G_DBUS_PROXY (animal2),
1746 "org.freedesktop.DBus.Peer.Ping",
1747 NULL, G_DBUS_CALL_FLAGS_NONE, -1,
1749 g_assert_no_error (error);
1750 g_assert (value != NULL);
1751 g_variant_unref (value);
1753 /* Give the proxies a chance to refresh in the defaul main loop */
1754 g_timeout_add (1000, codegen_quit_mainloop_timeout, NULL);
1755 g_main_loop_run (loop);
1757 /* Assert animals are happy */
1758 g_assert_cmpstr (example_animal_get_mood (animal1), ==, "Happy");
1759 g_assert_cmpstr (example_animal_get_mood (animal2), ==, "Happy");
1761 /* This final call making the animal happy and sad will cause
1762 * the server to quit, when the server quits we dont get property
1763 * change notifications anyway because those are done from an idle handler
1765 example_animal_call_poke_sync (animal2, TRUE, TRUE, NULL, &error);
1767 g_object_unref (animal1);
1768 g_object_unref (animal2);
1769 g_thread_join (service_thread);
1772 /* ---------------------------------------------------------------------------------------------------- */
1780 GDBusNodeInfo *introspection_data = NULL;
1781 gchar *tmpdir = NULL;
1784 g_test_init (&argc, &argv, NULL);
1786 g_unsetenv ("DBUS_SESSION_BUS_ADDRESS");
1788 introspection_data = g_dbus_node_info_new_for_xml (test_interface_introspection_xml, NULL);
1789 g_assert (introspection_data != NULL);
1790 test_interface_introspection_data = introspection_data->interfaces[0];
1792 test_guid = g_dbus_generate_guid ();
1796 if (g_unix_socket_address_abstract_names_supported ())
1797 tmp_address = g_strdup ("unix:tmpdir=/tmp/gdbus-test-");
1800 tmpdir = g_dir_make_tmp ("gdbus-test-XXXXXX", NULL);
1801 tmp_address = g_strdup_printf ("unix:tmpdir=%s", tmpdir);
1805 tmp_address = g_strdup ("nonce-tcp:");
1807 /* all the tests rely on a shared main loop */
1808 loop = g_main_loop_new (NULL, FALSE);
1810 g_test_add_func ("/gdbus/peer-to-peer", test_peer);
1811 g_test_add_func ("/gdbus/delayed-message-processing", delayed_message_processing);
1812 g_test_add_func ("/gdbus/nonce-tcp", test_nonce_tcp);
1813 g_test_add_func ("/gdbus/tcp-anonymous", test_tcp_anonymous);
1814 g_test_add_func ("/gdbus/credentials", test_credentials);
1815 g_test_add_func ("/gdbus/overflow", test_overflow);
1816 g_test_add_func ("/gdbus/codegen-peer-to-peer", codegen_test_peer);
1820 g_main_loop_unref (loop);
1822 g_dbus_node_info_unref (introspection_data);
1824 g_free (tmp_address);