]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
tests: Add implicit conversion tests for GLib.Variant
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 25 Oct 2018 11:26:46 +0000 (13:26 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 25 Oct 2018 11:36:31 +0000 (13:36 +0200)
tests/Makefile.am
tests/basic-types/gvariants.vala [new file with mode: 0644]

index 0f0c8f0072ddc79cc4ac218f294c77b7ae31aa39..afc6f25d8c9575fa13f0abaa124d3efbc5b228f4 100644 (file)
@@ -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 (file)
index 0000000..ebfedb9
--- /dev/null
@@ -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 ();
+}