Author: spouliot
Date: 2008-02-03 15:03:41 -0500 (Sun, 03 Feb 2008)
New Revision: 94717

Modified:
   
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUninstantiatedInternalClassesTest.cs
   trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/ChangeLog
   
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/DontIgnoreMethodResultTest.cs
Log:
2008-02-03  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * AvoidUninstantiatedInternalClassesTest.cs: Add more test cases.
        * DontIgnoreMethodResultTest.cs: Add test cases for more exceptions.



Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUninstantiatedInternalClassesTest.cs
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUninstantiatedInternalClassesTest.cs
   2008-02-03 19:50:09 UTC (rev 94716)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUninstantiatedInternalClassesTest.cs
   2008-02-03 20:03:41 UTC (rev 94717)
@@ -160,10 +160,40 @@
                }
        }
 
+       public class NestedEnumUsedAsParameter {
+               private enum PrivateEnum {
+                       Good,
+                       Bad,
+                       Unsure
+               }
+               private bool Get (PrivateEnum p)
+               {
+                       return false;
+               }
+       }
+
+       public class NestedConstValue {
+               public class Strings {
+                       public const string Hello = "Allo";
+               }
+       }
+
        public class ClassWithDelegate {
                delegate void MyOwnDelegate (int x);
        }
 
+       public abstract class ClassWithArray {
+               private class ExistAsArrayOnly {
+                       int value;
+               }
+
+               private ExistAsArrayOnly [] Get ()
+               {
+                       return null;
+               }
+       }
+
+
        [TestFixture]
        public class AvoidUninstantiatedInternalClassesTest {
                
@@ -291,5 +321,21 @@
                        messageCollection = typeRule.CheckType (type, new 
MinimalRunner ());
                        Assert.IsNotNull (messageCollection);
                }
+               
+               [Test]
+               public void NestedEnumUsedAsParameter ()
+               {
+                       type = GetTest 
("NestedEnumUsedAsParameter/PrivateEnum");
+                       messageCollection = typeRule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNull (messageCollection);
+               }
+
+               [Test]
+               public void StructExistAsArrayOnly ()
+               {
+                       type = GetTest ("ClassWithArray/ExistAsArrayOnly");
+                       messageCollection = typeRule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNull (messageCollection);
+               }
        }
 }

Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/ChangeLog   
2008-02-03 19:50:09 UTC (rev 94716)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/ChangeLog   
2008-02-03 20:03:41 UTC (rev 94717)
@@ -1,3 +1,8 @@
+2008-02-03  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * AvoidUninstantiatedInternalClassesTest.cs: Add more test cases.
+       * DontIgnoreMethodResultTest.cs: Add test cases for more exceptions.
+
 2008-01-29  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * AvoidUninstantiatedInternalClassesTest.cs: Add nested enum test 

Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/DontIgnoreMethodResultTest.cs
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/DontIgnoreMethodResultTest.cs
       2008-02-03 19:50:09 UTC (rev 94716)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Performance/Test/DontIgnoreMethodResultTest.cs
       2008-02-03 20:03:41 UTC (rev 94717)
@@ -3,8 +3,10 @@
 //
 // Authors:
 //     Lukasz Knop <[EMAIL PROTECTED]>
+//     Sebastien Pouliot <[EMAIL PROTECTED]>
 //
 // Copyright (C) 2007 Lukasz Knop
+// 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
@@ -27,45 +29,96 @@
 //
 
 using System;
+using System.Globalization;
+using System.IO;
+using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
 using System.Text;
+using System.Threading;
 
 using Gendarme.Framework;
 using Gendarme.Rules.Performance;
 using Mono.Cecil;
 using NUnit.Framework;
-using System.Globalization;
-using System.Reflection;
 
-namespace Test.Rules.Performance
-{
+namespace Test.Rules.Performance {
+
        [TestFixture]
-       public class DontIgnoreMethodResultTest
-       {
-               public class Item
-               {
-                       public void Violations()
+       public class DontIgnoreMethodResultTest {
+
+               public class Item {
+
+                       public void Violations ()
                        {
                                
"violationOne".ToUpper(CultureInfo.InvariantCulture);
                                string violationTwo = "MediuM ";
                                
violationTwo.ToLower(CultureInfo.InvariantCulture).Trim();
                        }
 
-                       public static void CreateItem()
+                       public static void CreateItem ()
                        {
-                               new Item();
+                               new Item ();
                        }
 
-                       public void NotAViolation()
+                       // StringBuilder is a special case when the method 
returns a StringBuilder
+                       public string StringBuilderOk ()
                        {
-                               StringBuilder sb = new StringBuilder();
-                               sb.Append("test").Append("test");
-                               ReturnInt();
+                               StringBuilder sb = new StringBuilder ();
+                               sb.Append ("test").Insert (2, true).Remove (0, 
1).Replace ("oh", "ah").
+                                       AppendFormat ("-{0}-", 1).AppendLine ();
+                               return sb.ToString ();
                        }
 
-                       private int ReturnInt()
+                       public void StringBuilderBad ()
                        {
-                               return 0;
+                               StringBuilder sb = new StringBuilder ();
+                               sb.Append ("test").Insert (2, true).Remove (0, 
1).Replace ("oh", "ah").
+                                       AppendFormat ("-{0}-", 1).AppendLine ();
+                               // this is not ok
+                               sb.ToString ();
                        }
+
+                       public void DirectoryOk ()
+                       {
+                               // the DirectoryInfo this returns may not be 
needed
+                               Directory.CreateDirectory ("mono");
+
+                               DirectoryInfo di = Directory.CreateDirectory 
("2.0");
+                               // the DirectoryInfo this returns may not be 
needed
+                               di.CreateSubdirectory ("gac");
+                       }
+
+                       public void DirectoryBad ()
+                       {
+                               DirectoryInfo di = Directory.CreateDirectory 
("mono");
+                               // this is not ok
+                               di.GetDirectories ();
+                       }
+
+                       public void PermissionSetOk ()
+                       {
+                               PermissionSet set = new PermissionSet 
(PermissionState.None);
+                               // the IPermission this returns may not be 
needed
+                               set.AddPermission (new GacIdentityPermission 
());
+                               set.RemovePermission (typeof 
(GacIdentityPermission));
+                       }
+
+                       public void PermissionSetBad ()
+                       {
+                               PermissionSet set = new PermissionSet 
(PermissionState.None);
+                               // this is not ok
+                               set.Union (set);
+                       }
+
+                       void TimeoutCallback (object state)
+                       {
+                       }
+
+                       public void TimerOk ()
+                       {
+                               new Timer (TimeoutCallback, null, 3000, 
Timeout.Infinite);
+                       }
                }
 
                private IMethodRule rule;
@@ -112,14 +165,40 @@
                }
 
                [Test]
-               public void TestStringBuilder()
+               public void TestStringBuilder ()
                {
-                       MethodDefinition method = GetTest("NotAViolation");
-                       Assert.IsNull(CheckMethod(method));
+                       MethodDefinition method = GetTest ("StringBuilderOk");
+                       Assert.IsNull (CheckMethod (method), "Ok");
+
+                       method = GetTest ("StringBuilderBad");
+                       Assert.IsNotNull (CheckMethod (method), "Bad");
                }
 
+               [Test]
+               public void TestDirectory ()
+               {
+                       MethodDefinition method = GetTest ("DirectoryOk");
+                       Assert.IsNull (CheckMethod (method), "Ok");
 
+                       method = GetTest ("DirectoryBad");
+                       Assert.IsNotNull (CheckMethod (method), "Bad");
+               }
 
+               [Test]
+               public void TestPermissionSet ()
+               {
+                       MethodDefinition method = GetTest ("PermissionSetOk");
+                       Assert.IsNull (CheckMethod (method), "Ok");
 
+                       method = GetTest ("PermissionSetBad");
+                       Assert.IsNotNull (CheckMethod (method), "Bad");
+               }
+
+               [Test]
+               public void TestTimer ()
+               {
+                       MethodDefinition method = GetTest ("TimerOk");
+                       Assert.IsNull (CheckMethod (method), "Ok");
+               }
        }
 }

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

Reply via email to