1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 #include <dbus/dbus-glib.h>
6 #include "test-service-glib-bindings.h"
7 #include <glib/dbus-gidl.h>
8 #include <glib/dbus-gparser.h>
10 #include <glib-object.h>
11 #include "my-object-marshal.h"
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;
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;
30 unset_and_free_gvalue (gpointer val)
37 timed_exit (gpointer loop)
39 g_print ("timed exit!\n");
40 g_main_loop_quit (loop);
45 proxy_destroyed_cb (DBusGProxy *proxy, gpointer user_data)
47 proxy_destroyed = TRUE;
48 if (proxy_destroy_and_nameowner && !proxy_destroy_and_nameowner_complete && await_terminating_service == NULL)
50 g_source_remove (exit_timeout);
51 g_main_loop_quit (loop);
52 proxy_destroy_and_nameowner_complete = TRUE;
57 name_owner_changed (DBusGProxy *proxy,
59 const char *prev_owner,
60 const char *new_owner,
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))
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)
73 g_source_remove (exit_timeout);
74 g_main_loop_quit (loop);
75 proxy_destroy_and_nameowner_complete = TRUE;
77 else if (!proxy_destroy_and_nameowner)
79 g_source_remove (exit_timeout);
80 g_main_loop_quit (loop);
86 foo_signal_handler (DBusGProxy *proxy,
90 n_times_foo_received += 1;
92 g_print ("Got Foo signal\n");
94 g_main_loop_quit (loop);
95 g_source_remove (exit_timeout);
99 frobnicate_signal_handler (DBusGProxy *proxy,
103 n_times_frobnicate_received += 1;
105 g_assert (val == 42);
106 g_print ("Got Frobnicate signal\n");
108 g_main_loop_quit (loop);
109 g_source_remove (exit_timeout);
113 frobnicate_signal_handler_2 (DBusGProxy *proxy,
117 n_times_frobnicate_received_2 += 1;
119 g_assert (val == 42);
120 g_print ("Got Frobnicate signal (again)\n");
124 sig0_signal_handler (DBusGProxy *proxy,
130 n_times_sig0_received += 1;
132 g_assert (!strcmp (str0, "foo"));
134 g_assert (val == 22);
136 g_assert (!strcmp (str1, "moo"));
138 g_print ("Got Sig0 signal\n");
140 g_main_loop_quit (loop);
141 g_source_remove (exit_timeout);
145 sig1_signal_handler (DBusGProxy *proxy,
150 n_times_sig1_received += 1;
152 g_assert (!strcmp (str0, "baz"));
154 g_assert (G_VALUE_HOLDS_STRING (value));
156 g_assert (!strcmp (g_value_get_string (value), "bar"));
158 g_print ("Got Sig1 signal\n");
160 g_main_loop_quit (loop);
161 g_source_remove (exit_timeout);
165 sig2_signal_handler (DBusGProxy *proxy,
169 n_times_sig2_received += 1;
171 g_assert (g_hash_table_size (table) == 2);
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"));
178 g_print ("Got Sig2 signal\n");
180 g_main_loop_quit (loop);
181 g_source_remove (exit_timeout);
184 static DBusGProxyCall *echo_call;
185 static guint n_times_echo_cb_entered;
187 echo_received_cb (DBusGProxy *proxy,
188 DBusGProxyCall *call,
194 g_assert (call == echo_call);
195 g_assert (data == NULL);
199 n_times_echo_cb_entered++;
201 if (!dbus_g_proxy_end_call (proxy, call, &error,
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);
209 g_main_loop_quit (loop);
210 g_source_remove (exit_timeout);
214 increment_received_cb (DBusGProxy *proxy,
215 DBusGProxyCall *call,
222 g_assert (!strcmp (data, "moo"));
226 if (!dbus_g_proxy_end_call (proxy, call, &error,
229 lose_gerror ("Failed to complete (async) Increment call", error);
232 lose ("Increment call returned %d, should be 43", val);
234 g_print ("Async increment gave \"%d\"\n", val);
235 g_main_loop_quit (loop);
236 g_source_remove (exit_timeout);
240 increment_async_cb (DBusGProxy *proxy, guint val, GError *error, gpointer data)
243 lose_gerror ("Failed to complete (wrapped async) Increment call", error);
246 lose ("(wrapped async) Increment call gave unexpected data");
248 lose ("(wrapped async) Increment call returned %d, should be 43", val);
250 g_print ("(wrapped async) increment gave \"%d\"\n", val);
251 g_main_loop_quit (loop);
252 g_source_remove (exit_timeout);
257 lose (const char *str, ...)
261 va_start (args, str);
263 vfprintf (stderr, str, args);
264 fputc ('\n', stderr);
272 lose_gerror (const char *prefix, GError *error)
274 if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
275 lose ("%s (%s): %s", prefix, dbus_g_error_get_name (error),
278 lose ("%s: %s", prefix, error->message);
286 ctx = g_main_loop_get_context (loop);
288 while (g_main_context_pending (ctx))
289 g_main_context_iteration (ctx, FALSE);
293 main (int argc, char **argv)
295 DBusGConnection *connection;
303 DBusGProxyCall *call;
311 g_log_set_always_fatal (G_LOG_LEVEL_WARNING);
313 loop = g_main_loop_new (NULL, FALSE);
316 connection = dbus_g_bus_get (DBUS_BUS_SESSION,
318 if (connection == NULL)
319 lose_gerror ("Failed to open connection to bus", error);
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));
326 /* Create a proxy object for the "bus driver" */
328 driver = dbus_g_proxy_new_for_name (connection,
331 DBUS_INTERFACE_DBUS);
333 dbus_g_proxy_add_signal (driver,
340 dbus_g_proxy_connect_signal (driver,
342 G_CALLBACK (name_owner_changed),
345 /* Call ListNames method */
348 if (!dbus_g_proxy_call (driver, "ListNames", &error,
350 G_TYPE_STRV, &name_list,
352 lose_gerror ("Failed to complete ListNames call", error);
354 g_print ("Names on the message bus:\n");
356 name_list_len = g_strv_length (name_list);
357 while (i < name_list_len)
359 g_assert (name_list[i] != NULL);
360 g_print (" %s\n", name_list[i]);
363 g_assert (name_list[i] == NULL);
365 g_strfreev (name_list);
367 g_print ("calling ThisMethodDoesNotExist\n");
368 /* Test handling of unknown method */
369 if (dbus_g_proxy_call (driver, "ThisMethodDoesNotExist", &error,
371 "blah blah blah blah blah",
374 G_TYPE_INVALID, G_TYPE_INVALID) != FALSE)
375 lose ("Calling nonexistent method succeeded!");
377 g_print ("Got EXPECTED error from calling unknown method: %s\n", error->message);
378 g_clear_error (&error);
382 /* Activate a service */
383 g_print ("Activating echo service\n");
384 if (!dbus_g_proxy_call (driver, "StartServiceByName", &error,
386 "org.freedesktop.DBus.TestSuiteEchoService",
389 G_TYPE_UINT, &result,
391 lose_gerror ("Failed to complete Activate call", error);
393 g_print ("Starting echo service result = 0x%x\n", result);
395 /* Activate a service again */
396 g_print ("Activating echo service again\n");
397 if (!dbus_g_proxy_call (driver, "StartServiceByName", &error,
399 "org.freedesktop.DBus.TestSuiteEchoService",
403 G_TYPE_UINT, &result,
405 lose_gerror ("Failed to complete Activate call", error);
407 g_print ("Duplicate start of echo service = 0x%x\n", result);
409 /* Talk to the new service */
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",
419 lose_gerror ("Failed to create proxy for name owner", error);
423 g_print ("Calling Echo\n");
424 if (!dbus_g_proxy_call (proxy, "Echo", &error,
425 G_TYPE_STRING, "my string hello",
427 G_TYPE_STRING, &v_STRING_2,
429 lose_gerror ("Failed to complete Echo call", error);
431 g_print ("String echoed = \"%s\"\n", v_STRING_2);
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",
439 dbus_g_connection_flush (connection);
440 exit_timeout = g_timeout_add (5000, timed_exit, loop);
441 g_main_loop_run (loop);
443 /* Test oneway call and signal handling */
445 g_print ("Testing Foo emission\n");
446 dbus_g_proxy_add_signal (proxy, "Foo", G_TYPE_DOUBLE, G_TYPE_INVALID);
448 dbus_g_proxy_connect_signal (proxy, "Foo",
449 G_CALLBACK (foo_signal_handler),
452 dbus_g_proxy_call_no_reply (proxy, "EmitFoo",
455 dbus_g_connection_flush (connection);
456 exit_timeout = g_timeout_add (5000, timed_exit, loop);
457 g_main_loop_run (loop);
459 if (n_times_foo_received != 1)
460 lose ("Foo signal received %d times, should have been 1", n_times_foo_received);
462 /* Activate test servie */
463 g_print ("Activating TestSuiteGLibService\n");
465 if (!dbus_g_proxy_call (driver, "StartServiceByName", &error,
467 "org.freedesktop.DBus.TestSuiteGLibService",
471 G_TYPE_UINT, &result,
473 lose_gerror ("Failed to complete Activate call", error);
476 g_print ("TestSuiteGLibService activated\n");
478 if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION"))
479 g_usleep (8 * G_USEC_PER_SEC);
481 g_object_unref (G_OBJECT (proxy));
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",
492 lose_gerror ("Failed to create proxy for name owner", error);
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);
499 g_print ("Calling Increment\n");
501 if (!dbus_g_proxy_call (proxy, "Increment", &error,
504 G_TYPE_UINT, &v_UINT32_2,
506 lose_gerror ("Failed to complete Increment call", error);
507 if (v_UINT32_2 != 43)
508 lose ("Increment call returned %d, should be 43", v_UINT32_2);
511 g_print ("Calling Increment (async)\n");
512 call = dbus_g_proxy_begin_call (proxy, "Increment",
513 increment_received_cb, g_strdup ("moo"), g_free,
516 dbus_g_connection_flush (connection);
517 exit_timeout = g_timeout_add (5000, timed_exit, loop);
518 g_main_loop_run (loop);
520 g_print ("Calling IncrementRetval\n");
523 if (!dbus_g_proxy_call (proxy, "IncrementRetval", &error,
526 G_TYPE_UINT, &v_UINT32_2,
528 lose_gerror ("Failed to complete Increment call", error);
529 if (v_UINT32_2 != 43)
530 lose ("IncrementRetval call returned %d, should be 43", v_UINT32_2);
532 g_print ("Calling IncrementRetvalError\n");
535 if (!dbus_g_proxy_call (proxy, "IncrementRetvalError", &error,
538 G_TYPE_UINT, &v_UINT32_2,
540 lose_gerror ("Failed to complete Increment call", error);
542 lose ("IncrementRetval call returned %d, should be 6", v_UINT32_2);
544 g_print ("Calling ThrowError\n");
545 if (dbus_g_proxy_call (proxy, "ThrowError", &error,
546 G_TYPE_INVALID, G_TYPE_INVALID) != FALSE)
547 lose ("ThrowError call unexpectedly succeeded!");
549 if (!dbus_g_error_has_name (error, "org.freedesktop.DBus.Tests.MyObject.Foo"))
550 lose ("ThrowError call returned unexpected error \"%s\": %s", dbus_g_error_get_name (error),
553 g_print ("ThrowError failed (as expected) returned error: %s\n", error->message);
554 g_clear_error (&error);
556 g_print ("Calling IncrementRetvalError (for error)\n");
559 if (dbus_g_proxy_call (proxy, "IncrementRetvalError", &error,
562 G_TYPE_UINT, &v_UINT32_2,
563 G_TYPE_INVALID) != FALSE)
564 lose ("IncrementRetvalError call unexpectedly succeeded!");
565 if (!dbus_g_error_has_name (error, "org.freedesktop.DBus.Tests.MyObject.Foo"))
566 lose ("IncrementRetvalError call returned unexpected error \"%s\": %s", dbus_g_error_get_name (error), error->message);
567 g_clear_error (&error);
570 g_print ("Calling Uppercase\n");
571 if (!dbus_g_proxy_call (proxy, "Uppercase", &error,
572 G_TYPE_STRING, "foobar",
574 G_TYPE_STRING, &v_STRING_2,
576 lose_gerror ("Failed to complete Uppercase call", error);
577 if (strcmp ("FOOBAR", v_STRING_2) != 0)
578 lose ("Uppercase call returned unexpected string %s", v_STRING_2);
583 g_print ("Calling ManyArgs\n");
584 if (!dbus_g_proxy_call (proxy, "ManyArgs", &error,
586 G_TYPE_STRING, "bazwhee",
589 G_TYPE_DOUBLE, &v_DOUBLE_2,
590 G_TYPE_STRING, &v_STRING_2,
592 lose_gerror ("Failed to complete ManyArgs call", error);
593 if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56)
594 lose ("ManyArgs call returned unexpected double value %f", v_DOUBLE_2);
595 if (strcmp ("BAZWHEE", v_STRING_2) != 0)
596 lose ("ManyArgs call returned unexpected string %s", v_STRING_2);
599 g_print ("Calling (wrapped) do_nothing\n");
600 if (!org_freedesktop_DBus_Tests_MyObject_do_nothing (proxy, &error))
601 lose_gerror ("Failed to complete (wrapped) DoNothing call", error);
603 g_print ("Calling (wrapped) increment\n");
604 if (!org_freedesktop_DBus_Tests_MyObject_increment (proxy, 42, &v_UINT32_2, &error))
605 lose_gerror ("Failed to complete (wrapped) Increment call", error);
607 if (v_UINT32_2 != 43)
608 lose ("(wrapped) increment call returned %d, should be 43", v_UINT32_2);
610 g_print ("Calling (wrapped async) increment\n");
611 if (!org_freedesktop_DBus_Tests_MyObject_increment_async (proxy, 42, increment_async_cb, NULL))
612 lose_gerror ("Failed to complete (wrapped) Increment call", error);
613 dbus_g_connection_flush (connection);
614 exit_timeout = g_timeout_add (5000, timed_exit, loop);
615 g_main_loop_run (loop);
618 if (!org_freedesktop_DBus_Tests_MyObject_async_increment (proxy, 42, &v_UINT32_2, &error))
619 lose_gerror ("Failed to complete (wrapped) AsyncIncrement call", error);
621 if (v_UINT32_2 != 43)
622 lose ("(wrapped) async increment call returned %d, should be 43", v_UINT32_2);
624 g_print ("Calling (wrapped) throw_error\n");
625 if (org_freedesktop_DBus_Tests_MyObject_throw_error (proxy, &error) != FALSE)
626 lose ("(wrapped) ThrowError call unexpectedly succeeded!");
628 g_print ("(wrapped) ThrowError failed (as expected) returned error: %s\n", error->message);
629 g_clear_error (&error);
631 if (org_freedesktop_DBus_Tests_MyObject_async_throw_error (proxy, &error) != FALSE)
632 lose ("(wrapped) AsyncThrowError call unexpectedly succeeded!");
634 g_print ("(wrapped) AsyncThrowError failed (as expected) returned error: %s\n", error->message);
635 g_clear_error (&error);
637 g_print ("Calling (wrapped) uppercase\n");
638 if (!org_freedesktop_DBus_Tests_MyObject_uppercase (proxy, "foobar", &v_STRING_2, &error))
639 lose_gerror ("Failed to complete (wrapped) Uppercase call", error);
640 if (strcmp ("FOOBAR", v_STRING_2) != 0)
641 lose ("(wrapped) Uppercase call returned unexpected string %s", v_STRING_2);
644 g_print ("Calling (wrapped) many_args\n");
645 if (!org_freedesktop_DBus_Tests_MyObject_many_args (proxy, 26, "bazwhee", G_PI,
646 &v_DOUBLE_2, &v_STRING_2, &error))
647 lose_gerror ("Failed to complete (wrapped) ManyArgs call", error);
649 if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56)
651 lose ("(wrapped) ManyArgs call returned unexpected double value %f", v_DOUBLE_2);
653 if (strcmp ("BAZWHEE", v_STRING_2) != 0)
654 lose ("(wrapped) ManyArgs call returned unexpected string %s", v_STRING_2);
665 g_print ("Calling (wrapped) many_return\n");
666 if (!org_freedesktop_DBus_Tests_MyObject_many_return (proxy, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &error))
667 lose_gerror ("Failed to complete (wrapped) ManyReturn call", error);
670 lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg0);
672 if (strcmp ("42", arg1) != 0)
673 lose ("(wrapped) ManyReturn call returned unexpected string %s", arg1);
677 lose ("(wrapped) ManyReturn call returned unexpected gint32 value %u", arg2);
680 lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg3);
683 lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg4);
685 if (strcmp ("hello world", arg5))
686 lose ("(wrapped) ManyReturn call returned unexpected string %s", arg5);
693 GValue value = {0, };
695 g_value_init (&value, G_TYPE_STRING);
696 g_value_set_string (&value, "foo");
698 g_print ("Calling (wrapped) stringify, with string\n");
699 if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
703 lose_gerror ("Failed to complete (wrapped) stringify call", error);
704 if (strcmp ("foo", v_STRING_2) != 0)
705 lose ("(wrapped) stringify call returned unexpected string %s", v_STRING_2);
708 g_value_unset (&value);
709 g_value_init (&value, G_TYPE_INT);
710 g_value_set_int (&value, 42);
712 g_print ("Calling (wrapped) stringify, with int\n");
713 if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
717 lose_gerror ("Failed to complete (wrapped) stringify call 2", error);
718 if (strcmp ("42", v_STRING_2) != 0)
719 lose ("(wrapped) stringify call 2 returned unexpected string %s", v_STRING_2);
720 g_value_unset (&value);
723 g_value_init (&value, G_TYPE_INT);
724 g_value_set_int (&value, 88);
725 g_print ("Calling (wrapped) stringify, with another int\n");
726 if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
730 lose_gerror ("Failed to complete (wrapped) stringify call 3", error);
731 g_value_unset (&value);
733 g_print ("Calling (wrapped) unstringify, for string\n");
734 if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy,
738 lose_gerror ("Failed to complete (wrapped) unstringify call", error);
739 if (!G_VALUE_HOLDS_STRING (&value))
740 lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value));
741 if (strcmp (g_value_get_string (&value), "foo"))
742 lose ("(wrapped) unstringify call returned unexpected string %s",
743 g_value_get_string (&value));
745 g_value_unset (&value);
747 g_print ("Calling (wrapped) unstringify, for int\n");
748 if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy,
752 lose_gerror ("Failed to complete (wrapped) unstringify call", error);
753 if (!G_VALUE_HOLDS_INT (&value))
754 lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value));
755 if (g_value_get_int (&value) != 10)
756 lose ("(wrapped) unstringify call returned unexpected integer %d",
757 g_value_get_int (&value));
759 g_value_unset (&value);
769 array = g_array_new (FALSE, TRUE, sizeof (guint32));
771 g_array_append_val (array, val);
773 g_array_append_val (array, val);
775 g_array_append_val (array, val);
777 g_array_append_val (array, val);
779 g_array_append_val (array, val);
782 g_print ("Calling (wrapped) recursive1\n");
783 if (!org_freedesktop_DBus_Tests_MyObject_recursive1 (proxy, array,
785 lose_gerror ("Failed to complete (wrapped) recursive1 call", error);
787 lose ("(wrapped) recursive1 call returned invalid length %u", arraylen);
791 GArray *array = NULL;
794 g_print ("Calling (wrapped) recursive2\n");
795 if (!org_freedesktop_DBus_Tests_MyObject_recursive2 (proxy, 2, &array, &error))
796 lose_gerror ("Failed to complete (wrapped) Recursive2 call", error);
799 lose ("(wrapped) Recursive2 call returned NULL");
801 lose ("(wrapped) Recursive2 call returned unexpected array length %u", array->len);
803 arrayvals = (guint32*) array->data;
804 if (arrayvals[0] != 42)
805 lose ("(wrapped) Recursive2 call returned unexpected value %d in position 0", arrayvals[0]);
806 if (arrayvals[1] != 26)
807 lose ("(wrapped) Recursive2 call returned unexpected value %d in position 1", arrayvals[1]);
808 if (arrayvals[4] != 2)
809 lose ("(wrapped) Recursive2 call returned unexpected value %d in position 4", arrayvals[4]);
811 g_array_free (array, TRUE);
820 strs = g_new0 (char *, 4);
827 g_print ("Calling (wrapped) many_uppercase\n");
828 if (!org_freedesktop_DBus_Tests_MyObject_many_uppercase (proxy, strs, &strs_ret, &error))
829 lose_gerror ("Failed to complete (wrapped) ManyUppercase call", error);
830 g_assert (strs_ret != NULL);
831 if (strcmp ("HELLO", strs_ret[0]) != 0)
832 lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[0]);
833 if (strcmp ("HELLO", strs_ret[1]) != 0)
834 lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[1]);
835 if (strcmp ("HELLO", strs_ret[2]) != 0)
836 lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[2]);
839 g_strfreev (strs_ret);
846 table = g_hash_table_new (g_str_hash, g_str_equal);
847 g_hash_table_insert (table, "moooo", "b");
848 g_hash_table_insert (table, "xxx", "cow!");
851 g_print ("Calling (wrapped) str_hash_len\n");
852 if (!org_freedesktop_DBus_Tests_MyObject_str_hash_len (proxy, table, &len, &error))
853 lose_gerror ("(wrapped) StrHashLen call failed", error);
855 lose ("(wrapped) StrHashLen returned unexpected length %u", len);
856 g_hash_table_destroy (table);
863 g_print ("Calling (wrapped) get_hash\n");
864 if (!org_freedesktop_DBus_Tests_MyObject_get_hash (proxy, &table, &error))
865 lose_gerror ("(wrapped) GetHash call failed", error);
866 val = g_hash_table_lookup (table, "foo");
867 if (val == NULL || strcmp ("bar", val))
868 lose ("(wrapped) StrHashLen returned invalid value %s for key \"foo\"",
869 val ? val : "(null)");
870 val = g_hash_table_lookup (table, "baz");
871 if (val == NULL || strcmp ("whee", val))
872 lose ("(wrapped) StrHashLen returned invalid value %s for key \"whee\"",
873 val ? val : "(null)");
874 val = g_hash_table_lookup (table, "cow");
875 if (val == NULL || strcmp ("crack", val))
876 lose ("(wrapped) StrHashLen returned invalid value %s for key \"cow\"",
877 val ? val : "(null)");
878 if (g_hash_table_size (table) != 3)
879 lose ("(wrapped) StrHashLen returned unexpected hash size %u",
880 g_hash_table_size (table));
882 g_hash_table_destroy (table);
889 GValueArray *vals_ret;
892 vals = g_value_array_new (3);
894 g_value_array_append (vals, NULL);
895 g_value_init (g_value_array_get_nth (vals, vals->n_values - 1), G_TYPE_STRING);
896 g_value_set_string (g_value_array_get_nth (vals, 0), "foo");
898 g_value_array_append (vals, NULL);
899 g_value_init (g_value_array_get_nth (vals, vals->n_values - 1), G_TYPE_UINT);
900 g_value_set_uint (g_value_array_get_nth (vals, vals->n_values - 1), 42);
902 g_value_array_append (vals, NULL);
903 g_value_init (g_value_array_get_nth (vals, vals->n_values - 1), G_TYPE_VALUE);
904 val = g_new0 (GValue, 1);
905 g_value_init (val, G_TYPE_UCHAR);
906 g_value_set_uchar (val, '!');
907 g_value_set_boxed (g_value_array_get_nth (vals, vals->n_values - 1), val);
910 g_print ("Calling SendCar\n");
911 if (!dbus_g_proxy_call (proxy, "SendCar", &error,
912 G_TYPE_VALUE_ARRAY, vals,
914 G_TYPE_VALUE_ARRAY, &vals_ret,
916 lose_gerror ("Failed to complete SendCar call", error);
918 g_assert (vals_ret != NULL);
919 g_assert (vals_ret->n_values == 2);
921 g_assert (G_VALUE_HOLDS_UINT (g_value_array_get_nth (vals_ret, 0)));
922 g_assert (g_value_get_uint (g_value_array_get_nth (vals_ret, 0)) == 43);
924 g_assert (G_VALUE_TYPE (g_value_array_get_nth (vals_ret, 1)) == DBUS_TYPE_G_OBJECT_PATH);
925 g_assert (!strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
926 g_value_get_boxed (g_value_array_get_nth (vals_ret, 1))));
928 g_value_array_free (vals);
929 g_value_array_free (vals_ret);
935 GHashTable *ret_table;
937 table = g_hash_table_new_full (g_str_hash, g_str_equal,
938 g_free, unset_and_free_gvalue);
940 val = g_new0 (GValue, 1);
941 g_value_init (val, G_TYPE_UINT);
942 g_value_set_uint (val, 42);
943 g_hash_table_insert (table, g_strdup ("foo"), val);
945 val = g_new0 (GValue, 1);
946 g_value_init (val, G_TYPE_STRING);
947 g_value_set_string (val, "hello");
948 g_hash_table_insert (table, g_strdup ("bar"), val);
951 g_print ("Calling ManyStringify\n");
952 if (!dbus_g_proxy_call (proxy, "ManyStringify", &error,
953 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), table,
955 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &ret_table,
957 lose_gerror ("Failed to complete ManyStringify call", error);
959 g_assert (ret_table != NULL);
960 g_assert (g_hash_table_size (ret_table) == 2);
962 val = g_hash_table_lookup (ret_table, "foo");
963 g_assert (val != NULL);
964 g_assert (G_VALUE_HOLDS_STRING (val));
965 g_assert (!strcmp ("42", g_value_get_string (val)));
967 val = g_hash_table_lookup (ret_table, "bar");
968 g_assert (val != NULL);
969 g_assert (G_VALUE_HOLDS_STRING (val));
970 g_assert (!strcmp ("hello", g_value_get_string (val)));
972 g_hash_table_destroy (table);
973 g_hash_table_destroy (ret_table);
978 GPtrArray *out_array;
982 in_array = g_ptr_array_new ();
984 strs = g_new0 (char *, 3);
988 g_ptr_array_add (in_array, strs);
990 strs = g_new0 (char *, 4);
995 g_ptr_array_add (in_array, strs);
998 g_print ("Calling RecArrays\n");
999 if (!dbus_g_proxy_call (proxy, "RecArrays", &error,
1000 dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRV), in_array,
1002 dbus_g_type_get_collection ("GPtrArray",
1003 dbus_g_type_get_collection ("GPtrArray",
1004 G_TYPE_UINT)), &out_array,
1006 lose_gerror ("Failed to complete RecArrays call", error);
1007 g_free (g_ptr_array_index (in_array, 0));
1008 g_free (g_ptr_array_index (in_array, 1));
1010 g_assert (out_array);
1011 g_assert (out_array->len == 2);
1012 uints = g_ptr_array_index (out_array, 0);
1014 g_assert (uints->len == 3);
1015 g_assert (g_array_index (uints, guint, 0) == 10);
1016 g_assert (g_array_index (uints, guint, 1) == 42);
1017 g_assert (g_array_index (uints, guint, 2) == 27);
1018 g_array_free (uints, TRUE);
1019 uints = g_ptr_array_index (out_array, 1);
1021 g_assert (uints->len == 1);
1022 g_assert (g_array_index (uints, guint, 0) == 30);
1023 g_array_free (uints, TRUE);
1024 g_ptr_array_free (out_array, TRUE);
1030 DBusGProxy *ret_proxy;
1032 g_print ("Calling (wrapped) objpath\n");
1033 if (!dbus_g_proxy_call (proxy, "Objpath", &error,
1034 DBUS_TYPE_G_PROXY, proxy, G_TYPE_INVALID,
1035 DBUS_TYPE_G_PROXY, &ret_proxy, G_TYPE_INVALID))
1036 lose_gerror ("Failed to complete Objpath call", error);
1037 if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
1038 dbus_g_proxy_get_path (ret_proxy)) != 0)
1039 lose ("(wrapped) objpath call returned unexpected proxy %s",
1040 dbus_g_proxy_get_path (ret_proxy));
1042 g_print ("Doing get/increment val tests\n");
1044 if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
1045 lose_gerror ("Failed to complete (wrapped) GetVal call", error);
1047 lose ("(wrapped) GetVal returned invalid value %d", val);
1049 if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
1050 lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
1052 if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
1053 lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
1055 if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
1056 lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
1058 if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
1059 lose_gerror ("Failed to complete (wrapped) GetVal call", error);
1061 lose ("(wrapped) GetVal returned invalid value %d", val);
1063 if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error))
1064 lose_gerror ("Failed to complete (wrapped) GetVal call", error);
1066 lose ("(wrapped) GetVal returned invalid value %d", val);
1068 if (!org_freedesktop_DBus_Tests_MyObject_increment_val (proxy, &error))
1069 lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
1071 if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error))
1072 lose_gerror ("Failed to complete (wrapped) GetVal call", error);
1074 lose ("(wrapped) GetVal returned invalid value %d", val);
1076 if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
1077 lose_gerror ("Failed to complete (wrapped) GetVal call", error);
1079 lose ("(wrapped) GetVal returned invalid value %d", val);
1081 g_object_unref (G_OBJECT (ret_proxy));
1083 g_print ("Calling objpath again\n");
1086 if (!dbus_g_proxy_call (proxy, "Objpath", &error,
1087 DBUS_TYPE_G_OBJECT_PATH,
1088 dbus_g_proxy_get_path (proxy),
1090 DBUS_TYPE_G_OBJECT_PATH,
1093 lose_gerror ("Failed to complete Objpath call 2", error);
1094 if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2", ret_path) != 0)
1095 lose ("Objpath call 2 returned unexpected path %s",
1098 ret_proxy = dbus_g_proxy_new_for_name_owner (connection,
1099 "org.freedesktop.DBus.TestSuiteGLibService",
1101 "org.freedesktop.DBus.Tests.FooObject",
1106 if (!org_freedesktop_DBus_Tests_FooObject_get_value (ret_proxy, &val, &error))
1107 lose_gerror ("Failed to complete (wrapped) GetValue call", error);
1109 lose ("(wrapped) GetValue returned invalid value %d", val);
1118 g_print ("Calling GetObjs\n");
1120 if (!dbus_g_proxy_call (proxy, "GetObjs", &error, G_TYPE_INVALID,
1121 dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH),
1124 lose_gerror ("Failed to complete GetObjs call", error);
1126 lose ("GetObjs call returned unexpected number of objects %d, expected 2",
1129 if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject",
1130 g_ptr_array_index (objs, 0)) != 0)
1131 lose ("GetObjs call returned unexpected path \"%s\" in position 0; expected /org/freedesktop/DBus/Tests/MyTestObject", (char*) g_ptr_array_index (objs, 0));
1133 if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
1134 g_ptr_array_index (objs, 1)) != 0)
1135 lose ("GetObjs call returned unexpected path \"%s\" in position 1; expected /org/freedesktop/DBus/Tests/MyTestObject2", (char*) g_ptr_array_index (objs, 1));
1137 for (i = 0; i < objs->len; i++)
1138 g_free (g_ptr_array_index (objs, i));
1139 g_ptr_array_free (objs, TRUE);
1142 /* Signal handling tests */
1144 g_print ("Testing signal handling\n");
1145 dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1147 dbus_g_proxy_connect_signal (proxy, "Frobnicate",
1148 G_CALLBACK (frobnicate_signal_handler),
1151 g_print ("Calling EmitFrobnicate\n");
1152 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1153 G_TYPE_INVALID, G_TYPE_INVALID))
1154 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1157 dbus_g_connection_flush (connection);
1158 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1159 g_main_loop_run (loop);
1161 if (n_times_frobnicate_received != 1)
1162 lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1164 g_print ("Calling EmitFrobnicate again\n");
1165 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1166 G_TYPE_INVALID, G_TYPE_INVALID))
1167 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1169 dbus_g_connection_flush (connection);
1170 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1171 g_main_loop_run (loop);
1173 if (n_times_frobnicate_received != 2)
1174 lose ("Frobnicate signal received %d times, should have been 2", n_times_frobnicate_received);
1176 g_object_unref (G_OBJECT (proxy));
1180 g_print ("Creating proxy for FooObject interface\n");
1181 proxy = dbus_g_proxy_new_for_name_owner (connection,
1182 "org.freedesktop.DBus.TestSuiteGLibService",
1183 "/org/freedesktop/DBus/Tests/MyTestObject",
1184 "org.freedesktop.DBus.Tests.FooObject",
1188 lose_gerror ("Failed to create proxy for name owner", error);
1190 dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_INT_STRING,
1191 G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
1193 dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_BOXED,
1194 G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
1196 dbus_g_proxy_add_signal (proxy, "Sig0", G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
1197 dbus_g_proxy_add_signal (proxy, "Sig1", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
1198 dbus_g_proxy_add_signal (proxy, "Sig2", DBUS_TYPE_G_STRING_STRING_HASHTABLE, G_TYPE_INVALID);
1200 dbus_g_proxy_connect_signal (proxy, "Sig0",
1201 G_CALLBACK (sig0_signal_handler),
1203 dbus_g_proxy_connect_signal (proxy, "Sig1",
1204 G_CALLBACK (sig1_signal_handler),
1206 dbus_g_proxy_connect_signal (proxy, "Sig2",
1207 G_CALLBACK (sig2_signal_handler),
1210 g_print ("Calling FooObject EmitSignals\n");
1211 dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1213 dbus_g_connection_flush (connection);
1214 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1215 g_main_loop_run (loop);
1216 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1217 g_main_loop_run (loop);
1219 if (n_times_sig0_received != 1)
1220 lose ("Sig0 signal received %d times, should have been 1", n_times_sig0_received);
1221 if (n_times_sig1_received != 1)
1222 lose ("Sig1 signal received %d times, should have been 1", n_times_sig1_received);
1224 g_print ("Calling FooObject EmitSignals and EmitSignal2\n");
1225 dbus_g_proxy_call_no_reply (proxy, "EmitSignal2", G_TYPE_INVALID);
1226 dbus_g_connection_flush (connection);
1228 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1229 g_main_loop_run (loop);
1231 if (n_times_sig2_received != 1)
1232 lose ("Sig2 signal received %d times, should have been 1", n_times_sig2_received);
1234 g_print ("Calling FooObject EmitSignals two more times\n");
1235 dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1236 dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1238 dbus_g_connection_flush (connection);
1239 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1240 g_main_loop_run (loop);
1241 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1242 g_main_loop_run (loop);
1243 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1244 g_main_loop_run (loop);
1245 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1246 g_main_loop_run (loop);
1248 if (n_times_sig0_received != 3)
1249 lose ("Sig0 signal received %d times, should have been 3", n_times_sig0_received);
1250 if (n_times_sig1_received != 3)
1251 lose ("Sig1 signal received %d times, should have been 3", n_times_sig1_received);
1253 /* Terminate again */
1254 g_print ("Terminating service\n");
1255 await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService";
1256 dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID);
1258 proxy_destroyed = FALSE;
1259 proxy_destroy_and_nameowner = TRUE;
1260 proxy_destroy_and_nameowner_complete = FALSE;
1262 g_signal_connect (G_OBJECT (proxy),
1264 G_CALLBACK (proxy_destroyed_cb),
1267 dbus_g_connection_flush (connection);
1268 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1269 g_main_loop_run (loop);
1271 if (await_terminating_service != NULL)
1272 lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\"");
1273 if (!proxy_destroyed)
1274 lose ("Didn't get proxy_destroyed");
1275 g_print ("Proxy destroyed successfully\n");
1277 /* Don't need to unref, proxy was destroyed */
1281 /* Create a new proxy for the name; should not be associated */
1282 proxy = dbus_g_proxy_new_for_name (connection,
1283 "org.freedesktop.DBus.TestSuiteGLibService",
1284 "/org/freedesktop/DBus/Tests/MyTestObject",
1285 "org.freedesktop.DBus.Tests.MyObject");
1286 g_assert (proxy != NULL);
1288 proxy_destroyed = FALSE;
1289 proxy_destroy_and_nameowner = FALSE;
1290 proxy_destroy_and_nameowner_complete = FALSE;
1292 g_signal_connect (G_OBJECT (proxy),
1294 G_CALLBACK (proxy_destroyed_cb),
1297 if (!dbus_g_proxy_call (driver, "GetNameOwner", &error,
1299 "org.freedesktop.DBus.TestSuiteGLibService",
1304 if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NAME_HAS_NO_OWNER)
1305 g_print ("Got expected error \"org.freedesktop.DBus.Error.NameHasNoOwner\"\n");
1307 lose_gerror ("Unexpected error from GetNameOwner", error);
1309 lose ("GetNameOwner unexpectedly succeeded!");
1310 g_clear_error (&error);
1312 /* This will have the side-effect of activating the service, thus
1313 * causing a NameOwnerChanged, which should let our name proxy
1316 g_print ("Calling Uppercase for name proxy\n");
1317 if (!dbus_g_proxy_call (proxy, "Uppercase", &error,
1318 G_TYPE_STRING, "bazwhee",
1320 G_TYPE_STRING, &v_STRING_2,
1322 lose_gerror ("Failed to complete Uppercase call", error);
1323 g_free (v_STRING_2);
1325 if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION1"))
1326 g_usleep (8 * G_USEC_PER_SEC);
1328 dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1330 dbus_g_proxy_connect_signal (proxy, "Frobnicate",
1331 G_CALLBACK (frobnicate_signal_handler),
1334 g_print ("Calling EmitFrobnicate\n");
1335 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1336 G_TYPE_INVALID, G_TYPE_INVALID))
1337 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1339 n_times_frobnicate_received = 0;
1341 dbus_g_connection_flush (connection);
1342 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1343 g_main_loop_run (loop);
1345 if (n_times_frobnicate_received != 1)
1346 lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1348 /* Now terminate the service, then start it again (implicitly) and wait for signals */
1349 g_print ("Terminating service (2)\n");
1350 await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService";
1351 dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID);
1352 dbus_g_connection_flush (connection);
1353 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1354 g_main_loop_run (loop);
1355 if (await_terminating_service != NULL)
1356 lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\"");
1358 if (proxy_destroyed)
1359 lose ("Unexpectedly got proxy_destroyed!");
1361 n_times_frobnicate_received = 0;
1363 g_print ("Calling EmitFrobnicate (2)\n");
1364 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1365 G_TYPE_INVALID, G_TYPE_INVALID))
1366 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1368 if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION2"))
1369 g_usleep (8 * G_USEC_PER_SEC);
1371 dbus_g_connection_flush (connection);
1372 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1373 g_main_loop_run (loop);
1375 if (n_times_frobnicate_received != 1)
1376 lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1378 if (proxy_destroyed)
1379 lose ("Unexpectedly got proxy_destroyed!");
1381 /* Create another proxy for the name; should be associated immediately */
1382 proxy2 = dbus_g_proxy_new_for_name (connection,
1383 "org.freedesktop.DBus.TestSuiteGLibService",
1384 "/org/freedesktop/DBus/Tests/MyTestObject",
1385 "org.freedesktop.DBus.Tests.MyObject");
1386 g_assert (proxy2 != NULL);
1388 dbus_g_proxy_add_signal (proxy2, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1390 dbus_g_proxy_connect_signal (proxy2, "Frobnicate",
1391 G_CALLBACK (frobnicate_signal_handler_2),
1394 g_print ("Calling EmitFrobnicate (3)\n");
1395 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1396 G_TYPE_INVALID, G_TYPE_INVALID))
1397 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1399 dbus_g_connection_flush (connection);
1400 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1401 g_main_loop_run (loop);
1403 if (n_times_frobnicate_received != 2)
1404 lose ("Frobnicate signal received %d times for 1st proxy, should have been 2", n_times_frobnicate_received);
1405 if (n_times_frobnicate_received_2 != 1)
1406 lose ("Frobnicate signal received %d times for 2nd proxy, should have been 1", n_times_frobnicate_received_2);
1408 g_object_unref (G_OBJECT (proxy));
1409 g_object_unref (G_OBJECT (proxy2));
1413 /* Test introspection */
1414 proxy = dbus_g_proxy_new_for_name_owner (connection,
1415 "org.freedesktop.DBus.TestSuiteGLibService",
1416 "/org/freedesktop/DBus/Tests/MyTestObject",
1417 "org.freedesktop.DBus.Introspectable",
1420 lose_gerror ("Failed to create proxy for name owner", error);
1422 g_print ("Testing introspect\n");
1423 if (!dbus_g_proxy_call (proxy, "Introspect", &error,
1425 G_TYPE_STRING, &v_STRING_2,
1427 lose_gerror ("Failed to complete Introspect call", error);
1429 /* Could just do strcmp(), but that seems more fragile */
1433 gboolean found_introspectable;
1434 gboolean found_properties;
1435 gboolean found_myobject;
1436 gboolean found_fooobject;
1438 node = description_load_from_string (v_STRING_2, strlen (v_STRING_2), &error);
1440 lose_gerror ("Failed to parse introspection data: %s", error);
1442 found_introspectable = FALSE;
1443 found_properties = FALSE;
1444 found_myobject = FALSE;
1445 found_fooobject = FALSE;
1446 for (elt = node_info_get_interfaces (node); elt ; elt = elt->next)
1448 InterfaceInfo *iface = elt->data;
1450 if (!found_introspectable && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Introspectable") == 0)
1451 found_introspectable = TRUE;
1452 else if (!found_properties && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Properties") == 0)
1453 found_properties = TRUE;
1454 else if (!found_myobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.MyObject") == 0)
1457 gboolean found_manyargs;
1459 found_myobject = TRUE;
1461 found_manyargs = FALSE;
1462 for (elt = interface_info_get_methods (iface); elt; elt = elt->next)
1467 if (strcmp (method_info_get_name (method), "ManyArgs") == 0)
1469 found_manyargs = TRUE;
1473 if (!found_manyargs)
1474 lose ("Missing method org.freedesktop.DBus.Tests.MyObject.ManyArgs");
1476 else if (!found_fooobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.FooObject") == 0)
1477 found_fooobject = TRUE;
1479 lose ("Unexpected or duplicate interface %s", interface_info_get_name (iface));
1482 if (!(found_introspectable && found_myobject && found_properties))
1483 lose ("Missing interface");
1485 g_free (v_STRING_2);
1487 g_object_unref (G_OBJECT (driver));
1489 g_print ("Successfully completed %s\n", argv[0]);