From: Jürg Billeter Date: Sun, 21 Mar 2010 19:30:17 +0000 (+0100) Subject: D-Bus: Add simple signal test X-Git-Tag: 0.8.0~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21065d0e72f628f05e6dd64c76498da4504b1b61;p=thirdparty%2Fvala.git D-Bus: Add simple signal test --- diff --git a/tests/Makefile.am b/tests/Makefile.am index a71eda75e..661de874f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -83,6 +83,7 @@ TESTS = \ dbus/arrays.test \ dbus/structs.test \ dbus/async.test \ + dbus/signals.test \ dbus/bug596862.vala \ $(NULL) diff --git a/tests/dbus/signals.test b/tests/dbus/signals.test new file mode 100644 index 000000000..12f35e0a8 --- /dev/null +++ b/tests/dbus/signals.test @@ -0,0 +1,69 @@ +Packages: dbus-glib-1 + +Program: client + +[DBus (name = "org.example.Test")] +interface Test : Object { + public signal void foo (int i); + + public abstract void do_foo (int i) throws DBus.Error; +} + +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.foo.connect ((i) => { + assert (i == 42); + main_loop.quit (); + }); + + test.do_foo (42); + + main_loop = new MainLoop (); + main_loop.run (); +} + +Program: server + +[DBus (name = "org.example.Test")] +class Test : Object { + public signal void foo (int i); + + public void do_foo (int i) { + this.foo (i); + } +} + +MainLoop main_loop; + +void client_exit (Pid pid, int status) { + // client finished, terminate server + assert (status == 0); + main_loop.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"); + + // 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); + + // 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 (); +}