--pkg gio-2.0 \
test-codegen.xml.vala; \
tail -n +3 test-codegen.xml.vala | diff -wu $(srcdir)/test-codegen.xml.vala-expected - || exit 1; \
- rm -f test-codegen.xml.vala test-codegen.xml.c
+ rm -f test-codegen.xml.vala test-codegen.xml.c; \
+ $(top_builddir)/dbusgen/valadbusgen \
+ --vapidir $(top_srcdir)/vapi \
+ runtime-test-dbus.xml; \
+ $(top_builddir)/compiler/valac \
+ --vapidir $(top_srcdir)/vapi \
+ --pkg gio-2.0 \
+ runtime-test-server.vala \
+ runtime-test-dbus.xml.vala 2>/dev/null; \
+ $(top_builddir)/compiler/valac \
+ --vapidir $(top_srcdir)/vapi \
+ --pkg gio-2.0 \
+ runtime-test.vala \
+ runtime-test-dbus.xml.vala 2>/dev/null; \
+ ./runtime-test-server & \
+ ./runtime-test; \
+ rm -f runtime-test runtime-test-dbus.xml.vala runtime-test-server
+
check: check-dbusgen
EXTRA_DIST = \
test-codegen.xml \
test-codegen.xml.vala-expected \
+ runtime-test.vala \
+ runtime-test-dbus.xml \
+ runtime-test-server.vala \
$(NULL)
CLEANFILES = \
test-codegen.xml.c \
test-codegen.xml.vala \
+ runtime-test \
+ runtime-test-server \
+ runtime-test-dbus.xml.vala \
$(NULL)
--- /dev/null
+<node>
+ <interface name="org.gnome.Example">
+ <method name="RetInt">
+ <arg name="ret" type="t" direction="out"/>
+ </method>
+ <method name="RetString">
+ <arg name="ret" type="s" direction="out"/>
+ </method>
+ <method name="RetDict">
+ <arg name="ret" type="a{sv}" direction="out"/>
+ </method>
+ <method name="RetArray">
+ <arg name="ret" type="at" direction="out"/>
+ </method>
+ <method name="RetObject">
+ <arg name="ret" type="(ii(si))" direction="out"/>
+ </method>
+ <method name="Exit">
+ </method>
+ </interface>
+</node>
--- /dev/null
+/* runtime-test-server.vala
+ *
+ * Copyright 2022 JCWasmx86 <JCWasmx86@t-online.de>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+[DBus (name = "org.gnome.Example")]
+class DbusTestServer : GLib.Object, OrgGnomeExample {
+ public void ret_int (out uint64 ret) throws GLib.DBusError, GLib.IOError {
+ ret = 42;
+ }
+ public void ret_string (out string ret) throws GLib.DBusError, GLib.IOError {
+ // Unicode test
+ ret = "Vala💙äöüß";
+ }
+ public void ret_dict (out GLib.HashTable<string,GLib.Variant> ret) throws GLib.DBusError, GLib.IOError {
+ ret = new GLib.HashTable<string, Variant> (str_hash, str_equal);
+ ret["a_bool"] = new Variant.boolean (true);
+ ret["a_int"] = new Variant.int64 (-1);
+ ret["a_string"] = new Variant.string ("string");
+ }
+
+ public void ret_array (out uint64[] ret) throws GLib.DBusError, GLib.IOError {
+ ret = new uint64[5];
+ ret[0] = 3;
+ ret[1] = 1;
+ ret[2] = 4;
+ ret[3] = 1;
+ ret[4] = 5;
+ }
+ public void ret_object (out DBusProxyStruct_1ii_1si1_1_ ret) throws GLib.DBusError, GLib.IOError {
+ ret = DBusProxyStruct_1ii_1si1_1_ () {
+ arg0 = -1,
+ arg1 = 5,
+ arg2 = DBusProxyStruct_1si1_ () {
+ arg0 = "foo",
+ arg1 = -1,
+ }
+ };
+ }
+ public void exit () throws GLib.DBusError, GLib.IOError {
+ Process.exit (0);
+ }
+}
+
+void on_bus_aquired (DBusConnection conn) {
+ try {
+ conn.register_object ("/org/gnome/Example", new DbusTestServer ());
+ } catch (IOError e) {
+ stderr.printf ("Could not register service\n");
+ }
+}
+
+int main () {
+ Bus.own_name (BusType.SESSION, "org.gnome.Example", BusNameOwnerFlags.REPLACE, on_bus_aquired, null, () => {
+ info ("Lost connection");
+ });
+ new MainLoop ().run ();
+ return 0;
+}
--- /dev/null
+/* runtime-test.vala
+ *
+ * Copyright 2022 JCWasmx86 <JCWasmx86@t-online.de>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+int main () {
+ OrgGnomeExample example;
+ try {
+ example = Bus.get_proxy_sync (BusType.SESSION, "org.gnome.Example",
+ "/org/gnome/Example");
+ uint64 r_int;
+ example.ret_int (out r_int);
+ assert (r_int == 42);
+ string r_string;
+ example.ret_string (out r_string);
+ assert (r_string == "Vala💙äöüß");
+ GLib.HashTable<string, Variant> r_dict;
+ example.ret_dict (out r_dict);
+ assert (r_dict.length == 3);
+ assert (r_dict["a_bool"].get_boolean ());
+ assert (r_dict["a_int"].get_int64 () == -1);
+ assert (r_dict["a_string"].get_string () == "string");
+ uint64[] r_array;
+ example.ret_array (out r_array);
+ assert (r_array.length == 5);
+ assert (r_array[0] == 3 && r_array[1] == 1 && r_array[2] == 4 && r_array[3] == 1 && r_array[4] == 5);
+ DBusProxyStruct_1ii_1si1_1_ r_obj;
+ example.ret_object (out r_obj);
+ assert (r_obj.arg0 == -1);
+ assert (r_obj.arg1 == 5);
+ assert (r_obj.arg2.arg0 == "foo");
+ assert (r_obj.arg2.arg1 == -1);
+
+ } catch (Error e) {
+ error ("Caught error: %s", e.message);
+ }
+ try {
+ example.exit ();
+ } catch (Error e) {
+ // Ignore, as it is expected to throw exception
+ }
+ return 0;
+}