Release 0.41.92
[vala-gnome.git] / tests / dbus / errors.test
blob9088fb4fddce00c5ea163ac16129e76992a7c6da
1 Packages: gio-2.0
2 D-Bus
4 Program: client
6 [DBus (name = "org.example.Test")]
7 interface Test : Object {
8         public abstract void test_void () throws Error;
9         public abstract int test_int (int i, out int j) throws Error;
10         public abstract string test_string (string s, out string t) throws Error;
11         public abstract void test_cancellable (Cancellable? cancellable = null) throws Error;
14 void main () {
15         // client
16         Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
18         try {
19                 test.test_void ();
20                 assert_not_reached ();
21         } catch {
22         }
24         try {
25                 int j, k;
26                 k = test.test_int (42, out j);
27                 assert_not_reached ();
28         } catch {
29         }
31         try {
32                 string t, u;
33                 u = test.test_string ("hello", out t);
34                 assert (t == "world");
35                 assert (u == "vala");
36                 assert_not_reached ();
37         } catch {
38         }
40         try {
41                 var cancellable = new Cancellable ();
42                 cancellable.cancel ();
43                 test.test_cancellable (cancellable);
44                 assert_not_reached ();
45         } catch {
46         }
49 Program: server
51 [DBus (name = "org.example.Test")]
52 class Test : Object {
53         public void test_void () throws Error {
54                 throw new IOError.FAILED ("Operation failed");
55         }
57         public int test_int (int i, out int j) throws Error {
58                 throw new IOError.FAILED ("Operation failed");
59         }
61         public string test_string (string s, out string t) throws Error {
62                 throw new IOError.FAILED ("Operation failed");
63         }
65         public void test_cancellable (Cancellable? cancellable = null) throws Error {
66         }
69 MainLoop main_loop;
71 void client_exit (Pid pid, int status) {
72         // client finished, terminate server
73         assert (status == 0);
74         main_loop.quit ();
77 void main () {
78         var conn = Bus.get_sync (BusType.SESSION);
79         conn.register_object ("/org/example/test", new Test ());
81         // try to register service in session bus
82         var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
83                                               new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
84         assert ((uint) request_result.get_child_value (0) == 1);
86         // server ready, spawn client
87         Pid client_pid;
88         Process.spawn_async (null, { "test", "/dbus/errors/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
89         ChildWatch.add (client_pid, client_exit);
91         main_loop = new MainLoop ();
92         main_loop.run ();