]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
test: Add "GLib.Closure parameter" test to increase coverage
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 12 Nov 2019 22:49:35 +0000 (23:49 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 18 Nov 2019 08:33:15 +0000 (09:33 +0100)
tests/Makefile.am
tests/delegates/gclosure-conversion.vala [new file with mode: 0644]

index 6f9e5fd837e69bcd1d8ca5c34461e2a6c07b674e..4b424f87cc303bbecbbea1ffcea9b89ed30befeb 100644 (file)
@@ -279,6 +279,7 @@ TESTS = \
        delegates/error-pos.vala \
        delegates/fields.vala \
        delegates/fields-no-target.vala \
+       delegates/gclosure-conversion.vala \
        delegates/instance-method-to-no-target.test \
        delegates/lambda-mixed-instance-static.vala \
        delegates/lambda-shared-closure.vala \
diff --git a/tests/delegates/gclosure-conversion.vala b/tests/delegates/gclosure-conversion.vala
new file mode 100644 (file)
index 0000000..7df324a
--- /dev/null
@@ -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");
+}