From: Rico Tzschichholz Date: Tue, 12 Nov 2019 22:49:35 +0000 (+0100) Subject: test: Add "GLib.Closure parameter" test to increase coverage X-Git-Tag: 0.47.2~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07ff8734d0712921787681d20e59cc1531cdf7af;p=thirdparty%2Fvala.git test: Add "GLib.Closure parameter" test to increase coverage --- 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"); +}