Imported Upstream version 5.4.0.199

Former-commit-id: f4d318e4b2f128fa9f4d31b37bb3839a3fc0dfb2
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-09-25 16:57:44 +00:00
parent 536cd135cc
commit 5924117973
223 changed files with 3826 additions and 487 deletions

View File

@@ -87,7 +87,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (Normalize (expected), Normalize (Formatter.FormatMethodBody (method)));
}
static string Normalize (string str)
public static string Normalize (string str)
{
return str.Trim ().Replace ("\r\n", "\n");
}
@@ -118,11 +118,13 @@ namespace Mono.Cecil.Tests {
if (testCase.ReadOnly)
return;
#if !READ_ONLY
using (var runner = new TestRunner (testCase, TestCaseType.WriteFromDeferred))
runner.RunTest ();
using (var runner = new TestRunner (testCase, TestCaseType.WriteFromImmediate))
runner.RunTest ();
#endif
}
}
@@ -237,12 +239,14 @@ namespace Mono.Cecil.Tests {
case TestCaseType.ReadDeferred:
parameters.ReadingMode = ReadingMode.Deferred;
return ModuleDefinition.ReadModule (location, parameters);
#if !READ_ONLY
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");
#endif
default:
return null;
}
@@ -256,6 +260,7 @@ namespace Mono.Cecil.Tests {
return (ISymbolReaderProvider) Activator.CreateInstance (test_case.SymbolReaderProvider);
}
#if !READ_ONLY
ISymbolWriterProvider GetSymbolWriterProvider ()
{
if (test_case.SymbolReaderProvider == null)
@@ -263,6 +268,7 @@ namespace Mono.Cecil.Tests {
return (ISymbolWriterProvider) Activator.CreateInstance (test_case.SymbolWriterProvider);
}
#endif
IAssemblyResolver GetAssemblyResolver ()
{
@@ -275,6 +281,7 @@ namespace Mono.Cecil.Tests {
return test_resolver;
}
#if !READ_ONLY
ModuleDefinition RoundTrip (string location, ReaderParameters reader_parameters, string folder)
{
var rt_folder = Path.Combine (Path.GetTempPath (), folder);
@@ -297,7 +304,7 @@ namespace Mono.Cecil.Tests {
return ModuleDefinition.ReadModule (rt_module, reader_parameters);
}
#endif
public void RunTest ()
{
var module = GetModule ();
@@ -321,7 +328,9 @@ namespace Mono.Cecil.Tests {
enum TestCaseType {
ReadImmediate,
ReadDeferred,
#if !READ_ONLY
WriteFromImmediate,
WriteFromDeferred,
#endif
}
}

View File

@@ -251,6 +251,10 @@ namespace Mono.Cecil.Tests {
static string WinSdkTool (string tool)
{
var sdks = new [] {
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools",
@"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",

View File

@@ -449,6 +449,7 @@ namespace Mono.Cecil.Tests {
});
}
#if !READ_ONLY
[Test]
public void DefineCustomAttributeFromBlob ()
{
@@ -486,7 +487,7 @@ namespace Mono.Cecil.Tests {
module.Dispose ();
}
#endif
static void AssertCustomAttribute (string expected, CustomAttribute attribute)
{
Assert.AreEqual (expected, PrettyPrint (attribute));

View File

@@ -195,6 +195,7 @@ namespace Mono.Cecil.Tests {
});
}
#if !READ_ONLY
[Test]
public void ExternalPdbDeterministicAssembly ()
{
@@ -223,5 +224,6 @@ namespace Mono.Cecil.Tests {
Assert.IsTrue (header.Entries.Any (e => e.Directory.Type == ImageDebugType.EmbeddedPortablePdb));
}, symbolReaderProvider: typeof (EmbeddedPortablePdbReaderProvider), symbolWriterProvider: typeof (EmbeddedPortablePdbWriterProvider));
}
#endif
}
}

View File

@@ -1,3 +1,4 @@
#if !READ_ONLY
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -372,3 +373,4 @@ namespace Mono.Cecil.Tests {
}
}
}
#endif

View File

@@ -1,3 +1,4 @@
#if !READ_ONLY
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -419,3 +420,4 @@ namespace Mono.Cecil.Tests {
}
}
}
#endif

View File

