Release 0.41.92
[vala-gnome.git] / tests / structs / gvalue.vala
blob927db030431a4cf72b808d985e563e9227dd70c1
1 void test_value () {
2 Value v1 = 1;
3 assert (v1.get_int() == 1);
5 string s = "hello";
6 Value v2 = s;
7 assert (v2.get_string () == s);
10 void test_value_array () {
11 int[] iarray = {1,2,3,4,5};
12 Value[] viarray = {1,2,3,4,5};
13 assert (viarray.length == iarray.length);
14 for (int i = 0; i < viarray.length; i++) {
15 assert (viarray[i].get_int () == iarray[i]);
18 string[] sarray = { "hello", "vala", "world" };
19 Value[] vsarray = { "hello", "vala", "world" };
20 assert (vsarray.length == sarray.length);
21 for (int i = 0; i < vsarray.length; i++) {
22 assert (vsarray[i].get_string () == sarray[i]);
26 void test_nullable_value () {
27 Value? v1 = 1;
28 assert (v1.get_int() == 1);
30 string s = "hello";
31 Value? v2 = s;
32 assert (v2.get_string () == s);
35 void test_nullable_value_array () {
36 int[] iarray = {1,2,3,4,5};
37 Value?[] viarray = {1,2,3,4,5};
38 assert (viarray.length == iarray.length);
39 for (int i = 0; i < viarray.length; i++) {
40 assert (viarray[i].get_int () == iarray[i]);
43 string[] sarray = { "hello", "vala", "world" };
44 Value?[] vsarray = { "hello", "vala", "world" };
45 assert (vsarray.length == sarray.length);
46 for (int i = 0; i < vsarray.length; i++) {
47 assert (vsarray[i].get_string () == sarray[i]);
51 void take_value (Value v) {
54 bool make_bool () {
55 return true;
58 struct FooStruct {
59 public int i;
62 void test_try_cast_value () {
63 FooStruct s = { 42 };
64 Value vs = s;
66 FooStruct s2 = (FooStruct) vs;
67 assert (s2.i == 42);
69 string[] sarray = { "hello", "vala", "world" };
70 Value va = sarray;
72 string[] sarray2 = (string[]) va;
73 assert (sarray[1] == "vala");
76 void main () {
77 test_value ();
78 test_value_array ();
79 test_nullable_value ();
80 test_nullable_value_array ();
81 take_value (make_bool ());
82 test_try_cast_value ();