Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -0,0 +1,264 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Mono.Cecil.Rocks;
namespace N
{
/// <summary>
/// ID string generated is "T:N.X".
/// </summary>
public class X
{
/// <summary>
/// ID string generated is "M:N.X.#ctor".
/// </summary>
public X() { }
/// <summary>
/// ID string generated is "M:N.X.#ctor(System.Int32)".
/// </summary>
/// <param name="i">Describe parameter.</param>
public X(int i) { }
/// <summary>
/// ID string generated is "F:N.X.q".
/// </summary>
public string q;
/// <summary>
/// ID string generated is "F:N.X.PI".
/// </summary>
public const double PI = 3.14;
/// <summary>
/// ID string generated is "M:N.X.f".
/// </summary>
public int f() { return 1; }
/// <summary>
/// ID string generated is "M:N.X.bb(System.String,System.Int32@)".
/// </summary>
public int bb(string s, ref int y) { return 1; }
/// <summary>
/// ID string generated is "M:N.X.gg(System.Int16[],System.Int32[0:,0:])".
/// </summary>
public int gg(short[] array1, int[,] array) { return 0; }
/// <summary>
/// ID string generated is "M:N.X.op_Addition(N.X,N.X)".
/// </summary>
public static X operator +(X x, X xx) { return x; }
/// <summary>
/// ID string generated is "P:N.X.prop".
/// </summary>
public int prop { get { return 1; } set { } }
/// <summary>
/// ID string generated is "E:N.X.d".
/// </summary>
#pragma warning disable 67
public event D d;
#pragma warning restore 67
/// <summary>
/// ID string generated is "P:N.X.Item(System.String)".
/// </summary>
public int this[string s] { get { return 1; } }
/// <summary>
/// ID string generated is "T:N.X.Nested".
/// </summary>
public class Nested { }
/// <summary>
/// ID string generated is "T:N.X.D".
/// </summary>
public delegate void D(int i);
/// <summary>
/// ID string generated is "M:N.X.op_Explicit(N.X)~System.Int32".
/// </summary>
public static explicit operator int(X x) { return 1; }
public static void Linq (IEnumerable<string> enumerable, Func<string> selector)
{
}
}
}
namespace Mono.Cecil.Tests {
[TestFixture]
public class DocCommentIdTests {
[Test]
public void TypeDef ()
{
AssertDocumentID ("T:N.X", GetTestType ());
}
[Test]
public void ParameterlessCtor ()
{
var type = GetTestType ();
var ctor = type.GetConstructors ().Single (m => m.Parameters.Count == 0);
AssertDocumentID ("M:N.X.#ctor", ctor);
}
[Test]
public void CtorWithParameters ()
{
var type = GetTestType ();
var ctor = type.GetConstructors ().Single (m => m.Parameters.Count == 1);
AssertDocumentID ("M:N.X.#ctor(System.Int32)", ctor);
}
[Test]
public void Field ()
{
var type = GetTestType ();
var field = type.Fields.Single (m => m.Name == "q");
AssertDocumentID ("F:N.X.q", field);
}
[Test]
public void ConstField ()
{
var type = GetTestType ();
var field = type.Fields.Single (m => m.Name == "PI");
AssertDocumentID ("F:N.X.PI", field);
}
[Test]
public void ParameterlessMethod ()
{
var type = GetTestType ();
var method = type.Methods.Single (m => m.Name == "f");
AssertDocumentID ("M:N.X.f", method);
}
[Test]
public void MethodWithByRefParameters ()
{
var type = GetTestType ();
var method = type.Methods.Single (m => m.Name == "bb");
AssertDocumentID ("M:N.X.bb(System.String,System.Int32@)", method);
}
[Test]
public void MethodWithArrayParameters ()
{
var type = GetTestType ();
var method = type.Methods.Single (m => m.Name == "gg");
AssertDocumentID ("M:N.X.gg(System.Int16[],System.Int32[0:,0:])", method);
}
[Test]
public void OpAddition ()
{
var type = GetTestType ();
var op = type.Methods.Single (m => m.Name == "op_Addition");
AssertDocumentID ("M:N.X.op_Addition(N.X,N.X)", op);
}
[Test]
public void OpExplicit ()
{
var type = GetTestType ();
var op = type.Methods.Single (m => m.Name == "op_Explicit");
AssertDocumentID ("M:N.X.op_Explicit(N.X)~System.Int32", op);
}
[Test]
public void Property ()
{
var type = GetTestType ();
var property = type.Properties.Single (p => p.Name == "prop");
AssertDocumentID ("P:N.X.prop", property);
}
[Test]
public void Indexer ()
{
var type = GetTestType ();
var indexer = type.Properties.Single (p => p.Name == "Item");
AssertDocumentID ("P:N.X.Item(System.String)", indexer);
}
[Test]
public void Event ()
{
var type = GetTestType ();
var @event = type.Events.Single (e => e.Name == "d");
AssertDocumentID ("E:N.X.d", @event);
}
[Test]
public void Delegate ()
{
var type = GetTestType ();
var @delegate = type.NestedTypes.Single (t => t.Name == "D");
AssertDocumentID ("T:N.X.D", @delegate);
}
[Test]
public void NestedType ()
{
var type = GetTestType ();
var nestedType = type.NestedTypes.Single (t => t.Name == "Nested");
AssertDocumentID ("T:N.X.Nested", nestedType);
}
[Test]
public void Linq ()
{
var type = GetTestType ();
var method = type.GetMethod ("Linq");
AssertDocumentID ("M:N.X.Linq(System.Collections.Generic.IEnumerable{System.String},System.Func{System.String})", method);
}
TypeDefinition GetTestType ()
{
return typeof (N.X).ToDefinition ();
}
static void AssertDocumentID (string docId, IMemberDefinition member)
{
Assert.AreEqual (docId, DocCommentId.GetDocCommentId (member));
}
}
}

View File

@@ -0,0 +1,66 @@
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 ();
public abstract void DoBar ();
}
class Bar : Foo {
public override void DoFoo ()
{
}
public override void DoBar ()
{
}
}
class Baz : Bar {
public override void DoFoo ()
{
}
public virtual new void DoBar ()
{
}
}
[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 ());
var new_dobar = baz.GetMethod ("DoBar");
@base = new_dobar.GetBaseMethod();
Assert.AreEqual("Baz", @base.DeclaringType.Name);
}
[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,29 @@
using System.Linq;
using NUnit.Framework;
using Mono.Cecil.Rocks;
namespace Mono.Cecil.Tests {
[TestFixture]
public class ModuleDefinitionRocksTests : BaseTestFixture {
[Test]
public void GetAllTypesTest ()
{
TestCSharp ("Types.cs", 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,67 @@
using System.Security.Permissions;
using NUnit.Framework;
using Mono.Cecil.Rocks;
namespace Mono.Cecil.Tests {
[TestFixture]
public class SecurityDeclarationRocksTests : BaseTestFixture {
[Test]
public void ToPermissionSetFromPermissionSetAttribute ()
{
TestModule ("decsec-xml.dll", 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 ()));
});
}
[Test]
public void ToPermissionSetFromSecurityAttribute ()
{
TestModule ("decsec-att.dll", 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).ImportReference (type);
}
}
}