]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
D-Bus: Port tests to GDBus
authorJürg Billeter <j@bitron.ch>
Sat, 19 Jun 2010 20:35:02 +0000 (22:35 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 20 Jun 2010 09:35:09 +0000 (11:35 +0200)
tests/dbus/arrays.test
tests/dbus/async.test
tests/dbus/basic-types.test
tests/dbus/bug596862.vala
tests/dbus/bug602003.test
tests/dbus/signals.test
tests/dbus/structs.test
tests/testrunner.sh

index f119fda459a1b01ecd1437a0f1cb172debe4e28b..64551c02638c546229cfd8c0ee7e2393e3332cde 100644 (file)
@@ -1,4 +1,5 @@
-Packages: dbus-glib-1
+Packages: gio-2.0
+D-Bus
 
 Program: client
 
@@ -6,15 +7,13 @@ Program: client
 interface Test : Object {
        public abstract string[] test_property { owned get; set; }
 
-       public abstract int[] test_int (int[] i, out int[] j) throws DBus.Error;
-       public abstract string[] test_string (string[] s, out string[] t) throws DBus.Error;
+       public abstract int[] test_int (int[] i, out int[] j) throws IOError;
+       public abstract string[] test_string (string[] s, out string[] t) throws IOError;
 }
 
 void main () {
-       var conn = DBus.Bus.get (DBus.BusType.SESSION);
-
        // client
-       var test = (Test) conn.get_object ("org.example.Test", "/org/example/test");
+       Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
 
        int[] j, k;
        k = test.test_int ({ 42 }, out j);
@@ -50,31 +49,25 @@ class Test : Object {
        }
 }
 
-MainLoop main_loop;
+Application app;
 
 void client_exit (Pid pid, int status) {
        // client finished, terminate server
        assert (status == 0);
-       main_loop.quit ();
+       app.quit ();
 }
 
 void 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");
+       var conn = Bus.get_sync (BusType.SESSION);
+       conn.register_object ("/org/example/test", new Test ());
 
        // try to register service in session bus
-       uint request_name_result = bus.request_name ("org.example.Test", (uint) 0);
-       assert (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER);
-
-       // start server
-       var server = new Test ();
-       conn.register_object ("/org/example/test", server);
+       app = new Application ("org.example.Test");
 
        // server ready, spawn client
        Pid client_pid;
        Process.spawn_async (null, { "test", "/dbus/arrays/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 ();
+       app.run ();
 }
index f23aaf9c53f6ba8254f96719a106214746252962..11c0eeeb6c3fe63a0ca3f298a050398b1d6099e3 100644 (file)
@@ -1,11 +1,12 @@
-Packages: gio-2.0 dbus-glib-1
+Packages: gio-2.0
+D-Bus
 
 Program: client
 
 [DBus (name = "org.example.Test")]
 interface Test : Object {
-       public abstract async int test_int (int i, out int j) throws DBus.Error;
-       public abstract async string test_string (string s, out string t) throws DBus.Error;
+       public abstract async int test_int (int i, out int j) throws IOError;
+       public abstract async string test_string (string s, out string t) throws IOError;
 }
 
 MainLoop main_loop;
@@ -25,10 +26,8 @@ async void run (Test test) {
 }
 
 void main () {
-       var conn = DBus.Bus.get (DBus.BusType.SESSION);
-
        // client
-       var test = (Test) conn.get_object ("org.example.Test", "/org/example/test");
+       Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
 
        run.begin (test);
 
@@ -57,31 +56,25 @@ class Test : Object {
        }
 }
 
-MainLoop main_loop;
+Application app;
 
 void client_exit (Pid pid, int status) {
        // client finished, terminate server
        assert (status == 0);
-       main_loop.quit ();
+       app.quit ();
 }
 
 void 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");
+       var conn = Bus.get_sync (BusType.SESSION);
+       conn.register_object ("/org/example/test", new Test ());
 
        // try to register service in session bus
-       uint request_name_result = bus.request_name ("org.example.Test", (uint) 0);
-       assert (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER);
-
-       // start server
-       var server = new Test ();
-       conn.register_object ("/org/example/test", server);
+       app = new Application ("org.example.Test");
 
        // server ready, spawn client
        Pid client_pid;
        Process.spawn_async (null, { "test", "/dbus/async/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 ();
+       app.run ();
 }
index 7dc6a9200918f3305d5fbe6c8b91ced00676736a..d76805353c19b8f8b67b231acb03c47fbf2c2580 100644 (file)
@@ -1,4 +1,5 @@
-Packages: dbus-glib-1
+Packages: gio-2.0
+D-Bus
 
 Program: client
 
@@ -6,15 +7,13 @@ Program: client
 interface Test : Object {
        public abstract string test_property { owned get; set; }
 
-       public abstract int test_int (int i, out int j) throws DBus.Error;
-       public abstract string test_string (string s, out string t) throws DBus.Error;
+       public abstract int test_int (int i, out int j) throws IOError;
+       public abstract string test_string (string s, out string t) throws IOError;
 }
 
 void main () {
-       var conn = DBus.Bus.get (DBus.BusType.SESSION);
-
-       // client       
-       var test = (Test) conn.get_object ("org.example.Test", "/org/example/test");
+       // client
+       Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
 
        int j, k;
        k = test.test_int (42, out j);
@@ -50,31 +49,25 @@ class Test : Object {
        }
 }
 
-MainLoop main_loop;
+Application app;
 
 void client_exit (Pid pid, int status) {
        // client finished, terminate server
        assert (status == 0);
-       main_loop.quit ();
+       app.quit ();
 }
 
 void 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");
+       var conn = Bus.get_sync (BusType.SESSION);
+       conn.register_object ("/org/example/test", new Test ());
 
        // try to register service in session bus
-       uint request_name_result = bus.request_name ("org.example.Test", (uint) 0);
-       assert (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER);
-
-       // start server
-       var server = new Test ();
-       conn.register_object ("/org/example/test", server);
+       app = new Application ("org.example.Test");
 
        // server ready, spawn client
        Pid client_pid;
        Process.spawn_async (null, { "test", "/dbus/basic-types/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 ();
+       app.run ();
 }
index fd9ec5ec71093de01e24ad125935209a578b7101..69487a0ffe279e04360cd582bb439bd81c9dc258 100644 (file)
@@ -1,6 +1,6 @@
 [DBus (name = "org.example.Test")]
 public class Foo : Object {
-        public void do_foo (Value value) {
+        public void do_foo (Variant value) {
         }
 }
 
index cf3127f42962fea1cc7bb57946e6e79e98a1eeac..e715cc12a0c0ddeb98fb9bdc05fa1e0c2c4faa3a 100644 (file)
@@ -1,19 +1,18 @@
-Packages: dbus-glib-1
+Packages: gio-2.0
+D-Bus
 
 Program: client
 
 [DBus (name = "org.example.Test")]
 interface Test : Object {
-       public abstract Value test_string () throws DBus.Error;
+       public abstract Variant test_string () throws IOError;
 }
 
 void main () {
-       var conn = DBus.Bus.get (DBus.BusType.SESSION);
-
        // client
-       var test = (Test) conn.get_object ("org.example.Test", "/org/example/test");
+       Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
 
-       Value v = test.test_string ();
+       Variant v = test.test_string ();
        string[] s = (string[]) v;
        assert (s.length == 1 && s[0] == "hello");
 }
@@ -22,37 +21,31 @@ Program: server
 
 [DBus (name = "org.example.Test")]
 class Test : Object {
-       public Value test_string () {
+       public Variant test_string () {
                string[] s = { "hello" };
                return s;
        }
 }
 
-MainLoop main_loop;
+Application app;
 
 void client_exit (Pid pid, int status) {
        // client finished, terminate server
        assert (status == 0);
-       main_loop.quit ();
+       app.quit ();
 }
 
 void 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");
+       var conn = Bus.get_sync (BusType.SESSION);
+       conn.register_object ("/org/example/test", new Test ());
 
        // try to register service in session bus
-       uint request_name_result = bus.request_name ("org.example.Test", (uint) 0);
-       assert (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER);
-
-       // start server
-       var server = new Test ();
-       conn.register_object ("/org/example/test", server);
+       app = new Application ("org.example.Test");
 
        // server ready, spawn client
        Pid client_pid;
        Process.spawn_async (null, { "test", "/dbus/bug602003/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 ();
+       app.run ();
 }
index 12f35e0a8787cf0befae9e64a2711f39cf328b0e..10df0d35312ff1311872a5c2850d45240682cbcd 100644 (file)
@@ -1,4 +1,5 @@
-Packages: dbus-glib-1
+Packages: gio-2.0
+D-Bus
 
 Program: client
 
@@ -6,16 +7,14 @@ Program: client
 interface Test : Object {
        public signal void foo (int i);
 
-       public abstract void do_foo (int i) throws DBus.Error;
+       public abstract void do_foo (int i) throws IOError;
 }
 
 MainLoop main_loop;
 
 void main () {
-       var conn = DBus.Bus.get (DBus.BusType.SESSION);
-
        // client
-       var test = (Test) conn.get_object ("org.example.Test", "/org/example/test");
+       Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
 
        test.foo.connect ((i) => {
                assert (i == 42);
@@ -39,31 +38,25 @@ class Test : Object {
        }
 }
 
-MainLoop main_loop;
+Application app;
 
 void client_exit (Pid pid, int status) {
        // client finished, terminate server
        assert (status == 0);
-       main_loop.quit ();
+       app.quit ();
 }
 
 void 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");
+       var conn = Bus.get_sync (BusType.SESSION);
+       conn.register_object ("/org/example/test", new Test ());
 
        // try to register service in session bus
-       uint request_name_result = bus.request_name ("org.example.Test", (uint) 0);
-       assert (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER);
-
-       // start server
-       var server = new Test ();
-       conn.register_object ("/org/example/test", server);
+       app = new Application ("org.example.Test");
 
        // server ready, spawn client
        Pid client_pid;
        Process.spawn_async (null, { "test", "/dbus/signals/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 ();
+       app.run ();
 }
index 744aad498732726c6b1348bdc2c3706d37521a57..8f721eb41e1179d2f6c82b5a8f861964acbea28b 100644 (file)
@@ -1,4 +1,5 @@
-Packages: dbus-glib-1
+Packages: gio-2.0
+D-Bus
 
 Program: client
 
@@ -16,14 +17,12 @@ struct FooStruct {
 interface Test : Object {
        public abstract FooStruct test_property { owned get; set; }
 
-       public abstract FooStruct test_struct (FooStruct f, out FooStruct g) throws DBus.Error;
+       public abstract FooStruct test_struct (FooStruct f, out FooStruct g) throws IOError;
 }
 
 void main () {
-       var conn = DBus.Bus.get (DBus.BusType.SESSION);
-
        // client
-       var test = (Test) conn.get_object ("org.example.Test", "/org/example/test");
+       Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
 
        FooStruct f, g, h;
        f = FooStruct (42, "hello");
@@ -63,31 +62,25 @@ class Test : Object {
        }
 }
 
-MainLoop main_loop;
+Application app;
 
 void client_exit (Pid pid, int status) {
        // client finished, terminate server
        assert (status == 0);
-       main_loop.quit ();
+       app.quit ();
 }
 
 void 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");
+       var conn = Bus.get_sync (BusType.SESSION);
+       conn.register_object ("/org/example/test", new Test ());
 
        // try to register service in session bus
-       uint request_name_result = bus.request_name ("org.example.Test", (uint) 0);
-       assert (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER);
-
-       // start server
-       var server = new Test ();
-       conn.register_object ("/org/example/test", server);
+       app = new Application ("org.example.Test");
 
        // server ready, spawn client
        Pid client_pid;
        Process.spawn_async (null, { "test", "/dbus/structs/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 ();
+       app.run ();
 }
index 5eb436b0b1046f9d3c62ebe1bd554bf6ba996ce8..175cacae122374462578e4f6375bf6b3b0ea91ae 100755 (executable)
@@ -35,12 +35,9 @@ function testheader() {
        if [ "$1" = "Packages:" ]; then
                shift
                PACKAGES="$PACKAGES $@"
-               for pkg in "$@"; do
-                       if [ "$pkg" = "dbus-glib-1" ]; then
-                               echo 'eval `dbus-launch --sh-syntax`' >> prepare
-                               echo 'trap "kill $DBUS_SESSION_BUS_PID" INT TERM EXIT' >> prepare
-                       fi
-               done
+       elif [ "$1" = "D-Bus" ]; then
+               echo 'eval `dbus-launch --sh-syntax`' >> prepare
+               echo 'trap "kill $DBUS_SESSION_BUS_PID" INT TERM EXIT' >> prepare
        fi
 }