summaryrefslogtreecommitdiff
path: root/tests/src/reflection
diff options
context:
space:
mode:
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>2019-04-23 21:18:25 +0200
committerGitHub <noreply@github.com>2019-04-23 21:18:25 +0200
commitd5f569771f8dfda895867f5a1309afbe384ebf51 (patch)
tree3f1959cb7b302c631a6750c4df2f39685ed84c9f /tests/src/reflection
parent6c09b4c6f39727abcf2780f1ae4334ca9352bef4 (diff)
downloadcoreclr-d5f569771f8dfda895867f5a1309afbe384ebf51.tar.gz
coreclr-d5f569771f8dfda895867f5a1309afbe384ebf51.tar.bz2
coreclr-d5f569771f8dfda895867f5a1309afbe384ebf51.zip
Add test coverage for static members on interfaces (#23928)
This has been supported since v1 but we don't have much test coverage. C# is going to enable interfaces to have static members and static constructors so we better start testing it.
Diffstat (limited to 'tests/src/reflection')
-rw-r--r--tests/src/reflection/StaticInterfaceMembers/consumer.cs35
-rw-r--r--tests/src/reflection/StaticInterfaceMembers/consumer.csproj38
-rw-r--r--tests/src/reflection/StaticInterfaceMembers/provider.il34
-rw-r--r--tests/src/reflection/StaticInterfaceMembers/provider.ilproj36
4 files changed, 143 insertions, 0 deletions
diff --git a/tests/src/reflection/StaticInterfaceMembers/consumer.cs b/tests/src/reflection/StaticInterfaceMembers/consumer.cs
new file mode 100644
index 0000000000..c5e8f20736
--- /dev/null
+++ b/tests/src/reflection/StaticInterfaceMembers/consumer.cs
@@ -0,0 +1,35 @@
+// 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.Reflection;
+
+class Program
+{
+ static int Main()
+ {
+ {
+ FieldInfo fi = typeof(IFoo<object>).GetField("O");
+ object val = fi.GetValue(null);
+ if (!object.ReferenceEquals(val, typeof(object[])))
+ throw new Exception();
+ }
+
+ {
+ MethodInfo mi = typeof(IFoo<string>).GetMethod("GimmeT");
+ object val = mi.Invoke(null, Array.Empty<object>());
+ if (!object.ReferenceEquals(val, typeof(string)))
+ throw new Exception();
+ }
+
+ {
+ MethodInfo mi = typeof(IFoo<object>).GetMethod("GimmeU").MakeGenericMethod(typeof(string));
+ object val = mi.Invoke(null, Array.Empty<object>());
+ if (!object.ReferenceEquals(val, typeof(string)))
+ throw new Exception();
+ }
+
+ return 100;
+ }
+} \ No newline at end of file
diff --git a/tests/src/reflection/StaticInterfaceMembers/consumer.csproj b/tests/src/reflection/StaticInterfaceMembers/consumer.csproj
new file mode 100644
index 0000000000..ac71bb0251
--- /dev/null
+++ b/tests/src/reflection/StaticInterfaceMembers/consumer.csproj
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <CLRTestKind>BuildAndRun</CLRTestKind>
+ <CLRTestPriority>0</CLRTestPriority>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="consumer.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="provider.ilproj" />
+ </ItemGroup>
+ <ItemGroup>
+ <NoWarn Include="42016,42020,42025,42024" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/reflection/StaticInterfaceMembers/provider.il b/tests/src/reflection/StaticInterfaceMembers/provider.il
new file mode 100644
index 0000000000..8ce9d85ed8
--- /dev/null
+++ b/tests/src/reflection/StaticInterfaceMembers/provider.il
@@ -0,0 +1,34 @@
+// 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.
+
+.assembly provider { }
+
+.assembly extern mscorlib { }
+
+.class interface public IFoo<T>
+{
+ .field public static class [mscorlib]System.Type O
+
+ .method public static specialname rtspecialname void .cctor()
+ {
+ ldtoken !T[]
+ call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
+ stsfld class [mscorlib]System.Type class IFoo<!T>::O
+ ret
+ }
+
+ .method public static class [mscorlib]System.Type GimmeT()
+ {
+ ldtoken !T
+ call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
+ ret
+ }
+
+ .method public static class [mscorlib]System.Type GimmeU<U>()
+ {
+ ldtoken !!U
+ call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
+ ret
+ }
+}
diff --git a/tests/src/reflection/StaticInterfaceMembers/provider.ilproj b/tests/src/reflection/StaticInterfaceMembers/provider.ilproj
new file mode 100644
index 0000000000..919182beb5
--- /dev/null
+++ b/tests/src/reflection/StaticInterfaceMembers/provider.ilproj
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <PropertyGroup>
+
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="provider.il" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project>