2009-05-14 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / arrays.cs
index 012bdfdf7565646297e52a6a20b6c9c2bb4d51db..0bd8bb300fa2bb58492559bc80f776a3ef87f7c5 100644 (file)
@@ -476,6 +476,152 @@ class Tests {
 
                return y;
        }
+
+       public static int test_0_stelem_ref_null_opt () {
+               object[] arr = new Tests [1];
+
+               arr [0] = new Tests ();
+               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 static int 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;
+       }
 }