[vala/staging] tests: Add dedicated "property ownership" tests
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] tests: Add dedicated "property ownership" tests
- Date: Mon, 2 Sep 2019 08:32:12 +0000 (UTC)
commit 6e38fba613cf7c930938a3129aa3dc7e1d67225f
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 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);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]