2005-06-26 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-object.h>
10 #include "my-object-marshal.h"
11
12 static GMainLoop *loop = NULL;
13 static int n_times_foo_received = 0;
14 static int n_times_frobnicate_received = 0;
15 static int n_times_sig0_received = 0;
16 static int n_times_sig1_received = 0;
17 static guint exit_timeout = 0;
18
19 static gboolean
20 timed_exit (gpointer loop)
21 {
22   g_main_loop_quit (loop);
23   return TRUE;
24 }
25
26 static void
27 foo_signal_handler (DBusGProxy  *proxy,
28                     double       d,
29                     void        *user_data)
30 {
31   n_times_foo_received += 1;
32
33   g_main_loop_quit (loop);
34   g_source_remove (exit_timeout);
35 }
36
37 static void
38 frobnicate_signal_handler (DBusGProxy  *proxy,
39                            int          val,
40                            void        *user_data)
41 {
42   n_times_frobnicate_received += 1;
43
44   g_assert (val == 42);
45
46   g_main_loop_quit (loop);
47   g_source_remove (exit_timeout);
48 }
49
50 static void
51 sig0_signal_handler (DBusGProxy  *proxy,
52                      const char  *str0,
53                      int          val,
54                      const char  *str1,
55                      void        *user_data)
56 {
57   n_times_sig0_received += 1;
58
59   g_assert (!strcmp (str0, "foo"));
60
61   g_assert (val == 22);
62
63   g_assert (!strcmp (str1, "moo"));
64
65   g_main_loop_quit (loop);
66   g_source_remove (exit_timeout);
67 }
68
69 static void
70 sig1_signal_handler (DBusGProxy  *proxy,
71                      const char  *str0,
72                      GValue      *value,
73                      void        *user_data)
74 {
75   n_times_sig1_received += 1;
76
77   g_assert (!strcmp (str0, "baz"));
78
79   g_assert (G_VALUE_HOLDS_STRING (value));
80
81   g_assert (!strcmp (g_value_get_string (value), "bar"));
82
83   g_main_loop_quit (loop);
84   g_source_remove (exit_timeout);
85 }
86
87 static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
88 static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
89
90 static void
91 lose (const char *str, ...)
92 {
93   va_list args;
94
95   va_start (args, str);
96
97   vfprintf (stderr, str, args);
98   fputc ('\n', stderr);
99
100   va_end (args);
101
102   exit (1);
103 }
104
105 static void
106 lose_gerror (const char *prefix, GError *error) 
107 {
108   lose ("%s: %s", prefix, error->message);
109 }
110
111 int
112 main (int argc, char **argv)
113 {
114   DBusGConnection *connection;
115   GError *error;
116   DBusGProxy *driver;
117   DBusGProxy *proxy;
118   DBusGPendingCall *call;
119   char **name_list;
120   guint name_list_len;
121   guint i;
122   guint32 result;
123   const char *v_STRING;
124   char *v_STRING_2;
125   guint32 v_UINT32;
126   guint32 v_UINT32_2;
127   double v_DOUBLE;
128   double v_DOUBLE_2;
129     
130   g_type_init ();
131
132   g_log_set_always_fatal (G_LOG_LEVEL_WARNING);
133   
134   loop = g_main_loop_new (NULL, FALSE);
135
136   error = NULL;
137   connection = dbus_g_bus_get (DBUS_BUS_SESSION,
138                                &error);
139   if (connection == NULL)
140     lose_gerror ("Failed to open connection to bus", error);
141
142   /* should always get the same one */
143   g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
144   g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
145   g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
146   
147   /* Create a proxy object for the "bus driver" */
148   
149   driver = dbus_g_proxy_new_for_name (connection,
150                                       DBUS_SERVICE_DBUS,
151                                       DBUS_PATH_DBUS,
152                                       DBUS_INTERFACE_DBUS);
153
154   /* Call ListNames method */
155   
156   call = dbus_g_proxy_begin_call (driver, "ListNames", G_TYPE_INVALID);
157
158   error = NULL;
159   if (!dbus_g_proxy_end_call (driver, call, &error,
160                               G_TYPE_STRV, &name_list,
161                               G_TYPE_INVALID))
162     lose_gerror ("Failed to complete ListNames call", error);
163
164   g_print ("Names on the message bus:\n");
165   i = 0;
166   name_list_len = g_strv_length (name_list);
167   while (i < name_list_len)
168     {
169       g_assert (name_list[i] != NULL);
170       g_print ("  %s\n", name_list[i]);
171       ++i;
172     }
173   g_assert (name_list[i] == NULL);
174
175   g_strfreev (name_list);
176
177   /* Test handling of unknown method */
178   call = dbus_g_proxy_begin_call (driver, "ThisMethodDoesNotExist",
179                                   G_TYPE_STRING,
180                                   "blah blah blah blah blah",
181                                   G_TYPE_INT,
182                                   10,
183                                   G_TYPE_INVALID);
184
185   error = NULL;
186   if (dbus_g_proxy_end_call (driver, call, &error,
187                              G_TYPE_INVALID))
188     lose ("Calling nonexistent method succeeded!");
189
190   g_print ("Got EXPECTED error from calling unknown method: %s\n", error->message);
191   g_error_free (error);
192   
193   /* Activate a service */
194   call = dbus_g_proxy_begin_call (driver, "StartServiceByName",
195                                   G_TYPE_STRING,
196                                   "org.freedesktop.DBus.TestSuiteEchoService",
197                                   G_TYPE_UINT,
198                                   0,
199                                   G_TYPE_INVALID);
200
201   error = NULL;
202   if (!dbus_g_proxy_end_call (driver, call, &error,
203                               G_TYPE_UINT, &result,
204                               G_TYPE_INVALID))
205     lose_gerror ("Failed to complete Activate call", error);
206
207   g_print ("Starting echo service result = 0x%x\n", result);
208
209   /* Activate a service again */
210   call = dbus_g_proxy_begin_call (driver, "StartServiceByName",
211                                   G_TYPE_STRING,
212                                   "org.freedesktop.DBus.TestSuiteEchoService",
213                                   G_TYPE_UINT,
214                                   0,
215                                   DBUS_TYPE_INVALID);
216
217   error = NULL;
218   if (!dbus_g_proxy_end_call (driver, call, &error,
219                               G_TYPE_UINT, &result,
220                               G_TYPE_INVALID))
221     lose_gerror ("Failed to complete Activate call", error);
222
223   g_print ("Duplicate start of echo service = 0x%x\n", result);
224
225   /* Talk to the new service */
226   
227   proxy = dbus_g_proxy_new_for_name_owner (connection,
228                                            "org.freedesktop.DBus.TestSuiteEchoService",
229                                            "/org/freedesktop/TestSuite",
230                                            "org.freedesktop.TestSuite",
231                                            &error);
232   
233   if (proxy == NULL)
234     lose_gerror ("Failed to create proxy for name owner", error);
235
236   call = dbus_g_proxy_begin_call (proxy, "Echo",
237                                   G_TYPE_STRING,
238                                   "my string hello",
239                                   G_TYPE_INVALID);
240
241   error = NULL;
242   if (!dbus_g_proxy_end_call (proxy, call, &error,
243                               G_TYPE_STRING, &v_STRING_2,
244                               G_TYPE_INVALID))
245     lose_gerror ("Failed to complete Echo call", error);
246
247   g_print ("String echoed = \"%s\"\n", v_STRING_2);
248   g_free (v_STRING_2);
249
250   /* Test oneway call and signal handling */
251
252   dbus_g_proxy_add_signal (proxy, "Foo", G_TYPE_DOUBLE, G_TYPE_INVALID);
253   
254   dbus_g_proxy_connect_signal (proxy, "Foo",
255                                G_CALLBACK (foo_signal_handler),
256                                NULL, NULL);
257   
258   dbus_g_proxy_call_no_reply (proxy, "EmitFoo",
259                               G_TYPE_INVALID);
260   
261   dbus_g_connection_flush (connection);
262   exit_timeout = g_timeout_add (5000, timed_exit, loop);
263   g_main_loop_run (loop);
264
265   if (n_times_foo_received != 1)
266     lose ("Foo signal received %d times, should have been 1", n_times_foo_received);
267   
268   /* Activate test servie */ 
269   g_print ("Activating TestSuiteGLibService\n");
270   error = NULL;
271   if (!dbus_g_proxy_call (driver, "StartServiceByName", &error,
272                           G_TYPE_STRING,
273                           "org.freedesktop.DBus.TestSuiteGLibService",
274                           G_TYPE_UINT,
275                           0,
276                           G_TYPE_INVALID,
277                           G_TYPE_UINT, &result,
278                           G_TYPE_INVALID)) {
279     lose_gerror ("Failed to complete Activate call", error);
280   }
281
282   g_print ("TestSuiteGLibService activated\n");
283
284   if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION"))
285     g_usleep (8 * G_USEC_PER_SEC);
286
287   g_object_unref (G_OBJECT (proxy));
288
289   proxy = dbus_g_proxy_new_for_name_owner (connection,
290                                            "org.freedesktop.DBus.TestSuiteGLibService",
291                                            "/org/freedesktop/DBus/Tests/MyTestObject",
292                                            "org.freedesktop.DBus.Tests.MyObject",
293                                            &error);
294   
295   if (proxy == NULL)
296     lose_gerror ("Failed to create proxy for name owner", error);
297
298   g_print ("Beginning method calls\n");
299
300   call = dbus_g_proxy_begin_call (proxy, "DoNothing",
301                                   G_TYPE_INVALID);
302   error = NULL;
303   if (!dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID))
304     lose_gerror ("Failed to complete DoNothing call", error);
305
306   error = NULL;
307   if (!dbus_g_proxy_call (proxy, "Increment", &error,
308                           G_TYPE_UINT, 42,
309                           G_TYPE_INVALID,
310                           G_TYPE_UINT, &v_UINT32_2,
311                           G_TYPE_INVALID))
312     lose_gerror ("Failed to complete Increment call", error);
313
314   if (v_UINT32_2 != 43)
315     lose ("Increment call returned %d, should be 43", v_UINT32_2);
316
317   call = dbus_g_proxy_begin_call (proxy, "ThrowError", G_TYPE_INVALID);
318   error = NULL;
319   if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID) != FALSE)
320     lose ("ThrowError call unexpectedly succeeded!");
321   if (!dbus_g_error_has_name (error, "org.freedesktop.DBus.Tests.MyObject.Foo"))
322     lose ("ThrowError call returned unexpected error %s", dbus_g_error_get_name (error));
323
324   g_print ("ThrowError failed (as expected) returned error: %s\n", error->message);
325   g_clear_error (&error);
326
327   call = dbus_g_proxy_begin_call (proxy, "Uppercase",
328                                   G_TYPE_STRING, "foobar",
329                                   G_TYPE_INVALID);
330   error = NULL;
331   if (!dbus_g_proxy_end_call (proxy, call, &error,
332                               G_TYPE_STRING, &v_STRING_2,
333                               G_TYPE_INVALID))
334     lose_gerror ("Failed to complete Uppercase call", error);
335   if (strcmp ("FOOBAR", v_STRING_2) != 0)
336     lose ("Uppercase call returned unexpected string %s", v_STRING_2);
337   g_free (v_STRING_2);
338
339   v_STRING = "bazwhee";
340   v_UINT32 = 26;
341   v_DOUBLE = G_PI;
342   call = dbus_g_proxy_begin_call (proxy, "ManyArgs",
343                                   G_TYPE_UINT, 26,
344                                   G_TYPE_STRING, "bazwhee",
345                                   G_TYPE_DOUBLE, G_PI,
346                                   G_TYPE_INVALID);
347   error = NULL;
348   if (!dbus_g_proxy_end_call (proxy, call, &error,
349                               G_TYPE_DOUBLE, &v_DOUBLE_2,
350                               G_TYPE_STRING, &v_STRING_2,
351                               G_TYPE_INVALID))
352     lose_gerror ("Failed to complete ManyArgs call", error);
353   if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56)
354     lose ("ManyArgs call returned unexpected double value %f", v_DOUBLE_2);
355   if (strcmp ("BAZWHEE", v_STRING_2) != 0)
356     lose ("ManyArgs call returned unexpected string %s", v_STRING_2);
357   g_free (v_STRING_2);
358
359   if (!org_freedesktop_DBus_Tests_MyObject_do_nothing (proxy, &error))
360     lose_gerror ("Failed to complete (wrapped) DoNothing call", error);
361
362   if (!org_freedesktop_DBus_Tests_MyObject_increment (proxy, 42, &v_UINT32_2, &error))
363     lose_gerror ("Failed to complete (wrapped) Increment call", error);
364
365   if (v_UINT32_2 != 43)
366     lose ("(wrapped) increment call returned %d, should be 43", v_UINT32_2);
367
368   if (org_freedesktop_DBus_Tests_MyObject_throw_error (proxy, &error) != FALSE)
369     lose ("(wrapped) ThrowError call unexpectedly succeeded!");
370
371   g_print ("(wrapped) ThrowError failed (as expected) returned error: %s\n", error->message);
372   g_clear_error (&error);
373
374   if (!org_freedesktop_DBus_Tests_MyObject_uppercase (proxy, "foobar", &v_STRING_2, &error)) 
375     lose_gerror ("Failed to complete (wrapped) Uppercase call", error);
376   if (strcmp ("FOOBAR", v_STRING_2) != 0)
377     lose ("(wrapped) Uppercase call returned unexpected string %s", v_STRING_2);
378   g_free (v_STRING_2);
379
380   if (!org_freedesktop_DBus_Tests_MyObject_many_args (proxy, 26, "bazwhee", G_PI,
381                                                       &v_DOUBLE_2, &v_STRING_2, &error))
382     lose_gerror ("Failed to complete (wrapped) ManyArgs call", error);
383
384   if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56)
385     
386     lose ("(wrapped) ManyArgs call returned unexpected double value %f", v_DOUBLE_2);
387
388   if (strcmp ("BAZWHEE", v_STRING_2) != 0)
389     lose ("(wrapped) ManyArgs call returned unexpected string %s", v_STRING_2);
390   g_free (v_STRING_2);
391
392   {
393     guint32 arg0;
394     char *arg1;
395     gint32 arg2;
396     guint32 arg3;
397     guint32 arg4;
398     char *arg5;
399     
400     if (!org_freedesktop_DBus_Tests_MyObject_many_return (proxy, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &error))
401       lose_gerror ("Failed to complete (wrapped) ManyReturn call", error);
402
403     if (arg0 != 42)
404       lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg0);
405
406     if (strcmp ("42", arg1) != 0)
407       lose ("(wrapped) ManyReturn call returned unexpected string %s", arg1);
408     g_free (arg1);
409
410     if (arg2 != -67)
411       lose ("(wrapped) ManyReturn call returned unexpected gint32 value %u", arg2);
412
413     if (arg3 != 2)
414       lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg3);
415
416     if (arg4 != 26)
417       lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg4);
418
419     if (strcmp ("hello world", arg5))
420       lose ("(wrapped) ManyReturn call returned unexpected string %s", arg5);
421     g_free (arg5);
422   }
423
424   {
425     GValue value = {0, };
426
427     g_value_init (&value, G_TYPE_STRING);
428     g_value_set_string (&value, "foo");
429
430     if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
431                                                         &value,
432                                                         &v_STRING_2,
433                                                         &error))
434       lose_gerror ("Failed to complete (wrapped) stringify call", error);
435     if (strcmp ("foo", v_STRING_2) != 0)
436       lose ("(wrapped) stringify call returned unexpected string %s", v_STRING_2);
437     g_free (v_STRING_2);
438
439     g_value_unset (&value);
440     g_value_init (&value, G_TYPE_INT);
441     g_value_set_int (&value, 42);
442
443     if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
444                                                         &value,
445                                                         &v_STRING_2,
446                                                         &error))
447       lose_gerror ("Failed to complete (wrapped) stringify call 2", error);
448     if (strcmp ("42", v_STRING_2) != 0)
449       lose ("(wrapped) stringify call 2 returned unexpected string %s", v_STRING_2);
450     g_value_unset (&value);
451     g_free (v_STRING_2);
452
453     g_value_init (&value, G_TYPE_INT);
454     g_value_set_int (&value, 88);
455     if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
456                                                         &value,
457                                                         NULL,
458                                                         &error))
459       lose_gerror ("Failed to complete (wrapped) stringify call 3", error);
460     g_value_unset (&value);
461
462     if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy,
463                                                           "foo",
464                                                           &value,
465                                                           &error))
466       lose_gerror ("Failed to complete (wrapped) unstringify call", error);
467     if (!G_VALUE_HOLDS_STRING (&value))
468       lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value));
469     if (strcmp (g_value_get_string (&value), "foo"))
470       lose ("(wrapped) unstringify call returned unexpected string %s",
471             g_value_get_string (&value));
472         
473     g_value_unset (&value);
474
475     if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy,
476                                                           "10",
477                                                           &value,
478                                                           &error))
479       lose_gerror ("Failed to complete (wrapped) unstringify call", error);
480     if (!G_VALUE_HOLDS_INT (&value))
481       lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value));
482     if (g_value_get_int (&value) != 10)
483       lose ("(wrapped) unstringify call returned unexpected integer %d",
484             g_value_get_int (&value));
485
486     g_value_unset (&value);
487   }
488
489   {
490     GArray *array;
491     guint32 val;
492     guint32 arraylen;
493
494     array = g_array_new (FALSE, TRUE, sizeof (guint32));
495     val = 42;
496     g_array_append_val (array, val);
497     val = 69;
498     g_array_append_val (array, val);
499     val = 88;
500     g_array_append_val (array, val);
501     val = 26;
502     g_array_append_val (array, val);
503     val = 2;
504     g_array_append_val (array, val);
505
506     arraylen = 0;
507     if (!org_freedesktop_DBus_Tests_MyObject_recursive1 (proxy, array,
508                                                          &arraylen, &error))
509       lose_gerror ("Failed to complete (wrapped) recursive1 call", error);
510     if (arraylen != 5)
511       lose ("(wrapped) recursive1 call returned invalid length %u", arraylen);
512   }
513
514   {
515     GArray *array = NULL;
516     guint32 *arrayvals;
517     
518     if (!org_freedesktop_DBus_Tests_MyObject_recursive2 (proxy, 2, &array, &error))
519       lose_gerror ("Failed to complete (wrapped) Recursive2 call", error);
520
521     if (array == NULL)
522       lose ("(wrapped) Recursive2 call returned NULL");
523     if (array->len != 5)
524       lose ("(wrapped) Recursive2 call returned unexpected array length %u", array->len);
525
526     arrayvals = (guint32*) array->data;
527     if (arrayvals[0] != 42)
528       lose ("(wrapped) Recursive2 call returned unexpected value %d in position 0", arrayvals[0]);
529     if (arrayvals[1] != 26)
530       lose ("(wrapped) Recursive2 call returned unexpected value %d in position 1", arrayvals[1]);
531     if (arrayvals[4] != 2)
532       lose ("(wrapped) Recursive2 call returned unexpected value %d in position 4", arrayvals[4]);
533
534     g_array_free (array, TRUE);
535   }
536
537   {
538     char **strs;
539     char **strs_ret;
540
541     strs = g_new0 (char *, 4);
542     strs[0] = "hello";
543     strs[1] = "HellO";
544     strs[2] = "HELLO";
545     strs[3] = NULL;
546
547     strs_ret = NULL;
548     if (!org_freedesktop_DBus_Tests_MyObject_many_uppercase (proxy, strs, &strs_ret, &error)) 
549       lose_gerror ("Failed to complete (wrapped) ManyUppercase call", error);
550     g_assert (strs_ret != NULL);
551     if (strcmp ("HELLO", strs_ret[0]) != 0)
552       lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[0]);
553     if (strcmp ("HELLO", strs_ret[1]) != 0)
554       lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[1]);
555     if (strcmp ("HELLO", strs_ret[2]) != 0)
556       lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[2]);
557
558     g_strfreev (strs_ret);
559   }
560
561   {
562     GHashTable *table;
563     guint len;
564
565     table = g_hash_table_new (g_str_hash, g_str_equal);
566     g_hash_table_insert (table, "moooo", "b");
567     g_hash_table_insert (table, "xxx", "cow!");
568
569     len = 0;
570     if (!org_freedesktop_DBus_Tests_MyObject_str_hash_len (proxy, table, &len, &error))
571       lose_gerror ("(wrapped) StrHashLen call failed", error);
572     if (len != 13) 
573       lose ("(wrapped) StrHashLen returned unexpected length %u", len);
574     g_hash_table_destroy (table);
575   }
576
577   {
578     GHashTable *table;
579     const char *val;
580
581     if (!org_freedesktop_DBus_Tests_MyObject_get_hash (proxy, &table, &error))
582       lose_gerror ("(wrapped) GetHash call failed", error);
583     val = g_hash_table_lookup (table, "foo");
584     if (val == NULL || strcmp ("bar", val))
585       lose ("(wrapped) StrHashLen returned invalid value %s for key \"foo\"",
586             val ? val : "(null)");
587     val = g_hash_table_lookup (table, "baz");
588     if (val == NULL || strcmp ("whee", val))
589       lose ("(wrapped) StrHashLen returned invalid value %s for key \"whee\"",
590             val ? val : "(null)");
591     val = g_hash_table_lookup (table, "cow");
592     if (val == NULL || strcmp ("crack", val))
593       lose ("(wrapped) StrHashLen returned invalid value %s for key \"cow\"",
594             val ? val : "(null)");
595     if (g_hash_table_size (table) != 3)
596       lose ("(wrapped) StrHashLen returned unexpected hash size %u",
597             g_hash_table_size (table));
598
599     g_hash_table_destroy (table);
600   }
601
602   {
603     guint val;
604     DBusGProxy *ret_proxy;
605
606     if (!org_freedesktop_DBus_Tests_MyObject_objpath (proxy, proxy, &ret_proxy, &error))
607       lose_gerror ("Failed to complete (wrapped) Objpath call", error);
608     if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
609                 dbus_g_proxy_get_path (ret_proxy)) != 0)
610       lose ("(wrapped) objpath call returned unexpected proxy %s",
611             dbus_g_proxy_get_path (ret_proxy));
612
613     val = 1;
614     if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
615       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
616     if (val != 0)
617       lose ("(wrapped) GetVal returned invalid value %d", val);
618
619     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
620       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
621
622     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
623       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
624
625     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
626       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
627
628     if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
629       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
630     if (val != 3)
631       lose ("(wrapped) GetVal returned invalid value %d", val);
632
633     if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error))
634       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
635     if (val != 0)
636       lose ("(wrapped) GetVal returned invalid value %d", val);
637
638     if (!org_freedesktop_DBus_Tests_MyObject_increment_val (proxy, &error))
639       lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
640
641     if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error))
642       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
643     if (val != 1)
644       lose ("(wrapped) GetVal returned invalid value %d", val);
645
646     if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
647       lose_gerror ("Failed to complete (wrapped) GetVal call", error);
648     if (val != 3)
649       lose ("(wrapped) GetVal returned invalid value %d", val);
650
651     g_object_unref (G_OBJECT (ret_proxy));
652
653     ret_proxy = NULL;
654     if (!org_freedesktop_DBus_Tests_MyObject_objpath (proxy, proxy, &ret_proxy, &error))
655       lose_gerror ("Failed to complete (wrapped) Objpath call 2", error);
656     if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
657                 dbus_g_proxy_get_path (ret_proxy)) != 0)
658       lose ("(wrapped) objpath call 2 returned unexpected proxy %s",
659             dbus_g_proxy_get_path (ret_proxy));
660     {
661       const char *iface = dbus_g_proxy_get_interface (ret_proxy);
662       g_print ("returned proxy has interface \"%s\"\n",
663                iface ? iface : "(NULL)");
664     }
665
666     dbus_g_proxy_set_interface (ret_proxy, "org.freedesktop.DBus.Tests.FooObject");
667
668     val = 0;
669     if (!org_freedesktop_DBus_Tests_FooObject_get_value (ret_proxy, &val, &error))
670       lose_gerror ("Failed to complete (wrapped) GetValue call", error);
671     if (val != 3)
672       lose ("(wrapped) GetValue returned invalid value %d", val);
673   }
674
675   /* Signal handling tests */
676   
677   dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
678   
679   dbus_g_proxy_connect_signal (proxy, "Frobnicate",
680                                G_CALLBACK (frobnicate_signal_handler),
681                                NULL, NULL);
682   
683   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
684                           G_TYPE_INVALID, G_TYPE_INVALID))
685     lose_gerror ("Failed to complete EmitFrobnicate call", error);
686
687   
688   dbus_g_connection_flush (connection);
689   exit_timeout = g_timeout_add (5000, timed_exit, loop);
690   g_main_loop_run (loop);
691
692   if (n_times_frobnicate_received != 1)
693     lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
694
695   if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
696                           G_TYPE_INVALID, G_TYPE_INVALID))
697     lose_gerror ("Failed to complete EmitFrobnicate call", error);
698   
699   dbus_g_connection_flush (connection);
700   exit_timeout = g_timeout_add (5000, timed_exit, loop);
701   g_main_loop_run (loop);
702
703   if (n_times_frobnicate_received != 2)
704     lose ("Frobnicate signal received %d times, should have been 2", n_times_frobnicate_received);
705
706   g_object_unref (G_OBJECT (proxy));
707
708   proxy = dbus_g_proxy_new_for_name_owner (connection,
709                                            "org.freedesktop.DBus.TestSuiteGLibService",
710                                            "/org/freedesktop/DBus/Tests/MyTestObject",
711                                            "org.freedesktop.DBus.Tests.FooObject",
712                                            &error);
713   
714   if (proxy == NULL)
715     lose_gerror ("Failed to create proxy for name owner", error);
716
717   dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_INT_STRING, 
718                                      G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
719
720   dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_BOXED, 
721                                      G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
722
723   dbus_g_proxy_add_signal (proxy, "Sig0", G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
724   dbus_g_proxy_add_signal (proxy, "Sig1", G_TYPE_STRING, G_TYPE_VALUE);
725   
726   dbus_g_proxy_connect_signal (proxy, "Sig0",
727                                G_CALLBACK (sig0_signal_handler),
728                                NULL, NULL);
729   dbus_g_proxy_connect_signal (proxy, "Sig1",
730                                G_CALLBACK (sig1_signal_handler),
731                                NULL, NULL);
732
733   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
734
735   dbus_g_connection_flush (connection);
736   exit_timeout = g_timeout_add (5000, timed_exit, loop);
737   g_main_loop_run (loop);
738   exit_timeout = g_timeout_add (5000, timed_exit, loop);
739   g_main_loop_run (loop);
740
741   if (n_times_sig0_received != 1)
742     lose ("Sig0 signal received %d times, should have been 1", n_times_sig0_received);
743   if (n_times_sig1_received != 1)
744     lose ("Sig1 signal received %d times, should have been 1", n_times_sig1_received);
745
746   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
747   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
748
749   dbus_g_connection_flush (connection);
750   exit_timeout = g_timeout_add (5000, timed_exit, loop);
751   g_main_loop_run (loop);
752   exit_timeout = g_timeout_add (5000, timed_exit, loop);
753   g_main_loop_run (loop);
754   exit_timeout = g_timeout_add (5000, timed_exit, loop);
755   g_main_loop_run (loop);
756   exit_timeout = g_timeout_add (5000, timed_exit, loop);
757   g_main_loop_run (loop);
758
759   if (n_times_sig0_received != 3)
760     lose ("Sig0 signal received %d times, should have been 3", n_times_sig0_received);
761   if (n_times_sig1_received != 3)
762     lose ("Sig1 signal received %d times, should have been 3", n_times_sig1_received);
763   
764   g_object_unref (G_OBJECT (proxy));
765
766   proxy = dbus_g_proxy_new_for_name_owner (connection,
767                                            "org.freedesktop.DBus.TestSuiteGLibService",
768                                            "/org/freedesktop/DBus/Tests/MyTestObject",
769                                            "org.freedesktop.DBus.Introspectable",
770                                            &error);
771   
772   if (proxy == NULL)
773     lose_gerror ("Failed to create proxy for name owner", error);
774
775   call = dbus_g_proxy_begin_call (proxy, "Introspect",
776                                   G_TYPE_INVALID);
777   error = NULL;
778   if (!dbus_g_proxy_end_call (proxy, call, &error,
779                               G_TYPE_STRING, &v_STRING_2,
780                               G_TYPE_INVALID))
781     lose_gerror ("Failed to complete Introspect call", error);
782
783   /* Could just do strcmp(), but that seems more fragile */
784   {
785     NodeInfo *node;
786     GSList *elt;
787     gboolean found_introspectable;
788     gboolean found_properties;
789     gboolean found_myobject;
790     gboolean found_fooobject;
791
792     node = description_load_from_string (v_STRING_2, strlen (v_STRING_2), &error);
793     if (!node)
794       lose_gerror ("Failed to parse introspection data: %s", error);
795
796     found_introspectable = FALSE;
797     found_properties = FALSE;
798     found_myobject = FALSE;
799     found_fooobject = FALSE;
800     for (elt = node_info_get_interfaces (node); elt ; elt = elt->next)
801       {
802         InterfaceInfo *iface = elt->data;
803
804         if (!found_introspectable && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Introspectable") == 0)
805           found_introspectable = TRUE;
806         else if (!found_properties && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Properties") == 0)
807           found_properties = TRUE;
808         else if (!found_myobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.MyObject") == 0)
809           {
810             GSList *elt;
811             gboolean found_manyargs;
812             
813             found_myobject = TRUE;
814             
815             found_manyargs = FALSE;
816             for (elt = interface_info_get_methods (iface); elt; elt = elt->next)
817               {
818                 MethodInfo *method;
819
820                 method = elt->data;
821                 if (strcmp (method_info_get_name (method), "ManyArgs") == 0)
822                   {
823                     found_manyargs = TRUE;
824                     break;
825                   }
826               }
827             if (!found_manyargs)
828               lose ("Missing method org.freedesktop.DBus.Tests.MyObject.ManyArgs");
829           }
830         else if (!found_fooobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.FooObject") == 0)
831           found_fooobject = TRUE;
832         else
833           lose ("Unexpected or duplicate interface %s", interface_info_get_name (iface));
834       }
835
836     if (!(found_introspectable && found_myobject && found_properties))
837       lose ("Missing interface"); 
838   }
839   g_free (v_STRING_2);
840   
841   g_object_unref (G_OBJECT (driver));
842
843   g_print ("Successfully completed %s\n", argv[0]);
844   
845   return 0;
846 }