Author: spouliot
Date: 2007-12-26 15:57:36 -0500 (Wed, 26 Dec 2007)
New Revision: 91904
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AbstractTypesShouldNotHavePublicConstructorsTest.cs
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AvoidEmptyInterfaceTest.cs
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPropertiesWithoutGetAccessorTest.cs
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldDefineAZeroValueTest.cs
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/FlagsShouldNotDefineAZeroValueTest.cs
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/TypesShouldBeInsideNamespacesTest.cs
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs
Log:
2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
* AbstractTypesShouldNotHavePublicConstructorsTest.cs: New. Unit tests
* AvoidEmptyInterfaceTest.cs: New. Unit tests
* AvoidPropertiesWithoutGetAccessorTest.cs: New. Unit tests
* EnumsShouldDefineAZeroValueTest.cs: New. Unit tests
* FlagsShouldNotDefineAZeroValueTest.cs: New. Unit tests
* TypesShouldBeInsideNamespacesTest.cs: New. Unit tests
* UsingCloneWithoutImplementingICloneableTest.cs: Add test cases
for inheritance.
* Test.Rules.Design.mdp: Add new unit test to MonoDevelop project
file.
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AbstractTypesShouldNotHavePublicConstructorsTest.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AbstractTypesShouldNotHavePublicConstructorsTest.cs
2007-12-26 20:34:12 UTC (rev 91903)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AbstractTypesShouldNotHavePublicConstructorsTest.cs
2007-12-26 20:57:36 UTC (rev 91904)
@@ -0,0 +1,135 @@
+//
+// Unit tests for AbstractTypesShouldNotHavePublicConstructorsRule
+//
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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 {
+
+ public abstract class PublicAbstractClass {
+ public abstract int X { get; }
+ }
+
+ public abstract class PublicAbstractClassWithPublicCtor {
+
+ public PublicAbstractClassWithPublicCtor ()
+ {
+ }
+ }
+
+ public abstract class PublicAbstractClassWithProtectedCtor {
+
+ protected PublicAbstractClassWithProtectedCtor ()
+ {
+ }
+ }
+
+ [TestFixture]
+ public class AbstractTypesShouldNotHavePublicConstructorsTest {
+
+ public abstract class NestedPublicAbstractClass {
+ public abstract int X { get; }
+ }
+
+ public abstract class NestedPublicAbstractClassWithPublicCtors {
+
+ public NestedPublicAbstractClassWithPublicCtors ()
+ {
+ }
+
+ public NestedPublicAbstractClassWithPublicCtors (int x)
+ {
+ }
+ }
+
+ public abstract class
NestedPublicAbstractClassWithProtectedCtors {
+
+ protected NestedPublicAbstractClassWithProtectedCtors ()
+ {
+ }
+
+ protected NestedPublicAbstractClassWithProtectedCtors
(int x)
+ {
+ }
+ }
+
+ private ITypeRule rule;
+ private AssemblyDefinition assembly;
+ private Runner runner;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ rule = new
AbstractTypesShouldNotHavePublicConstructorsRule ();
+ runner = new MinimalRunner ();
+ }
+
+ private TypeDefinition GetType (string name)
+ {
+ string fullname = "Test.Rules.Design." + name;
+ return assembly.MainModule.Types [fullname];
+ }
+
+ [Test]
+ public void WithNoConstructors ()
+ {
+ TypeDefinition type = GetType ("PublicAbstractClass");
+ Assert.IsNull (rule.CheckType (type, runner),
"PublicAbstractClass");
+
+ type = GetType
("AbstractTypesShouldNotHavePublicConstructorsTest/NestedPublicAbstractClass");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedPublicAbstractClass");
+ }
+
+ [Test]
+ public void WithPublicConstructors ()
+ {
+ TypeDefinition type = GetType
("PublicAbstractClassWithPublicCtor");
+ Assert.AreEqual (1, rule.CheckType (type,
runner).Count, "PublicAbstractClassWithPublicCtor");
+
+ type = GetType
("AbstractTypesShouldNotHavePublicConstructorsTest/NestedPublicAbstractClassWithPublicCtors");
+ Assert.AreEqual (2, rule.CheckType (type,
runner).Count, "NestedPublicAbstractClassWithPublicCtors");
+ }
+
+ [Test]
+ public void WithProtectedConstructors ()
+ {
+ TypeDefinition type = GetType
("PublicAbstractClassWithProtectedCtor");
+ Assert.IsNull (rule.CheckType (type, runner),
"PublicAbstractClassWithProtectedCtor");
+
+ type = GetType
("AbstractTypesShouldNotHavePublicConstructorsTest/NestedPublicAbstractClassWithProtectedCtors");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedPublicAbstractClassWithProtectedCtors");
+ }
+ }
+}
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AvoidEmptyInterfaceTest.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AvoidEmptyInterfaceTest.cs
2007-12-26 20:34:12 UTC (rev 91903)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AvoidEmptyInterfaceTest.cs
2007-12-26 20:57:36 UTC (rev 91904)
@@ -0,0 +1,95 @@
+//
+// Unit tests for AvoidEmptyInterfaceRule
+//
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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 AvoidEmptyInterfaceTest {
+
+ interface IAmEmpty {
+ }
+
+ interface IAmNotEmpty {
+ int GetMe ();
+ }
+
+ interface IImplementSeveralInterfaces : IAmEmpty, IAmNotEmpty {
+ }
+
+ private ITypeRule rule;
+ private AssemblyDefinition assembly;
+ private Runner runner;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ rule = new AvoidEmptyInterfaceRule ();
+ runner = new MinimalRunner ();
+ }
+
+ private TypeDefinition GetTest (string name)
+ {
+ string fullname =
"Test.Rules.Design.AvoidEmptyInterfaceTest" + name;
+ return assembly.MainModule.Types [fullname];
+ }
+
+ [Test]
+ public void NotAnInterface ()
+ {
+ TypeDefinition type = GetTest (String.Empty);
+ Assert.IsNull (rule.CheckType (type, runner));
+ }
+
+ [Test]
+ public void Empty ()
+ {
+ TypeDefinition type = GetTest ("/IAmEmpty");
+ Assert.IsNotNull (rule.CheckType (type, runner));
+ }
+
+ [Test]
+ public void NotEmpty ()
+ {
+ TypeDefinition type = GetTest ("/IAmNotEmpty");
+ Assert.IsNull (rule.CheckType (type, runner),
"IAmNotEmpty");
+
+ type = GetTest ("/IImplementSeveralInterfaces");
+ Assert.IsNull (rule.CheckType (type, runner),
"IImplementSeveralInterfaces");
+ }
+ }
+}
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPropertiesWithoutGetAccessorTest.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPropertiesWithoutGetAccessorTest.cs
2007-12-26 20:34:12 UTC (rev 91903)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPropertiesWithoutGetAccessorTest.cs
2007-12-26 20:57:36 UTC (rev 91904)
@@ -0,0 +1,222 @@
+//
+// Unit tests for AvoidPropertiesWithoutGetAccessorRule
+//
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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 {
+
+ public abstract class PublicAbstract {
+ public abstract int Value { get; set; }
+ }
+
+ public abstract class PublicAbstractGetOnly {
+ public abstract int Value { get; }
+ }
+
+ public abstract class PublicAbstractSetOnly {
+ public abstract int Value { set; }
+ }
+
+ public interface IPublic {
+ int Value { get; set; }
+ }
+
+ public interface IPublicGetOnly {
+ int Value { get; }
+ }
+
+ public interface IPublicSetOnly {
+ int Value { set; }
+ }
+
+ public class PublicClassInterface : IPublic {
+ public int Value {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+ }
+
+ public class PublicClassExplicitInterface : IPublic {
+ int IPublic.Value {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+ }
+
+ public class PublicClass {
+ public int Value {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+ }
+
+ public class PublicSetOnlyInheritClass : PublicAbstractSetOnly {
+ public override int Value {
+ set { throw new NotImplementedException (); }
+ }
+ }
+
+ public class PublicSetOnlyImplementClass : IPublicSetOnly {
+ public int Value {
+ set { throw new NotImplementedException (); }
+ }
+ }
+
+#if false
+ // this cannot be compiled with CSC - error CS0082
+ public class PublicGetIsNotAGetterClass : IPublicSetOnly {
+
+ // try to confuse the rule
+ public int get_Value ()
+ {
+ return 42;
+ }
+
+ public int Value {
+ set { throw new NotImplementedException (); }
+ }
+ }
+#endif
+ public class PublicSetIsNotASetterClass {
+
+ public void set_Value ()
+ {
+ }
+ }
+
+ [TestFixture]
+ public class AvoidPropertiesWithoutGetAccessorTest {
+
+
+ private IMethodRule rule;
+ private AssemblyDefinition assembly;
+ private Runner runner;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ rule = new AvoidPropertiesWithoutGetAccessorRule ();
+ runner = new MinimalRunner ();
+ }
+
+ private TypeDefinition GetType (string name)
+ {
+ string fullname = "Test.Rules.Design." + name;
+ return assembly.MainModule.Types [fullname];
+ }
+
+ [Test]
+ public void WithNoProperties ()
+ {
+ TypeDefinition type = GetType
("AvoidPropertiesWithoutGetAccessorTest");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNull (rule.CheckMethod (method,
runner), method.Name);
+ }
+ }
+
+ [Test]
+ public void WithBothGetAndSet ()
+ {
+ TypeDefinition type = GetType ("PublicAbstract");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+
+ type = GetType ("IPublic");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+
+ type = GetType ("PublicClass");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+
+ type = GetType ("PublicClassExplicitInterface");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+
+ type = GetType ("PublicClassInterface");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+ }
+
+ [Test]
+ public void WithOnlyGet ()
+ {
+ TypeDefinition type = GetType ("PublicAbstractGetOnly");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+
+ type = GetType ("IPublicGetOnly");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+ }
+
+ [Test]
+ public void WithOnlySet ()
+ {
+ TypeDefinition type = GetType ("PublicAbstractSetOnly");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNotNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+
+ type = GetType ("IPublicSetOnly");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNotNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+
+ type = GetType ("PublicSetOnlyInheritClass");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNotNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+
+ type = GetType ("PublicSetOnlyImplementClass");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNotNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+
+ type = GetType ("PublicSetIsNotASetterClass");
+ foreach (MethodDefinition method in type.Methods) {
+ Assert.IsNull (rule.CheckMethod (method,
runner), method.ToString ());
+ }
+ }
+ }
+}
Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
2007-12-26 20:34:12 UTC (rev 91903)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
2007-12-26 20:57:36 UTC (rev 91904)
@@ -1,3 +1,16 @@
+2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * AbstractTypesShouldNotHavePublicConstructorsTest.cs: New. Unit tests
+ * AvoidEmptyInterfaceTest.cs: New. Unit tests
+ * AvoidPropertiesWithoutGetAccessorTest.cs: New. Unit tests
+ * EnumsShouldDefineAZeroValueTest.cs: New. Unit tests
+ * FlagsShouldNotDefineAZeroValueTest.cs: New. Unit tests
+ * TypesShouldBeInsideNamespacesTest.cs: New. Unit tests
+ * UsingCloneWithoutImplementingICloneableTest.cs: Add test cases
+ for inheritance.
+ * Test.Rules.Design.mdp: Add new unit test to MonoDevelop project
+ file.
+
2007-11-22 Sebastien Pouliot <[EMAIL PROTECTED]>
* UsingCloneWithoutImplementingICloneableTest.cs: Add a test case
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldDefineAZeroValueTest.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldDefineAZeroValueTest.cs
2007-12-26 20:34:12 UTC (rev 91903)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldDefineAZeroValueTest.cs
2007-12-26 20:57:36 UTC (rev 91904)
@@ -0,0 +1,129 @@
+//
+// Unit tests for EnumsShouldDefineAZeroValueRule
+//
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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 {
+
+ enum PrivateEnumWithZeroValue {
+ Zero,
+ One,
+ Two
+ }
+
+ internal enum InternalEnumWithoutZeroValue {
+ One = 1,
+ Two,
+ Three
+ }
+
+ [TestFixture]
+ public class EnumsShouldDefineAZeroValueTest {
+
+ public enum NestedPublicEnumWithZeroValue {
+ Zero
+ }
+
+ [Flags]
+ private enum NestedInternalFlagsWithZeroValue {
+ GhostBit = 0,
+ FirstBit,
+ }
+
+ [Flags]
+ private enum NestedPrivateFlagsWithoutZeroValue {
+ FirstBit = 1,
+ SecondBit = 2,
+ ThirdBit = 4
+ }
+
+ private ITypeRule rule;
+ private AssemblyDefinition assembly;
+ private Runner runner;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ rule = new EnumsShouldDefineAZeroValueRule ();
+ runner = new MinimalRunner ();
+ }
+
+ private TypeDefinition GetTest (string name)
+ {
+ string fullname = "Test.Rules.Design." + name;
+ return assembly.MainModule.Types [fullname];
+ }
+
+ [Test]
+ public void NotAnEnumType ()
+ {
+ TypeDefinition type = GetTest
("EnumsShouldDefineAZeroValueTest");
+ Assert.IsNull (rule.CheckType (type, runner));
+ }
+
+ [Test]
+ public void EnumWithZeroValue ()
+ {
+ TypeDefinition type = GetTest
("PrivateEnumWithZeroValue");
+ Assert.IsNull (rule.CheckType (type, runner),
"PrivateEnumWithZeroValue");
+
+ type = GetTest
("EnumsShouldDefineAZeroValueTest/NestedPublicEnumWithZeroValue");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedPublicEnumWithZeroValue");
+ }
+
+ [Test]
+ public void EnumWithoutZeroValue ()
+ {
+ TypeDefinition type = GetTest
("InternalEnumWithoutZeroValue");
+ Assert.IsNotNull (rule.CheckType (type, runner));
+ }
+
+ [Test]
+ public void FlagWithoutZeroValue ()
+ {
+ TypeDefinition type = GetTest
("EnumsShouldDefineAZeroValueTest/NestedPrivateFlagsWithoutZeroValue");
+ Assert.IsNull (rule.CheckType (type, runner));
+ }
+
+ [Test]
+ public void FlagWithZeroValue ()
+ {
+ // flags are ignored by the rule
+ TypeDefinition type = GetTest
("EnumsShouldDefineAZeroValueTest/NestedInternalFlagsWithZeroValue");
+ Assert.IsNull (rule.CheckType (type, runner));
+ }
+ }
+}
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/FlagsShouldNotDefineAZeroValueTest.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/FlagsShouldNotDefineAZeroValueTest.cs
2007-12-26 20:34:12 UTC (rev 91903)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/FlagsShouldNotDefineAZeroValueTest.cs
2007-12-26 20:57:36 UTC (rev 91904)
@@ -0,0 +1,125 @@
+//
+// Unit tests for FlagsShouldNotDefineAZeroValueTest
+//
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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 {
+
+ [Flags]
+ enum PrivateFlagsWithZeroValue {
+ Zero = 0,
+ One = 1,
+ Two = 2
+ }
+
+ [Flags]
+ internal enum InternalFlagsWithoutZeroValue {
+ Zero = 1,
+ One = 2,
+ Two = 4
+ }
+
+ [TestFixture]
+ public class FlagsShouldNotDefineAZeroValueTest {
+
+ public enum NestedPublicEnumWithZeroValue {
+ Zero
+ }
+
+ private enum NestedPrivateEnumWithoutZeroValue {
+ FirstBit = 1,
+ SecondBit = 2,
+ ThirdBit = 4
+ }
+
+ [Flags]
+ private enum NestedInternalFlagsWithZeroValue {
+ GhostBit = 0,
+ FirstBit,
+ }
+
+ private ITypeRule rule;
+ private AssemblyDefinition assembly;
+ private Runner runner;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ rule = new FlagsShouldNotDefineAZeroValueRule ();
+ runner = new MinimalRunner ();
+ }
+
+ private TypeDefinition GetTest (string name)
+ {
+ string fullname = "Test.Rules.Design." + name;
+ return assembly.MainModule.Types [fullname];
+ }
+
+ [Test]
+ public void NotAnEnumType ()
+ {
+ TypeDefinition type = GetTest
("FlagsShouldNotDefineAZeroValueTest");
+ Assert.IsNull (rule.CheckType (type, runner));
+ }
+
+ [Test]
+ public void NotAFlags ()
+ {
+ TypeDefinition type = GetTest
("FlagsShouldNotDefineAZeroValueTest/NestedPublicEnumWithZeroValue");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedPublicEnumWithZeroValue");
+
+ type = GetTest
("FlagsShouldNotDefineAZeroValueTest/NestedPrivateEnumWithoutZeroValue");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedPrivateEnumWithoutZeroValue");
+ }
+
+ [Test]
+ public void FlagsWithoutZeroValue ()
+ {
+ TypeDefinition type = GetTest
("InternalFlagsWithoutZeroValue");
+ Assert.IsNull (rule.CheckType (type, runner),
"InternalFlagsWithoutZeroValue");
+ }
+
+ [Test]
+ public void FlagsWithZeroValue ()
+ {
+ TypeDefinition type = GetTest
("PrivateFlagsWithZeroValue");
+ Assert.IsNotNull (rule.CheckType (type, runner),
"PrivateFlagsWithZeroValue");
+
+ type = GetTest
("FlagsShouldNotDefineAZeroValueTest/NestedInternalFlagsWithZeroValue");
+ Assert.IsNotNull (rule.CheckType (type, runner),
"NestedInternalFlagsWithZeroValue");
+ }
+ }
+}
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
2007-12-26 20:34:12 UTC (rev 91903)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
2007-12-26 20:57:36 UTC (rev 91904)
@@ -7,15 +7,21 @@
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True"
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
</Configuration>
<Configuration name="Release" ctype="DotNetProjectConfiguration">
- <Output directory="./bin/Release" assembly="Test.Rules.Design" />
+ <Output directory="bin/Release" assembly="Test.Rules.Design" />
<Build debugmode="False" target="Library" />
<Execution runwithwarnings="True" consolepause="False" runtime="MsNet"
clr-version="Net_2_0" />
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True"
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
</Configuration>
</Configurations>
<Contents>
- <File name="./DontDeclareProtectedFieldsInSealedClassTest.cs"
subtype="Code" buildaction="Compile" />
- <File name="./UsingCloneWithoutImplementingICloneableTest.cs"
subtype="Code" buildaction="Compile" />
+ <File name="DontDeclareProtectedFieldsInSealedClassTest.cs" subtype="Code"
buildaction="Compile" />
+ <File name="UsingCloneWithoutImplementingICloneableTest.cs" subtype="Code"
buildaction="Compile" />
+ <File name="AbstractTypesShouldNotHavePublicConstructorsTest.cs"
subtype="Code" buildaction="Compile" />
+ <File name="AvoidEmptyInterfaceTest.cs" subtype="Code"
buildaction="Compile" />
+ <File name="AvoidPropertiesWithoutGetAccessorTest.cs" subtype="Code"
buildaction="Compile" />
+ <File name="EnumsShouldDefineAZeroValueTest.cs" subtype="Code"
buildaction="Compile" />
+ <File name="FlagsShouldNotDefineAZeroValueTest.cs" subtype="Code"
buildaction="Compile" />
+ <File name="TypesShouldBeInsideNamespacesTest.cs" subtype="Code"
buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Assembly" localcopy="True"
refto="../../../../lib/Mono.Cecil.dll" />
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/TypesShouldBeInsideNamespacesTest.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/TypesShouldBeInsideNamespacesTest.cs
2007-12-26 20:34:12 UTC (rev 91903)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/TypesShouldBeInsideNamespacesTest.cs
2007-12-26 20:57:36 UTC (rev 91904)
@@ -0,0 +1,158 @@
+//
+// Unit tests for TypesShouldBeInsideNamespacesRule
+//
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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;
+
+public class PublicTypeOutsideNamescape {
+ public class NestedPublicTypeOutsideNamescape {
+ }
+
+ protected class NestedProtectedTypeOutsideNamespace {
+ }
+
+ internal class NestedInternalTypeOutsideNamespace {
+ }
+
+ private class NestedPrivateClassOutsideNamespace {
+ }
+}
+
+internal class InternalTypeOutsideNamespace {
+}
+
+class PrivateClassOutsideNamespace {
+}
+
+namespace Test.Rules.Design {
+
+ public class PublicTypeInsideNamescape {
+ public class NestedPublicTypeInsideNamescape {
+ }
+
+ protected class NestedProtectedTypeInsideNamespace {
+ }
+
+ internal class NestedInternalTypeInsideNamespace {
+ }
+
+ private class NestedPrivateClassInsideNamespace {
+ }
+ }
+
+ internal class InternalTypeInsideNamespace {
+ }
+
+ class PrivateClassInsideNamespace {
+ }
+
+ [TestFixture]
+ public class TypesShouldBeInsideNamespacesTest {
+
+ private ITypeRule rule;
+ private AssemblyDefinition assembly;
+ private Runner runner;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ rule = new TypesShouldBeInsideNamespacesRule ();
+ runner = new MinimalRunner ();
+ }
+
+ private TypeDefinition GetType (string name)
+ {
+ return assembly.MainModule.Types [name];
+ }
+
+ [Test]
+ public void OutsideNamespace ()
+ {
+ TypeDefinition type = GetType
("PublicTypeOutsideNamescape");
+ Assert.IsNotNull (rule.CheckType (type, runner),
"PublicTypeOutsideNamescape");
+
+ type = GetType ("InternalTypeOutsideNamespace");
+ Assert.IsNull (rule.CheckType (type, runner),
"InternalTypeOutsideNamespace");
+
+ type = GetType ("PrivateClassOutsideNamespace");
+ Assert.IsNull (rule.CheckType (type, runner),
"PrivateClassOutsideNamespace");
+ }
+
+ [Test]
+ public void NestedOutsideNamespace ()
+ {
+ TypeDefinition type = GetType
("PublicTypeOutsideNamescape/NestedPublicTypeOutsideNamescape");
+ Assert.IsNotNull (rule.CheckType (type, runner),
"NestedPublicTypeInsideNamescape");
+
+ type = GetType
("PublicTypeOutsideNamescape/NestedProtectedTypeOutsideNamespace");
+ Assert.IsNotNull (rule.CheckType (type, runner),
"NestedProtectedTypeOutsideNamespace");
+
+ type = GetType
("PublicTypeOutsideNamescape/NestedInternalTypeOutsideNamespace");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedInternalTypeInsideNamespace");
+
+ type = GetType
("PublicTypeOutsideNamescape/NestedPrivateClassOutsideNamespace");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedPrivateClassInsideNamespace");
+ }
+
+ [Test]
+ public void InsideNamespace ()
+ {
+ TypeDefinition type = GetType
("Test.Rules.Design.PublicTypeInsideNamescape");
+ Assert.IsNull (rule.CheckType (type, runner),
"PublicTypeInsideNamescape");
+
+ type = GetType
("Test.Rules.Design.InternalTypeInsideNamespace");
+ Assert.IsNull (rule.CheckType (type, runner),
"InternalTypeInsideNamespace");
+
+ type = GetType
("Test.Rules.Design.PrivateClassInsideNamespace");
+ Assert.IsNull (rule.CheckType (type, runner),
"PrivateClassInsideNamespace");
+ }
+
+ [Test]
+ public void NestedInsideNamespace ()
+ {
+ TypeDefinition type = GetType
("Test.Rules.Design.PublicTypeInsideNamescape/NestedPublicTypeInsideNamescape");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedPublicTypeInsideNamescape");
+
+ type = GetType
("Test.Rules.Design.PublicTypeInsideNamescape/NestedProtectedTypeInsideNamespace");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedProtectedTypeInsideNamespace");
+
+ type = GetType
("Test.Rules.Design.PublicTypeInsideNamescape/NestedInternalTypeInsideNamespace");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedInternalTypeInsideNamespace");
+
+ type = GetType
("Test.Rules.Design.PublicTypeInsideNamescape/NestedPrivateClassInsideNamespace");
+ Assert.IsNull (rule.CheckType (type, runner),
"NestedPrivateClassInsideNamespace");
+ }
+ }
+}
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs
2007-12-26 20:34:12 UTC (rev 91903)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs
2007-12-26 20:57:36 UTC (rev 91904)
@@ -27,6 +27,7 @@
// THE SOFTWARE.
using System;
+using System.Collections;
using System.Reflection;
using Gendarme.Framework;
@@ -40,7 +41,7 @@
public class UsingCloneWithoutImplementingICloneableTest {
public class UsingCloneAndImplementingICloneable: ICloneable
{
- public object Clone ()
+ public virtual object Clone ()
{
return this.MemberwiseClone ();
}
@@ -84,6 +85,32 @@
return new CloningType ();
}
}
+
+ // ArrayList implements ICloneable but it located in another
assembly (mscorlib)
+ public class MyArrayList : ArrayList {
+
+ public override object Clone ()
+ {
+ return new MyArrayList ();
+ }
+ }
+
+ public class SecondLevelClone :
UsingCloneAndImplementingICloneable {
+
+ // CS0108 on purpose
+ public object Clone ()
+ {
+ return new SecondLevelClone ();
+ }
+ }
+
+ public class SecondLevelCloneWithOverride :
UsingCloneAndImplementingICloneable {
+
+ public override object Clone ()
+ {
+ return new SecondLevelCloneWithOverride ();
+ }
+ }
private ITypeRule typeRule;
private AssemblyDefinition assembly;
@@ -152,5 +179,27 @@
type = GetTest ("CloningType");
Assert.IsNotNull (typeRule.CheckType (type, new
MinimalRunner ()));
}
+
+ [Test]
+ [Ignore ("Type located outside this assembly - need
AssemblyResolver")]
+ public void InheritFromTypeOutsideAssembly ()
+ {
+ type = GetTest ("MyArrayList");
+ Assert.IsNull (typeRule.CheckType (type, new
MinimalRunner ()));
+ }
+
+ [Test]
+ public void
InheritFromTypeImplementingICloneableButWithoutOverride ()
+ {
+ type = GetTest ("SecondLevelClone");
+ Assert.IsNull (typeRule.CheckType (type, new
MinimalRunner ()));
+ }
+
+ [Test]
+ public void InheritFromTypeImplementingICloneable ()
+ {
+ type = GetTest ("SecondLevelCloneWithOverride");
+ Assert.IsNull (typeRule.CheckType (type, new
MinimalRunner ()));
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches