Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@@ -0,0 +1,7 @@
bin
obj
*.suo
*.user
*.pidb
*.userprefs
*.xml

View File

@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">net_4_0_Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mono.Cecil.Rocks.Tests</RootNamespace>
<AssemblyName>Mono.Cecil.Rocks.Tests</AssemblyName>
<FileAlignment>512</FileAlignment>
</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>
<Reference Include="nunit.core">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Test\libs\nunit-2.6.2\nunit.core.dll</HintPath>
</Reference>
<Reference Include="nunit.core.interfaces">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Test\libs\nunit-2.6.2\nunit.core.interfaces.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Test\libs\nunit-2.6.2\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\..\Test\Mono.Cecil.Tests.csproj">
<Project>{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}</Project>
<Name>Mono.Cecil.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil.Rocks.csproj">
<Project>{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}</Project>
<Name>Mono.Cecil.Rocks</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Mono.Cecil.Tests\Addin.cs" />
<Compile Include="Mono.Cecil.Tests\MethodDefinitionRocksTests.cs" />
<Compile Include="Mono.Cecil.Tests\ModuleDefinitionRocksTests.cs" />
<Compile Include="Mono.Cecil.Tests\SecurityDeclarationRocksTests.cs" />
<Compile Include="Mono.Cecil.Tests\TypeDefinitionRocksTests.cs" />
<Compile Include="Mono.Cecil.Tests\TypeReferenceRocksTests.cs" />
<Content Include="Resources\cs\Types.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\assemblies\decsec-att.dll" />
<Content Include="Resources\assemblies\decsec-xml.dll" />
</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>

View File

@@ -0,0 +1,8 @@
using NUnit.Core.Extensibility;
namespace Mono.Cecil.Tests {
[NUnitAddin]
public class CecilRocksAddin : CecilTestAddin {
}
}

View File

@@ -0,0 +1,53 @@
using System.Linq;
using NUnit.Framework;
using Mono.Cecil.Rocks;
namespace Mono.Cecil.Tests {
[TestFixture]
public class MethodDefinitionRocksTests : BaseTestFixture {
abstract class Foo {
public abstract void DoFoo ();
}
class Bar : Foo {
public override void DoFoo ()
{
}
}
class Baz : Bar {
public override void DoFoo ()
{
}
}
[Test]
public void GetBaseMethod ()
{
var baz = typeof (Baz).ToDefinition ();
var baz_dofoo = baz.GetMethod ("DoFoo");
var @base = baz_dofoo.GetBaseMethod ();
Assert.AreEqual ("Bar", @base.DeclaringType.Name);
@base = @base.GetBaseMethod ();
Assert.AreEqual ("Foo", @base.DeclaringType.Name);
Assert.AreEqual (@base, @base.GetBaseMethod ());
}
[Test]
public void GetOriginalBaseMethod ()
{
var baz = typeof (Baz).ToDefinition ();
var baz_dofoo = baz.GetMethod ("DoFoo");
var @base = baz_dofoo.GetOriginalBaseMethod ();
Assert.AreEqual ("Foo", @base.DeclaringType.Name);
}
}
}

View File

@@ -0,0 +1,27 @@
using System.Linq;
using NUnit.Framework;
using Mono.Cecil.Rocks;
namespace Mono.Cecil.Tests {
[TestFixture]
public class ModuleDefinitionRocksTests : BaseTestFixture {
[TestCSharp ("Types.cs")]
public void GetAllTypesTest (ModuleDefinition module)
{
var sequence = new [] {
module.GetType ("<Module>"),
module.GetType ("Foo"),
module.GetType ("Foo/Bar"),
module.GetType ("Foo/Gazonk"),
module.GetType ("Foo/Gazonk/Baz"),
module.GetType ("Pan"),
};
Assert.IsTrue (sequence.SequenceEqual (module.GetAllTypes ()));
}
}
}

View File

@@ -0,0 +1,63 @@
using System.Security.Permissions;
using NUnit.Framework;
using Mono.Cecil.Rocks;
namespace Mono.Cecil.Tests {
[TestFixture]
public class SecurityDeclarationRocksTests : BaseTestFixture {
[TestModule ("decsec-xml.dll")]
public void ToPermissionSetFromPermissionSetAttribute (ModuleDefinition module)
{
var type = module.GetType ("SubLibrary");
Assert.IsTrue (type.HasSecurityDeclarations);
Assert.AreEqual (1, type.SecurityDeclarations.Count);
var declaration = type.SecurityDeclarations [0];
var permission_set = declaration.ToPermissionSet ();
Assert.IsNotNull (permission_set);
string permission_set_value = "<PermissionSet class=\"System.Security.PermissionSe"
+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"{0}\"\r\nversion=\"1\"\r\nFla"
+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n";
permission_set_value = string.Format (permission_set_value, typeof (SecurityPermission).AssemblyQualifiedName);
Assert.AreEqual (Normalize (permission_set_value), Normalize (permission_set.ToXml ().ToString ()));
}
[TestModule ("decsec-att.dll")]
public void ToPermissionSetFromSecurityAttribute (ModuleDefinition module)
{
var type = module.GetType ("SubLibrary");
Assert.IsTrue (type.HasSecurityDeclarations);
Assert.AreEqual (1, type.SecurityDeclarations.Count);
var declaration = type.SecurityDeclarations [0];
var permission_set = declaration.ToPermissionSet ();
Assert.IsNotNull (permission_set);
string permission_set_value = "<PermissionSet class=\"System.Security.PermissionSe"
+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"{0}\"\r\nversion=\"1\"\r\nFla"
+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n";
permission_set_value = string.Format (permission_set_value, typeof (SecurityPermission).AssemblyQualifiedName);
Assert.AreEqual (Normalize (permission_set_value), Normalize (permission_set.ToXml ().ToString ()));
}
static string Normalize (string s)
{
return s.Replace ("\n", "").Replace ("\r", "");
}
}
}

