[runtime] Synthesize IList and IReadOnlyList for the element type of enum errays...
[mono.git] / mono / tests / array.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Runtime.InteropServices;
4
5 public class Test {
6
7         public static int test_0_jagged ()
8         {
9                 int[][] j2 = new int [3][];
10
11                 // does not work 
12                 // j2 [0] = new int[] {1, 2, 3};
13                 // j2 [1] = new int[] {1, 2, 3, 4, 5, 6};
14                 // j2 [2] = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
15
16                 j2 [0] = new int[3];
17                 j2 [1] = new int[6];
18                 j2 [2] = new int[9];
19
20                 for (int i = 0; i < j2.Length; i++)
21                         for (int j = 0; j < (i+1)*3; j++)
22                                 j2 [i][j] = j;
23
24                 for (int i = 0; i < j2.Length; i++)
25                         for (int j = 0; j < (i+1)*3; j++)
26                                 if (j2 [i][j] != j)
27                                         return 1;
28                 return 0;
29         }
30
31         public static int test_0_stest ()
32         {
33                 string[] sa = new string[32];
34
35                 sa [0] = "This";
36                 sa [2] = "is";
37                 sa [10] = "a";
38                 sa [20] = "stupid";
39                 sa [21] = "Test";
40
41                 for (int i = 0; i < sa.Length; i++){
42                         if (sa [i] != null)
43                                 Console.WriteLine (sa [i]);
44                 }
45                 
46                 return 0;
47         }
48         
49         public static int test_0_atest2 ()
50         {
51                 int[,] ia = new int[32,32];
52
53                 for (int i = 0; i <ia.GetLength (0); i++)
54                         ia [i,i] = i*i;
55
56                 for (int i = 0; i <ia.GetLength (0); i++)
57                         if (ia [i,i] != i*i)
58                                 return 1;
59
60                 for (int i = 0; i <ia.GetLength (0); i++)
61                         ia.SetValue (i*i*i, i, i);
62
63                 for (int i = 0; i <ia.GetLength (0); i++)
64                         if ((int)ia.GetValue (i, i) != i*i*i)
65                                 return 1;
66
67                 return 0;
68         }
69         
70         public static int test_0_atest ()
71         {
72                 int[] ia = new int[32];
73
74                 for (int i = 0; i <ia.Length; i++)
75                         ia [i] = i*i;
76                 
77                 for (int i = 0; i <ia.Length; i++)
78                         if (ia [i] != i*i)
79                                 return 1;
80                 
81                 if (ia.Rank != 1)
82                         return 2;
83
84                 if (ia.GetValue (2) == null)
85                         return 3;
86
87                 for (int i = 0; i <ia.Length; i++)
88                         ia.SetValue (i*i*i, i);
89
90                 for (int i = 0; i <ia.Length; i++)
91                         if ((int)ia.GetValue (i) != i*i*i){
92                                 Console.WriteLine ("Crap: " + i + " " + (int) ia.GetValue (i) );
93
94                                 return 4;
95                         }
96                 
97                 return 0;
98         }
99
100         enum Foo { a, b };
101         public static int test_0_enum_array_casting () {
102         var x = new Foo[10];
103                 try {
104                         var y = (IReadOnlyList<int>)(object)x;
105                 } catch (Exception e) {
106                         return 1;
107                 }
108                 try {
109                         var y = (IList<int>)(object)x;
110                 } catch (Exception e) {
111                         return 2;
112                 }
113
114                 try {
115                         var y = (ICollection<int>)(object)x;
116                 } catch (Exception e) {
117                         return 3;
118                 }
119
120                 try {
121                         var y = (IEnumerable<int>)(object)x;
122                 } catch (Exception e) {
123                         return 4;
124                 }
125
126                 try {
127                         var y = (IReadOnlyCollection<int>)(object)x;
128                 } catch (Exception e) {
129                         return 5;
130                 }
131                 return 0;
132         }
133
134         public static int Main (string[] args) {
135                 return TestDriver.RunTests (typeof (Test), args);
136         }
137 }
138
139