Wed Jun 16 14:33:22 CEST 2004 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / mini / arrays.cs
1 using System;
2 using System.Reflection;
3
4 /*
5  * Regression tests for the mono JIT.
6  *
7  * Each test needs to be of the form:
8  *
9  * static int test_<result>_<name> ();
10  *
11  * where <result> is an integer (the value that needs to be returned by
12  * the method to make it pass.
13  * <name> is a user-displayed name used to identify the test.
14  *
15  * The tests can be driven in two ways:
16  * *) running the program directly: Main() uses reflection to find and invoke
17  *      the test methods (this is useful mostly to check that the tests are correct)
18  * *) with the --regression switch of the jit (this is the preferred way since
19  *      all the tests will be run with optimizations on and off)
20  *
21  * The reflection logic could be moved to a .dll since we need at least another
22  * regression test file written in IL code to have better control on how
23  * the IL code looks.
24  */
25
26 class Tests {
27
28         static int Main () {
29                 return TestDriver.RunTests (typeof (Tests));
30         }
31         
32         static int test_10_create () {
33                 int[] a = new int [10];
34                 return a.Length;
35         }
36
37         static int test_0_unset_value () {
38                 int[] a = new int [10];
39                 return a [5];
40         }
41
42         static int test_3_set_value () {
43                 int[] a = new int [10];
44                 a [5] = 3;
45                 return a [5];
46         }
47
48         static int test_0_char_array_1 () {
49                 int value = -30;
50                 char[] tmp = new char [20];
51                 char[] digitLowerTable = new char[16];
52                 tmp[0] = digitLowerTable[-(value % 10)];
53                 return 0;
54         }
55         
56         static int test_0_char_array_2 () {
57                 int value = 5;
58                 char[] tmp = new char [20];
59                 char[] digitLowerTable = new char[16];
60                 tmp[0] = digitLowerTable[value % 10];
61                 return 0;
62         }
63
64         static int test_0_char_array_3 () {
65                 int value = -1;
66                 char[] tmp = new char [20];
67                 char[] digitLowerTable = new char[16];
68                 tmp [0] = digitLowerTable[value & 15];          
69                 return 0;
70         }
71
72         unsafe static int test_0_byte_array () {
73                 byte [] src = new byte [8];
74                 double ret;
75                 byte *dst = (byte *)&ret;
76                 int start = 0;
77
78                 dst[0] = src[4 + start];
79                 
80                 return 0;
81         }
82         
83         public static int test_0_set_after_shift () {
84                 int [] n = new int [1];
85                 int b = 16;
86                    
87                 n [0] = 100 + (1 << (16 - b));
88
89                 if (n [0] != 101)
90                         return 1;
91
92                 return 0;
93         }
94
95         /* Regression test for #30073 */
96         public static int test_0_newarr_emulation () {
97                 double d = 500;
98                 checked {
99                         double [] arr = new double [(int)d];
100                 }
101                 return 0;
102         }
103
104         private Int32[] m_array = new int [10];
105         
106         void setBit (int bitIndex, bool value) {
107                 int index = bitIndex/32;
108                 int shift = bitIndex%32;
109
110                 Int32 theBit = 1 << shift;
111                 if (value)
112                         m_array[index] |= theBit;
113                 else
114                         m_array[index] &= ~theBit;
115         }
116         
117         bool getBit (int bitIndex) {
118                 int index = bitIndex/32;
119                 int shift = bitIndex%32;
120
121                 Int32 theBit = m_array[index] & (1 << shift);
122                 return (theBit == 0) ? false : true;
123
124         }
125         
126         public static int test_1_bit_index () {
127                 Tests t = new Tests ();
128                 t.setBit (0, true);
129                 t.setBit (3, true);
130                 if (t.getBit (1))
131                         return 4;
132                 if (!t.getBit (0))
133                         return 5;
134                 if (!t.getBit (3))
135                         return 6;
136                 return 1;
137         }
138
139         class helper1 {
140
141                 int [] ma = new int [56];
142                 const int MBIG = int.MaxValue;
143
144                 public helper1 () {
145                         for (int k = 1; k < 5; k++) {
146                                 for (int i = 1; i < 56; i++) {
147                                         ma [i] -= ma [1 + (i + 30) % 55];
148                                         if (ma [i] < 0)
149                                                 ma [i] += MBIG;
150                                 }
151                         }
152                 }
153         }
154
155         public static int test_2_regalloc () {
156                 helper1 h = new helper1 ();
157                 return 2;
158         }
159 }
160