Make gdbus-peer build on !linux
[platform/upstream/glib.git] / gio / tests / gdbus-peer.c
1 /* GLib testing framework examples and tests
2  *
3  * Copyright (C) 2008-2010 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: David Zeuthen <davidz@redhat.com>
21  */
22
23 #include <gio/gio.h>
24 #include <unistd.h>
25 #include <string.h>
26
27 /* for open(2) */
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31
32 /* for g_unlink() */
33 #include <glib/gstdio.h>
34
35 #include <gio/gunixsocketaddress.h>
36 #include <gio/gunixfdlist.h>
37
38 /* for struct ucred */
39 #ifdef __linux__
40 #define __USE_GNU
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #endif
44
45 /* for SOCK_STREAM and AF_UNIX */
46 #include <sys/socket.h>
47
48 /* used in test_overflow */
49 #ifdef G_OS_UNIX
50 #include <gio/gunixconnection.h>
51 #endif
52
53 #include "gdbus-tests.h"
54
55 #ifdef G_OS_UNIX
56 static gboolean is_unix = TRUE;
57 #else
58 static gboolean is_unix = FALSE;
59 #endif
60
61 static gchar *test_guid = NULL;
62 static GMainLoop *service_loop = NULL;
63 static GDBusServer *server = NULL;
64 static GMainLoop *loop = NULL;
65
66 /* ---------------------------------------------------------------------------------------------------- */
67 /* Test that peer-to-peer connections work */
68 /* ---------------------------------------------------------------------------------------------------- */
69
70
71 typedef struct
72 {
73   gboolean accept_connection;
74   gint num_connection_attempts;
75   GPtrArray *current_connections;
76   guint num_method_calls;
77   gboolean signal_received;
78 } PeerData;
79
80 static const gchar *test_interface_introspection_xml =
81   "<node>"
82   "  <interface name='org.gtk.GDBus.PeerTestInterface'>"
83   "    <method name='HelloPeer'>"
84   "      <arg type='s' name='greeting' direction='in'/>"
85   "      <arg type='s' name='response' direction='out'/>"
86   "    </method>"
87   "    <method name='EmitSignal'/>"
88   "    <method name='EmitSignalWithNameSet'/>"
89   "    <method name='OpenFile'>"
90   "      <arg type='s' name='path' direction='in'/>"
91   "    </method>"
92   "    <signal name='PeerSignal'>"
93   "      <arg type='s' name='a_string'/>"
94   "    </signal>"
95   "    <property type='s' name='PeerProperty' access='read'/>"
96   "  </interface>"
97   "</node>";
98 static GDBusInterfaceInfo *test_interface_introspection_data = NULL;
99
100 static void
101 test_interface_method_call (GDBusConnection       *connection,
102                             const gchar           *sender,
103                             const gchar           *object_path,
104                             const gchar           *interface_name,
105                             const gchar           *method_name,
106                             GVariant              *parameters,
107                             GDBusMethodInvocation *invocation,
108                             gpointer               user_data)
109 {
110   PeerData *data = user_data;
111
112   data->num_method_calls++;
113
114   g_assert_cmpstr (object_path, ==, "/org/gtk/GDBus/PeerTestObject");
115   g_assert_cmpstr (interface_name, ==, "org.gtk.GDBus.PeerTestInterface");
116
117   if (g_strcmp0 (method_name, "HelloPeer") == 0)
118     {
119       const gchar *greeting;
120       gchar *response;
121
122       g_variant_get (parameters, "(&s)", &greeting);
123
124       response = g_strdup_printf ("You greeted me with '%s'.",
125                                   greeting);
126       g_dbus_method_invocation_return_value (invocation,
127                                              g_variant_new ("(s)", response));
128       g_free (response);
129     }
130   else if (g_strcmp0 (method_name, "EmitSignal") == 0)
131     {
132       GError *error;
133
134       error = NULL;
135       g_dbus_connection_emit_signal (connection,
136                                      NULL,
137                                      "/org/gtk/GDBus/PeerTestObject",
138                                      "org.gtk.GDBus.PeerTestInterface",
139                                      "PeerSignal",
140                                      NULL,
141                                      &error);
142       g_assert_no_error (error);
143       g_dbus_method_invocation_return_value (invocation, NULL);
144     }
145   else if (g_strcmp0 (method_name, "EmitSignalWithNameSet") == 0)
146     {
147       GError *error;
148       gboolean ret;
149       GDBusMessage *message;
150
151       message = g_dbus_message_new_signal ("/org/gtk/GDBus/PeerTestObject",
152                                            "org.gtk.GDBus.PeerTestInterface",
153                                            "PeerSignalWithNameSet");
154       g_dbus_message_set_sender (message, ":1.42");
155
156       error = NULL;
157       ret = g_dbus_connection_send_message (connection, message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error);
158       g_assert_no_error (error);
159       g_assert (ret);
160       g_object_unref (message);
161
162       g_dbus_method_invocation_return_value (invocation, NULL);
163     }
164   else if (g_strcmp0 (method_name, "OpenFile") == 0)
165     {
166 #ifdef G_OS_UNIX
167       const gchar *path;
168       GDBusMessage *reply;
169       GError *error;
170       gint fd;
171       GUnixFDList *fd_list;
172
173       g_variant_get (parameters, "(&s)", &path);
174
175       fd_list = g_unix_fd_list_new ();
176
177       error = NULL;
178
179       fd = open (path, O_RDONLY);
180       g_unix_fd_list_append (fd_list, fd, &error);
181       g_assert_no_error (error);
182       close (fd);
183
184       reply = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
185       g_dbus_message_set_unix_fd_list (reply, fd_list);
186       g_object_unref (invocation);
187
188       error = NULL;
189       g_dbus_connection_send_message (connection,
190                                       reply,
191                                       G_DBUS_SEND_MESSAGE_FLAGS_NONE,
192                                       NULL, /* out_serial */
193                                       &error);
194       g_assert_no_error (error);
195       g_object_unref (reply);
196 #else
197       g_dbus_method_invocation_return_dbus_error (invocation,
198                                                   "org.gtk.GDBus.NotOnUnix",
199                                                   "Your OS does not support file descriptor passing");
200 #endif
201     }
202   else
203     {
204       g_assert_not_reached ();
205     }
206 }
207
208 static GVariant *
209 test_interface_get_property (GDBusConnection  *connection,
210                              const gchar      *sender,
211                              const gchar      *object_path,
212                              const gchar      *interface_name,
213                              const gchar      *property_name,
214                              GError          **error,
215                              gpointer          user_data)
216 {
217   g_assert_cmpstr (object_path, ==, "/org/gtk/GDBus/PeerTestObject");
218   g_assert_cmpstr (interface_name, ==, "org.gtk.GDBus.PeerTestInterface");
219   g_assert_cmpstr (property_name, ==, "PeerProperty");
220
221   return g_variant_new_string ("ThePropertyValue");
222 }
223
224
225 static const GDBusInterfaceVTable test_interface_vtable =
226 {
227   test_interface_method_call,
228   test_interface_get_property,
229   NULL  /* set_property */
230 };
231
232 static void
233 on_proxy_signal_received (GDBusProxy *proxy,
234                           gchar      *sender_name,
235                           gchar      *signal_name,
236                           GVariant   *parameters,
237                           gpointer    user_data)
238 {
239   PeerData *data = user_data;
240
241   data->signal_received = TRUE;
242
243   g_assert (sender_name == NULL);
244   g_assert_cmpstr (signal_name, ==, "PeerSignal");
245   g_main_loop_quit (loop);
246 }
247
248 static void
249 on_proxy_signal_received_with_name_set (GDBusProxy *proxy,
250                                         gchar      *sender_name,
251                                         gchar      *signal_name,
252                                         GVariant   *parameters,
253                                         gpointer    user_data)
254 {
255   PeerData *data = user_data;
256
257   data->signal_received = TRUE;
258
259   g_assert_cmpstr (sender_name, ==, ":1.42");
260   g_assert_cmpstr (signal_name, ==, "PeerSignalWithNameSet");
261   g_main_loop_quit (loop);
262 }
263
264 /* ---------------------------------------------------------------------------------------------------- */
265
266 static gboolean
267 on_authorize_authenticated_peer (GDBusAuthObserver *observer,
268                                  GIOStream         *stream,
269                                  GCredentials      *credentials,
270                                  gpointer           user_data)
271 {
272   PeerData *data = user_data;
273   gboolean authorized;
274
275   data->num_connection_attempts++;
276
277   authorized = TRUE;
278   if (!data->accept_connection)
279     {
280       authorized = FALSE;
281       g_main_loop_quit (loop);
282     }
283
284   return authorized;
285 }
286
287 /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
288 static void
289 on_new_connection (GDBusServer *server,
290                    GDBusConnection *connection,
291                    gpointer user_data)
292 {
293   PeerData *data = user_data;
294   GError *error;
295   guint reg_id;
296
297   //g_print ("Client connected.\n"
298   //         "Negotiated capabilities: unix-fd-passing=%d\n",
299   //         g_dbus_connection_get_capabilities (connection) & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
300
301   g_ptr_array_add (data->current_connections, g_object_ref (connection));
302
303   /* export object on the newly established connection */
304   error = NULL;
305   reg_id = g_dbus_connection_register_object (connection,
306                                               "/org/gtk/GDBus/PeerTestObject",
307                                               test_interface_introspection_data,
308                                               &test_interface_vtable,
309                                               data,
310                                               NULL, /* GDestroyNotify for data */
311                                               &error);
312   g_assert_no_error (error);
313   g_assert (reg_id > 0);
314
315   g_main_loop_quit (loop);
316 }
317
318 static gpointer
319 service_thread_func (gpointer user_data)
320 {
321   PeerData *data = user_data;
322   GMainContext *service_context;
323   GDBusAuthObserver *observer;
324   GError *error;
325
326   service_context = g_main_context_new ();
327   g_main_context_push_thread_default (service_context);
328
329   error = NULL;
330   observer = g_dbus_auth_observer_new ();
331   server = g_dbus_server_new_sync (is_unix ? "unix:tmpdir=/tmp/gdbus-test-" : "nonce-tcp:",
332                                    G_DBUS_SERVER_FLAGS_NONE,
333                                    test_guid,
334                                    observer,
335                                    NULL, /* cancellable */
336                                    &error);
337   g_assert_no_error (error);
338
339   g_signal_connect (server,
340                     "new-connection",
341                     G_CALLBACK (on_new_connection),
342                     data);
343   g_signal_connect (observer,
344                     "authorize-authenticated-peer",
345                     G_CALLBACK (on_authorize_authenticated_peer),
346                     data);
347   g_object_unref (observer);
348
349   g_dbus_server_start (server);
350
351   service_loop = g_main_loop_new (service_context, FALSE);
352   g_main_loop_run (service_loop);
353
354   g_main_context_pop_thread_default (service_context);
355
356   g_main_loop_unref (service_loop);
357   g_main_context_unref (service_context);
358
359   /* test code specifically unrefs the server - see below */
360   g_assert (server == NULL);
361
362   return NULL;
363 }
364
365 #if 0
366 static gboolean
367 on_incoming_connection (GSocketService     *service,
368                         GSocketConnection  *socket_connection,
369                         GObject            *source_object,
370                         gpointer           user_data)
371 {
372   PeerData *data = user_data;
373
374   if (data->accept_connection)
375     {
376       GError *error;
377       guint reg_id;
378       GDBusConnection *connection;
379
380       error = NULL;
381       connection = g_dbus_connection_new_sync (G_IO_STREAM (socket_connection),
382                                                test_guid,
383                                                G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER,
384                                                NULL, /* cancellable */
385                                                &error);
386       g_assert_no_error (error);
387
388       g_ptr_array_add (data->current_connections, connection);
389
390       /* export object on the newly established connection */
391       error = NULL;
392       reg_id = g_dbus_connection_register_object (connection,
393                                                   "/org/gtk/GDBus/PeerTestObject",
394                                                   &test_interface_introspection_data,
395                                                   &test_interface_vtable,
396                                                   data,
397                                                   NULL, /* GDestroyNotify for data */
398                                                   &error);
399       g_assert_no_error (error);
400       g_assert (reg_id > 0);
401
402     }
403   else
404     {
405       /* don't do anything */
406     }
407
408   data->num_connection_attempts++;
409
410   g_main_loop_quit (loop);
411
412   /* stops other signal handlers from being invoked */
413   return TRUE;
414 }
415
416 static gpointer
417 service_thread_func (gpointer data)
418 {
419   GMainContext *service_context;
420   gchar *socket_path;
421   GSocketAddress *address;
422   GError *error;
423
424   service_context = g_main_context_new ();
425   g_main_context_push_thread_default (service_context);
426
427   socket_path = g_strdup_printf ("/tmp/gdbus-test-pid-%d", getpid ());
428   address = g_unix_socket_address_new (socket_path);
429
430   service = g_socket_service_new ();
431   error = NULL;
432   g_socket_listener_add_address (G_SOCKET_LISTENER (service),
433                                  address,
434                                  G_SOCKET_TYPE_STREAM,
435                                  G_SOCKET_PROTOCOL_DEFAULT,
436                                  NULL, /* source_object */
437                                  NULL, /* effective_address */
438                                  &error);
439   g_assert_no_error (error);
440   g_signal_connect (service,
441                     "incoming",
442                     G_CALLBACK (on_incoming_connection),
443                     data);
444   g_socket_service_start (service);
445
446   service_loop = g_main_loop_new (service_context, FALSE);
447   g_main_loop_run (service_loop);
448
449   g_main_context_pop_thread_default (service_context);
450
451   g_main_loop_unref (service_loop);
452   g_main_context_unref (service_context);
453
454   g_object_unref (address);
455   g_free (socket_path);
456   return NULL;
457 }
458 #endif
459
460 /* ---------------------------------------------------------------------------------------------------- */
461
462 #if 0
463 static gboolean
464 check_connection (gpointer user_data)
465 {
466   PeerData *data = user_data;
467   guint n;
468
469   for (n = 0; n < data->current_connections->len; n++)
470     {
471       GDBusConnection *c;
472       GIOStream *stream;
473
474       c = G_DBUS_CONNECTION (data->current_connections->pdata[n]);
475       stream = g_dbus_connection_get_stream (c);
476
477       g_debug ("In check_connection for %d: connection %p, stream %p", n, c, stream);
478       g_debug ("closed = %d", g_io_stream_is_closed (stream));
479
480       GSocket *socket;
481       socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (stream));
482       g_debug ("socket_closed = %d", g_socket_is_closed (socket));
483       g_debug ("socket_condition_check = %d", g_socket_condition_check (socket, G_IO_IN|G_IO_OUT|G_IO_ERR|G_IO_HUP));
484
485       gchar buf[128];
486       GError *error;
487       gssize num_read;
488       error = NULL;
489       num_read = g_input_stream_read (g_io_stream_get_input_stream (stream),
490                                       buf,
491                                       128,
492                                       NULL,
493                                       &error);
494       if (num_read < 0)
495         {
496           g_debug ("error: %s", error->message);
497           g_error_free (error);
498         }
499       else
500         {
501           g_debug ("no error, read %d bytes", (gint) num_read);
502         }
503     }
504
505   return FALSE;
506 }
507
508 static gboolean
509 on_do_disconnect_in_idle (gpointer data)
510 {
511   GDBusConnection *c = G_DBUS_CONNECTION (data);
512   g_debug ("GDC %p has ref_count %d", c, G_OBJECT (c)->ref_count);
513   g_dbus_connection_disconnect (c);
514   g_object_unref (c);
515   return FALSE;
516 }
517 #endif
518
519 static void
520 test_peer (void)
521 {
522   GDBusConnection *c;
523   GDBusConnection *c2;
524   GDBusProxy *proxy;
525   GError *error;
526   PeerData data;
527   GVariant *value;
528   GVariant *result;
529   const gchar *s;
530   GThread *service_thread;
531   gulong signal_handler_id;
532
533   memset (&data, '\0', sizeof (PeerData));
534   data.current_connections = g_ptr_array_new_with_free_func (g_object_unref);
535
536   /* first try to connect when there is no server */
537   error = NULL;
538   c = g_dbus_connection_new_for_address_sync (is_unix ? "unix:path=/tmp/gdbus-test-does-not-exist-pid" :
539                                               /* NOTE: Even if something is listening on port 12345 the connection
540                                                * will fail because the nonce file doesn't exist */
541                                               "nonce-tcp:host=localhost,port=12345,noncefile=this-does-not-exist-gdbus",
542                                               G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
543                                               NULL, /* GDBusAuthObserver */
544                                               NULL, /* cancellable */
545                                               &error);
546   _g_assert_error_domain (error, G_IO_ERROR);
547   g_assert (!g_dbus_error_is_remote_error (error));
548   g_clear_error (&error);
549   g_assert (c == NULL);
550
551   /* bring up a server - we run the server in a different thread to avoid deadlocks */
552   error = NULL;
553   service_thread = g_thread_create (service_thread_func,
554                                     &data,
555                                     TRUE,
556                                     &error);
557   while (service_loop == NULL)
558     g_thread_yield ();
559   g_assert (server != NULL);
560
561   /* bring up a connection and accept it */
562   data.accept_connection = TRUE;
563   error = NULL;
564   c = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
565                                               G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
566                                               NULL, /* GDBusAuthObserver */
567                                               NULL, /* cancellable */
568                                               &error);
569   g_assert_no_error (error);
570   g_assert (c != NULL);
571   while (data.current_connections->len < 1)
572     g_main_loop_run (loop);
573   g_assert_cmpint (data.current_connections->len, ==, 1);
574   g_assert_cmpint (data.num_connection_attempts, ==, 1);
575   g_assert (g_dbus_connection_get_unique_name (c) == NULL);
576   g_assert_cmpstr (g_dbus_connection_get_guid (c), ==, test_guid);
577
578   /* check that we create a proxy, read properties, receive signals and invoke
579    * the HelloPeer() method. Since the server runs in another thread it's fine
580    * to use synchronous blocking API here.
581    */
582   error = NULL;
583   proxy = g_dbus_proxy_new_sync (c,
584                                  G_DBUS_PROXY_FLAGS_NONE,
585                                  NULL,
586                                  NULL, /* bus_name */
587                                  "/org/gtk/GDBus/PeerTestObject",
588                                  "org.gtk.GDBus.PeerTestInterface",
589                                  NULL, /* GCancellable */
590                                  &error);
591   g_assert_no_error (error);
592   g_assert (proxy != NULL);
593   error = NULL;
594   value = g_dbus_proxy_get_cached_property (proxy, "PeerProperty");
595   g_assert_cmpstr (g_variant_get_string (value, NULL), ==, "ThePropertyValue");
596
597   /* try invoking a method */
598   error = NULL;
599   result = g_dbus_proxy_call_sync (proxy,
600                                    "HelloPeer",
601                                    g_variant_new ("(s)", "Hey Peer!"),
602                                    G_DBUS_CALL_FLAGS_NONE,
603                                    -1,
604                                    NULL,  /* GCancellable */
605                                    &error);
606   g_assert_no_error (error);
607   g_variant_get (result, "(&s)", &s);
608   g_assert_cmpstr (s, ==, "You greeted me with 'Hey Peer!'.");
609   g_variant_unref (result);
610   g_assert_cmpint (data.num_method_calls, ==, 1);
611
612   /* make the other peer emit a signal - catch it */
613   signal_handler_id = g_signal_connect (proxy,
614                                         "g-signal",
615                                         G_CALLBACK (on_proxy_signal_received),
616                                         &data);
617   g_assert (!data.signal_received);
618   g_dbus_proxy_call (proxy,
619                      "EmitSignal",
620                      NULL,  /* no arguments */
621                      G_DBUS_CALL_FLAGS_NONE,
622                      -1,
623                      NULL,  /* GCancellable */
624                      NULL,  /* GAsyncReadyCallback - we don't care about the result */
625                      NULL); /* user_data */
626   g_main_loop_run (loop);
627   g_assert (data.signal_received);
628   g_assert_cmpint (data.num_method_calls, ==, 2);
629   g_signal_handler_disconnect (proxy, signal_handler_id);
630
631   /* Also ensure that messages with the sender header-field set gets
632    * delivered to the proxy - note that this doesn't really make sense
633    * e.g. names are meaning-less in a peer-to-peer case... but we
634    * support it because it makes sense in certain bridging
635    * applications - see e.g. #623815.
636    */
637   signal_handler_id = g_signal_connect (proxy,
638                                         "g-signal",
639                                         G_CALLBACK (on_proxy_signal_received_with_name_set),
640                                         &data);
641   data.signal_received = FALSE;
642   g_dbus_proxy_call (proxy,
643                      "EmitSignalWithNameSet",
644                      NULL,  /* no arguments */
645                      G_DBUS_CALL_FLAGS_NONE,
646                      -1,
647                      NULL,  /* GCancellable */
648                      NULL,  /* GAsyncReadyCallback - we don't care about the result */
649                      NULL); /* user_data */
650   g_main_loop_run (loop);
651   g_assert (data.signal_received);
652   g_assert_cmpint (data.num_method_calls, ==, 3);
653   g_signal_handler_disconnect (proxy, signal_handler_id);
654
655   /* check for UNIX fd passing */
656 #ifdef G_OS_UNIX
657   {
658     GDBusMessage *method_call_message;
659     GDBusMessage *method_reply_message;
660     GUnixFDList *fd_list;
661     gint fd;
662     gchar buf[1024];
663     gssize len;
664     gchar *buf2;
665     gsize len2;
666
667     method_call_message = g_dbus_message_new_method_call (NULL, /* name */
668                                                           "/org/gtk/GDBus/PeerTestObject",
669                                                           "org.gtk.GDBus.PeerTestInterface",
670                                                           "OpenFile");
671     g_dbus_message_set_body (method_call_message, g_variant_new ("(s)", "/etc/hosts"));
672     error = NULL;
673     method_reply_message = g_dbus_connection_send_message_with_reply_sync (c,
674                                                                            method_call_message,
675                                                                            G_DBUS_SEND_MESSAGE_FLAGS_NONE,
676                                                                            -1,
677                                                                            NULL, /* out_serial */
678                                                                            NULL, /* cancellable */
679                                                                            &error);
680     g_assert_no_error (error);
681     g_assert (g_dbus_message_get_message_type (method_reply_message) == G_DBUS_MESSAGE_TYPE_METHOD_RETURN);
682     fd_list = g_dbus_message_get_unix_fd_list (method_reply_message);
683     g_assert (fd_list != NULL);
684     g_assert_cmpint (g_unix_fd_list_get_length (fd_list), ==, 1);
685     error = NULL;
686     fd = g_unix_fd_list_get (fd_list, 0, &error);
687     g_assert_no_error (error);
688     g_object_unref (method_call_message);
689     g_object_unref (method_reply_message);
690
691     memset (buf, '\0', sizeof (buf));
692     len = read (fd, buf, sizeof (buf) - 1);
693     close (fd);
694
695     error = NULL;
696     g_file_get_contents ("/etc/hosts",
697                          &buf2,
698                          &len2,
699                          &error);
700     g_assert_no_error (error);
701     if (len2 > sizeof (buf))
702       buf2[sizeof (buf)] = '\0';
703     g_assert_cmpstr (buf, ==, buf2);
704     g_free (buf2);
705   }
706 #else
707   error = NULL;
708   result = g_dbus_proxy_call_sync (proxy,
709                                    "OpenFile",
710                                    g_variant_new ("(s)", "boo"),
711                                    G_DBUS_CALL_FLAGS_NONE,
712                                    -1,
713                                    NULL,  /* GCancellable */
714                                    &error);
715   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR);
716   g_assert (result == NULL);
717   g_error_free (error);
718 #endif /* G_OS_UNIX */
719
720   /* Check that g_socket_get_credentials() work - this really should
721    * be in a GSocket-specific test suite but no such test suite exists
722    * right now.
723    */
724   {
725     GSocket *socket;
726     GCredentials *credentials;
727     socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (g_dbus_connection_get_stream (c)));
728     g_assert (G_IS_SOCKET (socket));
729     error = NULL;
730     credentials = g_socket_get_credentials (socket, &error);
731 #ifdef __linux__
732     {
733       struct ucred *native_creds;
734       g_assert_no_error (error);
735       g_assert (G_IS_CREDENTIALS (credentials));
736       native_creds = g_credentials_get_native (credentials, G_CREDENTIALS_TYPE_LINUX_UCRED);
737       g_assert (native_creds != NULL);
738       g_assert (native_creds->uid == getuid ());
739       g_assert (native_creds->gid == getgid ());
740       g_assert (native_creds->pid == getpid ());
741     }
742     g_object_unref (credentials);
743 #else
744     g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
745     g_assert (credentials == NULL);
746 #endif
747   }
748
749
750   /* bring up a connection - don't accept it - this should fail
751    */
752   data.accept_connection = FALSE;
753   error = NULL;
754   c2 = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
755                                                G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
756                                                NULL, /* GDBusAuthObserver */
757                                                NULL, /* cancellable */
758                                                &error);
759   _g_assert_error_domain (error, G_IO_ERROR);
760   g_assert (c2 == NULL);
761
762 #if 0
763   /* TODO: THIS TEST DOESN'T WORK YET */
764
765   /* bring up a connection - accept it.. then disconnect from the client side - check
766    * that the server side gets the disconnect signal.
767    */
768   error = NULL;
769   data.accept_connection = TRUE;
770   c2 = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
771                                                G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
772                                                NULL, /* GDBusAuthObserver */
773                                                NULL, /* cancellable */
774                                                &error);
775   g_assert_no_error (error);
776   g_assert (c2 != NULL);
777   g_assert (!g_dbus_connection_get_is_disconnected (c2));
778   while (data.num_connection_attempts < 3)
779     g_main_loop_run (loop);
780   g_assert_cmpint (data.current_connections->len, ==, 2);
781   g_assert_cmpint (data.num_connection_attempts, ==, 3);
782   g_assert (!g_dbus_connection_get_is_disconnected (G_DBUS_CONNECTION (data.current_connections->pdata[1])));
783   g_idle_add (on_do_disconnect_in_idle, c2);
784   g_debug ("==================================================");
785   g_debug ("==================================================");
786   g_debug ("==================================================");
787   g_debug ("waiting for disconnect on connection %p, stream %p",
788            data.current_connections->pdata[1],
789            g_dbus_connection_get_stream (data.current_connections->pdata[1]));
790
791   g_timeout_add (2000, check_connection, &data);
792   //_g_assert_signal_received (G_DBUS_CONNECTION (data.current_connections->pdata[1]), "closed");
793   g_main_loop_run (loop);
794   g_assert (g_dbus_connection_get_is_disconnected (G_DBUS_CONNECTION (data.current_connections->pdata[1])));
795   g_ptr_array_set_size (data.current_connections, 1); /* remove disconnected connection object */
796 #endif
797
798   /* unref the server and stop listening for new connections
799    *
800    * This won't bring down the established connections - check that c is still connected
801    * by invoking a method
802    */
803   //g_socket_service_stop (service);
804   //g_object_unref (service);
805   g_dbus_server_stop (server);
806   g_object_unref (server);
807   server = NULL;
808
809   error = NULL;
810   result = g_dbus_proxy_call_sync (proxy,
811                                    "HelloPeer",
812                                    g_variant_new ("(s)", "Hey Again Peer!"),
813                                    G_DBUS_CALL_FLAGS_NONE,
814                                    -1,
815                                    NULL,  /* GCancellable */
816                                    &error);
817   g_assert_no_error (error);
818   g_variant_get (result, "(&s)", &s);
819   g_assert_cmpstr (s, ==, "You greeted me with 'Hey Again Peer!'.");
820   g_variant_unref (result);
821   g_assert_cmpint (data.num_method_calls, ==, 5);
822
823 #if 0
824   /* TODO: THIS TEST DOESN'T WORK YET */
825
826   /* now disconnect from the server side - check that the client side gets the signal */
827   g_assert_cmpint (data.current_connections->len, ==, 1);
828   g_assert (G_DBUS_CONNECTION (data.current_connections->pdata[0]) != c);
829   g_dbus_connection_disconnect (G_DBUS_CONNECTION (data.current_connections->pdata[0]));
830   if (!g_dbus_connection_get_is_disconnected (c))
831     _g_assert_signal_received (c, "closed");
832   g_assert (g_dbus_connection_get_is_disconnected (c));
833 #endif
834
835   g_object_unref (c);
836   g_ptr_array_unref (data.current_connections);
837   g_object_unref (proxy);
838
839   g_main_loop_quit (service_loop);
840   g_thread_join (service_thread);
841 }
842
843 /* ---------------------------------------------------------------------------------------------------- */
844
845 typedef struct
846 {
847   GDBusServer *server;
848   GMainContext *context;
849   GMainLoop *loop;
850
851   GList *connections;
852 } DmpData;
853
854 static void
855 dmp_data_free (DmpData *data)
856 {
857   g_main_loop_unref (data->loop);
858   g_main_context_unref (data->context);
859   g_object_unref (data->server);
860   g_list_foreach (data->connections, (GFunc) g_object_unref, NULL);
861   g_list_free (data->connections);
862   g_free (data);
863 }
864
865 static void
866 dmp_on_method_call (GDBusConnection       *connection,
867                     const gchar           *sender,
868                     const gchar           *object_path,
869                     const gchar           *interface_name,
870                     const gchar           *method_name,
871                     GVariant              *parameters,
872                     GDBusMethodInvocation *invocation,
873                     gpointer               user_data)
874 {
875   //DmpData *data = user_data;
876   gint32 first;
877   gint32 second;
878   g_variant_get (parameters,
879                  "(ii)",
880                  &first,
881                  &second);
882   g_dbus_method_invocation_return_value (invocation,
883                                          g_variant_new ("(i)", first + second));
884 }
885
886 static const GDBusInterfaceVTable dmp_interface_vtable =
887 {
888   dmp_on_method_call,
889   NULL,  /* get_property */
890   NULL   /* set_property */
891 };
892
893
894 /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
895 static void
896 dmp_on_new_connection (GDBusServer     *server,
897                        GDBusConnection *connection,
898                        gpointer         user_data)
899 {
900   DmpData *data = user_data;
901   GDBusNodeInfo *node;
902   GError *error;
903
904   /* accept the connection */
905   data->connections = g_list_prepend (data->connections, g_object_ref (connection));
906
907   error = NULL;
908   node = g_dbus_node_info_new_for_xml ("<node>"
909                                        "  <interface name='org.gtk.GDBus.DmpInterface'>"
910                                        "    <method name='AddPair'>"
911                                        "      <arg type='i' name='first' direction='in'/>"
912                                        "      <arg type='i' name='second' direction='in'/>"
913                                        "      <arg type='i' name='sum' direction='out'/>"
914                                        "    </method>"
915                                        "  </interface>"
916                                        "</node>",
917                                        &error);
918   g_assert_no_error (error);
919
920   /* sleep 100ms before exporting an object - this is to test that
921    * G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING really works
922    * (GDBusServer uses this feature).
923    */
924   usleep (100 * 1000);
925
926   /* export an object */
927   error = NULL;
928   g_dbus_connection_register_object (connection,
929                                      "/dmp/test",
930                                      node->interfaces[0],
931                                      &dmp_interface_vtable,
932                                      data,
933                                      NULL,
934                                      &error);
935   g_dbus_node_info_unref (node);
936 }
937
938 static gpointer
939 dmp_thread_func (gpointer user_data)
940 {
941   DmpData *data = user_data;
942   GError *error;
943   gchar *guid;
944
945   data->context = g_main_context_new ();
946   g_main_context_push_thread_default (data->context);
947
948   error = NULL;
949   guid = g_dbus_generate_guid ();
950   data->server = g_dbus_server_new_sync ("unix:tmpdir=/tmp/gdbus-test-",
951                                          G_DBUS_SERVER_FLAGS_NONE,
952                                          guid,
953                                          NULL, /* GDBusAuthObserver */
954                                          NULL, /* GCancellable */
955                                          &error);
956   g_assert_no_error (error);
957   g_signal_connect (data->server,
958                     "new-connection",
959                     G_CALLBACK (dmp_on_new_connection),
960                     data);
961
962   g_dbus_server_start (data->server);
963
964   data->loop = g_main_loop_new (data->context, FALSE);
965   g_main_loop_run (data->loop);
966
967   g_main_context_pop_thread_default (data->context);
968
969   g_free (guid);
970   return NULL;
971 }
972
973 static void
974 delayed_message_processing (void)
975 {
976   GError *error;
977   DmpData *data;
978   GThread *service_thread;
979   guint n;
980
981   data = g_new0 (DmpData, 1);
982
983   error = NULL;
984   service_thread = g_thread_create (dmp_thread_func,
985                                     data,
986                                     TRUE,
987                                     &error);
988   while (data->server == NULL || !g_dbus_server_is_active (data->server))
989     g_thread_yield ();
990
991   for (n = 0; n < 5; n++)
992     {
993       GDBusConnection *c;
994       GVariant *res;
995       gint32 val;
996
997       error = NULL;
998       c = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (data->server),
999                                                   G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1000                                                   NULL, /* GDBusAuthObserver */
1001                                                   NULL, /* GCancellable */
1002                                                   &error);
1003       g_assert_no_error (error);
1004
1005       error = NULL;
1006       res = g_dbus_connection_call_sync (c,
1007                                          NULL,    /* bus name */
1008                                          "/dmp/test",
1009                                          "org.gtk.GDBus.DmpInterface",
1010                                          "AddPair",
1011                                          g_variant_new ("(ii)", 2, n),
1012                                          G_VARIANT_TYPE ("(i)"),
1013                                          G_DBUS_CALL_FLAGS_NONE,
1014                                          -1, /* timeout_msec */
1015                                          NULL, /* GCancellable */
1016                                          &error);
1017       g_assert_no_error (error);
1018       g_variant_get (res, "(i)", &val);
1019       g_assert_cmpint (val, ==, 2 + n);
1020       g_variant_unref (res);
1021       g_object_unref (c);
1022   }
1023
1024   g_main_loop_quit (data->loop);
1025   g_thread_join (service_thread);
1026   dmp_data_free (data);
1027 }
1028
1029 /* ---------------------------------------------------------------------------------------------------- */
1030
1031 static gboolean
1032 nonce_tcp_on_authorize_authenticated_peer (GDBusAuthObserver *observer,
1033                                            GIOStream         *stream,
1034                                            GCredentials      *credentials,
1035                                            gpointer           user_data)
1036 {
1037   PeerData *data = user_data;
1038   gboolean authorized;
1039
1040   data->num_connection_attempts++;
1041
1042   authorized = TRUE;
1043   if (!data->accept_connection)
1044     {
1045       authorized = FALSE;
1046       g_main_loop_quit (loop);
1047     }
1048
1049   return authorized;
1050 }
1051
1052 /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
1053 static void
1054 nonce_tcp_on_new_connection (GDBusServer *server,
1055                              GDBusConnection *connection,
1056                              gpointer user_data)
1057 {
1058   PeerData *data = user_data;
1059
1060   g_ptr_array_add (data->current_connections, g_object_ref (connection));
1061
1062   g_main_loop_quit (loop);
1063 }
1064
1065 static gpointer
1066 nonce_tcp_service_thread_func (gpointer user_data)
1067 {
1068   PeerData *data = user_data;
1069   GMainContext *service_context;
1070   GDBusAuthObserver *observer;
1071   GError *error;
1072
1073   service_context = g_main_context_new ();
1074   g_main_context_push_thread_default (service_context);
1075
1076   error = NULL;
1077   observer = g_dbus_auth_observer_new ();
1078   server = g_dbus_server_new_sync ("nonce-tcp:",
1079                                    G_DBUS_SERVER_FLAGS_NONE,
1080                                    test_guid,
1081                                    observer,
1082                                    NULL, /* cancellable */
1083                                    &error);
1084   g_assert_no_error (error);
1085
1086   g_signal_connect (server,
1087                     "new-connection",
1088                     G_CALLBACK (nonce_tcp_on_new_connection),
1089                     data);
1090   g_signal_connect (observer,
1091                     "authorize-authenticated-peer",
1092                     G_CALLBACK (nonce_tcp_on_authorize_authenticated_peer),
1093                     data);
1094   g_object_unref (observer);
1095
1096   g_dbus_server_start (server);
1097
1098   service_loop = g_main_loop_new (service_context, FALSE);
1099   g_main_loop_run (service_loop);
1100
1101   g_main_context_pop_thread_default (service_context);
1102
1103   g_main_loop_unref (service_loop);
1104   g_main_context_unref (service_context);
1105
1106   /* test code specifically unrefs the server - see below */
1107   g_assert (server == NULL);
1108
1109   return NULL;
1110 }
1111
1112 static void
1113 test_nonce_tcp (void)
1114 {
1115   PeerData data;
1116   GError *error;
1117   GThread *service_thread;
1118   GDBusConnection *c;
1119   gchar *s;
1120   gchar *nonce_file;
1121   gboolean res;
1122   const gchar *address;
1123
1124   memset (&data, '\0', sizeof (PeerData));
1125   data.current_connections = g_ptr_array_new_with_free_func (g_object_unref);
1126
1127   error = NULL;
1128   server = NULL;
1129   service_loop = NULL;
1130   service_thread = g_thread_create (nonce_tcp_service_thread_func,
1131                                     &data,
1132                                     TRUE,
1133                                     &error);
1134   while (service_loop == NULL)
1135     g_thread_yield ();
1136   g_assert (server != NULL);
1137
1138
1139   /* bring up a connection and accept it */
1140   data.accept_connection = TRUE;
1141   error = NULL;
1142   c = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
1143                                               G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1144                                               NULL, /* GDBusAuthObserver */
1145                                               NULL, /* cancellable */
1146                                               &error);
1147   g_assert_no_error (error);
1148   g_assert (c != NULL);
1149   while (data.current_connections->len < 1)
1150     g_main_loop_run (loop);
1151   g_assert_cmpint (data.current_connections->len, ==, 1);
1152   g_assert_cmpint (data.num_connection_attempts, ==, 1);
1153   g_assert (g_dbus_connection_get_unique_name (c) == NULL);
1154   g_assert_cmpstr (g_dbus_connection_get_guid (c), ==, test_guid);
1155   g_object_unref (c);
1156
1157   /* now, try to subvert the nonce file (this assumes noncefile is the last key/value pair)
1158    */
1159
1160   address = g_dbus_server_get_client_address (server);
1161
1162   s = strstr (address, "noncefile=");
1163   g_assert (s != NULL);
1164   s += sizeof "noncefile=" - 1;
1165   nonce_file = g_strdup (s);
1166
1167   /* First try invalid data in the nonce file - this will actually
1168    * make the client send this and the server will reject it. The way
1169    * it works is that if the nonce doesn't match, the server will
1170    * simply close the connection. So, from the client point of view,
1171    * we can see a variety of errors.
1172    */
1173   error = NULL;
1174   res = g_file_set_contents (nonce_file,
1175                              "0123456789012345",
1176                              -1,
1177                              &error);
1178   g_assert_no_error (error);
1179   g_assert (res);
1180   c = g_dbus_connection_new_for_address_sync (address,
1181                                               G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1182                                               NULL, /* GDBusAuthObserver */
1183                                               NULL, /* cancellable */
1184                                               &error);
1185   _g_assert_error_domain (error, G_IO_ERROR);
1186   g_assert (c == NULL);
1187
1188   /* Then try with a nonce-file of incorrect length - this will make
1189    * the client complain - we won't even try connecting to the server
1190    * for this
1191    */
1192   error = NULL;
1193   res = g_file_set_contents (nonce_file,
1194                              "0123456789012345_",
1195                              -1,
1196                              &error);
1197   g_assert_no_error (error);
1198   g_assert (res);
1199   c = g_dbus_connection_new_for_address_sync (address,
1200                                               G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1201                                               NULL, /* GDBusAuthObserver */
1202                                               NULL, /* cancellable */
1203                                               &error);
1204   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
1205   g_assert (c == NULL);
1206
1207   /* Finally try with no nonce-file at all */
1208   g_assert_cmpint (g_unlink (nonce_file), ==, 0);
1209   error = NULL;
1210   c = g_dbus_connection_new_for_address_sync (address,
1211                                               G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1212                                               NULL, /* GDBusAuthObserver */
1213                                               NULL, /* cancellable */
1214                                               &error);
1215   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
1216   g_assert (c == NULL);
1217
1218   g_free (nonce_file);
1219
1220   g_dbus_server_stop (server);
1221   g_object_unref (server);
1222   server = NULL;
1223
1224   g_main_loop_quit (service_loop);
1225   g_thread_join (service_thread);
1226 }
1227
1228 static void
1229 test_credentials (void)
1230 {
1231   GCredentials *c1, *c2;
1232   GError *error;
1233   gchar *desc;
1234
1235   c1 = g_credentials_new ();
1236   c2 = g_credentials_new ();
1237
1238   error = NULL;
1239   if (g_credentials_set_unix_user (c2, getuid (), &error))
1240     g_assert_no_error (error);
1241
1242   g_clear_error (&error);
1243   g_assert (g_credentials_is_same_user (c1, c2, &error));
1244   g_assert_no_error (error);
1245
1246   desc = g_credentials_to_string (c1);
1247   g_assert (desc != NULL);
1248   g_free (desc);
1249
1250   g_object_unref (c1);
1251   g_object_unref (c2);
1252 }
1253
1254 /* ---------------------------------------------------------------------------------------------------- */
1255
1256 #ifdef G_OS_UNIX
1257
1258 /* Chosen to be big enough to overflow the socket buffer */
1259 #define OVERFLOW_NUM_SIGNALS 5000
1260 #define OVERFLOW_TIMEOUT_SEC 10
1261
1262 static gboolean
1263 overflow_filter_func (GDBusConnection *connection,
1264                       GDBusMessage    *message,
1265                       gboolean         incoming,
1266                       gpointer         user_data)
1267 {
1268   volatile gint *counter = user_data;
1269   *counter += 1;
1270   return FALSE; /* don't drop the message */
1271 }
1272
1273 static gboolean
1274 overflow_on_500ms_later_func (gpointer user_data)
1275 {
1276   g_main_loop_quit (loop);
1277   return FALSE; /* don't keep the idle */
1278 }
1279
1280 static void
1281 test_overflow (void)
1282 {
1283   gint sv[2];
1284   gint n;
1285   GSocket *socket;
1286   GSocketConnection *socket_connection;
1287   GDBusConnection *producer, *consumer;
1288   GError *error;
1289   GTimer *timer;
1290   volatile gint n_messages_received;
1291   volatile gint n_messages_sent;
1292
1293   g_assert_cmpint (socketpair (AF_UNIX, SOCK_STREAM, 0, sv), ==, 0);
1294
1295   error = NULL;
1296   socket = g_socket_new_from_fd (sv[0], &error);
1297   g_assert_no_error (error);
1298   socket_connection = g_socket_connection_factory_create_connection (socket);
1299   g_assert (socket_connection != NULL);
1300   g_object_unref (socket);
1301   producer = g_dbus_connection_new_sync (G_IO_STREAM (socket_connection),
1302                                          NULL, /* guid */
1303                                          G_DBUS_CONNECTION_FLAGS_NONE,
1304                                          NULL, /* GDBusAuthObserver */
1305                                          NULL, /* GCancellable */
1306                                          &error);
1307   g_dbus_connection_set_exit_on_close (producer, TRUE);
1308   g_assert_no_error (error);
1309   g_object_unref (socket_connection);
1310   n_messages_sent = 0;
1311   g_dbus_connection_add_filter (producer, overflow_filter_func, (gpointer) &n_messages_sent, NULL);
1312
1313   /* send enough data that we get an EAGAIN */
1314   for (n = 0; n < OVERFLOW_NUM_SIGNALS; n++)
1315     {
1316       error = NULL;
1317       g_dbus_connection_emit_signal (producer,
1318                                      NULL, /* destination */
1319                                      "/org/foo/Object",
1320                                      "org.foo.Interface",
1321                                      "Member",
1322                                      g_variant_new ("(s)", "a string"),
1323                                      &error);
1324       g_assert_no_error (error);
1325     }
1326
1327   /* sleep for 0.5 sec (to allow the GDBus IO thread to fill up the
1328    * kernel buffers) and verify that n_messages_sent <
1329    * OVERFLOW_NUM_SIGNALS
1330    *
1331    * This is to verify that not all the submitted messages have been
1332    * sent to the underlying transport.
1333    */
1334   g_timeout_add (500, overflow_on_500ms_later_func, NULL);
1335   g_main_loop_run (loop);
1336   g_assert_cmpint (n_messages_sent, <, OVERFLOW_NUM_SIGNALS);
1337
1338   /* now suck it all out as a client, and add it up */
1339   socket = g_socket_new_from_fd (sv[1], &error);
1340   g_assert_no_error (error);
1341   socket_connection = g_socket_connection_factory_create_connection (socket);
1342   g_assert (socket_connection != NULL);
1343   g_object_unref (socket);
1344   consumer = g_dbus_connection_new_sync (G_IO_STREAM (socket_connection),
1345                                          NULL, /* guid */
1346                                          G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING,
1347                                          NULL, /* GDBusAuthObserver */
1348                                          NULL, /* GCancellable */
1349                                          &error);
1350   g_assert_no_error (error);
1351   g_object_unref (socket_connection);
1352   n_messages_received = 0;
1353   g_dbus_connection_add_filter (consumer, overflow_filter_func, (gpointer) &n_messages_received, NULL);
1354   g_dbus_connection_start_message_processing (consumer);
1355
1356   timer = g_timer_new ();
1357   g_timer_start (timer);
1358
1359   while (n_messages_received < OVERFLOW_NUM_SIGNALS && g_timer_elapsed (timer, NULL) < OVERFLOW_TIMEOUT_SEC)
1360       g_main_context_iteration (NULL, FALSE);
1361
1362   g_assert_cmpint (n_messages_sent, ==, OVERFLOW_NUM_SIGNALS);
1363   g_assert_cmpint (n_messages_received, ==, OVERFLOW_NUM_SIGNALS);
1364
1365   g_timer_destroy (timer);
1366   g_object_unref (consumer);
1367   g_object_unref (producer);
1368 }
1369 #else
1370 static void
1371 test_overflow (void)
1372 {
1373   /* TODO: test this with e.g. GWin32InputStream/GWin32OutputStream */
1374 }
1375 #endif
1376
1377 /* ---------------------------------------------------------------------------------------------------- */
1378
1379 int
1380 main (int   argc,
1381       char *argv[])
1382 {
1383   gint ret;
1384   GDBusNodeInfo *introspection_data = NULL;
1385
1386   g_type_init ();
1387   g_thread_init (NULL);
1388   g_test_init (&argc, &argv, NULL);
1389
1390   introspection_data = g_dbus_node_info_new_for_xml (test_interface_introspection_xml, NULL);
1391   g_assert (introspection_data != NULL);
1392   test_interface_introspection_data = introspection_data->interfaces[0];
1393
1394   test_guid = g_dbus_generate_guid ();
1395
1396   /* all the tests rely on a shared main loop */
1397   loop = g_main_loop_new (NULL, FALSE);
1398
1399   g_test_add_func ("/gdbus/peer-to-peer", test_peer);
1400   g_test_add_func ("/gdbus/delayed-message-processing", delayed_message_processing);
1401   g_test_add_func ("/gdbus/nonce-tcp", test_nonce_tcp);
1402   g_test_add_func ("/gdbus/credentials", test_credentials);
1403   g_test_add_func ("/gdbus/overflow", test_overflow);
1404
1405   ret = g_test_run();
1406
1407   g_main_loop_unref (loop);
1408   g_free (test_guid);
1409   g_dbus_node_info_unref (introspection_data);
1410
1411   return ret;
1412 }