Release 0.41.92
[vala-gnome.git] / tests / dbus / rawvariants.test
blobca80e74fb1633fbc8b5e7e12297553f9de391586
1 Packages: gio-2.0
2 D-Bus
4 Program: client
6 [DBus (name = "org.example.Test")]
7 public interface Test : Object {
8         public abstract string test_property { owned get; set; }
10         public signal void test_signal (int i);
12         public abstract int test_method (int j, int k) throws IOError;
15 [DBus (name = "org.example.Test")]
16 public interface TestRaw : Object {
17         [DBus (signature = "s")]
18         public abstract Variant test_property { owned get; set; }
20         public signal void test_signal ([DBus (signature = "i")] Variant i);
22         [DBus (signature = "i")]
23         public abstract Variant test_method ([DBus (signature = "i")] Variant j, [DBus (signature = "i")] Variant k) throws IOError;
26 void test_raw (TestRaw test) {
27         var main_loop = new MainLoop ();
29         var id = test.test_signal.connect ((var_i) => {
30                 var i = (int) var_i;
31                 assert (i == 46);
32                 main_loop.quit ();
33         });
35         int j = (int) test.test_method (23, 11);
36         assert (j == 42);
38         main_loop.run ();
39         test.disconnect (id);
41         test.test_property = "hello";
42         var s = (string) test.test_property;
43         assert (s == "hello");
46 void test (Test test) {
47         var main_loop = new MainLoop ();
49         var id = test.test_signal.connect ((i) => {
50                 assert (i == 46);
51                 main_loop.quit ();
52         });
54         int j = test.test_method (23, 11);
55         assert (j == 42);
57         main_loop.run ();
58         test.disconnect (id);
60         test.test_property = "hello";
61         var s = test.test_property;
62         assert (s == "hello");
65 void main () {
66         // raw variant server, standard client
67         Test test1 = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/testraw", DBusProxyFlags.DO_NOT_LOAD_PROPERTIES);
68         test (test1);
70         // standard server, raw variant client
71         TestRaw test2 = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test", DBusProxyFlags.DO_NOT_LOAD_PROPERTIES);
72         test_raw (test2);
74         // raw variant server, raw variant client
75         TestRaw test3 = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/testraw", DBusProxyFlags.DO_NOT_LOAD_PROPERTIES);
76         test_raw (test3);
79 Program: server
81 [DBus (name = "org.example.Test")]
82 public class Test : Object {
83         public string test_property { owned get; set; }
85         public signal void test_signal (int i);
87         public int test_method (int j, int k) {
88                 assert (j == 23);
89                 assert (k == 11);
90                 test_signal (46);
91                 return 42;
92         }
95 [DBus (name = "org.example.Test")]
96 public class TestRaw : Object {
97         [DBus (signature = "s")]
98         public Variant test_property { owned get; set; }
100         public signal void test_signal ([DBus (signature = "i")] Variant i);
102         [DBus (signature = "i")]
103         public Variant test_method ([DBus (signature = "i")] Variant j, [DBus (signature = "i")] Variant k) {
104                 assert ((int) j == 23);
105                 assert ((int) k == 11);
106                 test_signal (46);
107                 return 42;
108         }
111 MainLoop main_loop;
113 void client_exit (Pid pid, int status) {
114         // client finished, terminate server
115         assert (status == 0);
116         main_loop.quit ();
119 void main () {
120         var conn = Bus.get_sync (BusType.SESSION);
121         conn.register_object ("/org/example/test", new Test ());
122         conn.register_object ("/org/example/testraw", new TestRaw ());
124         // try to register service in session bus
125         var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
126                                               new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
127         assert ((uint) request_result.get_child_value (0) == 1);
129         // server ready, spawn client
130         Pid client_pid;
131         Process.spawn_async (null, { "test", "/dbus/rawvariants/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
132         ChildWatch.add (client_pid, client_exit);
134         main_loop = new MainLoop ();
135         main_loop.run ();