[vala/0.40] tests: Check uchar[] and uint8[] compatibility
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] tests: Check uchar[] and uint8[] compatibility
- Date: Mon, 17 Sep 2018 15:03:18 +0000 (UTC)
commit 2df82ea82c132fc69f18886f2c918473a10d4fc1
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 4862fdcb0..4c4361ed7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,6 +20,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]