Author: spouliot
Date: 2008-01-18 19:30:17 -0500 (Fri, 18 Jan 2008)
New Revision: 93307

Added:
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/EnsureSymmetryForOverloadedOperatorsTest.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/OperatorEqualsShouldBeOverloadedTest.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/OverrideEqualsMethodTest.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ProvideAlternativeNamesForOperatorOverloadsTest.cs
Modified:
   trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
Log:
2008-01-18  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * EnsureSymmetryForOverloadedOperatorsTest.cs: New. Unit tests by 
        Andreas Noever
        * OperatorEqualsShouldBeOverloadedTest.cs: New. Unit tests by 
        Andreas Noever
        * OverrideEqualsMethodTest.cs: New. Unit tests by Andreas Noever
        * ProvideAlternativeNamesForOperatorOverloadsTest.cs: New. Unit 
        tests by Andreas Noever



Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog     
2008-01-19 00:25:22 UTC (rev 93306)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog     
2008-01-19 00:30:17 UTC (rev 93307)
@@ -1,3 +1,13 @@
+2008-01-18  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * EnsureSymmetryForOverloadedOperatorsTest.cs: New. Unit tests by 
+       Andreas Noever
+       * OperatorEqualsShouldBeOverloadedTest.cs: New. Unit tests by 
+       Andreas Noever
+       * OverrideEqualsMethodTest.cs: New. Unit tests by Andreas Noever
+       * ProvideAlternativeNamesForOperatorOverloadsTest.cs: New. Unit 
+       tests by Andreas Noever
+
 2008-01-13  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * FinalizersShouldBeProtectedTest.cs: New. Unit tests by Daniel 

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/EnsureSymmetryForOverloadedOperatorsTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/EnsureSymmetryForOverloadedOperatorsTest.cs
   2008-01-19 00:25:22 UTC (rev 93306)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/EnsureSymmetryForOverloadedOperatorsTest.cs
   2008-01-19 00:30:17 UTC (rev 93307)
