[vala/0.40] tests: Add dedicated "property ownership" tests
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] tests: Add dedicated "property ownership" tests
- Date: Wed, 9 Oct 2019 17:33:00 +0000 (UTC)
commit f336a5d573f94be460c66d4f4c5aa845af34d896
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Sep 2 10:21:05 2019 +0200
tests: Add dedicated "property ownership" tests
tests/Makefile.am | 1 +
tests/objects/property-ownership.vala | 89 +++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 37e95951a..c0f969963 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -282,6 +282,7 @@ TESTS = \
objects/methods.vala \
objects/paramspec.vala \
objects/properties.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);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]