[vala/0.42] tests: Add implicit conversion tests for GLib.Variant



commit 97663a7e0ac762b7cebff208ef53a90610eec40d
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 95dbf07ab..c5bc71281 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -30,6 +30,7 @@ TESTS = \
        basic-types/sizeof.vala \
        basic-types/garray.vala \
        basic-types/glists.vala \
+       basic-types/gvariants.vala \
        basic-types/bug570846.test \
        basic-types/bug571486.vala \
        basic-types/bug591552.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]