[vala/staging: 3/4] test: Add "GLib.Closure parameter" test to increase coverage



commit 07ff8734d0712921787681d20e59cc1531cdf7af
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Nov 12 23:49:35 2019 +0100

    test: Add "GLib.Closure parameter" test to increase coverage

 tests/Makefile.am                        |  1 +
 tests/delegates/gclosure-conversion.vala | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b9dd5bf38..3d0cef528 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -282,6 +282,7 @@ TESTS = \
        delegates/error-pos.vala \
        delegates/fields.vala \
        delegates/fields-no-target.vala \
+       delegates/gclosure-conversion.vala \
        delegates/incompatible.test \
        delegates/incompatible-assignment.test \
        delegates/incompatible-initializer.test \
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");
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]