Author: spouliot
Date: 2008-02-07 22:44:10 -0500 (Thu, 07 Feb 2008)
New Revision: 95219

Added:
   
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldUseInt32Test.cs
Modified:
   trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
   
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
Log:
2008-02-07  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * EnumsShouldUseInt32Test.cs: New. Unit tests.
        * Test.Rules.Design.mdp: Update project file.



Modified: trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog        
2008-02-08 03:39:18 UTC (rev 95218)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog        
2008-02-08 03:44:10 UTC (rev 95219)
@@ -1,3 +1,8 @@
+2008-02-07  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * EnumsShouldUseInt32Test.cs: New. Unit tests.
+       * Test.Rules.Design.mdp: Update project file.
+
 2008-02-07  Nestor Salceda  <[EMAIL PROTECTED]>
 
        * FinalizersShouldCallBaseClassFinalizerTest.cs:Replaced 
TypeDefinition.GetFinalizer

Added: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldUseInt32Test.cs
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldUseInt32Test.cs
       2008-02-08 03:39:18 UTC (rev 95218)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldUseInt32Test.cs
       2008-02-08 03:44:10 UTC (rev 95219)
@@ -0,0 +1,138 @@
+// 
+// Unit tests for EnumsShouldUseInt32Rule
+//
+// Authors:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// 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.Reflection;
+
+using Mono.Cecil;
+
+using Gendarme.Framework;
+using Gendarme.Rules.Design;
+
+using NUnit.Framework;
+
+namespace Test.Rules.Design {
+
+       [TestFixture]
+       public class EnumsShouldUseInt32Test {
+
+               public enum DefaultEnum {
+               }
+
+               public enum ByteEnum : byte {
+               }
+
+               public enum SignedByteEnum : sbyte {
+               }
+
+               public enum ShortEnum : short {
+               }
+
+               public enum UnsignedShortEnum : ushort {
+               }
+
+               public enum IntEnum : int {
+               }
+
+               public enum UnsignedIntEnum : uint {
+               }
+
+               public enum LongEnum : long {
+               }
+
+               public enum UnsignedLongEnum : ulong {
+               }
+
+               private ITypeRule rule;
+               private AssemblyDefinition assembly;
+               private Runner runner;
+
+               [TestFixtureSetUp]
+               public void FixtureSetUp ()
+               {
+                       string unit = Assembly.GetExecutingAssembly ().Location;
+                       assembly = AssemblyFactory.GetAssembly (unit);
+                       rule = new EnumsShouldUseInt32Rule ();
+                       runner = new MinimalRunner ();
+               }
+
+               private TypeDefinition GetTest (string name)
+               {
+                       string fullname = 
"Test.Rules.Design.EnumsShouldUseInt32Test" + name;
+                       return assembly.MainModule.Types [fullname];
+               }
+
+               [Test]
+               public void NotAnEnum ()
+               {
+                       TypeDefinition type = GetTest (String.Empty);
+                       Assert.IsNull (rule.CheckType (type, runner));
+               }
+
+               [Test]
+               public void Ok ()
+               {
+                       TypeDefinition type = GetTest ("/DefaultEnum");
+                       Assert.IsNull (rule.CheckType (type, runner), 
"DefaultEnum");
+
+                       type = GetTest ("/IntEnum");
+                       Assert.IsNull (rule.CheckType (type, runner), 
"IntEnum");
+               }
+
+               [Test]
+               public void Bad ()
+               {
+                       // CLS compliant types: Byte, Int16 or Int64 (Int32 is 
CLS but Ok)
+
+                       TypeDefinition type = GetTest ("/ByteEnum");
+                       Assert.IsNotNull (rule.CheckType (type, runner), 
"ByteEnum");
+
+                       type = GetTest ("/ShortEnum");
+                       Assert.IsNotNull (rule.CheckType (type, runner), 
"ShortEnum");
+
+                       type = GetTest ("/LongEnum");
+                       Assert.IsNotNull (rule.CheckType (type, runner), 
"LongEnum");
+               }
+
+               [Test]
+               public void ReallyBad ()
+               {
+                       // i.e. using non-CLS compliant types, SByte, UInt16, 
UInt32 or UInt64
+
+                       TypeDefinition type = GetTest ("/SignedByteEnum");
+                       Assert.IsNotNull (rule.CheckType (type, runner), 
"SignedByteEnum");
+
+                       type = GetTest ("/UnsignedShortEnum");
+                       Assert.IsNotNull (rule.CheckType (type, runner), 
"UnsignedShortEnum");
+
+                       type = GetTest ("/UnsignedIntEnum");
+                       Assert.IsNotNull (rule.CheckType (type, runner), 
"UnsignedIntEnum");
+
+                       type = GetTest ("/UnsignedLongEnum");
+                       Assert.IsNotNull (rule.CheckType (type, runner), 
"UnsignedLongEnum");
+               }
+       }
+}

Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
    2008-02-08 03:39:18 UTC (rev 95218)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
    2008-02-08 03:44:10 UTC (rev 95219)
@@ -32,6 +32,13 @@
     <File name="TypesWithNativeFieldsShouldBeDisposableTest.cs" subtype="Code" 
buildaction="Compile" />
     <File name="FinalizersShouldBeProtectedTest.cs" subtype="Code" 
buildaction="Compile" />
     <File name="FinalizersShouldCallBaseClassFinalizerTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="AttributeArgumentsShouldHaveAccessorsTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="EnsureSymmetryForOverloadedOperatorsTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="EnumsShouldUseInt32Test.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="ImplementEqualsAndGetHashCodeInPairTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="OperatorEqualsShouldBeOverloadedTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="OverrideEqualsMethodTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="ProvideAlternativeNamesForOperatorOverloadsTest.cs" 
subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Assembly" localcopy="True" 
refto="../../../../lib/Mono.Cecil.dll" />

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

Reply via email to