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