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,4 @@
bin
obj
*.xml
*.user

View File

@@ -0,0 +1,124 @@
<?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>{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mono.Cecil.Pdb.Tests</RootNamespace>
<AssemblyName>Mono.Cecil.Pdb.Tests</AssemblyName>
<FileAlignment>512</FileAlignment>
</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>
<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.Pdb.csproj">
<Project>{63E6915C-7EA4-4D76-AB28-0D7191EEA626}</Project>
<Name>Mono.Cecil.Pdb</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Mono.Cecil.Tests\Addin.cs" />
<Compile Include="Mono.Cecil.Tests\Linq.cs" />
<Compile Include="Mono.Cecil.Tests\PdbTests.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\assemblies\fsapp.exe" />
<Content Include="Resources\assemblies\fsapp.pdb" />
<Content Include="Resources\assemblies\test.exe" />
<Content Include="Resources\assemblies\test.pdb" />
<Content Include="Resources\assemblies\VBConsApp.exe" />
<Content Include="Resources\assemblies\VBConsApp.pdb" />
</ItemGroup>
<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>
</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 CecilPdbAddin : CecilTestAddin {
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
#if !NET_3_5 && !NET_4_0
namespace System {
delegate TResult Func<T, TResult> (T t);
}
namespace System.Runtime.CompilerServices {
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
sealed class ExtensionAttribute : Attribute {
}
}
namespace System.Linq {
static class Enumerable {
public static IEnumerable<TRet> Select<TItem, TRet> (this IEnumerable<TItem> self, Func<TItem, TRet> selector)
{
foreach (var item in self)
yield return selector (item);
}
public static IEnumerable<T> Where<T> (this IEnumerable<T> self, Func<T, bool> predicate)
{
foreach (var item in self)
if (predicate (item))
yield return item;
}
public static T First<T> (this IEnumerable<T> self)
{
using (var enumerator = self.GetEnumerator ()) {
if (!enumerator.MoveNext ())
throw new InvalidOperationException ();
return enumerator.Current;
}
}
}
}
#endif

View File

@@ -0,0 +1,175 @@
using System.IO;
using System.Linq;
using Mono.Cecil.Cil;
using Mono.Cecil.Pdb;
using NUnit.Framework;
namespace Mono.Cecil.Tests {
[TestFixture]
public class PdbTests : BaseTestFixture {
[TestModule ("test.exe", SymbolReaderProvider = typeof (PdbReaderProvider), SymbolWriterProvider = typeof (PdbWriterProvider))]
public void Main (ModuleDefinition module)
{
var type = module.GetType ("Program");
var main = type.GetMethod ("Main");
AssertCode (@"
.locals init (System.Int32 i, System.Int32 CS$1$0000, System.Boolean CS$4$0001)
.line 6,6:2,3 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0000: nop
.line 7,7:8,18 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0001: ldc.i4.0
IL_0002: stloc.0
.line 16707566,16707566:0,0 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0003: br.s IL_0012
.line 8,8:4,21 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0005: ldarg.0
IL_0006: ldloc.0
IL_0007: ldelem.ref
IL_0008: call System.Void Program::Print(System.String)
IL_000d: nop
.line 7,7:36,39 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_000e: ldloc.0
IL_000f: ldc.i4.1
IL_0010: add
IL_0011: stloc.0
.line 7,7:19,34 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0012: ldloc.0
IL_0013: ldarg.0
IL_0014: ldlen
IL_0015: conv.i4
IL_0016: clt
IL_0018: stloc.2
.line 16707566,16707566:0,0 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0019: ldloc.2
IL_001a: brtrue.s IL_0005
.line 10,10:3,12 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_001c: ldc.i4.0
IL_001d: stloc.1
IL_001e: br.s IL_0020
.line 11,11:2,3 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0020: ldloc.1
IL_0021: ret
", main);
}
[TestModule ("test.exe", SymbolReaderProvider = typeof (PdbReaderProvider), SymbolWriterProvider = typeof (PdbWriterProvider))]
public void Document (ModuleDefinition module)
{
var type = module.GetType ("Program");
var method = type.GetMethod ("Main");
var sequence_point = method.Body.Instructions.Where (i => i.SequencePoint != null).First ().SequencePoint;
var document = sequence_point.Document;
Assert.IsNotNull (document);
Assert.AreEqual (@"c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs", document.Url);
Assert.AreEqual (DocumentType.Text, document.Type);
Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm);
Assert.AreEqual (DocumentLanguage.CSharp, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}
[TestModule ("VBConsApp.exe", SymbolReaderProvider = typeof (PdbReaderProvider), SymbolWriterProvider = typeof (PdbWriterProvider))]
public void BasicDocument (ModuleDefinition module)
{
var type = module.GetType ("VBConsApp.Program");
var method = type.GetMethod ("Main");
var sequence_point = method.Body.Instructions.Where (i => i.SequencePoint != null).First ().SequencePoint;
var document = sequence_point.Document;
Assert.IsNotNull (document);
Assert.AreEqual (@"c:\tmp\VBConsApp\Program.vb", document.Url);
Assert.AreEqual (DocumentType.Text, document.Type);
Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm);
Assert.AreEqual (DocumentLanguage.Basic, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}
[TestModule ("fsapp.exe", SymbolReaderProvider = typeof (PdbReaderProvider), SymbolWriterProvider = typeof (PdbWriterProvider))]
public void FSharpDocument (ModuleDefinition module)
{
var type = module.GetType ("Program");
var method = type.GetMethod ("fact");
var sequence_point = method.Body.Instructions.Where (i => i.SequencePoint != null).First ().SequencePoint;
var document = sequence_point.Document;
Assert.IsNotNull (document);
Assert.AreEqual (@"c:\tmp\fsapp\Program.fs", document.Url);
Assert.AreEqual (DocumentType.Text, document.Type);
Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm);
Assert.AreEqual (DocumentLanguage.FSharp, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}
[Test]
public void CreateMethodFromScratch ()
{
var module = ModuleDefinition.CreateModule ("Pan", ModuleKind.Dll);
var type = new TypeDefinition ("Pin", "Pon", TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Sealed, module.Import (typeof (object)));
module.Types.Add (type);
var method = new MethodDefinition ("Pang", MethodAttributes.Public | MethodAttributes.Static, module.Import (typeof (string)));
type.Methods.Add (method);
var body = method.Body;
body.InitLocals = true;
var il = body.GetILProcessor ();
var temp = new VariableDefinition ("temp", module.Import (typeof (string)));
body.Variables.Add (temp);
il.Emit (OpCodes.Nop);
il.Emit (OpCodes.Ldstr, "hello");
il.Emit (OpCodes.Stloc, temp);
il.Emit (OpCodes.Ldloc, temp);
il.Emit (OpCodes.Ret);
body.Instructions [0].SequencePoint = new SequencePoint (new Document (@"C:\test.cs")) {
StartLine = 0,
StartColumn = 0,
EndLine = 0,
EndColumn = 4,
};
var file = Path.Combine (Path.GetTempPath (), "Pan.dll");
module.Write (file, new WriterParameters {
SymbolWriterProvider = new PdbWriterProvider (),
});
module = ModuleDefinition.ReadModule (file, new ReaderParameters {
SymbolReaderProvider = new PdbReaderProvider (),
});
method = module.GetType ("Pin.Pon").GetMethod ("Pang");
Assert.AreEqual ("temp", method.Body.Variables [0].Name);
}
static void AssertCode (string expected, MethodDefinition method)
{
Assert.IsTrue (method.HasBody);
Assert.IsNotNull (method.Body);
System.Console.WriteLine (Formatter.FormatMethodBody (method));
Assert.AreEqual (Normalize (expected), Normalize (Formatter.FormatMethodBody (method)));
}
static string Normalize (string str)
{
return str.Trim ().Replace ("\r\n", "\n");
}
}
}

Binary file not shown.

Binary file not shown.