]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
tests: Add "properties in structs" test to increase coverage
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 28 Apr 2021 19:33:10 +0000 (21:33 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 28 Apr 2021 20:01:49 +0000 (22:01 +0200)
tests/Makefile.am
tests/structs/properties.vala [new file with mode: 0644]

index b5a1acf04dcbac3c5fbcc65a5dc0af30b398da7a..64e7101cf90f010894a6e03e8e1834c40ebd0b26 100644 (file)
@@ -346,6 +346,7 @@ TESTS = \
        structs/gtype-base-struct.vala \
        structs/gvalue.vala \
        structs/gvalue-implicit-comparison.vala \
+       structs/properties.vala \
        structs/simple-type-constructor.vala \
        structs/simple-type-disposable.test \
        structs/bug530605.vala \
diff --git a/tests/structs/properties.vala b/tests/structs/properties.vala
new file mode 100644 (file)
index 0000000..60991af
--- /dev/null
@@ -0,0 +1,35 @@
+struct Foo {
+       public int i { get; set; }
+       public string s { get; set; }
+       public string os { owned get; set; }
+
+       public string s_get {
+               get {
+                       return _s;
+               }
+       }
+
+       public string s_set {
+               set {
+                       _s = value;
+               }
+       }
+}
+
+void main () {
+       {
+               Foo foo = { 23, "foo", "bar" };
+               assert (foo.i == 23);
+               assert (foo.s == "foo");
+               assert (foo.s_get == "foo");
+               assert (foo.os == "bar");
+
+               foo.i = 42;
+               foo.s_set = "bar";
+               foo.os = "manam";
+               assert (foo.i == 42);
+               assert (foo.s == "bar");
+               assert (foo.s_get == "bar");
+               assert (foo.os == "manam");
+       }
+}