Author: spouliot
Date: 2008-02-15 14:08:46 -0500 (Fri, 15 Feb 2008)
New Revision: 95790

Added:
   
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/DontDestroyStackTraceTest.cs
Removed:
   
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/TestPatterns.cs
Modified:
   trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/ChangeLog
   
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/DontSwallowErrorsCatchingNonspecificExceptionsTest.cs
Log:
2008-02-15  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * DontDestroyStackTraceTest.cs: (renamed from TestPatterns.cs)
        * DontSwallowErrorsCatchingNonspecificExceptionsTest.cs:
                Update unit tests wrt framework changes.



Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/ChangeLog    
2008-02-15 19:01:34 UTC (rev 95789)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/ChangeLog    
2008-02-15 19:08:46 UTC (rev 95790)
@@ -1,3 +1,9 @@
+2008-02-15  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * DontDestroyStackTraceTest.cs: (renamed from TestPatterns.cs)
+       * DontSwallowErrorsCatchingNonspecificExceptionsTest.cs:
+               Update unit tests wrt framework changes.
+
 2007-10-07  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * Test.Rules.Exeptions.mdp: Update project file.

Copied: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/DontDestroyStackTraceTest.cs
 (from rev 95783, 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/TestPatterns.cs)
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/TestPatterns.cs  
    2008-02-15 18:29:58 UTC (rev 95783)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/DontDestroyStackTraceTest.cs
 2008-02-15 19:08:46 UTC (rev 95790)
