Author: spouliot
Date: 2007-10-07 19:10:46 -0400 (Sun, 07 Oct 2007)
New Revision: 87064

Added:
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/AvoidConstructorsInStaticTypesRule.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/CallingEqualsWithNullArgRule.cs
   trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/FloatComparisonRule.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/AvoidConstructorsInStaticTypesTest.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/CallingEqualsWithNullArgTest.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/FloatComparisonRuleTest.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/UseValueInPropertySetterTest.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/UseValueInPropertySetterRule.cs
Modified:
   trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/ChangeLog
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.mdp
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.xml.in
   trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Makefile.am
   trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/ChangeLog
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/Test.Rules.Correctness.mdp
Log:
Integrate some GSoC 2007 work and update project files

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/AvoidConstructorsInStaticTypesRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/AvoidConstructorsInStaticTypesRule.cs
 2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/AvoidConstructorsInStaticTypesRule.cs
 2007-10-07 23:10:46 UTC (rev 87064)
@@ -0,0 +1,76 @@
+//
+// Gendarme.Rules.Correctness.AvoidConstructorsInStaticTypesRule
+//
+// Authors:
+//     Lukasz Knop <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Lukasz Knop
+//
+// 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.Text;
+
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+using Gendarme.Framework;
+
+namespace Gendarme.Rules.Correctness
+{
+       public class AvoidConstructorsInStaticTypesRule : ITypeRule
+       {
+               private const string MessageString = "Types with no instance 
fields or methods should not have public instance constructors";
+               
+               public MessageCollection CheckType(TypeDefinition type, Runner 
runner)
+               {
+                       MessageCollection messageCollection = new 
MessageCollection();
+
+                       foreach (MethodDefinition method in type.Methods)
+                       {
+                               if (!method.IsStatic)
+                               {
+                                       return null;
+                               }
+                       }
+
+                       foreach (FieldDefinition field in type.Fields)
+                       {
+                               if (!field.IsStatic)
+                               {
+                                       return null;
+                               }
+                       }
+                       
+                       foreach (MethodDefinition ctor in type.Constructors)
+                       {
+                               if (!ctor.IsStatic && (ctor.Attributes & 
MethodAttributes.Public) == MethodAttributes.Public)
+                               {
+                                       Location location = new 
Location(type.Name, ctor.Name, 0);
+                                       Message message = new 
Message(MessageString, location, MessageType.Error);
+                                       messageCollection.Add(message);
+                               }
+                       }
+
+                       return messageCollection.Count > 0 ? messageCollection 
: null;
+                       
+               }
+       }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/CallingEqualsWithNullArgRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/CallingEqualsWithNullArgRule.cs
       2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/CallingEqualsWithNullArgRule.cs
       2007-10-07 23:10:46 UTC (rev 87064)
@@ -0,0 +1,57 @@
+// 
+// Gendarme.Rules.Correctness.CallingEqualsWithNullArgRule
+//
+// Authors:
+//     Nidhi Rawal <[EMAIL PROTECTED]>
+//
+// Copyright (c) <2007> Nidhi Rawal
+//
+// 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.Collections;
+
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+using Gendarme.Framework;
+
+namespace Gendarme.Rules.Correctness {
+       public class CallingEqualsWithNullArgRule: IMethodRule
+       {
+               public MessageCollection CheckMethod (MethodDefinition method, 
Runner runner)
+               {                       
+                       MessageCollection messageCollection = new 
MessageCollection ();
+                       
+                       foreach (Instruction ins in method.Body.Instructions)
+                               if (ins.OpCode == OpCodes.Call || ins.OpCode == 
OpCodes.Callvirt) {
+                                       MethodReference calledMethod = 
(MethodReference) ins.Operand;
+                                       if (calledMethod.Name == "Equals" && 
calledMethod.ReturnType.ReturnType.FullName == "System.Boolean")
+                                               if (ins.Previous.OpCode == 
OpCodes.Ldnull) {
+                                                       Location location = new 
Location (method.DeclaringType.FullName, method.Name, 0);
+                                                       Message message = new 
Message ("You should not call Equals (null), i.e., argument should not be 
null", location, MessageType.Error);
+                                                       messageCollection.Add 
(message);
+                                               }
+                               }
+               
+                       if (messageCollection.Count == 0)
+                               return null;
+                       return messageCollection;
+               }
+       }
+}
\ No newline at end of file

Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/ChangeLog     
2007-10-07 23:04:34 UTC (rev 87063)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/ChangeLog     
2007-10-07 23:10:46 UTC (rev 87064)
@@ -1,3 +1,14 @@
+2007-10-07  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * AvoidConstructorsInStaticTypesRule.cs: Unit tests (Lukasz Knop, 
+       GSoC 2007)
+       * CallingEqualsWithNullArgRule.cs: New rule (Nidhi Rawal, GSoC 2007)
+       * FloatComparisonRule.cs: Unit tests (Lukasz Knop, GSoC 2007)
+       * UseValueInPropertySetterRule.cs: Unit tests (Lukasz Knop, GSoC 2007)
+       * Gendarme.Rules.Correctness.xml.in: Update rule description.
+       * Gendarme.Rules.Correctness.mdp: Update project file.
+       * Makefile.am: Update build file.
+
 2007-03-12  Alp Toker  <[EMAIL PROTECTED]>
 
        * Gendarme.Rules.Correctness.xml.in: Typo fix.

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/FloatComparisonRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/FloatComparisonRule.cs    
    2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/FloatComparisonRule.cs    
    2007-10-07 23:10:46 UTC (rev 87064)
@@ -0,0 +1,175 @@
+//
+// Gendarme.Rules.Correctness.FloatComparisonRule
+//
+// Authors:
+//     Lukasz Knop <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Lukasz Knop
+//
+// 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.Text;
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+
+using Gendarme.Framework;
+
+namespace Gendarme.Rules.Correctness
+{
+       public class FloatComparisonRule : IMethodRule
+       {
+               private const string MessageString = "Floating point values 
should not be compared for equality";
+
+               public MessageCollection CheckMethod(MethodDefinition method, 
Runner runner)
+               {
+                       MessageCollection messageCollection = new 
MessageCollection();
+                       
+                       foreach (Instruction instruction in 
method.Body.Instructions)
+                       {
+                               if (instruction.OpCode == OpCodes.Ceq)
+                               {
+                                       Instruction precedingInstruction = 
SkipArithmeticOperations(instruction);
+                                       
+                                       switch 
(precedingInstruction.OpCode.Code)
+                                       {
+                                               
+                                               case Code.Conv_R4:
+                                               case Code.Conv_R8:
+                                                       AddProblem(method, 
instruction, messageCollection);
+                                                       break;
+                                               case Code.Ldc_R4:
+                                               case Code.Ldc_R8:
+                                                       
CheckFloatConstants(precedingInstruction.Operand, method, instruction, 
messageCollection);
+                                                       break;
+                                               case Code.Ldloc_0:
+                                                       
CheckTypeReference(method.Body.Variables[0].VariableType, method, instruction, 
messageCollection);
+                                                       break;
+                                               case Code.Ldloc_1:
+                                                       
CheckTypeReference(method.Body.Variables[1].VariableType, method, instruction, 
messageCollection);
+                                                       break;
+                                               case Code.Ldloc_2:
+                                                       
CheckTypeReference(method.Body.Variables[2].VariableType, method, instruction, 
messageCollection);
+                                                       break;
+                                               case Code.Ldloc_3:
+                                                       
CheckTypeReference(method.Body.Variables[3].VariableType, method, instruction, 
messageCollection);
+                                                       break;
+                                               case Code.Ldloc_S:
+                                                       VariableReference local 
= precedingInstruction.Operand as VariableReference;
+                                                       
CheckTypeReference(local.VariableType, method, instruction, messageCollection);
+                                                       break;
+                                               case Code.Ldarg_1:
+                                                       
CheckTypeReference(method.Parameters[0].ParameterType, method, instruction, 
messageCollection);
+                                                       break;
+                                               case Code.Ldarg_2:
+                                                       
CheckTypeReference(method.Parameters[1].ParameterType, method, instruction, 
messageCollection);
+                                                       break;
+                                               case Code.Ldarg_3:
+                                                       
CheckTypeReference(method.Parameters[2].ParameterType, method, instruction, 
messageCollection);
+                                                       break;
+                                               case Code.Ldarg:
+                                                       ParameterReference 
parameter = precedingInstruction.Operand as ParameterReference;
+                                                       
CheckTypeReference(parameter.ParameterType, method, instruction, 
messageCollection);
+                                                       break;
+                                               case Code.Call:
+                                               case Code.Calli:
+                                               case Code.Callvirt:
+                                                       MethodReference call = 
precedingInstruction.Operand as MethodReference;
+                                                       
CheckTypeReference(call.ReturnType.ReturnType, method, instruction, 
messageCollection);
+                                                       break;
+                                               case Code.Ldfld:
+                                               case Code.Ldsfld:
+                                                       FieldReference field = 
precedingInstruction.Operand as FieldReference;
+                                                       
CheckTypeReference(field.FieldType, method, instruction, messageCollection);
+                                                       break;
+                                       }
+                               }
+                               else if (instruction.OpCode.Code == Code.Call)
+                               {
+                                       MemberReference member = 
instruction.Operand as MemberReference;
+                                       
+                                       if 
(member.DeclaringType.FullName.Equals("System.Single") &&
+                                               member.Name.Equals("Equals"))
+                                       {
+                                               AddProblem(method, instruction, 
messageCollection);
+                                       }
+                               }
+                       }
+
+                       return messageCollection.Count == 0 ? 
runner.RuleSuccess : messageCollection;
+               }
+
+               private Instruction SkipArithmeticOperations(Instruction 
instruction)
+               {
+                       Instruction prevInstr = instruction.Previous;
+                       OpCode[] arithOpCodes = new OpCode[] 
+                               {       
+                                       OpCodes.Mul, 
+                                       OpCodes.Add, 
+                                       OpCodes.Sub, 
+                                       OpCodes.Div 
+                               };
+
+                       while (Array.Exists(arithOpCodes, delegate(OpCode code) 
{ return code == prevInstr.OpCode; }))
+                       {
+                               prevInstr = prevInstr.Previous;
+                       }
+                       return prevInstr;
+               }
+
+               private void AddProblem(MethodDefinition method, Instruction 
instruction, MessageCollection messageCollection)
+               {
+                       Location location = new 
Location(method.DeclaringType.Name, method.Name, instruction.Offset);
+                       Message message = new Message(MessageString, location, 
MessageType.Error);
+                       messageCollection.Add(message);
+               }
+
+               private void CheckTypeReference(TypeReference type, 
MethodDefinition method, Instruction instruction, MessageCollection 
messageCollection)
+               {
+                       if (type.FullName.Equals("System.Single") || 
type.FullName.Equals("System.Double"))
+                       {
+                               AddProblem(method, instruction, 
messageCollection);
+                       }
+
+               }
+
+               private void CheckFloatConstants(object operand, 
MethodDefinition method, Instruction instruction, MessageCollection 
messageCollection)
+               {
+                       object[] specialValues = new object[] 
+                       {
+                               float.PositiveInfinity,
+                               float.NegativeInfinity,
+                               float.MinValue,
+                               float.MaxValue,
+                               double.PositiveInfinity,
+                               double.NegativeInfinity,
+                               double.MinValue,
+                               double.MaxValue
+                       };
+
+                       if (!Array.Exists(specialValues, delegate(object value) 
{ return value.Equals(operand); }))
+                       {
+                               AddProblem(method, instruction, 
messageCollection);
+                       }
+               }
+
+       }
+}

Modified: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.mdp
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.mdp
        2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.mdp
        2007-10-07 23:10:46 UTC (rev 87064)
@@ -1,19 +1,18 @@
-<Project name="Gendarme.Rules.Correctness" fileversion="2.0" language="C#" 
clr-version="Net_1_1" ctype="DotNetProject">
+<Project name="Gendarme.Rules.Correctness" fileversion="2.0" language="C#" 
clr-version="Net_2_0" ctype="DotNetProject">
   <Configurations active="Debug">
     <Configuration name="Debug" ctype="DotNetProjectConfiguration">
       <Output directory="./bin/Debug" assembly="Gendarme.Rules.Correctness" />
       <Build debugmode="True" target="Library" />
-      <Execution runwithwarnings="True" consolepause="False" runtime="MsNet" 
clr-version="Net_1_1" />
+      <Execution runwithwarnings="True" consolepause="False" runtime="MsNet" 
clr-version="Net_2_0" />
       <CodeGeneration compiler="Csc" warninglevel="4" optimize="True" 
unsafecodeallowed="False" generateoverflowchecks="True" 
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
     </Configuration>
     <Configuration name="Release" ctype="DotNetProjectConfiguration">
       <Output directory="./bin/Release" assembly="Gendarme.Rules.Correctness" 
/>
       <Build debugmode="False" target="Library" />
-      <Execution runwithwarnings="True" consolepause="False" runtime="MsNet" 
clr-version="Net_1_1" />
+      <Execution runwithwarnings="True" consolepause="False" runtime="MsNet" 
clr-version="Net_2_0" />
       <CodeGeneration compiler="Csc" warninglevel="4" optimize="True" 
unsafecodeallowed="False" generateoverflowchecks="True" 
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
     </Configuration>
   </Configurations>
-  <DeployTargets />
   <Contents>
     <File name="./BadRecursiveInvocationRule.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./MethodCanBeMadeStaticRule.cs" subtype="Code" 
buildaction="Compile" />
@@ -36,10 +35,17 @@
     <File name="./graph/IGraph.cs" subtype="Code" buildaction="Compile" />
     <File name="./graph/INode.cs" subtype="Code" buildaction="Compile" />
     <File name="./graph/Node.cs" subtype="Code" buildaction="Compile" />
+    <File name="./CallingEqualsWithNullArgRule.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="./Gendarme.Rules.Correctness.xml.in" subtype="Code" 
buildaction="Nothing" />
+    <File name="./AvoidConstructorsInStaticTypesRule.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="./FloatComparisonRule.cs" subtype="Code" buildaction="Compile" 
/>
+    <File name="./UseValueInPropertySetterRule.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="Assembly" localcopy="True" 
refto="../../../lib/Mono.Cecil.dll" />
     <ProjectReference type="Project" localcopy="True" refto="framework" />
+    <ProjectReference type="Gac" localcopy="True" refto="System, 
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   </References>
+  <Deployment.LinuxDeployData generatePcFile="False" />
+  <DeployTargets />
 </Project>
\ No newline at end of file

Modified: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.xml.in
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.xml.in
     2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.xml.in
     2007-10-07 23:10:46 UTC (rev 87064)
@@ -17,4 +17,10 @@
                <problem>Method or property '{0}' might dereference a null 
pointer, or cause other code to do so.</problem>
                <solution>Examine the detailed listing of problem locations, 
and ensure that the variables in question cannot be null.</solution>
        </rule>
+       <rule   Name="CallingEqualsWithNullArgRule"
+               Type="Gendarme.Rules.Correctness.CallingEqualsWithNullArgRule, 
Gendarme.Rules.Correctness, [EMAIL PROTECTED]@, Culture=neutral, 
PublicKeyToken=null"
+               Uri="" >
+               <problem>Method '{0}' calls Object.Equals (Object) with null 
argument.</problem>
+               <solution>Pass some other appropriate argument than null, as 
passing null parameter should always return false.</solution>
+       </rule>
 </rules>

Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Makefile.am   
2007-10-07 23:04:34 UTC (rev 87063)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Makefile.am   
2007-10-07 23:10:46 UTC (rev 87064)
@@ -9,19 +9,13 @@
 
 correctness_rules_sources_in = ../../AssemblyInfo.cs.in
 correctness_rules_generated_sources = $(correctness_rules_sources_in:.in=)
-correctness_rules_sources = BadRecursiveInvocationRule.cs OpCodeConstants.cs \
-                           MethodCanBeMadeStaticRule.cs \
-                           NonNullAttribute.cs NonNullAttributeCollector.cs \
-                           NullDerefAnalysis.cs NullDerefRule.cs \
-                           NullDerefFrame.cs Nullity.cs \
-                           graph/INode.cs graph/Node.cs \
-                           graph/IEdge.cs graph/Edge.cs graph/IGraph.cs \
-                           graph/Graph.cs dataflow/BasicBlock.cs \
-                           dataflow/CFG.cs dataflow/CFGEdge.cs \
-                           dataflow/Dataflow.cs graph/DFS.cs \
-                           dataflow/IDataflowAnalysis.cs
+correctness_rules_sources = BadRecursiveInvocationRule.cs OpCodeConstants.cs 
MethodCanBeMadeStaticRule.cs \
+       CallingEqualsWithNullArgRule.cs NonNullAttribute.cs 
NonNullAttributeCollector.cs NullDerefAnalysis.cs NullDerefRule.cs \
+       NullDerefFrame.cs Nullity.cs graph/INode.cs graph/Node.cs 
graph/IEdge.cs graph/Edge.cs graph/IGraph.cs \
+       graph/Graph.cs dataflow/BasicBlock.cs dataflow/CFG.cs 
dataflow/CFGEdge.cs dataflow/Dataflow.cs graph/DFS.cs \
+       dataflow/IDataflowAnalysis.cs FloatComparisonRule.cs 
CallingEqualsWithNullArgRule.cs UseValueInPropertySetterRule.cs \
+       AvoidConstructorsInStaticTypesRule.cs
 
-
 correctness_rules_build_sources = $(addprefix $(srcdir)/, 
$(correctness_rules_sources))
 correctness_rules_build_sources += $(correctness_rules_generated_sources)
 
@@ -42,10 +36,9 @@
                rm -f $(DESTDIR)$(pkglibdir)/`basename $$ASM`; \
        done;
 
-correctness_test_sources = BadRecursiveInvocationTest.cs \
-                           MethodCanBeMadeStaticTest.cs
+correctness_test_sources = BadRecursiveInvocationTest.cs 
MethodCanBeMadeStaticTest.cs UseValueInPropertySetterTest.cs \
+       AvoidConstructorsInStaticTypesTest.cs CallingEqualsWithNullArgTest.cs 
FloatComparisonRuleTest.cs
 
-
 correctness_test_build_sources = $(addprefix $(srcdir)/Test/, 
$(correctness_test_sources))
 
 Test.Rules.Correctness.dll: $(correctness_rules_build_sources)
@@ -55,7 +48,7 @@
 test: Gendarme.Rules.Correctness.dll Test.Rules.Correctness.dll
 
 run-test: Test.Rules.Correctness.dll
-       MONO_PATH=../../framework/:$(CECIL_PATH):$(MONO_PATH) nunit-console 
Test.Rules.Correctness.dll
+       MONO_PATH=../../framework/:$(CECIL_PATH):$(MONO_PATH) nunit-console2 
Test.Rules.Correctness.dll
 
 self-test: test
        gendarme Gendarme.Rules.Correctness.dll

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/AvoidConstructorsInStaticTypesTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/AvoidConstructorsInStaticTypesTest.cs
    2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/AvoidConstructorsInStaticTypesTest.cs
    2007-10-07 23:10:46 UTC (rev 87064)
@@ -0,0 +1,130 @@
+//
+// Unit test for AvoidConstructorsInStaticTypesRule
+//
+// Authors:
+//     Lukasz Knop <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Lukasz Knop
+//
+// 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.Text;
+using Gendarme.Framework;
+using Gendarme.Rules.Correctness;
+using Mono.Cecil;
+using NUnit.Framework;
+
+
+namespace Test.Rules.Correctness
+{
+
+
+       [TestFixture]
+       public class AvoidConstructorsInStaticTypesTest
+       {
+               public class CannotBeMadeStatic
+               {
+                       public void Method()
+                       {
+
+                       }
+               }
+
+               public class CanBeMadeStatic
+               {
+                       public static void Method()
+                       {
+                       }
+               }
+
+               public static class IsStatic
+               {
+                       public static void Method()
+                       {
+                       }
+               }
+
+               public class IsMadeStatic
+               {
+                       private IsMadeStatic()
+                       {
+                       }
+
+                       public static void Method()
+                       {
+                       }
+
+               }
+
+               private ITypeRule rule;
+               private AssemblyDefinition assembly;
+               private TypeDefinition type;
+               private MessageCollection messageCollection;
+
+               [TestFixtureSetUp]
+               public void FixtureSetUp()
+               {
+                       string unit = Assembly.GetExecutingAssembly().Location;
+                       assembly = AssemblyFactory.GetAssembly(unit);
+                       rule = new AvoidConstructorsInStaticTypesRule();
+                       messageCollection = null;
+               }
+
+
+               [Test]
+               public void TestClassHasNoPublicConstructors()
+               {
+                       type = 
assembly.MainModule.Types["Test.Rules.Correctness.AvoidConstructorsInStaticTypesTest/IsMadeStatic"];
+                       messageCollection = rule.CheckType(type, new 
MinimalRunner());
+                       Assert.IsNull(messageCollection);
+               }
+
+               [Test]
+               public void TestClassIsDeclaredStatic()
+               {
+                       type = 
assembly.MainModule.Types["Test.Rules.Correctness.AvoidConstructorsInStaticTypesTest/IsStatic"];
+                       messageCollection = rule.CheckType(type, new 
MinimalRunner());
+                       Assert.IsNull(messageCollection);
+               }
+
+
+               [Test]
+               public void TestClassCannotBeMadeStatic()
+               {
+                       type = 
assembly.MainModule.Types["Test.Rules.Correctness.AvoidConstructorsInStaticTypesTest/CannotBeMadeStatic"];
+                       messageCollection = rule.CheckType(type, new 
MinimalRunner());
+                       Assert.IsNull(messageCollection);
+               }
+
+               [Test]
+               public void TestClassCanBeMadeStatic()
+               {
+                       type = 
assembly.MainModule.Types["Test.Rules.Correctness.AvoidConstructorsInStaticTypesTest/CanBeMadeStatic"];
+                       messageCollection = rule.CheckType(type, new 
MinimalRunner());
+                       Assert.IsNotNull(messageCollection);
+               }
+
+
+
+       }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/CallingEqualsWithNullArgTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/CallingEqualsWithNullArgTest.cs
  2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/CallingEqualsWithNullArgTest.cs
  2007-10-07 23:10:46 UTC (rev 87064)
@@ -0,0 +1,236 @@
+// 
+// Unit tests for CallingEqualsWithNullArgRule
+//
+// Authors:
+//     Nidhi Rawal <[EMAIL PROTECTED]>
+//
+// Copyright (c) <2007> Nidhi Rawal
+//
+// 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.Rules.Correctness;
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Rules.Correctness
+{
+       [TestFixture]
+       public class CallingEqualsWithNullArgTest {
+               
+               public class CallToEqualsWithNullArg
+               {
+                       public static void Main (string [] args)
+                       {
+                               CallToEqualsWithNullArg c = new 
CallToEqualsWithNullArg ();
+                               c.Equals (null);
+                       }
+               }
+               
+               public class CallingEqualsWithNonNullArg 
+               {
+                       public static void Main (string [] args)
+                       {
+                               CallingEqualsWithNonNullArg c = new 
CallingEqualsWithNonNullArg ();
+                               CallingEqualsWithNonNullArg c1 = new 
CallingEqualsWithNonNullArg ();
+                               c.Equals (c1);
+                       }
+               }
+               
+               public class CallingEqualsOnEnum
+               {
+                       enum Days { Saturday, Sunday, Monday, Tuesday, 
Wednesday, Thursday, Friday };
+                       
+                       public bool Equals (Enum e)
+                       {
+                               if (e == null)
+                                       return false;
+                               else
+                                       return e.GetType () == typeof (Days);
+                       }
+                       
+                       public void PassingArgNullInEquals ()
+                       {
+                               Type e = typeof (Days);
+                               e.Equals (null);
+                       }
+                       
+                       public void NotPassingNullArgInEquals ()
+                       {
+                               Type e = typeof (Days);
+                               Type e1 = typeof (Days);
+                               e.Equals (e1);
+                       }
+               }
+               
+               public struct structure 
+               {
+                       public bool Equals (structure s)
+                       {
+                               return s.GetType () == typeof (structure);
+                       }
+               }
+               
+               public class CallingEqualsOnStruct
+               {                       
+                       public void PassingNullArgument ()
+                       {
+                               structure s = new structure ();
+                               s.Equals (null);
+                       }
+                       
+                       public void PassingNonNullArg ()
+                       {
+                               structure s = new structure ();
+                               structure s1 = new structure ();
+                               s.Equals (s1);
+                       }
+               }
+               
+               public class CallingEqualsOnArray
+               {
+                       int [] a = new int [] {1, 2, 3};
+                       
+                       public bool Equals (int [] b)
+                       {
+                               if (b == null)
+                                       return false;
+                               else
+                                       return a.Length == b.Length;
+                       }
+                       
+                       public void PassingNullArg ()
+                       {
+                               int [] b = new int [] {1, 2, 3};
+                               b.Equals (null);
+                       }
+                       
+                       public void PassingNonNullArg ()
+                       {
+                               int [] b = new int [] {1, 2, 3};
+                               b.Equals (a);
+                       }
+               }
+               
+               private IMethodRule methodRule;
+               private AssemblyDefinition assembly;
+               private TypeDefinition type;
+               MessageCollection messageCollection;
+
+               [TestFixtureSetUp]
+               public void FixtureSetUp ()
+               {
+                       string unit = Assembly.GetExecutingAssembly ().Location;
+                       assembly = AssemblyFactory.GetAssembly (unit);
+                       methodRule = new CallingEqualsWithNullArgRule ();
+                       messageCollection = null;
+               }
+               
+               private TypeDefinition GetTest (string name)
+               {
+                       string fullname = 
"Test.Rules.Correctness.CallingEqualsWithNullArgTest/" + name;
+                       return assembly.MainModule.Types[fullname];
+               }
+       
+               [Test]
+               public void callToEqualsWithNullArgTest ()
+               {
+                       type = GetTest ("CallToEqualsWithNullArg");
+                       foreach (MethodDefinition method in type.Methods)
+                               messageCollection = methodRule.CheckMethod 
(method, new MinimalRunner ());
+                       Assert.IsNotNull (messageCollection);
+                       Assert.AreEqual (1, messageCollection.Count);
+               }
+               
+               [Test]
+               public void callingEqualsWithNonNullArgTest ()
+               {
+                       type = GetTest ("CallingEqualsWithNonNullArg");
+                       foreach (MethodDefinition method in type.Methods)
+                               messageCollection = methodRule.CheckMethod 
(method, new MinimalRunner ());
+                       Assert.IsNull (messageCollection);
+               }
+               
+               [Test]
+               public void enumPassingArgNullInEqualsTest ()
+               {
+                       type = GetTest ("CallingEqualsOnEnum");
+                       foreach (MethodDefinition method in type.Methods)
+                               if (method.Name == "PassingArgNullInEquals")
+                                       messageCollection = 
methodRule.CheckMethod (method, new MinimalRunner ());
+                       Assert.IsNotNull (messageCollection);
+                       Assert.AreEqual (1, messageCollection.Count);
+               }
+               
+               [Test]
+               public void enumNotPassingArgNullInEqualsTest ()
+               {
+                       type = GetTest ("CallingEqualsOnEnum");
+                       foreach (MethodDefinition method in type.Methods)
+                               if (method.Name == "NotPassingNullArgInEquals")
+                                       messageCollection = 
methodRule.CheckMethod (method, new MinimalRunner ());
+                       Assert.IsNull (messageCollection);
+               }
+               
+               [Test]
+               public void passingNullArgumentThanStructTest ()
+               {
+                       type = GetTest ("CallingEqualsOnStruct");
+                       foreach (MethodDefinition method in type.Methods)
+                               if (method.Name == "PassingNullArgument")
+                                       messageCollection = 
methodRule.CheckMethod (method, new MinimalRunner ());
+                       Assert.IsNotNull (messageCollection);
+                       Assert.AreEqual (1, messageCollection.Count);
+               }
+                               
+               [Test]
+               public void passingNonNullStructArgTest ()
+               {
+                       type = GetTest ("CallingEqualsOnStruct");
+                       foreach (MethodDefinition method in type.Methods)
+                               if (method.Name == "PassingNonNullArg")
+                                       messageCollection = 
methodRule.CheckMethod (method, new MinimalRunner ());
+                       Assert.IsNull (messageCollection);
+               }
+               
+               [Test]
+               public void passingNullArgumentThanArrayTest ()
+               {
+                       type = GetTest ("CallingEqualsOnArray");
+                       foreach (MethodDefinition method in type.Methods)
+                               if (method.Name == "PassingNullArg")
+                                       messageCollection = 
methodRule.CheckMethod (method, new MinimalRunner ());
+                       Assert.IsNotNull (messageCollection);
+                       Assert.AreEqual (1, messageCollection.Count);
+               }
+               
+               [Test]
+               public void passingNonNullArrayArgumentTest ()
+               {
+                       type = GetTest ("CallingEqualsOnArray");
+                       foreach (MethodDefinition method in type.Methods)
+                               if (method.Name == "PassingNonNullArg")
+                                       messageCollection = 
methodRule.CheckMethod (method, new MinimalRunner ());
+                       Assert.IsNull (messageCollection);
+               }
+       }
+}
\ No newline at end of file

Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/ChangeLog        
2007-10-07 23:04:34 UTC (rev 87063)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/ChangeLog        
2007-10-07 23:10:46 UTC (rev 87064)
@@ -1,3 +1,12 @@
+2007-10-07  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * AvoidConstructorsInStaticTypesTest.cs: Unit tests (Lukasz Knop, 
+       GSoC 2007)
+       * CallingEqualsWithNullArgTest.cs: Unit tests (Nidhi Rawal, GSoC 2007)
+       * FloatComparisonRuleTest.cs: Unit tests (Lukasz Knop, GSoC 2007)
+       * UseValueInPropertySetterTest.cs: Unit tests (Lukasz Knop, GSoC 2007)
+       * Test.Rules.Correctness.mdp: Update project files.
+
 2007-02-27  Jb Evain  <[EMAIL PROTECTED]>
 
        * MethodCanBeMadeStaticTest.cs:

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/FloatComparisonRuleTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/FloatComparisonRuleTest.cs
       2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/FloatComparisonRuleTest.cs
       2007-10-07 23:10:46 UTC (rev 87064)
@@ -0,0 +1,247 @@
+//
+// Unit test for FloatComparisonRule
+//
+// Authors:
+//     Lukasz Knop <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Lukasz Knop
+//
+// 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.Text;
+
+using System.Reflection;
+
+using Gendarme.Framework;
+using Gendarme.Rules.Correctness;
+using Mono.Cecil;
+using NUnit.Framework;
+
+
+namespace Test.Rules.Correctness
+{
+       [TestFixture]
+       public class FloatComparisonRuleTest
+       {
+
+               public class Item
+               {
+                       public float floatField = 0f;
+                       public static float staticFloatField = 0f;
+
+                       public float FloatProperty
+                       {
+                               get { return floatField; }
+                       }
+
+                       public static float StaticFloatMethod()
+                       {
+                               return 0f;
+                       }
+
+                       public void FloatFields()
+                       {
+                               bool a = floatField == staticFloatField;
+                               bool b = staticFloatField == floatField;
+                               
+                       }
+
+                       public bool FloatMethodResult()
+                       {
+                               bool a = FloatProperty == StaticFloatMethod();
+                               bool b = StaticFloatMethod() == FloatProperty;
+                               return a && b;
+                       }
+
+                       public void FloatParameters(float f, float g)
+                       {
+                               bool a = f == g;
+                               
+                       }
+
+                       public void FloatLocal()
+                       {
+                               float f1 = 0f;
+                               float f2 = 0f;
+                               bool a = f1 == f2;
+                               bool b = f2 == f1;
+                       }
+
+                       public void FloatLocalAbove4()
+                       {
+                               string s1 = String.Empty;
+                               string s2 = String.Empty;
+                               string s3 = String.Empty;
+                               string s4 = String.Empty;
+                               float f1 = 0f;
+                               float f2 = 0f;
+                               bool a = f1 == f2;
+                               bool b = f2 == f1;
+                       }
+
+                       public void FloatComparisonAfterArithmeticOperation()
+                       {
+                               float f1 = 0f;
+                               float f2 = 0f;
+                               bool a = f1 * 1 == f2 * 1;
+                       }
+
+                       public void LegalFloatComparisons()
+                       {
+                               float f = 0f;
+                               bool a;
+                               bool b;
+                               
+                               //a = float.PositiveInfinity == f;
+                               b = f == float.PositiveInfinity;
+                               
+                               //a = float.NegativeInfinity == f;
+                               b = f == float.NegativeInfinity;
+                               
+                       }
+
+                       public void LegalIntegerComparisons()
+                       {
+                               int i = 0;
+                               int j = 1;
+                               bool a = i == j;
+                               
+                       }
+
+
+                       public void FloatEqualsCall()
+                       {
+                               float f1 = 0f;
+                               float f2 = 0f;
+                               bool a = f1.Equals(f2);
+                       }
+
+                       public bool NoFloatComparison()
+                       {
+                               return false;
+                       }
+
+               }
+
+               private IMethodRule rule;
+               private AssemblyDefinition assembly;
+               private TypeDefinition type;
+               private ModuleDefinition module;
+
+               [TestFixtureSetUp]
+               public void FixtureSetUp()
+               {
+                       string unit = Assembly.GetExecutingAssembly().Location;
+                       assembly = AssemblyFactory.GetAssembly(unit);
+                       module = assembly.MainModule;
+                       type = 
module.Types["Test.Rules.Correctness.FloatComparisonRuleTest/Item"];
+                       rule = new FloatComparisonRule();
+               }
+
+               MethodDefinition GetTest(string name)
+               {
+                       foreach (MethodDefinition method in type.Methods)
+                               if (method.Name == name)
+                                       return method;
+
+                       return null;
+               }
+
+               MessageCollection CheckMethod(MethodDefinition method)
+               {
+                       return rule.CheckMethod(method, new MinimalRunner());
+               }
+
+               [Test]
+               public void TestFloatFields()
+               {
+                       MethodDefinition method = GetTest("FloatFields");
+                       Assert.IsNotNull(CheckMethod(method));
+               }
+
+               [Test]
+               public void TestFloatMethodResult()
+               {
+                       MethodDefinition method = GetTest("FloatMethodResult");
+                       Assert.IsNotNull(CheckMethod(method));
+               }
+               
+               [Test]
+               public void TestFloatParameters()
+               {
+                       MethodDefinition method = GetTest("FloatParameters");
+                       Assert.IsNotNull(CheckMethod(method));
+               }
+
+               [Test]
+               public void TestFloatLocal()
+               {
+                       MethodDefinition method = GetTest("FloatLocal");
+                       Assert.IsNotNull(CheckMethod(method));
+               }
+
+               [Test]
+               public void TestFloatLocalAbove4()
+               {
+                       MethodDefinition method = GetTest("FloatLocalAbove4");
+                       Assert.IsNotNull(CheckMethod(method));
+               }
+
+               [Test]
+               public void TestFloatComparisonAfterArithmeticOperation()
+               {
+                       MethodDefinition method = 
GetTest("FloatComparisonAfterArithmeticOperation");
+                       Assert.IsNotNull(CheckMethod(method));
+               }
+
+               [Test]
+               public void TestLegalFloatComparisons()
+               {
+                       MethodDefinition method = 
GetTest("LegalFloatComparisons");
+                       Assert.IsNull(CheckMethod(method));
+               }
+
+               [Test]
+               public void TestLegalIntegerComparisons()
+               {
+                       MethodDefinition method = 
GetTest("LegalIntegerComparisons");
+                       Assert.IsNull(CheckMethod(method));
+               }
+
+
+               [Test]
+               public void TestFloatEqualsCall()
+               {
+                       MethodDefinition method = GetTest("FloatEqualsCall");
+                       Assert.IsNotNull(CheckMethod(method));
+               }
+               
+
+               [Test]
+               public void TestNoFloatComparison()
+               {
+                       MethodDefinition method = GetTest("NoFloatComparison");
+                       Assert.IsNull(CheckMethod(method));
+               }
+
+       }
+}

Modified: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/Test.Rules.Correctness.mdp
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/Test.Rules.Correctness.mdp
       2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/Test.Rules.Correctness.mdp
       2007-10-07 23:10:46 UTC (rev 87064)
@@ -13,10 +13,13 @@
       <CodeGeneration compiler="Csc" warninglevel="4" optimize="True" 
unsafecodeallowed="False" generateoverflowchecks="True" 
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
     </Configuration>
   </Configurations>
-  <DeployTargets />
   <Contents>
     <File name="./BadRecursiveInvocationTest.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./MethodCanBeMadeStaticTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="./CallingEqualsWithNullArgTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="./AvoidConstructorsInStaticTypesTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="./FloatComparisonRuleTest.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="./UseValueInPropertySetterTest.cs" subtype="Code" 
buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, 
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
@@ -25,4 +28,6 @@
     <ProjectReference type="Assembly" localcopy="True" 
refto="../../../../lib/Mono.Cecil.dll" />
     <ProjectReference type="Project" localcopy="True" refto="framework" />
   </References>
+  <Deployment.LinuxDeployData generatePcFile="False" />
+  <DeployTargets />
 </Project>
\ No newline at end of file

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/UseValueInPropertySetterTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/UseValueInPropertySetterTest.cs
  2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/UseValueInPropertySetterTest.cs
  2007-10-07 23:10:46 UTC (rev 87064)
@@ -0,0 +1,118 @@
+//
+// Unit test for UseValueInPropertySetterRule
+//
+// Authors:
+//     Lukasz Knop <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Lukasz Knop
+//
+// 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.Text;
+using Gendarme.Framework;
+using Gendarme.Rules.Correctness;
+using Mono.Cecil;
+using NUnit.Framework;
+using System.Reflection;
+
+namespace Test.Rules.Correctness
+{
+       [TestFixture]
+       public class UseValueInPropertySetterTest
+       {
+               public class Item
+               {
+
+                       public bool UsesValue
+                       {
+                               set
+                               {
+                                       bool val = value;
+                               }
+                       }
+
+                       public bool DoesNotUseValue
+                       {
+                               set
+                               {
+                                       bool val = true;
+                               }
+                       }
+
+                       public void set_NotAProperty(bool value)
+                       {
+                               bool val = true;
+                       }
+               }
+
+               private IMethodRule rule;
+               private AssemblyDefinition assembly;
+               private TypeDefinition type;
+               private ModuleDefinition module;
+
+               [TestFixtureSetUp]
+               public void FixtureSetUp()
+               {
+                       string unit = Assembly.GetExecutingAssembly().Location;
+                       assembly = AssemblyFactory.GetAssembly(unit);
+                       module = assembly.MainModule;
+                       type = 
module.Types["Test.Rules.Correctness.UseValueInPropertySetterTest/Item"];
+                       rule = new UseValueInPropertySetterRule();
+               }
+
+               MethodDefinition GetTest(string name)
+               {
+                       foreach (MethodDefinition method in type.Methods)
+                               if (method.Name == name)
+                                       return method;
+
+                       return null;
+               }
+
+               MessageCollection CheckMethod(MethodDefinition method)
+               {
+                       return rule.CheckMethod(method, new MinimalRunner());
+               }
+
+               [Test]
+               public void TestUsesValue()
+               {
+                       MethodDefinition method = GetTest("set_UsesValue");
+                       Assert.IsNull(CheckMethod(method));
+               }
+               
+               [Test]
+               public void TestDoesNotUseValue()
+               {
+                       MethodDefinition method = 
GetTest("set_DoesNotUseValue");
+                       Assert.IsNotNull(CheckMethod(method));
+               }
+
+               [Test]
+               public void TestNotAProperty()
+               {
+                       MethodDefinition method = GetTest("set_NotAProperty");
+                       Assert.IsNull(CheckMethod(method));
+               }
+
+       }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/UseValueInPropertySetterRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/UseValueInPropertySetterRule.cs
       2007-10-07 23:04:34 UTC (rev 87063)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/UseValueInPropertySetterRule.cs
       2007-10-07 23:10:46 UTC (rev 87064)
@@ -0,0 +1,72 @@
+
+// Gendarme.Rules.Correctness.UseValueInPropertySetterRule 
+//
+// Authors:
+//     Lukasz Knop <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Lukasz Knop
+//
+// 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.Text;
+
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+
+using Gendarme.Framework;
+
+
+namespace Gendarme.Rules.Correctness
+{
+       public class UseValueInPropertySetterRule : IMethodRule
+       {
+               private const string MessageString = "Property setter should 
use the assigned value";
+               
+                       
+               public MessageCollection CheckMethod(MethodDefinition method, 
Runner runner)
+               {
+                       MessageCollection messageCollection = new 
MessageCollection();
+
+                       if ((method.Attributes & MethodAttributes.SpecialName) 
== MethodAttributes.SpecialName && method.Name.StartsWith("set_"))
+                       {
+                               bool valueAccessed = false;
+                               foreach (Instruction instruction in 
method.Body.Instructions)
+                               {
+                                       if (instruction.OpCode.Code == 
Code.Ldarg_1)
+                                       {
+                                               valueAccessed = true;
+                                       }
+                               }
+                               if (!valueAccessed)
+                               {
+                                       Location location = new 
Location(method.DeclaringType.Name, method.Name, 0);
+                                       Message message = new 
Message(MessageString, location, MessageType.Error);
+                                       messageCollection.Add(message);
+                               }
+                       }
+                       
+                       return messageCollection.Count > 0 ? messageCollection 
: null;
+               }
+
+               
+       }
+}

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

Reply via email to