Release 0.41.92
[vala-gnome.git] / tests / dbus / bug735437.test
blobc2b75821ce5a4325071278dfb033e2190852fd2d
1 Packages: gio-2.0
2 D-Bus
4 Program: client
6 [DBus (name = "org.example.Test")]
7 interface Test : Object {
8         public abstract double[] array () throws DBusError, IOError;
9         public abstract double[,] multi_array () throws DBusError, IOError;
10         public abstract string[,,] multi_array2 () throws DBusError, IOError;
13 void main () {
14         // client
15         Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
17         var a = test.array ();
18         assert (a.length == 2 && a[0] == 2.0 && a[1] == 3.0);
20         var b = test.multi_array ();
21         assert (b.length[0] == 2 && b.length[1] == 2 && b[0,0] == 2.0 && b[0,1] == 3.0 && b[1,0] == 4.0 && b[1,1] == 5.0);
23         var c = test.multi_array2 ();
24         assert (c.length[0] == 2 && c.length[1] == 2 && c.length[2] == 2 && c[0,0,0] == "foo" && c[0,0,1] == "bar" && c[1,1,0] == "baz2" && c[1,1,1] == "man2");
27 Program: server
29 [DBus (name = "org.example.Test")]
30 class Test : Object {
31         public double[] array () {
32                 return new double[] { 2.0, 3.0 };
33         }
35         public double[,] multi_array () {
36                 return new double[,] { { 2.0, 3.0 }, { 4.0, 5.0 } };
37         }
39         public string[,,] multi_array2 () {
40                 return new string[,,] { { { "foo", "bar" }, { "baz", "man" } }, { { "foo2", "bar2" }, { "baz2", "man2" } } };
41         }
44 MainLoop main_loop;
46 void client_exit (Pid pid, int status) {
47         // client finished, terminate server
48         assert (status == 0);
49         main_loop.quit ();
52 void main () {
53         var conn = Bus.get_sync (BusType.SESSION);
54         conn.register_object ("/org/example/test", new Test ());
56         // try to register service in session bus
57         var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
58                                               new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
59         assert ((uint) request_result.get_child_value (0) == 1);
61         // server ready, spawn client
62         Pid client_pid;
63         Process.spawn_async (null, { "test", "/dbus/bug735437/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
64         ChildWatch.add (client_pid, client_exit);
66         main_loop = new MainLoop ();
67         main_loop.run ();