[vala/staging] tests: Add "GObject and GType class lifetime" tests to increase coverage



commit 529cf21366cb895e1ad111ee8aa5675df791ea9f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Feb 18 15:03:42 2020 +0100

    tests: Add "GObject and GType class lifetime" tests to increase coverage

 tests/Makefile.am                         |  2 ++
 tests/objects/gobject-class-lifetime.vala | 38 +++++++++++++++++++++++++++++++
 tests/objects/gtype-class-lifetime.vala   | 21 +++++++++++++++++
 3 files changed, 61 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 071935bd1..69456f5bd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -352,7 +352,9 @@ TESTS = \
        objects/initially-unowned.vala \
        objects/field-leading-digit.test \
        objects/fields.vala \
+       objects/gobject-class-lifetime.vala \
        objects/gsource.vala \
+       objects/gtype-class-lifetime.vala \
        objects/instance-comparison.vala \
        objects/interface_only.vala \
        objects/interface-async-base-access.vala \
diff --git a/tests/objects/gobject-class-lifetime.vala b/tests/objects/gobject-class-lifetime.vala
new file mode 100644
index 000000000..85de17090
--- /dev/null
+++ b/tests/objects/gobject-class-lifetime.vala
@@ -0,0 +1,38 @@
+int pos;
+
+class Foo : Object {
+       public Foo () {
+               assert (++pos == 3);
+               print ("%i. new\n", pos);
+       }
+
+       // GObjectClass.constructor()
+       construct {
+               assert (++pos == 1);
+               print ("%i. constructor\n", pos);
+       }
+
+       // GObjectClass.finalize()
+       ~Foo () {
+               assert (++pos == 5);
+               print ("%i. finalize\n", pos);
+       }
+
+       public override void constructed () {
+               assert (++pos == 2);
+               print ("%i. constructed\n", pos);
+       }
+
+       public override void dispose () {
+               assert (++pos == 4);
+               print ("%i. dispose\n", pos);
+       }
+}
+
+void main () {
+       pos = 0;
+       {
+               var foo = new Foo ();
+       }
+       assert (pos == 5);
+}
diff --git a/tests/objects/gtype-class-lifetime.vala b/tests/objects/gtype-class-lifetime.vala
new file mode 100644
index 000000000..0c891e7a7
--- /dev/null
+++ b/tests/objects/gtype-class-lifetime.vala
@@ -0,0 +1,21 @@
+int pos;
+
+class Foo {
+       public Foo () {
+               assert (++pos == 1);
+               print ("%i. new\n", pos);
+       }
+
+       ~Foo () {
+               assert (++pos == 2);
+               print ("%i. finalize\n", pos);
+       }
+}
+
+void main () {
+       pos = 0;
+       {
+               var foo = new Foo ();
+       }
+       assert (pos == 2);
+}


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