summaryrefslogtreecommitdiff
path: root/tests/dbus
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2010-03-21 20:30:17 +0100
committerJürg Billeter <j@bitron.ch>2010-03-21 20:30:53 +0100
commit21065d0e72f628f05e6dd64c76498da4504b1b61 (patch)
tree88ccb10f6365965361bf0325cb8f841e8354cb27 /tests/dbus
parent46e22cd13bfab93ab50ac02d2636e3b8712ce0c5 (diff)
downloadvala-21065d0e72f628f05e6dd64c76498da4504b1b61.tar.gz
D-Bus: Add simple signal test
Diffstat (limited to 'tests/dbus')
-rw-r--r--tests/dbus/signals.test69
1 files changed, 69 insertions, 0 deletions
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 ();
+}