@@ -0,0 +1,204 @@
+//
+// Unit Test for DontDestroyStackTraceTest Rule
+//
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.Reflection;
+using Gendarme.Framework;
+using Gendarme.Rules.Exceptions;
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Rules.Exceptions {
+
+       [TestFixture]   
+       public class DontDestroyStackTraceTest {
+       
+               private IMethodRule rule;
+               private TestRunner runner;
+               private AssemblyDefinition assembly;
+               private TypeDefinition type;
+               
+               // Test setup
+               [TestFixtureSetUp]
+               public void FixtureSetUp ()
+               {
+                       string unit = Assembly.GetExecutingAssembly ().Location;
+                       assembly = AssemblyFactory.GetAssembly (unit);
+                       type = assembly.MainModule.Types 
["Test.Rules.Exceptions.DontDestroyStackTraceTest"];
+                       rule = new DontDestroyStackTrace ();
+                       runner = new TestRunner (rule);
+               }
+
+               // Test infrastructure
+               private MethodDefinition GetMethodToTest (string name)
+               {
+                       return type.Methods.GetMethod (name, new Type [0]);
+               }
+
+               // Individual test cases
+               [Test]
+               public void TestThrowOriginalEx ()
+               {
+                       MethodDefinition method = GetMethodToTest 
("ThrowOriginalEx");
+                       // Should result in 1 warning message
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
+               }
+
+               [Test]
+               public void TestThrowOriginalExWithJunk ()
+               {
+                       MethodDefinition method = GetMethodToTest 
("ThrowOriginalExWithJunk");
+                       // Should result in 1 warning message
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
+               }
+
+               [Test]
+               public void TestRethrowOriginalEx ()
+               {
+                       MethodDefinition method = GetMethodToTest 
("RethrowOriginalEx");
+                       // Should result in 0 warning messages
+                       Assert.AreEqual (RuleResult.Success, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (0, runner.Defects.Count, "Count");
+               }
+
+               [Test]
+               public void TestThrowOriginalExAndRethrowWithJunk ()
+               {
+                       MethodDefinition method = GetMethodToTest 
("ThrowOriginalExAndRethrowWithJunk");
+                       // Should result in one warning message
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
+               }
+
+               [Test]
+               public void TestRethrowOriginalExAndThrowWithJunk ()
+               {
+                       MethodDefinition method = GetMethodToTest 
("RethrowOriginalExAndThrowWithJunk");
+                       // Should result in one warning message
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
+               }
+
+               // Functions whose IL is used by the test cases for the 
DontDestroyStackTrace rule
+
+               public void ThrowOriginalEx ()
+               {
+                       try  {
+                               Int32.Parse("Broken!");
+                       }
+                       catch (Exception ex) {
+                               // Throw exception immediately.
+                               // This should trip the DontDestroyStackTrace 
rule.
+                               throw ex;
+                       }
+               }
+
+               public void ThrowOriginalExWithJunk ()
+               {
+                       try {
+                               Int32.Parse ("Broken!");
+                       }
+                       catch (Exception ex) {
+                               int j = 0;
+                               for (int k=0; k<10; k++) {
+                                       // throw some junk into the catch 
block, to ensure that
+                                       j += 10;
+                                       Console.WriteLine (j);
+                               }
+
+                               // This should trip the DontDestroyStackTrace 
rule, because we're
+                               // throwing the original exception.
+                               throw ex;
+                       }
+               }
+
+               public void RethrowOriginalEx ()
+               {
+                       try {
+                               Int32.Parse ("Broken!");
+                       }
+                       catch (Exception ex) {
+                               // avoid compiler warning
+                               Assert.IsNotNull (ex);
+                               // This should NOT trip the 
DontDestroyStackTrace rule, because we're
+                               // rethrowing the original exception.
+                               throw;
+                       }
+               }
+
+               public void ThrowOriginalExAndRethrowWithJunk ()
+               {
+                       int i = 0;
+                       try {
+                               i = Int32.Parse ("Broken!");
+                       }
+                       catch (Exception ex) {
+                               int j = 0;
+                               for (int k=0; k<10; k++) {
+                                       // throw some junk into the catch 
block, to ensure that
+                                       j += 10;
+                                       Console.WriteLine (j);
+                                       if ((i % 1234) > 56) {
+                                               // This should trip the 
DontDestroyStackTrace rule, because we're
+                                               // throwing the original 
exception.
+                                               throw ex;
+                                       }
+                               }
+
+                               // More junk - just to ensure that alternate 
paths through
+                               // this catch block end up at a throw and a 
rethrow
+                               throw;
+                       }
+               }
+
+               public void RethrowOriginalExAndThrowWithJunk ()
+               {
+                       int i = 0;
+                       try {
+                               i = Int32.Parse ("Broken!");
+                       }
+                       catch (Exception ex) {
+                               int j = 0;
+                               for (int k=0; k<10; k++) {
+                                       // throw some junk into the catch 
block, to ensure that
+                                       j += 10;
+                                       Console.WriteLine (j);
+                                       if ((i % 1234) > 56) {
+                                               // More junk - just to ensure 
that alternate paths through
+                                               // this catch block end up at a 
throw and a rethrow
+                                               throw;
+                                       }
+                               }
+
+                               // This should trip the DontDestroyStackTrace 
rule, because we're
+                               // throwing the original exception.
+                               throw ex;
+                       }
+               }
+       }
+}

Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/DontSwallowErrorsCatchingNonspecificExceptionsTest.cs
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/DontSwallowErrorsCatchingNonspecificExceptionsTest.cs
        2008-02-15 19:01:34 UTC (rev 95789)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/DontSwallowErrorsCatchingNonspecificExceptionsTest.cs
        2008-02-15 19:08:46 UTC (rev 95790)
@@ -38,15 +38,14 @@
 
 namespace Test.Rules.Exceptions {
        
-
        [TestFixture]
        public class DontSwallowErrorsCatchingNonspecificExceptionsTest {
                
                private IMethodRule rule;
+               private TestRunner runner;
                private AssemblyDefinition assembly;
                private MethodDefinition method;
                private TypeDefinition type;
-               private MessageCollection messageCollection;
                
                [TestFixtureSetUp]
                public void FixtureSetUp ()
@@ -54,109 +53,80 @@
                        string unit = Assembly.GetExecutingAssembly ().Location;
                        assembly = AssemblyFactory.GetAssembly (unit);
                        rule = new 
DontSwallowErrorsCatchingNonspecificExceptionsRule ();
+                       runner = new TestRunner (rule);
                        type = assembly.MainModule.Types 
["Test.Rules.Exceptions.DontSwallowErrorsCatchingNonspecificExceptionsTest"];
-                       messageCollection = null;
                }
-               
-               private void CheckMessageType (MessageCollection 
messageCollection, MessageType messageType) 
-               {
-                       IEnumerator enumerator = 
messageCollection.GetEnumerator ();
-                       if (enumerator.MoveNext ()) {
-                               Message message = (Message) enumerator.Current;
-                               Assert.AreEqual (message.Type, messageType);
-                       }
-               }
-               
+
                [Test]
                public void SwallowErrorsCatchingExceptionsEmptyCatchBlockTest 
() 
                {
                        method = type.Methods.GetMethod 
("SwallowErrorsCatchingExceptionEmptyCatchBlock", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
-               
                [Test]
                public void 
SwallowErrorsCatchingExceptionsNoEmptyCatchBlockTest () 
                {
                        method = type.Methods.GetMethod 
("SwallowErrorsCatchingExceptionNoEmptyCatchBlock", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                [Test]
                public void 
SwallowErrorsCatchingSystemExceptionEmptyCatchBlockTest () 
                {
                        method = type.Methods.GetMethod 
("SwallowErrorsCatchingSystemExceptionEmptyCatchBlock", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
-               
                [Test]
                public void 
SwallowErrorsCatchingSystemExceptionNoEmptyCatchBlockTest () 
                {
                        method = type.Methods.GetMethod 
("SwallowErrorsCatchingSystemExceptionNoEmptyCatchBlock", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                [Test]
                public void 
SwallowErrorsCatchingTypeExceptionEmptyCatchBlockTest () 
                {
                        method = type.Methods.GetMethod 
("SwallowErrorsCatchingTypeExceptionEmptyCatchBlock", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                [Test]
                public void 
SwallowErrorsCatchingTypeExceptionNoEmptyCatchBlockTest () 
                {
                        method = type.Methods.GetMethod 
("SwallowErrorsCatchingTypeExceptionNoEmptyCatchBlock", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                [Test]
                public void SwallowErrorsCatchingAllEmptyCatchBlockTest () 
                {
                        method = type.Methods.GetMethod 
("SwallowErrorsCatchingAllEmptyCatchBlock", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                [Test]
                public void SwallowErrorsCatchingAllNoEmptyCatchBlockTest () 
                {
                        method = type.Methods.GetMethod 
("SwallowErrorsCatchingAllNoEmptyCatchBlock", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                [Test]
                public void NotSwallowRethrowingExceptionTest () 
                {
                        method = type.Methods.GetMethod 
("NotSwallowRethrowingException", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                
@@ -164,8 +134,8 @@
                public void NotSwallowRethrowingGeneralExceptionTest () 
                {
                        method = type.Methods.GetMethod 
("NotSwallowRethrowingGeneralException", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNull (messageCollection); 
+                       Assert.AreEqual (RuleResult.Success, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (0, runner.Defects.Count, "Count");
                }
                
                
@@ -173,48 +143,40 @@
                public void NotSwallowCatchingSpecificExceptionTest () 
                {
                        method = type.Methods.GetMethod 
("NotSwallowCatchingSpecificException", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNull (messageCollection); 
+                       Assert.AreEqual (RuleResult.Success, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (0, runner.Defects.Count, "Count");
                }
                
                [Test]
                public void NotSwallowThrowingANewExceptionTest () 
                {
                        method = type.Methods.GetMethod 
("NotSwallowThrowingANewException", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                [Test]
                public void NotSwallowCatchingAllThrowingANewExceptionTest () 
                {
                        method = type.Methods.GetMethod 
("NotSwallowCatchingAllThrowingANewException", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                [Test]
                public void 
NotSwallowCatchingTypeExceptionThrowingANewExceptionTest () 
                {
                        method = type.Methods.GetMethod 
("NotSwallowCatchingTypeExceptionThrowingANewException", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                [Test]
                public void 
NotSwallowCatchingSystemExceptionThrowingANewExceptionTest () 
                {
                        method = type.Methods.GetMethod 
("NotSwallowCatchingSystemExceptionThrowingANewException", Type.EmptyTypes);
-                       messageCollection = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsNotNull (messageCollection);
-                       Assert.AreEqual (messageCollection.Count, 1);
-                       CheckMessageType (messageCollection, MessageType.Error);
+                       Assert.AreEqual (RuleResult.Failure, runner.CheckMethod 
(method), "RuleResult");
+                       Assert.AreEqual (1, runner.Defects.Count, "Count");
                }
                
                //Methods for make the tests
@@ -238,7 +200,6 @@
                        }
                }
                
-               
                public void SwallowErrorsCatchingSystemExceptionEmptyCatchBlock 
() 
                {
                        try {
@@ -248,8 +209,6 @@
                        }
                }
                
-               
-               
                public void 
SwallowErrorsCatchingSystemExceptionNoEmptyCatchBlock () 
                {
                        try {

Deleted: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/TestPatterns.cs
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/TestPatterns.cs  
    2008-02-15 19:01:34 UTC (rev 95789)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Exceptions/Test/TestPatterns.cs  
    2008-02-15 19:08:46 UTC (rev 95790)
@@ -1,194 +0,0 @@
-using System;
-using System.Collections;
-using System.Reflection;
-using Gendarme.Framework;
-using Gendarme.Rules.Exceptions;
-using Mono.Cecil;
-using NUnit.Framework;
-
-namespace Test.Rules.Exceptions {
-
-       [TestFixture]   
-       public class DontDestroyStackTraceTest {
-       
-               private IMethodRule rule;
-               private AssemblyDefinition assembly;
-               private ModuleDefinition module;
-               private TypeDefinition type;
-               
-               // Test setup
-               [TestFixtureSetUp]
-               public void FixtureSetUp ()
-               {
-                       string unit = Assembly.GetExecutingAssembly ().Location;
-                       assembly = AssemblyFactory.GetAssembly (unit);
-                       module = assembly.MainModule;
-                       string fullname = 
"Test.Rules.Exceptions.DontDestroyStackTraceTest";
-                       type = module.Types [fullname];
-                       rule = new DontDestroyStackTrace ();
-               }
-
-               // Test infrastructure
-               private MethodDefinition GetMethodToTest (string name)
-               {
-                       return type.Methods.GetMethod (name, new Type [0]);
-               }
-
-               // Individual test cases
-               [Test]
-               public void TestThrowOriginalEx ()
-               {
-                       string testName = "ThrowOriginalEx";
-                       MethodDefinition method = GetMethodToTest (testName);
-
-                       // Should result in 1 warning message
-                       MessageCollection list = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsTrue (list != null, "Warnings were not 
generated for the test named " + testName);
-                       Assert.AreEqual (list.Count, 1, "One warning should 
have been generated for the test named " + testName);
-               }
-
-               [Test]
-               public void TestThrowOriginalExWithJunk ()
-               {
-                       string testName = "ThrowOriginalExWithJunk";
-                       MethodDefinition method = GetMethodToTest (testName);
-                       
-                       // Should result in 1 warning message
-                       MessageCollection list = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsTrue (list != null, "Warnings were not 
generated for the test named " + testName);
-                       Assert.AreEqual (list.Count, 1, "One warning should 
have been generated for the test named " + testName);
-               }
-
-               [Test]
-               public void TestRethrowOriginalEx ()
-               {
-                       string testName = "RethrowOriginalEx";
-                       MethodDefinition method = GetMethodToTest (testName);
-
-                       // Should result in 0 warning messages
-                       MessageCollection list = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsTrue (list == null, "Warnings were generated 
for the test named " + testName);
-               }
-
-               [Test]
-               public void TestThrowOriginalExAndRethrowWithJunk ()
-               {
-                       string testName = "ThrowOriginalExAndRethrowWithJunk";
-                       MethodDefinition method = GetMethodToTest (testName);
-
-                       // Should result in one warning message
-                       MessageCollection list = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsTrue (list != null, "Warnings were not 
generated for the test named " + testName);
-                       Assert.AreEqual (list.Count, 1, "One warning should 
have been generated for the test named " + testName);
-               }
-
-               [Test]
-               public void TestRethrowOriginalExAndThrowWithJunk ()
-               {
-                       string testName = "RethrowOriginalExAndThrowWithJunk";
-                       MethodDefinition method = GetMethodToTest (testName);
-
-                       // Should result in one warning message
-                       MessageCollection list = rule.CheckMethod (method, new 
MinimalRunner ());
-                       Assert.IsTrue (list != null, "Warnings were not 
generated for the test named " + testName);
-                       Assert.AreEqual (list.Count, 1, "One warning should 
have been generated for the test named " + testName);
-               }
-
-               // Functions whose IL is used by the test cases for the 
DontDestroyStackTrace rule
-
-               public void ThrowOriginalEx ()
-               {
-                       try  {
-                               Int32.Parse("Broken!");
-                       }
-                       catch (Exception ex) {
-                               // Throw exception immediately.
-                               // This should trip the DontDestroyStackTrace 
rule.
-                               throw ex;
-                       }
-               }
-
-               public void ThrowOriginalExWithJunk ()
-               {
-                       try {
-                               Int32.Parse ("Broken!");
-                       }
-                       catch (Exception ex) {
-                               int j = 0;
-                               for (int k=0; k<10; k++) {
-                                       // throw some junk into the catch 
block, to ensure that
-                                       j += 10;
-                                       Console.WriteLine (j);
-                               }
-
-                               // This should trip the DontDestroyStackTrace 
rule, because we're
-                               // throwing the original exception.
-                               throw ex;
-                       }
-               }
-
-               public void RethrowOriginalEx ()
-               {
-                       try {
-                               Int32.Parse ("Broken!");
-                       }
-                       catch (Exception ex) {
-                               // avoid compiler warning
-                               Assert.IsNotNull (ex);
-                               // This should NOT trip the 
DontDestroyStackTrace rule, because we're
-                               // rethrowing the original exception.
-                               throw;
-                       }
-               }
-
-               public void ThrowOriginalExAndRethrowWithJunk ()
-               {
-                       int i = 0;
-                       try {
-                               i = Int32.Parse ("Broken!");
-                       }
-                       catch (Exception ex) {
-                               int j = 0;
-                               for (int k=0; k<10; k++) {
-                                       // throw some junk into the catch 
block, to ensure that
-                                       j += 10;
-                                       Console.WriteLine (j);
-                                       if ((i % 1234) > 56) {
-                                               // This should trip the 
DontDestroyStackTrace rule, because we're
-                                               // throwing the original 
exception.
-                                               throw ex;
-                                       }
-                               }
-
-                               // More junk - just to ensure that alternate 
paths through
-                               // this catch block end up at a throw and a 
rethrow
-                               throw;
-                       }
-               }
-
-               public void RethrowOriginalExAndThrowWithJunk ()
-               {
-                       int i = 0;
-                       try {
-                               i = Int32.Parse ("Broken!");
-                       }
-                       catch (Exception ex) {
-                               int j = 0;
-                               for (int k=0; k<10; k++) {
-                                       // throw some junk into the catch 
block, to ensure that
-                                       j += 10;
-                                       Console.WriteLine (j);
-                                       if ((i % 1234) > 56) {
-                                               // More junk - just to ensure 
that alternate paths through
-                                               // this catch block end up at a 
throw and a rethrow
-                                               throw;
-                                       }
-                               }
-
-                               // This should trip the DontDestroyStackTrace 
rule, because we're
-                               // throwing the original exception.
-                               throw ex;
-                       }
-               }
-       }
-}

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to