Release 0.41.92
[vala-gnome.git] / tests / dbus / bug782719.test
blobfe52eb3e2c6d3d8964a63bfcd3aed6c8019823b0
1 Packages: gio-2.0
2 D-Bus
4 Program: client
6 [DBus (name = "org.example.Test")]
7 interface Test : Object {
8         public abstract HashTable<string, HashTable<string, Variant>> test_nested_dict () throws IOError;
11 void main () {
12         // client
13         Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
15         HashTable<string, HashTable<string, Variant>> dict = test.test_nested_dict ();
16         assert (dict.size () == 1);
17         HashTable<string, Variant> nested_dict = dict.lookup ("hello");
18         assert (nested_dict != null);
19         Variant v = nested_dict.lookup ("hello");
20         assert (v != null);
21         string[] s = (string[]) v;
22         assert (s.length == 1 && s[0] == "hello");
25 Program: server
27 [DBus (name = "org.example.Test")]
28 class Test : Object {
29         public HashTable<string, HashTable<string, Variant>> test_nested_dict () {
30                 string[] s = { "hello" };
31                 HashTable<string, Variant> nested_dict = new HashTable<string, Variant> (str_hash, null);
32                 nested_dict.insert ("hello", s);
33                 HashTable<string, HashTable<string, Variant>> dict = new HashTable<string, HashTable<string, Variant>> (str_hash, null);
34                 dict.insert ("hello", nested_dict);
35                 return dict;
36         }
39 MainLoop main_loop;
41 void client_exit (Pid pid, int status) {
42         // client finished, terminate server
43         assert (status == 0);
44         main_loop.quit ();
47 void main () {
48         var conn = Bus.get_sync (BusType.SESSION);
49         conn.register_object ("/org/example/test", new Test ());
51         // try to register service in session bus
52         var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
53                                               new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
54         assert ((uint) request_result.get_child_value (0) == 1);
56         // server ready, spawn client
57         Pid client_pid;
58         Process.spawn_async (null, { "test", "/dbus/bug782719/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
59         ChildWatch.add (client_pid, client_exit);
61         main_loop = new MainLoop ();
62         main_loop.run ();