diff options
author | Sven Boemer <sbomer@gmail.com> | 2022-03-19 02:28:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-19 02:28:27 +0300 |
commit | 5929598c16cd5d791eb33d4b5978f3140a136262 (patch) | |
tree | befb6f2b43ce4ffd245e20fcd5cb609adff14617 /test/Mono.Linker.Tests.Cases/DataFlow | |
parent | 9f2b304f6eb43c32bd7fb6f7cf7b39d5aa677378 (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.cs | 59 |
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 { } |