[vala/staging] tests: Add "dynamic" signal and property tests to increase coverage



commit bd0a65b8311f2cb5331dde2850cbeb3bcadebb63
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Jan 7 10:44:18 2018 +0100

    tests: Add "dynamic" signal and property tests to increase coverage

 tests/Makefile.am          |    1 +
 tests/objects/dynamic.vala |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8ba947c..26424ed 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -181,6 +181,7 @@ TESTS = \
        objects/chainup.vala \
        objects/classes.vala \
        objects/constructors.vala \
+       objects/dynamic.vala \
        objects/generics.vala \
        objects/initially-unowned.vala \
        objects/fields.vala \
diff --git a/tests/objects/dynamic.vala b/tests/objects/dynamic.vala
new file mode 100644
index 0000000..aa42943
--- /dev/null
+++ b/tests/objects/dynamic.vala
@@ -0,0 +1,35 @@
+class Foo : Object {
+       public signal void sig ();
+       public string prop { get; set; }
+}
+
+bool success = false;
+
+void sig_cb () {
+       success = true;
+}
+
+void sig_after_cb () {
+       assert (success);
+}
+
+void main () {
+       var real = new Foo ();
+       dynamic Object foo = real;
+
+       foo.prop = "foo";
+       string s = foo.prop;
+       assert (s == "foo");
+
+       success = false;
+       var id1 = foo.sig.connect_after (sig_after_cb);
+       var id2 = foo.sig.connect (sig_cb);
+       real.sig ();
+       assert (success);
+
+       success = false;
+       SignalHandler.disconnect (foo, id1);
+       SignalHandler.disconnect (foo, id2);
+       real.sig ();
+       assert (!success);
+}


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