Imported Upstream version 6.6.0.89

Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-09-24 08:53:40 +00:00
parent cf815e07e0
commit 95fdb59ea6
2556 changed files with 138145 additions and 47453 deletions

View File

@@ -0,0 +1,95 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mono.Documentation.Util;
using Windows.UI.Xaml;
using Mono.Documentation.Updater;
namespace mdoc.Test.Enumeration
{
[TestFixture]
public class AttachedEntityTests : CecilBaseTest
{
[TestCase]
public void Test_NoEntities()
{
var type = GetTypeDef<AttachedTestClassNoAttachedEntities>();
var list = AttachedEntitiesHelper.GetAttachedEntities(type);
Assert.IsFalse(list.Any());
}
[TestCase]
public void Test_AttachedProperty()
{
var type = GetTypeDef<AttachedTestClass>();
var list = AttachedEntitiesHelper.GetAttachedEntities(type);
Assert.AreEqual(3, list.Count());
}
[TestCase]
public void Test_AttachedProperty_Formatter()
{
string expected = "see GetSome, and SetSome";
var type = GetTypeDef<AttachedTestClass>();
var list = AttachedEntitiesHelper.GetAttachedEntities(type);
MemberFormatter formatter = new CSharpMemberFormatter();
string def = formatter.GetDeclaration(list.First());
Assert.AreEqual(expected, def);
}
[TestCase]
public void Test_AttachedProperty_Formatter_GetOnly()
{
string expected = "see GetSomeGet";
var type = GetTypeDef<AttachedTestClass>();
var list = AttachedEntitiesHelper.GetAttachedEntities(type);
MemberFormatter formatter = new CSharpMemberFormatter();
string def = formatter.GetDeclaration(list.Skip(1).First());
Assert.AreEqual(expected, def);
}
[TestCase]
public void Test_AttachedProperty_Formatter_SetOnly()
{
string expected = "see SetSomeSet";
var type = GetTypeDef<AttachedTestClass>();
var list = AttachedEntitiesHelper.GetAttachedEntities(type);
MemberFormatter formatter = new CSharpMemberFormatter();
string def = formatter.GetDeclaration(list.Skip(2).First());
Assert.AreEqual(expected, def);
}
public class AttachedTestClassNoAttachedEntities { }
public class AttachedTestClass
{
public static readonly DependencyProperty SomeProperty;
public static bool GetSome(DependencyObject obj) { return false; }
public static void SetSome(DependencyObject obj, bool val) { }
public static readonly DependencyProperty SomeGetProperty;
public static bool GetSomeGet(DependencyObject obj) { return false; }
public static readonly DependencyProperty SomeSetProperty;
public static void SetSomeSet(DependencyObject obj, bool val) { }
public static DependencyProperty SomeNotReadonlyProperty;
public static bool GetSomeNotReadOnly(DependencyObject obj) { return false; }
public static void SetSomeNotReadOnly(DependencyObject obj, bool val) { }
}
}
}

View File

@@ -0,0 +1,30 @@
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Rocks;
using Mono.Documentation;
using Mono.Documentation.Updater.Frameworks;
namespace mdoc.Test
{
public abstract class CecilBaseTest
{
protected TypeDefinition GetTypeDef<T> ()
{
var type = typeof(T);
var path = type.Module.Assembly.Location;
var assemblyResolver = new MDocResolver();
var dependencyPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), "..", "..", "..", "..", "external", "Windows");
assemblyResolver.AddSearchDirectory(dependencyPath);
var cachedResolver = new CachedResolver(assemblyResolver);
if (!System.IO.Directory.Exists(dependencyPath))
throw new System.Exception($"The path '{dependencyPath}' doesn't seem to exist ... did project files get moved around?");
var resolver = new MDocMetadataResolver(cachedResolver);
var assembly = AssemblyDefinition.ReadAssembly(path, new ReaderParameters { AssemblyResolver = cachedResolver, MetadataResolver = resolver });
var typeref = assembly.MainModule.GetAllTypes ().FirstOrDefault (t => t.Name == type.Name);
return typeref;
}
}
}

View File

