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