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:
authorSven Boemer <sbomer@gmail.com>2022-03-19 02:28:27 +0300
committerGitHub <noreply@github.com>2022-03-19 02:28:27 +0300
commit5929598c16cd5d791eb33d4b5978f3140a136262 (patch)
treebefb6f2b43ce4ffd245e20fcd5cb609adff14617 /test/Mono.Linker.Tests.Cases/DataFlow
parent9f2b304f6eb43c32bd7fb6f7cf7b39d5aa677378 (diff)
Add test get interfaces (#2696)
* Add test which mimics what is done in Type.ImplementInterface helper in runtime There's nothing new in this test, but it's better to have coverage for the pattern as it's used in runtime. * Add tests for properties * Simplify Co-authored-by: vitek-karas <10670590+vitek-karas@users.noreply.github.com>
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
index 270d43616..b639a8233 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
@@ -5,6 +5,7 @@ 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;
@@ -50,6 +51,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestNoValue ();
Mixed_Derived.Test (typeof (TestType), 0);
+
+ LoopPatterns.Test ();
}
static void TestAllPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type derivedType)
@@ -275,6 +278,62 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
+ class LoopPatterns
+ {
+ static void EnumerateInterfacesOnBaseTypes ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.Interfaces)] Type type)
+ {
+ Type? t = type;
+ while (t != null) {
+ Type[] interfaces = t.GetInterfaces ();
+ t = t.BaseType;
+ }
+ }
+
+ [ExpectedWarning ("IL2070")]
+ [ExpectedWarning ("IL2075", ProducedBy = ProducedBy.Analyzer)] // Linker doesn't implement backward branches data flow yet
+ static void EnumerateInterfacesOnBaseTypes_Unannotated (Type type)
+ {
+ Type? t = type;
+ while (t != null) {
+ Type[] interfaces = t.GetInterfaces ();
+ t = t.BaseType;
+ }
+ }
+
+ // Can only work with All annotation as NonPublicProperties doesn't propagate to base types
+ static void EnumeratePrivatePropertiesOnBaseTypes ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type type)
+ {
+ const BindingFlags DeclaredOnlyLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
+ Type? t = type;
+ while (t != null) {
+ t.GetProperties (DeclaredOnlyLookup).GetEnumerator ();
+ t = t.BaseType;
+ }
+ }
+
+ // Can only work with All annotation as NonPublicProperties doesn't propagate to base types
+ static void EnumeratePrivatePropertiesOnBaseTypesWithForeach ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type type)
+ {
+ const BindingFlags DeclaredOnlyLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
+ Type? t = type;
+ while (t != null) {
+ foreach (var p in t.GetProperties (DeclaredOnlyLookup)) {
+ // Do nothing
+ }
+ t = t.BaseType;
+ }
+ }
+
+ public static void Test ()
+ {
+ EnumerateInterfacesOnBaseTypes (typeof (TestType));
+ EnumerateInterfacesOnBaseTypes_Unannotated (typeof (TestType));
+
+ EnumeratePrivatePropertiesOnBaseTypes (typeof (TestType));
+ EnumeratePrivatePropertiesOnBaseTypesWithForeach (typeof (TestType));
+ }
+ }
+
class TestType
{
}