]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
D-Bus: Test arrays
authorJürg Billeter <j@bitron.ch>
Mon, 15 Jun 2009 11:32:15 +0000 (13:32 +0200)
committerJürg Billeter <j@bitron.ch>
Mon, 15 Jun 2009 11:57:09 +0000 (13:57 +0200)
tests/Makefile.am
tests/dbus/arrays.test [new file with mode: 0644]

index 6e113eeea612555cfc00f5492a22dff7d97bf510..2d69f96d5a33ac401a229e7cf537a7ac653f8c12 100644 (file)
@@ -42,6 +42,7 @@ TESTS = \
        objects/test-034.test \
        errors/errors.test \
        dbus/basic-types.test \
+       dbus/arrays.test \
        $(NULL)
 
 EXTRA_DIST = \
diff --git a/tests/dbus/arrays.test b/tests/dbus/arrays.test
new file mode 100644 (file)
index 0000000..4d6e9ec
--- /dev/null
@@ -0,0 +1,86 @@
+Packages: dbus-glib-1
+
+Program: client
+
+[DBus (name = "org.example.Test")]
+interface Test : Object {
+       public abstract string[] test_property { owned get; set; }
+
+       public abstract int[] test_int (int[] i, out int[] j);
+       public abstract string[] test_string (string[] s, out string[] t);
+}
+
+void main () {
+       var conn = DBus.Bus.get (DBus.BusType.SESSION);
+
+       // client
+       var test = (Test) conn.get_object ("org.example.Test", "/org/example/test");
+
+       int[] j, k;
+       k = test.test_int ({ 42 }, out j);
+       assert (j.length == 1 && j[0] == 23);
+       assert (k.length == 1 && k[0] == 11);
+
+       string[] t, u;
+       u = test.test_string ({ "hello" }, out t);
+       assert (t.length == 1 && t[0] == "world");
+       assert (u.length == 1 && u[0] == "vala");
+
+       test.test_property = { "hello" };
+       t = test.test_property;
+       assert (t.length == 1 && t[0] == "hello");
+}
+
+Program: server
+
+[DBus (name = "org.example.Test")]
+class Test : Object {
+       public string[] test_property { owned get; set; }
+
+       public int[] test_int (int[] i, out int[] j) {
+               assert (i.length == 1 && i[0] == 42);
+               j = { 23 };
+               return { 11 };
+       }
+
+       public string[] test_string (string[] s, out string[] t) {
+               assert (s.length == 1 && s[0] == "hello");
+               t = { "world" };
+               return { "vala" };
+       }
+}
+
+MainLoop main_loop;
+int exit_status;
+
+void client_exit (Pid pid, int status) {
+       // client finished, terminate server
+       if (status != 0) {
+               exit_status = 1;
+       }
+       main_loop.quit ();
+}
+
+int main () {
+       var conn = DBus.Bus.get (DBus.BusType.SESSION);
+       dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus");
+
+       // try to register service in session bus
+       uint request_name_result = bus.request_name ("org.example.Test", (uint) 0);
+       if (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER) {
+               // start server
+               var server = new Test ();
+               conn.register_object ("/org/example/test", server);
+
+               // server ready, spawn client
+               Pid client_pid;
+               Process.spawn_async (null, { "client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
+               ChildWatch.add (client_pid, client_exit);
+
+               main_loop = new MainLoop (null, false);
+               main_loop.run ();
+       } else {
+               exit_status = 1;
+       }
+       return exit_status;
+}