[vala/0.36] tests: Add implicit conversion tests for GLib.Variant
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.36] tests: Add implicit conversion tests for GLib.Variant
- Date: Sun, 28 Oct 2018 11:47:18 +0000 (UTC)
commit 43232324e79d99a9230b7eab66e091bc68045b0a
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Oct 25 13:26:46 2018 +0200
tests: Add implicit conversion tests for GLib.Variant
tests/Makefile.am | 1 +
tests/basic-types/gvariants.vala | 65 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1889f2743..586556aba 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,6 +24,7 @@ TESTS = \
basic-types/sizeof.vala \
basic-types/garray.vala \
basic-types/glists.vala \
+ basic-types/gvariants.vala \
basic-types/bug571486.vala \
basic-types/bug591552.vala \
basic-types/bug595751.vala \
diff --git a/tests/basic-types/gvariants.vala b/tests/basic-types/gvariants.vala
new file mode 100644
index 000000000..ebfedb9c7
--- /dev/null
+++ b/tests/basic-types/gvariants.vala
@@ -0,0 +1,65 @@
+void string_conversion () {
+ Variant v = "foo";
+ string s = (string) v;
+ assert (s == "foo");
+}
+
+void string_array_conversion () {
+ Variant v = new string[] { "foo", "bar" };
+ string[] sa = (string[]) v;
+ assert (sa.length == 2);
+ assert (sa[1] == "bar");
+}
+
+void string_array_2d_conversion () {
+ Variant v = new string[,] { { "foo" , "faz" } , { "bar", "baz" } };
+ string[,] sa = (string[,]) v;
+ assert (sa.length[0] == 2);
+ assert (sa.length[1] == 2);
+ assert (sa[1,1] == "baz");
+}
+
+void string_array_3d_conversion () {
+ Variant v = new string[,,] { { { "foo", "bar" }, { "baz", "man" } }, { { "foo2", "bar2" }, { "baz2",
"man2" } } };
+ string[,,] sa = (string[,,]) v;
+ assert (sa.length[0] == 2);
+ assert (sa.length[1] == 2);
+ assert (sa.length[2] == 2);
+ assert (sa[0,1,0] == "baz");
+ assert (sa[0,1,1] == "man");
+ assert (sa[1,1,0] == "baz2");
+ assert (sa[1,1,1] == "man2");
+}
+
+void double_conversion () {
+ Variant v = 42.23;
+ double d = (double) v;
+ assert (d == 42.23);
+}
+
+void double_array_conversion () {
+ Variant v = new double[] { 42.23, 47.11 };
+ double[] da = (double[]) v;
+ assert (da.length == 2);
+ assert (da[1] == 47.11);
+}
+
+void double_array_2d_conversion () {
+ Variant v = new double[,] { { 42.23, 11.47 } , { 47.11, 23.42 } };
+ double[,] da = (double[,]) v;
+ assert (da.length[0] == 2);
+ assert (da.length[1] == 2);
+ assert (da[1,1] == 23.42);
+}
+
+void main () {
+ string_conversion ();
+ string_array_conversion ();
+ double_conversion ();
+ double_array_conversion ();
+
+ string_array_2d_conversion ();
+ double_array_2d_conversion ();
+
+ string_array_3d_conversion ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]