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