Release 0.41.92
[vala-gnome.git] / tests / dbus / basic-types.test
blobdbe63b13a467a5aac29b45c689e328ec5b71868a
1 Packages: gio-2.0
2 D-Bus
4 Program: client
6 [DBus (name = "org.example.Test")]
7 interface Test : Object {
8         public abstract string test_property { owned get; set; }
9         public abstract int test_int_property { get; set; }
11         public abstract void test_void () throws IOError;
12         public abstract int test_int (int i, out int j) throws IOError;
13         public abstract string test_string (string s, out string t) throws IOError;
16 void main () {
17         // client
18         Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test", DBusProxyFlags.DO_NOT_LOAD_PROPERTIES);
20         test.test_void ();
22         int j, k;
23         k = test.test_int (42, out j);
24         assert (j == 23);
25         assert (k == 11);
27         string t, u;
28         u = test.test_string ("hello", out t);
29         assert (t == "world");
30         assert (u == "vala");
32         test.test_property = "hello";
33         t = test.test_property;
34         assert (t == "hello");
36         test.test_int_property = 42;
37         j = test.test_int_property;
38         assert (j == 42);
41 Program: server
43 [DBus (name = "org.example.Test")]
44 class Test : Object {
45         public string test_property { owned get; set; }
46         public int test_int_property { get; set; }
48         public void test_void () {
49         }
51         public int test_int (int i, out int j) {
52                 assert (i == 42);
53                 j = 23;
54                 return 11;
55         }
57         public string test_string (string s, out string t) {
58                 assert (s == "hello");
59                 t = "world";
60                 return "vala";
61         }
64 MainLoop main_loop;
66 void client_exit (Pid pid, int status) {
67         // client finished, terminate server
68         assert (status == 0);
69         main_loop.quit ();
72 void main () {
73         var conn = Bus.get_sync (BusType.SESSION);
74         conn.register_object ("/org/example/test", new Test ());
76         // try to register service in session bus
77         var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
78                                               new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
79         assert ((uint) request_result.get_child_value (0) == 1);
81         // server ready, spawn client
82         Pid client_pid;
83         Process.spawn_async (null, { "test", "/dbus/basic-types/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
84         ChildWatch.add (client_pid, client_exit);
86         main_loop = new MainLoop ();
87         main_loop.run ();