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