Author: spouliot
Date: 2007-12-26 15:34:12 -0500 (Wed, 26 Dec 2007)
New Revision: 91903
Added:
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/CustomAttributeRocks.cs
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
trunk/cecil/gendarme/framework/Test/
trunk/cecil/gendarme/framework/Test/ChangeLog
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/ChangeLog
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/CustomAttributeRocksTest.cs
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/MethodRocksTest.cs
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/TypeRocksTest.cs
trunk/cecil/gendarme/framework/Test/Test.Framework.mdp
Modified:
trunk/cecil/gendarme/framework/ChangeLog
trunk/cecil/gendarme/framework/Location.cs
trunk/cecil/gendarme/framework/Makefile.am
trunk/cecil/gendarme/framework/framework.mdp
Log:
In Test:
2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
* Test.Framework.mdp: MonoDevelop project file for unit tests
In Test/Gendarme.Framework.Rocks:
2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
* CustomAttributeRocksTest.cs: New. Unit tests for CustomAttributeRocks
* MethodRocksTest.cs: New. Unit tests for MethodRocks
* TypeRocksTest.cs: New. Unit tests for TypeRocks
In .:
2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
* Makefile.am: Add rocks to the build, switch compiler to linq
* framework.mdp: Add rocks to the MonoDevelop project file, switch
compiler to linq.
* Location.cs: Add new constructors that accept a
[Method|Type]Definition to simplify rules.
In Gendarme.Framework.Rocks:
2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
* CustomAttributeRocks.cs: New. Extension methods for Cecil's
CustomAttribute[Collection] classes.
* MethodRocks.cs: New. Extension methods for Cecil's
Method[Reference|Definition][Collection] classes.
* TypeRocks.cs: New. Extension methods for Cecil's
Type[Reference|Definition][Collection] classes.
Modified: trunk/cecil/gendarme/framework/ChangeLog
===================================================================
--- trunk/cecil/gendarme/framework/ChangeLog 2007-12-26 18:09:49 UTC (rev
91902)
+++ trunk/cecil/gendarme/framework/ChangeLog 2007-12-26 20:34:12 UTC (rev
91903)
@@ -1,3 +1,11 @@
+2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * Makefile.am: Add rocks to the build, switch compiler to linq
+ * framework.mdp: Add rocks to the MonoDevelop project file, switch
+ compiler to linq.
+ * Location.cs: Add new constructors that accept a
+ [Method|Type]Definition to simplify rules.
+
2007-12-16 Sebastien Pouliot <[EMAIL PROTECTED]>
* AssemblyManager.cs: Make class static since we're now targetting
Added: trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
===================================================================
--- trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
2007-12-26 18:09:49 UTC (rev 91902)
+++ trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
2007-12-26 20:34:12 UTC (rev 91903)
@@ -0,0 +1,8 @@
+2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * CustomAttributeRocks.cs: New. Extension methods for Cecil's
+ CustomAttribute[Collection] classes.
+ * MethodRocks.cs: New. Extension methods for Cecil's
+ Method[Reference|Definition][Collection] classes.
+ * TypeRocks.cs: New. Extension methods for Cecil's
+ Type[Reference|Definition][Collection] classes.
Added:
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/CustomAttributeRocks.cs
===================================================================
---
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/CustomAttributeRocks.cs
2007-12-26 18:09:49 UTC (rev 91902)
+++
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/CustomAttributeRocks.cs
2007-12-26 20:34:12 UTC (rev 91903)
@@ -0,0 +1,65 @@
+//
+// Gendarme.Framework.Rocks.CustomAttributeRocks
+//
+// 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 Mono.Cecil;
+
+namespace Gendarme.Framework.Rocks {
+
+ // add CustomAttribute[Collection] extensions methods here
+ // only if:
+ // * you supply minimal documentation for them (xml)
+ // * you supply unit tests for them
+ // * they are required somewhere to simplify, even indirectly, the rules
+ // (i.e. don't bloat the framework in case of x, y or z in the future)
+
+ /// <summary>
+ /// CustomAttributeRocks contains extensions methods for CustomAttribute
+ /// and the related collection classes.
+ /// </summary>
+ public static class CustomAttributeRocks {
+
+ /// <summary>
+ /// Check if the custom attribute collection contains an
attribute of a specified type.
+ /// </summary>
+ /// <param name="self">The CustomAttributeCollection on which
the extension method can be called.</param>
+ /// <param name="attributeName">Full name of the attribute
class</param>
+ /// <returns>True if the collection contains an attribute of
the same name,
+ /// False otherwise.</returns>
+ public static bool Contains (this CustomAttributeCollection
self, string attributeName)
+ {
+ if (attributeName == null)
+ throw new ArgumentNullException
("attributeName");
+
+ foreach (CustomAttribute ca in self) {
+ if (ca.Constructor.DeclaringType.FullName ==
attributeName)
+ return true;
+ }
+ return false;
+ }
+ }
+}
Added: trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
===================================================================
--- trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
2007-12-26 18:09:49 UTC (rev 91902)
+++ trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
2007-12-26 20:34:12 UTC (rev 91903)
@@ -0,0 +1,143 @@
+//
+// Gendarme.Framework.Rocks.MethodRocks
+//
+// 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 Mono.Cecil;
+
+namespace Gendarme.Framework.Rocks {
+
+ // add CustomAttribute[Collection] extensions methods here
+ // only if:
+ // * you supply minimal documentation for them (xml)
+ // * you supply unit tests for them
+ // * they are required somewhere to simplify, even indirectly, the rules
+ // (i.e. don't bloat the framework in case of x, y or z in the future)
+
+ /// <summary>
+ /// MethodRocks contains extensions methods for
Method[Definition|Reference]
+ /// and the related collection classes.
+ ///
+ /// Note: whenever possible try to use MethodReference since it's
extend the
+ /// reach/usability of the code.
+ /// </summary>
+ public static class MethodRocks {
+
+ /// <summary>
+ /// Check if the method contains an attribute of a specified
type.
+ /// </summary>
+ /// <param name="self">The MethodDefinition on which the
extension method can be called.</param>
+ /// <param name="attributeName">Full name of the attribute
class</param>
+ /// <returns>True if the method contains an attribute of the
same name,
+ /// False otherwise.</returns>
+ public static bool HasAttribute (this MethodDefinition self,
string attributeName)
+ {
+ return self.CustomAttributes.Contains (attributeName);
+ }
+
+ /// <summary>
+ /// Check if the method was generated by the compiler.
+ /// </summary>
+ /// <param name="self">The MethodDefinition on which the
extension method can be called.</param>
+ /// <returns>True if the method as the [CompilerGenerated]
attribute, false otherwise.</returns>
+ public static bool IsCompilerGenerated (this MethodDefinition
self)
+ {
+ // FIXME: should we check the type too ?
+ return self.HasAttribute
("System.Runtime.CompilerServices.CompilerGeneratedAttribute");
+ }
+
+ /// <summary>
+ /// Check if the MethodReference is defined as the entry point
of it's assembly.
+ /// </summary>
+ /// <param name="self">The MethodReference on which the
extension method can be called.</param>
+ /// <returns>True if the method is defined as the entry point
of it's assembly, False otherwise</returns>
+ public static bool IsEntryPoint (this MethodReference self)
+ {
+ return (self ==
self.DeclaringType.Module.Assembly.EntryPoint);
+ }
+
+ /// <summary>
+ /// Check if the method corresponds to the get operation on a
property.
+ /// </summary>
+ /// <param name="self">The MethodDefinition on which the
extension method can be called.</param>
+ /// <returns>True if the method is a getter, False
otherwise</returns>
+ public static bool IsGetter (this MethodDefinition self)
+ {
+ return ((self.SemanticsAttributes &
MethodSemanticsAttributes.Getter) == MethodSemanticsAttributes.Getter);
+ }
+
+ /// <summary>
+ /// Check if the signature of a method is consitent for it's
use as a Main method.
+ /// Note: it doesn't check that the method is the EntryPoint of
it's assembly.
+ /// <code>
+ /// static [void|int] Main ()
+ /// static [void|int] Main (string[] args)
+ /// </code>
+ /// </summary>gre
+ /// <param name="self">The MethodDefinition on which the
extension method can be called.</param>
+ /// <returns>True if the method is a valid Main, False
otherwise.</returns>
+ public static bool IsMain (this MethodDefinition self)
+ {
+ // Main must be static
+ if (!self.IsStatic)
+ return false;
+
+ if (self.Name != "Main")
+ return false;
+
+ // Main must return void or int
+ switch (self.ReturnType.ReturnType.Name) {
+ case "Void":
+ case "Int32":
+ // ok, continue checks
+ break;
+ default:
+ return false;
+ }
+
+ switch (self.Parameters.Count) {
+ case 0:
+ // Main (void)
+ return true;
+ case 1:
+ // Main (string[] args)
+ return (self.Parameters [0].ParameterType.Name
== "String[]");
+ default:
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Check if the method corresponds to the set operation on a
property.
+ /// </summary>
+ /// <param name="self">The MethodDefinition on which the
extension method can be called.</param>
+ /// <returns>True if the method is a setter, False
otherwise</returns>
+ public static bool IsSetter (this MethodDefinition self)
+ {
+ return ((self.SemanticsAttributes &
MethodSemanticsAttributes.Setter) == MethodSemanticsAttributes.Setter);
+ }
+ }
+}
Added: trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
===================================================================
--- trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
2007-12-26 18:09:49 UTC (rev 91902)
+++ trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
2007-12-26 20:34:12 UTC (rev 91903)
@@ -0,0 +1,106 @@
+//
+// Gendarme.Framework.Rocks.TypeRocks
+//
+// 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 Mono.Cecil;
+
+namespace Gendarme.Framework.Rocks {
+
+ // add Type[Definition|Reference] extensions methods here
+ // only if:
+ // * you supply minimal documentation for them (xml)
+ // * you supply unit tests for them
+ // * they are required somewhere to simplify, even indirectly, the rules
+ // (i.e. don't bloat the framework in case of x, y or z in the future)
+
+ /// <summary>
+ /// TypeRocks contains extensions methods for Type[Definition|Reference]
+ /// and the related collection classes.
+ ///
+ /// Note: whenever possible try to use TypeReference since it's extend
the
+ /// reach/usability of the code.
+ /// </summary>
+ public static class TypeRocks {
+
+ /// <summary>
+ /// Check if the type contains an attribute of a specified type.
+ /// </summary>
+ /// <param name="self">The TypeDefinition on which the
extension method can be called.</param>
+ /// <param name="attributeName">Full name of the attribute
class</param>
+ /// <returns>True if the type contains an attribute of the same
name,
+ /// False otherwise.</returns>
+ public static bool HasAttribute (this TypeDefinition self,
string attributeName)
+ {
+ return self.CustomAttributes.Contains (attributeName);
+ }
+
+ /// <summary>
+ /// Check if the type implemented a specified interface. Note
that it is possible that
+ /// we might now be able to know all implementations since the
assembly where
+ /// the information resides could be unavailable.
+ /// </summary>
+ /// <param name="self">The TypeDefinition on which the
extension method can be called.</param>
+ /// <param name="interfaceName">Full name of the
interface</param>
+ /// <returns>True if the type implements the interface, False
otherwise.</returns>
+ public static bool Implements (this TypeDefinition self, string
interfaceName)
+ {
+ if (interfaceName == null)
+ throw new ArgumentNullException
("interfaceName");
+
+ // special case, check if we implement ourselves
+ if (self.IsInterface && (self.FullName ==
interfaceName))
+ return true;
+
+ // does the type implements it itself
+ foreach (TypeReference iface in self.Interfaces) {
+ if (iface.FullName == interfaceName)
+ return true;
+ }
+
+ // if not, then maybe it's parent does
+ // FIXME: right now we "ignore" case were a
TypeReference is given
+ TypeDefinition parent = (self.BaseType as
TypeDefinition);
+ if (parent != null)
+ return parent.Implements (interfaceName);
+
+ return false;
+ }
+
+ /// <summary>
+ /// Check if the type is a enumeration flags.
+ /// </summary>
+ /// <param name="self">The TypeDefinition on which the
extension method can be called.</param>
+ /// <returns>True if the type as the [Flags] attribute, false
otherwise.</returns>
+ public static bool IsFlags (this TypeDefinition self)
+ {
+ if (!self.IsEnum)
+ return false;
+
+ return self.HasAttribute ("System.FlagsAttribute");
+ }
+ }
+}
Modified: trunk/cecil/gendarme/framework/Location.cs
===================================================================
--- trunk/cecil/gendarme/framework/Location.cs 2007-12-26 18:09:49 UTC (rev
91902)
+++ trunk/cecil/gendarme/framework/Location.cs 2007-12-26 20:34:12 UTC (rev
91903)
@@ -4,10 +4,11 @@
*
* Authors:
* Aaron Tomb <[EMAIL PROTECTED]>
+ * Sebastien Pouliot <[EMAIL PROTECTED]>
+ *
+ * Copyright (c) 2005 Aaron Tomb
+ * Copyright (C) 2007 Novell, Inc (http://www.novell.com)
*
- * Copyright (c) 2005 Aaron Tomb and the contributors listed
- * in the ChangeLog.
- *
* This is free software, distributed under the MIT/X11 license.
* See the included LICENSE.MIT file for details.
**********************************************************************/
@@ -15,6 +16,8 @@
using System;
using System.Text;
+using Mono.Cecil;
+
namespace Gendarme.Framework {
public class Location {
@@ -36,6 +39,26 @@
this.offset = offset;
}
+ public Location (TypeDefinition type)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+
+ this.type = type.FullName;
+ this.method = String.Empty;
+ this.offset = -1;
+ }
+
+ public Location (MethodDefinition method)
+ {
+ if (method == null)
+ throw new ArgumentNullException ("method");
+
+ this.type = method.DeclaringType.FullName;
+ this.method = method.Name;
+ this.offset = -1;
+ }
+
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
Modified: trunk/cecil/gendarme/framework/Makefile.am
===================================================================
--- trunk/cecil/gendarme/framework/Makefile.am 2007-12-26 18:09:49 UTC (rev
91902)
+++ trunk/cecil/gendarme/framework/Makefile.am 2007-12-26 20:34:12 UTC (rev
91903)
@@ -15,7 +15,10 @@
RuleInformation.cs RuleInformationManager.cs \
Rules.cs Runner.cs Violation.cs Violations.cs \
Message.cs Location.cs MinimalRunner.cs \
- MessageCollection.cs MessageType.cs
+ MessageCollection.cs MessageType.cs \
+ Gendarme.Framework.Rocks/CustomAttributeRocks.cs \
+ Gendarme.Framework.Rocks/MethodRocks.cs \
+ Gendarme.Framework.Rocks/TypeRocks.cs
framework_build_sources = $(addprefix $(srcdir)/, $(framework_sources))
framework_build_sources += $(framework_generated_sources)
@@ -24,8 +27,24 @@
mkdir ../bin
../bin/Gendarme.Framework.dll: ../bin/ $(framework_build_sources)
- $(MCS) -debug -target:library -pkg:mono-cecil -r:System.Xml.dll -out:$@
$(framework_build_sources)
+ $(MCS) -debug -target:library -langversion:linq -pkg:mono-cecil
-r:System.Xml.dll -out:$@ $(framework_build_sources)
+
+framework_test_sources = Gendarme.Framework.Rocks/CustomAttributeRocksTest.cs \
+ Gendarme.Framework.Rocks/MethodRocksTest.cs \
+ Gendarme.Framework.Rocks/TypeRocksTest.cs
+framework_test_build_sources = $(addprefix $(srcdir)/Test/,
$(framework_test_sources))
+
+Test.Framework.dll: $(framework_test_build_sources) $(framework_rules_SCRIPTS)
../bin/Gendarme.Framework.dll
+ $(MCS) -target:library -langversion:linq -pkg:mono-cecil
-pkg:mono-nunit -r:../bin/Gendarme.Framework.dll \
+ -out:$@ $(framework_test_build_sources)
+
+test: Test.Framework.dll
+
+run-test: test
+ MONO_PATH=../bin/:$(CECIL_PATH):$(MONO_PATH) nunit-console2
Test.Framework.dll
+
+
self-test: $(framework_SCRIPTS)
mono --debug ../bin/gendarme.exe $(framework_SCRIPTS)
Added: trunk/cecil/gendarme/framework/Test/ChangeLog
===================================================================
--- trunk/cecil/gendarme/framework/Test/ChangeLog 2007-12-26 18:09:49 UTC
(rev 91902)
+++ trunk/cecil/gendarme/framework/Test/ChangeLog 2007-12-26 20:34:12 UTC
(rev 91903)
@@ -0,0 +1,3 @@
+2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * Test.Framework.mdp: MonoDevelop project file for unit tests
Added: trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/ChangeLog
===================================================================
--- trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/ChangeLog
2007-12-26 18:09:49 UTC (rev 91902)
+++ trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/ChangeLog
2007-12-26 20:34:12 UTC (rev 91903)
@@ -0,0 +1,5 @@
+2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * CustomAttributeRocksTest.cs: New. Unit tests for CustomAttributeRocks
+ * MethodRocksTest.cs: New. Unit tests for MethodRocks
+ * TypeRocksTest.cs: New. Unit tests for TypeRocks
Added:
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/CustomAttributeRocksTest.cs
===================================================================
---
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/CustomAttributeRocksTest.cs
2007-12-26 18:09:49 UTC (rev 91902)
+++
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/CustomAttributeRocksTest.cs
2007-12-26 20:34:12 UTC (rev 91903)
@@ -0,0 +1,67 @@
+//
+// Unit tests for CustomAttributeRocks
+//
+// 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 Gendarme.Framework;
+using Gendarme.Framework.Rocks;
+
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Framework.Rocks {
+
+ [TestFixture]
+ public class CustomAttributeRocksTest {
+
+ private AssemblyDefinition assembly;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Contains_Null ()
+ {
+ CustomAttributeCollection cac = new
CustomAttributeCollection (null);
+ cac.Contains ((string) null);
+ }
+
+ [Test]
+ public void Contains ()
+ {
+ TypeDefinition type = assembly.MainModule.Types
["Test.Framework.Rocks.CustomAttributeRocksTest"];
+ CustomAttributeCollection cac = type.CustomAttributes;
+ Assert.IsTrue (cac.Contains
("NUnit.Framework.TestFixtureAttribute"),
"NUnit.Framework.TestFixtureAttribute");
+ Assert.IsFalse (cac.Contains
("NUnit.Framework.TestFixture"), "NUnit.Framework.TestFixture");
+ }
+ }
+}
Added:
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/MethodRocksTest.cs
===================================================================
---
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/MethodRocksTest.cs
2007-12-26 18:09:49 UTC (rev 91902)
+++
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/MethodRocksTest.cs
2007-12-26 20:34:12 UTC (rev 91903)
@@ -0,0 +1,154 @@
+//
+// Unit tests for MethodRocks
+//
+// 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 System.Runtime.CompilerServices;
+
+using Gendarme.Framework;
+using Gendarme.Framework.Rocks;
+
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Framework.Rocks {
+
+ [TestFixture]
+ public class MethodRocksTest {
+
+ class MainClassVoidVoid {
+ static void Main ()
+ {
+ }
+ }
+
+ class MainClassIntVoid {
+ static int Main ()
+ {
+ return 42;
+ }
+ }
+
+ class MainClassVoidStrings {
+ static void Main (string[] args)
+ {
+ }
+ }
+
+ class MainClassIntStrings {
+ static int Main (string [] args)
+ {
+ return 42;
+ }
+ }
+
+ public int Value {
+ get { return 42; }
+ set { throw new NotSupportedException (); }
+ }
+
+ private AssemblyDefinition assembly;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ }
+
+ private MethodDefinition GetMethod (string typeName, string
methodName)
+ {
+ TypeDefinition type = assembly.MainModule.Types
[typeName];
+ foreach (MethodDefinition method in type.Methods) {
+ if (method.Name == methodName)
+ return method;
+ }
+ Assert.Fail ("Method {0} was not found.", methodName);
+ return null;
+ }
+
+ private MethodDefinition GetMethod (string name)
+ {
+ return GetMethod
("Test.Framework.Rocks.MethodRocksTest", name);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void HasAttribute_Null ()
+ {
+ CustomAttributeCollection cac = new
CustomAttributeCollection (null);
+ cac.Contains ((string) null);
+ }
+
+ [Test]
+ public void HasAttribute ()
+ {
+ CustomAttributeCollection cac = GetMethod
("FixtureSetUp").CustomAttributes;
+ Assert.IsTrue (cac.Contains
("NUnit.Framework.TestFixtureSetUpAttribute"),
"NUnit.Framework.TestFixtureSetUpAttribute");
+ Assert.IsFalse (cac.Contains
("NUnit.Framework.TestFixtureSetUp"), "NUnit.Framework.TestFixtureSetUp");
+ }
+
+ [Test]
+ [CompilerGenerated]
+ public void IsCompilerGenerated ()
+ {
+ Assert.IsTrue (GetMethod
("IsCompilerGenerated").IsCompilerGenerated (), "IsCompilerGenerated");
+ Assert.IsFalse (GetMethod
("FixtureSetUp").IsCompilerGenerated (), "FixtureSetUp");
+ }
+
+ [Test]
+ public void IsEntryPoint ()
+ {
+ Assert.IsFalse (GetMethod ("FixtureSetUp").IsEntryPoint
(), "FixtureSetUp");
+ }
+
+ [Test]
+ public void IsGetter ()
+ {
+ Assert.IsTrue (GetMethod ("get_Value").IsGetter (),
"get_Value");
+ Assert.IsFalse (GetMethod ("set_Value").IsGetter (),
"set_Value");
+ Assert.IsFalse (GetMethod ("FixtureSetUp").IsGetter (),
"FixtureSetUp");
+ }
+
+ [Test]
+ public void IsMain ()
+ {
+ Assert.IsTrue (GetMethod
("Test.Framework.Rocks.MethodRocksTest/MainClassVoidVoid", "Main").IsMain (),
"MainClassVoidVoid");
+ Assert.IsTrue (GetMethod
("Test.Framework.Rocks.MethodRocksTest/MainClassIntVoid", "Main").IsMain (),
"MainClassIntVoid");
+ Assert.IsTrue (GetMethod
("Test.Framework.Rocks.MethodRocksTest/MainClassVoidStrings", "Main").IsMain
(), "MainClassVoidStrings");
+ Assert.IsTrue (GetMethod
("Test.Framework.Rocks.MethodRocksTest/MainClassIntStrings", "Main").IsMain (),
"MainClassIntStrings");
+ Assert.IsFalse (GetMethod ("FixtureSetUp").IsMain (),
"FixtureSetUp");
+ }
+
+ [Test]
+ public void IsSetter ()
+ {
+ Assert.IsFalse (GetMethod ("get_Value").IsSetter (),
"get_Value");
+ Assert.IsTrue (GetMethod ("set_Value").IsSetter (),
"set_Value");
+ Assert.IsFalse (GetMethod ("FixtureSetUp").IsSetter (),
"FixtureSetUp");
+ }
+ }
+}
Added:
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/TypeRocksTest.cs
===================================================================
---
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/TypeRocksTest.cs
2007-12-26 18:09:49 UTC (rev 91902)
+++
trunk/cecil/gendarme/framework/Test/Gendarme.Framework.Rocks/TypeRocksTest.cs
2007-12-26 20:34:12 UTC (rev 91903)
@@ -0,0 +1,117 @@
+//
+// Unit tests for TypeRocks
+//
+// 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 Gendarme.Framework;
+using Gendarme.Framework.Rocks;
+
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Framework.Rocks {
+
+ [TestFixture]
+ public class TypeRocksTest {
+
+ public enum Enum {
+ Value
+ }
+
+ [Flags]
+ public enum Flags {
+ Mask
+ }
+
+ interface IDeepCloneable : ICloneable {
+ }
+
+ class Deep : IDeepCloneable {
+ public object Clone ()
+ {
+ throw new NotImplementedException ();
+ }
+ }
+
+ private AssemblyDefinition assembly;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ }
+
+ private TypeDefinition GetType (string name)
+ {
+ return assembly.MainModule.Types
["Test.Framework.Rocks.TypeRocksTest" + name];
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void HasAttribute_Null ()
+ {
+ GetType (String.Empty).HasAttribute (null);
+ }
+
+ [Test]
+ public void HasAttribute ()
+ {
+ Assert.IsTrue (GetType (String.Empty).HasAttribute
("NUnit.Framework.TestFixtureAttribute"), "TypeRocksTest");
+ Assert.IsFalse (GetType ("/Enum").HasAttribute
("System.FlagsAttribute"), "Enum/System.FlagsAttribute");
+ Assert.IsTrue (GetType ("/Flags").HasAttribute
("System.FlagsAttribute"), "Flags/System.FlagsAttribute");
+ // fullname is required
+ Assert.IsFalse (GetType ("/Flags").HasAttribute
("System.Flags"), "Flags/System.Flags");
+ Assert.IsFalse (GetType ("/Flags").HasAttribute
("FlagsAttribute"), "Flags/FlagsAttribute");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Implements_Null ()
+ {
+ GetType (String.Empty).Implements (null);
+ }
+
+ [Test]
+ public void Implements ()
+ {
+ Assert.IsFalse (GetType (String.Empty).Implements
("System.ICloneable"), "ICloneable");
+ Assert.IsTrue (GetType ("/IDeepCloneable").Implements
("Test.Framework.Rocks.TypeRocksTest/IDeepCloneable"), "itself");
+ Assert.IsTrue (GetType ("/IDeepCloneable").Implements
("System.ICloneable"), "interface inheritance");
+ Assert.IsTrue (GetType ("/Deep").Implements
("Test.Framework.Rocks.TypeRocksTest/IDeepCloneable"), "IDeepCloneable");
+ Assert.IsTrue (GetType ("/Deep").Implements
("System.ICloneable"), "second-level ICloneable");
+ }
+
+ [Test]
+ public void IsFlags ()
+ {
+ Assert.IsFalse (GetType (String.Empty).IsFlags (),
"Type.IsFlags");
+ Assert.IsFalse (GetType ("/Enum").IsFlags (),
"Enum.IsFlags");
+ Assert.IsTrue (GetType ("/Flags").IsFlags (),
"Flags.IsFlags");
+ }
+ }
+}
Added: trunk/cecil/gendarme/framework/Test/Test.Framework.mdp
===================================================================
--- trunk/cecil/gendarme/framework/Test/Test.Framework.mdp 2007-12-26
18:09:49 UTC (rev 91902)
+++ trunk/cecil/gendarme/framework/Test/Test.Framework.mdp 2007-12-26
20:34:12 UTC (rev 91903)
@@ -0,0 +1,30 @@
+<Project name="Test.Framework" fileversion="2.0" language="C#"
clr-version="Net_1_1" ctype="DotNetProject">
+ <Configurations active="Debug">
+ <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+ <Output directory="bin/Debug" assembly="Test.Framework" />
+ <Build debugmode="True" target="Library" />
+ <Execution runwithwarnings="True" consolepause="True" runtime="MsNet"
clr-version="Net_1_1" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True"
generatexmldocumentation="False" additionalargs="-langversion:linq"
ctype="CSharpCompilerParameters" />
+ </Configuration>
+ <Configuration name="Release" ctype="DotNetProjectConfiguration">
+ <Output directory="bin/Release" assembly="Test.Framework" />
+ <Build debugmode="False" target="Library" />
+ <Execution runwithwarnings="True" consolepause="True" runtime="MsNet"
clr-version="Net_1_1" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True"
generatexmldocumentation="False" additionalargs="-langversion:linq"
ctype="CSharpCompilerParameters" />
+ </Configuration>
+ </Configurations>
+ <Contents>
+ <File name="." subtype="Directory" buildaction="Compile" />
+ <File name="Gendarme.Framework.Rocks" subtype="Directory"
buildaction="Compile" />
+ <File name="Gendarme.Framework.Rocks/CustomAttributeRocksTest.cs"
subtype="Code" buildaction="Compile" />
+ <File name="Gendarme.Framework.Rocks/MethodRocksTest.cs" subtype="Code"
buildaction="Compile" />
+ <File name="Gendarme.Framework.Rocks/TypeRocksTest.cs" subtype="Code"
buildaction="Compile" />
+ </Contents>
+ <References>
+ <ProjectReference type="Gac" localcopy="True" refto="System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Gac" localcopy="True" refto="nunit.core,
Version=2.2.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
+ <ProjectReference type="Gac" localcopy="True" refto="nunit.framework,
Version=2.2.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
+ <ProjectReference type="Project" localcopy="True" refto="framework" />
+ <ProjectReference type="Assembly" localcopy="True"
refto="../../../lib/Mono.Cecil.dll" />
+ </References>
+</Project>
\ No newline at end of file
Modified: trunk/cecil/gendarme/framework/framework.mdp
===================================================================
--- trunk/cecil/gendarme/framework/framework.mdp 2007-12-26 18:09:49 UTC
(rev 91902)
+++ trunk/cecil/gendarme/framework/framework.mdp 2007-12-26 20:34:12 UTC
(rev 91903)
@@ -4,35 +4,40 @@
<Output directory="../bin" assembly="Gendarme.Framework" />
<Build debugmode="True" target="Library" />
<Execution runwithwarnings="True" consolepause="False" runtime="MsNet"
clr-version="Net_2_0" />
- <CodeGeneration compiler="Csc" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True" mainclass=""
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+ <CodeGeneration compiler="Csc" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True" mainclass=""
generatexmldocumentation="False" additionalargs="-langversion:linq"
langversion="ISO_2" ctype="CSharpCompilerParameters" />
</Configuration>
<Configuration name="Release" ctype="DotNetProjectConfiguration">
<Output directory="../bin/Release" assembly="Gendarme.Framework" />
<Build debugmode="False" target="Library" />
<Execution runwithwarnings="True" consolepause="False" runtime="MsNet"
clr-version="Net_2_0" />
- <CodeGeneration compiler="Csc" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True" mainclass=""
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+ <CodeGeneration compiler="Csc" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True" mainclass=""
generatexmldocumentation="False" additionalargs="-langversion:linq"
langversion="ISO_2" ctype="CSharpCompilerParameters" />
</Configuration>
</Configurations>
<Contents>
- <File name="./AssemblyManager.cs" subtype="Code" buildaction="Compile" />
- <File name="./IRule.cs" subtype="Code" buildaction="Compile" />
- <File name="./Location.cs" subtype="Code" buildaction="Compile" />
- <File name="./Message.cs" subtype="Code" buildaction="Compile" />
- <File name="./MessageCollection.cs" subtype="Code" buildaction="Compile" />
- <File name="./MinimalRunner.cs" subtype="Code" buildaction="Compile" />
- <File name="./RuleCollection.cs" subtype="Code" buildaction="Compile" />
- <File name="./RuleInformation.cs" subtype="Code" buildaction="Compile" />
- <File name="./RuleInformationManager.cs" subtype="Code"
buildaction="Compile" />
- <File name="./Rules.cs" subtype="Code" buildaction="Compile" />
- <File name="./Runner.cs" subtype="Code" buildaction="Compile" />
- <File name="./Violation.cs" subtype="Code" buildaction="Compile" />
- <File name="./Violations.cs" subtype="Code" buildaction="Compile" />
- <File name="./MessageType.cs" subtype="Code" buildaction="Compile" />
+ <File name="AssemblyManager.cs" subtype="Code" buildaction="Compile" />
+ <File name="IRule.cs" subtype="Code" buildaction="Compile" />
+ <File name="Location.cs" subtype="Code" buildaction="Compile" />
+ <File name="Message.cs" subtype="Code" buildaction="Compile" />
+ <File name="MessageCollection.cs" subtype="Code" buildaction="Compile" />
+ <File name="MinimalRunner.cs" subtype="Code" buildaction="Compile" />
+ <File name="RuleCollection.cs" subtype="Code" buildaction="Compile" />
+ <File name="RuleInformation.cs" subtype="Code" buildaction="Compile" />
+ <File name="RuleInformationManager.cs" subtype="Code"
buildaction="Compile" />
+ <File name="Rules.cs" subtype="Code" buildaction="Compile" />
+ <File name="Runner.cs" subtype="Code" buildaction="Compile" />
+ <File name="Violation.cs" subtype="Code" buildaction="Compile" />
+ <File name="Violations.cs" subtype="Code" buildaction="Compile" />
+ <File name="MessageType.cs" subtype="Code" buildaction="Compile" />
+ <File name="Gendarme.Framework.Rocks" subtype="Directory"
buildaction="Compile" />
+ <File name="Gendarme.Framework.Rocks/CustomAttributeRocks.cs"
subtype="Code" buildaction="Compile" />
+ <File name="Gendarme.Framework.Rocks/MethodRocks.cs" subtype="Code"
buildaction="Compile" />
+ <File name="Gendarme.Framework.Rocks/TypeRocks.cs" subtype="Code"
buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Assembly" localcopy="True"
refto="../../lib/Mono.Cecil.dll" />
<ProjectReference type="Gac" localcopy="True" refto="System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<ProjectReference type="Gac" localcopy="True" refto="System.Xml,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Gac" localcopy="True" refto="System.Core,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</References>
<DeployTargets />
</Project>
\ No newline at end of file
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches