From: Fadi Hanna Date: Mon, 4 Apr 2016 22:10:44 +0000 (-0700) Subject: Add generics test X-Git-Tag: accepted/tizen/base/20180629.140029~5129^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=479ab6fefe6ba4ab1214ec1fb99d3167d07fe9d6;p=platform%2Fupstream%2Fcoreclr.git Add generics test --- 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 index 0000000..454cdc5 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.il @@ -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() 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() + 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() + 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>() + + ret + } + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class B::.ctor() + call instance void class B::method1>() + + 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 index 0000000..7187cb4 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.ilproj @@ -0,0 +1,43 @@ + + + + + Method_ClassConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Library + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + 7a9bfb7d + true + false + BuildOnly + 1 + + + + + + + + + False + + + + + + + + + + + + + + + + \ 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 index 0000000..1efac5d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.cs @@ -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 +*/ + +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 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 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", "B", "method1", "System.Nullable`1[System.Int32]"); + + Console.WriteLine("\nType: A 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", "C", "method1", "System.Nullable`1[System.Int32]"); + + + + Console.WriteLine("\nType: A 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", "D", "method1", "System.Nullable`1[System.Int32]"); + + + Console.WriteLine("\nType: A 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", "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 index 0000000..b867791 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.csproj @@ -0,0 +1,52 @@ + + + + + Method_Constraints_Negative + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + 7a9bfb7d + true + false + BuildAndRun + 1 + + + + + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 index 0000000..fd926bb --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.il @@ -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() 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() + 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() + 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() + + 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() + + 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() + + 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() + + 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() + + 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() + + 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>() + 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>() + + 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>() + + 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>() + + + ret + } + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class D::.ctor() + call instance void class D::method1>() + + 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 index 0000000..ec74a8c --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.ilproj @@ -0,0 +1,43 @@ + + + + + Method_DefaultCtorAndClassConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Library + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + 7a9bfb7d + true + false + BuildOnly + 1 + + + + + + + + + False + + + + + + + + + + + + + + + + \ 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 index 0000000..5214b72 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.il @@ -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() 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() + 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() + + 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() + 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() + + 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() + + 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() + + 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() + 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>() + 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>() + + 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>() + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class E::.ctor() + call instance void class E::method1>() + + 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 index 0000000..d5f7e5d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.ilproj @@ -0,0 +1,43 @@ + + + + + Method_DefaultCtorAndStructConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Library + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + 7a9bfb7d + true + false + BuildOnly + 1 + + + + + + + + + False + + + + + + + + + + + + + + + + \ 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 index 0000000..9bf744b --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.il @@ -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() + 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() + 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() + 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() + 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() + + 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>() + 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>() + + 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 index 0000000..d0d36a9 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.ilproj @@ -0,0 +1,43 @@ + + + + + Method_DefaultCtorConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Library + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + 7a9bfb7d + true + false + BuildOnly + 1 + + + + + + + + + False + + + + + + + + + + + + + + + + \ 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 index 0000000..570576c --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.il @@ -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() 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() + + 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() + 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() + 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() + 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() + 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() + 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() + 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>() + + 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>() + + 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>() + + ret + } + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class C::.ctor() + call instance void class C::method1>() + + 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 index 0000000..3611ac5 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.ilproj @@ -0,0 +1,43 @@ + + + + + Method_StructConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Library + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + 7a9bfb7d + true + false + BuildOnly + 1 + + + + + + + + + False + + + + + + + + + + + + + + + + \ 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 index 0000000..62803f5 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 index 0000000..cda793f --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/project.json @@ -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 index 0000000..a43bb72 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.il @@ -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 + 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 + 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 + 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 +{ +} + + +.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 index 0000000..9fc7db8 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.ilproj @@ -0,0 +1,43 @@ + + + + + types + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Library + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + 7a9bfb7d + true + false + BuildOnly + 1 + + + + + + + + + False + + + + + + + + + + + + + + + + \ No newline at end of file