Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases for complex type data flow tests #1580

Merged
merged 2 commits into from
Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 104 additions & 8 deletions test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public static void Main ()
TestArrayOnGeneric ();
TestGenericArray ();
TestGenericArrayOnGeneric ();
TestArrayGetTypeFromMethodParam ();
TestArrayGetTypeFromField ();
TestArrayTypeGetType ();
TestArrayCreateInstanceByName ();
TestArrayInAttributeParameter ();
}

[Kept]
Expand Down Expand Up @@ -52,14 +57,6 @@ static void RequirePublicMethodsOnArrayOfGeneric<T> ()
RequirePublicMethods (typeof (T[]));
}

[Kept]
private static void RequirePublicMethods (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
Type type)
{
}

[Kept]
class ArrayElementInGenericType
{
Expand Down Expand Up @@ -96,5 +93,104 @@ static void RequirePublicMethodsOnArrayOfGenericParameter<T> ()
{
_ = new RequirePublicMethodsGeneric<T[]> ();
}

[Kept]
sealed class ArrayGetTypeFromMethodParamElement
{
[Kept] // This is a bug - the method should not be marked, instead Array.* should be marked
public void PublicMethod () { }
}

[Kept]
static void TestArrayGetTypeFromMethodParamHelper (ArrayGetTypeFromMethodParamElement[] p)
{
RequirePublicMethods (p.GetType ());
}

[Kept]
static void TestArrayGetTypeFromMethodParam ()
{
TestArrayGetTypeFromMethodParamHelper (null);
}

[Kept]
sealed class ArrayGetTypeFromFieldElement
{
[Kept] // This is a bug - the method should not be marked, instead Array.* should be marked
public void PublicMethod () { }
}

[Kept]
static ArrayGetTypeFromFieldElement[] _arrayGetTypeFromField;

[Kept]
static void TestArrayGetTypeFromField ()
{
RequirePublicMethods (_arrayGetTypeFromField.GetType ());
}

[Kept]
sealed class ArrayTypeGetTypeElement
{
[Kept] // This is a bug - the method should not be marked, instead Array.* should be marked
public void PublicMethod () { }
}

[Kept]
static void TestArrayTypeGetType ()
{
RequirePublicMethods (Type.GetType ("Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayTypeGetTypeElement[]"));
}

[Kept]
class ArrayCreateInstanceByNameElement
{
[Kept] // This is a bug - the .ctor should not be marked - in fact in this case nothing should be marked as CreateInstance doesn't work on arrays
public ArrayCreateInstanceByNameElement ()
{
}
}

[Kept]
static void TestArrayCreateInstanceByName ()
{
Activator.CreateInstance ("test", "Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayCreateInstanceByNameElement[]");
}

[Kept]
class ArrayInAttributeParamElement
{
[Kept] // This is a bug - the method should not be marked, instead Array.* should be marked
public void PublicMethod () { }
}

[Kept]
[KeptAttributeAttribute (typeof (RequiresPublicMethodAttribute))]
[RequiresPublicMethod (typeof (ArrayInAttributeParamElement[]))]
static void TestArrayInAttributeParameter ()
{
}


[Kept]
private static void RequirePublicMethods (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
Type type)
{
}

[Kept]
[KeptBaseType (typeof (Attribute))]
class RequiresPublicMethodAttribute : Attribute
{
[Kept]
public RequiresPublicMethodAttribute (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
Type t)
{
}
}
}
}