Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitek Karas <vitek.karas@microsoft.com>2021-01-06 18:38:31 +0300
committerGitHub <noreply@github.com>2021-01-06 18:38:31 +0300
commit83ea45b8f4ffcfe5e1d15c1b42d0d1a003865864 (patch)
tree4a4ebd20d7c517d564fdcdb3355b17f5a0121eea /test/Mono.Linker.Tests.Cases/DataFlow
parentc45a25d77dfe278bd8fa675cb998cb0573dcb1c0 (diff)
Better intrinsic handling of GetNestedType if input has All (#1719)
Co-authored-by: Tlakaelel Axayakatl Ceja <tlakaelel.ceja@microsoft.com>
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/GetNestedTypeOnAllAnnotatedType.cs122
1 files changed, 122 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/GetNestedTypeOnAllAnnotatedType.cs b/test/Mono.Linker.Tests.Cases/DataFlow/GetNestedTypeOnAllAnnotatedType.cs
new file mode 100644
index 000000000..6cd6d5dc5
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/GetNestedTypeOnAllAnnotatedType.cs
@@ -0,0 +1,122 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.DataFlow
+{
+ [RecognizedReflectionAccessPattern]
+ [SkipKeptItemsValidation]
+ class GetNestedTypeOnAllAnnotatedType
+ {
+ [RecognizedReflectionAccessPattern]
+ static void Main ()
+ {
+ TestOnAllAnnotatedParameter (typeof (GetNestedTypeOnAllAnnotatedType));
+ TestOnNonAllAnnotatedParameter (typeof (GetNestedTypeOnAllAnnotatedType));
+ TestWithBindingFlags (typeof (GetNestedTypeOnAllAnnotatedType));
+ TestWithUnknownBindingFlags (BindingFlags.Public, typeof (GetNestedTypeOnAllAnnotatedType));
+ TestUnsupportedBindingFlags (typeof (GetNestedTypeOnAllAnnotatedType));
+ TestWithNull ();
+ TestIfElse (1, typeof (GetNestedTypeOnAllAnnotatedType), typeof (GetNestedTypeOnAllAnnotatedType));
+ TestSwitchAllValid (1, typeof (GetNestedTypeOnAllAnnotatedType));
+ TestOnKnownTypeOnly ();
+ }
+
+ [RecognizedReflectionAccessPattern]
+ static void TestOnAllAnnotatedParameter ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentType)
+ {
+ var nestedType = parentType.GetNestedType (nameof (NestedType));
+ RequiresAll (nestedType);
+ }
+
+ [UnrecognizedReflectionAccessPattern (typeof (GetNestedTypeOnAllAnnotatedType), nameof (RequiresAll), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ static void TestOnNonAllAnnotatedParameter ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicNestedTypes)] Type parentType)
+ {
+ var nestedType = parentType.GetNestedType (nameof (NestedType));
+ RequiresAll (nestedType);
+ }
+
+ [RecognizedReflectionAccessPattern]
+ static void TestWithBindingFlags ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentType)
+ {
+ var nestedType = parentType.GetNestedType (nameof (NestedType), BindingFlags.Public);
+ RequiresAll (nestedType);
+ }
+
+ [RecognizedReflectionAccessPattern]
+ static void TestWithUnknownBindingFlags (BindingFlags bindingFlags, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentType)
+ {
+ var nestedType = parentType.GetNestedType (nameof (NestedType), bindingFlags);
+ RequiresAll (nestedType);
+ }
+
+ [RecognizedReflectionAccessPattern]
+ static void TestUnsupportedBindingFlags ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentType)
+ {
+ var nestedType = parentType.GetNestedType (nameof (NestedType), BindingFlags.IgnoreCase);
+ RequiresAll (nestedType);
+ }
+
+ [RecognizedReflectionAccessPattern]
+ static void TestWithNull ()
+ {
+ Type parentType = null;
+ var nestedType = parentType.GetNestedType (nameof (NestedType));
+ RequiresAll (nestedType);
+ }
+
+ [UnrecognizedReflectionAccessPattern (typeof (GetNestedTypeOnAllAnnotatedType), nameof (RequiresAll), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ static void TestIfElse (int number, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentWithAll, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicNestedTypes)] Type parentWithoutAll)
+ {
+ Type typeOfParent;
+ if (number == 1) {
+ typeOfParent = parentWithAll;
+ } else {
+ typeOfParent = parentWithoutAll;
+ }
+ var nestedType = typeOfParent.GetNestedType (nameof (NestedType));
+ RequiresAll (nestedType);
+ }
+
+ [RecognizedReflectionAccessPattern]
+ static void TestSwitchAllValid (int number, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentWithAll)
+ {
+ Type typeOfParent = number switch
+ {
+ 1 => parentWithAll,
+ 2 => null,
+ 3 => typeof (GetNestedTypeOnAllAnnotatedType)
+ };
+
+ var nestedType = typeOfParent.GetNestedType (nameof (NestedType));
+ RequiresAll (nestedType);
+ }
+
+ [RecognizedReflectionAccessPattern]
+ static void TestOnKnownTypeOnly ()
+ {
+ RequiresAll (typeof (GetNestedTypeOnAllAnnotatedType).GetNestedType (nameof (NestedType)));
+ }
+
+ static void RequiresAll ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type type)
+ {
+ }
+
+ private class NestedType
+ {
+ NestedType () { }
+ public static int PublicStaticInt;
+ public void Method () { }
+ int Prop { get; set; }
+ }
+ }
+}