* the IL code looks.
*/
-class Tests {
-
- static int Main () {
- return TestDriver.RunTests (typeof (Tests));
+#if __MOBILE__
+class ArrayTests
+#else
+class Tests
+#endif
+{
+
+#if !__MOBILE__
+ public static int Main (string[] args) {
+ return TestDriver.RunTests (typeof (Tests), args);
}
+#endif
public static int test_10_create () {
int[] a = new int [10];
return 0;
}
- private Int32[] m_array = new int [10];
-
- void setBit (int bitIndex, bool value) {
- int index = bitIndex/32;
- int shift = bitIndex%32;
+ class BitClass {
+ private Int32[] m_array = new int [10];
- Int32 theBit = 1 << shift;
- if (value)
- m_array[index] |= theBit;
- else
- m_array[index] &= ~theBit;
- }
-
- bool getBit (int bitIndex) {
- int index = bitIndex/32;
- int shift = bitIndex%32;
+ public void setBit (int bitIndex, bool value) {
+ int index = bitIndex/32;
+ int shift = bitIndex%32;
- Int32 theBit = m_array[index] & (1 << shift);
- return (theBit == 0) ? false : true;
+ Int32 theBit = 1 << shift;
+ if (value)
+ m_array[index] |= theBit;
+ else
+ m_array[index] &= ~theBit;
+ }
+
+ public bool getBit (int bitIndex) {
+ int index = bitIndex/32;
+ int shift = bitIndex%32;
+ Int32 theBit = m_array[index] & (1 << shift);
+ return (theBit == 0) ? false : true;
+ }
}
public static int test_1_bit_index () {
- Tests t = new Tests ();
+ var t = new BitClass ();
t.setBit (0, true);
t.setBit (3, true);
if (t.getBit (1))
if (sum != 1800)
return 12;
+ /* Null check */
+ object[,] a13 = null;
+ try {
+ a13 [0, 0] = new Object ();
+ return 13;
+ } catch (NullReferenceException) {
+ }
+
return 0;
}
+ public static int test_100_3_dimensional_arrays () {
+ int[,,] test = new int[10, 10, 10];
+
+ test [1, 1, 1] = 100;
+ return test [1, 1, 1];
+ }
+
+ public static int test_100_4_dimensional_arrays () {
+ int[,,,] test = new int[10, 10, 10, 10];
+
+ test [1, 1, 1, 1] = 100;
+ return test [1, 1, 1, 1];
+ }
+
public static int test_0_bug_71454 () {
int[,] a = new int[4,4];
int[,] b = new int[4,4];
return y;
}
+ class RefClass {
+ }
+
public static int test_0_stelem_ref_null_opt () {
- object[] arr = new Tests [1];
+ object[] arr = new RefClass [1];
- arr [0] = new Tests ();
+ arr [0] = new RefClass ();
arr [0] = null;
return arr [0] == null ? 0 : 1;
}
+
+ public static int test_0_invalid_new_array_size () {
+ int size;
+ object res = null;
+ size = -1;
+ try {
+ res = new float [size];
+ } catch (OverflowException e) {
+
+ } catch (Exception) {
+ return 1;
+ }
+ if (res != null)
+ return 2;
+
+ size = -2147483648;
+ try {
+ res = new float [size];
+ } catch (OverflowException e) {
+
+ } catch (Exception) {
+ return 3;
+ }
+
+ if (res != null)
+ return 4;
+
+ return 0;
+ }
+
+ public static int test_0_multidym_array_with_negative_lower_bound () {
+ int[,] x = (int[,]) Array.CreateInstance(typeof (int), new int[] { 2, 2 }, new int[] { -2, -3 });
+
+ if(x.GetLowerBound (0) != -2)
+ return 1;
+ if (x.GetLowerBound (1) != -3)
+ return 2;
+
+ x.SetValue (10, new int [] { -2, -3 });
+ x.SetValue (20, new int [] { -2, -2 });
+ x.SetValue (30, new int [] { -1, -3 });
+ x.SetValue (40, new int [] { -1, -2 });
+
+ try {
+ x.SetValue (10, new int [] { -3, -3 });
+ return 3;
+ } catch (IndexOutOfRangeException) { }
+
+ try {
+ x.SetValue (10, new int [] { -2, -4 });
+ return 4;
+ } catch (IndexOutOfRangeException) { }
+
+ try {
+ x.SetValue (10, new int [] { 0, -3 });
+ return 5;
+ } catch (IndexOutOfRangeException) { }
+
+ try {
+ x.SetValue (10, new int [] { -1, -1 });
+ return 6;
+ } catch (IndexOutOfRangeException) { }
+
+ if ((int)x.GetValue (new int [] { -2, -3 }) != 10)
+ return 7;
+ if ((int)x.GetValue (new int [] { -2, -2 }) != 20)
+ return 8;
+ if ((int)x.GetValue (new int [] { -1, -3 }) != 30)
+ return 9;
+ if ((int)x.GetValue (new int [] { -1, -2 }) != 40)
+ return 10;
+
+ try {
+ x.GetValue (new int [] { -3, -3 });
+ return 11;
+ } catch (IndexOutOfRangeException) { }
+
+ try {
+ x.GetValue ( new int [] { -2, -4 });
+ return 12;
+ } catch (IndexOutOfRangeException) { }
+
+ try {
+ x.GetValue (new int [] { 0, -3 });
+ return 13;
+ } catch (IndexOutOfRangeException) { }
+
+ try {
+ x.GetValue (new int [] { -1, -1 });
+ return 14;
+ } catch (IndexOutOfRangeException) { }
+ return 0;
+ }
+
+
+ public static int test_0_invalid_new_multi_dym_array_size () {
+ int dym_size = 1;
+ int size;
+ object res = null;
+ size = -1;
+ try {
+ res = new float [dym_size, size];
+ } catch (OverflowException e) {
+
+ } catch (Exception) {
+ return 1;
+ }
+ if (res != null)
+ return 2;
+
+ size = -2147483648;
+ try {
+ res = new float [size, dym_size];
+ } catch (OverflowException e) {
+
+ } catch (Exception) {
+ return 3;
+ }
+
+ if (res != null)
+ return 4;
+
+ return 0;
+ }
+
+ public enum IntEnum {
+ A,B,C
+ }
+
+ public enum UintEnum : uint {
+ A,B,C
+ }
+
+ static bool TryCast<T> (object o) {
+ return o is T[];
+ }
+
+ public static int test_0_primitive_array_cast () {
+ object a = new int[1];
+ object b = new uint[1];
+ object c = new IntEnum[1];
+ object d = new UintEnum[1];
+
+ object[] arr = new object[] { a, b, c, d };
+ int err = 1;
+
+ foreach (var v in arr) {
+ if (!TryCast<int> (v))
+ return err;
+ if (!TryCast<uint> (v))
+ return err + 1;
+ if (!TryCast<IntEnum> (v))
+ return err + 2;
+ if (!TryCast<UintEnum> (v))
+ return err + 3;
+ err += 4;
+ }
+
+ foreach (var v in arr) {
+ if (!(v is int[]))
+ return err;
+ if (!(v is uint[]))
+ return err;
+ if (!(v is IntEnum[]))
+ return err;
+ if (!(v is UintEnum[]))
+ return err;
+ err += 4;
+ }
+ return 0;
+ }
+
+ public static int test_0_intptr_array_cast () {
+ object[] a = new object[] { new int[1], new uint[1] };
+ object[] b = new object[] { new long[1], new ulong[1] };
+ object[] c = new object[] { new IntPtr[1], new UIntPtr[1] };
+
+ int err = 1;
+ if (IntPtr.Size == 4) {
+ foreach (var v in a) {
+ if (!(v is IntPtr[]))
+ return err;
+ if (!(v is IntPtr[]))
+ return err;
+ err += 2;
+ }
+ foreach (var v in b) {
+ if (v is IntPtr[])
+ return err;
+ if (v is IntPtr[])
+ return err;
+ err += 2;
+ }
+
+ foreach (var v in c) {
+ if (!(v is int[]))
+ return err;
+ if (!(v is uint[]))
+ return err;
+ err += 2;
+ }
+ } else {
+ foreach (var v in a) {
+ if (v is IntPtr[])
+ return err;
+ if (v is IntPtr[])
+ return err;
+ err += 2;
+ }
+ foreach (var v in b) {
+ if (!(v is IntPtr[]))
+ return err;
+ if (!(v is IntPtr[]))
+ return err;
+ err += 2;
+ }
+ foreach (var v in c) {
+ if (!(v is long[]))
+ return err;
+ if (!(v is ulong[]))
+ return err;
+ err += 2;
+ }
+ }
+ return 0;
+ }
+
+ public static int test_0_long_indices () {
+ int[] arr = new int [10];
+ int[,] arr2 = new int [10, 10];
+ long index = 1;
+ arr [index] = 5;
+ if (arr [index] != 5)
+ return 1;
+ arr2 [index, index] = 5;
+ if (arr2 [index, index] != 5)
+ return 2;
+ return 0;
+ }
+
+ // #7438
+ public static int test_0_ldelema_2_64bit () {
+ bool[,] test = new bool[201,201];
+ int x,y;
+ for(x=-100;x<100;x++) for(y=-100;y<100;y++){
+ test[x+100,y+100] = true;
+ }
+ return 0;
+ }
+
+ static bool alloc_long (long l) {
+ try {
+ var arr = new byte[l];
+ return false;
+ } catch (Exception e) {
+ return true;
+ }
+ }
+
+ // #13544
+ public static int test_0_newarr_ovf () {
+ if (!alloc_long (5000000000))
+ return 1;
+ if (!alloc_long (4000000000))
+ return 2;
+ if (!alloc_long (-1))
+ return 3;
+ if (!alloc_long (-4000000000))
+ return 4;
+ if (!alloc_long (-6000000000))
+ return 5;
+ return 0;
+ }
+
+ static int llvm_ldlen_licm (int[] arr) {
+ int sum = 0;
+ // The ldlen should be moved out of the loop
+ for (int i = 0; i < arr.Length; ++i)
+ sum += arr [i];
+ return sum;
+ }
+
+ public static int test_10_llvm_ldlen_licm () {
+ int[] arr = new int [10];
+ for (int i = 0; i < 10; ++i)
+ arr [i] = 1;
+ return llvm_ldlen_licm (arr);
+ }
}