From: Rico Tzschichholz Date: Mon, 2 Sep 2019 08:21:05 +0000 (+0200) Subject: tests: Add dedicated "property ownership" tests X-Git-Tag: 0.46.0~16 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=6e38fba613cf7c930938a3129aa3dc7e1d67225f;p=thirdparty%2Fvala.git tests: Add dedicated "property ownership" tests --- diff --git a/tests/Makefile.am b/tests/Makefile.am index a5bf21ec8..093ee5863 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -319,6 +319,7 @@ TESTS = \ objects/plugin-module-init.vala \ objects/properties.vala \ objects/property-notify.vala \ + objects/property-ownership.vala \ objects/property-read-only-auto.vala \ objects/property-read-only-write.test \ objects/property-construct-only-write.test \ diff --git a/tests/objects/property-ownership.vala b/tests/objects/property-ownership.vala new file mode 100644 index 000000000..4fa177586 --- /dev/null +++ b/tests/objects/property-ownership.vala @@ -0,0 +1,89 @@ +class Foo : Object { +} + +class Bar : Object { + public Foo foo { get; set; } + public Foo foo_owned { owned get; set; } + public weak Foo foo_weak { get; set; } + public weak Foo foo_weak_owned { owned get; set; } +} + +class Manam { + public Foo foo { get; set; } + public Foo foo_owned { owned get; set; } + public weak Foo foo_weak { get; set; } + public weak Foo foo_weak_owned { owned get; set; } +} + +void main () { + var foo = new Foo (); + assert (foo.ref_count == 1); + + //GObject class + { + var bar = new Bar (); + bar.foo = foo; + assert (foo.ref_count == 2); + unowned Foo f = bar.foo; + assert (foo.ref_count == 2); + } + assert (foo.ref_count == 1); + { + var bar = new Bar (); + bar.foo_owned = foo; + assert (foo.ref_count == 2); + Foo f = bar.foo_owned; + assert (foo.ref_count == 3); + } + assert (foo.ref_count == 1); + { + var bar = new Bar (); + bar.foo_weak = foo; + assert (foo.ref_count == 1); + unowned Foo f_weak = bar.foo_weak; + assert (foo.ref_count == 1); + } + assert (foo.ref_count == 1); + { + var bar = new Bar (); + bar.foo_weak_owned = foo; + assert (foo.ref_count == 1); + Foo f_weak_owned = bar.foo_weak_owned; + assert (foo.ref_count == 2); + } + assert (foo.ref_count == 1); + + //GType class + { + var manam = new Manam (); + manam.foo = foo; + assert (foo.ref_count == 2); + unowned Foo f = manam.foo; + assert (foo.ref_count == 2); + } + assert (foo.ref_count == 1); + { + var manam = new Manam (); + manam.foo_owned = foo; + assert (foo.ref_count == 2); + Foo f = manam.foo_owned; + assert (foo.ref_count == 3); + } + assert (foo.ref_count == 1); + { + var manam = new Manam (); + manam.foo_weak = foo; + assert (foo.ref_count == 1); + unowned Foo f_weak = manam.foo_weak; + assert (foo.ref_count == 1); + } + assert (foo.ref_count == 1); + { + var manam = new Manam (); + manam.foo_weak_owned = foo; + assert (foo.ref_count == 1); + Foo f_weak_owned = manam.foo_weak_owned; + assert (foo.ref_count == 2); + } + assert (foo.ref_count == 1); +}