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);
1147 g_print ("Calling ProcessVariantOfArrayOfInts123\n");
1149 array = g_array_sized_new (FALSE, FALSE, sizeof(gint), 3);
1151 g_array_append_val (array, i);
1153 g_array_append_val (array, i);
1155 g_array_append_val (array, i);
1157 variant = g_new0 (GValue, 1);
1158 g_value_init (variant, dbus_g_type_get_collection ("GArray", G_TYPE_INT));
1159 g_value_set_boxed_take_ownership (variant, array);
1161 if (!dbus_g_proxy_call (proxy, "ProcessVariantOfArrayOfInts123", &error,
1162 G_TYPE_VALUE, variant,
1165 lose_gerror ("Failed to send a vairant of array of ints 1, 2 and 3!", error);
1167 g_value_unset (variant);
1169 /* Signal handling tests */
1171 g_print ("Testing signal handling\n");
1172 dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1174 dbus_g_proxy_connect_signal (proxy, "Frobnicate",
1175 G_CALLBACK (frobnicate_signal_handler),
1178 g_print ("Calling EmitFrobnicate\n");
1179 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1180 G_TYPE_INVALID, G_TYPE_INVALID))
1181 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1184 dbus_g_connection_flush (connection);
1185 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1186 g_main_loop_run (loop);
1188 if (n_times_frobnicate_received != 1)
1189 lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1191 g_print ("Calling EmitFrobnicate again\n");
1192 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1193 G_TYPE_INVALID, G_TYPE_INVALID))
1194 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1196 dbus_g_connection_flush (connection);
1197 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1198 g_main_loop_run (loop);
1200 if (n_times_frobnicate_received != 2)
1201 lose ("Frobnicate signal received %d times, should have been 2", n_times_frobnicate_received);
1203 g_object_unref (G_OBJECT (proxy));
1207 g_print ("Creating proxy for FooObject interface\n");
1208 proxy = dbus_g_proxy_new_for_name_owner (connection,
1209 "org.freedesktop.DBus.TestSuiteGLibService",
1210 "/org/freedesktop/DBus/Tests/MyTestObject",
1211 "org.freedesktop.DBus.Tests.FooObject",
1215 lose_gerror ("Failed to create proxy for name owner", error);
1217 dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_INT_STRING,
1218 G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
1220 dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_BOXED,
1221 G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
1223 dbus_g_proxy_add_signal (proxy, "Sig0", G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
1224 dbus_g_proxy_add_signal (proxy, "Sig1", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
1225 dbus_g_proxy_add_signal (proxy, "Sig2", DBUS_TYPE_G_STRING_STRING_HASHTABLE, G_TYPE_INVALID);
1227 dbus_g_proxy_connect_signal (proxy, "Sig0",
1228 G_CALLBACK (sig0_signal_handler),
1230 dbus_g_proxy_connect_signal (proxy, "Sig1",
1231 G_CALLBACK (sig1_signal_handler),
1233 dbus_g_proxy_connect_signal (proxy, "Sig2",
1234 G_CALLBACK (sig2_signal_handler),
1237 g_print ("Calling FooObject EmitSignals\n");
1238 dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1240 dbus_g_connection_flush (connection);
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);
1246 if (n_times_sig0_received != 1)
1247 lose ("Sig0 signal received %d times, should have been 1", n_times_sig0_received);
1248 if (n_times_sig1_received != 1)
1249 lose ("Sig1 signal received %d times, should have been 1", n_times_sig1_received);
1251 g_print ("Calling FooObject EmitSignals and EmitSignal2\n");
1252 dbus_g_proxy_call_no_reply (proxy, "EmitSignal2", G_TYPE_INVALID);
1253 dbus_g_connection_flush (connection);
1255 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1256 g_main_loop_run (loop);
1258 if (n_times_sig2_received != 1)
1259 lose ("Sig2 signal received %d times, should have been 1", n_times_sig2_received);
1261 g_print ("Calling FooObject EmitSignals two more times\n");
1262 dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1263 dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1265 dbus_g_connection_flush (connection);
1266 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1267 g_main_loop_run (loop);
1268 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1269 g_main_loop_run (loop);
1270 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1271 g_main_loop_run (loop);
1272 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1273 g_main_loop_run (loop);
1275 if (n_times_sig0_received != 3)
1276 lose ("Sig0 signal received %d times, should have been 3", n_times_sig0_received);
1277 if (n_times_sig1_received != 3)
1278 lose ("Sig1 signal received %d times, should have been 3", n_times_sig1_received);
1280 /* Terminate again */
1281 g_print ("Terminating service\n");
1282 await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService";
1283 dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID);
1285 proxy_destroyed = FALSE;
1286 proxy_destroy_and_nameowner = TRUE;
1287 proxy_destroy_and_nameowner_complete = FALSE;
1289 g_signal_connect (G_OBJECT (proxy),
1291 G_CALLBACK (proxy_destroyed_cb),
1294 dbus_g_connection_flush (connection);
1295 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1296 g_main_loop_run (loop);
1298 if (await_terminating_service != NULL)
1299 lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\"");
1300 if (!proxy_destroyed)
1301 lose ("Didn't get proxy_destroyed");
1302 g_print ("Proxy destroyed successfully\n");
1304 /* Don't need to unref, proxy was destroyed */
1308 /* Create a new proxy for the name; should not be associated */
1309 proxy = dbus_g_proxy_new_for_name (connection,
1310 "org.freedesktop.DBus.TestSuiteGLibService",
1311 "/org/freedesktop/DBus/Tests/MyTestObject",
1312 "org.freedesktop.DBus.Tests.MyObject");
1313 g_assert (proxy != NULL);
1315 proxy_destroyed = FALSE;
1316 proxy_destroy_and_nameowner = FALSE;
1317 proxy_destroy_and_nameowner_complete = FALSE;
1319 g_signal_connect (G_OBJECT (proxy),
1321 G_CALLBACK (proxy_destroyed_cb),
1324 if (!dbus_g_proxy_call (driver, "GetNameOwner", &error,
1326 "org.freedesktop.DBus.TestSuiteGLibService",
1331 if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NAME_HAS_NO_OWNER)
1332 g_print ("Got expected error \"org.freedesktop.DBus.Error.NameHasNoOwner\"\n");
1334 lose_gerror ("Unexpected error from GetNameOwner", error);
1336 lose ("GetNameOwner unexpectedly succeeded!");
1337 g_clear_error (&error);
1339 /* This will have the side-effect of activating the service, thus
1340 * causing a NameOwnerChanged, which should let our name proxy
1343 g_print ("Calling Uppercase for name proxy\n");
1344 if (!dbus_g_proxy_call (proxy, "Uppercase", &error,
1345 G_TYPE_STRING, "bazwhee",
1347 G_TYPE_STRING, &v_STRING_2,
1349 lose_gerror ("Failed to complete Uppercase call", error);
1350 g_free (v_STRING_2);
1352 if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION1"))
1353 g_usleep (8 * G_USEC_PER_SEC);
1355 dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1357 dbus_g_proxy_connect_signal (proxy, "Frobnicate",
1358 G_CALLBACK (frobnicate_signal_handler),
1361 g_print ("Calling EmitFrobnicate\n");
1362 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1363 G_TYPE_INVALID, G_TYPE_INVALID))
1364 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1366 n_times_frobnicate_received = 0;
1368 dbus_g_connection_flush (connection);
1369 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1370 g_main_loop_run (loop);
1372 if (n_times_frobnicate_received != 1)
1373 lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1375 /* Now terminate the service, then start it again (implicitly) and wait for signals */
1376 g_print ("Terminating service (2)\n");
1377 await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService";
1378 dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID);
1379 dbus_g_connection_flush (connection);
1380 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1381 g_main_loop_run (loop);
1382 if (await_terminating_service != NULL)
1383 lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\"");
1385 if (proxy_destroyed)
1386 lose ("Unexpectedly got proxy_destroyed!");
1388 n_times_frobnicate_received = 0;
1390 g_print ("Calling EmitFrobnicate (2)\n");
1391 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1392 G_TYPE_INVALID, G_TYPE_INVALID))
1393 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1395 if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION2"))
1396 g_usleep (8 * G_USEC_PER_SEC);
1398 dbus_g_connection_flush (connection);
1399 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1400 g_main_loop_run (loop);
1402 if (n_times_frobnicate_received != 1)
1403 lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1405 if (proxy_destroyed)
1406 lose ("Unexpectedly got proxy_destroyed!");
1408 /* Create another proxy for the name; should be associated immediately */
1409 proxy2 = dbus_g_proxy_new_for_name (connection,
1410 "org.freedesktop.DBus.TestSuiteGLibService",
1411 "/org/freedesktop/DBus/Tests/MyTestObject",
1412 "org.freedesktop.DBus.Tests.MyObject");
1413 g_assert (proxy2 != NULL);
1415 dbus_g_proxy_add_signal (proxy2, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1417 dbus_g_proxy_connect_signal (proxy2, "Frobnicate",
1418 G_CALLBACK (frobnicate_signal_handler_2),
1421 g_print ("Calling EmitFrobnicate (3)\n");
1422 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1423 G_TYPE_INVALID, G_TYPE_INVALID))
1424 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1426 dbus_g_connection_flush (connection);
1427 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1428 g_main_loop_run (loop);
1430 if (n_times_frobnicate_received != 2)
1431 lose ("Frobnicate signal received %d times for 1st proxy, should have been 2", n_times_frobnicate_received);
1432 if (n_times_frobnicate_received_2 != 1)
1433 lose ("Frobnicate signal received %d times for 2nd proxy, should have been 1", n_times_frobnicate_received_2);
1435 g_object_unref (G_OBJECT (proxy));
1436 g_object_unref (G_OBJECT (proxy2));
1440 /* Test introspection */
1441 proxy = dbus_g_proxy_new_for_name_owner (connection,
1442 "org.freedesktop.DBus.TestSuiteGLibService",
1443 "/org/freedesktop/DBus/Tests/MyTestObject",
1444 "org.freedesktop.DBus.Introspectable",
1447 lose_gerror ("Failed to create proxy for name owner", error);
1449 g_print ("Testing introspect\n");
1450 if (!dbus_g_proxy_call (proxy, "Introspect", &error,
1452 G_TYPE_STRING, &v_STRING_2,
1454 lose_gerror ("Failed to complete Introspect call", error);
1456 /* Could just do strcmp(), but that seems more fragile */
1460 gboolean found_introspectable;
1461 gboolean found_properties;
1462 gboolean found_myobject;
1463 gboolean found_fooobject;
1465 node = description_load_from_string (v_STRING_2, strlen (v_STRING_2), &error);
1467 lose_gerror ("Failed to parse introspection data: %s", error);
1469 found_introspectable = FALSE;
1470 found_properties = FALSE;
1471 found_myobject = FALSE;
1472 found_fooobject = FALSE;
1473 for (elt = node_info_get_interfaces (node); elt ; elt = elt->next)
1475 InterfaceInfo *iface = elt->data;
1477 if (!found_introspectable && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Introspectable") == 0)
1478 found_introspectable = TRUE;
1479 else if (!found_properties && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Properties") == 0)
1480 found_properties = TRUE;
1481 else if (!found_myobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.MyObject") == 0)
1484 gboolean found_manyargs;
1486 found_myobject = TRUE;
1488 found_manyargs = FALSE;
1489 for (elt = interface_info_get_methods (iface); elt; elt = elt->next)
1494 if (strcmp (method_info_get_name (method), "ManyArgs") == 0)
1496 found_manyargs = TRUE;
1500 if (!found_manyargs)
1501 lose ("Missing method org.freedesktop.DBus.Tests.MyObject.ManyArgs");
1503 else if (!found_fooobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.FooObject") == 0)
1504 found_fooobject = TRUE;
1506 lose ("Unexpected or duplicate interface %s", interface_info_get_name (iface));
1509 if (!(found_introspectable && found_myobject && found_properties))
1510 lose ("Missing interface");
1512 g_free (v_STRING_2);
1514 g_object_unref (G_OBJECT (driver));
1516 g_print ("Successfully completed %s\n", argv[0]);