@@ -0,0 +1,203 @@
+//
+// Unit tests for EnsureSymmetryForOverloadedOperatorsRule
+//
+// Authors:
+//     Andreas Noever <[EMAIL PROTECTED]>
+//
+//  (C) 2008 Andreas Noever
+//
+// 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 Gendarme.Framework;
+using Gendarme.Rules.Design;
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Rules.Design {
+
+       [TestFixture]
+       public class EnsureSymmetryForOverloadedOperatorsTest {
+
+               private EnsureSymmetryForOverloadedOperatorsRule rule;
+               private AssemblyDefinition assembly;
+               private TypeDefinition type;
+
+               [TestFixtureSetUp]
+               public void FixtureSetUp ()
+               {
+                       string unit = 
System.Reflection.Assembly.GetExecutingAssembly ().Location;
+                       assembly = AssemblyFactory.GetAssembly (unit);
+                       type = assembly.MainModule.Types 
["Test.Rules.Design.EnsureSymmetryForOverloadedOperatorsTest"];
+                       rule = new EnsureSymmetryForOverloadedOperatorsRule ();
+               }
+
+               public TypeDefinition GetTest (string name)
+               {
+                       foreach (TypeDefinition nType in type.NestedTypes) {
+                               if (nType.Name == name)
+                                       return nType;
+                       }
+                       return null;
+               }
+
+               public TypeDefinition CreateType (string name, string [] 
methods, int parameterCount)
+               {
+                       TypeDefinition testType = new TypeDefinition (name, "", 
TypeAttributes.Class, type.BaseType);
+                       TypeDefinition returnType = new TypeDefinition 
("Boolean", "System", TypeAttributes.Class, type.BaseType);
+                       foreach (string method in methods) {
+                               MethodDefinition mDef = new MethodDefinition 
(method, MethodAttributes.Static | MethodAttributes.SpecialName, returnType);
+                               for (int i = 0; i < parameterCount; i++)
+                                       mDef.Parameters.Add (new 
ParameterDefinition (testType));
+                               testType.Methods.Add (mDef);
+
+                       }
+                       return testType;
+               }
+
+               class FalsePositive {
+                       public void DoStuff () { }
+               }
+
+               [Test]
+               public void TestFalsePositive ()
+               {
+                       TypeDefinition type = GetTest ("FalsePositive");
+                       Assert.IsNull (rule.CheckType (type, new MinimalRunner 
()));
+               }
+
+               class EverythingOK {
+                       public static EverythingOK operator + (EverythingOK a, 
EverythingOK b) { return null; }
+                       public static EverythingOK operator - (EverythingOK a, 
EverythingOK b) { return null; }
+                       public static EverythingOK operator * (EverythingOK a, 
EverythingOK b) { return null; }
+                       public static EverythingOK operator / (EverythingOK a, 
EverythingOK b) { return null; }
+                       public static EverythingOK operator % (EverythingOK a, 
EverythingOK b) { return null; }
+                       public static bool operator > (EverythingOK a, 
EverythingOK b) { return false; }
+                       public static bool operator >= (EverythingOK a, 
EverythingOK b) { return false; }
+                       public static bool operator < (EverythingOK a, 
EverythingOK b) { return false; }
+                       public static bool operator <= (EverythingOK a, 
EverythingOK b) { return false; }
+                       public static bool operator != (EverythingOK a, 
EverythingOK b) { return false; }
+                       public static bool operator == (EverythingOK a, 
EverythingOK b) { return false; }
+
+                       public static bool operator true (EverythingOK a) { 
return false; }
+                       public static bool operator false (EverythingOK a) { 
return true; }
+               }
+
+               [Test]
+               public void TestEverythingOK ()
+               {
+                       TypeDefinition type = GetTest ("EverythingOK");
+                       Assert.IsNull (rule.CheckType (type, new MinimalRunner 
()));
+               }
+
+               class Missing1 {
+                       public static Missing1 operator + (Missing1 a, Missing1 
b) { return null; }
+                       public static Missing1 operator * (Missing1 a, Missing1 
b) { return null; }
+               }
+
+               [Test]
+               public void TestMissing1 ()
+               {
+                       TypeDefinition type = GetTest ("Missing1");
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (2, results.Count);
+               }
+
+               class Missing2 {
+                       public static Missing2 operator - (Missing2 a, Missing2 
b) { return null; }
+                       public static Missing2 operator / (Missing2 a, Missing2 
b) { return null; }
+               }
+
+               [Test]
+               public void TestMissing2 ()
+               {
+                       TypeDefinition type = GetTest ("Missing2");
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (3, results.Count); // divide fires for 
multiply and modulus
+               }
+
+               [Test]
+               public void TestModulus ()
+               {
+                       TypeDefinition type = this.CreateType ("Modulus", new 
string [] { "op_Modulus" }, 2);
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (1, results.Count);
+               }
+
+               [Test]
+               public void TestGreater ()
+               {
+                       TypeDefinition type = this.CreateType ("Greater", new 
string [] { "op_GreaterThan", "op_GreaterThanOrEqual" }, 2);
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (2, results.Count);
+               }
+
+               [Test]
+               public void TestLess ()
+               {
+                       TypeDefinition type = this.CreateType ("Less", new 
string [] { "op_LessThan", "op_LessThanOrEqual" }, 2);
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (2, results.Count);
+               }
+
+               [Test]
+               public void TestEquality ()
+               {
+                       TypeDefinition type = this.CreateType ("Equality", new 
string [] { "op_Equality" }, 2);
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (1, results.Count);
+               }
+
+               [Test]
+               public void TestInequality ()
+               {
+                       TypeDefinition type = this.CreateType ("Inequality", 
new string [] { "op_Inequality" }, 2);
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (1, results.Count);
+               }
+
+               [Test]
+               public void TestTrue ()
+               {
+                       TypeDefinition type = this.CreateType ("True", new 
string [] { "op_True" }, 1);
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (1, results.Count);
+               }
+
+               [Test]
+               public void TestFalse ()
+               {
+                       TypeDefinition type = this.CreateType ("False", new 
string [] { "op_False" }, 1);
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (1, results.Count);
+               }
+       }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/OperatorEqualsShouldBeOverloadedTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/OperatorEqualsShouldBeOverloadedTest.cs
       2008-01-19 00:25:22 UTC (rev 93306)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/OperatorEqualsShouldBeOverloadedTest.cs
       2008-01-19 00:30:17 UTC (rev 93307)
@@ -0,0 +1,161 @@
+//
+// Unit tests for OperatorEqualsShouldBeOverloadedRule
+//
+// Authors:
+//     Andreas Noever <[EMAIL PROTECTED]>
+//
+//  (C) 2008 Andreas Noever
+//
+// 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.Design;
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Rules.Design {
+
+       [TestFixture]
+       public class OperatorEqualsShouldBeOverloadedTest {
+
+               private OperatorEqualsShouldBeOverloadedRule rule;
+               private AssemblyDefinition assembly;
+
+
+               [TestFixtureSetUp]
+               public void FixtureSetUp ()
+               {
+                       string unit = Assembly.GetExecutingAssembly ().Location;
+                       assembly = AssemblyFactory.GetAssembly (unit);
+                       rule = new OperatorEqualsShouldBeOverloadedRule ();
+               }
+
+               public TypeDefinition GetTest (string name)
+               {
+                       foreach (TypeDefinition type in 
assembly.MainModule.Types 
["Test.Rules.Design.OperatorEqualsShouldBeOverloadedTest"].NestedTypes) {
+                               if (type.Name == name)
+                                       return type;
+                       }
+                       return null;
+               }
+
+               class FalsePositive {
+                       public void DoStuff () { }
+               }
+
+               [Test]
+               public void TestFalsePositive ()
+               {
+                       TypeDefinition type = GetTest ("FalsePositive");
+                       Assert.IsNull (rule.CheckType (type, new MinimalRunner 
()));
+               }
+
+               class OnlyOneOperator {
+                       public static OnlyOneOperator operator + 
(OnlyOneOperator a, OnlyOneOperator b)
+                       {
+                               return new OnlyOneOperator ();
+                       }
+               }
+
+               [Test]
+               public void TestOnlyOneOperator ()
+               {
+                       TypeDefinition type = GetTest ("OnlyOneOperator");
+                       Assert.IsNull (rule.CheckType (type, new MinimalRunner 
()));
+               }
+
+               class EverythingOK {
+                       public static EverythingOK operator + (EverythingOK a, 
EverythingOK b)
+                       {
+                               return new EverythingOK ();
+                       }
+
+                       public static EverythingOK operator - (EverythingOK a, 
EverythingOK b)
+                       {
+                               return new EverythingOK ();
+                       }
+
+                       public static bool operator == (EverythingOK a, 
EverythingOK b)
+                       {
+                               return true;
+                       }
+
+                       public static bool operator != (EverythingOK a, 
EverythingOK b)
+                       {
+                               return true;
+                       }
+               }
+
+               [Test]
+               public void TestEverythingOK ()
+               {
+                       TypeDefinition type = GetTest ("EverythingOK");
+                       Assert.IsNull (rule.CheckType (type, new MinimalRunner 
()));
+               }
+
+               class NoEquals {
+                       public static NoEquals operator + (NoEquals a, NoEquals 
b)
+                       {
+                               return null;
+                       }
+
+                       public static NoEquals operator - (NoEquals a, NoEquals 
b)
+                       {
+                               return null;
+                       }
+               }
+
+               [Test]
+               public void TestNoEquals ()
+               {
+                       TypeDefinition type = GetTest ("NoEquals");
+                       Assert.IsNotNull (rule.CheckType (type, new 
MinimalRunner ()));
+               }
+
+               struct StructFalsePositive {
+                       public void DoWork () { }
+               }
+
+               [Test]
+               public void TestStructFalsePositive ()
+               {
+                       TypeDefinition type = GetTest ("StructFalsePositive");
+                       Assert.IsNull (rule.CheckType (type, new MinimalRunner 
()));
+               }
+
+               struct StructNoEquality {
+                       public override bool Equals (object obj)
+                       {
+                               return base.Equals (obj);
+                       }
+               }
+
+               [Test]
+               public void TestStructNoEquality ()
+               {
+                       TypeDefinition type = GetTest ("StructNoEquality");
+                       Assert.IsNotNull (rule.CheckType (type, new 
MinimalRunner ()));
+               }
+       }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/OverrideEqualsMethodTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/OverrideEqualsMethodTest.cs
   2008-01-19 00:25:22 UTC (rev 93306)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/OverrideEqualsMethodTest.cs
   2008-01-19 00:30:17 UTC (rev 93307)
@@ -0,0 +1,117 @@
+//
+// Unit tests for OverrideEqualsMethodRule
+//
+// Authors:
+//     Andreas Noever <[EMAIL PROTECTED]>
+//
+//  (C) 2008 Andreas Noever
+//
+// 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.Design;
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Rules.Design {
+
+       [TestFixture]
+       public class OverrideEqualsMethodTest {
+
+               private OverrideEqualsMethodRule rule;
+               private AssemblyDefinition assembly;
+
+
+               [TestFixtureSetUp]
+               public void FixtureSetUp ()
+               {
+                       string unit = Assembly.GetExecutingAssembly ().Location;
+                       assembly = AssemblyFactory.GetAssembly (unit);
+                       rule = new OverrideEqualsMethodRule ();
+               }
+
+               public TypeDefinition GetTest (string name)
+               {
+                       foreach (TypeDefinition type in 
assembly.MainModule.Types 
["Test.Rules.Design.OverrideEqualsMethodTest"].NestedTypes) {
+                               if (type.Name == name)
+                                       return type;
+                       }
+                       return null;
+               }
+
+               class FalsePositive {
+                       public void DoStuff () { }
+               }
+
+               [Test]
+               public void TestFalsePositive ()
+               {
+                       TypeDefinition type = GetTest ("FalsePositive");
+                       Assert.IsNull (rule.CheckType (type, new MinimalRunner 
()));
+               }
+
+               class EverythingOK {
+                       public static bool operator == (EverythingOK a, 
EverythingOK b)
+                       {
+                               return true;
+                       }
+
+                       public static bool operator != (EverythingOK a, 
EverythingOK b)
+                       {
+                               return true;
+                       }
+
+                       public override bool Equals (object obj)
+                       {
+                               return base.Equals (obj);
+                       }
+               }
+
+               [Test]
+               public void TestEverythingOK ()
+               {
+                       TypeDefinition type = GetTest ("EverythingOK");
+                       Assert.IsNull (rule.CheckType (type, new MinimalRunner 
()));
+               }
+
+               class NoEquals {
+                       public static bool operator == (NoEquals a, NoEquals b)
+                       {
+                               return true;
+                       }
+
+                       public static bool operator != (NoEquals a, NoEquals b)
+                       {
+                               return true;
+                       }
+               }
+
+               [Test]
+               public void TestNoEquals ()
+               {
+                       TypeDefinition type = GetTest ("NoEquals");
+                       Assert.IsNotNull (rule.CheckType (type, new 
MinimalRunner ()));
+               }
+       }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ProvideAlternativeNamesForOperatorOverloadsTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ProvideAlternativeNamesForOperatorOverloadsTest.cs
    2008-01-19 00:25:22 UTC (rev 93306)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ProvideAlternativeNamesForOperatorOverloadsTest.cs
    2008-01-19 00:30:17 UTC (rev 93307)
@@ -0,0 +1,202 @@
+//
+// Unit tests for ProvideAlternativeNamesForOperatorOverloadsRule
+//
+// Authors:
+//     Andreas Noever <[EMAIL PROTECTED]>
+//
+//  (C) 2008 Andreas Noever
+//
+// 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.Design;
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Rules.Design {
+
+       [TestFixture]
+       public class ProvideAlternativeNamesForOperatorOverloadsTest {
+
+               private ProvideAlternativeNamesForOperatorOverloadsRule rule;
+               private AssemblyDefinition assembly;
+
+
+               [TestFixtureSetUp]
+               public void FixtureSetUp ()
+               {
+                       string unit = Assembly.GetExecutingAssembly ().Location;
+                       assembly = AssemblyFactory.GetAssembly (unit);
+                       rule = new 
ProvideAlternativeNamesForOperatorOverloadsRule ();
+               }
+
+               public TypeDefinition GetTest (string name)
+               {
+                       foreach (TypeDefinition type in 
assembly.MainModule.Types 
["Test.Rules.Design.ProvideAlternativeNamesForOperatorOverloadsTest"].NestedTypes)
 {
+                               if (type.Name == name)
+                                       return type;
+                       }
+                       return null;
+               }
+
+               class FalsePositive {
+                       public void DoStuff () { }
+               }
+
+               [Test]
+               public void TestFalsePositive ()
+               {
+                       TypeDefinition type = GetTest ("FalsePositive");
+                       Assert.IsNull (rule.CheckType (type, new MinimalRunner 
()));
+               }
+
+               class EverythingIsThere {
+
+                       public static EverythingIsThere operator + 
(EverythingIsThere a) { return null; }
+                       public static EverythingIsThere operator - 
(EverythingIsThere a) { return null; }
+                       public static EverythingIsThere operator ! 
(EverythingIsThere a) { return null; }
+                       public static EverythingIsThere operator ~ 
(EverythingIsThere a) { return null; }
+
+                       public static EverythingIsThere operator ++ 
(EverythingIsThere a) { return null; }
+                       public static EverythingIsThere operator -- 
(EverythingIsThere a) { return null; }
+                       public static bool operator true (EverythingIsThere a) 
{ return false; }
+                       public static bool operator false (EverythingIsThere a) 
{ return true; }
+
+                       public static EverythingIsThere operator + 
(EverythingIsThere a, EverythingIsThere b) { return null; }
+                       public static EverythingIsThere operator - 
(EverythingIsThere a, EverythingIsThere b) { return null; }
+                       public static EverythingIsThere operator * 
(EverythingIsThere a, EverythingIsThere b) { return null; }
+                       public static EverythingIsThere operator / 
(EverythingIsThere a, EverythingIsThere b) { return null; }
+                       public static EverythingIsThere operator % 
(EverythingIsThere a, EverythingIsThere b) { return null; }
+
+                       public static EverythingIsThere operator & 
(EverythingIsThere a, EverythingIsThere b) { return null; }
+                       public static EverythingIsThere operator | 
(EverythingIsThere a, EverythingIsThere b) { return null; }
+                       public static EverythingIsThere operator ^ 
(EverythingIsThere a, EverythingIsThere b) { return null; }
+
+                       public static EverythingIsThere operator << 
(EverythingIsThere a, int b) { return null; }
+                       public static EverythingIsThere operator >> 
(EverythingIsThere a, int b) { return null; }
+
+                       public static bool operator > (EverythingIsThere a, 
EverythingIsThere b) { return false; }
+                       public static bool operator >= (EverythingIsThere a, 
EverythingIsThere b) { return false; }
+                       public static bool operator < (EverythingIsThere a, 
EverythingIsThere b) { return false; }
+                       public static bool operator <= (EverythingIsThere a, 
EverythingIsThere b) { return false; }
+                       public static bool operator != (EverythingIsThere a, 
EverythingIsThere b) { return false; }
+                       public static bool operator == (EverythingIsThere a, 
EverythingIsThere b) { return false; } //for !=
+
+                       public EverythingIsThere Plus () { return null; }
+                       public EverythingIsThere Negate () { return null; }
+                       public EverythingIsThere LogicalNot () { return null; }
+                       public EverythingIsThere OnesComplement () { return 
null; }
+
+                       public EverythingIsThere Increment () { return null; }
+                       public EverythingIsThere Decrement () { return null; }
+                       public EverythingIsThere IsTrue () { return null; }
+                       public EverythingIsThere IsFalse () { return null; }
+
+                       public EverythingIsThere Add (EverythingIsThere other) 
{ return null; }
+                       public EverythingIsThere Subtract (EverythingIsThere 
other) { return null; }
+                       public EverythingIsThere Multiply (EverythingIsThere 
other) { return null; }
+                       public EverythingIsThere Divide (EverythingIsThere 
other) { return null; }
+                       public EverythingIsThere Modulus (EverythingIsThere 
other) { return null; }
+
+                       public EverythingIsThere BitwiseAnd (EverythingIsThere 
other) { return null; }
+                       public EverythingIsThere BitwiseOr (EverythingIsThere 
other) { return null; }
+                       public EverythingIsThere ExclusiveOr (EverythingIsThere 
other) { return null; }
+
+                       public EverythingIsThere LeftShift (EverythingIsThere 
other) { return null; }
+                       public EverythingIsThere RightShift (EverythingIsThere 
other) { return null; }
+
+                       public int Compare (EverythingIsThere other) { return 
0; }
+               }
+
+               [Test]
+               public void TestEverythingIsThere ()
+               {
+                       TypeDefinition type = GetTest ("EverythingIsThere");
+                       Assert.IsNull (rule.CheckType (type, new MinimalRunner 
()));
+               }
+
+               class MissingCompare {
+                       public static bool operator > (MissingCompare a, 
MissingCompare b) { return false; }
+                       public static bool operator >= (MissingCompare a, 
MissingCompare b) { return false; }
+                       public static bool operator < (MissingCompare a, 
MissingCompare b) { return false; }
+                       public static bool operator <= (MissingCompare a, 
MissingCompare b) { return false; }
+                       public static bool operator != (MissingCompare a, 
MissingCompare b) { return false; }
+                       public static bool operator == (MissingCompare a, 
MissingCompare b) { return false; } //for !=
+               }
+
+               [Test]
+               public void TestMissingCompare ()
+               {
+                       TypeDefinition type = GetTest ("MissingCompare");
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (5, results.Count);
+               }
+
+               class MissingUnary {
+                       public static MissingUnary operator + (MissingUnary a) 
{ return null; }
+                       public static MissingUnary operator - (MissingUnary a) 
{ return null; }
+                       public static MissingUnary operator ! (MissingUnary a) 
{ return null; }
+                       public static MissingUnary operator ~ (MissingUnary a) 
{ return null; }
+
+                       public static MissingUnary operator ++ (MissingUnary a) 
{ return null; }
+                       public static MissingUnary operator -- (MissingUnary a) 
{ return null; }
+                       public static bool operator true (MissingUnary a) { 
return false; }
+                       public static bool operator false (MissingUnary a) { 
return true; }
+               }
+
+               [Test]
+               public void TestMissingUnary ()
+               {
+                       TypeDefinition type = GetTest ("MissingUnary");
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (8, results.Count);
+               }
+
+               class MissingBinary {
+                       public static MissingBinary operator + (MissingBinary 
a, MissingBinary b) { return null; }
+                       public static MissingBinary operator - (MissingBinary 
a, MissingBinary b) { return null; }
+                       public static MissingBinary operator * (MissingBinary 
a, MissingBinary b) { return null; }
+                       public static MissingBinary operator / (MissingBinary 
a, MissingBinary b) { return null; }
+                       public static MissingBinary operator % (MissingBinary 
a, MissingBinary b) { return null; }
+
+                       public static MissingBinary operator & (MissingBinary 
a, MissingBinary b) { return null; }
+                       public static MissingBinary operator | (MissingBinary 
a, MissingBinary b) { return null; }
+                       public static MissingBinary operator ^ (MissingBinary 
a, MissingBinary b) { return null; }
+
+                       public static MissingBinary operator << (MissingBinary 
a, int b) { return null; }
+                       public static MissingBinary operator >> (MissingBinary 
a, int b) { return null; }
+               }
+
+               [Test]
+               public void TestMissingBinary ()
+               {
+                       TypeDefinition type = GetTest ("MissingBinary");
+                       MessageCollection results = rule.CheckType (type, new 
MinimalRunner ());
+                       Assert.IsNotNull (results);
+                       Assert.AreEqual (10, results.Count);
+               }
+       }
+}

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

Reply via email to