2005-07-08 Colin Walters <walters@verbum.org>
[platform/upstream/dbus.git] / test / glib / test-dbus-glib.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 #include <dbus/dbus-glib.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include "test-service-glib-bindings.h"
7 #include <glib/dbus-gidl.h>
8 #include <glib/dbus-gparser.h>
9 #include <glib.h>
10 #include <glib-object.h>
11 #include "my-object-marshal.h"
12
13 static GMainLoop *loop = NULL;
14 static const char *await_terminating_service = NULL;
15 static int n_times_foo_received = 0;
16 static int n_times_frobnicate_received = 0;
17 static int n_times_frobnicate_received_2 = 0;
18 static int n_times_sig0_received = 0;
19 static int n_times_sig1_received = 0;
20 static int n_times_sig2_received = 0;
21 static guint exit_timeout = 0;
22 static gboolean proxy_destroyed = FALSE;
23 static gboolean proxy_destroy_and_nameowner = FALSE;
24 static gboolean proxy_destroy_and_nameowner_complete = FALSE;
25
26 static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
27 static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
28
29 static gboolean
30 timed_exit (gpointer loop)
31 {
32   g_print ("timed exit!\n");
33   g_main_loop_quit (loop);
34   return TRUE;
35 }
36
37 static void
38 proxy_destroyed_cb (DBusGProxy *proxy, gpointer user_data)
39 {
40   proxy_destroyed = TRUE;
41   if (proxy_destroy_and_nameowner && !proxy_destroy_and_nameowner_complete && await_terminating_service == NULL)
42     {
43       g_main_loop_quit (loop);
44       proxy_destroy_and_nameowner_complete = TRUE;
45     } 
46 }
47
48 static void
49 name_owner_changed (DBusGProxy *proxy,
50                     const char *name,
51                     const char *prev_owner,
52                     const char *new_owner,
53                     gpointer   user_data)
54 {
55   g_print ("(signal NameOwnerChanged) name owner changed for %s from %s to %s\n",
56            name, prev_owner, new_owner);
57   if (await_terminating_service &&
58       !strcmp (name, await_terminating_service)
59       && !strcmp ("", new_owner))
60     {
61       g_print ("Caught expected ownership loss for %s\n", name); 
62       await_terminating_service = NULL;
63       if (proxy_destroy_and_nameowner && !proxy_destroy_and_nameowner_complete && proxy_destroyed)
64         {
65           g_main_loop_quit (loop);
66           proxy_destroy_and_nameowner_complete = TRUE;
67         } 
68       else if (!proxy_destroy_and_nameowner)
69         {
70           g_main_loop_quit (loop);
71         }
72     }
73 }
74
75 static void
76 foo_signal_handler (DBusGProxy  *proxy,
77                     double       d,
78                     void        *user_data)
79 {
80   n_times_foo_received += 1;
81
82   g_print ("Got Foo signal\n");
83
84   g_main_loop_quit (loop);
85   g_source_remove (exit_timeout);
86 }
87
88 static void
89 frobnicate_signal_handler (DBusGProxy  *proxy,
90                            int          val,
91                            void        *user_data)
92 {
93   n_times_frobnicate_received += 1;
94
95   g_assert (val == 42);
96   g_print ("Got Frobnicate signal\n");
97
98   g_main_loop_quit (loop);
99   g_source_remove (exit_timeout);
100 }
101
102 static void
103 frobnicate_signal_handler_2 (DBusGProxy  *proxy,
104                              int          val,
105                              void        *user_data)
106 {
107   n_times_frobnicate_received_2 += 1;
108
109   g_assert (val == 42);
110   g_print ("Got Frobnicate signal (again)\n");
111 }
112
113 static void
114 sig0_signal_handler (DBusGProxy  *proxy,
115                      const char  *str0,
116                      int          val,
117                      const char  *str1,
118                      void        *user_data)
119 {
120   n_times_sig0_received += 1;
121
122   g_assert (!strcmp (str0, "foo"));
123
124   g_assert (val == 22);
125
126   g_assert (!strcmp (str1, "moo"));
127
128   g_print ("Got Sig0 signal\n");
129
130   g_main_loop_quit (loop);
131   g_source_remove (exit_timeout);
132 }
133
134 static void
135 sig1_signal_handler (DBusGProxy  *proxy,
136                      const char  *str0,
137                      GValue      *value,
138                      void        *user_data)
139 {
140   n_times_sig1_received += 1;
141
142   g_assert (!strcmp (str0, "baz"));
143
144   g_assert (G_VALUE_HOLDS_STRING (value));
145
146   g_assert (!strcmp (g_value_get_string (value), "bar"));
147
148   g_print ("Got Sig1 signal\n");
149
150   g_main_loop_quit (loop);
151   g_source_remove (exit_timeout);
152 }
153
154 static void
155 sig2_signal_handler (DBusGProxy  *proxy,
156                      GHashTable  *table,
157                      void        *user_data)
158 {
159   n_times_sig2_received += 1;
160
161   g_assert (g_hash_table_size (table) == 2);
162
163   g_assert (g_hash_table_lookup (table, "baz") != NULL);
164   g_assert (!strcmp (g_hash_table_lookup (table, "baz"), "cow"));
165   g_assert (g_hash_table_lookup (table, "bar") != NULL);
166   g_assert (!strcmp (g_hash_table_lookup (table, "bar"), "foo"));
167
168   g_print ("Got Sig2 signal\n");
169
170   g_main_loop_quit (loop);
171   g_source_remove (exit_timeout);
172 }
173
174 static DBusGProxyCall *echo_call;
175 static guint n_times_echo_cb_entered;
176 static void
177 echo_received_cb (DBusGProxy *proxy,
178                   DBusGProxyCall *call,
179                   gpointer data)
180 {
181   GError *error;
182   char *echo_data;
183
184   g_assert (call == echo_call);
185   g_assert (data == NULL);
186
187   error = NULL;
188   echo_data = NULL;
189   n_times_echo_cb_entered++;
190
191   if (!dbus_g_proxy_end_call (proxy, call, &error,
192                               G_TYPE_STRING,
193                               &echo_data,
194                               G_TYPE_INVALID))
195     lose_gerror ("Failed to complete async Echo", error);
196   g_assert (echo_data != NULL);
197   g_print ("Async echo gave \"%s\"", echo_data); 
198   g_free (echo_data);
199   g_main_loop_quit (loop);
200   g_source_remove (exit_timeout);
201 }
202
203 static void
204 increment_received_cb (DBusGProxy *proxy,
205                        DBusGProxyCall *call,
206                        gpointer data)
207 {
208   GError *error;
209   char *echo_data;
210   guint val;
211
212   g_assert (!strcmp (data, "moo"));
213
214   error = NULL;
215   echo_data = NULL;
216   if (!dbus_g_proxy_end_call (proxy, call, &error,
217                               G_TYPE_UINT, &val,
218                               G_TYPE_INVALID))
219     lose_gerror ("Failed to complete (async) Increment call", error);
220
221   if (val != 43)
222     lose ("Increment call returned %d, should be 43", val);
223   
224   g_print ("Async increment gave \"%d\"", val); 
225   g_main_loop_quit (loop);
226   g_source_remove (exit_timeout);
227 }
228
229 static void
230 lose (const char *str, ...)
231 {
232   va_list args;
233
234   va_start (args, str);
235
236   vfprintf (stderr, str, args);
237   fputc ('\n', stderr);
238
239   va_end (args);
240
241   exit (1);
242 }
243
244 static void
245 lose_gerror (const char *prefix, GError *error) 
246 {
247   if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
248     lose ("%s (%s): %s", prefix, dbus_g_error_get_name (error),
249           error->message);
250   else
251     lose ("%s: %s", prefix, error->message);
252 }
253
254 static void
255 run_mainloop (void)
256 {
257   GMainContext *ctx;
258
259   ctx = g_main_loop_get_context (loop);
260
261   while (g_main_context_pending (ctx))
262     g_main_context_iteration (ctx, FALSE);
263 }
264
265 int
266 main (int argc, char **argv)
267 {
268   DBusGConnection *connection;
269   GError *error;
270   DBusGProxy *driver;
271   DBusGProxy *proxy;
272   DBusGProxy *proxy2;
273   char **name_list;
274   guint name_list_len;
275   guint i;
276   DBusGProxyCall *call;
277   guint32 result;
278   char *v_STRING_2;
279   guint32 v_UINT32_2;
280   double v_DOUBLE_2;
281     
282   g_type_init ();
283
284   g_log_set_always_fatal (G_LOG_LEVEL_WARNING);
285   
286   loop = g_main_loop_new (NULL, FALSE);
287
288   error = NULL;
289   connection = dbus_g_bus_get (DBUS_BUS_SESSION,
290                                &error);
291   if (connection == NULL)
292     lose_gerror ("Failed to open connection to bus", error);
293
294   /* should always get the same one */
295   g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
296   g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
297   g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
298   
299   /* Create a proxy object for the "bus driver" */
300   
301   driver = dbus_g_proxy_new_for_name (connection,
302                                       DBUS_SERVICE_DBUS,
303                                       DBUS_PATH_DBUS,
304                                       DBUS_INTERFACE_DBUS);
305
306   dbus_g_proxy_add_signal (driver,
307                            "NameOwnerChanged",
308                            G_TYPE_STRING,
309                            G_TYPE_STRING,
310                            G_TYPE_STRING,
311                            G_TYPE_INVALID);
312   
313   dbus_g_proxy_connect_signal (driver,
314                                "NameOwnerChanged", 
315                                G_CALLBACK (name_owner_changed),
316                                NULL,
317                                NULL);
318   /* Call ListNames method */
319   
320   error = NULL;
321   if (!dbus_g_proxy_call (driver, "ListNames", &error,
322                           G_TYPE_INVALID,
323                           G_TYPE_STRV, &name_list,
324                           G_TYPE_INVALID))
325     lose_gerror ("Failed to complete ListNames call", error);
326
327   g_print ("Names on the message bus:\n");
328   i = 0;
329   name_list_len = g_strv_length (name_list);
330   while (i < name_list_len)
331     {
332       g_assert (name_list[i] != NULL);
333       g_print ("  %s\n", name_list[i]);
334       ++i;
335     }
336   g_assert (name_list[i] == NULL);
337
338   g_strfreev (name_list);
339
340   g_print ("calling ThisMethodDoesNotExist\n");
341   /* Test handling of unknown method */
342   if (dbus_g_proxy_call (driver, "ThisMethodDoesNotExist", &error,
343                          G_TYPE_STRING,
344                          "blah blah blah blah blah",
345                          G_TYPE_INT,
346                          10,
347                          G_TYPE_INVALID, G_TYPE_INVALID) != FALSE)
348     lose ("Calling nonexistent method succeeded!");
349
350   g_print ("Got EXPECTED error from calling unknown method: %s\n", error->message);
351   g_clear_error (&error);
352
353   run_mainloop ();
354   
355   /* Activate a service */
356   g_print ("Activating echo service\n");
357   if (!dbus_g_proxy_call (driver, "StartServiceByName", &error,
358                           G_TYPE_STRING,
359                           "org.freedesktop.DBus.TestSuiteEchoService",
360                           G_TYPE_UINT, 0,
361                           G_TYPE_INVALID,
362                           G_TYPE_UINT, &result,
363                           G_TYPE_INVALID))
364     lose_gerror ("Failed to complete Activate call", error);
365
366   g_print ("Starting echo service result = 0x%x\n", result);
367
368   /* Activate a service again */
369   g_print ("Activating echo service again\n");
370   if (!dbus_g_proxy_call (driver, "StartServiceByName", &error,
371                           G_TYPE_STRING,
372                           "org.freedesktop.DBus.TestSuiteEchoService",
373                           G_TYPE_UINT,
374                           0,
375                           G_TYPE_INVALID,
376                           G_TYPE_UINT, &result,
377                           G_TYPE_INVALID))
378     lose_gerror ("Failed to complete Activate call", error);
379
380   g_print ("Duplicate start of echo service = 0x%x\n", result);
381
382   /* Talk to the new service */
383   
384   g_print ("Creating proxy for echo service\n");
385   proxy = dbus_g_proxy_new_for_name_owner (connection,
386                                            "org.freedesktop.DBus.TestSuiteEchoService",
387                                            "/org/freedesktop/TestSuite",
388                                            "org.freedesktop.TestSuite",
389                                            &error);
390   
391   if (proxy == NULL)
392     lose_gerror ("Failed to create proxy for name owner", error);
393
394   run_mainloop ();
395
396   g_print ("Calling Echo\n");
397   if (!dbus_g_proxy_call (proxy, "Echo", &error,
398                           G_TYPE_STRING, "my string hello",
399                           G_TYPE_INVALID,
400                           G_TYPE_STRING, &v_STRING_2,
401                           G_TYPE_INVALID))
402     lose_gerror ("Failed to complete Echo call", error);
403
404   g_print ("String echoed = \"%s\"\n", v_STRING_2);
405   g_free (v_STRING_2);
406
407   g_print ("Calling Echo (async)\n");
408   echo_call = dbus_g_proxy_begin_call (proxy, "Echo",
409                                        echo_received_cb, NULL, NULL,
410                                        G_TYPE_STRING, "my string hello",
411                                        G_TYPE_INVALID);
412   dbus_g_connection_flush (connection);
413   exit_timeout = g_timeout_add (5000, timed_exit, loop);
414   g_main_loop_run (loop);
415
416   /* Test oneway call and signal handling */
417
418   g_print ("Testing Foo emission\n");
419   dbus_g_proxy_add_signal (proxy, "Foo", G_TYPE_DOUBLE, G_TYPE_INVALID);
420   
421   dbus_g_proxy_connect_signal (proxy, "Foo",
422                                G_CALLBACK (foo_signal_handler),
423                                NULL, NULL);
424   
425   dbus_g_proxy_call_no_reply (proxy, "EmitFoo",
426                               G_TYPE_INVALID);
427   
428   dbus_g_connection_flush (connection);
429   exit_timeout = g_timeout_add (5000, timed_exit, loop);
430   g_main_loop_run (loop);
431
432   if (n_times_foo_received != 1)
433     lose ("Foo signal received %d times, should have been 1", n_times_foo_received);
434   
435   /* Activate test servie */ 
436   g_print ("Activating TestSuiteGLibService\n");
437   error = NULL;
438   if (!dbus_g_proxy_call (driver, "StartServiceByName", &error,
439                           G_TYPE_STRING,
440                           "org.freedesktop.DBus.TestSuiteGLibService",
441                           G_TYPE_UINT,
442                           0,
443                           G_TYPE_INVALID,
444                           G_TYPE_UINT, &result,
445                           G_TYPE_INVALID)) {
446     lose_gerror ("Failed to complete Activate call", error);
447   }
448
449   g_print ("TestSuiteGLibService activated\n");
450
451   if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION"))
452     g_usleep (8 * G_USEC_PER_SEC);
453
454   g_object_unref (G_OBJECT (proxy));
455
456   run_mainloop ();
457
458   proxy = dbus_g_proxy_new_for_name_owner (connection,
459                                            "org.freedesktop.DBus.TestSuiteGLibService",
460                                            "/org/freedesktop/DBus/Tests/MyTestObject",
461                                            "org.freedesktop.DBus.Tests.MyObject",
462                                            &error);
463   
464   if (proxy == NULL)
465     lose_gerror ("Failed to create proxy for name owner", error);
466
467   g_print ("Calling DoNothing\n");
468   if (!dbus_g_proxy_call (proxy, "DoNothing", &error,
469                           G_TYPE_INVALID, G_TYPE_INVALID))
470     lose_gerror ("Failed to complete DoNothing call", error);
471
472   g_print ("Calling Increment\n");
473   error = NULL;
474   if (!dbus_g_proxy_call (proxy, "Increment", &error,
475                           G_TYPE_UINT, 42,
476                           G_TYPE_INVALID,
477                           G_TYPE_UINT, &v_UINT32_2,
478                           G_TYPE_INVALID))
479     lose_gerror ("Failed to complete Increment call", error);
480   g_assert (n_times_echo_cb_entered == 1);
481
482   if (v_UINT32_2 != 43)
483     lose ("Increment call returned %d, should be 43", v_UINT32_2);
484
485   call = dbus_g_proxy_begin_call (proxy, "Increment",
486                                   increment_received_cb, g_strdup ("moo"), g_free,
487                                   G_TYPE_UINT, 42,
488                                   G_TYPE_INVALID);
489   dbus_g_connection_flush (connection);
490   exit_timeout = g_timeout_add (5000, timed_exit, loop);
491   g_main_loop_run (loop);
492
493   g_print ("Calling ThrowError\n");
494   if (dbus_g_proxy_call (proxy, "ThrowError", &error,
495                          G_TYPE_INVALID, G_TYPE_INVALID) != FALSE)
496     lose ("ThrowError call unexpectedly succeeded!");
497
498   if (!dbus_g_error_has_name (error, "org.freedesktop.DBus.Tests.MyObject.Foo"))
499     lose ("ThrowError call returned unexpected error \"%s\": %s", dbus_g_error_get_name (error),
500           error->message);
501
502   g_print ("ThrowError failed (as expected) returned error: %s\n", error->message);
503   g_clear_error (&error);
504
505   error = NULL;
506   g_print ("Calling Uppercase\n");
507   if (!dbus_g_proxy_call (proxy, "Uppercase", &error,
508                           G_TYPE_STRING, "foobar",
509                           G_TYPE_INVALID,
510                           G_TYPE_STRING, &v_STRING_2,
511                           G_TYPE_INVALID))
512     lose_gerror ("Failed to complete Uppercase call", error);
513   if (strcmp ("FOOBAR", v_STRING_2) != 0)
514     lose ("Uppercase call returned unexpected string %s", v_STRING_2);
515   g_free (v_STRING_2);
516
517   run_mainloop ();
518
519   g_print ("Calling ManyArgs\n");
520   if (!dbus_g_proxy_call (proxy, "ManyArgs", &error,
521                           G_TYPE_UINT, 26,
522                           G_TYPE_STRING, "bazwhee",
523                           G_TYPE_DOUBLE, G_PI,
524                           G_TYPE_INVALID,
525                           G_TYPE_DOUBLE, &v_DOUBLE_2,
526                           G_TYPE_STRING, &v_STRING_2,
527                           G_TYPE_INVALID))
528     lose_gerror ("Failed to complete ManyArgs call", error);
529   if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56)
530     lose ("ManyArgs call returned unexpected double value %f", v_DOUBLE_2);
531   if (strcmp ("BAZWHEE", v_STRING_2) != 0)
532     lose ("ManyArgs call returned unexpected string %s", v_STRING_2);
533   g_free (v_STRING_2);
534
535   g_print ("Calling (wrapped) do_nothing\n");
536   if (!org_freedesktop_DBus_Tests_MyObject_do_nothing (proxy, &error))
537     lose_gerror ("Failed to complete (wrapped) DoNothing call", error);
538
539   g_print ("Calling (wrapped) increment\n");
540   if (!org_freedesktop_DBus_Tests_MyObject_increment (proxy, 42, &v_UINT32_2, &error))
541     lose_gerror ("Failed to complete (wrapped) Increment call", error);
542
543   if (v_UINT32_2 != 43)
544     lose ("(wrapped) increment call returned %d, should be 43", v_UINT32_2);
545
546   v_UINT32_2 = 0;
547   if (!org_freedesktop_DBus_Tests_MyObject_async_increment (proxy, 42, &v_UINT32_2, &error))
548     lose_gerror ("Failed to complete (wrapped) AsyncIncrement call", error);
549
550   if (v_UINT32_2 != 43)
551     lose ("(wrapped) async increment call returned %d, should be 43", v_UINT32_2);
552
553   g_print ("Calling (wrapped) throw_error\n");
554   if (org_freedesktop_DBus_Tests_MyObject_throw_error (proxy, &error) != FALSE)
555     lose ("(wrapped) ThrowError call unexpectedly succeeded!");
556
557   g_print ("(wrapped) ThrowError failed (as expected) returned error: %s\n", error->message);
558   g_clear_error (&error);
559
560   if (org_freedesktop_DBus_Tests_MyObject_async_throw_error (proxy, &error) != FALSE)
561     lose ("(wrapped) AsyncThrowError call unexpectedly succeeded!");
562
563   g_print ("(wrapped) AsyncThrowError failed (as expected) returned error: %s\n", error->message);
564   g_clear_error (&error);
565
566   g_print ("Calling (wrapped) uppercase\n");
567   if (!org_freedesktop_DBus_Tests_MyObject_uppercase (proxy, "foobar", &v_STRING_2, &error)) 
568     lose_gerror ("Failed to complete (wrapped) Uppercase call", error);
569   if (strcmp ("FOOBAR", v_STRING_2) != 0)
570     lose ("(wrapped) Uppercase call returned unexpected string %s", v_STRING_2);
571   g_free (v_STRING_2);
572
573   g_print ("Calling (wrapped) many_args\n");
574   if (!org_freedesktop_DBus_Tests_MyObject_many_args (proxy, 26, "bazwhee", G_PI,
575                                                       &v_DOUBLE_2, &v_STRING_2, &error))
576     lose_gerror ("Failed to complete (wrapped) ManyArgs call", error);
577
578   if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56)
579     
580     lose ("(wrapped) ManyArgs call returned unexpected double value %f", v_DOUBLE_2);
581
582   if (strcmp ("BAZWHEE", v_STRING_2) != 0)
583     lose ("(wrapped) ManyArgs call returned unexpected string %s", v_STRING_2);
584   g_free (v_STRING_2);
585
586   {
587     guint32 arg0;
588     char *arg1;
589     gint32 arg2;
590     guint32 arg3;
591     guint32 arg4;
592     char *arg5;
593     
594     g_print ("Calling (wrapped) many_return\n");
595     if (!org_freedesktop_DBus_Tests_MyObject_many_return (proxy, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &error))
596       lose_gerror ("Failed to complete (wrapped) ManyReturn call", error);
597
598     if (arg0 != 42)
599       lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg0);
600
601     if (strcmp ("42", arg1) != 0)
602       lose ("(wrapped) ManyReturn call returned unexpected string %s", arg1);
603     g_free (arg1);
604
605     if (arg2 != -67)
606       lose ("(wrapped) ManyReturn call returned unexpected gint32 value %u", arg2);
607
608     if (arg3 != 2)
609       lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg3);
610
611     if (arg4 != 26)
612       lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg4);
613
614     if (strcmp ("hello world", arg5))
615       lose ("(wrapped) ManyReturn call returned unexpected string %s", arg5);
616     g_free (arg5);
617   }
618
619   run_mainloop ();
620
621   {
622     GValue value = {0, };
623
624     g_value_init (&value, G_TYPE_STRING);
625     g_value_set_string (&value, "foo");
626
627     g_print ("Calling (wrapped) stringify, with string\n");
628     if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
629                                                         &value,
630                                                         &v_STRING_2,
631                                                         &error))
632       lose_gerror ("Failed to complete (wrapped) stringify call", error);
633     if (strcmp ("foo", v_STRING_2) != 0)
634       lose ("(wrapped) stringify call returned unexpected string %s", v_STRING_2);
635     g_free (v_STRING_2);
636
637     g_value_unset (&value);
638     g_value_init (&value, G_TYPE_INT);
639     g_value_set_int (&value, 42);
640
641     g_print ("Calling (wrapped) stringify, with int\n");
642     if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
643                                                         &value,
644                                                         &v_STRING_2,
645                                                         &error))
646       lose_gerror ("Failed to complete (wrapped) stringify call 2", error);
647     if (strcmp ("42", v_STRING_2) != 0)
648       lose ("(wrapped) stringify call 2 returned unexpected string %s", v_STRING_2);
649     g_value_unset (&value);
650     g_free (v_STRING_2);
651
652     g_value_init (&value, G_TYPE_INT);
653     g_value_set_int (&value, 88);
654     g_print ("Calling (wrapped) stringify, with another int\n");
655     if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
656                                                         &value,
657                                                         NULL,
658                                                         &error))
659       lose_gerror ("Failed to complete (wrapped) stringify call 3", error);
660     g_value_unset (&value);
661
662     g_print ("Calling (wrapped) unstringify, for string\n");
663     if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy,
664                                                           "foo",
665                                                           &value,
666                                                           &error))
667       lose_gerror ("Failed to complete (wrapped) unstringify call", error);
668     if (!G_VALUE_HOLDS_STRING (&value))
669       lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value));
670     if (strcmp (g_value_get_string (&value), "foo"))
671       lose ("(wrapped) unstringify call returned unexpected string %s",
672             g_value_get_string (&value));
673         
674     g_value_unset (&value);
675
676     g_print ("Calling (wrapped) unstringify, for int\n");
677     if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy,
678                                                           "10",
679                                                           &value,
680                                                           &error))
681       lose_gerror ("Failed to complete (wrapped) unstringify call", error);
682     if (!G_VALUE_HOLDS_INT (&value))
683       lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value));
684     if (g_value_get_int (&value) != 10)
685       lose ("(wrapped) unstringify call returned unexpected integer %d",
686             g_value_get_int (&value));
687
688     g_value_unset (&value);
689   }
690
691   run_mainloop ();
692
693   {
694     GArray *array;
695     guint32 val;
696     guint32 arraylen;
697
698     array = g_array_new (FALSE, TRUE, sizeof (guint32));
699     val = 42;
700     g_array_append_val (array, val);
701     val = 69;
702     g_array_append_val (array, val);
703     val = 88;
704     g_array_append_val (array, val);
705     val = 26;
706     g_array_append_val (array, val);
707     val = 2;
708     g_array_append_val (array, val);
709
710     arraylen = 0;
711     g_print ("Calling (wrapped) recursive1\n");
712     if (!org_freedesktop_DBus_Tests_MyObject_recursive1 (proxy, array,
713                                                          &arraylen, &error))
714       lose_gerror ("Failed to complete (wrapped) recursive1 call", error);
715     if (arraylen != 5)
716       lose ("(wrapped) recursive1 call returned invalid length %u", arraylen);
717   }
718
719   {
720     GArray *array = NULL;
721     guint32 *arrayvals;
722     
723     g_print ("Calling (wrapped) recursive2\n");
724     if (!org_freedesktop_DBus_Tests_MyObject_recursive2 (proxy, 2, &array, &error))
725       lose_gerror ("Failed to complete (wrapped) Recursive2 call", error);
726
727     if (array == NULL)
728       lose ("(wrapped) Recursive2 call returned NULL");
729     if (array->len != 5)
730       lose ("(wrapped) Recursive2 call returned unexpected array length %u", array->len);
731
732     arrayvals = (guint32*) array->data;
733     if (arrayvals[0] != 42)
734       lose ("(wrapped) Recursive2 call returned unexpected value %d in position 0", arrayvals[0]);
735     if (arrayvals[1] != 26)
736       lose ("(wrapped) Recursive2 call returned unexpected value %d in position 1", arrayvals[1]);
737     if (arrayvals[4] != 2)
738       lose ("(wrapped) Recursive2 call returned unexpected value %d in position 4", arrayvals[4]);
739
740     g_array_free (array, TRUE);
741   }
742
743   run_mainloop ();
744
745   {
746     char **strs;
747     char **strs_ret;
748
749     strs = g_new0 (char *, 4);
750     strs[0] = "hello";
751     strs[1] = "HellO";
752     strs[2] = "HELLO";
753     strs[3] = NULL;
754
755     strs_ret = NULL;
756     g_print ("Calling (wrapped) many_uppercase\n");
757     if (!org_freedesktop_DBus_Tests_MyObject_many_uppercase (proxy, strs, &strs_ret, &error)) 
758       lose_gerror ("Failed to complete (wrapped) ManyUppercase call", error);
759     g_assert (strs_ret != NULL);
760     if (strcmp ("HELLO", strs_ret[0]) != 0)
761       lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[0]);
762     if (strcmp ("HELLO", strs_ret[1]) != 0)
763       lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[1]);
764     if (strcmp ("HELLO", strs_ret[2]) != 0)
765       lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[2]);
766
767     g_free (strs);
768     g_strfreev (strs_ret);
769   }
770
771   {
772     GHashTable *table;
773     guint len;
774
775     table = g_hash_table_new (g_str_hash, g_str_equal);
776     g_hash_table_insert (table, "moooo", "b");
777     g_hash_table_insert (table, "xxx", "cow!");
778
779     len = 0;
780     g_print ("Calling (wrapped) str_hash_len\n");
781     if (!org_freedesktop_DBus_Tests_MyObject_str_hash_len (proxy, table, &len, &error))
782       lose_gerror ("(wrapped) StrHashLen call failed", error);
783     if (len != 13) 
784       lose ("(wrapped) StrHashLen returned unexpected length %u", len);
785     g_hash_table_destroy (table);
786   }
787
788   {
789     GHashTable *table;
790     const char *val;
791
792     g_print ("Calling (wrapped) get_hash\n");
793     if (!org_freedesktop_DBus_Tests_MyObject_get_hash (proxy, &table, &error))
794       lose_gerror ("(wrapped) GetHash call failed", error);
795     val = g_hash_table_lookup (table, "foo");
796     if (val == NULL || strcmp ("bar", val))
797       lose ("(wrapped) StrHashLen returned invalid value %s for key \"foo\"",
798             val ? val : "(null)");
799     val = g_hash_table_lookup (table, "baz");
800     if (val == NULL || strcmp ("whee", val))
801       lose ("(wrapped) StrHashLen returned invalid value %s for key \"whee\"",
802             val ? val : "(null)");
803     val = g_hash_table_lookup (table, "cow");
804     if (val == NULL || strcmp ("crack", val))
805       lose ("(wrapped) StrHashLen returned invalid value %s for key \"cow\"",
806             val ? val : "(null)");
807     if (g_hash_table_size (table) != 3)
808       lose ("(wrapped) StrHashLen returned unexpected hash size %u",
809             g_hash_table_size (table));
810
811     g_hash_table_destroy (table);
812   }
813
814   run_mainloop ();
815
816   {
817     guint val;
818     char *ret_path;
819     DBusGProxy *ret_proxy;
820
821     g_print ("Calling (wrapped) objpath\n");
822     if (!dbus_g_proxy_call (proxy, "Objpath", &error,
823                             DBUS_TYPE_G_PROXY, proxy, G_TYPE_INVALID,
824                             DBUS_TYPE_G_PROXY, &ret_proxy, G_TYPE_INVALID))
825       lose_gerror ("Failed to complete Objpath call", error);
826     if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
827                 dbus_g_proxy_get_path (ret_proxy)) != 0)
828       lose ("(wrapped) objpath call returned unexpected proxy %s",
829             dbus_g_proxy_get_path (ret_proxy));
830
831     g_print ("Doing get/increment val tests\n");
832     val = 1;
833     if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
834       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
835     if (val != 0)
836       lose ("(wrapped) GetVal returned invalid value %d", val);
837
838     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
839       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
840
841     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
842       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
843
844     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
845       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
846
847     if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
848       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
849     if (val != 3)
850       lose ("(wrapped) GetVal returned invalid value %d", val);
851
852     if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error))
853       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
854     if (val != 0)
855       lose ("(wrapped) GetVal returned invalid value %d", val);
856
857     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (proxy, &error))
858       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
859
860     if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error))
861       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
862     if (val != 1)
863       lose ("(wrapped) GetVal returned invalid value %d", val);
864
865     if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
866       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
867     if (val != 3)
868       lose ("(wrapped) GetVal returned invalid value %d", val);
869
870     g_object_unref (G_OBJECT (ret_proxy));
871
872     g_print ("Calling objpath again\n");
873     ret_proxy = NULL;
874
875     if (!dbus_g_proxy_call (proxy, "Objpath", &error,
876                             DBUS_TYPE_G_OBJECT_PATH,
877                             dbus_g_proxy_get_path (proxy),
878                             G_TYPE_INVALID,
879                             DBUS_TYPE_G_OBJECT_PATH,
880                             &ret_path,
881                             G_TYPE_INVALID))
882       lose_gerror ("Failed to complete Objpath call 2", error);
883     if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2", ret_path) != 0)
884       lose ("Objpath call 2 returned unexpected path %s",
885             ret_path);
886
887     ret_proxy = dbus_g_proxy_new_for_name_owner (connection,
888                                                  "org.freedesktop.DBus.TestSuiteGLibService",
889                                                  ret_path,
890                                                  "org.freedesktop.DBus.Tests.FooObject",
891                                                  &error);
892     g_free (ret_path);
893     
894     val = 0;
895     if (!org_freedesktop_DBus_Tests_FooObject_get_value (ret_proxy, &val, &error))
896       lose_gerror ("Failed to complete (wrapped) GetValue call", error);
897     if (val != 3)
898       lose ("(wrapped) GetValue returned invalid value %d", val);
899   }
900
901   run_mainloop ();
902
903   {
904     GPtrArray *objs;
905     guint i;
906
907     g_print ("Calling GetObjs\n");
908
909     if (!dbus_g_proxy_call (proxy, "GetObjs", &error, G_TYPE_INVALID,
910                             dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH),
911                             &objs,
912                             G_TYPE_INVALID))
913       lose_gerror ("Failed to complete GetObjs call", error);
914     if (objs->len != 2)
915       lose ("GetObjs call returned unexpected number of objects %d, expected 2",
916             objs->len);
917
918     if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject",
919                 g_ptr_array_index (objs, 0)) != 0)
920       lose ("GetObjs call returned unexpected path \"%s\" in position 0; expected /org/freedesktop/DBus/Tests/MyTestObject", (char*) g_ptr_array_index (objs, 0));
921
922     if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
923                 g_ptr_array_index (objs, 1)) != 0)
924       lose ("GetObjs call returned unexpected path \"%s\" in position 1; expected /org/freedesktop/DBus/Tests/MyTestObject2", (char*) g_ptr_array_index (objs, 1));
925
926     for (i = 0; i < objs->len; i++)
927       g_free (g_ptr_array_index (objs, i));
928     g_ptr_array_free (objs, TRUE);
929   }
930
931   /* Signal handling tests */
932   
933   g_print ("Testing signal handling\n");
934   dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
935   
936   dbus_g_proxy_connect_signal (proxy, "Frobnicate",
937                                G_CALLBACK (frobnicate_signal_handler),
938                                NULL, NULL);
939   
940   g_print ("Calling EmitFrobnicate\n");
941   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
942                           G_TYPE_INVALID, G_TYPE_INVALID))
943     lose_gerror ("Failed to complete EmitFrobnicate call", error);
944
945   
946   dbus_g_connection_flush (connection);
947   exit_timeout = g_timeout_add (5000, timed_exit, loop);
948   g_main_loop_run (loop);
949
950   if (n_times_frobnicate_received != 1)
951     lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
952
953   g_print ("Calling EmitFrobnicate again\n");
954   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
955                           G_TYPE_INVALID, G_TYPE_INVALID))
956     lose_gerror ("Failed to complete EmitFrobnicate call", error);
957   
958   dbus_g_connection_flush (connection);
959   exit_timeout = g_timeout_add (5000, timed_exit, loop);
960   g_main_loop_run (loop);
961
962   if (n_times_frobnicate_received != 2)
963     lose ("Frobnicate signal received %d times, should have been 2", n_times_frobnicate_received);
964
965   g_object_unref (G_OBJECT (proxy));
966
967   run_mainloop ();
968
969   g_print ("Creating proxy for FooObject interface\n");
970   proxy = dbus_g_proxy_new_for_name_owner (connection,
971                                            "org.freedesktop.DBus.TestSuiteGLibService",
972                                            "/org/freedesktop/DBus/Tests/MyTestObject",
973                                            "org.freedesktop.DBus.Tests.FooObject",
974                                            &error);
975   
976   if (proxy == NULL)
977     lose_gerror ("Failed to create proxy for name owner", error);
978
979   dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_INT_STRING, 
980                                      G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
981
982   dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_BOXED, 
983                                      G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
984
985   dbus_g_proxy_add_signal (proxy, "Sig0", G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
986   dbus_g_proxy_add_signal (proxy, "Sig1", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
987   dbus_g_proxy_add_signal (proxy, "Sig2", DBUS_TYPE_G_STRING_STRING_HASHTABLE, G_TYPE_INVALID);
988   
989   dbus_g_proxy_connect_signal (proxy, "Sig0",
990                                G_CALLBACK (sig0_signal_handler),
991                                NULL, NULL);
992   dbus_g_proxy_connect_signal (proxy, "Sig1",
993                                G_CALLBACK (sig1_signal_handler),
994                                NULL, NULL);
995   dbus_g_proxy_connect_signal (proxy, "Sig2",
996                                G_CALLBACK (sig2_signal_handler),
997                                NULL, NULL);
998
999   g_print ("Calling FooObject EmitSignals\n");
1000   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1001
1002   dbus_g_connection_flush (connection);
1003   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1004   g_main_loop_run (loop);
1005   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1006   g_main_loop_run (loop);
1007
1008   if (n_times_sig0_received != 1)
1009     lose ("Sig0 signal received %d times, should have been 1", n_times_sig0_received);
1010   if (n_times_sig1_received != 1)
1011     lose ("Sig1 signal received %d times, should have been 1", n_times_sig1_received);
1012
1013   g_print ("Calling FooObject EmitSignals and EmitSignal2\n");
1014   dbus_g_proxy_call_no_reply (proxy, "EmitSignal2", G_TYPE_INVALID);
1015   dbus_g_connection_flush (connection);
1016
1017   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1018   g_main_loop_run (loop);
1019
1020   if (n_times_sig2_received != 1)
1021     lose ("Sig2 signal received %d times, should have been 1", n_times_sig2_received);
1022
1023   g_print ("Calling FooObject EmitSignals two more times\n");
1024   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1025   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1026
1027   dbus_g_connection_flush (connection);
1028   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1029   g_main_loop_run (loop);
1030   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1031   g_main_loop_run (loop);
1032   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1033   g_main_loop_run (loop);
1034   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1035   g_main_loop_run (loop);
1036
1037   if (n_times_sig0_received != 3)
1038     lose ("Sig0 signal received %d times, should have been 3", n_times_sig0_received);
1039   if (n_times_sig1_received != 3)
1040     lose ("Sig1 signal received %d times, should have been 3", n_times_sig1_received);
1041
1042   /* Terminate again */
1043   g_print ("Terminating service\n");
1044   await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService";
1045   dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID);
1046
1047   proxy_destroyed = FALSE;
1048   proxy_destroy_and_nameowner = TRUE;
1049   proxy_destroy_and_nameowner_complete = FALSE;
1050
1051   g_signal_connect (G_OBJECT (proxy),
1052                     "destroy",
1053                     G_CALLBACK (proxy_destroyed_cb),
1054                     NULL);
1055
1056   dbus_g_connection_flush (connection);
1057   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1058   g_main_loop_run (loop);
1059
1060   if (await_terminating_service != NULL)
1061     lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\"");
1062   if (!proxy_destroyed)
1063     lose ("Didn't get proxy_destroyed");
1064   g_print ("Proxy destroyed successfully\n");
1065
1066   /* Don't need to unref, proxy was destroyed */
1067
1068   run_mainloop ();
1069
1070   /* Create a new proxy for the name; should not be associated */
1071   proxy = dbus_g_proxy_new_for_name (connection,
1072                                      "org.freedesktop.DBus.TestSuiteGLibService",
1073                                      "/org/freedesktop/DBus/Tests/MyTestObject",
1074                                      "org.freedesktop.DBus.Tests.MyObject");
1075   g_assert (proxy != NULL);
1076
1077   proxy_destroyed = FALSE;
1078   proxy_destroy_and_nameowner = FALSE;
1079   proxy_destroy_and_nameowner_complete = FALSE;
1080
1081   g_signal_connect (G_OBJECT (proxy),
1082                     "destroy",
1083                     G_CALLBACK (proxy_destroyed_cb),
1084                     NULL);
1085   
1086   if (!dbus_g_proxy_call (driver, "GetNameOwner", &error,
1087                           G_TYPE_STRING,
1088                           "org.freedesktop.DBus.TestSuiteGLibService",
1089                           G_TYPE_INVALID,
1090                           G_TYPE_STRING,
1091                           &v_STRING_2,
1092                           G_TYPE_INVALID)) {
1093     if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NAME_HAS_NO_OWNER)
1094       g_print ("Got expected error \"org.freedesktop.DBus.Error.NameHasNoOwner\"\n");
1095     else
1096       lose_gerror ("Unexpected error from GetNameOwner", error);
1097   } else
1098     lose ("GetNameOwner unexpectedly succeeded!");
1099   g_clear_error (&error);
1100
1101   /* This will have the side-effect of activating the service, thus
1102    * causing a NameOwnerChanged, which should let our name proxy
1103    * get signals
1104    */
1105   g_print ("Calling Uppercase for name proxy\n");
1106   if (!dbus_g_proxy_call (proxy, "Uppercase", &error,
1107                           G_TYPE_STRING, "bazwhee",
1108                           G_TYPE_INVALID,
1109                           G_TYPE_STRING, &v_STRING_2,
1110                           G_TYPE_INVALID))
1111     lose_gerror ("Failed to complete Uppercase call", error);
1112   g_free (v_STRING_2);
1113
1114   dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1115   
1116   dbus_g_proxy_connect_signal (proxy, "Frobnicate",
1117                                G_CALLBACK (frobnicate_signal_handler),
1118                                NULL, NULL);
1119   
1120   g_print ("Calling EmitFrobnicate\n");
1121   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1122                           G_TYPE_INVALID, G_TYPE_INVALID))
1123     lose_gerror ("Failed to complete EmitFrobnicate call", error);
1124
1125   n_times_frobnicate_received = 0;
1126
1127   dbus_g_connection_flush (connection);
1128   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1129   g_main_loop_run (loop);
1130
1131   if (n_times_frobnicate_received != 1)
1132     lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1133
1134   /* Now terminate the service, then start it again (implicitly) and wait for signals */
1135   g_print ("Terminating service (2)\n");
1136   await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService";
1137   dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID);
1138   dbus_g_connection_flush (connection);
1139   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1140   g_main_loop_run (loop);
1141   if (await_terminating_service != NULL)
1142     lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\"");
1143
1144   if (proxy_destroyed)
1145     lose ("Unexpectedly got proxy_destroyed!");
1146
1147   n_times_frobnicate_received = 0;
1148
1149   g_print ("Calling EmitFrobnicate (2)\n");
1150   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1151                           G_TYPE_INVALID, G_TYPE_INVALID))
1152     lose_gerror ("Failed to complete EmitFrobnicate call", error);
1153
1154   dbus_g_connection_flush (connection);
1155   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1156   g_main_loop_run (loop);
1157
1158   if (n_times_frobnicate_received != 1)
1159     lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1160
1161   if (proxy_destroyed)
1162     lose ("Unexpectedly got proxy_destroyed!");
1163   
1164   /* Create another proxy for the name; should be associated immediately */
1165   proxy2 = dbus_g_proxy_new_for_name (connection,
1166                                      "org.freedesktop.DBus.TestSuiteGLibService",
1167                                      "/org/freedesktop/DBus/Tests/MyTestObject",
1168                                      "org.freedesktop.DBus.Tests.MyObject");
1169   g_assert (proxy2 != NULL);
1170
1171   dbus_g_proxy_add_signal (proxy2, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1172   
1173   dbus_g_proxy_connect_signal (proxy2, "Frobnicate",
1174                                G_CALLBACK (frobnicate_signal_handler_2),
1175                                NULL, NULL);
1176
1177   g_print ("Calling EmitFrobnicate (3)\n");
1178   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1179                           G_TYPE_INVALID, G_TYPE_INVALID))
1180     lose_gerror ("Failed to complete EmitFrobnicate call", error);
1181
1182   dbus_g_connection_flush (connection);
1183   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1184   g_main_loop_run (loop);
1185
1186   if (n_times_frobnicate_received != 2)
1187     lose ("Frobnicate signal received %d times for 1st proxy, should have been 2", n_times_frobnicate_received);
1188   if (n_times_frobnicate_received_2 != 1)
1189     lose ("Frobnicate signal received %d times for 2nd proxy, should have been 1", n_times_frobnicate_received_2);
1190
1191   g_object_unref (G_OBJECT (proxy));
1192   g_object_unref (G_OBJECT (proxy2));
1193
1194   run_mainloop ();
1195
1196   /* Test introspection */
1197   proxy = dbus_g_proxy_new_for_name_owner (connection,
1198                                            "org.freedesktop.DBus.TestSuiteGLibService",
1199                                            "/org/freedesktop/DBus/Tests/MyTestObject",
1200                                            "org.freedesktop.DBus.Introspectable",
1201                                            &error);
1202   if (proxy == NULL)
1203     lose_gerror ("Failed to create proxy for name owner", error);
1204
1205   g_print ("Testing introspect\n");
1206   if (!dbus_g_proxy_call (proxy, "Introspect", &error,
1207                           G_TYPE_INVALID,
1208                           G_TYPE_STRING, &v_STRING_2,
1209                           G_TYPE_INVALID))
1210     lose_gerror ("Failed to complete Introspect call", error);
1211
1212   /* Could just do strcmp(), but that seems more fragile */
1213   {
1214     NodeInfo *node;
1215     GSList *elt;
1216     gboolean found_introspectable;
1217     gboolean found_properties;
1218     gboolean found_myobject;
1219     gboolean found_fooobject;
1220
1221     node = description_load_from_string (v_STRING_2, strlen (v_STRING_2), &error);
1222     if (!node)
1223       lose_gerror ("Failed to parse introspection data: %s", error);
1224
1225     found_introspectable = FALSE;
1226     found_properties = FALSE;
1227     found_myobject = FALSE;
1228     found_fooobject = FALSE;
1229     for (elt = node_info_get_interfaces (node); elt ; elt = elt->next)
1230       {
1231         InterfaceInfo *iface = elt->data;
1232
1233         if (!found_introspectable && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Introspectable") == 0)
1234           found_introspectable = TRUE;
1235         else if (!found_properties && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Properties") == 0)
1236           found_properties = TRUE;
1237         else if (!found_myobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.MyObject") == 0)
1238           {
1239             GSList *elt;
1240             gboolean found_manyargs;
1241             
1242             found_myobject = TRUE;
1243             
1244             found_manyargs = FALSE;
1245             for (elt = interface_info_get_methods (iface); elt; elt = elt->next)
1246               {
1247                 MethodInfo *method;
1248
1249                 method = elt->data;
1250                 if (strcmp (method_info_get_name (method), "ManyArgs") == 0)
1251                   {
1252                     found_manyargs = TRUE;
1253                     break;
1254                   }
1255               }
1256             if (!found_manyargs)
1257               lose ("Missing method org.freedesktop.DBus.Tests.MyObject.ManyArgs");
1258           }
1259         else if (!found_fooobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.FooObject") == 0)
1260           found_fooobject = TRUE;
1261         else
1262           lose ("Unexpected or duplicate interface %s", interface_info_get_name (iface));
1263       }
1264
1265     if (!(found_introspectable && found_myobject && found_properties))
1266       lose ("Missing interface"); 
1267   }
1268   g_free (v_STRING_2);
1269   
1270   g_object_unref (G_OBJECT (driver));
1271
1272   g_print ("Successfully completed %s\n", argv[0]);
1273   
1274   return 0;
1275 }