summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2020-03-17 15:26:36 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2020-03-17 15:35:01 +0100
commit5a97fa5a1b56e3a942f01d21efc203da25187d03 (patch)
treecfb66fa7d9fb83e880517583ba8a1009a1f233d3 /tests
parent2684574fcbd9d866e53f6e03aeb785d74a8fe9ac (diff)
downloadvala-5a97fa5a1b56e3a942f01d21efc203da25187d03.tar.gz
codegen: Improve handling of "array_length_type" attribute
This affects methods, parameters, field and properties. Fixes https://gitlab.gnome.org/GNOME/vala/issues/938
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/methods/array-length-type.vala156
2 files changed, 157 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 893392b94..464e61647 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -114,6 +114,7 @@ TESTS = \
chainup/struct-this-foo.vala \
chainup/bug791785.vala \
pointers/bug590641.vala \
+ methods/array-length-type.vala \
methods/lambda.vala \
methods/closures.vala \
methods/contains.vala \
diff --git a/tests/methods/array-length-type.vala b/tests/methods/array-length-type.vala
new file mode 100644
index 000000000..942bd5fcd
--- /dev/null
+++ b/tests/methods/array-length-type.vala
@@ -0,0 +1,156 @@
+[CCode (array_length_type = "guint8")]
+delegate int[] FooFunc ([CCode (array_length_type = "guint8")] owned int[] p);
+
+interface IFoo {
+ [CCode (array_length_type = "guint8")]
+ public abstract int[] manam { get; set; }
+
+ [CCode (array_length_type = "guint8")]
+ public abstract int[] get_foo ();
+ public abstract void set_foo ([CCode (array_length_type = "guint8")] out int[] p);
+}
+
+class Foo : IFoo {
+ public int[] manam { get; set; }
+
+ [CCode (array_length_type = "guint8")]
+ public virtual int[] manar { get; set; }
+
+ public int[] get_foo () {
+ var res = new int[255];
+ res[254] = 4711;
+ return res;
+ }
+
+ public void set_foo (out int[] p) {
+ p = new int[255];
+ p[254] = 4711;
+ }
+
+ [CCode (array_length_type = "guint8")]
+ public virtual int[] get_bar () {
+ var res = new int[255];
+ res[254] = 4711;
+ return res;
+ }
+
+ public virtual void set_bar ([CCode (array_length_type = "guint8")] out int[] p) {
+ p = new int[255];
+ p[254] = 4711;
+ }
+
+ public Foo () {
+ {
+ var a = get_foo ();
+ assert (a.length == 255);
+ assert (a[254] == 4711);
+ }
+ {
+ int[] a = null;
+ set_foo (out a);
+ assert (a.length == 255);
+ assert (a[254] == 4711);
+ }
+ }
+}
+
+class Bar : Foo {
+ public override int[] manar { get; set; }
+
+ public override int[] get_bar () {
+ var res = new int[255];
+ res[254] = 4711;
+ return res;
+ }
+
+ public override void set_bar (out int[] p) {
+ p = new int[255];
+ p[254] = 4711;
+ }
+
+ public Bar () {
+ {
+ var a = get_foo ();
+ assert (a.length == 255);
+ assert (a[254] == 4711);
+ }
+ {
+ int[] a = null;
+ set_foo (out a);
+ assert (a.length == 255);
+ assert (a[254] == 4711);
+ }
+ {
+ var a = get_bar ();
+ assert (a.length == 255);
+ assert (a[254] == 4711);
+ }
+ {
+ int[] a = null;
+ set_bar (out a);
+ assert (a.length == 255);
+ assert (a[254] == 4711);
+ }
+ }
+}
+
+[CCode (array_length_type = "guint8")]
+int[] get_foo () {
+ var res = new int[255];
+ res[254] = 4711;
+ return res;
+}
+
+void set_foo ([CCode (array_length_type = "guint8")] out int[] p) {
+ p = new int[255];
+ p[254] = 4711;
+}
+
+[CCode (array_length_type = "guint8")]
+int[] foo_func ([CCode (array_length_type = "guint8")] owned int[] p) {
+ return p;
+}
+
+void main () {
+ {
+ FooFunc f = (a) => { return a; };
+ int[] a = new int[255];
+ a[254] = 4711;
+ a = f ((owned) a);
+ assert (a.length == 255);
+ assert (a[254] == 4711);
+ }
+ {
+ FooFunc f = (FooFunc) foo_func;
+ int[] a = new int[255];
+ a[254] = 4711;
+ a = f ((owned) a);
+ assert (a.length == 255);
+ assert (a[254] == 4711);
+ }
+ {
+ var a = get_foo ();
+ assert (a.length == 255);
+ assert (a[254] == 4711);
+ }
+ {
+ int[] a = null;
+ set_foo (out a);
+ assert (a.length == 255);
+ assert (a[254] == 4711);
+ }
+ {
+ var foo = new Foo ();
+ foo.manam = new int[255];
+ foo.manam[254] = 4711;
+ assert (foo.manam.length == 255);
+ assert (foo.manam[254] == 4711);
+ }
+ {
+ var bar = new Bar ();
+ bar.manar = new int[255];
+ bar.manar[254] = 4711;
+ assert (bar.manar.length == 255);
+ assert (bar.manar[254] == 4711);
+ }
+}