diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2008-02-15 22:17:14 +0300 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2008-02-15 22:17:14 +0300 |
commit | 4d1867743a82af7368e95c8922e48b44862df903 (patch) | |
tree | d44368b16b3adb1736a076a1980c69da81b647b8 /gendarme/rules | |
parent | 06048ff0fb3db23763890e456a5780b27fef0610 (diff) |
2008-02-15 Sebastien Pouliot <sebastien@ximian.com>
* GetLastErrorMustBeCalledRightAfterPInvokeTest.cs
* MarshalStringsInPInvokeDeclarationsTest.cs
* PInvokeShouldNotBeVisibleTest.cs
* UseManagedAlternativesToPInvokeTest.cs:
Update unit tests wrt framework changes.
svn path=/trunk/mono-tools/; revision=95793
Diffstat (limited to 'gendarme/rules')
5 files changed, 51 insertions, 41 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Interoperability/Test/ChangeLog b/gendarme/rules/Gendarme.Rules.Interoperability/Test/ChangeLog index 88a9b9d7..344857c8 100644 --- a/gendarme/rules/Gendarme.Rules.Interoperability/Test/ChangeLog +++ b/gendarme/rules/Gendarme.Rules.Interoperability/Test/ChangeLog @@ -1,3 +1,11 @@ +2008-02-15 Sebastien Pouliot <sebastien@ximian.com> + + * GetLastErrorMustBeCalledRightAfterPInvokeTest.cs + * MarshalStringsInPInvokeDeclarationsTest.cs + * PInvokeShouldNotBeVisibleTest.cs + * UseManagedAlternativesToPInvokeTest.cs: + Update unit tests wrt framework changes. + 2008-01-30 Sebastien Pouliot <sebastien@ximian.com> * GetLastErrorMustBeCalledRightAfterPInvokeTest.cs: More unit diff --git a/gendarme/rules/Gendarme.Rules.Interoperability/Test/GetLastErrorMustBeCalledRightAfterPInvokeTest.cs b/gendarme/rules/Gendarme.Rules.Interoperability/Test/GetLastErrorMustBeCalledRightAfterPInvokeTest.cs index 2a5335dd..5be45dd6 100644 --- a/gendarme/rules/Gendarme.Rules.Interoperability/Test/GetLastErrorMustBeCalledRightAfterPInvokeTest.cs +++ b/gendarme/rules/Gendarme.Rules.Interoperability/Test/GetLastErrorMustBeCalledRightAfterPInvokeTest.cs @@ -43,6 +43,7 @@ namespace Test.Rules.Interoperability { private GetLastErrorMustBeCalledRightAfterPInvokeRule rule; private AssemblyDefinition assembly; private TypeDefinition type; + private TestRunner runner; [DllImport ("User32.dll")] static extern Boolean MessageBeep (UInt32 beepType); @@ -124,6 +125,7 @@ namespace Test.Rules.Interoperability { assembly = AssemblyFactory.GetAssembly (unit); type = assembly.MainModule.Types ["Test.Rules.Interoperability.GetLastErrorMustBeCalledRightAfterPInvokeTest"]; rule = new GetLastErrorMustBeCalledRightAfterPInvokeRule (); + runner = new TestRunner (rule); } private MethodDefinition GetTest (string name) @@ -139,70 +141,70 @@ namespace Test.Rules.Interoperability { public void TestNothing () { MethodDefinition method = GetTest ("CallNothing"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestNothingNotExternal () { MethodDefinition method = GetTest ("CallNothingNotExternal"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestPInvoke () { MethodDefinition method = GetTest ("CallPInvoke"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestPInvoke_GetError () { MethodDefinition method = GetTest ("CallPInvoke_GetError"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestPInvoke_GetError_valid () { MethodDefinition method = GetTest ("CallPInvoke_GetError_valid"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestPInvoke_GetError_invalid () { MethodDefinition method = GetTest ("CallPInvoke_GetError_invalid"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method)); } [Test] public void TestPInvoke_GetError_invalid_newobj () { MethodDefinition method = GetTest ("CallPInvoke_GetError_invalid_newobj"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method)); } [Test] public void TestPInvoke_GetError_invalid_struct () { MethodDefinition method = GetTest ("CallPInvoke_GetError_invalid_struct"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method)); } [Test] public void TestPInvoke_GetError_valid_struct () { MethodDefinition method = GetTest ("CallPInvoke_GetError_valid_struct"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestGetError () { MethodDefinition method = GetTest ("CallGetError"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } public void CallPInvoke_Branch () @@ -219,7 +221,7 @@ namespace Test.Rules.Interoperability { public void TestPInvoke_Branch () { MethodDefinition method = GetTest ("CallPInvoke_Branch"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } public void CallPInvoke_Switch () @@ -240,7 +242,7 @@ namespace Test.Rules.Interoperability { public void TestPInvoke_Switch () { MethodDefinition method = GetTest ("CallPInvoke_Switch"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } public void CallPInvoke_Endless () @@ -255,7 +257,7 @@ namespace Test.Rules.Interoperability { public void TestPInvoke_Endless () { MethodDefinition method = GetTest ("CallPInvoke_Endless"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } public void TwoPInvokes () @@ -269,7 +271,7 @@ namespace Test.Rules.Interoperability { public void TestTwoPInvokes () { MethodDefinition method = GetTest ("TwoPInvokes"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } } } diff --git a/gendarme/rules/Gendarme.Rules.Interoperability/Test/MarshalStringsInPInvokeDeclarationsTest.cs b/gendarme/rules/Gendarme.Rules.Interoperability/Test/MarshalStringsInPInvokeDeclarationsTest.cs index b45910e3..64182c3b 100644 --- a/gendarme/rules/Gendarme.Rules.Interoperability/Test/MarshalStringsInPInvokeDeclarationsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Interoperability/Test/MarshalStringsInPInvokeDeclarationsTest.cs @@ -44,6 +44,7 @@ namespace Test.Rules.Interoperability { private MarshalStringsInPInvokeDeclarationsRule rule; private AssemblyDefinition assembly; private TypeDefinition type; + private TestRunner runner; // checks for CharSet property [DllImport ("kernel32")] @@ -141,6 +142,7 @@ namespace Test.Rules.Interoperability { assembly = AssemblyFactory.GetAssembly (unit); type = assembly.MainModule.Types ["Test.Rules.Interoperability.MarshalStringsInPInvokeDeclarationsTest"]; rule = new MarshalStringsInPInvokeDeclarationsRule (); + runner = new TestRunner (rule); } private MethodDefinition GetTest (string name) @@ -156,65 +158,63 @@ namespace Test.Rules.Interoperability { public void TestEmptyMethod () { MethodDefinition method = GetTest ("EmptyMethod"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (method)); } [Test] public void TestNoStringsMethod () { MethodDefinition method = GetTest ("Sleep"); - MessageCollection messages = rule.CheckMethod (method, new MinimalRunner ()); - Assert.IsNull (messages); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestStringWithCharsetMethod () { MethodDefinition method = GetTest ("FindFirstFile"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestStringBuilderWithCharsetMethod () { MethodDefinition method = GetTest ("GetUserNameEx"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestStringWithoutCharsetMethod () { MethodDefinition method = GetTest ("PlaySound"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method)); } [Test] public void TestStringBuilderWithoutCharsetMethod () { MethodDefinition method = GetTest ("MessageBox"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method)); } [Test] public void TestDeclarationWithMarshalAs () { MethodDefinition method = GetTest ("GetShortPathNameGood"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestDeclarationWithoutMarshalAsCharsetSpec () { MethodDefinition method = GetTest ("GetShortPathNameBadParametersCharsetSpec"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestDeclarationWithoutMarshalAsCharsetNotSpec () { MethodDefinition method = GetTest ("GetShortPathNameBadParametersCharsetNotSpec"); - MessageCollection messages = rule.CheckMethod (method, new MinimalRunner ()); - Assert.IsNotNull (messages); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method)); } } } diff --git a/gendarme/rules/Gendarme.Rules.Interoperability/Test/PInvokeShouldNotBeVisibleTest.cs b/gendarme/rules/Gendarme.Rules.Interoperability/Test/PInvokeShouldNotBeVisibleTest.cs index 1de19ef3..81397520 100644 --- a/gendarme/rules/Gendarme.Rules.Interoperability/Test/PInvokeShouldNotBeVisibleTest.cs +++ b/gendarme/rules/Gendarme.Rules.Interoperability/Test/PInvokeShouldNotBeVisibleTest.cs @@ -72,6 +72,7 @@ namespace Test.Rules.Interoperability { public class PInvokeShouldNotBeVisibleRuleTest { private PInvokeShouldNotBeVisibleRule rule; + private TestRunner runner; private AssemblyDefinition assembly; private TypeDefinition internalType; private TypeDefinition publicType; @@ -91,6 +92,7 @@ namespace Test.Rules.Interoperability { publicType_PublicNested = assembly.MainModule.Types ["Test.Rules.Interoperability.PInvokePublic"].NestedTypes [0]; publicType_InternalNested = assembly.MainModule.Types ["Test.Rules.Interoperability.PInvokePublic"].NestedTypes [1]; rule = new PInvokeShouldNotBeVisibleRule (); + runner = new TestRunner (rule); } private MethodDefinition GetTest (TypeDefinition type, string name) @@ -106,49 +108,49 @@ namespace Test.Rules.Interoperability { public void TestInternal_Internal () { MethodDefinition method = GetTest (internalType, "MessageBeepInternal"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestInternal_Public () { MethodDefinition method = GetTest (internalType, "MessageBeepPublic"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestInternal_PublicNested() { MethodDefinition method = GetTest (internalType_PublicNested, "MessageBeepPublic"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestPublic_Internal () { MethodDefinition method = GetTest (publicType, "MessageBeepInternal"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } [Test] public void TestPublic_Public () { MethodDefinition method = GetTest (publicType, "MessageBeepPublic"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method)); } [Test] public void TestPublic_PublicNested () { MethodDefinition method = GetTest (publicType_PublicNested, "MessageBeepPublic"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method)); } [Test] - public void TestPublic_InernalNested () + public void TestPublic_InternalNested () { MethodDefinition method = GetTest (publicType_InternalNested, "MessageBeepPublic"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } } } diff --git a/gendarme/rules/Gendarme.Rules.Interoperability/Test/UseManagedAlternativesToPInvokeTest.cs b/gendarme/rules/Gendarme.Rules.Interoperability/Test/UseManagedAlternativesToPInvokeTest.cs index 869ead6c..28797f72 100644 --- a/gendarme/rules/Gendarme.Rules.Interoperability/Test/UseManagedAlternativesToPInvokeTest.cs +++ b/gendarme/rules/Gendarme.Rules.Interoperability/Test/UseManagedAlternativesToPInvokeTest.cs @@ -45,6 +45,7 @@ namespace Test.Rules.Interoperability { private UseManagedAlternativesToPInvokeRule rule; private AssemblyDefinition assembly; private TypeDefinition type; + private TestRunner runner; [DllImport ("kernel32")] static extern void Sleep (uint time); // bad because we have Thread.Sleep () @@ -65,6 +66,7 @@ namespace Test.Rules.Interoperability { assembly = AssemblyFactory.GetAssembly (unit); type = assembly.MainModule.Types ["Test.Rules.Interoperability.UseManagedAlternativesToPInvokeTest"]; rule = new UseManagedAlternativesToPInvokeRule (); + runner = new TestRunner (rule); } private MethodDefinition GetTest (string name) @@ -80,32 +82,28 @@ namespace Test.Rules.Interoperability { public void TestEmptyMethod () { MethodDefinition method = GetTest ("EmptyMethod"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (method)); } [Test] public void TestBadMethod () { MethodDefinition method = GetTest ("Sleep"); - MessageCollection messages = rule.CheckMethod (method, new MinimalRunner ()); - Assert.IsNotNull (messages); - Assert.AreEqual (1, messages.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method)); } [Test] public void TestBadMethodMultipleSolutions () { MethodDefinition method = GetTest ("FindFirstFile"); - MessageCollection messages = rule.CheckMethod (method, new MinimalRunner ()); - Assert.IsNotNull (messages); - Assert.AreEqual (1, messages.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method)); } [Test] public void TestOkMethod () { MethodDefinition method = GetTest ("MessageBeep"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method)); } } } |