Release 0.41.92
[vala-gnome.git] / tests / dbus / bug602003.test
blobceb2327e5de9e33e600ed1f0a3923804447f75ed
1 Packages: gio-2.0
2 D-Bus
4 Program: client
6 [DBus (name = "org.example.Test")]
7 interface Test : Object {
8         public abstract Variant test_string () throws IOError;
11 void main () {
12         // client
13         Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
15         Variant v = test.test_string ();
16         string[] s = (string[]) v;
17         assert (s.length == 1 && s[0] == "hello");
20 Program: server
22 [DBus (name = "org.example.Test")]
23 class Test : Object {
24         public Variant test_string () {
25                 string[] s = { "hello" };
26                 return s;
27         }
30 MainLoop main_loop;
32 void client_exit (Pid pid, int status) {
33         // client finished, terminate server
34         assert (status == 0);
35         main_loop.quit ();
38 void main () {
39         var conn = Bus.get_sync (BusType.SESSION);
40         conn.register_object ("/org/example/test", new Test ());
42         // try to register service in session bus
43         var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
44                                               new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
45         assert ((uint) request_result.get_child_value (0) == 1);
47         // server ready, spawn client
48         Pid client_pid;
49         Process.spawn_async (null, { "test", "/dbus/bug602003/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
50         ChildWatch.add (client_pid, client_exit);
52         main_loop = new MainLoop ();
53         main_loop.run ();