@@ -0,0 +1,167 @@
using NUnit.Framework;
using System;
using System.Linq;
using System.Xml;
using Mono.Cecil;
using Mono.Cecil.Rocks;
using Mono.Documentation.Updater;
using Mono.Documentation.Updater.Frameworks;
namespace mdoc.Test
{
/// <summary>
/// This is for testing the DocumentationEnumerator
/// </summary>
[TestFixture ()]
public class EnumeratorTests : CecilBaseTest
{
[Test]
public void FindProperty_NonEII () => TestProperty ("AProperty");
[Test]
public void FindProperty_EII1 () => TestProperty ("mdoc.Test.EnumeratorTests.IFace1.AProperty");
[Test]
public void FindProperty_EII2 () => TestProperty ("mdoc.Test.EnumeratorTests.IFace2.AProperty");
[Test]
public void FindProperty_NonExistent ()
{
string propertyName = "mdoc.Test.EnumeratorTests.IDontExist.AProperty";
TypeDefinition theclass = GetTypeDef<ConcreteClass> ();
var members = DocumentationEnumerator.GetReflectionMembers (theclass, propertyName, "Property").ToArray ();
Assert.IsFalse (members.Any (), "Invalid Member Matched");
}
[Test]
public void GetMember () => TestPropertyMember ("AProperty", XML_PROPERTY);
[Test]
public void GetMember_EII1 () => TestPropertyMember ("mdoc.Test.EnumeratorTests.IFace1.AProperty", XML_PROPERTY_IFACE1);
[Test]
public void GetMember_EII2 () => TestPropertyMember ("mdoc.Test.EnumeratorTests.IFace2.AProperty", XML_PROPERTY_IFACE2);
[Test]
public void GetMethod() => TestMethodMember("BeginRead", XML_METHOD_TESTMETHOD);
#region Test infrastructure
private void TestProperty (string propertyName)
{
TypeDefinition theclass = GetTypeDef<ConcreteClass> ();
var members = DocumentationEnumerator.GetReflectionMembers (theclass, propertyName, "Property").ToArray ();
Assert.IsTrue (members.Any (), "no members found");
Assert.AreEqual (1, members.Count (), "Different # of members found");
Assert.AreEqual (propertyName, members.Single ().Name);
}
private void TestPropertyMember (string propertyName, string theXml)
{
TypeDefinition theclass = GetTypeDef<ConcreteClass> ();
XmlDocument document = new XmlDocument ();
document.LoadXml (theXml);
var member = DocumentationEnumerator.GetMember (theclass, new DocumentationMember (document.FirstChild, FrameworkTypeEntry.Empty));
Assert.NotNull (member, "didn't find the node");
Assert.AreEqual (propertyName, member.Name);
}
private void TestMethodMember(string methodName, string theXml)
{
TypeDefinition theclass = GetTypeDef<ConcreteClass>();
XmlDocument document = new XmlDocument();
document.LoadXml(theXml);
var member = DocumentationEnumerator.GetMember(theclass, new DocumentationMember(document.FirstChild, FrameworkTypeEntry.Empty));
Assert.NotNull(member, "didn't find the node");
Assert.AreEqual(methodName, member.Name);
}
#endregion
#region Test Types
public interface IFace1
{
string AProperty { get; set; }
}
public interface IFace2
{
string AProperty { get; set; }
}
public class ConcreteClass : IFace1, IFace2
{
public string AProperty { get; set; }
string IFace1.AProperty { get; set; }
string IFace2.AProperty { get; set; }
public IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) => null;
}
#endregion
#region Test Data
private string XML_PROPERTY = @"<Member MemberName=""AProperty"">
<MemberType>Property</MemberType>
<Implements>
<InterfaceMember>P:mdoc.Test.EnumeratorTests.IFace1.AProperty</InterfaceMember>
<InterfaceMember>P:mdoc.Test.EnumeratorTests.IFace2.AProperty</InterfaceMember>
</Implements>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
</Member>";
private string XML_PROPERTY_IFACE1 = @"<Member MemberName=""mdoc.Test.EnumeratorTests.IFace1.AProperty"">
<MemberType>Property</MemberType>
<Implements>
<InterfaceMember>P:mdoc.Test.EnumeratorTests.IFace1.AProperty</InterfaceMember>
</Implements>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
</Member>";
private string XML_PROPERTY_IFACE2 = @"<Member MemberName=""mdoc.Test.EnumeratorTests.IFace2.AProperty"">
<MemberType>Property</MemberType>
<Implements>
<InterfaceMember>P:mdoc.Test.EnumeratorTests.IFace2.AProperty</InterfaceMember>
</Implements>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
</Member>";
private string XML_METHOD_TESTMETHOD = @"<Member MemberName=""BeginRead"">
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.IAsyncResult</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name = ""buffer"" Type=""System.Byte[]"" Index=""0"" FrameworkAlternate=""netcore-1.0;netcore-1.1;netcore-2.0"" />
<Parameter Name = ""array"" Type=""System.Byte[]"" Index=""0"" FrameworkAlternate=""netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netstandard-2.0"" />
<Parameter Name = ""offset"" Type=""System.Int32"" Index=""1"" FrameworkAlternate=""netcore-2.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netstandard-2.0"" />
<Parameter Name = ""count"" Type=""System.Int32"" Index=""2"" FrameworkAlternate=""netcore-2.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netstandard-2.0"" />
<Parameter Name = ""asyncCallback"" Type=""System.AsyncCallback"" Index=""3"" FrameworkAlternate=""netcore-2.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netstandard-2.0"" />
<Parameter Name = ""asyncState"" Type=""System.Object"" Index=""4"" FrameworkAlternate=""netcore-2.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netstandard-2.0"" />
</Parameters>
</Member>";
#endregion
}
}

