Add generics test
authorFadi Hanna <fadim@microsoft.com>
Mon, 4 Apr 2016 22:10:44 +0000 (15:10 -0700)
committerFadi Hanna <fadim@microsoft.com>
Mon, 4 Apr 2016 23:21:17 +0000 (16:21 -0700)
16 files changed:
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.il [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.ilproj [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.cs [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.csproj [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.il [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.ilproj [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.il [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.ilproj [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.il [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.ilproj [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.il [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.ilproj [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/app.config [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/project.json [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.il [new file with mode: 0644]
tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.ilproj [new file with mode: 0644]

diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.il
new file mode 100644 (file)
index 0000000..454cdc5
--- /dev/null
@@ -0,0 +1,93 @@
+// 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 extern mscorlib{}
+.assembly extern types{}
+
+.assembly Method_ClassConstraint_Neg {}
+
+
+
+.class public auto ansi beforefieldinit B
+         extends [mscorlib]System.Object
+{
+
+    // Generic method with class() constraint
+    .method public hidebysig instance void 
+            method1<class T>() cil managed
+    {
+      .maxstack  8
+      ret
+    }
+
+    .method public hidebysig specialname rtspecialname 
+            instance void  .ctor() cil managed
+    {
+      .maxstack  8
+      ldarg.0
+      call       instance void [mscorlib]System.Object::.ctor()
+      ret
+    } 
+} 
+
+.class public auto ansi beforefieldinit M_ClassConstraint 
+         extends [mscorlib]System.Object
+{
+
+  // NEGATIVE TEST
+  // generic argument is a struct
+  .method public hidebysig static void Test3() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class B::.ctor()
+    call instance void class B::method1<valuetype [types]NonGenStruct>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an enum with no default ctor
+  .method public hidebysig static void Test8() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class B::.ctor()
+    call instance void class B::method1<valuetype [types]Enum1>()
+    ret
+  }
+
+}
+
+.class public auto ansi beforefieldinit M_ClassConstraintGenTypes 
+         extends [mscorlib]System.Object
+{
+
+  // NEGATIVE TEST
+  // generic argument is a struct 
+  .method public hidebysig static void Test3() cil managed
+  {
+    .maxstack  1
+   
+    newobj instance void class B::.ctor()
+    call instance void class B::method1<valuetype [types]GenStruct<int32>>()
+
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is NUllable<T>
+  .method public hidebysig static void Test6() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class B::.ctor()
+    call instance void class B::method1<valuetype [mscorlib]System.'Nullable`1'<int32>>()
+
+    ret
+  }
+
+}
+
+
diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.ilproj
new file mode 100644 (file)
index 0000000..7187cb4
--- /dev/null
@@ -0,0 +1,43 @@
+<?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>
+    <AssemblyName>Method_ClassConstraint_Neg</AssemblyName>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib>
+    <CLRTestKind>BuildOnly</CLRTestKind>
+    <CLRTestPriority>1</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="Method_ClassConstraint_Neg.il" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </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/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.cs
new file mode 100644 (file)
index 0000000..1efac5d
--- /dev/null
@@ -0,0 +1,191 @@
+// 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.
+
+// NEGATIVE TESTS
+/* Test various combinations of constraints on methods 
+CONSTRAINTS:
+
+default ctor
+reference type 
+valuetype
+default ctor, reference tyoe
+default ctor, valuetype
+
+Test each constraint with
+- Class with default nullary ctor (Generic/Non generic)
+- Class with no default nullary ctor (Generic/Non generic)
+- Class from mscorlib with default nullary ctor
+- Abstract Class from mscorlib with no default nullary ctor
+
+- Struct from mscorlib (Generic/Non generic)
+- Struct (Generic/Non generic)
+- Enum (Generic/Non generic)
+
+- Interface (Generic/Non generic)
+
+- Array
+
+- Delegate
+
+- Nullable<T>
+*/
+
+using System;
+using System.Security;
+
+public class Test
+{
+       static bool pass;
+       static int testNumber = 1;
+
+       delegate void Case();
+       
+
+       static void Check(Case mytest, string testName, string type, string methodName, string violatingType)
+       {
+
+               Console.Write("Test"+testNumber + ": " + testName);
+               ++testNumber;
+
+               
+               try
+               {
+                       mytest();
+
+                       Console.WriteLine("\nFAIL: Did not catch expected TypeLoadException");
+                       pass = false;
+               }
+               catch (VerificationException e)
+               {
+
+                       
+                       Test.CheckVerificationExceptionMessage(8311, e, type, methodName, violatingType);
+               }
+       
+               catch (Exception e) 
+               {
+                       Console.WriteLine("\nFAIL: Caught unexpected exception: " + e);
+                       pass = false;
+               }       
+
+       }
+
+
+        public static void CheckVerificationExceptionMessage(uint ResourceID, VerificationException e, string type, string methodName, string violatingType)
+        {
+               // "Method %1.%2: type argument '%3' violates the constraint of type parameter '%4'."
+        bool found1 = e.ToString().IndexOf(type + "." + methodName) >= 0;
+        bool found2 = e.ToString().IndexOf(violatingType) >= 0;
+        bool found3 = e.ToString().IndexOf("T") >= 0;
+        
+               if (!found1 || !found2 || !found3)
+               {
+                   Console.WriteLine(" : Exception message is incorrect");
+                   Console.WriteLine("Expected: " + "Method " + type + "." + methodName + ": type argument '" + violatingType + "' violates the constraint of type parameter 'T'");
+                   Console.WriteLine("Actual: " + e.Message.ToString());
+                   pass = false;
+               }
+               else
+               {
+                   Console.WriteLine(" : Caught expected exception");
+               }
+       }
+
+       
+
+       public static int Main()
+       {
+               pass = true;
+
+               Console.WriteLine("\nNEGATIVE TESTS");
+
+               Console.WriteLine("\nType: A<T> where T : new()\n");
+               
+       
+               Check(new Case(M_DefaultCtorConstraint.Test2), "Generic argument is a class with no default ctor", "A", "method1", "ClassNoCtor");
+               Check(new Case(M_DefaultCtorConstraint.Test4), "Generic argument is a delegate", "A", "method1", "Delegate1");
+               Check(new Case(M_DefaultCtorConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor",  "A", "method1", "System.ValueType");
+               Check(new Case(M_DefaultCtorConstraint.Test7), "Generic argument is an interface with no default ctor",  "A", "method1", "NonGenInterface");
+
+               // WRONG?
+               Check(new Case(M_DefaultCtorConstraint.Test9), "Generic argument is an array of classes with default ctor",  "A", "method1", "ClassWithCtor[]");
+               
+               Check(new Case(M_DefaultCtorConstraintGenTypes.Test2), " Generic argument is a generic class with no default ctor",  "A", "method1", "GenClassNoCtor[System.Int32]");
+               Check(new Case(M_DefaultCtorConstraintGenTypes.Test5), "Generic argument is a generic interface",  "A", "method1",  "GenInterface[System.Int32]");
+
+
+               Console.WriteLine("\nType: A<T> where T : class()\n");
+               
+               Check(new Case(M_ClassConstraint.Test3), "Generic argument is a struct",  "B", "method1", "NonGenStruct");
+               Check(new Case(M_ClassConstraint.Test8), "Generic argument is an enum", "B", "method1", "Enum1");
+               Check(new Case(M_ClassConstraintGenTypes.Test3), "Generic argument is a generic struct with default ctor", "B", "method1", "GenStruct[System.Int32]");
+               Check(new Case(M_ClassConstraintGenTypes.Test6), "Generic argument is Nullable<T>", "B", "method1", "System.Nullable`1[System.Int32]");
+
+               Console.WriteLine("\nType: A<T> where T : struct()\n");
+               
+               Check(new Case(M_StructConstraint.Test1), "Generic argument is a class with default ctor", "C", "method1",  "ClassWithCtor");
+               Check(new Case(M_StructConstraint.Test2), "Generic argument is a class with no default ctor", "C", "method1",  "ClassNoCtor");
+               Check(new Case(M_StructConstraint.Test4), "Generic argument is a delegate", "C", "method1",  "Delegate1");
+               Check(new Case(M_StructConstraint.Test5), "Generic argument is an mscorlib class with default ctor", "C", "method1",  "System.Object");
+               Check(new Case(M_StructConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "C", "method1",  "System.ValueType");
+               Check(new Case(M_StructConstraint.Test7), "Generic argument is an interface", "C", "method1",  "NonGenInterface");
+               Check(new Case(M_StructConstraint.Test10), "Generic argument is an array of classes with default ctor", "C", "method1",  "ClassWithCtor[]");
+               
+               Check(new Case(M_StructConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "C", "method1",  "GenClassWithCtor[System.Int32]");
+               Check(new Case(M_StructConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "C", "method1",  "GenClassNoCtor[System.Int32]");
+               Check(new Case(M_StructConstraintGenTypes.Test5), "Generic argument is a generic interface", "C", "method1",  "GenInterface[System.Int32]");
+               Check(new Case(M_StructConstraintGenTypes.Test7), "Generic argument is Nullable<T>", "C", "method1",  "System.Nullable`1[System.Int32]");
+
+
+
+               Console.WriteLine("\nType: A<T> where T : class(), new() \n");
+
+               Check(new Case(M_DefaultCtorAndClassConstraint.Test2), "Generic argument is a class with no default ctor",  "D", "method1",  "ClassNoCtor");
+               Check(new Case(M_DefaultCtorAndClassConstraint.Test3), "Generic argument is a struct", "D", "method1",  "NonGenStruct");
+               Check(new Case(M_DefaultCtorAndClassConstraint.Test4), "Generic argument is a delegate", "D", "method1",  "Delegate1");
+               Check(new Case(M_DefaultCtorAndClassConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "D", "method1",  "System.ValueType");
+               Check(new Case(M_DefaultCtorAndClassConstraint.Test9), "Generic argument is an mscorlib struct",  "D", "method1",  "System.DateTime");
+               Check(new Case(M_DefaultCtorAndClassConstraint.Test7), "Generic argument is an interface", "D", "method1",  "NonGenInterface");
+               Check(new Case(M_DefaultCtorAndClassConstraint.Test8), "Generic argument is an enum", "D", "method1",  "Enum1");
+               Check(new Case(M_DefaultCtorAndClassConstraint.Test10), "Generic argument is an array of classes with default ctor", "D", "method1",  "ClassWithCtor[]");
+
+               
+               Check(new Case(M_DefaultCtorAndClassConstraintGenTypes.Test3), "Generic argument is a generic struct", "D", "method1",  "GenStruct[System.Int32]");
+               Check(new Case(M_DefaultCtorAndClassConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "D", "method1",  "GenClassNoCtor[System.Int32]");
+               Check(new Case(M_DefaultCtorAndClassConstraintGenTypes.Test5), "Generic argument is a generic interface", "D", "method1",  "GenInterface[System.Int32]");
+               Check(new Case(M_DefaultCtorAndClassConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct", "D", "method1",  "System.Collections.Generic.KeyValuePair`2[NonGenStruct,System.Int32]");
+               Check(new Case(M_DefaultCtorAndClassConstraintGenTypes.Test7), "Generic argument is Nullable<T>", "D", "method1",  "System.Nullable`1[System.Int32]");
+               
+
+               Console.WriteLine("\nType: A<T> where T : struct(), new()\n");
+
+               Check(new Case(M_DefaultCtorAndStructConstraint.Test1), "Generic argument is a class with default ctor", "E", "method1",  "ClassWithCtor");
+               Check(new Case(M_DefaultCtorAndStructConstraint.Test2), "Generic argument is a class with no default ctor", "E", "method1",  "ClassNoCtor");
+               Check(new Case(M_DefaultCtorAndStructConstraint.Test4), "Generic argument is a delegate", "E", "method1",  "Delegate1");
+               Check(new Case(M_DefaultCtorAndStructConstraint.Test5), "Generic argument is an mscorlib class with default ctor", "E", "method1",  "System.Object");
+               Check(new Case(M_DefaultCtorAndStructConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "E", "method1",  "System.ValueType");
+               Check(new Case(M_DefaultCtorAndStructConstraint.Test7), "Generic argument is an interface", "E", "method1",  "NonGenInterface");
+
+               Check(new Case(M_DefaultCtorAndStructConstraint.Test10), "Generic argument is an array of classes with default ctor", "E", "method1",  "NonGenStruct[]");
+               
+               Check(new Case(M_DefaultCtorAndStructConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "E", "method1",  "GenClassWithCtor[System.Int32]");
+               Check(new Case(M_DefaultCtorAndStructConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "E", "method1",  "GenClassNoCtor[System.Int32]");
+               Check(new Case(M_DefaultCtorAndStructConstraintGenTypes.Test5), "Generic argument is a generic interface", "E", "method1",  "GenInterface[System.Int32]");
+               Check(new Case(M_DefaultCtorAndStructConstraintGenTypes.Test7), "Generic argument is Nullable<T>", "E", "method1",  "System.Nullable`1[System.Int32]");
+
+
+               if (pass)
+               {
+                       Console.WriteLine("PASS");
+                       return 100;
+               }
+               else
+               {
+                       Console.WriteLine("FAIL");
+                       return 101;
+               }
+       
+       }
+}
+
diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.csproj
new file mode 100644 (file)
index 0000000..b867791
--- /dev/null
@@ -0,0 +1,52 @@
+<?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>
+    <AssemblyName>Method_Constraints_Negative</AssemblyName>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib>
+    <CLRTestKind>BuildAndRun</CLRTestKind>
+    <CLRTestPriority>1</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="Method_Constraints_Negative.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="Method_ClassConstraint_Neg.ilproj" />
+    <ProjectReference Include="Method_DefaultCtorAndClassConstraint_Neg.ilproj" />
+    <ProjectReference Include="Method_DefaultCtorAndStructConstraint_Neg.ilproj" />
+    <ProjectReference Include="Method_DefaultCtorConstraint_Neg.ilproj" />
+    <ProjectReference Include="Method_StructConstraint_Neg.ilproj" />
+    <ProjectReference Include="types.ilproj" />
+  </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/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.il
new file mode 100644 (file)
index 0000000..fd926bb
--- /dev/null
@@ -0,0 +1,211 @@
+// 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 extern mscorlib{}
+.assembly extern types{}
+
+.assembly Method_DefaultCtorAndClassConstraint_Neg {}
+
+
+
+.class public auto ansi beforefieldinit D
+         extends [mscorlib]System.Object
+{
+
+    // Generic method with class() and new() constraints
+    .method public hidebysig instance void 
+            method1<class .ctor T>() cil managed
+    {
+      .maxstack  8
+      ret
+    }
+
+    .method public hidebysig specialname rtspecialname 
+            instance void  .ctor() cil managed
+    {
+      .maxstack  8
+      ldarg.0
+      call       instance void [mscorlib]System.Object::.ctor()
+      ret
+    } 
+
+
+
+} 
+
+.class public auto ansi beforefieldinit M_DefaultCtorAndClassConstraint 
+         extends [mscorlib]System.Object
+{
+  // NEGATIVE TEST
+  // generic argument is a class with no default ctor
+  .method public hidebysig static void Test2() cil managed
+  {
+    .maxstack  1
+   
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<class [types]ClassNoCtor>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is a struct 
+  .method public hidebysig static void Test3() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<valuetype [types]NonGenStruct>()
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is a delegate (doesn't have public parameterless constructor)
+  .method public hidebysig static void Test4() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<class [types]Delegate1>()
+
+    ret
+  }
+
+
+
+  // NEGATIVE TEST
+  // generic argument is an mscorlib abstract class with no default ctor
+
+  .method public hidebysig static void Test6() cil managed
+  {
+    .maxstack  1
+        
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<class [mscorlib]System.ValueType>()
+
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an interface 
+  .method public hidebysig static void Test7() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<class [types]NonGenInterface>()
+
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an enum
+  .method public hidebysig static void Test8() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<valuetype [types]Enum1>()
+
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an mscorlib struct
+  .method public hidebysig static void Test9() cil managed
+  {
+    .maxstack  1
+   
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<valuetype [mscorlib]System.DateTime>()
+
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is an array of classes with default ctor
+  .method public hidebysig static void Test10() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<class [types]ClassWithCtor[]>()
+
+    ret
+  }
+
+}
+
+.class public auto ansi beforefieldinit M_DefaultCtorAndClassConstraintGenTypes 
+         extends [mscorlib]System.Object
+{
+
+  // NEGATIVE TEST
+  // generic argument is a class with no default ctor
+  .method public hidebysig static void Test2() cil managed
+  {
+    .maxstack  1
+   
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<class [types]GenClassNoCtor<int32>>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is a generic struct 
+  .method public hidebysig static void Test3() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<valuetype [types]GenStruct<int32>>()
+
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an generic interface
+  .method public hidebysig static void Test5() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<class [types]GenInterface<int32>>()
+
+    ret
+  }
+
+
+
+  // NEGATIVE TEST
+  // generic argument is an mscorlib generic struct
+  .method public hidebysig static void Test6() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<valuetype [mscorlib]System.Collections.Generic.KeyValuePair`2<valuetype [types]NonGenStruct,int32>>()
+
+
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is NUllable<T>
+  .method public hidebysig static void Test7() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class D::.ctor()
+    call instance void class D::method1<valuetype [mscorlib]System.'Nullable`1'<int32>>()
+
+    ret
+  }
+
+}
diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.ilproj
new file mode 100644 (file)
index 0000000..ec74a8c
--- /dev/null
@@ -0,0 +1,43 @@
+<?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>
+    <AssemblyName>Method_DefaultCtorAndClassConstraint_Neg</AssemblyName>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib>
+    <CLRTestKind>BuildOnly</CLRTestKind>
+    <CLRTestPriority>1</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="Method_DefaultCtorAndClassConstraint_Neg.il" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </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/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.il
new file mode 100644 (file)
index 0000000..5214b72
--- /dev/null
@@ -0,0 +1,185 @@
+// 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 extern mscorlib{}
+.assembly extern types{}
+
+.assembly Method_DefaultCtorAndStructConstraint_Neg {}
+
+
+
+.class public auto ansi beforefieldinit E
+         extends [mscorlib]System.Object
+{
+
+    // Generic method with struct() and new() constraints
+    .method public hidebysig instance void 
+            method1<valuetype .ctor T>() cil managed
+    {
+      .maxstack  8
+      ret
+    }
+
+    .method public hidebysig specialname rtspecialname 
+            instance void  .ctor() cil managed
+    {
+      .maxstack  8
+      ldarg.0
+      call       instance void [mscorlib]System.Object::.ctor()
+      ret
+    } 
+} 
+
+.class public auto ansi beforefieldinit M_DefaultCtorAndStructConstraint 
+         extends [mscorlib]System.Object
+{
+  // NEGATIVE TEST
+  // generic argument is a class with default ctor
+  .method public hidebysig static void Test1() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<class [types]ClassWithCtor>()
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is a class with no default ctor
+  .method public hidebysig static void Test2() cil managed
+  {
+    .maxstack  1
+   
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<class [types]ClassNoCtor>()
+
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is a delegate
+  .method public hidebysig static void Test4() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<class [types]Delegate1>()
+    ret
+  }
+
+
+
+
+  // NEGATIVE TEST
+  // generic argument is an mscorlib class with default ctor
+  .method public hidebysig static void Test5() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<class [mscorlib]System.Object>()
+
+    ret
+  }
+
+
+
+  // NEGATIVE TEST
+  // generic argument is an mscorlib abstract class with no default ctor
+
+  .method public hidebysig static void Test6() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<class [mscorlib]System.ValueType>()
+
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an interface 
+  .method public hidebysig static void Test7() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<class [types]NonGenInterface>()
+
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is an array of classes with default ctor
+  .method public hidebysig static void Test10() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<valuetype [types]NonGenStruct[]>()
+    ret
+  }
+
+
+}
+
+.class public auto ansi beforefieldinit M_DefaultCtorAndStructConstraintGenTypes 
+         extends [mscorlib]System.Object
+{
+  // NEGATIVE TEST
+  // generic argument is a class with default ctor
+  .method public hidebysig static void Test1() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<class [types]GenClassWithCtor<int32>>()
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is a class with no default ctor
+  .method public hidebysig static void Test2() cil managed
+  {
+    .maxstack  1
+   
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<class [types]GenClassNoCtor<int32>>()
+
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is an interface
+  .method public hidebysig static void Test5() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<class [types]GenInterface<int32>>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is NUllable<T>
+  .method public hidebysig static void Test7() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class E::.ctor()
+    call instance void class E::method1<valuetype [mscorlib]System.'Nullable`1'<int32>>()
+
+    ret
+  }
+
+
+
+}
+
+
+
+
diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.ilproj
new file mode 100644 (file)
index 0000000..d5f7e5d
--- /dev/null
@@ -0,0 +1,43 @@
+<?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>
+    <AssemblyName>Method_DefaultCtorAndStructConstraint_Neg</AssemblyName>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib>
+    <CLRTestKind>BuildOnly</CLRTestKind>
+    <CLRTestPriority>1</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="Method_DefaultCtorAndStructConstraint_Neg.il" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </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/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.il
new file mode 100644 (file)
index 0000000..9bf744b
--- /dev/null
@@ -0,0 +1,130 @@
+// 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 extern mscorlib{}
+.assembly extern types{}
+
+.assembly Method_DefaultCtorConstraint_Neg {}
+
+
+.class public auto ansi beforefieldinit A
+         extends [mscorlib]System.Object
+{
+
+    // Generic method with new() constraint
+    .method public hidebysig instance void 
+            method1<.ctor T>() cil managed
+    {
+      .maxstack  8
+      ret
+    } 
+
+    .method public hidebysig specialname rtspecialname 
+            instance void  .ctor() cil managed
+    {
+      .maxstack  8
+      ldarg.0
+      call       instance void [mscorlib]System.Object::.ctor()
+     ret
+    } 
+
+} 
+
+.class public auto ansi beforefieldinit M_DefaultCtorConstraint 
+         extends [mscorlib]System.Object
+{
+
+  // NEGATIVE TEST
+  // generic argument is a class with no default ctor
+  .method public hidebysig static void Test2() cil managed
+  {
+    .maxstack  1
+    newobj instance void class A::.ctor()
+    call instance void class A::method1<class [types]ClassNoCtor>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is a delegate (doesn't have public parameterless constructor)
+  .method public hidebysig static void Test4() cil managed
+  {
+    .maxstack  1
+    newobj instance void class A::.ctor()
+    call instance void class A::method1<class [types]Delegate1>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an mscorlib abstract class with no default ctor
+
+  .method public hidebysig static void Test6() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class A::.ctor()
+    call instance void class A::method1<class [mscorlib]System.ValueType>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an interface with no default ctor
+  .method public hidebysig static void Test7() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class A::.ctor()
+    call instance void class A::method1<class [types]NonGenInterface>()
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is an array of classes with default ctor
+  .method public hidebysig static void Test9() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class A::.ctor()
+    call instance void class A::method1<class [types]ClassWithCtor[]>()
+
+    ret
+  }
+
+
+}
+
+.class public auto ansi beforefieldinit M_DefaultCtorConstraintGenTypes
+         extends [mscorlib]System.Object
+{
+
+  // NEGATIVE TEST
+  // generic argument is a class with no default ctor
+  .method public hidebysig static void Test2() cil managed
+  {
+    .maxstack  1
+   
+    newobj instance void class A::.ctor()
+    call instance void class A::method1<class [types]GenClassNoCtor<int32>>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an interface
+  .method public hidebysig static void Test5() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class A::.ctor()
+    call instance void class A::method1<class [types]GenInterface<int32>>()
+
+    ret
+  }
+}
+
+
+
+
diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.ilproj
new file mode 100644 (file)
index 0000000..d0d36a9
--- /dev/null
@@ -0,0 +1,43 @@
+<?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>
+    <AssemblyName>Method_DefaultCtorConstraint_Neg</AssemblyName>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib>
+    <CLRTestKind>BuildOnly</CLRTestKind>
+    <CLRTestPriority>1</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="Method_DefaultCtorConstraint_Neg.il" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </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/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.il
new file mode 100644 (file)
index 0000000..570576c
--- /dev/null
@@ -0,0 +1,180 @@
+// 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 extern mscorlib{}
+.assembly extern types{}
+
+.assembly Method_StructConstraint_Neg {}
+
+
+
+.class public auto ansi beforefieldinit C
+         extends [mscorlib]System.Object
+{
+
+    // Generic method with class() constraint
+    .method public hidebysig instance void 
+            method1<valuetype T>() cil managed
+    {
+      .maxstack  8
+      ret
+    }
+
+    .method public hidebysig specialname rtspecialname 
+            instance void  .ctor() cil managed
+    {
+      .maxstack  8
+      ldarg.0
+      call       instance void [mscorlib]System.Object::.ctor()
+      ret
+    } 
+} 
+
+.class public auto ansi beforefieldinit M_StructConstraint 
+         extends [mscorlib]System.Object
+{
+  // NEGATIVE TEST
+  // generic argument is a class with default ctor
+  .method public hidebysig static void Test1() cil managed
+  {
+    .maxstack  1
+   
+    newobj instance void class C::.ctor()
+    call instance void class C::method1<class [types]ClassWithCtor>()
+
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is a class with no default ctor
+  .method public hidebysig static void Test2() cil managed
+  {
+    .maxstack  1
+   
+    newobj instance void class C::.ctor()
+    call instance void class C::method1<class [types]ClassNoCtor>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is a delegate
+  .method public hidebysig static void Test4() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class C::.ctor()
+    call instance void class C::method1<class [types]Delegate1>()
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is an mscorlib class with default ctor
+  .method public hidebysig static void Test5() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class C::.ctor()
+    call instance void class C::method1<class [mscorlib]System.Object>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an mscorlib abstract class with no default ctor
+
+  .method public hidebysig static void Test6() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class C::.ctor()
+    call instance void class C::method1<class [mscorlib]System.ValueType>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an interface with no default ctor
+  .method public hidebysig static void Test7() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class C::.ctor() 
+    call instance void class C::method1<class [types]NonGenInterface>()
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an array of classes with default ctor
+  .method public hidebysig static void Test10() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class C::.ctor()
+    call instance void class C::method1<class [types]ClassWithCtor[]>()
+    ret
+  }
+
+
+}
+
+.class public auto ansi beforefieldinit M_StructConstraintGenTypes 
+         extends [mscorlib]System.Object
+{
+  // NEGATIVE TEST
+  // generic argument is a class with default ctor
+  .method public hidebysig static void Test1() cil managed
+  {
+    .maxstack  1
+    
+    newobj instance void class C::.ctor()
+    call instance void class C::method1<class [types]GenClassWithCtor<int32>>()
+
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is a class with no default ctor
+  .method public hidebysig static void Test2() cil managed
+  {
+    .maxstack  1
+   
+
+    newobj instance void class C::.ctor()
+    call instance void class C::method1<class [types]GenClassNoCtor<int32>>()
+
+    ret
+  }
+
+
+  // NEGATIVE TEST
+  // generic argument is an interface 
+  .method public hidebysig static void Test5() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class C::.ctor()
+    call instance void class C::method1<class [types]GenInterface<int32>>()
+
+    ret
+  }
+
+  // NEGATIVE TEST
+  // generic argument is NUllable<T>
+  .method public hidebysig static void Test7() cil managed
+  {
+    .maxstack  1
+
+    newobj instance void class C::.ctor()
+    call instance void class C::method1<valuetype [mscorlib]System.'Nullable`1'<int32>>()
+
+    ret
+  }
+
+}
+
+
+
+
diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.ilproj
new file mode 100644 (file)
index 0000000..3611ac5
--- /dev/null
@@ -0,0 +1,43 @@
+<?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>
+    <AssemblyName>Method_StructConstraint_Neg</AssemblyName>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib>
+    <CLRTestKind>BuildOnly</CLRTestKind>
+    <CLRTestPriority>1</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="Method_StructConstraint_Neg.il" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </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/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/app.config b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/app.config
new file mode 100644 (file)
index 0000000..62803f5
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
\ No newline at end of file
diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/project.json b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/project.json
new file mode 100644 (file)
index 0000000..cda793f
--- /dev/null
@@ -0,0 +1,11 @@
+{
+  "dependencies": {
+    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
+    "System.Console": "4.0.0-rc2-23816",
+    "System.Runtime": "4.1.0-rc2-23816",
+    "System.Runtime.Extensions": "4.0.10"
+  },
+  "frameworks": {
+    "dnxcore50": {}
+  }
+}
diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.il
new file mode 100644 (file)
index 0000000..a43bb72
--- /dev/null
@@ -0,0 +1,115 @@
+// 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 extern mscorlib{}
+
+.assembly Types {}
+
+// class with public nullary ctor
+.class public auto ansi beforefieldinit ClassWithCtor
+       extends [mscorlib]System.Object
+{
+  .method public hidebysig specialname rtspecialname 
+          instance void  .ctor() cil managed
+  {
+    .maxstack  8
+    ldarg.0
+    call       instance void [mscorlib]System.Object::.ctor()
+    ret
+  } 
+}
+
+// generic class with public nullary ctor
+.class public auto ansi beforefieldinit GenClassWithCtor<T>
+       extends [mscorlib]System.Object
+{
+  .method public hidebysig specialname rtspecialname 
+          instance void  .ctor() cil managed
+  {
+    .maxstack  8
+    ldarg.0
+    call       instance void [mscorlib]System.Object::.ctor()
+    ret
+  } 
+}
+
+
+// class without public nullary ctor
+.class public auto ansi beforefieldinit ClassNoCtor
+       extends [mscorlib]System.Object
+{
+} 
+
+// generic class without public nullary ctor
+.class public auto ansi beforefieldinit GenClassNoCtor<T>
+       extends [mscorlib]System.Object
+{
+} 
+
+
+// struct (valuetypes have public nullary ctors by default)
+.class public sequential ansi sealed beforefieldinit NonGenStruct
+       extends [mscorlib]System.ValueType
+{
+  .pack 0
+  .size 1
+} 
+
+
+
+// generic struct (valuetypes have public nullary ctors by default)
+.class public sequential ansi sealed beforefieldinit GenStruct<T>
+       extends [mscorlib]System.ValueType
+{
+  .pack 0
+  .size 1
+}
+
+// interface without public nullary ctor
+.class public abstract interface auto ansi beforefieldinit NonGenInterface
+{
+} 
+
+// interface without public nullary ctor
+.class public abstract interface auto ansi beforefieldinit GenInterface<T>
+{
+} 
+
+
+.class public auto ansi sealed Enum1
+       extends [mscorlib]System.Enum
+{
+  .field public specialname rtspecialname int32 value__
+  .field public static literal valuetype Enum1 One = int32(0x00000000)
+}
+
+
+// doesn't have public parameterless constructor
+.class public auto ansi sealed Delegate1
+       extends [mscorlib]System.MulticastDelegate
+{
+
+  .method public hidebysig specialname rtspecialname 
+          instance void  .ctor(object 'object',
+                               native int 'method') runtime managed
+  {
+  }
+
+  .method public hidebysig newslot virtual 
+          instance void  Invoke() runtime managed
+  {
+  } 
+
+  .method public hidebysig newslot virtual 
+          instance class [mscorlib]System.IAsyncResult 
+          BeginInvoke(class [mscorlib]System.AsyncCallback callback,
+                      object 'object') runtime managed
+  {
+  } 
+
+  .method public hidebysig newslot virtual 
+          instance void  EndInvoke(class [mscorlib]System.IAsyncResult result) runtime managed
+  {
+  } 
+}
diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.ilproj
new file mode 100644 (file)
index 0000000..9fc7db8
--- /dev/null
@@ -0,0 +1,43 @@
+<?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>
+    <AssemblyName>types</AssemblyName>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib>
+    <CLRTestKind>BuildOnly</CLRTestKind>
+    <CLRTestPriority>1</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="types.il" />    
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file