summaryrefslogtreecommitdiff
path: root/tests/delegates
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-11-12 23:49:35 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2019-11-12 23:49:35 +0100
commit07ff8734d0712921787681d20e59cc1531cdf7af (patch)
treef2dc7baa2b957da2dd488e0802748f7db499359d /tests/delegates
parentbd5c49969e4d80f6c58b670a6317cd3914e2b358 (diff)
downloadvala-07ff8734d0712921787681d20e59cc1531cdf7af.tar.gz
test: Add "GLib.Closure parameter" test to increase coverage
Diffstat (limited to 'tests/delegates')
-rw-r--r--tests/delegates/gclosure-conversion.vala30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/delegates/gclosure-conversion.vala b/tests/delegates/gclosure-conversion.vala
new file mode 100644
index 000000000..7df324a3a
--- /dev/null
+++ b/tests/delegates/gclosure-conversion.vala
@@ -0,0 +1,30 @@
+class Foo : Object {
+ public string foo { get; set; }
+}
+
+class Bar : Object {
+ public int bar { get; set; }
+}
+
+bool to_int (Binding b, Value from, ref Value to) {
+ to.set_int (from.get_string ().to_int ());
+ return true;
+}
+
+bool to_string (Binding b, Value from, ref Value to) {
+ to.set_string (from.get_int ().to_string ());
+ return true;
+}
+
+void main () {
+ var foo = new Foo ();
+ var bar = new Bar ();
+
+ foo.bind_property ("foo", bar, "bar", BindingFlags.BIDIRECTIONAL,
+ (BindingTransformFunc) to_int, (BindingTransformFunc) to_string);
+
+ foo.foo = "42";
+ assert (bar.bar == 42);
+ bar.bar = 23;
+ assert (foo.foo == "23");
+}