View File

@@ -0,0 +1,66 @@
using Mono.Documentation;
using NUnit.Framework;
using System;
using System.Linq;
namespace mdoc.Test.Enumeration
{
[TestFixture ()]
public class ExceptionTests : CecilBaseTest
{
[Test ()]
public void TestExceptionEnumerations ()
{
var type = GetTypeDef<ExceptionTestClass> ();
var member = type.Methods.Single (m => m.Name == "ThrowAnException");
var sources = new ExceptionLookup (ExceptionLocations.DependentAssemblies)[member];
Assert.IsNotNull (sources);
Assert.AreEqual (1, sources.Count ());
var source = sources.First ();
Assert.AreEqual ("ThrowAnException", source.Sources.First ().Name);
}
[Test ()]
public void TestExceptionEnumerations_FromPrivateMethod ()
{
var type = GetTypeDef<ExceptionTestClass> ();
var member = type.Methods.Single (m => m.Name == "ThrowFromPrivateMethod");
var sources = new ExceptionLookup (ExceptionLocations.DependentAssemblies)[member];
Assert.IsNotNull (sources);
Assert.AreEqual (0, sources.Count ());
}
[Test ()]
public void TestExceptionEnumerations_FromPublicMethod ()
{
var type = GetTypeDef<ExceptionTestClass> ();
var member = type.Methods.Single (m => m.Name == "ThrowFromPublicMethod");
var sources = new ExceptionLookup (ExceptionLocations.Assembly)[member];
Assert.IsNotNull (sources);
Assert.AreEqual (1, sources.Count ());
var source = sources.First ();
Assert.AreEqual ("ThrowItPublic", source.Sources.First ().Name);
}
public class ExceptionTestClass
{
public void ThrowAnException()
{
throw new NotImplementedException ();
}
public void ThrowFromPrivateMethod () => ThrowItPrivate ();
private void ThrowItPrivate () => throw new NotImplementedException ();
public void ThrowFromPublicMethod () => ThrowItPublic ();
public void ThrowItPublic () => throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,55 @@
using Mono.Documentation.Updater;
using NUnit.Framework;
using System;
using System.Linq;
namespace mdoc.Test.Enumeration
{
[TestFixture ()]
public class InterfaceTests : CecilBaseTest
{
[Test ()]
public void TestCase ()
{
var type = GetTypeDef<TestClassWithInterfaces> ();
var ifaces = DocUtils.GetAllPublicInterfaces (type).ToArray ();
Assert.AreEqual (3, ifaces.Count ());
Assert.AreEqual ("I2", ifaces[0].Name);
Assert.AreEqual ("ICombined", ifaces[1].Name);
Assert.AreEqual ("I1", ifaces[2].Name);
}
[Test ()]
public void TestCase_WithComplexCombinations ()
{
var type = GetTypeDef<TestClassWithAllInterfaces> ();
var ifaces = DocUtils.GetAllPublicInterfaces (type).ToArray ();
Assert.AreEqual (4, ifaces.Count ());
Assert.AreEqual ("ICombined2", ifaces[0].Name);
Assert.AreEqual ("I1", ifaces[1].Name);
Assert.AreEqual ("ICombined", ifaces[2].Name);
Assert.AreEqual ("I2", ifaces[3].Name);
}
[Test ()]
public void TestCase_OnlyDirectlyImplemented ()
{
var type = GetTypeDef<TestClassWithInterfaces> ();
var ifaces = DocUtils.GetUserImplementedInterfaces (type).ToArray ();
Assert.AreEqual (2, ifaces.Count ());
Assert.AreEqual ("I2", ifaces[0].Name);
Assert.AreEqual ("ICombined", ifaces[1].Name);
}
}
public interface I1 {}
public interface I2 {}
public interface ICombined : I1 {}
public interface ICombined2 : I1, ICombined, I2 {}
public interface TestClassWithInterfaces : I2, ICombined {}
public interface TestClassWithAllInterfaces : ICombined2 {}
}