2002-05-07 Nick Drochak <ndrochak@gol.com>
authorNick Drochak <nickd@mono-cvs.ximian.com>
Tue, 7 May 2002 10:03:15 +0000 (10:03 -0000)
committerNick Drochak <nickd@mono-cvs.ximian.com>
Tue, 7 May 2002 10:03:15 +0000 (10:03 -0000)
* ExceptionTest.cs: New File. Provided by Linus Upson.

svn path=/trunk/mcs/; revision=4366

mcs/class/corlib/Test/System/AllTests.cs
mcs/class/corlib/Test/System/ChangeLog
mcs/class/corlib/Test/System/ExceptionTest.cs [new file with mode: 0644]

index 32f66abfce23db42d1f8b03007a3f39ff4f1c3cc..714a471a26e5282b569df5cacddeac9e88bcd0d4 100644 (file)
@@ -49,6 +49,7 @@ namespace MonoTests.System {
                                 suite.AddTest (UInt64Test.Suite);
                                suite.AddTest (VersionTest.Suite);
                                suite.AddTest (MulticastDelegateTest.Suite);
+                               suite.AddTest (ExceptionTest.Suite);
                                return suite;
                         }
                 }
index c72ce70195e0ed7b85caf51e277ca4b48237a544..decc784efe3b103ec49b9633df386253b6657e19 100644 (file)
@@ -1,3 +1,7 @@
+2002-05-07  Nick Drochak  <ndrochak@gol.com>
+
+       * ExceptionTest.cs: New File. Provided by Linus Upson.
+
 2002-05-05  Lawrence Pit  <loz@cable.a2000.nl>\r
 \r
        * StringTest.cs: Added test for replace function\r
