2003-09-04 Sebastien Pouliot <spouliot@videotron.ca>
[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         private Int32[] m_array = new int [10];
96         
97         void setBit (int bitIndex, bool value) {
98                 int index = bitIndex/32;
99                 int shift = bitIndex%32;
100
101                 Int32 theBit = 1 << shift;
102                 if (value)
103                         m_array[index] |= theBit;
104                 else
105                         m_array[index] &= ~theBit;
106         }
107         
108         bool getBit (int bitIndex) {
109                 int index = bitIndex/32;
110                 int shift = bitIndex%32;
111
112                 Int32 theBit = m_array[index] & (1 << shift);
113                 return (theBit == 0) ? false : true;
114
115         }
116         
117         public static int test_1_bit_index () {
118                 Tests t = new Tests ();
119                 t.setBit (0, true);
120                 t.setBit (3, true);
121                 if (t.getBit (1))
122                         return 4;
123                 if (!t.getBit (0))
124                         return 5;
125                 if (!t.getBit (3))
126                         return 6;
127                 return 1;
128         }
129
130         class helper1 {
131
132                 int [] ma = new int [56];
133                 const int MBIG = int.MaxValue;
134
135                 public helper1 () {
136                         for (int k = 1; k < 5; k++) {
137                                 for (int i = 1; i < 56; i++) {
138                                         ma [i] -= ma [1 + (i + 30) % 55];
139                                         if (ma [i] < 0)
140                                                 ma [i] += MBIG;
141                                 }
142                         }
143                 }
144         }
145
146         public static int test_2_regalloc () {
147                 helper1 h = new helper1 ();
148                 return 2;
149         }
150 }
151