]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Test marshalling of basic types over D-Bus
authorJürg Billeter <j@bitron.ch>
Fri, 16 Jan 2009 15:39:35 +0000 (15:39 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 16 Jan 2009 15:39:35 +0000 (15:39 +0000)
2009-01-16  Jürg Billeter  <j@bitron.ch>

* tests/Makefile.am:
* tests/dbus/basic-types.test:

Test marshalling of basic types over D-Bus

svn path=/trunk/; revision=2351

ChangeLog
tests/Makefile.am
tests/dbus/basic-types.test [new file with mode: 0644]

index 19f5f13307a84faf650120e088136741865346d6..86bdb39b606f18f107283ab00a3429f74ae65212 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-01-16  Jürg Billeter  <j@bitron.ch>
+
+       * tests/Makefile.am:
+       * tests/dbus/basic-types.test:
+
+       Test marshalling of basic types over D-Bus
+
 2009-01-16  Jürg Billeter  <j@bitron.ch>
 
        * vala/valafield.vala:
index 5fd31e791886f39a61393e11c3dbfc9e644ff6ea..a7bf6aa52a6098699cb75648bd77782f51c2fe36 100644 (file)
@@ -40,6 +40,7 @@ TESTS = \
        objects/test-029.test \
        objects/test-034.test \
        errors/errors.test \
+       dbus/basic-types.test \
        $(NULL)
 
 EXTRA_DIST = \
diff --git a/tests/dbus/basic-types.test b/tests/dbus/basic-types.test
new file mode 100644 (file)
index 0000000..9f142e9
--- /dev/null
@@ -0,0 +1,78 @@
+Packages: dbus-glib-1
+
+Program: client
+
+[DBus (name = "org.example.Test")]
+interface Test : Object {
+    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 == 23);
+       assert (k == 11);
+
+       string t, u;
+       u = test.test_string ("hello", out t);
+       assert (t == "world");
+       assert (u == "vala");
+}
+
+Program: server
+
+[DBus (name = "org.example.Test")]
+class Test : Object {
+    public int test_int (int i, out int j) {
+       assert (i == 42);
+       j = 23;
+       return 11;
+    }
+
+    public string test_string (string s, out string t) {
+       assert (s == "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;
+}