Release 0.41.92
[vala-gnome.git] / tests / dbus / async-errors.test
blob4c9483f5d34c434aac3ab3555027822080873f4c
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 void test_void () throws Error;
9         public abstract async int test_int (int i, out int j) throws Error;
10         public abstract async string test_string (string s, out string t) throws Error;
11         public abstract async void test_cancellable (Cancellable? cancellable = null) throws Error;
14 MainLoop main_loop;
16 async void run () {
17         Test test = yield Bus.get_proxy (BusType.SESSION, "org.example.Test", "/org/example/test");
19         try {
20                 yield test.test_void ();
21                 assert_not_reached ();
22         } catch {
23         }
25         try {
26                 int j, k;
27                 k = yield test.test_int (42, out j);
28                 assert_not_reached ();
29         } catch {
30         }
32         try {
33                 string t, u;
34                 u = yield test.test_string ("hello", out t);
35                 assert_not_reached ();
36         } catch {
37         }
39         try {
40                 var cancellable = new Cancellable ();
41                 cancellable.cancel ();
42                 yield test.test_cancellable (cancellable);
43                 assert_not_reached ();
44         } catch {
45         }
47         main_loop.quit ();
50 void main () {
51         // client
52         run.begin ();
54         main_loop = new MainLoop (null, false);
55         main_loop.run ();
58 Program: server
60 [DBus (name = "org.example.Test")]
61 class Test : Object {
62         public async void test_void () throws Error {
63                 Idle.add (test_void.callback);
64                 yield;
65                 throw new IOError.FAILED ("Operation failed");
66         }
68         public async int test_int (int i, out int j) throws Error {
69                 Idle.add (test_int.callback);
70                 yield;
71                 throw new IOError.FAILED ("Operation failed");
72         }
74         public async string test_string (string s, out string t) throws Error {
75                 Idle.add (test_string.callback);
76                 yield;
77                 throw new IOError.FAILED ("Operation failed");
78         }
80         public async void test_cancellable (Cancellable? cancellable = null) throws Error {
81                 Idle.add (test_cancellable.callback);
82                 yield;
83         }
86 MainLoop main_loop;
88 void client_exit (Pid pid, int status) {
89         // client finished, terminate server
90         assert (status == 0);
91         main_loop.quit ();
94 void main () {
95         var conn = Bus.get_sync (BusType.SESSION);
96         conn.register_object ("/org/example/test", new Test ());
98         // try to register service in session bus
99         var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
100                                               new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
101         assert ((uint) request_result.get_child_value (0) == 1);
103         // server ready, spawn client
104         Pid client_pid;
105         Process.spawn_async (null, { "test", "/dbus/async-errors/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
106         ChildWatch.add (client_pid, client_exit);
108         main_loop = new MainLoop ();
109         main_loop.run ();