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,
221 g_assert (!strcmp (data, "moo"));
224 if (!dbus_g_proxy_end_call (proxy, call, &error,
227 lose_gerror ("Failed to complete (async) Increment call", error);
230 lose ("Increment call returned %d, should be 43", val);
232 g_print ("Async increment gave \"%d\"\n", val);
233 g_main_loop_quit (loop);
234 g_source_remove (exit_timeout);
238 increment_async_cb (DBusGProxy *proxy, guint val, GError *error, gpointer data)
241 lose_gerror ("Failed to complete (wrapped async) Increment call", error);
244 lose ("(wrapped async) Increment call gave unexpected data");
246 lose ("(wrapped async) Increment call returned %d, should be 43", val);
248 g_print ("(wrapped async) increment gave \"%d\"\n", val);
249 g_main_loop_quit (loop);
250 g_source_remove (exit_timeout);
255 lose (const char *str, ...)
259 va_start (args, str);
261 vfprintf (stderr, str, args);
262 fputc ('\n', stderr);
270 lose_gerror (const char *prefix, GError *error)
272 if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
273 lose ("%s (%s): %s", prefix, dbus_g_error_get_name (error),
276 lose ("%s: %s", prefix, error->message);
284 ctx = g_main_loop_get_context (loop);
286 while (g_main_context_pending (ctx))
287 g_main_context_iteration (ctx, FALSE);
291 main (int argc, char **argv)
293 DBusGConnection *connection;
301 DBusGProxyCall *call;
309 g_log_set_always_fatal (G_LOG_LEVEL_WARNING);
311 loop = g_main_loop_new (NULL, FALSE);
314 connection = dbus_g_bus_get (DBUS_BUS_SESSION,
316 if (connection == NULL)
317 lose_gerror ("Failed to open connection to bus", error);
319 /* should always get the same one */
320 g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
321 g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
322 g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
324 /* Create a proxy object for the "bus driver" */
326 driver = dbus_g_proxy_new_for_name (connection,
329 DBUS_INTERFACE_DBUS);
331 dbus_g_proxy_add_signal (driver,
338 dbus_g_proxy_connect_signal (driver,
340 G_CALLBACK (name_owner_changed),
343 /* Call ListNames method */
346 if (!dbus_g_proxy_call (driver, "ListNames", &error,
348 G_TYPE_STRV, &name_list,
350 lose_gerror ("Failed to complete ListNames call", error);
352 g_print ("Names on the message bus:\n");
354 name_list_len = g_strv_length (name_list);
355 while (i < name_list_len)
357 g_assert (name_list[i] != NULL);
358 g_print (" %s\n", name_list[i]);
361 g_assert (name_list[i] == NULL);
363 g_strfreev (name_list);
365 g_print ("calling ThisMethodDoesNotExist\n");
366 /* Test handling of unknown method */
367 if (dbus_g_proxy_call (driver, "ThisMethodDoesNotExist", &error,
369 "blah blah blah blah blah",
372 G_TYPE_INVALID, G_TYPE_INVALID) != FALSE)
373 lose ("Calling nonexistent method succeeded!");
375 g_print ("Got EXPECTED error from calling unknown method: %s\n", error->message);
376 g_clear_error (&error);
380 /* Activate a service */
381 g_print ("Activating echo service\n");
382 if (!dbus_g_proxy_call (driver, "StartServiceByName", &error,
384 "org.freedesktop.DBus.TestSuiteEchoService",
387 G_TYPE_UINT, &result,
389 lose_gerror ("Failed to complete Activate call", error);
391 g_print ("Starting echo service result = 0x%x\n", result);
393 /* Activate a service again */
394 g_print ("Activating echo service again\n");
395 if (!dbus_g_proxy_call (driver, "StartServiceByName", &error,
397 "org.freedesktop.DBus.TestSuiteEchoService",
401 G_TYPE_UINT, &result,
403 lose_gerror ("Failed to complete Activate call", error);
405 g_print ("Duplicate start of echo service = 0x%x\n", result);
407 /* Talk to the new service */
409 g_print ("Creating proxy for echo service\n");
410 proxy = dbus_g_proxy_new_for_name_owner (connection,
411 "org.freedesktop.DBus.TestSuiteEchoService",
412 "/org/freedesktop/TestSuite",
413 "org.freedesktop.TestSuite",
417 lose_gerror ("Failed to create proxy for name owner", error);
421 g_print ("Calling Echo\n");
422 if (!dbus_g_proxy_call (proxy, "Echo", &error,
423 G_TYPE_STRING, "my string hello",
425 G_TYPE_STRING, &v_STRING_2,
427 lose_gerror ("Failed to complete Echo call", error);
429 g_print ("String echoed = \"%s\"\n", v_STRING_2);
432 g_print ("Calling Echo (async)\n");
433 echo_call = dbus_g_proxy_begin_call (proxy, "Echo",
434 echo_received_cb, NULL, NULL,
435 G_TYPE_STRING, "my string hello",
437 dbus_g_connection_flush (connection);
438 exit_timeout = g_timeout_add (5000, timed_exit, loop);
439 g_main_loop_run (loop);
441 /* Test oneway call and signal handling */
443 g_print ("Testing Foo emission\n");
444 dbus_g_proxy_add_signal (proxy, "Foo", G_TYPE_DOUBLE, G_TYPE_INVALID);
446 dbus_g_proxy_connect_signal (proxy, "Foo",
447 G_CALLBACK (foo_signal_handler),
450 dbus_g_proxy_call_no_reply (proxy, "EmitFoo",
453 dbus_g_connection_flush (connection);
454 exit_timeout = g_timeout_add (5000, timed_exit, loop);
455 g_main_loop_run (loop);
457 if (n_times_foo_received != 1)
458 lose ("Foo signal received %d times, should have been 1", n_times_foo_received);
460 /* Activate test servie */
461 g_print ("Activating TestSuiteGLibService\n");
463 if (!dbus_g_proxy_call (driver, "StartServiceByName", &error,
465 "org.freedesktop.DBus.TestSuiteGLibService",
469 G_TYPE_UINT, &result,
471 lose_gerror ("Failed to complete Activate call", error);
474 g_print ("TestSuiteGLibService activated\n");
476 if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION"))
477 g_usleep (8 * G_USEC_PER_SEC);
479 g_object_unref (G_OBJECT (proxy));
483 proxy = dbus_g_proxy_new_for_name_owner (connection,
484 "org.freedesktop.DBus.TestSuiteGLibService",
485 "/org/freedesktop/DBus/Tests/MyTestObject",
486 "org.freedesktop.DBus.Tests.MyObject",
490 lose_gerror ("Failed to create proxy for name owner", error);
492 g_print ("Calling DoNothing\n");
493 if (!dbus_g_proxy_call (proxy, "DoNothing", &error,
494 G_TYPE_INVALID, G_TYPE_INVALID))
495 lose_gerror ("Failed to complete DoNothing call", error);
497 g_print ("Calling Increment\n");
499 if (!dbus_g_proxy_call (proxy, "Increment", &error,
502 G_TYPE_UINT, &v_UINT32_2,
504 lose_gerror ("Failed to complete Increment call", error);
505 if (v_UINT32_2 != 43)
506 lose ("Increment call returned %d, should be 43", v_UINT32_2);
509 g_print ("Calling Increment (async)\n");
510 call = dbus_g_proxy_begin_call (proxy, "Increment",
511 increment_received_cb, g_strdup ("moo"), g_free,
514 dbus_g_connection_flush (connection);
515 exit_timeout = g_timeout_add (5000, timed_exit, loop);
516 g_main_loop_run (loop);
518 g_print ("Calling IncrementRetval\n");
521 if (!dbus_g_proxy_call (proxy, "IncrementRetval", &error,
524 G_TYPE_UINT, &v_UINT32_2,
526 lose_gerror ("Failed to complete Increment call", error);
527 if (v_UINT32_2 != 43)
528 lose ("IncrementRetval call returned %d, should be 43", v_UINT32_2);
530 g_print ("Calling IncrementRetvalError\n");
533 if (!dbus_g_proxy_call (proxy, "IncrementRetvalError", &error,
536 G_TYPE_UINT, &v_UINT32_2,
538 lose_gerror ("Failed to complete Increment call", error);
540 lose ("IncrementRetval call returned %d, should be 6", v_UINT32_2);
542 g_print ("Calling ThrowError\n");
543 if (dbus_g_proxy_call (proxy, "ThrowError", &error,
544 G_TYPE_INVALID, G_TYPE_INVALID) != FALSE)
545 lose ("ThrowError call unexpectedly succeeded!");
547 if (!dbus_g_error_has_name (error, "org.freedesktop.DBus.Tests.MyObject.Foo"))
548 lose ("ThrowError call returned unexpected error \"%s\": %s", dbus_g_error_get_name (error),
551 g_print ("ThrowError failed (as expected) returned error: %s\n", error->message);
552 g_clear_error (&error);
554 g_print ("Calling IncrementRetvalError (for error)\n");
557 if (dbus_g_proxy_call (proxy, "IncrementRetvalError", &error,
560 G_TYPE_UINT, &v_UINT32_2,
561 G_TYPE_INVALID) != FALSE)
562 lose ("IncrementRetvalError call unexpectedly succeeded!");
563 if (!dbus_g_error_has_name (error, "org.freedesktop.DBus.Tests.MyObject.Foo"))
564 lose ("IncrementRetvalError call returned unexpected error \"%s\": %s", dbus_g_error_get_name (error), error->message);
565 g_clear_error (&error);
568 g_print ("Calling Uppercase\n");
569 if (!dbus_g_proxy_call (proxy, "Uppercase", &error,
570 G_TYPE_STRING, "foobar",
572 G_TYPE_STRING, &v_STRING_2,
574 lose_gerror ("Failed to complete Uppercase call", error);
575 if (strcmp ("FOOBAR", v_STRING_2) != 0)
576 lose ("Uppercase call returned unexpected string %s", v_STRING_2);
581 g_print ("Calling ManyArgs\n");
582 if (!dbus_g_proxy_call (proxy, "ManyArgs", &error,
584 G_TYPE_STRING, "bazwhee",
587 G_TYPE_DOUBLE, &v_DOUBLE_2,
588 G_TYPE_STRING, &v_STRING_2,
590 lose_gerror ("Failed to complete ManyArgs call", error);
591 if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56)
592 lose ("ManyArgs call returned unexpected double value %f", v_DOUBLE_2);
593 if (strcmp ("BAZWHEE", v_STRING_2) != 0)
594 lose ("ManyArgs call returned unexpected string %s", v_STRING_2);
597 g_print ("Calling (wrapped) do_nothing\n");
598 if (!org_freedesktop_DBus_Tests_MyObject_do_nothing (proxy, &error))
599 lose_gerror ("Failed to complete (wrapped) DoNothing call", error);
601 g_print ("Calling (wrapped) increment\n");
602 if (!org_freedesktop_DBus_Tests_MyObject_increment (proxy, 42, &v_UINT32_2, &error))
603 lose_gerror ("Failed to complete (wrapped) Increment call", error);
605 if (v_UINT32_2 != 43)
606 lose ("(wrapped) increment call returned %d, should be 43", v_UINT32_2);
608 g_print ("Calling (wrapped async) increment\n");
609 if (!org_freedesktop_DBus_Tests_MyObject_increment_async (proxy, 42, increment_async_cb, NULL))
610 lose_gerror ("Failed to complete (wrapped) Increment call", error);
611 dbus_g_connection_flush (connection);
612 exit_timeout = g_timeout_add (5000, timed_exit, loop);
613 g_main_loop_run (loop);
616 if (!org_freedesktop_DBus_Tests_MyObject_async_increment (proxy, 42, &v_UINT32_2, &error))
617 lose_gerror ("Failed to complete (wrapped) AsyncIncrement call", error);
619 if (v_UINT32_2 != 43)
620 lose ("(wrapped) async increment call returned %d, should be 43", v_UINT32_2);
622 g_print ("Calling (wrapped) throw_error\n");
623 if (org_freedesktop_DBus_Tests_MyObject_throw_error (proxy, &error) != FALSE)
624 lose ("(wrapped) ThrowError call unexpectedly succeeded!");
626 g_print ("(wrapped) ThrowError failed (as expected) returned error: %s\n", error->message);
627 g_clear_error (&error);
629 if (org_freedesktop_DBus_Tests_MyObject_async_throw_error (proxy, &error) != FALSE)
630 lose ("(wrapped) AsyncThrowError call unexpectedly succeeded!");
632 g_print ("(wrapped) AsyncThrowError failed (as expected) returned error: %s\n", error->message);
633 g_clear_error (&error);
635 g_print ("Calling (wrapped) uppercase\n");
636 if (!org_freedesktop_DBus_Tests_MyObject_uppercase (proxy, "foobar", &v_STRING_2, &error))
637 lose_gerror ("Failed to complete (wrapped) Uppercase call", error);
638 if (strcmp ("FOOBAR", v_STRING_2) != 0)
639 lose ("(wrapped) Uppercase call returned unexpected string %s", v_STRING_2);
642 g_print ("Calling (wrapped) many_args\n");
643 if (!org_freedesktop_DBus_Tests_MyObject_many_args (proxy, 26, "bazwhee", G_PI,
644 &v_DOUBLE_2, &v_STRING_2, &error))
645 lose_gerror ("Failed to complete (wrapped) ManyArgs call", error);
647 if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56)
649 lose ("(wrapped) ManyArgs call returned unexpected double value %f", v_DOUBLE_2);
651 if (strcmp ("BAZWHEE", v_STRING_2) != 0)
652 lose ("(wrapped) ManyArgs call returned unexpected string %s", v_STRING_2);
663 g_print ("Calling (wrapped) many_return\n");
664 if (!org_freedesktop_DBus_Tests_MyObject_many_return (proxy, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &error))
665 lose_gerror ("Failed to complete (wrapped) ManyReturn call", error);
668 lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg0);
670 if (strcmp ("42", arg1) != 0)
671 lose ("(wrapped) ManyReturn call returned unexpected string %s", arg1);
675 lose ("(wrapped) ManyReturn call returned unexpected gint32 value %u", arg2);
678 lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg3);
681 lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg4);
683 if (strcmp ("hello world", arg5))
684 lose ("(wrapped) ManyReturn call returned unexpected string %s", arg5);
691 GValue value = {0, };
693 g_value_init (&value, G_TYPE_STRING);
694 g_value_set_string (&value, "foo");
696 g_print ("Calling (wrapped) stringify, with string\n");
697 if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
701 lose_gerror ("Failed to complete (wrapped) stringify call", error);
702 if (strcmp ("foo", v_STRING_2) != 0)
703 lose ("(wrapped) stringify call returned unexpected string %s", v_STRING_2);
706 g_value_unset (&value);
707 g_value_init (&value, G_TYPE_INT);
708 g_value_set_int (&value, 42);
710 g_print ("Calling (wrapped) stringify, with int\n");
711 if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
715 lose_gerror ("Failed to complete (wrapped) stringify call 2", error);
716 if (strcmp ("42", v_STRING_2) != 0)
717 lose ("(wrapped) stringify call 2 returned unexpected string %s", v_STRING_2);
718 g_value_unset (&value);
721 g_value_init (&value, G_TYPE_INT);
722 g_value_set_int (&value, 88);
723 g_print ("Calling (wrapped) stringify, with another int\n");
724 if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy,
728 lose_gerror ("Failed to complete (wrapped) stringify call 3", error);
729 g_value_unset (&value);
731 g_print ("Calling (wrapped) unstringify, for string\n");
732 if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy,
736 lose_gerror ("Failed to complete (wrapped) unstringify call", error);
737 if (!G_VALUE_HOLDS_STRING (&value))
738 lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value));
739 if (strcmp (g_value_get_string (&value), "foo"))
740 lose ("(wrapped) unstringify call returned unexpected string %s",
741 g_value_get_string (&value));
743 g_value_unset (&value);
745 g_print ("Calling (wrapped) unstringify, for int\n");
746 if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy,
750 lose_gerror ("Failed to complete (wrapped) unstringify call", error);
751 if (!G_VALUE_HOLDS_INT (&value))
752 lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value));
753 if (g_value_get_int (&value) != 10)
754 lose ("(wrapped) unstringify call returned unexpected integer %d",
755 g_value_get_int (&value));
757 g_value_unset (&value);
767 array = g_array_new (FALSE, TRUE, sizeof (guint32));
769 g_array_append_val (array, val);
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);
780 g_print ("Calling (wrapped) recursive1\n");
781 if (!org_freedesktop_DBus_Tests_MyObject_recursive1 (proxy, array,
783 lose_gerror ("Failed to complete (wrapped) recursive1 call", error);
785 lose ("(wrapped) recursive1 call returned invalid length %u", arraylen);
789 GArray *array = NULL;
792 g_print ("Calling (wrapped) recursive2\n");
793 if (!org_freedesktop_DBus_Tests_MyObject_recursive2 (proxy, 2, &array, &error))
794 lose_gerror ("Failed to complete (wrapped) Recursive2 call", error);
797 lose ("(wrapped) Recursive2 call returned NULL");
799 lose ("(wrapped) Recursive2 call returned unexpected array length %u", array->len);
801 arrayvals = (guint32*) array->data;
802 if (arrayvals[0] != 42)
803 lose ("(wrapped) Recursive2 call returned unexpected value %d in position 0", arrayvals[0]);
804 if (arrayvals[1] != 26)
805 lose ("(wrapped) Recursive2 call returned unexpected value %d in position 1", arrayvals[1]);
806 if (arrayvals[4] != 2)
807 lose ("(wrapped) Recursive2 call returned unexpected value %d in position 4", arrayvals[4]);
809 g_array_free (array, TRUE);
818 strs = g_new0 (char *, 4);
825 g_print ("Calling (wrapped) many_uppercase\n");
826 if (!org_freedesktop_DBus_Tests_MyObject_many_uppercase (proxy, strs, &strs_ret, &error))
827 lose_gerror ("Failed to complete (wrapped) ManyUppercase call", error);
828 g_assert (strs_ret != NULL);
829 if (strcmp ("HELLO", strs_ret[0]) != 0)
830 lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[0]);
831 if (strcmp ("HELLO", strs_ret[1]) != 0)
832 lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[1]);
833 if (strcmp ("HELLO", strs_ret[2]) != 0)
834 lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[2]);
837 g_strfreev (strs_ret);
844 table = g_hash_table_new (g_str_hash, g_str_equal);
845 g_hash_table_insert (table, "moooo", "b");
846 g_hash_table_insert (table, "xxx", "cow!");
849 g_print ("Calling (wrapped) str_hash_len\n");
850 if (!org_freedesktop_DBus_Tests_MyObject_str_hash_len (proxy, table, &len, &error))
851 lose_gerror ("(wrapped) StrHashLen call failed", error);
853 lose ("(wrapped) StrHashLen returned unexpected length %u", len);
854 g_hash_table_destroy (table);
861 g_print ("Calling (wrapped) get_hash\n");
862 if (!org_freedesktop_DBus_Tests_MyObject_get_hash (proxy, &table, &error))
863 lose_gerror ("(wrapped) GetHash call failed", error);
864 val = g_hash_table_lookup (table, "foo");
865 if (val == NULL || strcmp ("bar", val))
866 lose ("(wrapped) StrHashLen returned invalid value %s for key \"foo\"",
867 val ? val : "(null)");
868 val = g_hash_table_lookup (table, "baz");
869 if (val == NULL || strcmp ("whee", val))
870 lose ("(wrapped) StrHashLen returned invalid value %s for key \"whee\"",
871 val ? val : "(null)");
872 val = g_hash_table_lookup (table, "cow");
873 if (val == NULL || strcmp ("crack", val))
874 lose ("(wrapped) StrHashLen returned invalid value %s for key \"cow\"",
875 val ? val : "(null)");
876 if (g_hash_table_size (table) != 3)
877 lose ("(wrapped) StrHashLen returned unexpected hash size %u",
878 g_hash_table_size (table));
880 g_hash_table_destroy (table);
887 GValueArray *vals_ret;
890 vals = g_value_array_new (3);
892 g_value_array_append (vals, NULL);
893 g_value_init (g_value_array_get_nth (vals, vals->n_values - 1), G_TYPE_STRING);
894 g_value_set_string (g_value_array_get_nth (vals, 0), "foo");
896 g_value_array_append (vals, NULL);
897 g_value_init (g_value_array_get_nth (vals, vals->n_values - 1), G_TYPE_UINT);
898 g_value_set_uint (g_value_array_get_nth (vals, vals->n_values - 1), 42);
900 g_value_array_append (vals, NULL);
901 g_value_init (g_value_array_get_nth (vals, vals->n_values - 1), G_TYPE_VALUE);
902 val = g_new0 (GValue, 1);
903 g_value_init (val, G_TYPE_UCHAR);
904 g_value_set_uchar (val, '!');
905 g_value_set_boxed (g_value_array_get_nth (vals, vals->n_values - 1), val);
908 g_print ("Calling SendCar\n");
909 if (!dbus_g_proxy_call (proxy, "SendCar", &error,
910 G_TYPE_VALUE_ARRAY, vals,
912 G_TYPE_VALUE_ARRAY, &vals_ret,
914 lose_gerror ("Failed to complete SendCar call", error);
916 g_assert (vals_ret != NULL);
917 g_assert (vals_ret->n_values == 2);
919 g_assert (G_VALUE_HOLDS_UINT (g_value_array_get_nth (vals_ret, 0)));
920 g_assert (g_value_get_uint (g_value_array_get_nth (vals_ret, 0)) == 43);
922 g_assert (G_VALUE_TYPE (g_value_array_get_nth (vals_ret, 1)) == DBUS_TYPE_G_OBJECT_PATH);
923 g_assert (!strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
924 g_value_get_boxed (g_value_array_get_nth (vals_ret, 1))));
926 g_value_array_free (vals);
927 g_value_array_free (vals_ret);
933 GHashTable *ret_table;
935 table = g_hash_table_new_full (g_str_hash, g_str_equal,
936 g_free, unset_and_free_gvalue);
938 val = g_new0 (GValue, 1);
939 g_value_init (val, G_TYPE_UINT);
940 g_value_set_uint (val, 42);
941 g_hash_table_insert (table, g_strdup ("foo"), val);
943 val = g_new0 (GValue, 1);
944 g_value_init (val, G_TYPE_STRING);
945 g_value_set_string (val, "hello");
946 g_hash_table_insert (table, g_strdup ("bar"), val);
949 g_print ("Calling ManyStringify\n");
950 if (!dbus_g_proxy_call (proxy, "ManyStringify", &error,
951 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), table,
953 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &ret_table,
955 lose_gerror ("Failed to complete ManyStringify call", error);
957 g_assert (ret_table != NULL);
958 g_assert (g_hash_table_size (ret_table) == 2);
960 val = g_hash_table_lookup (ret_table, "foo");
961 g_assert (val != NULL);
962 g_assert (G_VALUE_HOLDS_STRING (val));
963 g_assert (!strcmp ("42", g_value_get_string (val)));
965 val = g_hash_table_lookup (ret_table, "bar");
966 g_assert (val != NULL);
967 g_assert (G_VALUE_HOLDS_STRING (val));
968 g_assert (!strcmp ("hello", g_value_get_string (val)));
970 g_hash_table_destroy (table);
971 g_hash_table_destroy (ret_table);
976 GPtrArray *out_array;
980 in_array = g_ptr_array_new ();
982 strs = g_new0 (char *, 3);
986 g_ptr_array_add (in_array, strs);
988 strs = g_new0 (char *, 4);
993 g_ptr_array_add (in_array, strs);
996 g_print ("Calling RecArrays\n");
997 if (!dbus_g_proxy_call (proxy, "RecArrays", &error,
998 dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRV), in_array,
1000 dbus_g_type_get_collection ("GPtrArray",
1001 dbus_g_type_get_collection ("GPtrArray",
1002 G_TYPE_UINT)), &out_array,
1004 lose_gerror ("Failed to complete RecArrays call", error);
1005 g_free (g_ptr_array_index (in_array, 0));
1006 g_free (g_ptr_array_index (in_array, 1));
1008 g_assert (out_array);
1009 g_assert (out_array->len == 2);
1010 uints = g_ptr_array_index (out_array, 0);
1012 g_assert (uints->len == 3);
1013 g_assert (g_array_index (uints, guint, 0) == 10);
1014 g_assert (g_array_index (uints, guint, 1) == 42);
1015 g_assert (g_array_index (uints, guint, 2) == 27);
1016 g_array_free (uints, TRUE);
1017 uints = g_ptr_array_index (out_array, 1);
1019 g_assert (uints->len == 1);
1020 g_assert (g_array_index (uints, guint, 0) == 30);
1021 g_array_free (uints, TRUE);
1022 g_ptr_array_free (out_array, TRUE);
1028 DBusGProxy *ret_proxy;
1030 g_print ("Calling (wrapped) objpath\n");
1031 if (!dbus_g_proxy_call (proxy, "Objpath", &error,
1032 DBUS_TYPE_G_PROXY, proxy, G_TYPE_INVALID,
1033 DBUS_TYPE_G_PROXY, &ret_proxy, G_TYPE_INVALID))
1034 lose_gerror ("Failed to complete Objpath call", error);
1035 if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
1036 dbus_g_proxy_get_path (ret_proxy)) != 0)
1037 lose ("(wrapped) objpath call returned unexpected proxy %s",
1038 dbus_g_proxy_get_path (ret_proxy));
1040 g_print ("Doing get/increment val tests\n");
1042 if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
1043 lose_gerror ("Failed to complete (wrapped) GetVal call", error);
1045 lose ("(wrapped) GetVal returned invalid value %d", val);
1047 if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
1048 lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
1050 if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
1051 lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
1053 if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error))
1054 lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
1056 if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
1057 lose_gerror ("Failed to complete (wrapped) GetVal call", error);
1059 lose ("(wrapped) GetVal returned invalid value %d", val);
1061 if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error))
1062 lose_gerror ("Failed to complete (wrapped) GetVal call", error);
1064 lose ("(wrapped) GetVal returned invalid value %d", val);
1066 if (!org_freedesktop_DBus_Tests_MyObject_increment_val (proxy, &error))
1067 lose_gerror ("Failed to complete (wrapped) IncrementVal call", error);
1069 if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error))
1070 lose_gerror ("Failed to complete (wrapped) GetVal call", error);
1072 lose ("(wrapped) GetVal returned invalid value %d", val);
1074 if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error))
1075 lose_gerror ("Failed to complete (wrapped) GetVal call", error);
1077 lose ("(wrapped) GetVal returned invalid value %d", val);
1079 g_object_unref (G_OBJECT (ret_proxy));
1081 g_print ("Calling objpath again\n");
1084 if (!dbus_g_proxy_call (proxy, "Objpath", &error,
1085 DBUS_TYPE_G_OBJECT_PATH,
1086 dbus_g_proxy_get_path (proxy),
1088 DBUS_TYPE_G_OBJECT_PATH,
1091 lose_gerror ("Failed to complete Objpath call 2", error);
1092 if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2", ret_path) != 0)
1093 lose ("Objpath call 2 returned unexpected path %s",
1096 ret_proxy = dbus_g_proxy_new_for_name_owner (connection,
1097 "org.freedesktop.DBus.TestSuiteGLibService",
1099 "org.freedesktop.DBus.Tests.FooObject",
1104 if (!org_freedesktop_DBus_Tests_FooObject_get_value (ret_proxy, &val, &error))
1105 lose_gerror ("Failed to complete (wrapped) GetValue call", error);
1107 lose ("(wrapped) GetValue returned invalid value %d", val);
1116 g_print ("Calling GetObjs\n");
1118 if (!dbus_g_proxy_call (proxy, "GetObjs", &error, G_TYPE_INVALID,
1119 dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH),
1122 lose_gerror ("Failed to complete GetObjs call", error);
1124 lose ("GetObjs call returned unexpected number of objects %d, expected 2",
1127 if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject",
1128 g_ptr_array_index (objs, 0)) != 0)
1129 lose ("GetObjs call returned unexpected path \"%s\" in position 0; expected /org/freedesktop/DBus/Tests/MyTestObject", (char*) g_ptr_array_index (objs, 0));
1131 if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2",
1132 g_ptr_array_index (objs, 1)) != 0)
1133 lose ("GetObjs call returned unexpected path \"%s\" in position 1; expected /org/freedesktop/DBus/Tests/MyTestObject2", (char*) g_ptr_array_index (objs, 1));
1135 for (i = 0; i < objs->len; i++)
1136 g_free (g_ptr_array_index (objs, i));
1137 g_ptr_array_free (objs, TRUE);
1145 g_print ("Calling ProcessVariantOfArrayOfInts123\n");
1147 array = g_array_sized_new (FALSE, FALSE, sizeof(gint), 3);
1149 g_array_append_val (array, i);
1151 g_array_append_val (array, i);
1153 g_array_append_val (array, i);
1155 variant = g_new0 (GValue, 1);
1156 g_value_init (variant, dbus_g_type_get_collection ("GArray", G_TYPE_INT));
1157 g_value_set_boxed_take_ownership (variant, array);
1159 if (!dbus_g_proxy_call (proxy, "ProcessVariantOfArrayOfInts123", &error,
1160 G_TYPE_VALUE, variant,
1163 lose_gerror ("Failed to send a vairant of array of ints 1, 2 and 3!", error);
1165 g_value_unset (variant);
1172 GHashTable *subtable;
1173 GHashTable *ret_table;
1175 table = g_hash_table_new_full (g_str_hash, g_str_equal,
1176 (GDestroyNotify) (g_free),
1177 (GDestroyNotify) (g_hash_table_destroy));
1179 subtable = g_hash_table_new_full (g_str_hash, g_str_equal,
1180 (GDestroyNotify) (g_free),
1181 (GDestroyNotify) (g_free));
1182 g_hash_table_insert (subtable, g_strdup ("foo"), g_strdup("1"));
1183 g_hash_table_insert (subtable, g_strdup ("bar"), g_strdup("2"));
1184 g_hash_table_insert (subtable, g_strdup ("baz"), g_strdup("3"));
1186 g_hash_table_insert (table, g_strdup("dict1"), subtable);
1188 subtable = g_hash_table_new_full (g_str_hash, g_str_equal,
1189 (GDestroyNotify) (g_free),
1190 (GDestroyNotify) (g_free));
1191 g_hash_table_insert (subtable, g_strdup ("foo"), g_strdup("4"));
1192 g_hash_table_insert (subtable, g_strdup ("bar"), g_strdup("5"));
1193 g_hash_table_insert (subtable, g_strdup ("baz"), g_strdup("6"));
1195 g_hash_table_insert (table, g_strdup("dict2"), subtable);
1201 g_print ("Calling DictOfDicts\n");
1202 if (!dbus_g_proxy_call (proxy, "DictOfDicts", &error,
1203 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING,
1204 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING,
1205 G_TYPE_STRING)), table,
1207 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING,
1208 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING,
1209 G_TYPE_STRING)), &ret_table,
1211 lose_gerror ("Failed to complete DictOfDicts call", error);
1213 g_assert (ret_table != NULL);
1214 g_assert (g_hash_table_size (ret_table) == 2);
1216 subtable = g_hash_table_lookup (ret_table, "dict1");
1218 g_assert (g_hash_table_size (subtable) == 3);
1220 val = g_hash_table_lookup (subtable, "foo");
1221 g_assert (val != NULL);
1222 g_assert (!strcmp ("dict1 1", val));
1224 val = g_hash_table_lookup (subtable, "bar");
1225 g_assert (val != NULL);
1226 g_assert (!strcmp ("dict1 2", val));
1228 val = g_hash_table_lookup (subtable, "baz");
1229 g_assert (val != NULL);
1230 g_assert (!strcmp ("dict1 3", val));
1232 subtable = g_hash_table_lookup (ret_table, "dict2");
1234 g_assert (g_hash_table_size (subtable) == 3);
1236 val = g_hash_table_lookup (subtable, "foo");
1237 g_assert (val != NULL);
1238 g_assert (!strcmp ("dict2 4", val));
1240 val = g_hash_table_lookup (subtable, "bar");
1241 g_assert (val != NULL);
1242 g_assert (!strcmp ("dict2 5", val));
1244 val = g_hash_table_lookup (subtable, "baz");
1245 g_assert (val != NULL);
1246 g_assert (!strcmp ("dict2 6", val));
1248 g_hash_table_destroy (table);
1249 g_hash_table_destroy (ret_table);
1256 /* Signal handling tests */
1258 g_print ("Testing signal handling\n");
1259 dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1261 dbus_g_proxy_connect_signal (proxy, "Frobnicate",
1262 G_CALLBACK (frobnicate_signal_handler),
1265 g_print ("Calling EmitFrobnicate\n");
1266 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1267 G_TYPE_INVALID, G_TYPE_INVALID))
1268 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1271 dbus_g_connection_flush (connection);
1272 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1273 g_main_loop_run (loop);
1275 if (n_times_frobnicate_received != 1)
1276 lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1278 g_print ("Calling EmitFrobnicate again\n");
1279 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1280 G_TYPE_INVALID, G_TYPE_INVALID))
1281 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1283 dbus_g_connection_flush (connection);
1284 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1285 g_main_loop_run (loop);
1287 if (n_times_frobnicate_received != 2)
1288 lose ("Frobnicate signal received %d times, should have been 2", n_times_frobnicate_received);
1290 g_object_unref (G_OBJECT (proxy));
1294 g_print ("Creating proxy for FooObject interface\n");
1295 proxy = dbus_g_proxy_new_for_name_owner (connection,
1296 "org.freedesktop.DBus.TestSuiteGLibService",
1297 "/org/freedesktop/DBus/Tests/MyTestObject",
1298 "org.freedesktop.DBus.Tests.FooObject",
1302 lose_gerror ("Failed to create proxy for name owner", error);
1304 dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_INT_STRING,
1305 G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
1307 dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_BOXED,
1308 G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
1310 dbus_g_proxy_add_signal (proxy, "Sig0", G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
1311 dbus_g_proxy_add_signal (proxy, "Sig1", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
1312 dbus_g_proxy_add_signal (proxy, "Sig2", DBUS_TYPE_G_STRING_STRING_HASHTABLE, G_TYPE_INVALID);
1314 dbus_g_proxy_connect_signal (proxy, "Sig0",
1315 G_CALLBACK (sig0_signal_handler),
1317 dbus_g_proxy_connect_signal (proxy, "Sig1",
1318 G_CALLBACK (sig1_signal_handler),
1320 dbus_g_proxy_connect_signal (proxy, "Sig2",
1321 G_CALLBACK (sig2_signal_handler),
1324 g_print ("Calling FooObject EmitSignals\n");
1325 dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1327 dbus_g_connection_flush (connection);
1328 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1329 g_main_loop_run (loop);
1330 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1331 g_main_loop_run (loop);
1333 if (n_times_sig0_received != 1)
1334 lose ("Sig0 signal received %d times, should have been 1", n_times_sig0_received);
1335 if (n_times_sig1_received != 1)
1336 lose ("Sig1 signal received %d times, should have been 1", n_times_sig1_received);
1338 g_print ("Calling FooObject EmitSignals and EmitSignal2\n");
1339 dbus_g_proxy_call_no_reply (proxy, "EmitSignal2", G_TYPE_INVALID);
1340 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_sig2_received != 1)
1346 lose ("Sig2 signal received %d times, should have been 1", n_times_sig2_received);
1348 g_print ("Calling FooObject EmitSignals two more times\n");
1349 dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
1350 dbus_g_proxy_call_no_reply (proxy, "EmitSignals", 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 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1356 g_main_loop_run (loop);
1357 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1358 g_main_loop_run (loop);
1359 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1360 g_main_loop_run (loop);
1362 if (n_times_sig0_received != 3)
1363 lose ("Sig0 signal received %d times, should have been 3", n_times_sig0_received);
1364 if (n_times_sig1_received != 3)
1365 lose ("Sig1 signal received %d times, should have been 3", n_times_sig1_received);
1367 /* Terminate again */
1368 g_print ("Terminating service\n");
1369 await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService";
1370 dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID);
1372 proxy_destroyed = FALSE;
1373 proxy_destroy_and_nameowner = TRUE;
1374 proxy_destroy_and_nameowner_complete = FALSE;
1376 g_signal_connect (G_OBJECT (proxy),
1378 G_CALLBACK (proxy_destroyed_cb),
1381 dbus_g_connection_flush (connection);
1382 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1383 g_main_loop_run (loop);
1385 if (await_terminating_service != NULL)
1386 lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\"");
1387 if (!proxy_destroyed)
1388 lose ("Didn't get proxy_destroyed");
1389 g_print ("Proxy destroyed successfully\n");
1391 /* Don't need to unref, proxy was destroyed */
1395 /* Create a new proxy for the name; should not be associated */
1396 proxy = dbus_g_proxy_new_for_name (connection,
1397 "org.freedesktop.DBus.TestSuiteGLibService",
1398 "/org/freedesktop/DBus/Tests/MyTestObject",
1399 "org.freedesktop.DBus.Tests.MyObject");
1400 g_assert (proxy != NULL);
1402 proxy_destroyed = FALSE;
1403 proxy_destroy_and_nameowner = FALSE;
1404 proxy_destroy_and_nameowner_complete = FALSE;
1406 g_signal_connect (G_OBJECT (proxy),
1408 G_CALLBACK (proxy_destroyed_cb),
1411 if (!dbus_g_proxy_call (driver, "GetNameOwner", &error,
1413 "org.freedesktop.DBus.TestSuiteGLibService",
1418 if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NAME_HAS_NO_OWNER)
1419 g_print ("Got expected error \"org.freedesktop.DBus.Error.NameHasNoOwner\"\n");
1421 lose_gerror ("Unexpected error from GetNameOwner", error);
1423 lose ("GetNameOwner unexpectedly succeeded!");
1424 g_clear_error (&error);
1426 /* This will have the side-effect of activating the service, thus
1427 * causing a NameOwnerChanged, which should let our name proxy
1430 g_print ("Calling Uppercase for name proxy\n");
1431 if (!dbus_g_proxy_call (proxy, "Uppercase", &error,
1432 G_TYPE_STRING, "bazwhee",
1434 G_TYPE_STRING, &v_STRING_2,
1436 lose_gerror ("Failed to complete Uppercase call", error);
1437 g_free (v_STRING_2);
1439 if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION1"))
1440 g_usleep (8 * G_USEC_PER_SEC);
1442 dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1444 dbus_g_proxy_connect_signal (proxy, "Frobnicate",
1445 G_CALLBACK (frobnicate_signal_handler),
1448 g_print ("Calling EmitFrobnicate\n");
1449 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1450 G_TYPE_INVALID, G_TYPE_INVALID))
1451 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1453 n_times_frobnicate_received = 0;
1455 dbus_g_connection_flush (connection);
1456 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1457 g_main_loop_run (loop);
1459 if (n_times_frobnicate_received != 1)
1460 lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1462 /* Now terminate the service, then start it again (implicitly) and wait for signals */
1463 g_print ("Terminating service (2)\n");
1464 await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService";
1465 dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID);
1466 dbus_g_connection_flush (connection);
1467 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1468 g_main_loop_run (loop);
1469 if (await_terminating_service != NULL)
1470 lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\"");
1472 if (proxy_destroyed)
1473 lose ("Unexpectedly got proxy_destroyed!");
1475 n_times_frobnicate_received = 0;
1477 g_print ("Calling EmitFrobnicate (2)\n");
1478 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1479 G_TYPE_INVALID, G_TYPE_INVALID))
1480 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1482 if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION2"))
1483 g_usleep (8 * G_USEC_PER_SEC);
1485 dbus_g_connection_flush (connection);
1486 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1487 g_main_loop_run (loop);
1489 if (n_times_frobnicate_received != 1)
1490 lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received);
1492 if (proxy_destroyed)
1493 lose ("Unexpectedly got proxy_destroyed!");
1495 /* Create another proxy for the name; should be associated immediately */
1496 proxy2 = dbus_g_proxy_new_for_name (connection,
1497 "org.freedesktop.DBus.TestSuiteGLibService",
1498 "/org/freedesktop/DBus/Tests/MyTestObject",
1499 "org.freedesktop.DBus.Tests.MyObject");
1500 g_assert (proxy2 != NULL);
1502 dbus_g_proxy_add_signal (proxy2, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
1504 dbus_g_proxy_connect_signal (proxy2, "Frobnicate",
1505 G_CALLBACK (frobnicate_signal_handler_2),
1508 g_print ("Calling EmitFrobnicate (3)\n");
1509 if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error,
1510 G_TYPE_INVALID, G_TYPE_INVALID))
1511 lose_gerror ("Failed to complete EmitFrobnicate call", error);
1513 dbus_g_connection_flush (connection);
1514 exit_timeout = g_timeout_add (5000, timed_exit, loop);
1515 g_main_loop_run (loop);
1517 if (n_times_frobnicate_received != 2)
1518 lose ("Frobnicate signal received %d times for 1st proxy, should have been 2", n_times_frobnicate_received);
1519 if (n_times_frobnicate_received_2 != 1)
1520 lose ("Frobnicate signal received %d times for 2nd proxy, should have been 1", n_times_frobnicate_received_2);
1522 g_object_unref (G_OBJECT (proxy));
1523 g_object_unref (G_OBJECT (proxy2));
1527 /* Test introspection */
1528 proxy = dbus_g_proxy_new_for_name_owner (connection,
1529 "org.freedesktop.DBus.TestSuiteGLibService",
1530 "/org/freedesktop/DBus/Tests/MyTestObject",
1531 "org.freedesktop.DBus.Introspectable",
1534 lose_gerror ("Failed to create proxy for name owner", error);
1536 g_print ("Testing introspect\n");
1537 if (!dbus_g_proxy_call (proxy, "Introspect", &error,
1539 G_TYPE_STRING, &v_STRING_2,
1541 lose_gerror ("Failed to complete Introspect call", error);
1543 /* Could just do strcmp(), but that seems more fragile */
1547 gboolean found_introspectable;
1548 gboolean found_properties;
1549 gboolean found_myobject;
1550 gboolean found_fooobject;
1552 node = description_load_from_string (v_STRING_2, strlen (v_STRING_2), &error);
1554 lose_gerror ("Failed to parse introspection data: %s", error);
1556 found_introspectable = FALSE;
1557 found_properties = FALSE;
1558 found_myobject = FALSE;
1559 found_fooobject = FALSE;
1560 for (elt = node_info_get_interfaces (node); elt ; elt = elt->next)
1562 InterfaceInfo *iface = elt->data;
1564 if (!found_introspectable && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Introspectable") == 0)
1565 found_introspectable = TRUE;
1566 else if (!found_properties && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Properties") == 0)
1567 found_properties = TRUE;
1568 else if (!found_myobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.MyObject") == 0)
1571 gboolean found_manyargs;
1573 found_myobject = TRUE;
1575 found_manyargs = FALSE;
1576 for (elt = interface_info_get_methods (iface); elt; elt = elt->next)
1581 if (strcmp (method_info_get_name (method), "ManyArgs") == 0)
1583 found_manyargs = TRUE;
1587 if (!found_manyargs)
1588 lose ("Missing method org.freedesktop.DBus.Tests.MyObject.ManyArgs");
1590 else if (!found_fooobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.FooObject") == 0)
1591 found_fooobject = TRUE;
1593 lose ("Unexpected or duplicate interface %s", interface_info_get_name (iface));
1596 if (!(found_introspectable && found_myobject && found_properties))
1597 lose ("Missing interface");
1599 g_free (v_STRING_2);
1601 g_object_unref (G_OBJECT (driver));
1603 g_print ("Successfully completed %s\n", argv[0]);