gdbus: Fix missing declaration of _fd_list for async methods
[vala-gnome.git] / tests / dbus / filedescriptor-async.test
blob96fc9764a2f637d809441ce40b4f762aee5226d5
1 Packages: gio-2.0 gio-unix-2.0 posix
2 D-Bus
4 Program: client
6 [DBus (name = "org.example.Test")]
7 interface Test : Object {
8         public abstract async UnixInputStream test_in (UnixInputStream i, out UnixInputStream j) throws IOError;
11 MainLoop main_loop;
13 async void run () {
14         // client
15         Test test = yield Bus.get_proxy (BusType.SESSION, "org.example.Test", "/org/example/test");
17         uint8[] buffer = new uint8[1];
19         int[] pipe1 = new int[2];
20         assert (Posix.pipe (pipe1) == 0);
21         buffer[0] = 42;
22         assert (Posix.write (pipe1[1], buffer, 1) == 1);
23         Posix.close (pipe1[1]);
25         UnixInputStream j, k;
26         k = yield test.test_in (new UnixInputStream (pipe1[0], true), out j);
28         assert (j.read (buffer) == 1);
29         assert (buffer[0] == 23);
31         assert (k.read (buffer) == 1);
32         assert (buffer[0] == 11);
34         main_loop.quit ();
37 void main () {
38         // client
39         run.begin ();
41         main_loop = new MainLoop (null, false);
42         main_loop.run ();
45 Program: server
47 [DBus (name = "org.example.Test")]
48 class Test : Object {
49         public async UnixInputStream test_in (UnixInputStream i, out UnixInputStream j) throws IOError {
50                 uint8[] buffer = new uint8[1];
52                 assert (i.read (buffer) == 1);
53                 assert (buffer[0] == 42);
55                 int[] pipe1 = new int[2];
56                 assert (Posix.pipe (pipe1) == 0);
57                 buffer[0] = 23;
58                 assert (Posix.write (pipe1[1], buffer, 1) == 1);
59                 Posix.close (pipe1[1]);
61                 int[] pipe2 = new int[2];
62                 assert (Posix.pipe (pipe2) == 0);
63                 buffer[0] = 11;
64                 assert (Posix.write (pipe2[1], buffer, 1) == 1);
65                 Posix.close (pipe2[1]);
67                 Idle.add (test_in.callback);
68                 yield;
70                 j = new UnixInputStream (pipe1[0], true);
71                 return new UnixInputStream (pipe2[0], true);
72         }
75 MainLoop main_loop;
77 void client_exit (Pid pid, int status) {
78         // client finished, terminate server
79         assert (status == 0);
80         main_loop.quit ();
83 void main () {
84         var conn = Bus.get_sync (BusType.SESSION);
85         conn.register_object ("/org/example/test", new Test ());
87         // try to register service in session bus
88         var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
89                                               new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
90         assert ((uint) request_result.get_child_value (0) == 1);
92         // server ready, spawn client
93         Pid client_pid;
94         Process.spawn_async (null, { "test", "/dbus/filedescriptor-async/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
95         ChildWatch.add (client_pid, client_exit);
97         main_loop = new MainLoop ();
98         main_loop.run ();