View File

@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil.Rocks;
using NUnit.Framework;
namespace Mono.Cecil.Tests {
[TestFixture]
public class TypeDefinitionRocksTests {
class Foo {
static Foo ()
{
}
public Foo (int a)
{
}
public Foo (int a, string s)
{
}
public static void Bar ()
{
}
void Baz ()
{
}
}
[Test]
public void GetConstructors ()
{
var foo = typeof (Foo).ToDefinition ();
var ctors = foo.GetConstructors ().Select (ctor => ctor.FullName);
var expected = new [] {
"System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.cctor()",
"System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.ctor(System.Int32)",
"System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.ctor(System.Int32,System.String)",
};
AssertSet (expected, ctors);
}
static void AssertSet<T> (IEnumerable<T> expected, IEnumerable<T> actual)
{
Assert.IsFalse (expected.Except (actual).Any ());
Assert.IsTrue (expected.Intersect (actual).SequenceEqual (expected));
}
[Test]
public void GetStaticConstructor ()
{
var foo = typeof (Foo).ToDefinition ();
var cctor = foo.GetStaticConstructor ();
Assert.IsNotNull (cctor);
Assert.AreEqual ("System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.cctor()", cctor.FullName);
}
[Test]
public void GetMethods ()
{
var foo = typeof (Foo).ToDefinition ();
var methods = foo.GetMethods ().ToArray ();
Assert.AreEqual (2, methods.Length);
Assert.AreEqual ("System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::Bar()", methods [0].FullName);
Assert.AreEqual ("System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::Baz()", methods [1].FullName);
}
enum Pan : byte {
Pin,
Pon,
}
[Test]
public void GetEnumUnderlyingType ()
{
var pan = typeof (Pan).ToDefinition ();
Assert.IsNotNull (pan);
Assert.IsTrue (pan.IsEnum);
var underlying_type = pan.GetEnumUnderlyingType ();
Assert.IsNotNull (underlying_type);
Assert.AreEqual ("System.Byte", underlying_type.FullName);
}
}
}

View File

@@ -0,0 +1,124 @@
using System;
using Mono.Cecil.Rocks;
using NUnit.Framework;
namespace Mono.Cecil.Tests {
[TestFixture]
public class TypeReferenceRocksTests {
[Test]
public void MakeArrayType ()
{
var @string = GetTypeReference (typeof (string));
var string_array = @string.MakeArrayType ();
Assert.IsInstanceOf (typeof (ArrayType), string_array);
Assert.AreEqual (1, string_array.Rank);
}
[Test]
public void MakeArrayTypeRank ()
{
var @string = GetTypeReference (typeof (string));
var string_array = @string.MakeArrayType (3);
Assert.IsInstanceOf (typeof (ArrayType), string_array);
Assert.AreEqual (3, string_array.Rank);
}
[Test]
public void MakePointerType ()
{
var @string = GetTypeReference (typeof (string));
var string_ptr = @string.MakePointerType ();
Assert.IsInstanceOf (typeof (PointerType), string_ptr);
}
[Test]
public void MakeByReferenceType ()
{
var @string = GetTypeReference (typeof (string));
var string_byref = @string.MakeByReferenceType ();
Assert.IsInstanceOf (typeof (ByReferenceType), string_byref);
}
class OptionalModifier {}
[Test]
public void MakeOptionalModifierType ()
{
var @string = GetTypeReference (typeof (string));
var modopt = GetTypeReference (typeof (OptionalModifier));
var string_modopt = @string.MakeOptionalModifierType (modopt);
Assert.IsInstanceOf (typeof (OptionalModifierType), string_modopt);
Assert.AreEqual (modopt, string_modopt.ModifierType);
}
class RequiredModifier { }
[Test]
public void MakeRequiredModifierType ()
{
var @string = GetTypeReference (typeof (string));
var modreq = GetTypeReference (typeof (RequiredModifierType));
var string_modreq = @string.MakeRequiredModifierType (modreq);
Assert.IsInstanceOf (typeof (RequiredModifierType), string_modreq);
Assert.AreEqual (modreq, string_modreq.ModifierType);
}
[Test]
public void MakePinnedType ()
{
var byte_array = GetTypeReference (typeof (byte []));
var pinned_byte_array = byte_array.MakePinnedType ();
Assert.IsInstanceOf (typeof (PinnedType), pinned_byte_array);
}
[Test]
public void MakeSentinelType ()
{
var @string = GetTypeReference (typeof (string));
var string_sentinel = @string.MakeSentinelType ();
Assert.IsInstanceOf (typeof (SentinelType), string_sentinel);
}
class Foo<T1, T2> {}
[Test]
public void MakeGenericInstanceType ()
{
var foo = GetTypeReference (typeof (Foo<,>));
var @string = GetTypeReference (typeof (string));
var @int = GetTypeReference (typeof (int));
var foo_string_int = foo.MakeGenericInstanceType (@string, @int);
Assert.IsInstanceOf (typeof (GenericInstanceType), foo_string_int);
Assert.AreEqual (2, foo_string_int.GenericArguments.Count);
Assert.AreEqual (@string, foo_string_int.GenericArguments [0]);
Assert.AreEqual (@int, foo_string_int.GenericArguments [1]);
}
static TypeReference GetTypeReference (Type type)
{
return ModuleDefinition.ReadModule (typeof (TypeReferenceRocksTests).Module.FullyQualifiedName).Import (type);
}
}
}

View File

@@ -0,0 +1,14 @@
public class Foo {
public class Bar {
}
public class Gazonk {
public class Baz {
}
}
}
public class Pan {
}