--- /dev/null
+//\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