@@ -12,6 +12,7 @@ namespace Mono.Cecil.Tests {
[TestFixture]
public class ModuleTests : BaseTestFixture {
#if !READ_ONLY
[Test]
public void CreateModuleEscapesAssemblyName ()
{
@@ -21,6 +22,7 @@ namespace Mono.Cecil.Tests {
module = ModuleDefinition.CreateModule ("Test.exe", ModuleKind.Console);
Assert.AreEqual ("Test", module.Assembly.Name.Name);
}
#endif
[Test]
public void SingleModule ()
@@ -277,6 +279,7 @@ namespace Mono.Cecil.Tests {
}
}
#if !READ_ONLY
[Test]
public void ReadAndWriteFile ()
{
@@ -294,5 +297,21 @@ namespace Mono.Cecil.Tests {
using (var module = ModuleDefinition.ReadModule (path))
Assert.AreEqual ("Foo.Foo", module.Types [1].FullName);
}
[Test]
public void ExceptionInWriteDoesNotKeepLockOnFile ()
{
var path = Path.GetTempFileName ();
var module = ModuleDefinition.CreateModule ("FooFoo", ModuleKind.Dll);
// Mixed mode module that Cecil can not write
module.Attributes = (ModuleAttributes) 0;
Assert.Throws<NotSupportedException>(() => module.Write (path));
// Ensure you can still delete the file
File.Delete (path);
}
#endif
}
}

View File

@@ -1,6 +1,8 @@
#if !READ_ONLY
using System;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Mono.Cecil.Cil;
@@ -337,6 +339,7 @@ namespace Mono.Cecil.Tests {
});
}
#if !READ_ONLY
[Test]
public void EmbeddedCompressedPortablePdb ()
{
@@ -396,13 +399,135 @@ namespace Mono.Cecil.Tests {
var symbol = method.DebugInformation;
Assert.IsNotNull (symbol);
Assert.AreEqual(1, symbol.Scope.Constants.Count);
Assert.AreEqual (1, symbol.Scope.Constants.Count);
var a = symbol.Scope.Constants [0];
Assert.AreEqual ("a", a.Name);
}, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider));
}
[Test]
public void InvalidConstantRecord ()
{
using (var module = GetResourceModule ("mylib.dll", new ReaderParameters { SymbolReaderProvider = new PortablePdbReaderProvider () })) {
var type = module.GetType ("mylib.Say");
var method = type.GetMethod ("hello");
var symbol = method.DebugInformation;
Assert.IsNotNull (symbol);
Assert.AreEqual (0, symbol.Scope.Constants.Count);
}
}
[Test]
public void SourceLink ()
{
TestModule ("TargetLib.dll", module => {
Assert.IsTrue (module.HasCustomDebugInformations);
Assert.AreEqual (1, module.CustomDebugInformations.Count);
var source_link = module.CustomDebugInformations [0] as SourceLinkDebugInformation;
Assert.IsNotNull (source_link);
Assert.AreEqual ("{\"documents\":{\"C:\\\\tmp\\\\SourceLinkProblem\\\\*\":\"https://raw.githubusercontent.com/bording/SourceLinkProblem/197d965ee7f1e7f8bd3cea55b5f904aeeb8cd51e/*\"}}", source_link.Content);
}, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider));
}
[Test]
public void EmbeddedSource ()
{
TestModule ("embedcs.exe", module => {
var program = GetDocument (module.GetType ("Program"));
var program_src = GetSourceDebugInfo (program);
Assert.IsTrue (program_src.compress);
var program_src_content = Encoding.UTF8.GetString (program_src.Content);
Assert.AreEqual (Normalize (@"using System;
class Program
{
static void Main()
{
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
// Hello hello hello hello hello hello
Console.WriteLine(B.Do());
Console.WriteLine(A.Do());
}
}
"), Normalize (program_src_content));
var a = GetDocument (module.GetType ("A"));
var a_src = GetSourceDebugInfo (a);
Assert.IsFalse (a_src.compress);
var a_src_content = Encoding.UTF8.GetString (a_src.Content);
Assert.AreEqual (Normalize (@"class A
{
public static string Do()
{
return ""A::Do"";
}
}"), Normalize (a_src_content));
var b = GetDocument(module.GetType ("B"));
var b_src = GetSourceDebugInfo (b);
Assert.IsFalse (b_src.compress);
var b_src_content = Encoding.UTF8.GetString (b_src.Content);
Assert.AreEqual (Normalize (@"class B
{
public static string Do()
{
return ""B::Do"";
}
}"), Normalize (b_src_content));
}, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider));
}
static Document GetDocument (TypeDefinition type)
{
foreach (var method in type.Methods) {
if (!method.HasBody)
continue;
foreach (var instruction in method.Body.Instructions) {
var sp = method.DebugInformation.GetSequencePoint (instruction);
if (sp != null && sp.Document != null)
return sp.Document;
}
}
return null;
}
static EmbeddedSourceDebugInformation GetSourceDebugInfo (Document document)
{
Assert.IsTrue (document.HasCustomDebugInformations);
Assert.AreEqual (1, document.CustomDebugInformations.Count);
var source = document.CustomDebugInformations [0] as EmbeddedSourceDebugInformation;
Assert.IsNotNull (source);
return source;
}
[Test]
public void PortablePdbLineInfo ()
{
@@ -418,5 +543,7 @@ namespace Mono.Cecil.Tests {
IL_0001: ret", main);
}, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider));
}
#endif
}
}
#endif

View File

@@ -93,6 +93,7 @@ namespace Mono.Cecil.Tests {
});
}
#if !READ_ONLY
[Test]
public void DefineSecurityDeclarationByBlob ()
{
@@ -125,6 +126,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual ("System.String", argument.Type.FullName);
Assert.AreEqual (permission_set, argument.Value);
}
#endif
[Test]
public void SecurityDeclarationWithoutAttributes ()

View File

@@ -1,3 +1,4 @@
#if !READ_ONLY
using System;
using System.IO;
@@ -51,3 +52,4 @@ namespace Mono.Cecil.Tests {
}
}
}
#endif

View File

@@ -63,6 +63,7 @@ namespace Mono.Cecil.Tests {
}, verify: false, assemblyResolver: WindowsRuntimeAssemblyResolver.CreateInstance (), applyWindowsRuntimeProjections: true);
}
#if !READ_ONLY
[Test]
public void CanStripType ()
{
@@ -90,6 +91,7 @@ namespace Mono.Cecil.Tests {
}
}, readOnly: true, verify: false, assemblyResolver: assemblyResolver, applyWindowsRuntimeProjections: true);
}
#endif
}
[TestFixture]

Binary file not shown.

Binary file not shown.

Binary file not shown.