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