diff --git a/mcs/class/corlib/Test/System/ExceptionTest.cs b/mcs/class/corlib/Test/System/ExceptionTest.cs
new file mode 100644 (file)
index 0000000..d0f6b80
--- /dev/null
@@ -0,0 +1,204 @@
+//\r
+// ExceptionTest.cs - NUnit Test Cases for the System.Exception class\r
+// \r
+// Linus Upson (linus@linus.com)\r
+//\r
+\r
+using System;\r
+using NUnit.Framework;\r
+\r
+namespace MonoTests.System\r
+{\r
+       public class ExceptionTest : TestCase\r
+       {\r
+               public ExceptionTest() : base ("MonoTests.System.ExceptionTest testsuite") {}\r
+               public ExceptionTest(string name) : base(name) {}\r
+               \r
+               public static ITest Suite {\r
+                       get {\r
+                               return new TestSuite(typeof(ExceptionTest));\r
+                       }\r
+               }\r
+               \r
+               // This test makes sure that exceptions thrown on block boundaries are\r
+               // handled in the correct block. The meaning of the 'caught' variable is\r
+               // a little confusing since there are two catchers: the method being\r
+               // tested the the method calling the test. There is probably a better\r
+               // name, but I can't think of it right now.\r
+               \r
+               public void TestThrowOnBlockBoundaries()\r
+               {\r
+                       bool caught;\r
+                       \r
+                       try {\r
+                               caught = false;\r
+                               ThrowBeforeTry();\r
+                       } catch {\r
+                               caught = true;\r
+                       }\r
+                       Assert("Exceptions thrown before try blocks should not be caught", caught);\r
+                       \r
+                       try {\r
+                               caught = false;\r
+                               ThrowAtBeginOfTry();\r
+                       } catch {\r
+                               caught = true;\r
+                       }\r
+                       Assert("Exceptions thrown at begin of try blocks should be caught", !caught);\r
+\r
+                       try {\r
+                               caught = false;\r
+                               ThrowAtEndOfTry();\r
+                       } catch {\r
+                               caught = true;\r
+                       }\r
+                       Assert("Exceptions thrown at end of try blocks should be caught", !caught);\r
+\r
+                       try {\r
+                               caught = false;\r
+                               ThrowAtBeginOfCatch();\r
+                       } catch {\r
+                               caught = true;\r
+                       }\r
+                       Assert("Exceptions thrown at begin of catch blocks should not be caught", caught);\r
+\r
+                       try {\r
+                               caught = false;\r
+                               ThrowAtEndOfCatch();\r
+                       } catch {\r
+                               caught = true;\r
+                       }\r
+                       Assert("Exceptions thrown at end of catch blocks should not be caught", caught);\r
+\r
+                       try {\r
+                               caught = false;\r
+                               ThrowAtBeginOfFinally();\r
+                       } catch {\r
+                               caught = true;\r
+                       }\r
+                       Assert("Exceptions thrown at begin of finally blocks should not be caught", caught);\r
+\r
+                       try {\r
+                               caught = false;\r
+                               ThrowAtEndOfFinally();\r
+                       } catch {\r
+                               caught = true;\r
+                       }\r
+                       Assert("Exceptions thrown at end of finally blocks should not be caught", caught);\r
+\r
+                       try {\r
+                               caught = false;\r
+                               ThrowAfterFinally();\r
+                       } catch {\r
+                               caught = true;\r
+                       }\r
+                       Assert("Exceptions thrown after finally blocks should not be caught", caught);\r
+               }\r
+               \r
+               private static void DoNothing()\r
+               {\r
+               }\r
+\r
+               private static void ThrowException()\r
+               {\r
+                       throw new Exception();\r
+               }\r
+               \r
+               private static void ThrowBeforeTry()\r
+               {\r
+                       ThrowException();\r
+                       try {\r
+                               DoNothing();\r
+                       } catch (Exception) {\r
+                               DoNothing();\r
+                       }\r
+               }\r
+\r
+               private static void ThrowAtBeginOfTry()\r
+               {\r
+                       DoNothing();\r
+                       try {\r
+                               ThrowException();\r
+                               DoNothing();\r
+                       } catch (Exception) {\r
+                               DoNothing();\r
+                       }\r
+               }\r
+\r
+               private static void ThrowAtEndOfTry()\r
+               {\r
+                       DoNothing();\r
+                       try {\r
+                               DoNothing();\r
+                               ThrowException();\r
+                       } catch (Exception) {\r
+                               DoNothing();\r
+                       }\r
+               }\r
+\r
+               private static void ThrowAtBeginOfCatch()\r
+               {\r
+                       DoNothing();\r
+                       try {\r
+                               DoNothing();\r
+                               ThrowException();\r
+                       } catch (Exception) {\r
+                               throw;\r
+                       }\r
+               }\r
+\r
+               private static void ThrowAtEndOfCatch()\r
+               {\r
+                       DoNothing();\r
+                       try {\r
+                               DoNothing();\r
+                               ThrowException();\r
+                       } catch (Exception) {\r
+                               DoNothing();\r
+                               throw;\r
+                       }\r
+               }\r
+\r
+               private static void ThrowAtBeginOfFinally()\r
+               {\r
+                       DoNothing();\r
+                       try {\r
+                               DoNothing();\r
+                               ThrowException();\r
+                       } catch (Exception) {\r
+                               DoNothing();\r
+                       } finally {\r
+                               ThrowException();\r
+                               DoNothing();\r
+                       }\r
+               }\r
+\r
+               private static void ThrowAtEndOfFinally()\r
+               {\r
+                       DoNothing();\r
+                       try {\r
+                               DoNothing();\r
+                               ThrowException();\r
+                       } catch (Exception) {\r
+                               DoNothing();\r
+                       } finally {\r
+                               DoNothing();\r
+                               ThrowException();\r
+                       }\r
+               }\r
+\r
+               private static void ThrowAfterFinally()\r
+               {\r
+                       DoNothing();\r
+                       try {\r
+                               DoNothing();\r
+                               ThrowException();\r
+                       } catch (Exception) {\r
+                               DoNothing();\r
+                       } finally {\r
+                               DoNothing();\r
+                       }\r
+                       ThrowException();\r
+               }\r
+       }\r
+}\r