[vala] tests: Check uchar[] and uint8[] compatibility



commit 9a43c317cb0df5d7a04591e4938f808a3ceea268
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Sep 9 13:46:19 2018 +0200

    tests: Check uchar[] and uint8[] compatibility

 tests/Makefile.am                               |  1 +
 tests/basic-types/array-uint8-uchar-compat.vala | 50 +++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d03e394c1..1b8162638 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -25,6 +25,7 @@ TESTS = \
        basic-types/floats.vala \
        basic-types/strings.vala \
        basic-types/arrays.vala \
+       basic-types/array-uint8-uchar-compat.vala \
        basic-types/pointers.vala \
        basic-types/sizeof.vala \
        basic-types/garray.vala \
diff --git a/tests/basic-types/array-uint8-uchar-compat.vala b/tests/basic-types/array-uint8-uchar-compat.vala
new file mode 100644
index 000000000..91ac3751d
--- /dev/null
+++ b/tests/basic-types/array-uint8-uchar-compat.vala
@@ -0,0 +1,50 @@
+[CCode (array_length = false)]
+uchar[] data;
+[CCode (array_length = false)]
+uint8[] data2;
+
+[CCode (array_length = false)]
+unowned uchar[] get_buffer () {
+       return data;
+}
+
+void change_buffer ([CCode (array_length = false)] uint8[] data) {
+       data[0] = 98;
+       data[1] = 97;
+       data[2] = 114;
+}
+
+[CCode (array_length = false)]
+unowned uint8[] get_buffer2 () {
+       return data2;
+}
+
+void change_buffer2 ([CCode (array_length = false)] uchar[] data) {
+       data[0] = 'b';
+       data[1] = 'a';
+       data[2] = 'z';
+}
+
+void main () {
+       {
+               data = { 'f', 'o', 'o', '\n' };
+               data2 = { 102, 111, 111, 10 };
+               assert ("foo\n" == (string) data);
+               change_buffer (get_buffer ());
+               assert ("bar\n" == (string) data);
+               change_buffer (get_buffer2 ());
+               assert ("bar\n" == (string) data2);
+               assert ((string) data == (string) data2);
+       }
+
+       {
+               data = { 'f', 'o', 'o', '\n' };
+               data2 = { 102, 111, 111, 10 };
+               assert ("foo\n" == (string) data2);
+               change_buffer2 (get_buffer2 ());
+               assert ("baz\n" == (string) data2);
+               change_buffer2 (get_buffer ());
+               assert ("baz\n" == (string) data);
+               assert ((string) data == (string) data2);
+       }
+}


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