diff options
author | Jb Evain <jb@evain.net> | 2015-04-25 14:52:23 +0300 |
---|---|---|
committer | Jb Evain <jb@evain.net> | 2015-04-25 14:52:23 +0300 |
commit | 73bd4f2fc18d332ee13f895bcc6f5c792f253527 (patch) | |
tree | e8aaf4b1d58b7a97a48ff81f5bb7d9ed0e6227af /Test | |
parent | 1472815cc068c4264a75a8667da784783a989c0e (diff) | |
parent | 7159774d52f0f28d5bd4731bba1ee65e44167dfc (diff) |
Merge branch 'master' into lowermemuse
Conflicts:
Mono.Cecil.PE/Image.cs
Mono.Cecil/DefaultAssemblyResolver.cs
Mono.Cecil/ModuleDefinition.cs
Test/Mono.Cecil.Tests/Addin.cs
Test/Mono.Cecil.Tests/ImageReadTests.cs
Test/Mono.Cecil.Tests/ImportCecilTests.cs
Test/Mono.Cecil.Tests/ImportReflectionTests.cs
Diffstat (limited to 'Test')
42 files changed, 2090 insertions, 1590 deletions
diff --git a/Test/.gitignore b/Test/.gitignore deleted file mode 100644 index 5c45d5f..0000000 --- a/Test/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -bin
-obj
-*.suo
-*.user
-*.xml
-*.pidb
-*.userprefs
diff --git a/Test/Mono.Cecil.Tests.csproj b/Test/Mono.Cecil.Tests.csproj index 31f2978..456e9d3 100644 --- a/Test/Mono.Cecil.Tests.csproj +++ b/Test/Mono.Cecil.Tests.csproj @@ -1,96 +1,13 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="..\Mono.Cecil.Tests.settings" /> <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">net_4_0_Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>9.0.30729</ProductVersion> - <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}</ProjectGuid> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>Mono.Cecil.Tests</RootNamespace> <AssemblyName>Mono.Cecil.Tests</AssemblyName> - <FileAlignment>512</FileAlignment> - <SignAssembly>true</SignAssembly> - <AssemblyOriginatorKeyFile>..\mono.snk</AssemblyOriginatorKeyFile> </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\net_2_0_Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\net_2_0_Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\net_3_5_Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE;NET_3_5</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\net_3_5_Release\</OutputPath> - <DefineConstants>TRACE;NET_3_5</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\net_4_0_Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE;NET_3_5;NET_4_0</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\net_4_0_Release\</OutputPath> - <DefineConstants>TRACE;NET_3_5;NET_4_0</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> - </PropertyGroup> - <ItemGroup Condition=" '$(TargetFrameworkVersion)' != 'v2.0' "> - <Reference Include="System.Core" /> - </ItemGroup> - <ItemGroup> - <Reference Include="nunit.core, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>libs\nunit-2.5.10\nunit.core.dll</HintPath> - </Reference> - <Reference Include="nunit.core.interfaces, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>libs\nunit-2.5.10\nunit.core.interfaces.dll</HintPath> - </Reference> - <Reference Include="nunit.framework, Version=2.5.10.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>libs\nunit-2.5.10\nunit.framework.dll</HintPath> - </Reference> - <Reference Include="System" /> - </ItemGroup> <ItemGroup> - <Compile Include="Mono.Cecil.Tests\Addin.cs" /> + <Compile Include="..\ProjectInfo.cs" /> <Compile Include="Mono.Cecil.Tests\AssemblyTests.cs" /> <Compile Include="Mono.Cecil.Tests\AssemblyInfo.cs" /> <Compile Include="Mono.Cecil.Tests\BaseTestFixture.cs" /> @@ -116,6 +33,7 @@ <Compile Include="Mono.Cecil.Tests\ImageReadTests.cs" /> <Compile Include="Mono.Cecil.Tests\ModuleTests.cs" /> <Compile Include="Mono.Cecil.Tests\NestedTypesTests.cs" /> + <None Include="Resources\il\explicitthis.il" /> <None Include="Resources\cs\CustomAttributes.cs" /> <None Include="Resources\cs\Generics.cs" /> <None Include="Resources\cs\Interfaces.cs" /> @@ -168,11 +86,4 @@ <Content Include="Resources\assemblies\varargs.exe" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> </Project>
\ No newline at end of file diff --git a/Test/Mono.Cecil.Tests/Addin.cs b/Test/Mono.Cecil.Tests/Addin.cs deleted file mode 100644 index 469d158..0000000 --- a/Test/Mono.Cecil.Tests/Addin.cs +++ /dev/null @@ -1,308 +0,0 @@ -using System; -using System.IO; -using System.Reflection; - -using NUnit.Core; -using NUnit.Core.Extensibility; - -using Mono.Cecil.Cil; - -namespace Mono.Cecil.Tests { - - public abstract class TestCecilAttribute : Attribute { - - bool verify = true; - Type symbol_reader_provider; - Type symbol_writer_provider; - - public bool Verify { - get { return verify; } - set { verify = value; } - } - - public Type SymbolReaderProvider { - get { return symbol_reader_provider; } - set { symbol_reader_provider = value; } - } - - public Type SymbolWriterProvider { - get { return symbol_writer_provider; } - set { symbol_writer_provider = value; } - } - - public abstract string GetModuleLocation (Assembly assembly); - } - - [AttributeUsage (AttributeTargets.Method, AllowMultiple = false)] - public sealed class TestModuleAttribute : TestCecilAttribute { - - readonly string module; - - public string Module { - get { return module; } - } - - public TestModuleAttribute (string assembly) - { - this.module = assembly; - } - - public override string GetModuleLocation (Assembly assembly) - { - return BaseTestFixture.GetAssemblyResourcePath (module, assembly); - } - } - - [AttributeUsage (AttributeTargets.Method, AllowMultiple = false)] - public sealed class TestCSharpAttribute : TestCecilAttribute { - - readonly string file; - - public string File { - get { return file; } - } - - public TestCSharpAttribute (string file) - { - this.file = file; - } - - public override string GetModuleLocation (Assembly assembly) - { - return CompilationService.CompileResource ( - BaseTestFixture.GetCSharpResourcePath (file, assembly)); - } - } - - [AttributeUsage (AttributeTargets.Method, AllowMultiple = false)] - public sealed class TestILAttribute : TestCecilAttribute { - - readonly string file; - - public string File { - get { return file; } - } - - public TestILAttribute (string file) - { - this.file = file; - } - - public override string GetModuleLocation (Assembly assembly) - { - return CompilationService.CompileResource ( - BaseTestFixture.GetILResourcePath (file, assembly)); - } - } - - class CecilTestCase : NUnitTestMethod { - - readonly TestCecilAttribute attribute; - readonly TestCaseType type; - - public CecilTestCase (MethodInfo method, TestCecilAttribute attribute, TestCaseType type) - : base (method) - { - this.TestName.Name = type.ToString (); - this.TestName.FullName = method.DeclaringType.FullName + "." + method.Name + "." + type; - this.attribute = attribute; - this.type = type; - } - - ModuleDefinition GetModule () - { - var location = attribute.GetModuleLocation (this.Method.DeclaringType.Assembly); - - var parameters = new ReaderParameters { - SymbolReaderProvider = GetSymbolReaderProvider (attribute), - }; - - switch (type) { - case TestCaseType.ReadImmediate: - parameters.ReadingMode = ReadingMode.Immediate; - return ModuleDefinition.ReadModule (location, parameters); - case TestCaseType.ReadDeferred: - parameters.ReadingMode = ReadingMode.Deferred; - return ModuleDefinition.ReadModule (location, parameters); - case TestCaseType.WriteFromImmediate: - parameters.ReadingMode = ReadingMode.Immediate; - return RoundTrip (location, parameters, "cecil-irt"); - case TestCaseType.WriteFromDeferred: - parameters.ReadingMode = ReadingMode.Deferred; - return RoundTrip (location, parameters, "cecil-drt"); - default: - return null; - } - } - - static ISymbolReaderProvider GetSymbolReaderProvider (TestCecilAttribute attribute) - { - if (attribute.SymbolReaderProvider == null) - return null; - - return (ISymbolReaderProvider) Activator.CreateInstance (attribute.SymbolReaderProvider); - } - - static ISymbolWriterProvider GetSymbolWriterProvider (TestCecilAttribute attribute) - { - if (attribute.SymbolReaderProvider == null) - return null; - - return (ISymbolWriterProvider) Activator.CreateInstance (attribute.SymbolWriterProvider); - } - - ModuleDefinition RoundTrip (string location, ReaderParameters reader_parameters, string folder) - { - var rt_folder = Path.Combine(Path.GetTempPath(), folder); - if (!Directory.Exists(rt_folder)) - Directory.CreateDirectory(rt_folder); - var rt_module = Path.Combine(rt_folder, Path.GetFileName(location)); - - using (var module = ModuleDefinition.ReadModule (location, reader_parameters)) { - var writer_parameters = new WriterParameters { - SymbolWriterProvider = GetSymbolWriterProvider (attribute), - }; - - Reflect.InvokeMethod (Method, Fixture, new object [] { module }); - - module.Write (rt_module, writer_parameters); - } - - if (attribute.Verify) - CompilationService.Verify (rt_module); - - return ModuleDefinition.ReadModule (rt_module, reader_parameters); - } - - public override TestResult RunTest () - { - var result = new TestResult (TestName); - - using (var module = GetModule ()) { - if (module == null) - return result; - - Reflect.InvokeMethod (Method, Fixture, new object [] { module }); - } - - result.Success (); - return result; - } - } - - class CecilTestSuite : TestSuite { - - public CecilTestSuite (MethodInfo method) - : base (method.DeclaringType.FullName, method.Name) - { - } - - public override TestResult Run (EventListener listener, ITestFilter filter) - { - if (this.Parent != null) - this.Fixture = this.Parent.Fixture; - - return base.Run (listener, filter); - } - - protected override void DoOneTimeSetUp (TestResult suiteResult) - { - } - - protected override void DoOneTimeTearDown (TestResult suiteResult) - { - } - } - - enum TestCaseType { - ReadImmediate, - ReadDeferred, - WriteFromImmediate, - WriteFromDeferred, - } - - static class CecilTestFactory { - - public static CecilTestSuite CreateTestSuite (MethodInfo method) - { - if (method == null) - throw new ArgumentNullException ("method"); - - var suite = new CecilTestSuite (method); - - NUnitFramework.ApplyCommonAttributes (method, suite); - PopulateTestSuite (method, suite); - - return suite; - } - - static void PopulateTestSuite (MethodInfo method, CecilTestSuite suite) - { - var attribute = GetTestCecilAttribute (method); - if (attribute == null) - throw new ArgumentException (); - - foreach (var value in Enum.GetValues (typeof (TestCaseType))) { - var test = CreateTestCase (method, attribute, (TestCaseType) value); - if (test != null) - suite.Add (test); - } - } - - static CecilTestCase CreateTestCase (MethodInfo method, TestCecilAttribute attribute, TestCaseType type) - { - return new CecilTestCase (method, attribute, type); - } - - static TestCecilAttribute GetTestCecilAttribute (MethodInfo method) - { - foreach (var attribute in method.GetCustomAttributes (false)) { - var test = attribute as TestCecilAttribute; - if (test != null) - return test; - } - - return null; - } - } - - [NUnitAddin] - public class CecilTestAddin : IAddin, ITestCaseBuilder { - - public bool Install (IExtensionHost host) - { - if (host == null) - throw new ArgumentNullException ("host"); - - var builders = host.GetExtensionPoint ("TestCaseBuilders"); - if (builders == null) - return false; - - builders.Install (this); - return true; - } - - public Test BuildFrom (MethodInfo method) - { - if (method == null) - throw new ArgumentNullException ("method"); - - return CecilTestFactory.CreateTestSuite (method); - } - - public bool CanBuildFrom (MethodInfo method) - { - if (method == null) - return false; - - return IsCecilTestMethod (method); - } - - static bool IsCecilTestMethod (MethodInfo method) - { - return Reflect.HasAttribute (method, typeof (TestModuleAttribute).FullName, false) - || Reflect.HasAttribute (method, typeof (TestILAttribute).FullName, false) - || Reflect.HasAttribute (method, typeof (TestCSharpAttribute).FullName, false); - } - } -} diff --git a/Test/Mono.Cecil.Tests/AssemblyInfo.cs b/Test/Mono.Cecil.Tests/AssemblyInfo.cs index ad7488f..f4a938a 100644 --- a/Test/Mono.Cecil.Tests/AssemblyInfo.cs +++ b/Test/Mono.Cecil.Tests/AssemblyInfo.cs @@ -1,14 +1,6 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle ("Mono.Cecil.Tests")] -[assembly: AssemblyProduct ("Mono.Cecil")] -[assembly: AssemblyCopyright ("Copyright © 2008 - 2011 Jb Evain")] - -[assembly: ComVisible (false)] [assembly: Guid ("da96c202-696a-457e-89af-5fa74e6bda0d")] - -[assembly: AssemblyVersion ("1.0.0.0")] -[assembly: AssemblyFileVersion ("1.0.0.0")] diff --git a/Test/Mono.Cecil.Tests/AssemblyTests.cs b/Test/Mono.Cecil.Tests/AssemblyTests.cs index 3267f77..7ba3dda 100644 --- a/Test/Mono.Cecil.Tests/AssemblyTests.cs +++ b/Test/Mono.Cecil.Tests/AssemblyTests.cs @@ -9,17 +9,19 @@ namespace Mono.Cecil.Tests { [TestFixture] public class AssemblyTests : BaseTestFixture { - [TestModule ("hello.exe")] - public void Name (ModuleDefinition module) + [Test] + public void Name () { - var name = module.Assembly.Name; + TestModule ("hello.exe", module => { + var name = module.Assembly.Name; - Assert.IsNotNull (name); + Assert.IsNotNull (name); - Assert.AreEqual ("hello", name.Name); - Assert.AreEqual (string.Empty, name.Culture); - Assert.AreEqual (new Version (0, 0, 0, 0), name.Version); - Assert.AreEqual (AssemblyHashAlgorithm.SHA1, name.HashAlgorithm); + Assert.AreEqual ("hello", name.Name); + Assert.AreEqual (string.Empty, name.Culture); + Assert.AreEqual (new Version (0, 0, 0, 0), name.Version); + Assert.AreEqual (AssemblyHashAlgorithm.SHA1, name.HashAlgorithm); + }); } [Test] diff --git a/Test/Mono.Cecil.Tests/BaseTestFixture.cs b/Test/Mono.Cecil.Tests/BaseTestFixture.cs index e160f48..2d0dcb2 100644 --- a/Test/Mono.Cecil.Tests/BaseTestFixture.cs +++ b/Test/Mono.Cecil.Tests/BaseTestFixture.cs @@ -1,7 +1,7 @@ using System; using System.IO; using System.Reflection; - +using Mono.Cecil.Cil; using NUnit.Framework; using Mono.Cecil.PE; @@ -10,6 +10,12 @@ namespace Mono.Cecil.Tests { public abstract class BaseTestFixture { + protected static void IgnoreOnMono () + { + if (Platform.OnMono) + Assert.Ignore (); + } + public static string GetResourcePath (string name, Assembly assembly) { return Path.Combine (FindResourcesDirectory (assembly), name); @@ -30,35 +36,35 @@ namespace Mono.Cecil.Tests { return GetResourcePath (Path.Combine ("il", name), assembly); } - public static ModuleDefinition GetResourceModule (string name) + public ModuleDefinition GetResourceModule (string name) { - return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly)); + return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, GetType ().Assembly)); } - public static ModuleDefinition GetResourceModule (string name, ReaderParameters parameters) + public ModuleDefinition GetResourceModule (string name, ReaderParameters parameters) { - return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly), parameters); + return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, GetType ().Assembly), parameters); } - public static ModuleDefinition GetResourceModule (string name, ReadingMode mode) + public ModuleDefinition GetResourceModule (string name, ReadingMode mode) { - return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly), new ReaderParameters (mode)); + return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, GetType ().Assembly), new ReaderParameters (mode)); } - internal static Image GetResourceImage (string name) + internal Image GetResourceImage (string name) { - using (var fs = new FileStream (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly), FileMode.Open, FileAccess.Read)) + using (var fs = new FileStream (GetAssemblyResourcePath (name, GetType ().Assembly), FileMode.Open, FileAccess.Read)) return ImageReader.ReadImageFrom (fs); } - public static ModuleDefinition GetCurrentModule () + public ModuleDefinition GetCurrentModule () { - return ModuleDefinition.ReadModule (typeof (BaseTestFixture).Module.FullyQualifiedName); + return ModuleDefinition.ReadModule (GetType ().Module.FullyQualifiedName); } - public static ModuleDefinition GetCurrentModule (ReaderParameters parameters) + public ModuleDefinition GetCurrentModule (ReaderParameters parameters) { - return ModuleDefinition.ReadModule (typeof (BaseTestFixture).Module.FullyQualifiedName, parameters); + return ModuleDefinition.ReadModule (GetType ().Module.FullyQualifiedName, parameters); } public static string FindResourcesDirectory (Assembly assembly) @@ -72,5 +78,221 @@ namespace Mono.Cecil.Tests { return Path.Combine (path, "Resources"); } + + public static void TestModule (string file, Action<ModuleDefinition> test, bool verify = true, bool readOnly = false, Type symbolReaderProvider = null, Type symbolWriterProvider = null) + { + Run (new ModuleTestCase (file, test, verify, readOnly, symbolReaderProvider, symbolWriterProvider)); + } + + public static void TestCSharp (string file, Action<ModuleDefinition> test, bool verify = true, bool readOnly = false, Type symbolReaderProvider = null, Type symbolWriterProvider = null) + { + Run (new CSharpTestCase (file, test, verify, readOnly, symbolReaderProvider, symbolWriterProvider)); + } + + public static void TestIL (string file, Action<ModuleDefinition> test, bool verify = true, bool readOnly = false, Type symbolReaderProvider = null, Type symbolWriterProvider = null) + { + Run (new ILTestCase (file, test, verify, readOnly, symbolReaderProvider, symbolWriterProvider)); + } + + private static void Run (TestCase testCase) + { + using (var runner = new TestRunner (testCase, TestCaseType.ReadDeferred)) + runner.RunTest (); + + using (var runner = new TestRunner (testCase, TestCaseType.ReadImmediate)) + runner.RunTest (); + + if (testCase.ReadOnly) + return; + + using (var runner = new TestRunner (testCase, TestCaseType.WriteFromDeferred)) + runner.RunTest(); + + using (var runner = new TestRunner (testCase, TestCaseType.WriteFromImmediate)) + runner.RunTest(); + } + } + + abstract class TestCase { + + public readonly bool Verify; + public readonly bool ReadOnly; + public readonly Type SymbolReaderProvider; + public readonly Type SymbolWriterProvider; + public readonly Action<ModuleDefinition> Test; + + public abstract string ModuleLocation { get; } + + protected Assembly Assembly { get { return Test.Method.Module.Assembly; } } + + protected TestCase (Action<ModuleDefinition> test, bool verify, bool readOnly, Type symbolReaderProvider, Type symbolWriterProvider) + { + Test = test; + Verify = verify; + ReadOnly = readOnly; + SymbolReaderProvider = symbolReaderProvider; + SymbolWriterProvider = symbolWriterProvider; + } + } + + class ModuleTestCase : TestCase { + + public readonly string Module; + + public ModuleTestCase (string module, Action<ModuleDefinition> test, bool verify, bool readOnly, Type symbolReaderProvider, Type symbolWriterProvider) + : base (test, verify, readOnly, symbolReaderProvider, symbolWriterProvider) + { + Module = module; + } + + public override string ModuleLocation + { + get { return BaseTestFixture.GetAssemblyResourcePath (Module, Assembly); } + } + } + + class CSharpTestCase : TestCase { + + public readonly string File; + + public CSharpTestCase (string file, Action<ModuleDefinition> test, bool verify, bool readOnly, Type symbolReaderProvider, Type symbolWriterProvider) + : base (test, verify, readOnly, symbolReaderProvider, symbolWriterProvider) + { + File = file; + } + + public override string ModuleLocation + { + get + { + return CompilationService.CompileResource (BaseTestFixture.GetCSharpResourcePath (File, Assembly)); + } + } + } + + class ILTestCase : TestCase { + + public readonly string File; + + public ILTestCase (string file, Action<ModuleDefinition> test, bool verify, bool readOnly, Type symbolReaderProvider, Type symbolWriterProvider) + : base (test, verify, readOnly, symbolReaderProvider, symbolWriterProvider) + { + File = file; + } + + public override string ModuleLocation + { + get + { + return CompilationService.CompileResource (BaseTestFixture.GetILResourcePath (File, Assembly)); ; + } + } + } + + class TestRunner : IDisposable { + + readonly TestCase test_case; + readonly TestCaseType type; + + ModuleDefinition test_module; + DefaultAssemblyResolver test_resolver; + + public TestRunner (TestCase testCase, TestCaseType type) + { + this.test_case = testCase; + this.type = type; + } + + ModuleDefinition GetModule () + { + var location = test_case.ModuleLocation; + var directory = Path.GetDirectoryName (location); + + test_resolver = new DefaultAssemblyResolver (); + test_resolver.AddSearchDirectory (directory); + + var parameters = new ReaderParameters { + SymbolReaderProvider = GetSymbolReaderProvider (), + AssemblyResolver = test_resolver, + }; + + switch (type) { + case TestCaseType.ReadImmediate: + parameters.ReadingMode = ReadingMode.Immediate; + return ModuleDefinition.ReadModule (location, parameters); + case TestCaseType.ReadDeferred: + parameters.ReadingMode = ReadingMode.Deferred; + return ModuleDefinition.ReadModule (location, parameters); + case TestCaseType.WriteFromImmediate: + parameters.ReadingMode = ReadingMode.Immediate; + return RoundTrip (location, parameters, "cecil-irt"); + case TestCaseType.WriteFromDeferred: + parameters.ReadingMode = ReadingMode.Deferred; + return RoundTrip (location, parameters, "cecil-drt"); + default: + return null; + } + } + + ISymbolReaderProvider GetSymbolReaderProvider () + { + if (test_case.SymbolReaderProvider == null) + return null; + + return (ISymbolReaderProvider) Activator.CreateInstance (test_case.SymbolReaderProvider); + } + + ISymbolWriterProvider GetSymbolWriterProvider () + { + if (test_case.SymbolReaderProvider == null) + return null; + + return (ISymbolWriterProvider) Activator.CreateInstance (test_case.SymbolWriterProvider); + } + + ModuleDefinition RoundTrip (string location, ReaderParameters reader_parameters, string folder) + { + var module = ModuleDefinition.ReadModule (location, reader_parameters); + var rt_folder = Path.Combine (Path.GetTempPath (), folder); + if (!Directory.Exists (rt_folder)) + Directory.CreateDirectory (rt_folder); + var rt_module = Path.Combine (rt_folder, Path.GetFileName (location)); + + var writer_parameters = new WriterParameters { + SymbolWriterProvider = GetSymbolWriterProvider (), + }; + + test_case.Test (module); + + module.Write (rt_module, writer_parameters); + + if (test_case.Verify) + CompilationService.Verify (rt_module); + + return ModuleDefinition.ReadModule (rt_module, reader_parameters); + } + + public void RunTest () + { + var module = GetModule (); + if (module == null) + return; + + test_module = module; + test_case.Test (module); + } + + public void Dispose () + { + test_module.Dispose (); + test_resolver.Dispose (); + } + } + + enum TestCaseType { + ReadImmediate, + ReadDeferred, + WriteFromImmediate, + WriteFromDeferred, } } diff --git a/Test/Mono.Cecil.Tests/CompilationService.cs b/Test/Mono.Cecil.Tests/CompilationService.cs index 5a2def5..54fef5f 100644 --- a/Test/Mono.Cecil.Tests/CompilationService.cs +++ b/Test/Mono.Cecil.Tests/CompilationService.cs @@ -20,6 +20,11 @@ namespace Mono.Cecil.Tests { } } + public static class Platform { + + public static bool OnMono { get { return typeof (object).Assembly.GetType ("Mono.Runtime") != null; } } + } + abstract class CompilationService { Dictionary<string, CompilationResult> files = new Dictionary<string, CompilationResult> (); @@ -77,11 +82,9 @@ namespace Mono.Cecil.Tests { return Path.Combine (tmp_cecil, Path.GetFileName (file_name) + ".dll"); } - static bool OnMono { get { return typeof (object).Assembly.GetType ("Mono.Runtime") != null; } } - public static void Verify (string name) { - var output = OnMono ? ShellService.PEDump (name) : ShellService.PEVerify (name); + var output = Platform.OnMono ? ShellService.PEDump (name) : ShellService.PEVerify (name); if (output.ExitCode != 0) Assert.Fail (output.ToString ()); } @@ -216,7 +219,11 @@ namespace Mono.Cecil.Tests { public static ProcessOutput ILAsm (string source, string output) { - return RunProcess ("ilasm", "/nologo", "/dll", "/out:" + Quote (output), Quote (source)); + var ilasm = "ilasm"; + if (!Platform.OnMono) + ilasm = NetFrameworkTool ("ilasm"); + + return RunProcess (ilasm, "/nologo", "/dll", "/out:" + Quote (output), Quote (source)); } static string Quote (string file) @@ -226,12 +233,43 @@ namespace Mono.Cecil.Tests { public static ProcessOutput PEVerify (string source) { - return RunProcess ("peverify", "/nologo", Quote (source)); + return RunProcess (WinSdkTool ("peverify"), "/nologo", Quote (source)); } public static ProcessOutput PEDump (string source) { return RunProcess ("pedump", "--verify code,metadata", Quote (source)); } + + static string NetFrameworkTool (string tool) + { + return Path.Combine ( + Path.GetDirectoryName (typeof (object).Assembly.Location), + tool + ".exe"); + } + + static string WinSdkTool (string tool) + { + var sdks = new [] { + @"Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools", + @"Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools", + @"Microsoft SDKs\Windows\v7.0A\Bin", + }; + + foreach (var sdk in sdks) { + var pgf = IntPtr.Size == 8 + ? Environment.GetEnvironmentVariable("ProgramFiles(x86)") + : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); + + var exe = Path.Combine ( + Path.Combine (pgf, sdk), + tool + ".exe"); + + if (File.Exists(exe)) + return exe; + } + + return tool; + } } } diff --git a/Test/Mono.Cecil.Tests/CustomAttributesTests.cs b/Test/Mono.Cecil.Tests/CustomAttributesTests.cs index ab8897d..8379c8f 100644 --- a/Test/Mono.Cecil.Tests/CustomAttributesTests.cs +++ b/Test/Mono.Cecil.Tests/CustomAttributesTests.cs @@ -15,331 +15,400 @@ namespace Mono.Cecil.Tests { [TestFixture] public class CustomAttributesTests : BaseTestFixture { - [TestCSharp ("CustomAttributes.cs")] - public void StringArgumentOnType (ModuleDefinition module) + [Test] + public void StringArgumentOnType () { - var hamster = module.GetType ("Hamster"); + TestCSharp ("CustomAttributes.cs", module => { + var hamster = module.GetType ("Hamster"); - Assert.IsTrue (hamster.HasCustomAttributes); - Assert.AreEqual (1, hamster.CustomAttributes.Count); + Assert.IsTrue (hamster.HasCustomAttributes); + Assert.AreEqual (1, hamster.CustomAttributes.Count); - var attribute = hamster.CustomAttributes [0]; - Assert.AreEqual ("System.Void FooAttribute::.ctor(System.String)", - attribute.Constructor.FullName); + var attribute = hamster.CustomAttributes [0]; + Assert.AreEqual ("System.Void FooAttribute::.ctor(System.String)", + attribute.Constructor.FullName); - Assert.IsTrue (attribute.HasConstructorArguments); - Assert.AreEqual (1, attribute.ConstructorArguments.Count); + Assert.IsTrue (attribute.HasConstructorArguments); + Assert.AreEqual (1, attribute.ConstructorArguments.Count); - AssertArgument ("bar", attribute.ConstructorArguments [0]); - } + AssertArgument ("bar", attribute.ConstructorArguments [0]); + }); + } - [TestCSharp ("CustomAttributes.cs")] - public void NullString (ModuleDefinition module) + [Test] + public void NullString () { - var dentist = module.GetType ("Dentist"); + TestCSharp ("CustomAttributes.cs", module => { + var dentist = module.GetType ("Dentist"); - var attribute = GetAttribute (dentist, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (dentist, "Foo"); + Assert.IsNotNull (attribute); - AssertArgument<string> (null, attribute.ConstructorArguments [0]); + AssertArgument<string> (null, attribute.ConstructorArguments [0]); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void Primitives1 (ModuleDefinition module) + [Test] + public void Primitives1 () { - var steven = module.GetType ("Steven"); - - var attribute = GetAttribute (steven, "Foo"); - Assert.IsNotNull (attribute); - - AssertArgument<sbyte> (-12, attribute.ConstructorArguments [0]); - AssertArgument<byte> (242, attribute.ConstructorArguments [1]); - AssertArgument<bool> (true, attribute.ConstructorArguments [2]); - AssertArgument<bool> (false, attribute.ConstructorArguments [3]); - AssertArgument<ushort> (4242, attribute.ConstructorArguments [4]); - AssertArgument<short> (-1983, attribute.ConstructorArguments [5]); - AssertArgument<char> ('c', attribute.ConstructorArguments [6]); + TestCSharp ("CustomAttributes.cs", module => { + var steven = module.GetType ("Steven"); + + var attribute = GetAttribute (steven, "Foo"); + Assert.IsNotNull (attribute); + + AssertArgument<sbyte> (-12, attribute.ConstructorArguments [0]); + AssertArgument<byte> (242, attribute.ConstructorArguments [1]); + AssertArgument<bool> (true, attribute.ConstructorArguments [2]); + AssertArgument<bool> (false, attribute.ConstructorArguments [3]); + AssertArgument<ushort> (4242, attribute.ConstructorArguments [4]); + AssertArgument<short> (-1983, attribute.ConstructorArguments [5]); + AssertArgument<char> ('c', attribute.ConstructorArguments [6]); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void Primitives2 (ModuleDefinition module) + [Test] + public void Primitives2 () { - var seagull = module.GetType ("Seagull"); - - var attribute = GetAttribute (seagull, "Foo"); - Assert.IsNotNull (attribute); - - AssertArgument<int> (-100000, attribute.ConstructorArguments [0]); - AssertArgument<uint> (200000, attribute.ConstructorArguments [1]); - AssertArgument<float> (12.12f, attribute.ConstructorArguments [2]); - AssertArgument<long> (long.MaxValue, attribute.ConstructorArguments [3]); - AssertArgument<ulong> (ulong.MaxValue, attribute.ConstructorArguments [4]); - AssertArgument<double> (64.646464, attribute.ConstructorArguments [5]); + TestCSharp ("CustomAttributes.cs", module => { + var seagull = module.GetType ("Seagull"); + + var attribute = GetAttribute (seagull, "Foo"); + Assert.IsNotNull (attribute); + + AssertArgument<int> (-100000, attribute.ConstructorArguments [0]); + AssertArgument<uint> (200000, attribute.ConstructorArguments [1]); + AssertArgument<float> (12.12f, attribute.ConstructorArguments [2]); + AssertArgument<long> (long.MaxValue, attribute.ConstructorArguments [3]); + AssertArgument<ulong> (ulong.MaxValue, attribute.ConstructorArguments [4]); + AssertArgument<double> (64.646464, attribute.ConstructorArguments [5]); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void StringArgumentOnAssembly (ModuleDefinition module) + [Test] + public void StringArgumentOnAssembly () { - var assembly = module.Assembly; + TestCSharp ("CustomAttributes.cs", module => { + var assembly = module.Assembly; - var attribute = GetAttribute (assembly, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (assembly, "Foo"); + Assert.IsNotNull (attribute); - AssertArgument ("bingo", attribute.ConstructorArguments [0]); + AssertArgument ("bingo", attribute.ConstructorArguments [0]); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void CharArray (ModuleDefinition module) + [Test] + public void CharArray () { - var rifle = module.GetType ("Rifle"); + TestCSharp ("CustomAttributes.cs", module => { + var rifle = module.GetType ("Rifle"); - var attribute = GetAttribute (rifle, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (rifle, "Foo"); + Assert.IsNotNull (attribute); - var argument = attribute.ConstructorArguments [0]; + var argument = attribute.ConstructorArguments [0]; - Assert.AreEqual ("System.Char[]", argument.Type.FullName); + Assert.AreEqual ("System.Char[]", argument.Type.FullName); - var array = argument.Value as CustomAttributeArgument []; - Assert.IsNotNull (array); + var array = argument.Value as CustomAttributeArgument []; + Assert.IsNotNull (array); - var str = "cecil"; + var str = "cecil"; - Assert.AreEqual (array.Length, str.Length); + Assert.AreEqual (array.Length, str.Length); - for (int i = 0; i < str.Length; i++) + for (int i = 0; i < str.Length; i++) AssertArgument (str [i], array [i]); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void BoxedArguments (ModuleDefinition module) + [Test] + public void BoxedArguments () { - var worm = module.GetType ("Worm"); + TestCSharp ("CustomAttributes.cs", module => { + var worm = module.GetType ("Worm"); - var attribute = GetAttribute (worm, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (worm, "Foo"); + Assert.IsNotNull (attribute); - Assert.AreEqual (".ctor ((Object:(String:\"2\")), (Object:(I4:2)))", PrettyPrint (attribute)); + Assert.AreEqual (".ctor ((Object:(String:\"2\")), (Object:(I4:2)))", PrettyPrint (attribute)); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void BoxedArraysArguments (ModuleDefinition module) + [Test] + public void BoxedArraysArguments () { - var sheep = module.GetType ("Sheep"); + TestCSharp ("CustomAttributes.cs", module => { + var sheep = module.GetType ("Sheep"); - var attribute = GetAttribute (sheep, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (sheep, "Foo"); + Assert.IsNotNull (attribute); - // [Foo (new object [] { "2", 2, 'c' }, new object [] { new object [] { 1, 2, 3}, null })] - AssertCustomAttribute (".ctor ((Object:(Object[]:{(Object:(String:\"2\")), (Object:(I4:2)), (Object:(Char:'c'))})), (Object:(Object[]:{(Object:(Object[]:{(Object:(I4:1)), (Object:(I4:2)), (Object:(I4:3))})), (Object:(String:null))})))", attribute); + // [Foo (new object [] { "2", 2, 'c' }, new object [] { new object [] { 1, 2, 3}, null })] + AssertCustomAttribute (".ctor ((Object:(Object[]:{(Object:(String:\"2\")), (Object:(I4:2)), (Object:(Char:'c'))})), (Object:(Object[]:{(Object:(Object[]:{(Object:(I4:1)), (Object:(I4:2)), (Object:(I4:3))})), (Object:(String:null))})))", attribute); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void FieldsAndProperties (ModuleDefinition module) + [Test] + public void FieldsAndProperties () { - var angola = module.GetType ("Angola"); + TestCSharp ("CustomAttributes.cs", module => { + var angola = module.GetType ("Angola"); - var attribute = GetAttribute (angola, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (angola, "Foo"); + Assert.IsNotNull (attribute); - Assert.AreEqual (2, attribute.Fields.Count); + Assert.AreEqual (2, attribute.Fields.Count); - var argument = attribute.Fields.Where (a => a.Name == "Pan").First (); - AssertCustomAttributeArgument ("(Object:(Object[]:{(Object:(I4:1)), (Object:(String:\"2\")), (Object:(Char:'3'))}))", argument); + var argument = attribute.Fields.Where (a => a.Name == "Pan").First (); + AssertCustomAttributeArgument ("(Object:(Object[]:{(Object:(I4:1)), (Object:(String:\"2\")), (Object:(Char:'3'))}))", argument); - argument = attribute.Fields.Where (a => a.Name == "PanPan").First (); - AssertCustomAttributeArgument ("(String[]:{(String:\"yo\"), (String:\"yo\")})", argument); + argument = attribute.Fields.Where (a => a.Name == "PanPan").First (); + AssertCustomAttributeArgument ("(String[]:{(String:\"yo\"), (String:\"yo\")})", argument); - Assert.AreEqual (2, attribute.Properties.Count); + Assert.AreEqual (2, attribute.Properties.Count); - argument = attribute.Properties.Where (a => a.Name == "Bang").First (); - AssertArgument (42, argument); + argument = attribute.Properties.Where (a => a.Name == "Bang").First (); + AssertArgument (42, argument); - argument = attribute.Properties.Where (a => a.Name == "Fiou").First (); - AssertArgument<string> (null, argument); + argument = attribute.Properties.Where (a => a.Name == "Fiou").First (); + AssertArgument<string> (null, argument); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void BoxedStringField (ModuleDefinition module) + [Test] + public void BoxedStringField () { - var type = module.GetType ("BoxedStringField"); + TestCSharp ("CustomAttributes.cs", module => { + var type = module.GetType ("BoxedStringField"); - var attribute = GetAttribute (type, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (type, "Foo"); + Assert.IsNotNull (attribute); - Assert.AreEqual (1, attribute.Fields.Count); + Assert.AreEqual (1, attribute.Fields.Count); - var argument = attribute.Fields.Where (a => a.Name == "Pan").First (); - AssertCustomAttributeArgument ("(Object:(String:\"fiouuu\"))", argument); + var argument = attribute.Fields.Where (a => a.Name == "Pan").First (); + AssertCustomAttributeArgument ("(Object:(String:\"fiouuu\"))", argument); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void TypeDefinitionEnum (ModuleDefinition module) + [Test] + public void TypeDefinitionEnum () { - var zero = module.GetType ("Zero"); + TestCSharp ("CustomAttributes.cs", module => { + var zero = module.GetType ("Zero"); - var attribute = GetAttribute (zero, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (zero, "Foo"); + Assert.IsNotNull (attribute); - Assert.AreEqual (1, attribute.ConstructorArguments.Count); + Assert.AreEqual (1, attribute.ConstructorArguments.Count); - Assert.AreEqual ((short) 2, attribute.ConstructorArguments [0].Value); - Assert.AreEqual ("Bingo", attribute.ConstructorArguments [0].Type.FullName); + Assert.AreEqual ((short) 2, attribute.ConstructorArguments [0].Value); + Assert.AreEqual ("Bingo", attribute.ConstructorArguments [0].Type.FullName); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void TypeReferenceEnum (ModuleDefinition module) + [Test] + public void TypeReferenceEnum () { - var ace = module.GetType ("Ace"); + TestCSharp ("CustomAttributes.cs", module => { + var ace = module.GetType ("Ace"); - var attribute = GetAttribute (ace, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (ace, "Foo"); + Assert.IsNotNull (attribute); - Assert.AreEqual (1, attribute.ConstructorArguments.Count); + Assert.AreEqual (1, attribute.ConstructorArguments.Count); - Assert.AreEqual ((byte) 0x04, attribute.ConstructorArguments [0].Value); - Assert.AreEqual ("System.Security.AccessControl.AceFlags", attribute.ConstructorArguments [0].Type.FullName); - Assert.AreEqual (module, attribute.ConstructorArguments [0].Type.Module); + Assert.AreEqual ((byte) 0x04, attribute.ConstructorArguments [0].Value); + Assert.AreEqual ("System.Security.AccessControl.AceFlags", attribute.ConstructorArguments [0].Type.FullName); + Assert.AreEqual (module, attribute.ConstructorArguments [0].Type.Module); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void BoxedEnumReference (ModuleDefinition module) + [Test] + public void BoxedEnumReference () { - var bzzz = module.GetType ("Bzzz"); + TestCSharp ("CustomAttributes.cs", module => { + var bzzz = module.GetType ("Bzzz"); - var attribute = GetAttribute (bzzz, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (bzzz, "Foo"); + Assert.IsNotNull (attribute); - // [Foo (new object [] { Bingo.Fuel, Bingo.Binga }, null, Pan = System.Security.AccessControl.AceFlags.NoPropagateInherit)] + // [Foo (new object [] { Bingo.Fuel, Bingo.Binga }, null, Pan = System.Security.AccessControl.AceFlags.NoPropagateInherit)] - Assert.AreEqual (2, attribute.ConstructorArguments.Count); + Assert.AreEqual (2, attribute.ConstructorArguments.Count); - var argument = attribute.ConstructorArguments [0]; + var argument = attribute.ConstructorArguments [0]; - AssertCustomAttributeArgument ("(Object:(Object[]:{(Object:(Bingo:2)), (Object:(Bingo:4))}))", argument); + AssertCustomAttributeArgument ("(Object:(Object[]:{(Object:(Bingo:2)), (Object:(Bingo:4))}))", argument); - argument = attribute.ConstructorArguments [1]; + argument = attribute.ConstructorArguments [1]; - AssertCustomAttributeArgument ("(Object:(String:null))", argument); + AssertCustomAttributeArgument ("(Object:(String:null))", argument); - argument = attribute.Fields.Where (a => a.Name == "Pan").First ().Argument; + argument = attribute.Fields.Where (a => a.Name == "Pan").First ().Argument; - AssertCustomAttributeArgument ("(Object:(System.Security.AccessControl.AceFlags:4))", argument); + AssertCustomAttributeArgument ("(Object:(System.Security.AccessControl.AceFlags:4))", argument); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void TypeOfTypeDefinition (ModuleDefinition module) + [Test] + public void TypeOfTypeDefinition () { - var typed = module.GetType ("Typed"); + TestCSharp ("CustomAttributes.cs", module => { + var typed = module.GetType ("Typed"); - var attribute = GetAttribute (typed, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (typed, "Foo"); + Assert.IsNotNull (attribute); - Assert.AreEqual (1, attribute.ConstructorArguments.Count); + Assert.AreEqual (1, attribute.ConstructorArguments.Count); - var argument = attribute.ConstructorArguments [0]; + var argument = attribute.ConstructorArguments [0]; - Assert.AreEqual ("System.Type", argument.Type.FullName); + Assert.AreEqual ("System.Type", argument.Type.FullName); - var type = argument.Value as TypeDefinition; - Assert.IsNotNull (type); + var type = argument.Value as TypeDefinition; + Assert.IsNotNull (type); - Assert.AreEqual ("Bingo", type.FullName); + Assert.AreEqual ("Bingo", type.FullName); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void TypeOfNestedTypeDefinition (ModuleDefinition module) + [Test] + public void TypeOfNestedTypeDefinition () { - var typed = module.GetType ("NestedTyped"); + TestCSharp ("CustomAttributes.cs", module => { + var typed = module.GetType ("NestedTyped"); - var attribute = GetAttribute (typed, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (typed, "Foo"); + Assert.IsNotNull (attribute); - Assert.AreEqual (1, attribute.ConstructorArguments.Count); + Assert.AreEqual (1, attribute.ConstructorArguments.Count); - var argument = attribute.ConstructorArguments [0]; + var argument = attribute.ConstructorArguments [0]; - Assert.AreEqual ("System.Type", argument.Type.FullName); + Assert.AreEqual ("System.Type", argument.Type.FullName); - var type = argument.Value as TypeDefinition; - Assert.IsNotNull (type); + var type = argument.Value as TypeDefinition; + Assert.IsNotNull (type); - Assert.AreEqual ("FooAttribute/Token", type.FullName); + Assert.AreEqual ("FooAttribute/Token", type.FullName); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void FieldTypeOf (ModuleDefinition module) + [Test] + public void FieldTypeOf () { - var truc = module.GetType ("Truc"); + TestCSharp ("CustomAttributes.cs", module => { + var truc = module.GetType ("Truc"); - var attribute = GetAttribute (truc, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (truc, "Foo"); + Assert.IsNotNull (attribute); - var argument = attribute.Fields.Where (a => a.Name == "Chose").First ().Argument; + var argument = attribute.Fields.Where (a => a.Name == "Chose").First ().Argument; - Assert.AreEqual ("System.Type", argument.Type.FullName); + Assert.AreEqual ("System.Type", argument.Type.FullName); - var type = argument.Value as TypeDefinition; - Assert.IsNotNull (type); + var type = argument.Value as TypeDefinition; + Assert.IsNotNull (type); - Assert.AreEqual ("Typed", type.FullName); + Assert.AreEqual ("Typed", type.FullName); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void FieldNullTypeOf (ModuleDefinition module) + [Test] + public void EscapedTypeName () { - var truc = module.GetType ("Machin"); + TestModule ("bug-185.dll", module => { + var foo = module.GetType ("Foo"); + var foo_do = foo.Methods.Where (m => !m.IsConstructor).First (); - var attribute = GetAttribute (truc, "Foo"); - Assert.IsNotNull (attribute); + var attribute = foo_do.CustomAttributes.Where (ca => ca.AttributeType.Name == "AsyncStateMachineAttribute").First (); + + Assert.AreEqual (foo.NestedTypes [0], attribute.ConstructorArguments [0].Value); - var argument = attribute.Fields.Where (a => a.Name == "Chose").First ().Argument; + var function = module.GetType ("Function`1"); - Assert.AreEqual ("System.Type", argument.Type.FullName); + var apply = function.Methods.Where(m => !m.IsConstructor).First (); - Assert.IsNull (argument.Value); + attribute = apply.CustomAttributes.Where (ca => ca.AttributeType.Name == "AsyncStateMachineAttribute").First (); + + Assert.AreEqual (function.NestedTypes [0], attribute.ConstructorArguments [0].Value); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void OpenGenericTypeOf (ModuleDefinition module) + [Test] + public void FieldNullTypeOf () { - var open_generic = module.GetType ("OpenGeneric`2"); - Assert.IsNotNull (open_generic); + TestCSharp ("CustomAttributes.cs", module => { + var truc = module.GetType ("Machin"); - var attribute = GetAttribute (open_generic, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (truc, "Foo"); + Assert.IsNotNull (attribute); - Assert.AreEqual (1, attribute.ConstructorArguments.Count); + var argument = attribute.Fields.Where (a => a.Name == "Chose").First ().Argument; - var argument = attribute.ConstructorArguments [0]; + Assert.AreEqual ("System.Type", argument.Type.FullName); - Assert.AreEqual ("System.Type", argument.Type.FullName); + Assert.IsNull (argument.Value); + }); + } + + [Test] + public void OpenGenericTypeOf () + { + TestCSharp ("CustomAttributes.cs", module => { + var open_generic = module.GetType ("OpenGeneric`2"); + Assert.IsNotNull (open_generic); + + var attribute = GetAttribute (open_generic, "Foo"); + Assert.IsNotNull (attribute); + + Assert.AreEqual (1, attribute.ConstructorArguments.Count); + + var argument = attribute.ConstructorArguments [0]; - var type = argument.Value as TypeReference; - Assert.IsNotNull (type); + Assert.AreEqual ("System.Type", argument.Type.FullName); - Assert.AreEqual ("System.Collections.Generic.Dictionary`2", type.FullName); + var type = argument.Value as TypeReference; + Assert.IsNotNull (type); + + Assert.AreEqual ("System.Collections.Generic.Dictionary`2", type.FullName); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void ClosedGenericTypeOf (ModuleDefinition module) + [Test] + public void ClosedGenericTypeOf () { - var closed_generic = module.GetType ("ClosedGeneric"); - Assert.IsNotNull (closed_generic); + TestCSharp ("CustomAttributes.cs", module => { + var closed_generic = module.GetType ("ClosedGeneric"); + Assert.IsNotNull (closed_generic); - var attribute = GetAttribute (closed_generic, "Foo"); - Assert.IsNotNull (attribute); + var attribute = GetAttribute (closed_generic, "Foo"); + Assert.IsNotNull (attribute); - Assert.AreEqual (1, attribute.ConstructorArguments.Count); + Assert.AreEqual (1, attribute.ConstructorArguments.Count); - var argument = attribute.ConstructorArguments [0]; + var argument = attribute.ConstructorArguments [0]; - Assert.AreEqual ("System.Type", argument.Type.FullName); + Assert.AreEqual ("System.Type", argument.Type.FullName); - var type = argument.Value as TypeReference; - Assert.IsNotNull (type); + var type = argument.Value as TypeReference; + Assert.IsNotNull (type); - Assert.AreEqual ("System.Collections.Generic.Dictionary`2<System.String,OpenGeneric`2<Machin,System.Int32>[,]>", type.FullName); + Assert.AreEqual ("System.Collections.Generic.Dictionary`2<System.String,OpenGeneric`2<Machin,System.Int32>[,]>", type.FullName); + }); + } + + [Test] + public void EmptyBlob () + { + TestIL ("types.il", module => { + var attribute = module.GetType ("CustomAttribute"); + Assert.AreEqual (1, attribute.CustomAttributes.Count); + Assert.AreEqual (0, attribute.CustomAttributes [0].ConstructorArguments.Count); + }); } [Test] @@ -348,7 +417,7 @@ namespace Mono.Cecil.Tests { var file = Path.Combine (Path.GetTempPath (), "CaBlob.dll"); var module = ModuleDefinition.CreateModule ("CaBlob.dll", new ModuleParameters { Kind = ModuleKind.Dll, Runtime = TargetRuntime.Net_2_0 }); - var assembly_title_ctor = module.Import (typeof (System.Reflection.AssemblyTitleAttribute).GetConstructor (new [] {typeof (string)})); + var assembly_title_ctor = module.ImportReference (typeof (System.Reflection.AssemblyTitleAttribute).GetConstructor (new [] {typeof (string)})); Assert.IsNotNull (assembly_title_ctor); diff --git a/Test/Mono.Cecil.Tests/EventTests.cs b/Test/Mono.Cecil.Tests/EventTests.cs index 15a599c..cb9064b 100644 --- a/Test/Mono.Cecil.Tests/EventTests.cs +++ b/Test/Mono.Cecil.Tests/EventTests.cs @@ -10,57 +10,70 @@ namespace Mono.Cecil.Tests { [TestFixture] public class EventTests : BaseTestFixture { - [TestCSharp ("Events.cs")] - public void AbstractMethod (ModuleDefinition module) + [Test] + public void AbstractMethod () { - var type = module.GetType ("Foo"); + TestCSharp ("Events.cs", module => { + var type = module.GetType ("Foo"); - Assert.IsTrue (type.HasEvents); + Assert.IsTrue (type.HasEvents); - var events = type.Events; + var events = type.Events; - Assert.AreEqual (1, events.Count); + Assert.AreEqual (1, events.Count); - var @event = events [0]; + var @event = events [0]; - Assert.IsNotNull (@event); - Assert.AreEqual ("Bar", @event.Name); - Assert.IsNotNull (@event.EventType); - Assert.AreEqual ("Pan", @event.EventType.FullName); + Assert.IsNotNull (@event); + Assert.AreEqual ("Bar", @event.Name); + Assert.IsNotNull (@event.EventType); + Assert.AreEqual ("Pan", @event.EventType.FullName); - Assert.IsNotNull (@event.AddMethod); - Assert.AreEqual (MethodSemanticsAttributes.AddOn, @event.AddMethod.SemanticsAttributes); - Assert.IsNotNull (@event.RemoveMethod); - Assert.AreEqual (MethodSemanticsAttributes.RemoveOn, @event.RemoveMethod.SemanticsAttributes); + Assert.IsNotNull (@event.AddMethod); + Assert.AreEqual (MethodSemanticsAttributes.AddOn, @event.AddMethod.SemanticsAttributes); + Assert.IsNotNull (@event.RemoveMethod); + Assert.AreEqual (MethodSemanticsAttributes.RemoveOn, @event.RemoveMethod.SemanticsAttributes); + }); } - [TestIL ("others.il")] - public void OtherMethod (ModuleDefinition module) + [Test] + public void OtherMethod () { - var type = module.GetType ("Others"); + TestIL ("others.il", module => { + var type = module.GetType ("Others"); - Assert.IsTrue (type.HasEvents); + Assert.IsTrue (type.HasEvents); - var events = type.Events; + var events = type.Events; - Assert.AreEqual (1, events.Count); + Assert.AreEqual (1, events.Count); - var @event = events [0]; + var @event = events [0]; - Assert.IsNotNull (@event); - Assert.AreEqual ("Handler", @event.Name); - Assert.IsNotNull (@event.EventType); - Assert.AreEqual ("System.EventHandler", @event.EventType.FullName); + Assert.IsNotNull (@event); + Assert.AreEqual ("Handler", @event.Name); + Assert.IsNotNull (@event.EventType); + Assert.AreEqual ("System.EventHandler", @event.EventType.FullName); - Assert.IsTrue (@event.HasOtherMethods); + Assert.IsTrue (@event.HasOtherMethods); - Assert.AreEqual (2, @event.OtherMethods.Count); + Assert.AreEqual (2, @event.OtherMethods.Count); - var other = @event.OtherMethods [0]; - Assert.AreEqual ("dang_Handler", other.Name); + var other = @event.OtherMethods [0]; + Assert.AreEqual ("dang_Handler", other.Name); - other = @event.OtherMethods [1]; - Assert.AreEqual ("fang_Handler", other.Name); + other = @event.OtherMethods [1]; + Assert.AreEqual ("fang_Handler", other.Name); + }); + } + + [Test] + public void UnattachedEvent () + { + var int32 = typeof (int).ToDefinition (); + var evt = new EventDefinition ("Event", EventAttributes.None, int32); + + Assert.AreEqual (null, evt.AddMethod); } } } diff --git a/Test/Mono.Cecil.Tests/FieldTests.cs b/Test/Mono.Cecil.Tests/FieldTests.cs index 8c63456..05165d6 100644 --- a/Test/Mono.Cecil.Tests/FieldTests.cs +++ b/Test/Mono.Cecil.Tests/FieldTests.cs @@ -1,7 +1,5 @@ using System; -using Mono.Cecil; -using Mono.Cecil.Metadata; using Mono.Cecil.PE; using NUnit.Framework; @@ -11,306 +9,347 @@ namespace Mono.Cecil.Tests { [TestFixture] public class FieldTests : BaseTestFixture { - [TestCSharp ("Fields.cs")] - public void TypeDefField (ModuleDefinition module) + [Test] + public void TypeDefField () { - var type = module.Types [1]; - Assert.AreEqual ("Foo", type.Name); - Assert.AreEqual (1, type.Fields.Count); - - var field = type.Fields [0]; - Assert.AreEqual ("bar", field.Name); - Assert.AreEqual (1, field.MetadataToken.RID); - Assert.IsNotNull (field.FieldType); - Assert.AreEqual ("Bar", field.FieldType.FullName); - Assert.AreEqual (TokenType.Field, field.MetadataToken.TokenType); - Assert.IsFalse (field.HasConstant); - Assert.IsNull (field.Constant); + TestCSharp ("Fields.cs", module => { + var type = module.Types [1]; + Assert.AreEqual ("Foo", type.Name); + Assert.AreEqual (1, type.Fields.Count); + + var field = type.Fields [0]; + Assert.AreEqual ("bar", field.Name); + Assert.AreEqual (1, field.MetadataToken.RID); + Assert.IsNotNull (field.FieldType); + Assert.AreEqual ("Bar", field.FieldType.FullName); + Assert.AreEqual (TokenType.Field, field.MetadataToken.TokenType); + Assert.IsFalse (field.HasConstant); + Assert.IsNull (field.Constant); + }); } - [TestCSharp ("Fields.cs")] - public void PrimitiveTypes (ModuleDefinition module) + [Test] + public void PrimitiveTypes () { - var type = module.GetType ("Baz"); - - AssertField (type, "char", typeof (char)); - AssertField (type, "bool", typeof (bool)); - AssertField (type, "sbyte", typeof (sbyte)); - AssertField (type, "byte", typeof (byte)); - AssertField (type, "int16", typeof (short)); - AssertField (type, "uint16", typeof (ushort)); - AssertField (type, "int32", typeof (int)); - AssertField (type, "uint32", typeof (uint)); - AssertField (type, "int64", typeof (long)); - AssertField (type, "uint64", typeof (ulong)); - AssertField (type, "single", typeof (float)); - AssertField (type, "double", typeof (double)); - AssertField (type, "string", typeof (string)); - AssertField (type, "object", typeof (object)); + TestCSharp ("Fields.cs", module => { + var type = module.GetType ("Baz"); + + AssertField (type, "char", typeof (char)); + AssertField (type, "bool", typeof (bool)); + AssertField (type, "sbyte", typeof (sbyte)); + AssertField (type, "byte", typeof (byte)); + AssertField (type, "int16", typeof (short)); + AssertField (type, "uint16", typeof (ushort)); + AssertField (type, "int32", typeof (int)); + AssertField (type, "uint32", typeof (uint)); + AssertField (type, "int64", typeof (long)); + AssertField (type, "uint64", typeof (ulong)); + AssertField (type, "single", typeof (float)); + AssertField (type, "double", typeof (double)); + AssertField (type, "string", typeof (string)); + AssertField (type, "object", typeof (object)); + }); } - [TestCSharp ("Fields.cs")] - public void VolatileField (ModuleDefinition module) + [Test] + public void VolatileField () { - var type = module.GetType ("Bar"); + TestCSharp ("Fields.cs", module => { + var type = module.GetType ("Bar"); - Assert.IsTrue (type.HasFields); - Assert.AreEqual (1, type.Fields.Count); + Assert.IsTrue (type.HasFields); + Assert.AreEqual (1, type.Fields.Count); - var field = type.Fields [0]; + var field = type.Fields [0]; - Assert.AreEqual ("oiseau", field.Name); - Assert.AreEqual ("System.Int32 modreq(System.Runtime.CompilerServices.IsVolatile)", field.FieldType.FullName); + Assert.AreEqual ("oiseau", field.Name); + Assert.AreEqual ("System.Int32 modreq(System.Runtime.CompilerServices.IsVolatile)", field.FieldType.FullName); - Assert.IsFalse (field.HasConstant); + Assert.IsFalse (field.HasConstant); + }); } - [TestCSharp ("Layouts.cs")] - public void FieldLayout (ModuleDefinition module) + [Test] + public void FieldLayout () { - var foo = module.GetType ("Foo"); - Assert.IsNotNull (foo); + TestCSharp ("Layouts.cs", module => { + var foo = module.GetType ("Foo"); + Assert.IsNotNull (foo); - Assert.IsTrue (foo.HasFields); + Assert.IsTrue (foo.HasFields); - var fields = foo.Fields; + var fields = foo.Fields; - var field = fields [0]; + var field = fields [0]; - Assert.AreEqual ("Bar", field.Name); - Assert.IsTrue (field.HasLayoutInfo); - Assert.AreEqual (0, field.Offset); + Assert.AreEqual ("Bar", field.Name); + Assert.IsTrue (field.HasLayoutInfo); + Assert.AreEqual (0, field.Offset); - field = fields [1]; + field = fields [1]; - Assert.AreEqual ("Baz", field.Name); - Assert.IsTrue (field.HasLayoutInfo); - Assert.AreEqual (2, field.Offset); + Assert.AreEqual ("Baz", field.Name); + Assert.IsTrue (field.HasLayoutInfo); + Assert.AreEqual (2, field.Offset); - field = fields [2]; + field = fields [2]; - Assert.AreEqual ("Gazonk", field.Name); - Assert.IsTrue (field.HasLayoutInfo); - Assert.AreEqual (4, field.Offset); + Assert.AreEqual ("Gazonk", field.Name); + Assert.IsTrue (field.HasLayoutInfo); + Assert.AreEqual (4, field.Offset); + }); } - [TestCSharp ("Layouts.cs")] - public void FieldRVA (ModuleDefinition module) + [Test] + public void FieldRVA () { - var priv_impl = GetPrivateImplementationType (module); - Assert.IsNotNull (priv_impl); + TestCSharp ("Layouts.cs", module => { + var priv_impl = GetPrivateImplementationType (module); + Assert.IsNotNull (priv_impl); - Assert.AreEqual (1, priv_impl.Fields.Count); + Assert.AreEqual (1, priv_impl.Fields.Count); - var field = priv_impl.Fields [0]; + var field = priv_impl.Fields [0]; - Assert.IsNotNull (field); - Assert.AreNotEqual (0, field.RVA); - Assert.IsNotNull (field.InitialValue); - Assert.AreEqual (16, field.InitialValue.Length); + Assert.IsNotNull (field); + Assert.AreNotEqual (0, field.RVA); + Assert.IsNotNull (field.InitialValue); + Assert.AreEqual (16, field.InitialValue.Length); - var buffer = new ByteBuffer (field.InitialValue); + var buffer = new ByteBuffer (field.InitialValue); - Assert.AreEqual (1, buffer.ReadUInt32 ()); - Assert.AreEqual (2, buffer.ReadUInt32 ()); - Assert.AreEqual (3, buffer.ReadUInt32 ()); - Assert.AreEqual (4, buffer.ReadUInt32 ()); + Assert.AreEqual (1, buffer.ReadUInt32 ()); + Assert.AreEqual (2, buffer.ReadUInt32 ()); + Assert.AreEqual (3, buffer.ReadUInt32 ()); + Assert.AreEqual (4, buffer.ReadUInt32 ()); + }); } - [TestCSharp ("Generics.cs")] - public void GenericFieldDefinition (ModuleDefinition module) + [Test] + public void GenericFieldDefinition () { - var bar = module.GetType ("Bar`1"); - Assert.IsNotNull (bar); + TestCSharp ("Generics.cs", module => { + var bar = module.GetType ("Bar`1"); + Assert.IsNotNull (bar); - Assert.IsTrue (bar.HasGenericParameters); - var t = bar.GenericParameters [0]; + Assert.IsTrue (bar.HasGenericParameters); + var t = bar.GenericParameters [0]; - Assert.AreEqual ("T", t.Name); - Assert.AreEqual (t.Owner, bar); + Assert.AreEqual ("T", t.Name); + Assert.AreEqual (t.Owner, bar); - var bang = bar.GetField ("bang"); + var bang = bar.GetField ("bang"); - Assert.IsNotNull (bang); + Assert.IsNotNull (bang); - Assert.AreEqual (t, bang.FieldType); + Assert.AreEqual (t, bang.FieldType); + }); } - [TestIL ("types.il")] - public void ArrayFields (ModuleDefinition module) + [Test] + public void ArrayFields () { - var types = module.GetType ("Types"); - Assert.IsNotNull (types); + TestIL ("types.il", module => { + var types = module.GetType ("Types"); + Assert.IsNotNull (types); - var rank_two = types.GetField ("rank_two"); + var rank_two = types.GetField ("rank_two"); - var array = rank_two.FieldType as ArrayType; - Assert.IsNotNull (array); + var array = rank_two.FieldType as ArrayType; + Assert.IsNotNull (array); - Assert.AreEqual (2, array.Rank); - Assert.IsFalse (array.Dimensions [0].IsSized); - Assert.IsFalse (array.Dimensions [1].IsSized); + Assert.AreEqual (2, array.Rank); + Assert.IsFalse (array.Dimensions [0].IsSized); + Assert.IsFalse (array.Dimensions [1].IsSized); - var rank_two_low_bound_zero = types.GetField ("rank_two_low_bound_zero"); + var rank_two_low_bound_zero = types.GetField ("rank_two_low_bound_zero"); - array = rank_two_low_bound_zero.FieldType as ArrayType; - Assert.IsNotNull (array); + array = rank_two_low_bound_zero.FieldType as ArrayType; + Assert.IsNotNull (array); - Assert.AreEqual (2, array.Rank); - Assert.IsTrue (array.Dimensions [0].IsSized); - Assert.AreEqual (0, array.Dimensions [0].LowerBound); - Assert.AreEqual (null, array.Dimensions [0].UpperBound); - Assert.IsTrue (array.Dimensions [1].IsSized); - Assert.AreEqual (0, array.Dimensions [1].LowerBound); - Assert.AreEqual (null, array.Dimensions [1].UpperBound); + Assert.AreEqual (2, array.Rank); + Assert.IsTrue (array.Dimensions [0].IsSized); + Assert.AreEqual (0, array.Dimensions [0].LowerBound); + Assert.AreEqual (null, array.Dimensions [0].UpperBound); + Assert.IsTrue (array.Dimensions [1].IsSized); + Assert.AreEqual (0, array.Dimensions [1].LowerBound); + Assert.AreEqual (null, array.Dimensions [1].UpperBound); - var rank_one_low_bound_m1 = types.GetField ("rank_one_low_bound_m1"); - array = rank_one_low_bound_m1.FieldType as ArrayType; - Assert.IsNotNull (array); + var rank_one_low_bound_m1 = types.GetField ("rank_one_low_bound_m1"); + array = rank_one_low_bound_m1.FieldType as ArrayType; + Assert.IsNotNull (array); - Assert.AreEqual (1, array.Rank); - Assert.IsTrue (array.Dimensions [0].IsSized); - Assert.AreEqual (-1, array.Dimensions [0].LowerBound); - Assert.AreEqual (4, array.Dimensions [0].UpperBound); + Assert.AreEqual (1, array.Rank); + Assert.IsTrue (array.Dimensions [0].IsSized); + Assert.AreEqual (-1, array.Dimensions [0].LowerBound); + Assert.AreEqual (4, array.Dimensions [0].UpperBound); + }); } - [TestCSharp ("Fields.cs")] - public void EnumFieldsConstant (ModuleDefinition module) + [Test] + public void EnumFieldsConstant () { - var pim = module.GetType ("Pim"); - Assert.IsNotNull (pim); + TestCSharp ("Fields.cs", module => { + var pim = module.GetType ("Pim"); + Assert.IsNotNull (pim); - var field = pim.GetField ("Pam"); - Assert.IsTrue (field.HasConstant); - Assert.AreEqual (1, (int) field.Constant); + var field = pim.GetField ("Pam"); + Assert.IsTrue (field.HasConstant); + Assert.AreEqual (1, (int) field.Constant); - field = pim.GetField ("Poum"); - Assert.AreEqual (2, (int) field.Constant); + field = pim.GetField ("Poum"); + Assert.AreEqual (2, (int) field.Constant); + }); } - [TestCSharp ("Fields.cs")] - public void StringAndClassConstant (ModuleDefinition module) + [Test] + public void StringAndClassConstant () { - var panpan = module.GetType ("PanPan"); - Assert.IsNotNull (panpan); + TestCSharp ("Fields.cs", module => { + var panpan = module.GetType ("PanPan"); + Assert.IsNotNull (panpan); - var field = panpan.GetField ("Peter"); - Assert.IsTrue (field.HasConstant); - Assert.IsNull (field.Constant); + var field = panpan.GetField ("Peter"); + Assert.IsTrue (field.HasConstant); + Assert.IsNull (field.Constant); - field = panpan.GetField ("QQ"); - Assert.AreEqual ("qq", (string) field.Constant); + field = panpan.GetField ("QQ"); + Assert.AreEqual ("qq", (string) field.Constant); - field = panpan.GetField ("nil"); - Assert.AreEqual (null, (string) field.Constant); + field = panpan.GetField ("nil"); + Assert.AreEqual (null, (string) field.Constant); + }); } - [TestCSharp ("Fields.cs")] - public void ObjectConstant (ModuleDefinition module) + [Test] + public void ObjectConstant () { - var panpan = module.GetType ("PanPan"); - Assert.IsNotNull (panpan); - - var field = panpan.GetField ("obj"); - Assert.IsTrue (field.HasConstant); - Assert.IsNull (field.Constant); + TestCSharp ("Fields.cs", module => { + var panpan = module.GetType ("PanPan"); + Assert.IsNotNull (panpan); + + var field = panpan.GetField ("obj"); + Assert.IsTrue (field.HasConstant); + Assert.IsNull (field.Constant); + }); } - [TestIL ("types.il")] - public void NullPrimitiveConstant (ModuleDefinition module) + [Test] + public void NullPrimitiveConstant () { - var fields = module.GetType ("Fields"); + TestIL ("types.il", module => { + var fields = module.GetType ("Fields"); - var field = fields.GetField ("int32_nullref"); - Assert.IsTrue (field.HasConstant); - Assert.AreEqual (null, field.Constant); + var field = fields.GetField ("int32_nullref"); + Assert.IsTrue (field.HasConstant); + Assert.AreEqual (null, field.Constant); + }); } - [TestCSharp ("Fields.cs")] - public void ArrayConstant (ModuleDefinition module) + [Test] + public void ArrayConstant () { - var panpan = module.GetType ("PanPan"); - Assert.IsNotNull (panpan); - - var field = panpan.GetField ("ints"); - Assert.IsTrue (field.HasConstant); - Assert.IsNull (field.Constant); + TestCSharp ("Fields.cs", module => { + var panpan = module.GetType ("PanPan"); + Assert.IsNotNull (panpan); + + var field = panpan.GetField ("ints"); + Assert.IsTrue (field.HasConstant); + Assert.IsNull (field.Constant); + }); } - [TestIL ("types.il")] - public void ConstantCoalescing (ModuleDefinition module) + [Test] + public void ConstantCoalescing () { - var fields = module.GetType ("Fields"); - - var field = fields.GetField ("int32_int16"); - Assert.AreEqual ("System.Int32", field.FieldType.FullName); - Assert.IsTrue (field.HasConstant); - Assert.IsInstanceOf (typeof (short), field.Constant); - Assert.AreEqual ((short) 1, field.Constant); - - field = fields.GetField ("int16_int32"); - Assert.AreEqual ("System.Int16", field.FieldType.FullName); - Assert.IsTrue (field.HasConstant); - Assert.IsInstanceOf (typeof (int), field.Constant); - Assert.AreEqual (1, field.Constant); - - field = fields.GetField ("char_int16"); - Assert.AreEqual ("System.Char", field.FieldType.FullName); - Assert.IsTrue (field.HasConstant); - Assert.IsInstanceOf (typeof (short), field.Constant); - Assert.AreEqual ((short) 1, field.Constant); - - field = fields.GetField ("int16_char"); - Assert.AreEqual ("System.Int16", field.FieldType.FullName); - Assert.IsTrue (field.HasConstant); - Assert.IsInstanceOf (typeof (char), field.Constant); - Assert.AreEqual ('s', field.Constant); + TestIL ("types.il", module => { + var fields = module.GetType ("Fields"); + + var field = fields.GetField ("int32_int16"); + Assert.AreEqual ("System.Int32", field.FieldType.FullName); + Assert.IsTrue (field.HasConstant); + Assert.IsInstanceOf (typeof (short), field.Constant); + Assert.AreEqual ((short) 1, field.Constant); + + field = fields.GetField ("int16_int32"); + Assert.AreEqual ("System.Int16", field.FieldType.FullName); + Assert.IsTrue (field.HasConstant); + Assert.IsInstanceOf (typeof (int), field.Constant); + Assert.AreEqual (1, field.Constant); + + field = fields.GetField ("char_int16"); + Assert.AreEqual ("System.Char", field.FieldType.FullName); + Assert.IsTrue (field.HasConstant); + Assert.IsInstanceOf (typeof (short), field.Constant); + Assert.AreEqual ((short) 1, field.Constant); + + field = fields.GetField ("int16_char"); + Assert.AreEqual ("System.Int16", field.FieldType.FullName); + Assert.IsTrue (field.HasConstant); + Assert.IsInstanceOf (typeof (char), field.Constant); + Assert.AreEqual ('s', field.Constant); + }); } - [TestCSharp ("Generics.cs")] - public void NestedEnumOfGenericTypeDefinition (ModuleDefinition module) + [Test] + public void NestedEnumOfGenericTypeDefinition () { - var dang = module.GetType ("Bongo`1/Dang"); - Assert.IsNotNull (dang); - - var field = dang.GetField ("Ding"); - Assert.IsNotNull (field); - Assert.AreEqual (2, field.Constant); - - field = dang.GetField ("Dong"); - Assert.IsNotNull (field); - Assert.AreEqual (12, field.Constant); + TestCSharp ("Generics.cs", module => { + var dang = module.GetType ("Bongo`1/Dang"); + Assert.IsNotNull (dang); + + var field = dang.GetField ("Ding"); + Assert.IsNotNull (field); + Assert.AreEqual (2, field.Constant); + + field = dang.GetField ("Dong"); + Assert.IsNotNull (field); + Assert.AreEqual (12, field.Constant); + }); } - [TestModule ("marshal.dll")] - public void MarshalAsFixedStr (ModuleDefinition module) + [Test] + public void MarshalAsFixedStr () { - var boc = module.GetType ("Boc"); - var field = boc.GetField ("a"); + TestModule ("marshal.dll", module => { + var boc = module.GetType ("Boc"); + var field = boc.GetField ("a"); - Assert.IsNotNull (field); + Assert.IsNotNull (field); - Assert.IsTrue (field.HasMarshalInfo); + Assert.IsTrue (field.HasMarshalInfo); - var info = (FixedSysStringMarshalInfo) field.MarshalInfo; + var info = (FixedSysStringMarshalInfo) field.MarshalInfo; - Assert.AreEqual (42, info.Size); + Assert.AreEqual (42, info.Size); + }); } - [TestModule ("marshal.dll")] - public void MarshalAsFixedArray (ModuleDefinition module) + [Test] + public void MarshalAsFixedArray () { - var boc = module.GetType ("Boc"); - var field = boc.GetField ("b"); + TestModule ("marshal.dll", module => { + var boc = module.GetType ("Boc"); + var field = boc.GetField ("b"); + + Assert.IsNotNull (field); + + Assert.IsTrue (field.HasMarshalInfo); - Assert.IsNotNull (field); + var info = (FixedArrayMarshalInfo) field.MarshalInfo; - Assert.IsTrue (field.HasMarshalInfo); + Assert.AreEqual (12, info.Size); + Assert.AreEqual (NativeType.Boolean, info.ElementType); + }); + } - var info = (FixedArrayMarshalInfo) field.MarshalInfo; + [Test] + public void UnattachedField () + { + var field = new FieldDefinition ("Field", FieldAttributes.Public, typeof (int).ToDefinition ()); - Assert.AreEqual (12, info.Size); - Assert.AreEqual (NativeType.Boolean, info.ElementType); + Assert.IsFalse (field.HasConstant); + Assert.IsNull (field.Constant); } static TypeDefinition GetPrivateImplementationType (ModuleDefinition module) diff --git a/Test/Mono.Cecil.Tests/ImageReadTests.cs b/Test/Mono.Cecil.Tests/ImageReadTests.cs index f2db8b1..4f737c4 100644 --- a/Test/Mono.Cecil.Tests/ImageReadTests.cs +++ b/Test/Mono.Cecil.Tests/ImageReadTests.cs @@ -27,10 +27,10 @@ namespace Mono.Cecil.Tests { public void ImageMetadataVersion () { using (var image = GetResourceImage ("hello.exe")) - Assert.AreEqual (TargetRuntime.Net_2_0, image.Runtime); + Assert.AreEqual (TargetRuntime.Net_2_0, image.RuntimeVersion.ParseRuntime ()); using (var image = GetResourceImage ("hello1.exe")) - Assert.AreEqual (TargetRuntime.Net_1_1, image.Runtime); + Assert.AreEqual (TargetRuntime.Net_1_1, image.RuntimeVersion.ParseRuntime ()); } [Test] @@ -90,40 +90,79 @@ namespace Mono.Cecil.Tests { } [Test] - public void ReadX64Image () + public void X64Module () { - using (var image = GetResourceImage ("hello.x64.exe")) { + TestModule ("hello.x64.exe", module => { + Assert.AreEqual (TargetArchitecture.AMD64, module.Image.Architecture); + Assert.AreEqual (ModuleAttributes.ILOnly, module.Image.Attributes); + }, verify: !Platform.OnMono); + } - Assert.AreEqual (TargetArchitecture.AMD64, image.Architecture); - Assert.AreEqual (ModuleAttributes.ILOnly, image.Attributes); - } + [Test] + public void X64ModuleTextOnlySection () + { + TestModule ("hello.textonly.x64.exe", module => { + Assert.AreEqual (TargetArchitecture.AMD64, module.Image.Architecture); + Assert.AreEqual (ModuleAttributes.ILOnly, module.Image.Attributes); + }, verify: !Platform.OnMono); } [Test] - public void ReadIA64Image () + public void IA64Module () { - using (var image = GetResourceImage ("hello.ia64.exe")) { - Assert.AreEqual (TargetArchitecture.IA64, image.Architecture); - Assert.AreEqual (ModuleAttributes.ILOnly, image.Attributes); - } + TestModule ("hello.ia64.exe", module => { + Assert.AreEqual (TargetArchitecture.IA64, module.Image.Architecture); + Assert.AreEqual (ModuleAttributes.ILOnly, module.Image.Attributes); + }, verify: !Platform.OnMono); } [Test] - public void ReadX86Image () + public void X86Module () { - using (var image = GetResourceImage ("hello.x86.exe")) { - Assert.AreEqual (TargetArchitecture.I386, image.Architecture); - Assert.AreEqual (ModuleAttributes.ILOnly | ModuleAttributes.Required32Bit, image.Attributes); - } + TestModule ("hello.x86.exe", module => { + Assert.AreEqual (TargetArchitecture.I386, module.Image.Architecture); + Assert.AreEqual (ModuleAttributes.ILOnly | ModuleAttributes.Required32Bit, module.Image.Attributes); + }); } [Test] - public void ReadAnyCpuImage () + public void AnyCpuModule () { - using (var image = GetResourceImage ("hello.anycpu.exe")) { - Assert.AreEqual (TargetArchitecture.I386, image.Architecture); - Assert.AreEqual (ModuleAttributes.ILOnly, image.Attributes); - } + TestModule ("hello.anycpu.exe", module => { + Assert.AreEqual (TargetArchitecture.I386, module.Image.Architecture); + Assert.AreEqual (ModuleAttributes.ILOnly, module.Image.Attributes); + }); + } + + [Test] + public void DelaySignedAssembly () + { + TestModule ("delay-signed.dll", module => { + Assert.IsNotNull (module.Assembly.Name.PublicKey); + Assert.AreNotEqual (0, module.Assembly.Name.PublicKey.Length); + Assert.AreNotEqual (ModuleAttributes.StrongNameSigned, module.Attributes & ModuleAttributes.StrongNameSigned); + Assert.AreNotEqual (0, module.Image.StrongName.VirtualAddress); + Assert.AreNotEqual (0, module.Image.StrongName.Size); + }); + } + + [Test] + public void WindowsPhoneNonSignedAssembly () + { + TestModule ("wp7.dll", module => { + Assert.AreEqual (0, module.Assembly.Name.PublicKey.Length); + Assert.AreNotEqual (ModuleAttributes.StrongNameSigned, module.Attributes & ModuleAttributes.StrongNameSigned); + Assert.AreEqual (0, module.Image.StrongName.VirtualAddress); + Assert.AreEqual (0, module.Image.StrongName.Size); + }, verify: false); + } + + [Test] + public void MetroAssembly () + { + TestModule ("metro.exe", module => { + Assert.AreEqual (ModuleCharacteristics.AppContainer, module.Characteristics & ModuleCharacteristics.AppContainer); + }, verify: false, readOnly: Platform.OnMono); } } } diff --git a/Test/Mono.Cecil.Tests/ImportCecilTests.cs b/Test/Mono.Cecil.Tests/ImportCecilTests.cs index 7554863..299948f 100644 --- a/Test/Mono.Cecil.Tests/ImportCecilTests.cs +++ b/Test/Mono.Cecil.Tests/ImportCecilTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; @@ -28,10 +29,10 @@ namespace Mono.Cecil.Tests { type.Methods.Add (method_by_ref); - method_by_ref.MethodReturnType.ReturnType = module.Import (typeof (void).ToDefinition ()); + method_by_ref.MethodReturnType.ReturnType = module.ImportReference (typeof (void).ToDefinition ()); - method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (typeof (string).ToDefinition ()))); - method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (new ByReferenceType (typeof (string).ToDefinition ())))); + method_by_ref.Parameters.Add (new ParameterDefinition (module.ImportReference (typeof (string).ToDefinition ()))); + method_by_ref.Parameters.Add (new ParameterDefinition (module.ImportReference (new ByReferenceType (typeof (string).ToDefinition ())))); var m_il = method_by_ref.Body.GetILProcessor (); m_il.Emit (OpCodes.Ldarg_1); @@ -39,7 +40,7 @@ namespace Mono.Cecil.Tests { m_il.Emit (OpCodes.Stind_Ref); m_il.Emit (OpCodes.Ret); - var v_0 = new VariableDefinition (module.Import (typeof (string).ToDefinition ())); + var v_0 = new VariableDefinition (module.ImportReference (typeof (string).ToDefinition ())); body.Variables.Add (v_0); var il = body.GetILProcessor (); @@ -74,7 +75,7 @@ namespace Mono.Cecil.Tests { { var get_empty = Compile<Func<string>> ((module, body) => { var il = body.GetILProcessor (); - il.Emit (OpCodes.Ldsfld, module.Import (typeof (string).GetField ("Empty").ToDefinition ())); + il.Emit (OpCodes.Ldsfld, module.ImportReference (typeof (string).GetField ("Empty").ToDefinition ())); il.Emit (OpCodes.Ret); }); @@ -88,7 +89,7 @@ namespace Mono.Cecil.Tests { var il = body.GetILProcessor (); il.Emit (OpCodes.Ldarg_0); il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Call, module.Import (typeof (string).GetMethod ("Concat", new [] { typeof (string), typeof (string) }).ToDefinition ())); + il.Emit (OpCodes.Call, module.ImportReference (typeof (string).GetMethod ("Concat", new [] { typeof (string), typeof (string) }).ToDefinition ())); il.Emit (OpCodes.Ret); }); @@ -118,12 +119,12 @@ namespace Mono.Cecil.Tests { public void ImportGenericField () { var get_field = Compile<Func<Generic<string>, string>> ((module, body) => { - var generic_def = module.Import (typeof (Generic<>)).Resolve (); + var generic_def = module.ImportReference (typeof (Generic<>)).Resolve (); var field_def = generic_def.Fields.Where (f => f.Name == "Field").First (); - var field_string = field_def.MakeGeneric (module.Import (typeof (string))); + var field_string = field_def.MakeGeneric (module.ImportReference (typeof (string))); - var field_ref = module.Import (field_string); + var field_ref = module.ImportReference (field_string); var il = body.GetILProcessor (); il.Emit (OpCodes.Ldarg_0); @@ -142,11 +143,11 @@ namespace Mono.Cecil.Tests { public void ImportGenericMethod () { var generic_identity = Compile<Func<Generic<int>, int, int>> ((module, body) => { - var generic_def = module.Import (typeof (Generic<>)).Resolve (); + var generic_def = module.ImportReference (typeof (Generic<>)).Resolve (); var method_def = generic_def.Methods.Where (m => m.Name == "Method").First (); - var method_int = method_def.MakeGeneric (module.Import (typeof (int))); - var method_ref = module.Import (method_int); + var method_int = method_def.MakeGeneric (module.ImportReference (typeof (int))); + var method_ref = module.ImportReference (method_int); var il = body.GetILProcessor (); il.Emit (OpCodes.Ldarg_0); @@ -162,14 +163,14 @@ namespace Mono.Cecil.Tests { public void ImportGenericMethodSpec () { var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => { - var generic_def = module.Import (typeof (Generic<>)).Resolve (); + var generic_def = module.ImportReference (typeof (Generic<>)).Resolve (); var method_def = generic_def.Methods.Where (m => m.Name == "GenericMethod").First (); - var method_string = method_def.MakeGeneric (module.Import (typeof (string))); + var method_string = method_def.MakeGeneric (module.ImportReference (typeof (string))); - var method_instance = method_string.MakeGenericMethod (module.Import (typeof (int))); + var method_instance = method_string.MakeGenericMethod (module.ImportReference (typeof (int))); - var method_ref = module.Import (method_instance); + var method_ref = module.ImportReference (method_instance); var il = body.GetILProcessor (); il.Emit (OpCodes.Ldarg_0); @@ -186,16 +187,16 @@ namespace Mono.Cecil.Tests { public void ImportComplexGenericMethodSpec () { var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => { - var generic_def = module.Import (typeof (Generic<>)).Resolve (); + var generic_def = module.ImportReference (typeof (Generic<>)).Resolve (); var method_def = generic_def.Methods.Where (m => m.Name == "ComplexGenericMethod").First (); - var method_string = method_def.MakeGeneric (module.Import (typeof (string))); - var method_instance = method_string.MakeGenericMethod (module.Import (typeof (int))); - var method_ref = module.Import (method_instance); + var method_string = method_def.MakeGeneric (module.ImportReference (typeof (string))); + var method_instance = method_string.MakeGenericMethod (module.ImportReference (typeof (int))); + var method_ref = module.ImportReference (method_instance); var field_def = generic_def.Fields.Where (f => f.Name == "Field").First (); - var field_int = field_def.MakeGeneric (module.Import (typeof (int))); - var field_ref = module.Import (field_int); + var field_int = field_def.MakeGeneric (module.ImportReference (typeof (int))); + var field_ref = module.ImportReference (field_int); var il = body.GetILProcessor (); il.Emit (OpCodes.Ldarg_0); @@ -213,12 +214,76 @@ namespace Mono.Cecil.Tests { public void ImportMethodOnOpenGeneric () { var generic = typeof (Generic<>).ToDefinition (); + using (var module = ModuleDefinition.CreateModule ("foo", ModuleKind.Dll)) { - var method = module.Import (generic.GetMethod ("Method")); + var method = module.ImportReference (generic.GetMethod ("Method")); Assert.AreEqual ("T Mono.Cecil.Tests.ImportCecilTests/Generic`1::Method(T)", method.FullName); } } + public class ContextGeneric1Method2<G1> + { + public G1 GenericMethod<R1, S1> (R1 r, S1 s) + { + return default (G1); + } + } + + public class ContextGeneric2Method1<G2, H2> + { + public R2 GenericMethod<R2> (G2 g, H2 h) + { + return default (R2); + } + } + + public class NestedGenericsA<A> + { + public class NestedGenericsB<B> + { + public class NestedGenericsC<C> + { + public A GenericMethod (B b, C c) + { + return default (A); + } + } + } + } + + [Test] + public void ContextGenericTest () + { + var module = ModuleDefinition.ReadModule (typeof (ContextGeneric1Method2<>).Module.FullyQualifiedName); + // by mixing open generics with 2 & 1 parameters, we make sure the right context is used (because otherwise, an exception will be thrown) + var type = typeof (ContextGeneric1Method2<>).MakeGenericType (typeof (ContextGeneric2Method1<,>)); + var meth = type.GetMethod ("GenericMethod"); + var imported_type = module.ImportReference (type); + var method = module.ImportReference (meth, imported_type); + Assert.AreEqual ("G1 Mono.Cecil.Tests.ImportCecilTests/ContextGeneric1Method2`1<Mono.Cecil.Tests.ImportCecilTests/ContextGeneric2Method1`2<G2,H2>>::GenericMethod<R1,S1>(R1,S1)", method.FullName); + + // and the other way around + type = typeof (ContextGeneric2Method1<,>).MakeGenericType (typeof (ContextGeneric1Method2<>), typeof (IList<>)); + meth = type.GetMethod ("GenericMethod"); + imported_type = module.ImportReference (type); + method = module.ImportReference (meth, imported_type); + Assert.AreEqual ("R2 Mono.Cecil.Tests.ImportCecilTests/ContextGeneric2Method1`2<Mono.Cecil.Tests.ImportCecilTests/ContextGeneric1Method2`1<G1>,System.Collections.Generic.IList`1<T>>::GenericMethod<R2>(G2,H2)", method.FullName); + + // not sure about this one + type = typeof (NestedGenericsA<string>.NestedGenericsB<int>.NestedGenericsC<float>); + meth = type.GetMethod ("GenericMethod"); + imported_type = module.ImportReference (type); + method = module.ImportReference (meth, imported_type); + Assert.AreEqual ("A Mono.Cecil.Tests.ImportCecilTests/NestedGenericsA`1/NestedGenericsB`1/NestedGenericsC`1<System.String,System.Int32,System.Single>::GenericMethod(B,C)", method.FullName); + + // We need both the method & type ! + type = typeof (Generic<>).MakeGenericType (typeof (string)); + meth = type.GetMethod ("ComplexGenericMethod"); + imported_type = module.ImportReference (type); + method = module.ImportReference (meth, imported_type); + Assert.AreEqual ("Mono.Cecil.Tests.ImportCecilTests/Generic`1<TS> Mono.Cecil.Tests.ImportCecilTests/Generic`1<System.String>::ComplexGenericMethod<TS>(T,TS)", method.FullName); + } + delegate void Emitter (ModuleDefinition module, MethodBody body); [MethodImpl (MethodImplOptions.NoInlining)] @@ -261,7 +326,7 @@ namespace Mono.Cecil.Tests { "", name, TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract, - module.Import (typeof (object))); + module.ImportReference (typeof (object))); module.Types.Add (type); @@ -284,10 +349,10 @@ namespace Mono.Cecil.Tests { type.Methods.Add (method); - method.MethodReturnType.ReturnType = module.Import (pattern.ReturnType); + method.MethodReturnType.ReturnType = module.ImportReference (pattern.ReturnType); foreach (var parameter_pattern in pattern.GetParameters ()) - method.Parameters.Add (new ParameterDefinition (module.Import (parameter_pattern.ParameterType))); + method.Parameters.Add (new ParameterDefinition (module.ImportReference (parameter_pattern.ParameterType))); return method; } diff --git a/Test/Mono.Cecil.Tests/ImportReflectionTests.cs b/Test/Mono.Cecil.Tests/ImportReflectionTests.cs index ffb2619..71412af 100644 --- a/Test/Mono.Cecil.Tests/ImportReflectionTests.cs +++ b/Test/Mono.Cecil.Tests/ImportReflectionTests.cs @@ -54,10 +54,10 @@ namespace Mono.Cecil.Tests { type.Methods.Add (method_by_ref); - method_by_ref.MethodReturnType.ReturnType = module.Import (typeof (void)); + method_by_ref.MethodReturnType.ReturnType = module.ImportReference (typeof (void)); - method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (typeof (string)))); - method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (typeof (string).MakeByRefType ()))); + method_by_ref.Parameters.Add (new ParameterDefinition (module.ImportReference (typeof (string)))); + method_by_ref.Parameters.Add (new ParameterDefinition (module.ImportReference (typeof (string).MakeByRefType ()))); var m_il = method_by_ref.Body.GetILProcessor (); m_il.Emit (OpCodes.Ldarg_1); @@ -65,7 +65,7 @@ namespace Mono.Cecil.Tests { m_il.Emit (OpCodes.Stind_Ref); m_il.Emit (OpCodes.Ret); - var v_0 = new VariableDefinition (module.Import (typeof (string))); + var v_0 = new VariableDefinition (module.ImportReference (typeof (string))); body.Variables.Add (v_0); var il = body.GetILProcessor (); @@ -100,7 +100,7 @@ namespace Mono.Cecil.Tests { { var get_empty = Compile<Func<string>> ((module, body) => { var il = body.GetILProcessor (); - il.Emit (OpCodes.Ldsfld, module.Import (typeof (string).GetField ("Empty"))); + il.Emit (OpCodes.Ldsfld, module.ImportReference (typeof (string).GetField ("Empty"))); il.Emit (OpCodes.Ret); }); @@ -114,7 +114,7 @@ namespace Mono.Cecil.Tests { var il = body.GetILProcessor (); il.Emit (OpCodes.Ldarg_0); il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Call, module.Import (typeof (string).GetMethod ("Concat", new [] { typeof (string), typeof (string) }))); + il.Emit (OpCodes.Call, module.ImportReference (typeof (string).GetMethod ("Concat", new [] { typeof (string), typeof (string) }))); il.Emit (OpCodes.Ret); }); @@ -146,7 +146,7 @@ namespace Mono.Cecil.Tests { var get_field = Compile<Func<Generic<string>, string>> ((module, body) => { var il = body.GetILProcessor (); il.Emit (OpCodes.Ldarg_0); - il.Emit (OpCodes.Ldfld, module.Import (typeof (Generic<string>).GetField ("Field"))); + il.Emit (OpCodes.Ldfld, module.ImportReference (typeof (Generic<string>).GetField ("Field"))); il.Emit (OpCodes.Ret); }); @@ -164,7 +164,7 @@ namespace Mono.Cecil.Tests { var il = body.GetILProcessor (); il.Emit (OpCodes.Ldarg_0); il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Callvirt, module.Import (typeof (Generic<int>).GetMethod ("Method"))); + il.Emit (OpCodes.Callvirt, module.ImportReference (typeof (Generic<int>).GetMethod ("Method"))); il.Emit (OpCodes.Ret); }); @@ -179,7 +179,7 @@ namespace Mono.Cecil.Tests { il.Emit (OpCodes.Ldarg_0); il.Emit (OpCodes.Ldnull); il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Callvirt, module.Import (typeof (Generic<string>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)))); + il.Emit (OpCodes.Callvirt, module.ImportReference (typeof (Generic<string>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)))); il.Emit (OpCodes.Ret); }); @@ -194,8 +194,8 @@ namespace Mono.Cecil.Tests { il.Emit (OpCodes.Ldarg_0); il.Emit (OpCodes.Ldnull); il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Callvirt, module.Import (typeof (Generic<string>).GetMethod ("ComplexGenericMethod").MakeGenericMethod (typeof (int)))); - il.Emit (OpCodes.Ldfld, module.Import (typeof (Generic<string>).GetField ("Field"))); + il.Emit (OpCodes.Callvirt, module.ImportReference (typeof (Generic<string>).GetMethod ("ComplexGenericMethod").MakeGenericMethod (typeof (int)))); + il.Emit (OpCodes.Ldfld, module.ImportReference (typeof (Generic<string>).GetField ("Field"))); il.Emit (OpCodes.Ret); }); @@ -210,8 +210,8 @@ namespace Mono.Cecil.Tests { public void ImportGenericTypeDefOrOpen () { using (var module = typeof (Foo<>).ToDefinition ().Module) { - var foo_def = module.Import (typeof (Foo<>)); - var foo_open = module.Import (typeof (Foo<>), foo_def); + var foo_def = module.ImportReference (typeof (Foo<>)); + var foo_open = module.ImportReference (typeof (Foo<>), foo_def); Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Foo`1", foo_def.FullName); Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Foo`1<TFoo>", foo_open.FullName); @@ -226,7 +226,7 @@ namespace Mono.Cecil.Tests { var foo_def = typeof (Foo<>).ToDefinition (); using (var module = foo_def.Module) { - var generic_foo = module.Import (generic_list_foo_open, foo_def); + var generic_foo = module.ImportReference (generic_list_foo_open, foo_def); Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>", generic_foo.FullName); @@ -241,7 +241,7 @@ namespace Mono.Cecil.Tests { var foo_def = typeof (Foo<>).ToDefinition (); using (var module = foo_def.Module) { - var generic_foo = module.Import (generic_foo_open, foo_def); + var generic_foo = module.ImportReference (generic_foo_open, foo_def); Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Generic`1<Mono.Cecil.Tests.ImportReflectionTests/Foo`1<TFoo>>", generic_foo.FullName); @@ -256,7 +256,7 @@ namespace Mono.Cecil.Tests { var foo_def = typeof (Foo<>).ToDefinition (); using (var module = foo_def.Module) { - var array_foo = module.Import (foo_open_array, foo_def); + var array_foo = module.ImportReference (foo_open_array, foo_def); Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Foo`1<TFoo>[]", array_foo.FullName); @@ -272,9 +272,9 @@ namespace Mono.Cecil.Tests { var foo_def = typeof (Foo<>).ToDefinition (); using (var module = foo_def.Module) { - var generic_field = module.Import (generic_list_foo_open_field, foo_def); + var generic_field = module.ImportReference (generic_list_foo_open_field, foo_def); - Assert.AreEqual ("TFoo Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>::Field", + Assert.AreEqual ("T Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>::Field", generic_field.FullName); } } @@ -288,9 +288,9 @@ namespace Mono.Cecil.Tests { var foo_def = typeof (Foo<>).ToDefinition (); using (var module = foo_def.Module) { - var generic_method = module.Import (generic_list_foo_open_method, foo_def); + var generic_method = module.ImportReference (generic_list_foo_open_method, foo_def); - Assert.AreEqual ("TFoo Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>::Method(TFoo)", + Assert.AreEqual ("T Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>::Method(T)", generic_method.FullName); } } @@ -299,7 +299,7 @@ namespace Mono.Cecil.Tests { public void ImportMethodOnOpenGenericType () { using (var module = typeof (Generic<>).ToDefinition ().Module) { - var method = module.Import (typeof (Generic<>).GetMethod ("Method")); + var method = module.ImportReference (typeof (Generic<>).GetMethod ("Method")); Assert.AreEqual ("T Mono.Cecil.Tests.ImportReflectionTests/Generic`1<T>::Method(T)", method.FullName); } @@ -309,11 +309,11 @@ namespace Mono.Cecil.Tests { public void ImportGenericMethodOnOpenGenericType () { using (var module = typeof (Generic<>).ToDefinition ().Module) { - var generic_method = module.Import (typeof (Generic<>).GetMethod ("GenericMethod")); + var generic_method = module.ImportReference (typeof (Generic<>).GetMethod ("GenericMethod")); Assert.AreEqual ("TS Mono.Cecil.Tests.ImportReflectionTests/Generic`1<T>::GenericMethod(T,TS)", generic_method.FullName); - generic_method = module.Import (typeof (Generic<>).GetMethod ("GenericMethod"), generic_method); + generic_method = module.ImportReference (typeof (Generic<>).GetMethod ("GenericMethod"), generic_method); Assert.AreEqual ("TS Mono.Cecil.Tests.ImportReflectionTests/Generic`1<T>::GenericMethod<TS>(T,TS)", generic_method.FullName); } @@ -361,7 +361,7 @@ namespace Mono.Cecil.Tests { "", name, TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract, - module.Import (typeof (object))); + module.ImportReference (typeof (object))); module.Types.Add (type); @@ -384,10 +384,10 @@ namespace Mono.Cecil.Tests { type.Methods.Add (method); - method.MethodReturnType.ReturnType = module.Import (pattern.ReturnType); + method.MethodReturnType.ReturnType = module.ImportReference (pattern.ReturnType); foreach (var parameter_pattern in pattern.GetParameters ()) - method.Parameters.Add (new ParameterDefinition (module.Import (parameter_pattern.ParameterType))); + method.Parameters.Add (new ParameterDefinition (module.ImportReference (parameter_pattern.ParameterType))); return method; } diff --git a/Test/Mono.Cecil.Tests/MethodBodyTests.cs b/Test/Mono.Cecil.Tests/MethodBodyTests.cs index afe8f79..96f9e7a 100644 --- a/Test/Mono.Cecil.Tests/MethodBodyTests.cs +++ b/Test/Mono.Cecil.Tests/MethodBodyTests.cs @@ -11,17 +11,18 @@ namespace Mono.Cecil.Tests { [TestFixture] public class MethodBodyTests : BaseTestFixture { - [TestIL ("hello.il")] - public void MultiplyMethod (ModuleDefinition module) + [Test] + public void MultiplyMethod () { - var foo = module.GetType ("Foo"); - Assert.IsNotNull (foo); + TestIL ("hello.il", module => { + var foo = module.GetType ("Foo"); + Assert.IsNotNull (foo); - var bar = foo.GetMethod ("Bar"); - Assert.IsNotNull (bar); - Assert.IsTrue (bar.IsIL); + var bar = foo.GetMethod ("Bar"); + Assert.IsNotNull (bar); + Assert.IsTrue (bar.IsIL); - AssertCode (@" + AssertCode (@" .locals init (System.Int32 V_0) IL_0000: ldarg.0 IL_0001: ldarg.1 @@ -31,35 +32,39 @@ namespace Mono.Cecil.Tests { IL_0005: call System.Void Foo::Baz(System.Int32) IL_000a: ret ", bar); + }); } - [TestIL ("hello.il")] - public void PrintStringEmpty (ModuleDefinition module) + [Test] + public void PrintStringEmpty () { - var foo = module.GetType ("Foo"); - Assert.IsNotNull (foo); + TestIL ("hello.il", module => { + var foo = module.GetType ("Foo"); + Assert.IsNotNull (foo); - var print_empty = foo.GetMethod ("PrintEmpty"); - Assert.IsNotNull (print_empty); + var print_empty = foo.GetMethod ("PrintEmpty"); + Assert.IsNotNull (print_empty); - AssertCode (@" + AssertCode (@" .locals () IL_0000: ldsfld System.String System.String::Empty IL_0005: call System.Void System.Console::WriteLine(System.String) IL_000a: ret ", print_empty); + }); } - [TestModule ("libhello.dll")] - public void Branch (ModuleDefinition module) + [Test] + public void Branch () { - var lib = module.GetType ("Library"); - Assert.IsNotNull (lib); + TestModule ("libhello.dll", module => { + var lib = module.GetType ("Library"); + Assert.IsNotNull (lib); - var method = lib.GetMethod ("GetHelloString"); - Assert.IsNotNull (method); + var method = lib.GetMethod ("GetHelloString"); + Assert.IsNotNull (method); - AssertCode (@" + AssertCode (@" .locals init (System.String V_0) IL_0000: nop IL_0001: ldstr ""hello world of tomorrow"" @@ -68,18 +73,20 @@ namespace Mono.Cecil.Tests { IL_0009: ldloc.0 IL_000a: ret ", method); + }); } - [TestModule ("switch.exe")] - public void Switch (ModuleDefinition module) + [Test] + public void Switch () { - var program = module.GetType ("Program"); - Assert.IsNotNull (program); + TestModule ("switch.exe", module => { + var program = module.GetType ("Program"); + Assert.IsNotNull (program); - var method = program.GetMethod ("Main"); - Assert.IsNotNull (method); + var method = program.GetMethod ("Main"); + Assert.IsNotNull (method); - AssertCode (@" + AssertCode (@" .locals init (System.Int32 V_0) IL_0000: ldarg.0 IL_0001: ldlen @@ -112,32 +119,36 @@ namespace Mono.Cecil.Tests { IL_0038: ldc.i4.s 42 IL_003a: ret ", method); + }); } - [TestIL ("methodspecs.il")] - public void MethodSpec (ModuleDefinition module) + [Test] + public void MethodSpec () { - var tamtam = module.GetType ("Tamtam"); + TestIL ("methodspecs.il", module => { + var tamtam = module.GetType ("Tamtam"); - var bar = tamtam.GetMethod ("Bar"); - Assert.IsNotNull (bar); + var bar = tamtam.GetMethod ("Bar"); + Assert.IsNotNull (bar); - AssertCode (@" + AssertCode (@" .locals () IL_0000: ldc.i4.2 IL_0001: call System.Void Tamtam::Foo<System.Int32>(TFoo) IL_0006: ret ", bar); + }); } - [TestModule ("catch.exe")] - public void NestedTryCatchFinally (ModuleDefinition module) + [Test] + public void NestedTryCatchFinally () { - var program = module.GetType ("Program"); - var main = program.GetMethod ("Main"); - Assert.IsNotNull (main); + TestModule ("catch.exe", module => { + var program = module.GetType ("Program"); + var main = program.GetMethod ("Main"); + Assert.IsNotNull (main); - AssertCode (@" + AssertCode (@" .locals () IL_0000: call System.Void Program::Foo() IL_0005: leave.s IL_000d @@ -159,16 +170,18 @@ namespace Mono.Cecil.Tests { .try IL_0000 to IL_000f catch System.Exception handler IL_0017 to IL_001f .try IL_0000 to IL_0021 finally handler IL_0021 to IL_0027 ", main); + }); } - [TestModule ("fptr.exe", Verify = false)] - public void FunctionPointersAndCallSites (ModuleDefinition module) + [Test] + public void FunctionPointersAndCallSites () { - var type = module.Types [0]; - var start = type.GetMethod ("Start"); - Assert.IsNotNull (start); + TestModule ("fptr.exe", module => { + var type = module.Types [0]; + var start = type.GetMethod ("Start"); + Assert.IsNotNull (start); - AssertCode (@" + AssertCode (@" .locals init () IL_0000: ldc.i4.1 IL_0001: call method System.Int32 *(System.Int32) MakeDecision::Decide() @@ -184,52 +197,123 @@ namespace Mono.Cecil.Tests { IL_002b: call System.Void System.Console::WriteLine(System.Int32) IL_0030: ret ", start); + }, verify: false); } - [TestIL ("hello.il")] - public void ThisParameter (ModuleDefinition module) + [Test] + public void ThisParameter () { - var type = module.GetType ("Foo"); - var method = type.GetMethod ("Gazonk"); + TestIL ("hello.il", module => { + var type = module.GetType ("Foo"); + var method = type.GetMethod ("Gazonk"); - Assert.IsNotNull (method); + Assert.IsNotNull (method); - AssertCode (@" + AssertCode (@" .locals () IL_0000: ldarg 0 IL_0004: pop IL_0005: ret ", method); - Assert.AreEqual (method.Body.ThisParameter, method.Body.Instructions [0].Operand); + Assert.AreEqual (method.Body.ThisParameter.ParameterType, type); + Assert.AreEqual (method.Body.ThisParameter, method.Body.Instructions [0].Operand); + }); } - [TestIL ("hello.il")] - public void FilterMaxStack (ModuleDefinition module) + [Test] + public void ThisParameterStaticMethod () { - var type = module.GetType ("Foo"); - var method = type.GetMethod ("TestFilter"); + var static_method = typeof (ModuleDefinition).ToDefinition ().Methods.Where (m => m.IsStatic).First (); + Assert.IsNull (static_method.Body.ThisParameter); + } - Assert.IsNotNull (method); - Assert.AreEqual (2, method.Body.MaxStackSize); + [Test] + public void ThisParameterPrimitive () + { + var int32 = typeof (int).ToDefinition (); + var int_to_string = int32.Methods.Where (m => m.Name == "ToString" && m.Parameters.Count == 0).First(); + Assert.IsNotNull (int_to_string); + + var this_parameter_type = int_to_string.Body.ThisParameter.ParameterType; + Assert.IsTrue (this_parameter_type.IsPointer); + + var element_type = ((PointerType) this_parameter_type).ElementType; + Assert.AreEqual (int32, element_type); } - [TestModule ("iterator.exe")] - public void Iterator (ModuleDefinition module) + [Test] + public void ThisParameterValueType () { - var method = module.GetType ("Program").GetMethod ("GetLittleArgs"); - Assert.IsNotNull (method.Body); + var token = typeof (MetadataToken).ToDefinition (); + var token_to_string = token.Methods.Where (m => m.Name == "ToString" && m.Parameters.Count == 0).First (); + Assert.IsNotNull (token_to_string); + + var this_parameter_type = token_to_string.Body.ThisParameter.ParameterType; + Assert.IsTrue (this_parameter_type.IsPointer); + + var element_type = ((PointerType) this_parameter_type).ElementType; + Assert.AreEqual (token, element_type); + } + + [Test] + public void ThisParameterObject () + { + var module = typeof (MethodBodyTests).ToDefinition ().Module; + var @object = module.TypeSystem.Object.Resolve (); + var method = @object.Methods.Where (m => m.HasBody).First (); + + var type = method.Body.ThisParameter.ParameterType; + Assert.IsFalse (type.IsValueType); + Assert.IsFalse (type.IsPrimitive); + Assert.IsFalse (type.IsPointer); + } + + [Test] + public void FilterMaxStack () + { + TestIL ("hello.il", module => { + var type = module.GetType ("Foo"); + var method = type.GetMethod ("TestFilter"); + + Assert.IsNotNull (method); + Assert.AreEqual (2, method.Body.MaxStackSize); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void LoadString (ModuleDefinition module) + [Test] + public void Iterator () { - var type = module.GetType ("FooAttribute"); - var get_fiou = type.GetMethod ("get_Fiou"); - Assert.IsNotNull (get_fiou); + TestModule ("iterator.exe", module => { + var method = module.GetType ("Program").GetMethod ("GetLittleArgs"); + Assert.IsNotNull (method.Body); + }); + } + + [Test] + public void LoadString () + { + TestCSharp ("CustomAttributes.cs", module => { + var type = module.GetType ("FooAttribute"); + var get_fiou = type.GetMethod ("get_Fiou"); + Assert.IsNotNull (get_fiou); + + var ldstr = get_fiou.Body.Instructions.Where (i => i.OpCode == OpCodes.Ldstr).First (); + Assert.AreEqual ("fiou", ldstr.Operand); + }); + } + + [Test] + public void UnattachedMethodBody () + { + var system_void = typeof (void).ToDefinition (); + var method = new MethodDefinition ("NewMethod", MethodAttributes.Assembly | MethodAttributes.Static, system_void); + var body = new MethodBody (method); + var il = body.GetILProcessor (); + il.Emit (OpCodes.Ret); + method.Body = body; - var ldstr = get_fiou.Body.Instructions.Where (i => i.OpCode == OpCodes.Ldstr).First (); - Assert.AreEqual ("fiou", ldstr.Operand); + Assert.AreEqual (body, method.Body); } static void AssertCode (string expected, MethodDefinition method) diff --git a/Test/Mono.Cecil.Tests/MethodTests.cs b/Test/Mono.Cecil.Tests/MethodTests.cs index c7d55f9..bc76aa6 100644 --- a/Test/Mono.Cecil.Tests/MethodTests.cs +++ b/Test/Mono.Cecil.Tests/MethodTests.cs @@ -11,183 +11,209 @@ namespace Mono.Cecil.Tests { [TestFixture] public class MethodTests : BaseTestFixture { - [TestCSharp ("Methods.cs")] - public void AbstractMethod (ModuleDefinition module) + [Test] + public void AbstractMethod () { - var type = module.Types [1]; - Assert.AreEqual ("Foo", type.Name); - Assert.AreEqual (2, type.Methods.Count); + TestCSharp ("Methods.cs", module => { + var type = module.Types [1]; + Assert.AreEqual ("Foo", type.Name); + Assert.AreEqual (2, type.Methods.Count); - var method = type.GetMethod ("Bar"); - Assert.AreEqual ("Bar", method.Name); - Assert.IsTrue (method.IsAbstract); - Assert.IsNotNull (method.ReturnType); + var method = type.GetMethod ("Bar"); + Assert.AreEqual ("Bar", method.Name); + Assert.IsTrue (method.IsAbstract); + Assert.IsNotNull (method.ReturnType); - Assert.AreEqual (1, method.Parameters.Count); + Assert.AreEqual (1, method.Parameters.Count); - var parameter = method.Parameters [0]; + var parameter = method.Parameters [0]; - Assert.AreEqual ("a", parameter.Name); - Assert.AreEqual ("System.Int32", parameter.ParameterType.FullName); + Assert.AreEqual ("a", parameter.Name); + Assert.AreEqual ("System.Int32", parameter.ParameterType.FullName); + }); } - [TestCSharp ("Methods.cs")] - public void SimplePInvoke (ModuleDefinition module) + [Test] + public void SimplePInvoke () { - var bar = module.GetType ("Bar"); - var pan = bar.GetMethod ("Pan"); + TestCSharp ("Methods.cs", module => { + var bar = module.GetType ("Bar"); + var pan = bar.GetMethod ("Pan"); - Assert.IsTrue (pan.IsPInvokeImpl); - Assert.IsNotNull (pan.PInvokeInfo); + Assert.IsTrue (pan.IsPInvokeImpl); + Assert.IsNotNull (pan.PInvokeInfo); - Assert.AreEqual ("Pan", pan.PInvokeInfo.EntryPoint); - Assert.IsNotNull (pan.PInvokeInfo.Module); - Assert.AreEqual ("foo.dll", pan.PInvokeInfo.Module.Name); + Assert.AreEqual ("Pan", pan.PInvokeInfo.EntryPoint); + Assert.IsNotNull (pan.PInvokeInfo.Module); + Assert.AreEqual ("foo.dll", pan.PInvokeInfo.Module.Name); + }); } - [TestCSharp ("Generics.cs")] - public void GenericMethodDefinition (ModuleDefinition module) + [Test] + public void GenericMethodDefinition () { - var baz = module.GetType ("Baz"); + TestCSharp ("Generics.cs", module => { + var baz = module.GetType ("Baz"); - var gazonk = baz.GetMethod ("Gazonk"); + var gazonk = baz.GetMethod ("Gazonk"); - Assert.IsNotNull (gazonk); + Assert.IsNotNull (gazonk); - Assert.IsTrue (gazonk.HasGenericParameters); - Assert.AreEqual (1, gazonk.GenericParameters.Count); - Assert.AreEqual ("TBang", gazonk.GenericParameters [0].Name); + Assert.IsTrue (gazonk.HasGenericParameters); + Assert.AreEqual (1, gazonk.GenericParameters.Count); + Assert.AreEqual ("TBang", gazonk.GenericParameters [0].Name); + }); } - [TestCSharp ("Generics.cs")] - public void ReturnGenericInstance (ModuleDefinition module) + [Test] + public void ReturnGenericInstance () { - var bar = module.GetType ("Bar`1"); + TestCSharp ("Generics.cs", module => { + var bar = module.GetType ("Bar`1"); - var self = bar.GetMethod ("Self"); - Assert.IsNotNull (self); + var self = bar.GetMethod ("Self"); + Assert.IsNotNull (self); - var bar_t = self.ReturnType; + var bar_t = self.ReturnType; - Assert.IsTrue (bar_t.IsGenericInstance); + Assert.IsTrue (bar_t.IsGenericInstance); - var bar_t_instance = (GenericInstanceType) bar_t; + var bar_t_instance = (GenericInstanceType) bar_t; - Assert.AreEqual (bar.GenericParameters [0], bar_t_instance.GenericArguments [0]); + Assert.AreEqual (bar.GenericParameters [0], bar_t_instance.GenericArguments [0]); - var self_str = bar.GetMethod ("SelfString"); - Assert.IsNotNull (self_str); + var self_str = bar.GetMethod ("SelfString"); + Assert.IsNotNull (self_str); - var bar_str = self_str.ReturnType; - Assert.IsTrue (bar_str.IsGenericInstance); + var bar_str = self_str.ReturnType; + Assert.IsTrue (bar_str.IsGenericInstance); - var bar_str_instance = (GenericInstanceType) bar_str; + var bar_str_instance = (GenericInstanceType) bar_str; - Assert.AreEqual ("System.String", bar_str_instance.GenericArguments [0].FullName); + Assert.AreEqual ("System.String", bar_str_instance.GenericArguments [0].FullName); + }); } - [TestCSharp ("Generics.cs")] - public void ReturnGenericInstanceWithMethodParameter (ModuleDefinition module) + [Test] + public void ReturnGenericInstanceWithMethodParameter () { - var baz = module.GetType ("Baz"); + TestCSharp ("Generics.cs", module => { + var baz = module.GetType ("Baz"); - var gazoo = baz.GetMethod ("Gazoo"); - Assert.IsNotNull (gazoo); + var gazoo = baz.GetMethod ("Gazoo"); + Assert.IsNotNull (gazoo); - var bar_bingo = gazoo.ReturnType; + var bar_bingo = gazoo.ReturnType; - Assert.IsTrue (bar_bingo.IsGenericInstance); + Assert.IsTrue (bar_bingo.IsGenericInstance); - var bar_bingo_instance = (GenericInstanceType) bar_bingo; + var bar_bingo_instance = (GenericInstanceType) bar_bingo; - Assert.AreEqual (gazoo.GenericParameters [0], bar_bingo_instance.GenericArguments [0]); + Assert.AreEqual (gazoo.GenericParameters [0], bar_bingo_instance.GenericArguments [0]); + }); } - [TestCSharp ("Interfaces.cs")] - public void SimpleOverrides (ModuleDefinition module) + [Test] + public void SimpleOverrides () { - var ibingo = module.GetType ("IBingo"); - var ibingo_foo = ibingo.GetMethod ("Foo"); - Assert.IsNotNull (ibingo_foo); + TestCSharp ("Interfaces.cs", module => { + var ibingo = module.GetType ("IBingo"); + var ibingo_foo = ibingo.GetMethod ("Foo"); + Assert.IsNotNull (ibingo_foo); - var ibingo_bar = ibingo.GetMethod ("Bar"); - Assert.IsNotNull (ibingo_bar); + var ibingo_bar = ibingo.GetMethod ("Bar"); + Assert.IsNotNull (ibingo_bar); - var bingo = module.GetType ("Bingo"); + var bingo = module.GetType ("Bingo"); - var foo = bingo.GetMethod ("IBingo.Foo"); - Assert.IsNotNull (foo); + var foo = bingo.GetMethod ("IBingo.Foo"); + Assert.IsNotNull (foo); - Assert.IsTrue (foo.HasOverrides); - Assert.AreEqual (ibingo_foo, foo.Overrides [0]); + Assert.IsTrue (foo.HasOverrides); + Assert.AreEqual (ibingo_foo, foo.Overrides [0]); - var bar = bingo.GetMethod ("IBingo.Bar"); - Assert.IsNotNull (bar); + var bar = bingo.GetMethod ("IBingo.Bar"); + Assert.IsNotNull (bar); - Assert.IsTrue (bar.HasOverrides); - Assert.AreEqual (ibingo_bar, bar.Overrides [0]); + Assert.IsTrue (bar.HasOverrides); + Assert.AreEqual (ibingo_bar, bar.Overrides [0]); + }); } - [TestModule ("varargs.exe")] - public void VarArgs (ModuleDefinition module) + [Test] + public void VarArgs () { - var module_type = module.Types [0]; + TestModule ("varargs.exe", module => { + var module_type = module.Types [0]; - Assert.AreEqual (3, module_type.Methods.Count); + Assert.AreEqual (3, module_type.Methods.Count); - var bar = module_type.GetMethod ("Bar"); - var baz = module_type.GetMethod ("Baz"); - var foo = module_type.GetMethod ("Foo"); + var bar = module_type.GetMethod ("Bar"); + var baz = module_type.GetMethod ("Baz"); + var foo = module_type.GetMethod ("Foo"); - Assert.IsTrue (bar.IsVarArg ()); - Assert.IsFalse (baz.IsVarArg ()); + Assert.IsTrue (bar.IsVarArg ()); + Assert.IsFalse (baz.IsVarArg ()); - Assert.IsTrue(foo.IsVarArg ()); + Assert.IsTrue(foo.IsVarArg ()); - var bar_reference = (MethodReference) baz.Body.Instructions.Where (i => i.Offset == 0x000a).First ().Operand; + var bar_reference = (MethodReference) baz.Body.Instructions.Where (i => i.Offset == 0x000a).First ().Operand; - Assert.IsTrue (bar_reference.IsVarArg ()); - Assert.AreEqual (0, bar_reference.GetSentinelPosition ()); + Assert.IsTrue (bar_reference.IsVarArg ()); + Assert.AreEqual (0, bar_reference.GetSentinelPosition ()); - var foo_reference = (MethodReference) baz.Body.Instructions.Where (i => i.Offset == 0x0023).First ().Operand; + var foo_reference = (MethodReference) baz.Body.Instructions.Where (i => i.Offset == 0x0023).First ().Operand; - Assert.IsTrue (foo_reference.IsVarArg ()); + Assert.IsTrue (foo_reference.IsVarArg ()); - Assert.AreEqual (1, foo_reference.GetSentinelPosition ()); + Assert.AreEqual (1, foo_reference.GetSentinelPosition ()); + }); } - [TestCSharp ("Generics.cs")] - public void GenericInstanceMethod (ModuleDefinition module) + [Test] + public void GenericInstanceMethod () { - var type = module.GetType ("It"); - var method = type.GetMethod ("ReadPwow"); + TestCSharp ("Generics.cs", module => { + var type = module.GetType ("It"); + var method = type.GetMethod ("ReadPwow"); - GenericInstanceMethod instance = null; + GenericInstanceMethod instance = null; - foreach (var instruction in method.Body.Instructions) { - instance = instruction.Operand as GenericInstanceMethod; - if (instance != null) - break; - } + foreach (var instruction in method.Body.Instructions) { + instance = instruction.Operand as GenericInstanceMethod; + if (instance != null) + break; + } - Assert.IsNotNull (instance); + Assert.IsNotNull (instance); - Assert.AreEqual (TokenType.MethodSpec, instance.MetadataToken.TokenType); - Assert.AreNotEqual (0, instance.MetadataToken.RID); + Assert.AreEqual (TokenType.MethodSpec, instance.MetadataToken.TokenType); + Assert.AreNotEqual (0, instance.MetadataToken.RID); + }); } - [TestCSharp ("Generics.cs")] - public void MethodRefDeclaredOnGenerics (ModuleDefinition module) + [Test] + public void MethodRefDeclaredOnGenerics () { - var type = module.GetType ("Tamtam"); - var beta = type.GetMethod ("Beta"); - var charlie = type.GetMethod ("Charlie"); + TestCSharp ("Generics.cs", module => { + var type = module.GetType ("Tamtam"); + var beta = type.GetMethod ("Beta"); + var charlie = type.GetMethod ("Charlie"); - var new_list_beta = (MethodReference) beta.Body.Instructions [0].Operand; - var new_list_charlie = (MethodReference) charlie.Body.Instructions [0].Operand; + var new_list_beta = (MethodReference) beta.Body.Instructions [0].Operand; + var new_list_charlie = (MethodReference) charlie.Body.Instructions [0].Operand; - Assert.AreEqual ("System.Collections.Generic.List`1<TBeta>", new_list_beta.DeclaringType.FullName); - Assert.AreEqual ("System.Collections.Generic.List`1<TCharlie>", new_list_charlie.DeclaringType.FullName); + Assert.AreEqual ("System.Collections.Generic.List`1<TBeta>", new_list_beta.DeclaringType.FullName); + Assert.AreEqual ("System.Collections.Generic.List`1<TCharlie>", new_list_charlie.DeclaringType.FullName); + }); + } + + [Test] + public void ReturnParameterMethod () + { + var method = typeof (MethodTests).ToDefinition ().GetMethod ("ReturnParameterMethod"); + Assert.IsNotNull (method); + Assert.AreEqual (method, method.MethodReturnType.Parameter.Method); } } } diff --git a/Test/Mono.Cecil.Tests/ModuleTests.cs b/Test/Mono.Cecil.Tests/ModuleTests.cs index ee0b3d1..e8b9484 100644 --- a/Test/Mono.Cecil.Tests/ModuleTests.cs +++ b/Test/Mono.Cecil.Tests/ModuleTests.cs @@ -22,176 +22,204 @@ namespace Mono.Cecil.Tests { Assert.AreEqual ("Test", module.Assembly.Name.Name); } - [TestModule ("hello.exe")] - public void SingleModule (ModuleDefinition module) + [Test] + public void SingleModule () { - var assembly = module.Assembly; + TestModule ("hello.exe", module => { + var assembly = module.Assembly; - Assert.AreEqual (1, assembly.Modules.Count); - Assert.IsNotNull (assembly.MainModule); + Assert.AreEqual (1, assembly.Modules.Count); + Assert.IsNotNull (assembly.MainModule); + }); } - [TestModule ("hello.exe")] - public void EntryPoint (ModuleDefinition module) + [Test] + public void EntryPoint () { - var entry_point = module.EntryPoint; - Assert.IsNotNull (entry_point); + TestModule ("hello.exe", module => { + var entry_point = module.EntryPoint; + Assert.IsNotNull (entry_point); - Assert.AreEqual ("System.Void Program::Main()", entry_point.ToString ()); + Assert.AreEqual ("System.Void Program::Main()", entry_point.ToString ()); + }); } - [TestModule ("mma.exe")] - public void MultiModules (ModuleDefinition module) + [Test] + public void MultiModules () { - var assembly = module.Assembly; + TestModule ("mma.exe", module => { + var assembly = module.Assembly; - Assert.AreEqual (3, assembly.Modules.Count); + Assert.AreEqual (3, assembly.Modules.Count); - Assert.AreEqual ("mma.exe", assembly.Modules [0].Name); - Assert.AreEqual (ModuleKind.Console, assembly.Modules [0].Kind); + Assert.AreEqual ("mma.exe", assembly.Modules [0].Name); + Assert.AreEqual (ModuleKind.Console, assembly.Modules [0].Kind); - Assert.AreEqual ("moda.netmodule", assembly.Modules [1].Name); - Assert.AreEqual ("eedb4721-6c3e-4d9a-be30-49021121dd92", assembly.Modules [1].Mvid.ToString ()); - Assert.AreEqual (ModuleKind.NetModule, assembly.Modules [1].Kind); + Assert.AreEqual ("moda.netmodule", assembly.Modules [1].Name); + Assert.AreEqual ("eedb4721-6c3e-4d9a-be30-49021121dd92", assembly.Modules [1].Mvid.ToString ()); + Assert.AreEqual (ModuleKind.NetModule, assembly.Modules [1].Kind); - Assert.AreEqual ("modb.netmodule", assembly.Modules [2].Name); - Assert.AreEqual ("46c5c577-11b2-4ea0-bb3c-3c71f1331dd0", assembly.Modules [2].Mvid.ToString ()); - Assert.AreEqual (ModuleKind.NetModule, assembly.Modules [2].Kind); + Assert.AreEqual ("modb.netmodule", assembly.Modules [2].Name); + Assert.AreEqual ("46c5c577-11b2-4ea0-bb3c-3c71f1331dd0", assembly.Modules [2].Mvid.ToString ()); + Assert.AreEqual (ModuleKind.NetModule, assembly.Modules [2].Kind); + }); } - [TestModule ("hello.exe")] - public void ModuleInformation (ModuleDefinition module) + [Test] + public void ModuleInformation () { - Assert.IsNotNull (module); + TestModule ("hello.exe", module => { + Assert.IsNotNull (module); - Assert.AreEqual ("hello.exe", module.Name); - Assert.AreEqual (new Guid ("C3BC2BD3-2576-4D00-A80E-465B5632415F"), module.Mvid); + Assert.AreEqual ("hello.exe", module.Name); + Assert.AreEqual (new Guid ("C3BC2BD3-2576-4D00-A80E-465B5632415F"), module.Mvid); + }); } - [TestModule ("hello.exe")] - public void AssemblyReferences (ModuleDefinition module) + [Test] + public void AssemblyReferences () { - Assert.AreEqual (1, module.AssemblyReferences.Count); + TestModule ("hello.exe", module => { + Assert.AreEqual (1, module.AssemblyReferences.Count); - var reference = module.AssemblyReferences [0]; + var reference = module.AssemblyReferences [0]; - Assert.AreEqual ("mscorlib", reference.Name); - Assert.AreEqual (new Version (2, 0, 0, 0), reference.Version); - Assert.AreEqual (new byte [] { 0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89 }, reference.PublicKeyToken); + Assert.AreEqual ("mscorlib", reference.Name); + Assert.AreEqual (new Version (2, 0, 0, 0), reference.Version); + Assert.AreEqual (new byte [] { 0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89 }, reference.PublicKeyToken); + }); } - [TestModule ("pinvoke.exe")] - public void ModuleReferences (ModuleDefinition module) + [Test] + public void ModuleReferences () { - Assert.AreEqual (2, module.ModuleReferences.Count); - Assert.AreEqual ("kernel32.dll", module.ModuleReferences [0].Name); - Assert.AreEqual ("shell32.dll", module.ModuleReferences [1].Name); + TestModule ("pinvoke.exe", module => { + Assert.AreEqual (2, module.ModuleReferences.Count); + Assert.AreEqual ("kernel32.dll", module.ModuleReferences [0].Name); + Assert.AreEqual ("shell32.dll", module.ModuleReferences [1].Name); + }); } - [TestModule ("hello.exe")] - public void Types (ModuleDefinition module) + [Test] + public void Types () { - Assert.AreEqual (2, module.Types.Count); - Assert.AreEqual ("<Module>", module.Types [0].FullName); - Assert.AreEqual ("<Module>", module.GetType ("<Module>").FullName); - Assert.AreEqual ("Program", module.Types [1].FullName); - Assert.AreEqual ("Program", module.GetType ("Program").FullName); + TestModule ("hello.exe", module => { + Assert.AreEqual (2, module.Types.Count); + Assert.AreEqual ("<Module>", module.Types [0].FullName); + Assert.AreEqual ("<Module>", module.GetType ("<Module>").FullName); + Assert.AreEqual ("Program", module.Types [1].FullName); + Assert.AreEqual ("Program", module.GetType ("Program").FullName); + }); } - [TestModule ("libres.dll")] - public void LinkedResource (ModuleDefinition module) + [Test] + public void LinkedResource () { - var resource = module.Resources.Where (res => res.Name == "linked.txt").First () as LinkedResource; - Assert.IsNotNull (resource); - - Assert.AreEqual ("linked.txt", resource.Name); - Assert.AreEqual ("linked.txt", resource.File); - Assert.AreEqual (ResourceType.Linked, resource.ResourceType); - Assert.IsTrue (resource.IsPublic); + TestModule ("libres.dll", module => { + var resource = module.Resources.Where (res => res.Name == "linked.txt").First () as LinkedResource; + Assert.IsNotNull (resource); + + Assert.AreEqual ("linked.txt", resource.Name); + Assert.AreEqual ("linked.txt", resource.File); + Assert.AreEqual (ResourceType.Linked, resource.ResourceType); + Assert.IsTrue (resource.IsPublic); + }); } - [TestModule ("libres.dll")] - public void EmbeddedResource (ModuleDefinition module) + [Test] + public void EmbeddedResource () { - var resource = module.Resources.Where (res => res.Name == "embedded1.txt").First () as EmbeddedResource; - Assert.IsNotNull (resource); + TestModule ("libres.dll", module => { + var resource = module.Resources.Where (res => res.Name == "embedded1.txt").First () as EmbeddedResource; + Assert.IsNotNull (resource); - Assert.AreEqual ("embedded1.txt", resource.Name); - Assert.AreEqual (ResourceType.Embedded, resource.ResourceType); - Assert.IsTrue (resource.IsPublic); + Assert.AreEqual ("embedded1.txt", resource.Name); + Assert.AreEqual (ResourceType.Embedded, resource.ResourceType); + Assert.IsTrue (resource.IsPublic); - using (var reader = new StreamReader (resource.GetResourceStream ())) + using (var reader = new StreamReader (resource.GetResourceStream ())) Assert.AreEqual ("Hello", reader.ReadToEnd ()); - resource = module.Resources.Where (res => res.Name == "embedded2.txt").First () as EmbeddedResource; - Assert.IsNotNull (resource); + resource = module.Resources.Where (res => res.Name == "embedded2.txt").First () as EmbeddedResource; + Assert.IsNotNull (resource); - Assert.AreEqual ("embedded2.txt", resource.Name); - Assert.AreEqual (ResourceType.Embedded, resource.ResourceType); - Assert.IsTrue (resource.IsPublic); + Assert.AreEqual ("embedded2.txt", resource.Name); + Assert.AreEqual (ResourceType.Embedded, resource.ResourceType); + Assert.IsTrue (resource.IsPublic); - using (var reader = new StreamReader (resource.GetResourceStream ())) + using (var reader = new StreamReader (resource.GetResourceStream ())) Assert.AreEqual ("World", reader.ReadToEnd ()); + }); } - [TestModule ("mma.exe")] - public void ExportedTypeFromNetModule (ModuleDefinition module) + [Test] + public void ExportedTypeFromNetModule () { - Assert.IsTrue (module.HasExportedTypes); - Assert.AreEqual (2, module.ExportedTypes.Count); + TestModule ("mma.exe", module => { + Assert.IsTrue (module.HasExportedTypes); + Assert.AreEqual (2, module.ExportedTypes.Count); - var exported_type = module.ExportedTypes [0]; + var exported_type = module.ExportedTypes [0]; - Assert.AreEqual ("Module.A.Foo", exported_type.FullName); - Assert.AreEqual ("moda.netmodule", exported_type.Scope.Name); + Assert.AreEqual ("Module.A.Foo", exported_type.FullName); + Assert.AreEqual ("moda.netmodule", exported_type.Scope.Name); - exported_type = module.ExportedTypes [1]; + exported_type = module.ExportedTypes [1]; - Assert.AreEqual ("Module.B.Baz", exported_type.FullName); - Assert.AreEqual ("modb.netmodule", exported_type.Scope.Name); + Assert.AreEqual ("Module.B.Baz", exported_type.FullName); + Assert.AreEqual ("modb.netmodule", exported_type.Scope.Name); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void NestedTypeForwarder (ModuleDefinition module) + [Test] + public void NestedTypeForwarder () { - Assert.IsTrue (module.HasExportedTypes); - Assert.AreEqual (2, module.ExportedTypes.Count); + TestCSharp ("CustomAttributes.cs", module => { + Assert.IsTrue (module.HasExportedTypes); + Assert.AreEqual (2, module.ExportedTypes.Count); - var exported_type = module.ExportedTypes [0]; + var exported_type = module.ExportedTypes [0]; - Assert.AreEqual ("System.Diagnostics.DebuggableAttribute", exported_type.FullName); - Assert.AreEqual ("mscorlib", exported_type.Scope.Name); - Assert.IsTrue (exported_type.IsForwarder); + Assert.AreEqual ("System.Diagnostics.DebuggableAttribute", exported_type.FullName); + Assert.AreEqual ("mscorlib", exported_type.Scope.Name); + Assert.IsTrue (exported_type.IsForwarder); - var nested_exported_type = module.ExportedTypes [1]; + var nested_exported_type = module.ExportedTypes [1]; - Assert.AreEqual ("System.Diagnostics.DebuggableAttribute/DebuggingModes", nested_exported_type.FullName); - Assert.AreEqual (exported_type, nested_exported_type.DeclaringType); - Assert.AreEqual ("mscorlib", nested_exported_type.Scope.Name); + Assert.AreEqual ("System.Diagnostics.DebuggableAttribute/DebuggingModes", nested_exported_type.FullName); + Assert.AreEqual (exported_type, nested_exported_type.DeclaringType); + Assert.AreEqual ("mscorlib", nested_exported_type.Scope.Name); + }); } - [TestCSharp ("CustomAttributes.cs")] - public void HasTypeReference (ModuleDefinition module) + [Test] + public void HasTypeReference () { - Assert.IsTrue (module.HasTypeReference ("System.Attribute")); - Assert.IsTrue (module.HasTypeReference ("mscorlib", "System.Attribute")); + TestCSharp ("CustomAttributes.cs", module => { + Assert.IsTrue (module.HasTypeReference ("System.Attribute")); + Assert.IsTrue (module.HasTypeReference ("mscorlib", "System.Attribute")); - Assert.IsFalse (module.HasTypeReference ("System.Core", "System.Attribute")); - Assert.IsFalse (module.HasTypeReference ("System.Linq.Enumerable")); + Assert.IsFalse (module.HasTypeReference ("System.Core", "System.Attribute")); + Assert.IsFalse (module.HasTypeReference ("System.Linq.Enumerable")); + }); } - [TestModule ("libhello.dll")] - public void Win32FileVersion (ModuleDefinition module) + [Test] + public void Win32FileVersion () { - var version = FileVersionInfo.GetVersionInfo (module.FullyQualifiedName); + TestModule ("libhello.dll", module => { + var version = FileVersionInfo.GetVersionInfo (module.FullyQualifiedName); - Assert.AreEqual ("0.0.0.0", version.FileVersion); + Assert.AreEqual ("0.0.0.0", version.FileVersion); + }); } - [TestModule ("noblob.dll")] - public void ModuleWithoutBlob (ModuleDefinition module) + [Test] + public void ModuleWithoutBlob () { - Assert.IsNull (module.Image.BlobHeap); + TestModule ("noblob.dll", module => { + Assert.IsNull (module.Image.BlobHeap); + }); } [Test] diff --git a/Test/Mono.Cecil.Tests/NestedTypesTests.cs b/Test/Mono.Cecil.Tests/NestedTypesTests.cs index a839292..c840e63 100644 --- a/Test/Mono.Cecil.Tests/NestedTypesTests.cs +++ b/Test/Mono.Cecil.Tests/NestedTypesTests.cs @@ -9,37 +9,55 @@ namespace Mono.Cecil.Tests { [TestFixture] public class NestedTypesTests : BaseTestFixture { - [TestCSharp ("NestedTypes.cs")] - public void NestedTypes (ModuleDefinition module) + [Test] + public void NestedTypes () { - var foo = module.GetType ("Foo"); + TestCSharp ("NestedTypes.cs", module => { + var foo = module.GetType ("Foo"); - Assert.AreEqual ("Foo", foo.Name); - Assert.AreEqual ("Foo", foo.FullName); - Assert.AreEqual (module, foo.Module); - Assert.AreEqual (1, foo.NestedTypes.Count); + Assert.AreEqual ("Foo", foo.Name); + Assert.AreEqual ("Foo", foo.FullName); + Assert.AreEqual (module, foo.Module); + Assert.AreEqual (1, foo.NestedTypes.Count); - var bar = foo.NestedTypes [0]; + var bar = foo.NestedTypes [0]; - Assert.AreEqual ("Bar", bar.Name); - Assert.AreEqual ("Foo/Bar", bar.FullName); - Assert.AreEqual (module, bar.Module); - Assert.AreEqual (1, bar.NestedTypes.Count); + Assert.AreEqual ("Bar", bar.Name); + Assert.AreEqual ("Foo/Bar", bar.FullName); + Assert.AreEqual (module, bar.Module); + Assert.AreEqual (1, bar.NestedTypes.Count); - var baz = bar.NestedTypes [0]; + var baz = bar.NestedTypes [0]; - Assert.AreEqual ("Baz", baz.Name); - Assert.AreEqual ("Foo/Bar/Baz", baz.FullName); - Assert.AreEqual (module, baz.Module); + Assert.AreEqual ("Baz", baz.Name); + Assert.AreEqual ("Foo/Bar/Baz", baz.FullName); + Assert.AreEqual (module, baz.Module); + }); } - [TestCSharp ("NestedTypes.cs")] - public void DirectNestedType (ModuleDefinition module) + [Test] + public void DirectNestedType () { - var bingo = module.GetType ("Bingo"); - var get_fuel = bingo.GetMethod ("GetFuel"); + TestCSharp ("NestedTypes.cs", module => { + var bingo = module.GetType ("Bingo"); + var get_fuel = bingo.GetMethod ("GetFuel"); - Assert.AreEqual ("Bingo/Fuel", get_fuel.ReturnType.FullName); + Assert.AreEqual ("Bingo/Fuel", get_fuel.ReturnType.FullName); + }); + } + + [Test] + public void NestedTypeWithOwnNamespace () + { + TestModule ("bug-185.dll", module => { + var foo = module.GetType ("Foo"); + var foo_child = foo.NestedTypes [0]; + + Assert.AreEqual ("<IFoo<System.Byte[]>", foo_child.Namespace); + Assert.AreEqual ("Do>d__0", foo_child.Name); + + Assert.AreEqual ("Foo/<IFoo<System.Byte[]>.Do>d__0", foo_child.FullName); + }); } } } diff --git a/Test/Mono.Cecil.Tests/ParameterTests.cs b/Test/Mono.Cecil.Tests/ParameterTests.cs index 124d7e1..5ec3e06 100644 --- a/Test/Mono.Cecil.Tests/ParameterTests.cs +++ b/Test/Mono.Cecil.Tests/ParameterTests.cs @@ -1,8 +1,4 @@ using System; -using System.Linq; - -using Mono.Cecil; -using Mono.Cecil.Metadata; using NUnit.Framework; @@ -11,107 +7,136 @@ namespace Mono.Cecil.Tests { [TestFixture] public class ParameterTests : BaseTestFixture { - [TestModule ("marshal.dll")] - public void MarshalAsI4 (ModuleDefinition module) + [Test] + public void MarshalAsI4 () { - var bar = module.GetType ("Bar"); - var pan = bar.GetMethod ("Pan"); + TestModule ("marshal.dll", module => { + var bar = module.GetType ("Bar"); + var pan = bar.GetMethod ("Pan"); - Assert.AreEqual (1, pan.Parameters.Count); + Assert.AreEqual (1, pan.Parameters.Count); - var parameter = pan.Parameters [0]; + var parameter = pan.Parameters [0]; - Assert.IsTrue (parameter.HasMarshalInfo); - var info = parameter.MarshalInfo; + Assert.IsTrue (parameter.HasMarshalInfo); + var info = parameter.MarshalInfo; - Assert.AreEqual (typeof (MarshalInfo), info.GetType ()); - Assert.AreEqual (NativeType.I4, info.NativeType); + Assert.AreEqual (typeof (MarshalInfo), info.GetType ()); + Assert.AreEqual (NativeType.I4, info.NativeType); + }); } - [TestModule ("marshal.dll")] - public void CustomMarshaler (ModuleDefinition module) + [Test] + public void CustomMarshaler () { - var bar = module.GetType ("Bar"); - var pan = bar.GetMethod ("PanPan"); + TestModule ("marshal.dll", module => { + var bar = module.GetType ("Bar"); + var pan = bar.GetMethod ("PanPan"); - var parameter = pan.Parameters [0]; + var parameter = pan.Parameters [0]; - Assert.IsTrue (parameter.HasMarshalInfo); + Assert.IsTrue (parameter.HasMarshalInfo); - var info = (CustomMarshalInfo) parameter.MarshalInfo; + var info = (CustomMarshalInfo) parameter.MarshalInfo; - Assert.AreEqual (Guid.Empty, info.Guid); - Assert.AreEqual (string.Empty, info.UnmanagedType); - Assert.AreEqual (NativeType.CustomMarshaler, info.NativeType); - Assert.AreEqual ("nomnom", info.Cookie); + Assert.AreEqual (Guid.Empty, info.Guid); + Assert.AreEqual (string.Empty, info.UnmanagedType); + Assert.AreEqual (NativeType.CustomMarshaler, info.NativeType); + Assert.AreEqual ("nomnom", info.Cookie); - Assert.AreEqual ("Boc", info.ManagedType.FullName); - Assert.AreEqual (module, info.ManagedType.Scope); + Assert.AreEqual ("Boc", info.ManagedType.FullName); + Assert.AreEqual (module, info.ManagedType.Scope); + }); } - [TestModule ("marshal.dll")] - public void SafeArrayMarshaler (ModuleDefinition module) + [Test] + public void SafeArrayMarshaler () { - var bar = module.GetType ("Bar"); - var pan = bar.GetMethod ("PanPan"); + TestModule ("marshal.dll", module => { + var bar = module.GetType ("Bar"); + var pan = bar.GetMethod ("PanPan"); - Assert.IsTrue (pan.MethodReturnType.HasMarshalInfo); + Assert.IsTrue (pan.MethodReturnType.HasMarshalInfo); - var info = (SafeArrayMarshalInfo) pan.MethodReturnType.MarshalInfo; + var info = (SafeArrayMarshalInfo) pan.MethodReturnType.MarshalInfo; - Assert.AreEqual (VariantType.Dispatch, info.ElementType); + Assert.AreEqual (VariantType.Dispatch, info.ElementType); + }); } - [TestModule ("marshal.dll")] - public void ArrayMarshaler (ModuleDefinition module) + [Test] + public void ArrayMarshaler () { - var bar = module.GetType ("Bar"); - var pan = bar.GetMethod ("PanPan"); + TestModule ("marshal.dll", module => { + var bar = module.GetType ("Bar"); + var pan = bar.GetMethod ("PanPan"); - var parameter = pan.Parameters [1]; + var parameter = pan.Parameters [1]; - Assert.IsTrue (parameter.HasMarshalInfo); + Assert.IsTrue (parameter.HasMarshalInfo); - var info = (ArrayMarshalInfo) parameter.MarshalInfo; + var info = (ArrayMarshalInfo) parameter.MarshalInfo; - Assert.AreEqual (NativeType.I8, info.ElementType); - Assert.AreEqual (66, info.Size); - Assert.AreEqual (2, info.SizeParameterIndex); + Assert.AreEqual (NativeType.I8, info.ElementType); + Assert.AreEqual (66, info.Size); + Assert.AreEqual (2, info.SizeParameterIndex); - parameter = pan.Parameters [3]; + parameter = pan.Parameters [3]; - Assert.IsTrue (parameter.HasMarshalInfo); + Assert.IsTrue (parameter.HasMarshalInfo); - info = (ArrayMarshalInfo) parameter.MarshalInfo; + info = (ArrayMarshalInfo) parameter.MarshalInfo; - Assert.AreEqual (NativeType.I2, info.ElementType); - Assert.AreEqual (-1, info.Size); - Assert.AreEqual (-1, info.SizeParameterIndex); + Assert.AreEqual (NativeType.I2, info.ElementType); + Assert.AreEqual (-1, info.Size); + Assert.AreEqual (-1, info.SizeParameterIndex); + }); } - [TestModule ("marshal.dll")] - public void ArrayMarshalerSized (ModuleDefinition module) + [Test] + public void ArrayMarshalerSized () { - var delegate_type = module.GetType ("SomeMethod"); - var parameter = delegate_type.GetMethod ("Invoke").Parameters [1]; + TestModule ("marshal.dll", module => { + var delegate_type = module.GetType ("SomeMethod"); + var parameter = delegate_type.GetMethod ("Invoke").Parameters [1]; - Assert.IsTrue (parameter.HasMarshalInfo); - var array_info = (ArrayMarshalInfo) parameter.MarshalInfo; + Assert.IsTrue (parameter.HasMarshalInfo); + var array_info = (ArrayMarshalInfo) parameter.MarshalInfo; - Assert.IsNotNull (array_info); + Assert.IsNotNull (array_info); - Assert.AreEqual (0, array_info.SizeParameterMultiplier); + Assert.AreEqual (0, array_info.SizeParameterMultiplier); + }); } - [TestModule ("boxedoptarg.dll")] - public void BoxedDefaultArgumentValue (ModuleDefinition module) + [Test] + public void NullableConstant () { - var foo = module.GetType ("Foo"); - var bar = foo.GetMethod ("Bar"); - var baz = bar.Parameters [0]; + TestModule ("nullable-constant.exe", module => { + var type = module.GetType ("Program"); + var method = type.GetMethod ("Foo"); + + Assert.IsTrue (method.Parameters [0].HasConstant); + Assert.IsTrue (method.Parameters [1].HasConstant); + Assert.IsTrue (method.Parameters [2].HasConstant); + + Assert.AreEqual (1234, method.Parameters [0].Constant); + Assert.AreEqual (null, method.Parameters [1].Constant); + Assert.AreEqual (12, method.Parameters [2].Constant); + }); + } - Assert.IsTrue (baz.HasConstant); - Assert.AreEqual (-1, baz.Constant); + [Test] + public void BoxedDefaultArgumentValue () + { + TestModule ("boxedoptarg.dll", module => { + var foo = module.GetType ("Foo"); + var bar = foo.GetMethod ("Bar"); + var baz = bar.Parameters [0]; + + Assert.IsTrue (baz.HasConstant); + Assert.AreEqual (-1, baz.Constant); + }); } [Test] @@ -207,18 +232,43 @@ namespace Mono.Cecil.Tests { Assert.AreEqual (2, z.Index); } - [TestIL ("hello.il")] - public void GenericParameterConstant (ModuleDefinition module) + [Test] + public void GenericParameterConstant () { - var foo = module.GetType ("Foo"); - var method = foo.GetMethod ("GetState"); + TestIL ("hello.il", module => { + var foo = module.GetType ("Foo"); + var method = foo.GetMethod ("GetState"); + + Assert.IsNotNull (method); + + var parameter = method.Parameters [1]; + + Assert.IsTrue (parameter.HasConstant); + Assert.IsNull (parameter.Constant); + }); + } + + [Test] + public void NullablePrimitiveParameterConstant () + { + TestModule ("nullable-parameter.dll", module => { + var test = module.GetType ("Test"); + var method = test.GetMethod ("Foo"); + + Assert.IsNotNull (method); - Assert.IsNotNull (method); + var param = method.Parameters [0]; + Assert.IsTrue (param.HasConstant); + Assert.AreEqual (1234, param.Constant); - var parameter = method.Parameters [1]; + param = method.Parameters [1]; + Assert.IsTrue (param.HasConstant); + Assert.AreEqual (null, param.Constant); - Assert.IsTrue (parameter.HasConstant); - Assert.IsNull (parameter.Constant); + param = method.Parameters [2]; + Assert.IsTrue (param.HasConstant); + Assert.AreEqual (12, param.Constant); + }); } } } diff --git a/Test/Mono.Cecil.Tests/PropertyTests.cs b/Test/Mono.Cecil.Tests/PropertyTests.cs index 2ff9c92..587868f 100644 --- a/Test/Mono.Cecil.Tests/PropertyTests.cs +++ b/Test/Mono.Cecil.Tests/PropertyTests.cs @@ -7,106 +7,122 @@ namespace Mono.Cecil.Tests { [TestFixture] public class PropertyTests : BaseTestFixture { - [TestCSharp ("Properties.cs")] - public void AbstractMethod (ModuleDefinition module) + [Test] + public void AbstractMethod () { - var type = module.GetType ("Foo"); + TestCSharp ("Properties.cs", module => { + var type = module.GetType ("Foo"); - Assert.IsTrue (type.HasProperties); + Assert.IsTrue (type.HasProperties); - var properties = type.Properties; + var properties = type.Properties; - Assert.AreEqual (3, properties.Count); + Assert.AreEqual (3, properties.Count); - var property = properties [0]; + var property = properties [0]; - Assert.IsNotNull (property); - Assert.AreEqual ("Bar", property.Name); - Assert.IsNotNull (property.PropertyType); - Assert.AreEqual ("System.Int32", property.PropertyType.FullName); + Assert.IsNotNull (property); + Assert.AreEqual ("Bar", property.Name); + Assert.IsNotNull (property.PropertyType); + Assert.AreEqual ("System.Int32", property.PropertyType.FullName); - Assert.IsNotNull (property.GetMethod); - Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes); - Assert.IsNull (property.SetMethod); + Assert.IsNotNull (property.GetMethod); + Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes); + Assert.IsNull (property.SetMethod); - property = properties [1]; + property = properties [1]; - Assert.IsNotNull (property); - Assert.AreEqual ("Baz", property.Name); - Assert.IsNotNull (property.PropertyType); - Assert.AreEqual ("System.String", property.PropertyType.FullName); + Assert.IsNotNull (property); + Assert.AreEqual ("Baz", property.Name); + Assert.IsNotNull (property.PropertyType); + Assert.AreEqual ("System.String", property.PropertyType.FullName); - Assert.IsNotNull (property.GetMethod); - Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes); - Assert.IsNotNull (property.SetMethod); - Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes); + Assert.IsNotNull (property.GetMethod); + Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes); + Assert.IsNotNull (property.SetMethod); + Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes); - property = properties [2]; + property = properties [2]; - Assert.IsNotNull (property); - Assert.AreEqual ("Gazonk", property.Name); - Assert.IsNotNull (property.PropertyType); - Assert.AreEqual ("System.String", property.PropertyType.FullName); + Assert.IsNotNull (property); + Assert.AreEqual ("Gazonk", property.Name); + Assert.IsNotNull (property.PropertyType); + Assert.AreEqual ("System.String", property.PropertyType.FullName); - Assert.IsNull (property.GetMethod); - Assert.IsNotNull (property.SetMethod); - Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes); + Assert.IsNull (property.GetMethod); + Assert.IsNotNull (property.SetMethod); + Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes); + }); } - [TestIL ("others.il")] - public void OtherMethod (ModuleDefinition module) + [Test] + public void OtherMethod () { - var type = module.GetType ("Others"); + TestIL ("others.il", module => { + var type = module.GetType ("Others"); - Assert.IsTrue (type.HasProperties); + Assert.IsTrue (type.HasProperties); - var properties = type.Properties; + var properties = type.Properties; - Assert.AreEqual (1, properties.Count); + Assert.AreEqual (1, properties.Count); - var property = properties [0]; + var property = properties [0]; - Assert.IsNotNull (property); - Assert.AreEqual ("Context", property.Name); - Assert.IsNotNull (property.PropertyType); - Assert.AreEqual ("System.String", property.PropertyType.FullName); + Assert.IsNotNull (property); + Assert.AreEqual ("Context", property.Name); + Assert.IsNotNull (property.PropertyType); + Assert.AreEqual ("System.String", property.PropertyType.FullName); - Assert.IsTrue (property.HasOtherMethods); + Assert.IsTrue (property.HasOtherMethods); - Assert.AreEqual (2, property.OtherMethods.Count); + Assert.AreEqual (2, property.OtherMethods.Count); - var other = property.OtherMethods [0]; - Assert.AreEqual ("let_Context", other.Name); + var other = property.OtherMethods [0]; + Assert.AreEqual ("let_Context", other.Name); - other = property.OtherMethods [1]; - Assert.AreEqual ("bet_Context", other.Name); + other = property.OtherMethods [1]; + Assert.AreEqual ("bet_Context", other.Name); + }); } - [TestCSharp ("Properties.cs")] - public void SetOnlyIndexer (ModuleDefinition module) + [Test] + public void SetOnlyIndexer () { - var type = module.GetType ("Bar"); - var indexer = type.Properties.Where (property => property.Name == "Item").First (); + TestCSharp ("Properties.cs", module => { + var type = module.GetType ("Bar"); + var indexer = type.Properties.Where (property => property.Name == "Item").First (); - var parameters = indexer.Parameters; + var parameters = indexer.Parameters; - Assert.AreEqual (2, parameters.Count); - Assert.AreEqual ("System.Int32", parameters [0].ParameterType.FullName); - Assert.AreEqual ("System.String", parameters [1].ParameterType.FullName); + Assert.AreEqual (2, parameters.Count); + Assert.AreEqual ("System.Int32", parameters [0].ParameterType.FullName); + Assert.AreEqual ("System.String", parameters [1].ParameterType.FullName); + }); } - [TestCSharp ("Properties.cs")] - public void ReadSemanticsFirst (ModuleDefinition module) + [Test] + public void ReadSemanticsFirst () { - var type = module.GetType ("Baz"); - var setter = type.GetMethod ("set_Bingo"); + TestCSharp ("Properties.cs", module => { + var type = module.GetType ("Baz"); + var setter = type.GetMethod ("set_Bingo"); + + Assert.AreEqual (MethodSemanticsAttributes.Setter, setter.SemanticsAttributes); + + var property = type.Properties.Where (p => p.Name == "Bingo").First (); - Assert.AreEqual (MethodSemanticsAttributes.Setter, setter.SemanticsAttributes); + Assert.AreEqual (setter, property.SetMethod); + Assert.AreEqual (type.GetMethod ("get_Bingo"), property.GetMethod); + }); + } - var property = type.Properties.Where (p => p.Name == "Bingo").First (); + [Test] + public void UnattachedProperty () + { + var property = new PropertyDefinition ("Property", PropertyAttributes.None, typeof (int).ToDefinition ()); - Assert.AreEqual (setter, property.SetMethod); - Assert.AreEqual (type.GetMethod ("get_Bingo"), property.GetMethod); + Assert.IsNull (property.GetMethod); } } } diff --git a/Test/Mono.Cecil.Tests/ResolveTests.cs b/Test/Mono.Cecil.Tests/ResolveTests.cs index ca0cd56..02eeb8c 100644 --- a/Test/Mono.Cecil.Tests/ResolveTests.cs +++ b/Test/Mono.Cecil.Tests/ResolveTests.cs @@ -212,7 +212,22 @@ namespace Mono.Cecil.Tests { Assert.IsNotNull (resolver.Resolve (reference)); } - static TRet GetReference<TDel, TRet> (TDel code) + [Test] + public void ResolvePortableClassLibraryReference () + { + var resolver = new DefaultAssemblyResolver (); + var parameters = new ReaderParameters { AssemblyResolver = resolver }; + var pcl = GetResourceModule ("PortableClassLibrary.dll", parameters); + + foreach (var reference in pcl.AssemblyReferences) { + Assert.IsTrue (reference.IsRetargetable); + var assembly = resolver.Resolve (reference); + Assert.IsNotNull (assembly); + Assert.AreEqual (typeof (object).Assembly.GetName ().Version, assembly.Name.Version); + } + } + + TRet GetReference<TDel, TRet> (TDel code) { var @delegate = code as Delegate; if (@delegate == null) @@ -250,7 +265,7 @@ namespace Mono.Cecil.Tests { throw new InvalidOperationException (); } - static MethodDefinition GetMethodFromDelegate (Delegate @delegate) + MethodDefinition GetMethodFromDelegate (Delegate @delegate) { var method = @delegate.Method; var type = (TypeDefinition) TypeParser.ParseType (GetCurrentModule (), method.DeclaringType.FullName); diff --git a/Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs b/Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs index 2cc8d5b..3939502 100644 --- a/Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs +++ b/Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs @@ -15,78 +15,82 @@ namespace Mono.Cecil.Tests { [TestFixture] public class SecurityDeclarationTests : BaseTestFixture { - [TestModule ("decsec-xml.dll")] - public void XmlSecurityDeclaration (ModuleDefinition module) + [Test] + public void XmlSecurityDeclaration () { - var type = module.GetType ("SubLibrary"); + TestModule ("decsec-xml.dll", module => { + var type = module.GetType ("SubLibrary"); - Assert.IsTrue (type.HasSecurityDeclarations); + Assert.IsTrue (type.HasSecurityDeclarations); - Assert.AreEqual (1, type.SecurityDeclarations.Count); + Assert.AreEqual (1, type.SecurityDeclarations.Count); - var declaration = type.SecurityDeclarations [0]; - Assert.AreEqual (SecurityAction.Deny, declaration.Action); + var declaration = type.SecurityDeclarations [0]; + Assert.AreEqual (SecurityAction.Deny, declaration.Action); - Assert.AreEqual (1, declaration.SecurityAttributes.Count); + Assert.AreEqual (1, declaration.SecurityAttributes.Count); - var attribute = declaration.SecurityAttributes [0]; + var attribute = declaration.SecurityAttributes [0]; - Assert.AreEqual ("System.Security.Permissions.PermissionSetAttribute", attribute.AttributeType.FullName); + Assert.AreEqual ("System.Security.Permissions.PermissionSetAttribute", attribute.AttributeType.FullName); - Assert.AreEqual (1, attribute.Properties.Count); + Assert.AreEqual (1, attribute.Properties.Count); - var named_argument = attribute.Properties [0]; + var named_argument = attribute.Properties [0]; - Assert.AreEqual ("XML", named_argument.Name); + Assert.AreEqual ("XML", named_argument.Name); - var argument = named_argument.Argument; + var argument = named_argument.Argument; - Assert.AreEqual ("System.String", argument.Type.FullName); + Assert.AreEqual ("System.String", argument.Type.FullName); - const string permission_set = "<PermissionSet class=\"System.Security.PermissionSe" + const string permission_set = "<PermissionSet class=\"System.Security.PermissionSe" + "t\"\r\nversion=\"1\">\r\n<IPermission class=\"System.Security.Permis" + "sions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture" + "=neutral, PublicKeyToken=b77a5c561934e089\"\r\nversion=\"1\"\r\nFla" + "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n"; - Assert.AreEqual (permission_set, argument.Value); + Assert.AreEqual (permission_set, argument.Value); + }); } - [TestModule ("decsec1-xml.dll")] - public void XmlNet_1_1SecurityDeclaration (ModuleDefinition module) + [Test] + public void XmlNet_1_1SecurityDeclaration () { - var type = module.GetType ("SubLibrary"); + TestModule ("decsec1-xml.dll", module => { + var type = module.GetType ("SubLibrary"); - Assert.IsTrue (type.HasSecurityDeclarations); + Assert.IsTrue (type.HasSecurityDeclarations); - Assert.AreEqual (1, type.SecurityDeclarations.Count); + Assert.AreEqual (1, type.SecurityDeclarations.Count); - var declaration = type.SecurityDeclarations [0]; - Assert.AreEqual (SecurityAction.Deny, declaration.Action); + var declaration = type.SecurityDeclarations [0]; + Assert.AreEqual (SecurityAction.Deny, declaration.Action); - Assert.AreEqual (1, declaration.SecurityAttributes.Count); + Assert.AreEqual (1, declaration.SecurityAttributes.Count); - var attribute = declaration.SecurityAttributes [0]; + var attribute = declaration.SecurityAttributes [0]; - Assert.AreEqual ("System.Security.Permissions.PermissionSetAttribute", attribute.AttributeType.FullName); + Assert.AreEqual ("System.Security.Permissions.PermissionSetAttribute", attribute.AttributeType.FullName); - Assert.AreEqual (1, attribute.Properties.Count); + Assert.AreEqual (1, attribute.Properties.Count); - var named_argument = attribute.Properties [0]; + var named_argument = attribute.Properties [0]; - Assert.AreEqual ("XML", named_argument.Name); + Assert.AreEqual ("XML", named_argument.Name); - var argument = named_argument.Argument; + var argument = named_argument.Argument; - Assert.AreEqual ("System.String", argument.Type.FullName); + Assert.AreEqual ("System.String", argument.Type.FullName); - const string permission_set = "<PermissionSet class=\"System.Security.PermissionSe" + const string permission_set = "<PermissionSet class=\"System.Security.PermissionSe" + "t\"\r\nversion=\"1\">\r\n<IPermission class=\"System.Security.Permis" + "sions.SecurityPermission, mscorlib, Version=1.0.0.0, Culture" + "=neutral, PublicKeyToken=b77a5c561934e089\"\r\nversion=\"1\"\r\nFla" + "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n"; - Assert.AreEqual (permission_set, argument.Value); + Assert.AreEqual (permission_set, argument.Value); + }); } [Test] @@ -122,55 +126,59 @@ namespace Mono.Cecil.Tests { Assert.AreEqual (permission_set, argument.Value); } - [TestModule ("empty-decsec-att.dll")] - public void SecurityDeclarationWithoutAttributes (ModuleDefinition module) + [Test] + public void SecurityDeclarationWithoutAttributes () { - var type = module.GetType ("TestSecurityAction.ModalUITypeEditor"); - var method = type.GetMethod ("GetEditStyle"); + TestModule ("empty-decsec-att.dll", module => { + var type = module.GetType ("TestSecurityAction.ModalUITypeEditor"); + var method = type.GetMethod ("GetEditStyle"); - Assert.IsNotNull (method); + Assert.IsNotNull (method); - Assert.AreEqual (1, method.SecurityDeclarations.Count); + Assert.AreEqual (1, method.SecurityDeclarations.Count); - var declaration = method.SecurityDeclarations [0]; - Assert.AreEqual (SecurityAction.LinkDemand, declaration.Action); - Assert.AreEqual (1, declaration.SecurityAttributes.Count); + var declaration = method.SecurityDeclarations [0]; + Assert.AreEqual (SecurityAction.LinkDemand, declaration.Action); + Assert.AreEqual (1, declaration.SecurityAttributes.Count); - var attribute = declaration.SecurityAttributes [0]; - Assert.AreEqual ("System.Security.Permissions.SecurityPermissionAttribute", attribute.AttributeType.FullName); - Assert.AreEqual (0, attribute.Fields.Count); - Assert.AreEqual (0, attribute.Properties.Count); + var attribute = declaration.SecurityAttributes [0]; + Assert.AreEqual ("System.Security.Permissions.SecurityPermissionAttribute", attribute.AttributeType.FullName); + Assert.AreEqual (0, attribute.Fields.Count); + Assert.AreEqual (0, attribute.Properties.Count); + }); } - [TestModule ("decsec-att.dll")] - public void AttributeSecurityDeclaration (ModuleDefinition module) + [Test] + public void AttributeSecurityDeclaration () { - var type = module.GetType ("SubLibrary"); + TestModule ("decsec-att.dll", module => { + var type = module.GetType ("SubLibrary"); - Assert.IsTrue (type.HasSecurityDeclarations); + Assert.IsTrue (type.HasSecurityDeclarations); - Assert.AreEqual (1, type.SecurityDeclarations.Count); + Assert.AreEqual (1, type.SecurityDeclarations.Count); - var declaration = type.SecurityDeclarations [0]; - Assert.AreEqual (SecurityAction.Deny, declaration.Action); + var declaration = type.SecurityDeclarations [0]; + Assert.AreEqual (SecurityAction.Deny, declaration.Action); - Assert.AreEqual (1, declaration.SecurityAttributes.Count); + Assert.AreEqual (1, declaration.SecurityAttributes.Count); - var attribute = declaration.SecurityAttributes [0]; + var attribute = declaration.SecurityAttributes [0]; - Assert.AreEqual ("System.Security.Permissions.SecurityPermissionAttribute", attribute.AttributeType.FullName); + Assert.AreEqual ("System.Security.Permissions.SecurityPermissionAttribute", attribute.AttributeType.FullName); - Assert.AreEqual (1, attribute.Properties.Count); + Assert.AreEqual (1, attribute.Properties.Count); - var named_argument = attribute.Properties [0]; + var named_argument = attribute.Properties [0]; - Assert.AreEqual ("UnmanagedCode", named_argument.Name); + Assert.AreEqual ("UnmanagedCode", named_argument.Name); - var argument = named_argument.Argument; + var argument = named_argument.Argument; - Assert.AreEqual ("System.Boolean", argument.Type.FullName); + Assert.AreEqual ("System.Boolean", argument.Type.FullName); - Assert.AreEqual (true, argument.Value); + Assert.AreEqual (true, argument.Value); + }); } static void AssertCustomAttributeArgument (string expected, CustomAttributeNamedArgument named_argument) diff --git a/Test/Mono.Cecil.Tests/TypeTests.cs b/Test/Mono.Cecil.Tests/TypeTests.cs index 82e025b..1e6cb82 100644 --- a/Test/Mono.Cecil.Tests/TypeTests.cs +++ b/Test/Mono.Cecil.Tests/TypeTests.cs @@ -12,188 +12,243 @@ namespace Mono.Cecil.Tests { [TestFixture] public class TypeTests : BaseTestFixture { - [TestCSharp ("Layouts.cs")] - public void TypeLayout (ModuleDefinition module) + [Test] + public void TypeLayout () { - var foo = module.GetType ("Foo"); - Assert.IsNotNull (foo); - Assert.IsTrue (foo.IsValueType); - - Assert.IsTrue (foo.HasLayoutInfo); - Assert.AreEqual (16, foo.ClassSize); - - var babar = module.GetType ("Babar"); - Assert.IsNotNull (babar); - Assert.IsFalse (babar.IsValueType); - Assert.IsFalse (babar.HasLayoutInfo); + TestCSharp ("Layouts.cs", module => { + var foo = module.GetType ("Foo"); + Assert.IsNotNull (foo); + Assert.IsTrue (foo.IsValueType); + + Assert.IsTrue (foo.HasLayoutInfo); + Assert.AreEqual (16, foo.ClassSize); + + var babar = module.GetType ("Babar"); + Assert.IsNotNull (babar); + Assert.IsFalse (babar.IsValueType); + Assert.IsFalse (babar.HasLayoutInfo); + }); } - [TestIL ("types.il")] - public void SimpleInterfaces (ModuleDefinition module) + [Test] + public void SimpleInterfaces () { - var ibaz = module.GetType ("IBaz"); - Assert.IsNotNull (ibaz); + TestIL ("types.il", module => { + var ibaz = module.GetType ("IBaz"); + Assert.IsNotNull (ibaz); - Assert.IsTrue (ibaz.HasInterfaces); + Assert.IsTrue (ibaz.HasInterfaces); - var interfaces = ibaz.Interfaces; + var interfaces = ibaz.Interfaces; - Assert.AreEqual (2, interfaces.Count); + Assert.AreEqual (2, interfaces.Count); - Assert.AreEqual ("IBar", interfaces [0].FullName); - Assert.AreEqual ("IFoo", interfaces [1].FullName); + Assert.AreEqual ("IBar", interfaces [0].FullName); + Assert.AreEqual ("IFoo", interfaces [1].FullName); + }); } - [TestCSharp ("Generics.cs")] - public void GenericTypeDefinition (ModuleDefinition module) + [Test] + public void GenericTypeDefinition () { - var foo = module.GetType ("Foo`2"); - Assert.IsNotNull (foo); + TestCSharp ("Generics.cs", module => { + var foo = module.GetType ("Foo`2"); + Assert.IsNotNull (foo); - Assert.IsTrue (foo.HasGenericParameters); - Assert.AreEqual (2, foo.GenericParameters.Count); + Assert.IsTrue (foo.HasGenericParameters); + Assert.AreEqual (2, foo.GenericParameters.Count); - var tbar = foo.GenericParameters [0]; + var tbar = foo.GenericParameters [0]; - Assert.AreEqual ("TBar", tbar.Name); - Assert.AreEqual (foo, tbar.Owner); + Assert.AreEqual ("TBar", tbar.Name); + Assert.AreEqual (foo, tbar.Owner); - var tbaz = foo.GenericParameters [1]; + var tbaz = foo.GenericParameters [1]; - Assert.AreEqual ("TBaz", tbaz.Name); - Assert.AreEqual (foo, tbaz.Owner); + Assert.AreEqual ("TBaz", tbaz.Name); + Assert.AreEqual (foo, tbaz.Owner); + }); } - [TestCSharp ("Generics.cs")] - public void ConstrainedGenericType (ModuleDefinition module) + [Test] + public void ConstrainedGenericType () { - var bongo_t = module.GetType ("Bongo`1"); - Assert.IsNotNull (bongo_t); + TestCSharp ("Generics.cs", module => { + var bongo_t = module.GetType ("Bongo`1"); + Assert.IsNotNull (bongo_t); - var t = bongo_t.GenericParameters [0]; - Assert.IsNotNull (t); - Assert.AreEqual ("T", t.Name); + var t = bongo_t.GenericParameters [0]; + Assert.IsNotNull (t); + Assert.AreEqual ("T", t.Name); - Assert.IsTrue (t.HasConstraints); - Assert.AreEqual (2, t.Constraints.Count); + Assert.IsTrue (t.HasConstraints); + Assert.AreEqual (2, t.Constraints.Count); - Assert.AreEqual ("Zap", t.Constraints [0].FullName); - Assert.AreEqual ("IZoom", t.Constraints [1].FullName); + Assert.AreEqual ("Zap", t.Constraints [0].FullName); + Assert.AreEqual ("IZoom", t.Constraints [1].FullName); + }); } - [TestCSharp ("Generics.cs")] - public void GenericBaseType (ModuleDefinition module) + [Test] + public void GenericBaseType () { - var child = module.GetType ("Child`1"); + TestCSharp ("Generics.cs", module => { + var child = module.GetType ("Child`1"); - var child_t = child.GenericParameters [0]; - Assert.IsNotNull (child_t); + var child_t = child.GenericParameters [0]; + Assert.IsNotNull (child_t); - var instance = child.BaseType as GenericInstanceType; - Assert.IsNotNull (instance); - Assert.AreNotEqual (0, instance.MetadataToken.RID); + var instance = child.BaseType as GenericInstanceType; + Assert.IsNotNull (instance); + Assert.AreNotEqual (0, instance.MetadataToken.RID); - Assert.AreEqual (child_t, instance.GenericArguments [0]); + Assert.AreEqual (child_t, instance.GenericArguments [0]); + }); } - [TestCSharp ("Generics.cs")] - public void GenericConstraintOnGenericParameter (ModuleDefinition module) + [Test] + public void GenericConstraintOnGenericParameter () { - var duel = module.GetType ("Duel`3"); + TestCSharp ("Generics.cs", module => { + var duel = module.GetType ("Duel`3"); - Assert.AreEqual (3, duel.GenericParameters.Count); + Assert.AreEqual (3, duel.GenericParameters.Count); - var t1 = duel.GenericParameters [0]; - var t2 = duel.GenericParameters [1]; - var t3 = duel.GenericParameters [2]; + var t1 = duel.GenericParameters [0]; + var t2 = duel.GenericParameters [1]; + var t3 = duel.GenericParameters [2]; - Assert.AreEqual (t1, t2.Constraints [0]); - Assert.AreEqual (t2, t3.Constraints [0]); + Assert.AreEqual (t1, t2.Constraints [0]); + Assert.AreEqual (t2, t3.Constraints [0]); + }); } - [TestCSharp ("Generics.cs")] - public void GenericForwardBaseType (ModuleDefinition module) + [Test] + public void GenericForwardBaseType () { - var tamchild = module.GetType ("TamChild"); + TestCSharp ("Generics.cs", module => { + var tamchild = module.GetType ("TamChild"); - Assert.IsNotNull (tamchild); - Assert.IsNotNull (tamchild.BaseType); + Assert.IsNotNull (tamchild); + Assert.IsNotNull (tamchild.BaseType); - var generic_instance = tamchild.BaseType as GenericInstanceType; + var generic_instance = tamchild.BaseType as GenericInstanceType; - Assert.IsNotNull (generic_instance); + Assert.IsNotNull (generic_instance); - Assert.AreEqual (1, generic_instance.GenericArguments.Count); - Assert.AreEqual (module.GetType ("Tamtam"), generic_instance.GenericArguments [0]); + Assert.AreEqual (1, generic_instance.GenericArguments.Count); + Assert.AreEqual (module.GetType ("Tamtam"), generic_instance.GenericArguments [0]); + }); } - [TestCSharp ("Generics.cs")] - public void TypeExtentingGenericOfSelf (ModuleDefinition module) + [Test] + public void TypeExtentingGenericOfSelf () { - var rec_child = module.GetType ("RecChild"); + TestCSharp ("Generics.cs", module => { + var rec_child = module.GetType ("RecChild"); - Assert.IsNotNull (rec_child); - Assert.IsNotNull (rec_child.BaseType); + Assert.IsNotNull (rec_child); + Assert.IsNotNull (rec_child.BaseType); - var generic_instance = rec_child.BaseType as GenericInstanceType; + var generic_instance = rec_child.BaseType as GenericInstanceType; - Assert.IsNotNull (generic_instance); + Assert.IsNotNull (generic_instance); - Assert.AreEqual (1, generic_instance.GenericArguments.Count); - Assert.AreEqual (rec_child, generic_instance.GenericArguments [0]); + Assert.AreEqual (1, generic_instance.GenericArguments.Count); + Assert.AreEqual (rec_child, generic_instance.GenericArguments [0]); + }); } - [TestCSharp ("Methods.cs")] - public void TypeReferenceValueType (ModuleDefinition module) + [Test] + public void TypeReferenceValueType () { - var baz = module.GetType ("Baz"); - var method = baz.GetMethod ("PrintAnswer"); + TestCSharp ("Methods.cs", module => { + var baz = module.GetType ("Baz"); + var method = baz.GetMethod ("PrintAnswer"); - var box = method.Body.Instructions.Where (i => i.OpCode == OpCodes.Box).First (); - var int32 = (TypeReference) box.Operand; + var box = method.Body.Instructions.Where (i => i.OpCode == OpCodes.Box).First (); + var int32 = (TypeReference) box.Operand; - Assert.IsTrue (int32.IsValueType); + Assert.IsTrue (int32.IsValueType); + }); } - [TestModule ("gifaceref.exe")] - public void GenericInterfaceReference (ModuleDefinition module) + [Test] + public void GenericInterfaceReference () { - var type = module.GetType ("Program"); - var iface = type.Interfaces [0]; + TestModule ("gifaceref.exe", module => { + var type = module.GetType ("Program"); + var iface = type.Interfaces [0]; - var instance = (GenericInstanceType) iface; - var owner = instance.ElementType; + var instance = (GenericInstanceType) iface; + var owner = instance.ElementType; - Assert.AreEqual (1, instance.GenericArguments.Count); - Assert.AreEqual (1, owner.GenericParameters.Count); + Assert.AreEqual (1, instance.GenericArguments.Count); + Assert.AreEqual (1, owner.GenericParameters.Count); + }); } - [TestModule ("cscgpbug.dll", Verify = false)] - public void UnboundGenericParameter (ModuleDefinition module) + [Test] + public void UnboundGenericParameter () { - var type = module.GetType ("ListViewModel"); - var method = type.GetMethod ("<>n__FabricatedMethod1"); + TestModule ("cscgpbug.dll", module => { + var type = module.GetType ("ListViewModel"); + var method = type.GetMethod ("<>n__FabricatedMethod1"); - var parameter = method.ReturnType as GenericParameter; + var parameter = method.ReturnType as GenericParameter; + + Assert.IsNotNull (parameter); + Assert.AreEqual (0, parameter.Position); + Assert.IsNull (parameter.Owner); + }, verify: false); + } - Assert.IsNotNull (parameter); - Assert.AreEqual (0, parameter.Position); - Assert.IsNull (parameter.Owner); + [Test] + public void GenericMultidimensionalArray () + { + TestCSharp ("Generics.cs", module => { + var type = module.GetType ("LaMatrix"); + var method = type.GetMethod ("At"); + + var call = method.Body.Instructions.Where (i => i.Operand is MethodReference).First (); + var get = (MethodReference) call.Operand; + + Assert.IsNotNull (get); + Assert.AreEqual (0, get.GenericParameters.Count); + Assert.AreEqual (MethodCallingConvention.Default, get.CallingConvention); + Assert.AreEqual (method.GenericParameters [0], get.ReturnType); + }); } - [TestCSharp ("Generics.cs")] - public void GenericMultidimensionalArray (ModuleDefinition module) + [Test] + public void CorlibPrimitive () { - var type = module.GetType ("LaMatrix"); - var method = type.GetMethod ("At"); + var module = typeof (TypeTests).ToDefinition ().Module; + + var int32 = module.TypeSystem.Int32; + Assert.IsTrue (int32.IsPrimitive); + Assert.AreEqual (MetadataType.Int32, int32.MetadataType); - var call = method.Body.Instructions.Where (i => i.Operand is MethodReference).First (); - var get = (MethodReference) call.Operand; + var int32_def = int32.Resolve (); + Assert.IsTrue (int32_def.IsPrimitive); + Assert.AreEqual (MetadataType.Int32, int32_def.MetadataType); + } - Assert.IsNotNull (get); - Assert.AreEqual (0, get.GenericParameters.Count); - Assert.AreEqual (MethodCallingConvention.Default, get.CallingConvention); - Assert.AreEqual (method.GenericParameters [0], get.ReturnType); + [Test] + public void ExplicitThis () + { + TestIL ("explicitthis.il", module => { + var type = module.GetType ("MakeDecision"); + var method = type.GetMethod ("Decide"); + var fptr = method.ReturnType as FunctionPointerType; + + Assert.IsNotNull (fptr); + Assert.IsTrue (fptr.HasThis); + Assert.IsTrue (fptr.ExplicitThis); + + Assert.AreEqual (0, fptr.Parameters [0].Sequence); + Assert.AreEqual (1, fptr.Parameters [1].Sequence); + }, verify: false); } } } diff --git a/Test/Resources/assemblies/PortableClassLibrary.dll b/Test/Resources/assemblies/PortableClassLibrary.dll Binary files differnew file mode 100644 index 0000000..21bb42f --- /dev/null +++ b/Test/Resources/assemblies/PortableClassLibrary.dll diff --git a/Test/Resources/assemblies/bug-185.dll b/Test/Resources/assemblies/bug-185.dll Binary files differnew file mode 100644 index 0000000..a32ebbc --- /dev/null +++ b/Test/Resources/assemblies/bug-185.dll diff --git a/Test/Resources/assemblies/cscgpbug.dll b/Test/Resources/assemblies/cscgpbug.dll Binary files differindex 5a5c0f3..5a5c0f3 100755..100644 --- a/Test/Resources/assemblies/cscgpbug.dll +++ b/Test/Resources/assemblies/cscgpbug.dll diff --git a/Test/Resources/assemblies/decsec1-xml.dll b/Test/Resources/assemblies/decsec1-xml.dll Binary files differindex d898c2a..d898c2a 100755..100644 --- a/Test/Resources/assemblies/decsec1-xml.dll +++ b/Test/Resources/assemblies/decsec1-xml.dll diff --git a/Test/Resources/assemblies/delay-signed.dll b/Test/Resources/assemblies/delay-signed.dll Binary files differnew file mode 100644 index 0000000..3571ccf --- /dev/null +++ b/Test/Resources/assemblies/delay-signed.dll diff --git a/Test/Resources/assemblies/hello.textonly.x64.exe b/Test/Resources/assemblies/hello.textonly.x64.exe Binary files differnew file mode 100644 index 0000000..020efc7 --- /dev/null +++ b/Test/Resources/assemblies/hello.textonly.x64.exe diff --git a/Test/Resources/assemblies/metro.exe b/Test/Resources/assemblies/metro.exe Binary files differnew file mode 100644 index 0000000..68784b3 --- /dev/null +++ b/Test/Resources/assemblies/metro.exe diff --git a/Test/Resources/assemblies/nullable-constant.exe b/Test/Resources/assemblies/nullable-constant.exe Binary files differnew file mode 100644 index 0000000..2d4b579 --- /dev/null +++ b/Test/Resources/assemblies/nullable-constant.exe diff --git a/Test/Resources/assemblies/nullable-parameter.dll b/Test/Resources/assemblies/nullable-parameter.dll Binary files differnew file mode 100644 index 0000000..a46851f --- /dev/null +++ b/Test/Resources/assemblies/nullable-parameter.dll diff --git a/Test/Resources/assemblies/text_file.txt b/Test/Resources/assemblies/text_file.txt index 5de1caf..ea780ea 100644 --- a/Test/Resources/assemblies/text_file.txt +++ b/Test/Resources/assemblies/text_file.txt @@ -1 +1 @@ -Cecil ftw!
+Cecil ftw! diff --git a/Test/Resources/assemblies/wp7.dll b/Test/Resources/assemblies/wp7.dll Binary files differnew file mode 100644 index 0000000..c3cbf7b --- /dev/null +++ b/Test/Resources/assemblies/wp7.dll diff --git a/Test/Resources/il/explicitthis.il b/Test/Resources/il/explicitthis.il new file mode 100644 index 0000000..59b3327 --- /dev/null +++ b/Test/Resources/il/explicitthis.il @@ -0,0 +1,113 @@ +.assembly extern mscorlib +{ + .ver 0:0:0:0 +} + +.assembly fptr +{ + .ver 0:0:0:0 +} +.module fptr.exe + +.method public static void Main() cil managed +{ + .entrypoint + .locals init (class MakeDecision d, method instance explicit int32 *(class MakeDecision, int32) m, int32 i) + + ldc.i4.1 + ldc.i4 42 + newobj instance void MakeDecision::.ctor(bool, int32) + stloc d + + ldc.i4.0 + stloc i + br test + +loop: + ldloc d + call instance method instance explicit int32 *(class MakeDecision, int32) MakeDecision::Decide() + stloc m + + ldloc d + ldc.i4.1 + ldloc m + calli instance int32(int32) + call void [mscorlib]System.Console::WriteLine(int32) + + ldloc i + ldc.i4.1 + add + stloc i + +test: + ldloc i + ldc.i4 10 + blt loop + + ret +} + +.class public auto ansi sealed MakeDecision + extends [mscorlib]System.Object +{ + .field private bool Oscillate + .field private int32 Value + + .method public instance method instance explicit int32 *(class MakeDecision, int32) Decide() cil managed + { + .locals init (bool t) + + ldarg.0 + ldfld bool MakeDecision::Oscillate + stloc t + + ldarg.0 + ldloc t + ldc.i4.0 + ceq + stfld bool MakeDecision::Oscillate + + ldloc t + brfalse subs + + ldftn instance int32 MakeDecision::Add(int32) + ret + + subs: + ldftn instance int32 MakeDecision::Sub(int32) + ret + } + + .method public int32 Add(int32 i) cil managed + { + ldarg.0 + ldfld int32 MakeDecision::Value + ldarg i + add + ret + } + + .method public int32 Sub(int32 i) cil managed + { + ldarg.0 + ldfld int32 MakeDecision::Value + ldarg i + sub + ret + } + + .method public hidebysig specialname rtspecialname instance void .ctor(bool s, int32 val) cil managed + { + ldarg.0 + ldarg s + stfld bool MakeDecision::Oscillate + + ldarg.0 + ldarg val + stfld int32 MakeDecision::Value + + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} diff --git a/Test/Resources/il/types.il b/Test/Resources/il/types.il index 4c9acaf..b230c21 100644 --- a/Test/Resources/il/types.il +++ b/Test/Resources/il/types.il @@ -44,3 +44,15 @@ .field private static literal int16 int16_char = char(0x0073) .field private static literal int32 int32_nullref = nullref } + +.class public auto ansi CustomAttribute extends [mscorlib]System.Attribute +{ + .custom instance void CustomAttribute::.ctor() = () + + .method public hidebysig specialname rtspecialname instance void .ctor() + { + ldarg.0 + call instance void [mscorlib]System.Attribute::.ctor() + ret + } +} diff --git a/Test/libs/nunit-2.5.10/nunit.core.dll b/Test/libs/nunit-2.5.10/nunit.core.dll Binary files differdeleted file mode 100755 index a1dd698..0000000 --- a/Test/libs/nunit-2.5.10/nunit.core.dll +++ /dev/null diff --git a/Test/libs/nunit-2.5.10/nunit.core.interfaces.dll b/Test/libs/nunit-2.5.10/nunit.core.interfaces.dll Binary files differdeleted file mode 100755 index 0ac8788..0000000 --- a/Test/libs/nunit-2.5.10/nunit.core.interfaces.dll +++ /dev/null diff --git a/Test/libs/nunit-2.5.10/nunit.framework.dll b/Test/libs/nunit-2.5.10/nunit.framework.dll Binary files differdeleted file mode 100755 index 6856e51..0000000 --- a/Test/libs/nunit-2.5.10/nunit.framework.dll +++ /dev/null diff --git a/Test/libs/nunit-2.4.8/license.txt b/Test/libs/nunit-2.6.2/license.txt index fef6910..530a6e0 100644 --- a/Test/libs/nunit-2.4.8/license.txt +++ b/Test/libs/nunit-2.6.2/license.txt @@ -1,15 +1,15 @@ -Copyright © 2002-2007 Charlie Poole
-Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
-Copyright © 2000-2002 Philip A. Craig
-
-This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
-
-Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment (see the following) in the product documentation is required.
-
-Portions Copyright © 2002-2007 Charlie Poole or Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov or Copyright © 2000-2002 Philip A. Craig
-
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-
-3. This notice may not be removed or altered from any source distribution.
+Copyright © 2002-2012 Charlie Poole +Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov +Copyright © 2000-2002 Philip A. Craig + +This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment (see the following) in the product documentation is required. + +Portions Copyright © 2002-2012 Charlie Poole or Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov or Copyright © 2000-2002 Philip A. Craig + +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source distribution. diff --git a/Test/libs/nunit-2.6.2/nunit.core.dll b/Test/libs/nunit-2.6.2/nunit.core.dll Binary files differnew file mode 100644 index 0000000..8e6d956 --- /dev/null +++ b/Test/libs/nunit-2.6.2/nunit.core.dll diff --git a/Test/libs/nunit-2.6.2/nunit.core.interfaces.dll b/Test/libs/nunit-2.6.2/nunit.core.interfaces.dll Binary files differnew file mode 100644 index 0000000..a966ad5 --- /dev/null +++ b/Test/libs/nunit-2.6.2/nunit.core.interfaces.dll diff --git a/Test/libs/nunit-2.6.2/nunit.framework.dll b/Test/libs/nunit-2.6.2/nunit.framework.dll Binary files differnew file mode 100644 index 0000000..3e24ba1 --- /dev/null +++ b/Test/libs/nunit-2.6.2/nunit.framework.dll |