2005-06-30 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\": %s", dbus_g_error_get_name (error),
445           error->message);
446
447   g_print ("ThrowError failed (as expected) returned error: %s\n", error->message);
448   g_clear_error (&error);
449
450   g_print ("Calling Uppercase\n");
451   call = dbus_g_proxy_begin_call (proxy, "Uppercase",
452                                   G_TYPE_STRING, "foobar",
453                                   G_TYPE_INVALID);
454   error = NULL;
455   if (!dbus_g_proxy_end_call (proxy, call, &error,
456                               G_TYPE_STRING, &v_STRING_2,
457                               G_TYPE_INVALID))
458     lose_gerror ("Failed to complete Uppercase call", error);
459   if (strcmp ("FOOBAR", v_STRING_2) != 0)
460     lose ("Uppercase call returned unexpected string %s", v_STRING_2);
461   g_free (v_STRING_2);
462
463   run_mainloop ();
464
465   g_print ("Calling ManyArgs\n");
466   call = dbus_g_proxy_begin_call (proxy, "ManyArgs",
467                                   G_TYPE_UINT, 26,
468                                   G_TYPE_STRING, "bazwhee",
469                                   G_TYPE_DOUBLE, G_PI,
470                                   G_TYPE_INVALID);
471   error = NULL;
472   if (!dbus_g_proxy_end_call (proxy, call, &error,
473                               G_TYPE_DOUBLE, &v_DOUBLE_2,
474                               G_TYPE_STRING, &v_STRING_2,
475                               G_TYPE_INVALID))
476     lose_gerror ("Failed to complete ManyArgs call", error);
477   if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56)
478     lose ("ManyArgs call returned unexpected double value %f", v_DOUBLE_2);
479   if (strcmp ("BAZWHEE", v_STRING_2) != 0)
480     lose ("ManyArgs call returned unexpected string %s", v_STRING_2);
481   g_free (v_STRING_2);
482
483   g_print ("Calling (wrapped) do_nothing\n");
484   if (!org_freedesktop_DBus_Tests_MyObject_do_nothing (proxy, &error))
485     lose_gerror ("Failed to complete (wrapped) DoNothing call", error);
486
487   g_print ("Calling (wrapped) increment\n");
488   if (!org_freedesktop_DBus_Tests_MyObject_increment (proxy, 42, &v_UINT32_2, &error))
489     lose_gerror ("Failed to complete (wrapped) Increment call", error);
490
491   if (v_UINT32_2 != 43)
492     lose ("(wrapped) increment call returned %d, should be 43", v_UINT32_2);
493
494   v_UINT32_2 = 0;
495   if (!org_freedesktop_DBus_Tests_MyObject_async_increment (proxy, 42, &v_UINT32_2, &error))
496     lose_gerror ("Failed to complete (wrapped) AsyncIncrement call", error);
497
498   if (v_UINT32_2 != 43)
499     lose ("(wrapped) async increment call returned %d, should be 43", v_UINT32_2);
500
501   g_print ("Calling (wrapped) throw_error\n");
502   if (org_freedesktop_DBus_Tests_MyObject_throw_error (proxy, &error) != FALSE)
503     lose ("(wrapped) ThrowError call unexpectedly succeeded!");
504
505   g_print ("(wrapped) ThrowError failed (as expected) returned error: %s\n", error->message);
506   g_clear_error (&error);
507
508   if (org_freedesktop_DBus_Tests_MyObject_async_throw_error (proxy, &error) != FALSE)
509     lose ("(wrapped) AsyncThrowError call unexpectedly succeeded!");
510
511   g_print ("(wrapped) AsyncThrowError failed (as expected) returned error: %s\n", error->message);
512   g_clear_error (&error);
513
514   g_print ("Calling (wrapped) uppercase\n");
515   if (!org_freedesktop_DBus_Tests_MyObject_uppercase (proxy, "foobar", &v_STRING_2, &error)) 
516     lose_gerror ("Failed to complete (wrapped) Uppercase call", error);
517   if (strcmp ("FOOBAR", v_STRING_2) != 0)
518     lose ("(wrapped) Uppercase call returned unexpected string %s", v_STRING_2);
519   g_free (v_STRING_2);
520
521   g_print ("Calling (wrapped) many_args\n");
522   if (!org_freedesktop_DBus_Tests_MyObject_many_args (proxy, 26, "bazwhee", G_PI,
523                                                       &v_DOUBLE_2, &v_STRING_2, &error))
524     lose_gerror ("Failed to complete (wrapped) ManyArgs call", error);
525
526   if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56)
527     
528     lose ("(wrapped) ManyArgs call returned unexpected double value %f", v_DOUBLE_2);
529
530   if (strcmp ("BAZWHEE", v_STRING_2) != 0)
531     lose ("(wrapped) ManyArgs call returned unexpected string %s", v_STRING_2);
532   g_free (v_STRING_2);
533
534   {
535     guint32 arg0;
536     char *arg1;
537     gint32 arg2;
538     guint32 arg3;
539     guint32 arg4;
540     char *arg5;
541     
542     g_print ("Calling (wrapped) many_return\n");
543     if (!org_freedesktop_DBus_Tests_MyObject_many_return (proxy, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &error))
544       lose_gerror ("Failed to complete (wrapped) ManyReturn call", error);
545
546     if (arg0 != 42)
547       lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg0);
548
549     if (strcmp ("42", arg1) != 0)
550       lose ("(wrapped) ManyReturn call returned unexpected string %s", arg1);
551     g_free (arg1);
552
553     if (arg2 != -67)
554       lose ("(wrapped) ManyReturn call returned unexpected gint32 value %u", arg2);
555
556     if (arg3 != 2)
557       lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg3);
558
559     if (arg4 != 26)
560       lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg4);
561
562     if (strcmp ("hello world", arg5))
563       lose ("(wrapped) ManyReturn call returned unexpected string %s", arg5);
564     g_free (arg5);
565   }
566
567   run_mainloop ();
568
569   {
570     GValue value = {0, };
571
572     g_value_init (&value, G_TYPE_STRING);
573     g_value_set_string (&value, "foo");
574
575     g_print ("Calling (wrapped) stringify, with string\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", error);
581     if (strcmp ("foo", v_STRING_2) != 0)
582       lose ("(wrapped) stringify call returned unexpected string %s", v_STRING_2);
583     g_free (v_STRING_2);
584
585     g_value_unset (&value);
586     g_value_init (&value, G_TYPE_INT);
587     g_value_set_int (&value, 42);
588
589     g_print ("Calling (wrapped) stringify, with int\n");
590     if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
591                                                         &value,
592                                                         &v_STRING_2,
593                                                         &error))
594       lose_gerror ("Failed to complete (wrapped) stringify call 2", error);
595     if (strcmp ("42", v_STRING_2) != 0)
596       lose ("(wrapped) stringify call 2 returned unexpected string %s", v_STRING_2);
597     g_value_unset (&value);
598     g_free (v_STRING_2);
599
600     g_value_init (&value, G_TYPE_INT);
601     g_value_set_int (&value, 88);
602     g_print ("Calling (wrapped) stringify, with another int\n");
603     if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
604                                                         &value,
605                                                         NULL,
606                                                         &error))
607       lose_gerror ("Failed to complete (wrapped) stringify call 3", error);
608     g_value_unset (&value);
609
610     g_print ("Calling (wrapped) unstringify, for string\n");
611     if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy,
612                                                           "foo",
613                                                           &value,
614                                                           &error))
615       lose_gerror ("Failed to complete (wrapped) unstringify call", error);
616     if (!G_VALUE_HOLDS_STRING (&value))
617       lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value));
618     if (strcmp (g_value_get_string (&value), "foo"))
619       lose ("(wrapped) unstringify call returned unexpected string %s",
620             g_value_get_string (&value));
621         
622     g_value_unset (&value);
623
624     g_print ("Calling (wrapped) unstringify, for int\n");
625     if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy,
626                                                           "10",
627                                                           &value,
628                                                           &error))
629       lose_gerror ("Failed to complete (wrapped) unstringify call", error);
630     if (!G_VALUE_HOLDS_INT (&value))
631       lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value));
632     if (g_value_get_int (&value) != 10)
633       lose ("(wrapped) unstringify call returned unexpected integer %d",
634             g_value_get_int (&value));
635
636     g_value_unset (&value);
637   }
638
639   run_mainloop ();
640
641   {
642     GArray *array;
643     guint32 val;
644     guint32 arraylen;
645
646     array = g_array_new (FALSE, TRUE, sizeof (guint32));
647     val = 42;
648     g_array_append_val (array, val);
649     val = 69;
650     g_array_append_val (array, val);
651     val = 88;
652     g_array_append_val (array, val);
653     val = 26;
654     g_array_append_val (array, val);
655     val = 2;
656     g_array_append_val (array, val);
657
658     arraylen = 0;
659     g_print ("Calling (wrapped) recursive1\n");
660     if (!org_freedesktop_DBus_Tests_MyObject_recursive1 (proxy, array,
661                                                          &arraylen, &error))
662       lose_gerror ("Failed to complete (wrapped) recursive1 call", error);
663     if (arraylen != 5)
664       lose ("(wrapped) recursive1 call returned invalid length %u", arraylen);
665   }
666
667   {
668     GArray *array = NULL;
669     guint32 *arrayvals;
670     
671     g_print ("Calling (wrapped) recursive2\n");
672     if (!org_freedesktop_DBus_Tests_MyObject_recursive2 (proxy, 2, &array, &error))
673       lose_gerror ("Failed to complete (wrapped) Recursive2 call", error);
674
675     if (array == NULL)
676       lose ("(wrapped) Recursive2 call returned NULL");
677     if (array->len != 5)
678       lose ("(wrapped) Recursive2 call returned unexpected array length %u", array->len);
679
680     arrayvals = (guint32*) array->data;
681     if (arrayvals[0] != 42)
682       lose ("(wrapped) Recursive2 call returned unexpected value %d in position 0", arrayvals[0]);
683     if (arrayvals[1] != 26)
684       lose ("(wrapped) Recursive2 call returned unexpected value %d in position 1", arrayvals[1]);
685     if (arrayvals[4] != 2)
686       lose ("(wrapped) Recursive2 call returned unexpected value %d in position 4", arrayvals[4]);
687
688     g_array_free (array, TRUE);
689   }
690
691   run_mainloop ();
692
693   {
694     char **strs;
695     char **strs_ret;
696
697     strs = g_new0 (char *, 4);
698     strs[0] = "hello";
699     strs[1] = "HellO";
700     strs[2] = "HELLO";
701     strs[3] = NULL;
702
703     strs_ret = NULL;
704     g_print ("Calling (wrapped) many_uppercase\n");
705     if (!org_freedesktop_DBus_Tests_MyObject_many_uppercase (proxy, strs, &strs_ret, &error)) 
706       lose_gerror ("Failed to complete (wrapped) ManyUppercase call", error);
707     g_assert (strs_ret != NULL);
708     if (strcmp ("HELLO", strs_ret[0]) != 0)
709       lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[0]);
710     if (strcmp ("HELLO", strs_ret[1]) != 0)
711       lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[1]);
712     if (strcmp ("HELLO", strs_ret[2]) != 0)
713       lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[2]);
714
715     g_free (strs);
716     g_strfreev (strs_ret);
717   }
718
719   {
720     GHashTable *table;
721     guint len;
722
723     table = g_hash_table_new (g_str_hash, g_str_equal);
724     g_hash_table_insert (table, "moooo", "b");
725     g_hash_table_insert (table, "xxx", "cow!");
726
727     len = 0;
728     g_print ("Calling (wrapped) str_hash_len\n");
729     if (!org_freedesktop_DBus_Tests_MyObject_str_hash_len (proxy, table, &len, &error))
730       lose_gerror ("(wrapped) StrHashLen call failed", error);
731     if (len != 13) 
732       lose ("(wrapped) StrHashLen returned unexpected length %u", len);
733     g_hash_table_destroy (table);
734   }
735
736   {
737     GHashTable *table;
738     const char *val;
739
740     g_print ("Calling (wrapped) get_hash\n");
741     if (!org_freedesktop_DBus_Tests_MyObject_get_hash (proxy, &table, &error))
742       lose_gerror ("(wrapped) GetHash call failed", error);
743     val = g_hash_table_lookup (table, "foo");
744     if (val == NULL || strcmp ("bar", val))
745       lose ("(wrapped) StrHashLen returned invalid value %s for key \"foo\"",
746             val ? val : "(null)");
747     val = g_hash_table_lookup (table, "baz");
748     if (val == NULL || strcmp ("whee", val))
749       lose ("(wrapped) StrHashLen returned invalid value %s for key \"whee\"",
750             val ? val : "(null)");
751     val = g_hash_table_lookup (table, "cow");
752     if (val == NULL || strcmp ("crack", val))
753       lose ("(wrapped) StrHashLen returned invalid value %s for key \"cow\"",
754             val ? val : "(null)");
755     if (g_hash_table_size (table) != 3)
756       lose ("(wrapped) StrHashLen returned unexpected hash size %u",
757             g_hash_table_size (table));
758
759     g_hash_table_destroy (table);
760   }
761
762   run_mainloop ();
763
764   {
765     guint val;
766     char *ret_path;
767     DBusGProxy *ret_proxy;
768
769     g_print ("Calling (wrapped) objpath\n");
770     if (!dbus_g_proxy_call (proxy, "Objpath", &error,
771                             DBUS_TYPE_G_PROXY, proxy, G_TYPE_INVALID,
772                             DBUS_TYPE_G_PROXY, &ret_proxy, G_TYPE_INVALID))
773       lose_gerror ("Failed to complete Objpath call", error);
774     if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
775                 dbus_g_proxy_get_path (ret_proxy)) != 0)
776       lose ("(wrapped) objpath call returned unexpected proxy %s",
777             dbus_g_proxy_get_path (ret_proxy));
778
779     g_print ("Doing get/increment val tests\n");
780     val = 1;
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 != 0)
784       lose ("(wrapped) GetVal returned invalid value %d", val);
785
786     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
787       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
788
789     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
790       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
791
792     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
793       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
794
795     if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
796       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
797     if (val != 3)
798       lose ("(wrapped) GetVal returned invalid value %d", val);
799
800     if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error))
801       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
802     if (val != 0)
803       lose ("(wrapped) GetVal returned invalid value %d", val);
804
805     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (proxy, &error))
806       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
807
808     if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error))
809       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
810     if (val != 1)
811       lose ("(wrapped) GetVal returned invalid value %d", val);
812
813     if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
814       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
815     if (val != 3)
816       lose ("(wrapped) GetVal returned invalid value %d", val);
817
818     g_object_unref (G_OBJECT (ret_proxy));
819
820     g_print ("Calling objpath again\n");
821     ret_proxy = NULL;
822
823     if (!dbus_g_proxy_call (proxy, "Objpath", &error,
824                             DBUS_TYPE_G_OBJECT_PATH,
825                             dbus_g_proxy_get_path (proxy),
826                             G_TYPE_INVALID,
827                             DBUS_TYPE_G_OBJECT_PATH,
828                             &ret_path,
829                             G_TYPE_INVALID))
830       lose_gerror ("Failed to complete (wrapped) Objpath call 2", error);
831     if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2", ret_path) != 0)
832       lose ("(wrapped) objpath call 2 returned unexpected path %s",
833             ret_path);
834
835     ret_proxy = dbus_g_proxy_new_for_name_owner (connection,
836                                                  "org.freedesktop.DBus.TestSuiteGLibService",
837                                                  ret_path,
838                                                  "org.freedesktop.DBus.Tests.FooObject",
839                                                  &error);
840     
841     val = 0;
842     if (!org_freedesktop_DBus_Tests_FooObject_get_value (ret_proxy, &val, &error))
843       lose_gerror ("Failed to complete (wrapped) GetValue call", error);
844     if (val != 3)
845       lose ("(wrapped) GetValue returned invalid value %d", val);
846   }
847
848   run_mainloop ();
849
850   /* Signal handling tests */
851   
852   g_print ("Testing signal handling\n");
853   dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
854   
855   dbus_g_proxy_connect_signal (proxy, "Frobnicate",
856                                G_CALLBACK (frobnicate_signal_handler),
857                                NULL, NULL);
858   
859   g_print ("Calling EmitFrobnicate\n");
860   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
861                           G_TYPE_INVALID, G_TYPE_INVALID))
862     lose_gerror ("Failed to complete EmitFrobnicate call", error);
863
864   
865   dbus_g_connection_flush (connection);
866   exit_timeout = g_timeout_add (5000, timed_exit, loop);
867   g_main_loop_run (loop);
868
869   if (n_times_frobnicate_received != 1)
870     lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
871
872   g_print ("Calling EmitFrobnicate again\n");
873   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
874                           G_TYPE_INVALID, G_TYPE_INVALID))
875     lose_gerror ("Failed to complete EmitFrobnicate call", error);
876   
877   dbus_g_connection_flush (connection);
878   exit_timeout = g_timeout_add (5000, timed_exit, loop);
879   g_main_loop_run (loop);
880
881   if (n_times_frobnicate_received != 2)
882     lose ("Frobnicate signal received %d times, should have been 2", n_times_frobnicate_received);
883
884   g_object_unref (G_OBJECT (proxy));
885
886   run_mainloop ();
887
888   g_print ("Creating proxy for FooObject interface\n");
889   proxy = dbus_g_proxy_new_for_name_owner (connection,
890                                            "org.freedesktop.DBus.TestSuiteGLibService",
891                                            "/org/freedesktop/DBus/Tests/MyTestObject",
892                                            "org.freedesktop.DBus.Tests.FooObject",
893                                            &error);
894   
895   if (proxy == NULL)
896     lose_gerror ("Failed to create proxy for name owner", error);
897
898   dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_INT_STRING, 
899                                      G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
900
901   dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_BOXED, 
902                                      G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
903
904   dbus_g_proxy_add_signal (proxy, "Sig0", G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
905   dbus_g_proxy_add_signal (proxy, "Sig1", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
906   dbus_g_proxy_add_signal (proxy, "Sig2", DBUS_TYPE_G_STRING_STRING_HASHTABLE, G_TYPE_INVALID);
907   
908   dbus_g_proxy_connect_signal (proxy, "Sig0",
909                                G_CALLBACK (sig0_signal_handler),
910                                NULL, NULL);
911   dbus_g_proxy_connect_signal (proxy, "Sig1",
912                                G_CALLBACK (sig1_signal_handler),
913                                NULL, NULL);
914   dbus_g_proxy_connect_signal (proxy, "Sig2",
915                                G_CALLBACK (sig2_signal_handler),
916                                NULL, NULL);
917
918   g_print ("Calling FooObject EmitSignals\n");
919   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
920
921   dbus_g_connection_flush (connection);
922   exit_timeout = g_timeout_add (5000, timed_exit, loop);
923   g_main_loop_run (loop);
924   exit_timeout = g_timeout_add (5000, timed_exit, loop);
925   g_main_loop_run (loop);
926
927   if (n_times_sig0_received != 1)
928     lose ("Sig0 signal received %d times, should have been 1", n_times_sig0_received);
929   if (n_times_sig1_received != 1)
930     lose ("Sig1 signal received %d times, should have been 1", n_times_sig1_received);
931
932   g_print ("Calling FooObject EmitSignals and EmitSignal2\n");
933   dbus_g_proxy_call_no_reply (proxy, "EmitSignal2", G_TYPE_INVALID);
934   dbus_g_connection_flush (connection);
935
936   exit_timeout = g_timeout_add (5000, timed_exit, loop);
937   g_main_loop_run (loop);
938
939   if (n_times_sig2_received != 1)
940     lose ("Sig2 signal received %d times, should have been 1", n_times_sig2_received);
941
942   g_print ("Calling FooObject EmitSignals two more times\n");
943   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
944   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
945
946   dbus_g_connection_flush (connection);
947   exit_timeout = g_timeout_add (5000, timed_exit, loop);
948   g_main_loop_run (loop);
949   exit_timeout = g_timeout_add (5000, timed_exit, loop);
950   g_main_loop_run (loop);
951   exit_timeout = g_timeout_add (5000, timed_exit, loop);
952   g_main_loop_run (loop);
953   exit_timeout = g_timeout_add (5000, timed_exit, loop);
954   g_main_loop_run (loop);
955
956   if (n_times_sig0_received != 3)
957     lose ("Sig0 signal received %d times, should have been 3", n_times_sig0_received);
958   if (n_times_sig1_received != 3)
959     lose ("Sig1 signal received %d times, should have been 3", n_times_sig1_received);
960
961   /* Terminate again */
962   g_print ("Terminating service\n");
963   await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService";
964   dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID);
965
966   proxy_destroyed = FALSE;
967   proxy_destroy_and_nameowner = TRUE;
968   proxy_destroy_and_nameowner_complete = FALSE;
969
970   g_signal_connect (G_OBJECT (proxy),
971                     "destroy",
972                     G_CALLBACK (proxy_destroyed_cb),
973                     NULL);
974
975   dbus_g_connection_flush (connection);
976   exit_timeout = g_timeout_add (5000, timed_exit, loop);
977   g_main_loop_run (loop);
978
979   if (await_terminating_service != NULL)
980     lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\"");
981   if (!proxy_destroyed)
982     lose ("Didn't get proxy_destroyed");
983   g_print ("Proxy destroyed successfully\n");
984
985   g_object_unref (G_OBJECT (proxy));
986
987   run_mainloop ();
988
989   /* Create a new proxy for the name; should not be associated */
990   proxy = dbus_g_proxy_new_for_name (connection,
991                                      "org.freedesktop.DBus.TestSuiteGLibService",
992                                      "/org/freedesktop/DBus/Tests/MyTestObject",
993                                      "org.freedesktop.DBus.Tests.MyObject");
994   g_assert (proxy != NULL);
995
996   proxy_destroyed = FALSE;
997   proxy_destroy_and_nameowner = FALSE;
998   proxy_destroy_and_nameowner_complete = FALSE;
999
1000   g_signal_connect (G_OBJECT (proxy),
1001                     "destroy",
1002                     G_CALLBACK (proxy_destroyed_cb),
1003                     NULL);
1004   
1005   if (!dbus_g_proxy_call (driver, "GetNameOwner", &error,
1006                           G_TYPE_STRING,
1007                           "org.freedesktop.DBus.TestSuiteGLibService",
1008                           G_TYPE_INVALID,
1009                           G_TYPE_STRING,
1010                           &v_STRING_2,
1011                           G_TYPE_INVALID)) {
1012     if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NAME_HAS_NO_OWNER)
1013       g_print ("Got expected error \"org.freedesktop.DBus.Error.NameHasNoOwner\"\n");
1014     else
1015       lose_gerror ("Unexpected error from GetNameOwner", error);
1016   } else
1017     lose ("GetNameOwner unexpectedly succeeded!");
1018   g_clear_error (&error);
1019
1020   /* This will have the side-effect of activating the service, thus
1021    * causing a NameOwnerChanged, which should let our name proxy
1022    * get signals
1023    */
1024   g_print ("Calling Uppercase for name proxy\n");
1025   if (!dbus_g_proxy_call (proxy, "Uppercase", &error,
1026                           G_TYPE_STRING, "bazwhee",
1027                           G_TYPE_INVALID,
1028                           G_TYPE_STRING, &v_STRING_2,
1029                           G_TYPE_INVALID))
1030     lose_gerror ("Failed to complete Uppercase call", error);
1031   g_free (v_STRING_2);
1032
1033   dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1034   
1035   dbus_g_proxy_connect_signal (proxy, "Frobnicate",
1036                                G_CALLBACK (frobnicate_signal_handler),
1037                                NULL, NULL);
1038   
1039   g_print ("Calling EmitFrobnicate\n");
1040   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1041                           G_TYPE_INVALID, G_TYPE_INVALID))
1042     lose_gerror ("Failed to complete EmitFrobnicate call", error);
1043
1044   n_times_frobnicate_received = 0;
1045
1046   dbus_g_connection_flush (connection);
1047   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1048   g_main_loop_run (loop);
1049
1050   if (n_times_frobnicate_received != 1)
1051     lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1052
1053   /* Now terminate the service, then start it again (implicitly) and wait for signals */
1054   g_print ("Terminating service (2)\n");
1055   await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService";
1056   dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID);
1057   dbus_g_connection_flush (connection);
1058   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1059   g_main_loop_run (loop);
1060   if (await_terminating_service != NULL)
1061     lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\"");
1062
1063   if (proxy_destroyed)
1064     lose ("Unexpectedly got proxy_destroyed!");
1065
1066   n_times_frobnicate_received = 0;
1067
1068   g_print ("Calling EmitFrobnicate (2)\n");
1069   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1070                           G_TYPE_INVALID, G_TYPE_INVALID))
1071     lose_gerror ("Failed to complete EmitFrobnicate call", error);
1072
1073   dbus_g_connection_flush (connection);
1074   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1075   g_main_loop_run (loop);
1076
1077   if (n_times_frobnicate_received != 1)
1078     lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1079
1080   if (proxy_destroyed)
1081     lose ("Unexpectedly got proxy_destroyed!");
1082   
1083   /* Create another proxy for the name; should be associated immediately */
1084   proxy2 = dbus_g_proxy_new_for_name (connection,
1085                                      "org.freedesktop.DBus.TestSuiteGLibService",
1086                                      "/org/freedesktop/DBus/Tests/MyTestObject",
1087                                      "org.freedesktop.DBus.Tests.MyObject");
1088   g_assert (proxy2 != NULL);
1089
1090   dbus_g_proxy_add_signal (proxy2, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1091   
1092   dbus_g_proxy_connect_signal (proxy2, "Frobnicate",
1093                                G_CALLBACK (frobnicate_signal_handler_2),
1094                                NULL, NULL);
1095
1096   g_print ("Calling EmitFrobnicate (3)\n");
1097   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1098                           G_TYPE_INVALID, G_TYPE_INVALID))
1099     lose_gerror ("Failed to complete EmitFrobnicate call", error);
1100
1101   dbus_g_connection_flush (connection);
1102   exit_timeout = g_timeout_add (5000, timed_exit, loop);
1103   g_main_loop_run (loop);
1104
1105   if (n_times_frobnicate_received != 2)
1106     lose ("Frobnicate signal received %d times for 1st proxy, should have been 2", n_times_frobnicate_received);
1107   if (n_times_frobnicate_received_2 != 1)
1108     lose ("Frobnicate signal received %d times for 2nd proxy, should have been 1", n_times_frobnicate_received_2);
1109
1110   g_object_unref (G_OBJECT (proxy));
1111   g_object_unref (G_OBJECT (proxy2));
1112
1113   run_mainloop ();
1114
1115   /* Test introspection */
1116   proxy = dbus_g_proxy_new_for_name_owner (connection,
1117                                            "org.freedesktop.DBus.TestSuiteGLibService",
1118                                            "/org/freedesktop/DBus/Tests/MyTestObject",
1119                                            "org.freedesktop.DBus.Introspectable",
1120                                            &error);
1121   if (proxy == NULL)
1122     lose_gerror ("Failed to create proxy for name owner", error);
1123
1124   g_print ("Testing introspect\n");
1125   call = dbus_g_proxy_begin_call (proxy, "Introspect",
1126                                   G_TYPE_INVALID);
1127   error = NULL;
1128   if (!dbus_g_proxy_end_call (proxy, call, &error,
1129                               G_TYPE_STRING, &v_STRING_2,
1130                               G_TYPE_INVALID))
1131     lose_gerror ("Failed to complete Introspect call", error);
1132
1133   /* Could just do strcmp(), but that seems more fragile */
1134   {
1135     NodeInfo *node;
1136     GSList *elt;
1137     gboolean found_introspectable;
1138     gboolean found_properties;
1139     gboolean found_myobject;
1140     gboolean found_fooobject;
1141
1142     node = description_load_from_string (v_STRING_2, strlen (v_STRING_2), &error);
1143     if (!node)
1144       lose_gerror ("Failed to parse introspection data: %s", error);
1145
1146     found_introspectable = FALSE;
1147     found_properties = FALSE;
1148     found_myobject = FALSE;
1149     found_fooobject = FALSE;
1150     for (elt = node_info_get_interfaces (node); elt ; elt = elt->next)
1151       {
1152         InterfaceInfo *iface = elt->data;
1153
1154         if (!found_introspectable && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Introspectable") == 0)
1155           found_introspectable = TRUE;
1156         else if (!found_properties && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Properties") == 0)
1157           found_properties = TRUE;
1158         else if (!found_myobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.MyObject") == 0)
1159           {
1160             GSList *elt;
1161             gboolean found_manyargs;
1162             
1163             found_myobject = TRUE;
1164             
1165             found_manyargs = FALSE;
1166             for (elt = interface_info_get_methods (iface); elt; elt = elt->next)
1167               {
1168                 MethodInfo *method;
1169
1170                 method = elt->data;
1171                 if (strcmp (method_info_get_name (method), "ManyArgs") == 0)
1172                   {
1173                     found_manyargs = TRUE;
1174                     break;
1175                   }
1176               }
1177             if (!found_manyargs)
1178               lose ("Missing method org.freedesktop.DBus.Tests.MyObject.ManyArgs");
1179           }
1180         else if (!found_fooobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.FooObject") == 0)
1181           found_fooobject = TRUE;
1182         else
1183           lose ("Unexpected or duplicate interface %s", interface_info_get_name (iface));
1184       }
1185
1186     if (!(found_introspectable && found_myobject && found_properties))
1187       lose ("Missing interface"); 
1188   }
1189   g_free (v_STRING_2);
1190   
1191   g_object_unref (G_OBJECT (driver));
1192
1193   g_print ("Successfully completed %s\n", argv[0]);
1194   
1195   return 0;
1196 }