[vala/0.52] tests: Add runtime checks to signals tests and increase coverage



commit 8654caff88a185cf82967e65b568c1550e45d110
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Nov 25 20:22:00 2021 +0100

    tests: Add runtime checks to signals tests and increase coverage

 tests/objects/signals.vala | 37 ++++++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/tests/objects/signals.vala b/tests/objects/signals.vala
index 3e9764d94..9de25ac83 100644
--- a/tests/objects/signals.vala
+++ b/tests/objects/signals.vala
@@ -1,5 +1,7 @@
 using GLib;
 
+int counter;
+
 class Maman.Foo : Object {
        public signal void activated (bool b);
 
@@ -11,66 +13,81 @@ class Maman.Foo : Object {
 class Maman.Bar : Object {
        void activated (Foo foo, bool b) {
                if (b) {
-                       stdout.printf (" BAD");
+                       assert_not_reached ();
                } else {
                        stdout.printf (" 5");
+                       assert (++counter == 5);
                }
        }
 
        public void run () {
                stdout.printf (" 2");
+               assert (++counter == 2);
 
                var foo = new Foo ();
 
                foo.activated.connect ((foo, b) => {
                        if (b) {
                                stdout.printf (" 8");
+                               assert (++counter == 8);
                        } else {
                                stdout.printf (" 4");
+                               assert (++counter == 4);
                        }
                });
 
                foo.activated.connect (activated);
 
                stdout.printf (" 3");
+               assert (++counter == 3);
 
                foo.do_action (false);
 
                stdout.printf (" 6");
+               assert (++counter == 6);
 
                foo.activated.disconnect (activated);
 
                stdout.printf (" 7");
+               assert (++counter == 7);
 
                foo.do_action (true);
 
                stdout.printf (" 9");
+               assert (++counter == 9);
        }
 }
 
 class Maman.UserFoo : Object {
-       public signal void activated (int i1, int i2);
+       public signal void activated (int i1, int i2, out int i3);
 
        public void do_action () {
-               activated (6, -2);
+               int i;
+               activated (6, -2, out i);
+               assert (i == 4);
        }
 }
 
 class Maman.UserBar : Object {
        public void run () {
                stdout.printf (" 2");
+               assert (++counter == 2);
 
                var foo = new UserFoo ();
 
-               foo.activated.connect ((foo, i1, i2) => {
+               foo.activated.connect ((foo, i1, i2, out i3) => {
                        stdout.printf (" %d", i1 + i2);
+                       i3 = i1 + i2;
+                       assert (++counter == 4);
                });
 
                stdout.printf (" 3");
+               assert (++counter == 3);
 
                foo.do_action ();
 
                stdout.printf (" 5");
+               assert (++counter == 5);
        }
 }
 
@@ -82,29 +99,36 @@ class Maman.ReturnFoo : Object {
 class Maman.ReturnBar : Object {
        public void run () {
                stdout.printf (" 2");
+               assert (++counter == 2);
 
                var foo = new ReturnFoo ();
 
                foo.int_activated.connect ((foo, arg) => {
                        stdout.printf (" %d", arg);
+                       assert (++counter == 3);
                        return arg + 1;
                });
 
                foo.string_activated.connect ((foo, arg) => {
                        stdout.printf (arg);
+                       assert (++counter == 5);
                        return " 6";
                });
 
                stdout.printf (" %d", foo.int_activated (3));
+               assert (++counter == 4);
 
                stdout.printf (foo.string_activated (" 5"));
+               assert (++counter == 6);
 
                stdout.printf (" 7");
+               assert (++counter == 7);
        }
 }
 
 void main () {
        stdout.printf ("Signal Test: 1");
+       counter = 1;
 
        var bar = new Maman.Bar ();
        bar.run ();
@@ -112,17 +136,20 @@ void main () {
        stdout.printf (" 10\n");
 
        stdout.printf ("User Signal Test: 1");
+       counter = 1;
 
        var user_bar = new Maman.UserBar ();
        user_bar.run ();
 
        stdout.printf (" 6\n");
+       assert (++counter == 6);
 
        stdout.printf ("Signal Return Test: 1");
+       counter = 1;
 
        var return_bar = new Maman.ReturnBar ();
        return_bar.run ();
 
        stdout.printf (" 8\n");
+       assert (++counter == 8);
 }
-


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