2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / mini / exceptions.cs
index bf50666cbdf3821945500d11e9fa29c204225070..0f42f004fc6058c884855dabf1c79f533164300a 100644 (file)
@@ -563,20 +563,6 @@ class Tests {
                if (b != 127)
                        return -20;
 
-               try {
-                       l = 0x00000000ffffffff;
-                       failed = true;
-                       checked {
-                               b = (sbyte)l;
-                       }
-               } catch (OverflowException) {
-                       failed = false;
-               }
-               if (failed)
-                       return 21;
-               if (b != 127)
-                       return -21;
-
                return 0;
        }
 
@@ -945,6 +931,18 @@ class Tests {
                if (failed)
                        return 16;
 
+               try {
+                       l = 0x00000000ffffffff;
+                       failed = true;
+                       checked {
+                               b = (short)l;
+                       }
+               } catch (OverflowException) {
+                       failed = false;
+               }
+               if (failed)
+                       return 17;
+
                return 0;
        }
        
@@ -1066,6 +1064,20 @@ class Tests {
                if (failed)
                        return 9;
 
+               try {
+                       ulong ul = (long)(System.Int32.MaxValue) + 1;
+                       failed = true;
+                       checked {
+                               a = (int)ul;
+                       }
+               }
+               catch (OverflowException) {
+                       failed = false;
+               }
+               if (failed)
+                       return 10;
+
+
                {
                        int i; 
                        float f = 1.1f;
@@ -1230,7 +1242,6 @@ class Tests {
                if (failed)
                        return 2;
                
-
                try {
                        double d = System.Int64.MinValue - 1024.0;
                        failed = false;                 
@@ -1270,6 +1281,12 @@ class Tests {
                ulong a;
                bool failed;
 
+               /*
+                * These tests depend on properties of x86 fp arithmetic so they won't work
+                * on other platforms.
+                */
+
+               /*
                try {
                        double d = System.UInt64.MaxValue - 1024.0;
                        failed = true;
@@ -1293,7 +1310,7 @@ class Tests {
                }
                if (failed)
                        return 2;
-               
+               */      
 
                try {
                        double d = 0;
@@ -1363,6 +1380,11 @@ class Tests {
                if ((uint)d != 4294967295)
                        return 1;
 
+               /*
+                * These tests depend on properties of x86 fp arithmetic so they won't work
+                * on other platforms.
+                */
+               /*
                d = 0xffffffffffffffff;
 
                if ((ulong)d != 0)
@@ -1373,6 +1395,7 @@ class Tests {
                        
                if ((byte)d != 0)
                        return 4;
+               */
                        
                d = 0xffff;
 
@@ -2071,6 +2094,15 @@ class Tests {
                                ThrowClass.rethrow2 ();
                        }
                        catch (Exception ex) {
+                               // Check that each catch clause has its own exception variable
+                               // If not, the throw below will overwrite the exception used
+                               // by the rethrow
+                               try {
+                                       throw new DivideByZeroException ();
+                               }
+                               catch (Exception foo) {
+                               }
+
                                throw;
                        }
                }
@@ -2115,5 +2147,56 @@ class Tests {
                        return 1;
                }
        }
+
+       static int test_0_array_size () {
+               bool failed;
+
+               try {
+                       failed = true;
+                       int[] mem1 = new int [Int32.MaxValue];
+               }
+               catch (OutOfMemoryException e) {
+                       failed = false;
+               }
+               if (failed)
+                       return 1;
+
+               try {
+                       failed = true;
+                       int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
+               }
+               catch (OutOfMemoryException e) {
+                       failed = false;
+               }
+               if (failed)
+                       return 2;
+
+               return 0;
+       }
+
+       struct S {
+               int i, j, k, l, m, n;
+       }
+
+       static IntPtr[] addr;
+
+       static unsafe void throw_func (int i, S s) {
+               addr [i] = new IntPtr (&i);
+               throw new Exception ();
+       }
+
+       /* Test that arguments are correctly popped off the stack during unwinding */
+       static int test_0_stack_unwind () {
+               addr = new IntPtr [1000];
+               S s = new S ();
+               for (int j = 0; j < 1000; j++) {
+                       try {
+                               throw_func (j, s);
+                       }
+                       catch (Exception) {
+                       }
+               }
+               return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;
+       }               
 }