Release 0.41.92
[vala-gnome.git] / tests / dbus / bug783002.test
blobf300c2beb6714984644e7d6e8e2932d1aa95fa4d
1 Packages: gio-2.0
2 D-Bus
4 Program: client
6 [DBus (name = "org.example.Test")]
7 interface Test : Object {
8         public abstract async string test_array_lifetime (string[] items) throws IOError;
11 MainLoop main_loop;
13 void main () {
14         main_loop = new MainLoop ();
15         run.begin ();
16         main_loop.run ();
19 async void run () {
20         Test test = yield Bus.get_proxy (BusType.SESSION, "org.example.Test", "/org/example/test");
22         var result = yield test.test_array_lifetime (new string[] { "Badger", "Snake", "Mushroom" });
23         assert (result == "BadgerSnakeMushroom");
25         main_loop.quit ();
28 Program: server
30 [DBus (name = "org.example.Test")]
31 class Test : Object {
32         public async string test_array_lifetime (string[] items) throws IOError {
33                 Idle.add (() => {
34                         test_array_lifetime.callback ();
35                         return false;
36                 });
37                 yield;
39                 var result = new StringBuilder ();
40                 foreach (var item in items) {
41                         result.append (item);
42                 }
44                 assert (result.str == "BadgerSnakeMushroom");
45                 return result.str;
46         }
49 MainLoop main_loop;
51 void on_client_exit (Pid pid, int status) {
52         assert (status == 0);
53         main_loop.quit ();
56 void main () {
57         var conn = Bus.get_sync (BusType.SESSION);
58         conn.register_object ("/org/example/test", new Test ());
60         var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
61                                               new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
62         assert ((uint) request_result.get_child_value (0) == 1);
64         Pid client_pid;
65         Process.spawn_async (null, { "test", "/dbus/bug783002/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
66         ChildWatch.add (client_pid, on_client_exit);
68         main_loop = new MainLoop ();
69         main_loop.run ();