Author: spouliot
Date: 2008-01-03 07:40:20 -0500 (Thu, 03 Jan 2008)
New Revision: 92166

Added:
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidReturningArraysOnPropertiesTest.cs
Modified:
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUninstantiatedInternalClassesTest.cs
   trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/ChangeLog
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/Test.Rules.Performance.mdp
Log:
2008-01-03  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * AvoidReturningArraysOnPropertiesTest.cs: New. Unit tests by 
        Adrian Tsai
        * AvoidUninstantiatedInternalClassesTest.cs: Add new enum test cases.
        * Test.Rules.Performance.mdp: Add new test for MonoDevelop project 
        file.



Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidReturningArraysOnPropertiesTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidReturningArraysOnPropertiesTest.cs
  2008-01-03 12:25:11 UTC (rev 92165)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidReturningArraysOnPropertiesTest.cs
  2008-01-03 12:40:20 UTC (rev 92166)
@@ -0,0 +1,96 @@
+//
+// Unit tests for AvoidReturningArraysOnPropertiesRule
+//
+// Authors:
+//     Adrian Tsai <[EMAIL PROTECTED]>
+//
+// Copyright (c) 2007 Adrian Tsai
+//
+// 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.Reflection;
+
+using Gendarme.Framework;
+using Gendarme.Rules.Performance;
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Rules.Performance {
+
+       [TestFixture]
+       public class AvoidReturningArraysOnPropertiesTest {
+
+               public class ShouldBeCaught {
+                       byte [] foo;
+
+                       byte [] Foo {
+                               get { return foo; }
+                       }
+               }
+
+               public class ShouldBeIgnored {
+                       byte [] Bar ()
+                       {
+                               return new byte [10];
+                       }
+
+                       int foo;
+                       int Foo  {
+                               get { return foo; }
+                               set { foo = value; }
+                       }
+               }
+
+
+               private IMethodRule rule;
+               private AssemblyDefinition assembly;
+               private ModuleDefinition module;
+
+               [TestFixtureSetUp]
+               public void FixtureSetUp ()
+               {
+                       string unit = Assembly.GetExecutingAssembly ().Location;
+                       assembly = AssemblyFactory.GetAssembly (unit);
+                       module = assembly.MainModule;
+                       rule = new AvoidReturningArraysOnPropertiesRule ();
+               }
+
+               private TypeDefinition GetTest (string name)
+               {
+                       string fullname = 
"Test.Rules.Performance.AvoidReturningArraysOnPropertiesTest/" + name;
+                       return assembly.MainModule.Types [fullname];
+               }
+
+               [Test]
+               public void TestShouldBeCaught ()
+               {
+                       TypeDefinition type = GetTest ("ShouldBeCaught");
+                       foreach (MethodDefinition md in type.Methods)
+                               Assert.IsNotNull (rule.CheckMethod (md, new 
MinimalRunner ()));
+               }
+
+               [Test]
+               public void TestShouldBeIgnored ()
+               {
+                       TypeDefinition type = GetTest ("ShouldBeIgnored");
+                       foreach (MethodDefinition md in type.Methods)
+                               Assert.IsNull (rule.CheckMethod (md, new 
MinimalRunner ()));
+               }
+       }
+}

Modified: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUninstantiatedInternalClassesTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUninstantiatedInternalClassesTest.cs
        2008-01-03 12:25:11 UTC (rev 92165)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUninstantiatedInternalClassesTest.cs
        2008-01-03 12:40:20 UTC (rev 92166)
@@ -100,6 +100,27 @@
                void display ();
        }
 
+       public class NestedEnumInstantiated {
+               private enum PrivateEnum {
+                       Good,
+                       Bad,
+                       Unsure
+               }
+
+               private static PrivateEnum GetMe ()
+               {
+                       return PrivateEnum.Good;
+               }
+       }
+
+       public class NestedEnumNotInstantiated {
+               private enum PrivateEnum {
+                       Good,
+                       Bad,
+                       Unsure
+               }
+       }
+
        [TestFixture]
        public class AvoidUninstantiatedInternalClassesTest {
                
@@ -187,5 +208,21 @@
                        messageCollection = typeRule.CheckType (type, new 
MinimalRunner ());
                        Assert.IsNull (messageCollection);
                }
+
+               [Test]
+               public void NestedEnumInstantiated ()
+               {
+                       type = GetTest ("NestedEnumInstantiated");
+                       messageCollection = typeRule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNull (messageCollection);
+               }
+
+               [Test]
+               public void NestedEnumNotInstantiated ()
+               {
+                       type = GetTest ("NestedEnumNotInstantiated");
+                       messageCollection = typeRule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNull (messageCollection);
+               }
        }
 }

Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/ChangeLog        
2008-01-03 12:25:11 UTC (rev 92165)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/ChangeLog        
2008-01-03 12:40:20 UTC (rev 92166)
@@ -1,3 +1,11 @@
+2008-01-03  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * AvoidReturningArraysOnPropertiesTest.cs: New. Unit tests by 
+       Adrian Tsai
+       * AvoidUninstantiatedInternalClassesTest.cs: Add new enum test cases.
+       * Test.Rules.Performance.mdp: Add new test for MonoDevelop project 
+       file.
+
 2007-12-21  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * AvoidUncalledPrivateCodeTest.cs, AvoidUnusedParametersTest.cs:

Modified: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/Test.Rules.Performance.mdp
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/Test.Rules.Performance.mdp
       2008-01-03 12:25:11 UTC (rev 92165)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Test/Test.Rules.Performance.mdp
       2008-01-03 12:40:20 UTC (rev 92166)
@@ -14,15 +14,15 @@
     </Configuration>
   </Configurations>
   <Contents>
-    <File name="./EmptyDestructorTest.cs" subtype="Code" buildaction="Compile" 
/>
-    <File name="./IDisposableWithDestructorWithoutSuppressFinalizeTest.cs" 
subtype="Code" buildaction="Compile" />
-    <File name="./UseStringEmptyTest.cs" subtype="Code" buildaction="Compile" 
/>
-    <File name="./AvoidUnusedParametersTest.cs" subtype="Code" 
buildaction="Compile" />
-    <File name="./AvoidUncalledPrivateCodeTest.cs" subtype="Code" 
buildaction="Compile" />
-    <File name="./AvoidUninstantiatedInternalClassesTest.cs" subtype="Code" 
buildaction="Compile" />
-    <File name="./UsingStringLengthInsteadOfCheckingEmptyStringTest.cs" 
subtype="Code" buildaction="Compile" />
-    <File name="./AvoidToStringOnStringsTest.cs" subtype="Code" 
buildaction="Compile" />
-    <File name="./DontIgnoreMethodResultTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="EmptyDestructorTest.cs" subtype="Code" buildaction="Compile" />
+    <File name="IDisposableWithDestructorWithoutSuppressFinalizeTest.cs" 
subtype="Code" buildaction="Compile" />
+    <File name="UseStringEmptyTest.cs" subtype="Code" buildaction="Compile" />
+    <File name="AvoidUnusedParametersTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="AvoidUncalledPrivateCodeTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="AvoidUninstantiatedInternalClassesTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="UsingStringLengthInsteadOfCheckingEmptyStringTest.cs" 
subtype="Code" buildaction="Compile" />
+    <File name="AvoidToStringOnStringsTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="DontIgnoreMethodResultTest.cs" subtype="Code" 
buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Project" localcopy="True" 
refto="Gendarme.Rules.Performance" />

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

Reply via email to