Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFadi Hanna <fadim@microsoft.com>2017-02-16 04:10:46 +0300
committerGitHub <noreply@github.com>2017-02-16 04:10:46 +0300
commit3c8f0b2f21985c6016f9c83cf0cdd63f2cded93d (patch)
tree2e18fc68612d99004f8f79547e78ec3afe84dd05 /tests/src/Simple/Generics/Generics.cs
parent30aefcd3633b6cf4754ce88ee429540a3d817f4c (diff)
Enabling GVM target resolution (hookup work) (#2635)
Enabling GVM target resolution (hookup work)
Diffstat (limited to 'tests/src/Simple/Generics/Generics.cs')
-rw-r--r--tests/src/Simple/Generics/Generics.cs213
1 files changed, 213 insertions, 0 deletions
diff --git a/tests/src/Simple/Generics/Generics.cs b/tests/src/Simple/Generics/Generics.cs
index 14be4ef44..e009ea4c9 100644
--- a/tests/src/Simple/Generics/Generics.cs
+++ b/tests/src/Simple/Generics/Generics.cs
@@ -25,6 +25,7 @@ class Program
TestMDArrayAddressMethod.Run();
TestNameManglingCollisionRegression.Run();
TestUnusedGVMsDoNotCrashCompiler.Run();
+ TestSimpleGVMScenarios.Run();
return 100;
}
@@ -705,4 +706,216 @@ class Program
throw new Exception();
}
}
+
+ class TestSimpleGVMScenarios
+ {
+ interface IFoo<out U>
+ {
+ string IMethod1<T>(T t1, T t2);
+ }
+
+ class Base : IFoo<string>, IFoo<int>
+ {
+ public virtual string GMethod1<T>(T t1, T t2) { return "Base.GMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ public virtual string IMethod1<T>(T t1, T t2) { return "Base.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ }
+ class Derived : Base, IFoo<string>, IFoo<int>
+ {
+ public override string GMethod1<T>(T t1, T t2) { return "Derived.GMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ string IFoo<string>.IMethod1<T>(T t1, T t2) { return "Derived.IFoo<string>.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ }
+ class SuperDerived : Derived, IFoo<string>, IFoo<int>
+ {
+ string IFoo<int>.IMethod1<T>(T t1, T t2) { return "SuperDerived.IFoo<int>.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ }
+
+
+ class GenBase<A> : IFoo<string>, IFoo<int>
+ {
+ public virtual string GMethod1<T>(T t1, T t2) { return "GenBase<" + typeof(A) + ">.GMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ public virtual string IMethod1<T>(T t1, T t2) { return "GenBase<" + typeof(A) + ">.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ }
+ class GenDerived<A> : GenBase<A>, IFoo<string>, IFoo<int>
+ {
+ public override string GMethod1<T>(T t1, T t2) { return "GenDerived<" + typeof(A) + ">.GMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ string IFoo<string>.IMethod1<T>(T t1, T t2) { return "GenDerived<" + typeof(A) + ">.IFoo<string>.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ }
+ class GenSuperDerived<A> : GenDerived<A>, IFoo<string>, IFoo<int>
+ {
+ string IFoo<int>.IMethod1<T>(T t1, T t2) { return "GenSuperDerived<" + typeof(A) + ">.IFoo<int>.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ }
+
+ struct MyStruct1 : IFoo<string>, IFoo<int>
+ {
+ string IFoo<string>.IMethod1<T>(T t1, T t2) { return "MyStruct1.IFoo<string>.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ string IFoo<int>.IMethod1<T>(T t1, T t2) { return "MyStruct1.IFoo<int>.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ }
+ struct MyStruct2 : IFoo<string>, IFoo<int>
+ {
+ string IFoo<string>.IMethod1<T>(T t1, T t2) { return "MyStruct2.IFoo<string>.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ public string IMethod1<T>(T t1, T t2) { return "MyStruct2.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ }
+ struct MyStruct3 : IFoo<string>, IFoo<int>
+ {
+ string IFoo<int>.IMethod1<T>(T t1, T t2) { return "MyStruct3.IFoo<int>.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ public string IMethod1<T>(T t1, T t2) { return "MyStruct3.IMethod1<" + typeof(T) + ">(" + t1 + "," + t2 + ")"; }
+ }
+
+ static string s_GMethod1;
+ static string s_IFooString;
+ static string s_IFooObject;
+ static string s_IFooInt;
+
+ static int s_NumErrors = 0;
+
+ private static void TestWithStruct(IFoo<string> ifooStr, IFoo<object> ifooObj, IFoo<int> ifooInt)
+ {
+ var res = ifooStr.IMethod1<int>(1, 2);
+ WriteLineWithVerification(res, s_IFooString);
+
+ res = ifooObj.IMethod1<int>(3, 4);
+ WriteLineWithVerification(res, s_IFooObject);
+
+ res = ifooInt.IMethod1<int>(5, 6);
+ WriteLineWithVerification(res, s_IFooInt);
+ }
+
+ private static void TestWithClass(object o)
+ {
+ Base b = o as Base;
+ var res = b.GMethod1<int>(1, 2);
+ WriteLineWithVerification(res, s_GMethod1);
+
+ IFoo<string> ifoo1 = o as IFoo<string>;
+ res = ifoo1.IMethod1<int>(3, 4);
+ WriteLineWithVerification(res, s_IFooString);
+
+ IFoo<object> ifoo2 = o as IFoo<object>;
+ res = ifoo2.IMethod1<int>(5, 6);
+ WriteLineWithVerification(res, s_IFooObject);
+
+ IFoo<int> ifoo3 = o as IFoo<int>;
+ res = ifoo3.IMethod1<int>(7, 8);
+ WriteLineWithVerification(res, s_IFooInt);
+ }
+
+ private static void TestWithGenClass<T>(object o)
+ {
+ GenBase<T> b = o as GenBase<T>;
+ var res = b.GMethod1<int>(1, 2);
+ WriteLineWithVerification(res, s_GMethod1);
+
+ IFoo<string> ifoo1 = o as IFoo<string>;
+ res = ifoo1.IMethod1<int>(3, 4);
+ WriteLineWithVerification(res, s_IFooString);
+
+ IFoo<object> ifoo2 = o as IFoo<object>;
+ res = ifoo2.IMethod1<int>(5, 6);
+ WriteLineWithVerification(res, s_IFooObject);
+
+ IFoo<int> ifoo3 = o as IFoo<int>;
+ res = ifoo3.IMethod1<int>(7, 8);
+ WriteLineWithVerification(res, s_IFooInt);
+ }
+
+ private static void WriteLineWithVerification(string actual, string expected)
+ {
+ if (actual != expected)
+ {
+ Console.WriteLine("ACTUAL : " + actual);
+ Console.WriteLine("EXPECTED : " + expected);
+ s_NumErrors++;
+ }
+ else
+ {
+ Console.WriteLine(actual);
+ }
+ }
+
+ public static void Run()
+ {
+ {
+ s_GMethod1 = "Base.GMethod1<System.Int32>(1,2)";
+ s_IFooString = "Base.IMethod1<System.Int32>(3,4)";
+ s_IFooObject = "Base.IMethod1<System.Int32>(5,6)";
+ s_IFooInt = "Base.IMethod1<System.Int32>(7,8)";
+ TestWithClass(new Base());
+ Console.WriteLine("====================");
+
+
+ s_GMethod1 = "Derived.GMethod1<System.Int32>(1,2)";
+ s_IFooString = "Derived.IFoo<string>.IMethod1<System.Int32>(3,4)";
+ s_IFooObject = "Derived.IFoo<string>.IMethod1<System.Int32>(5,6)";
+ s_IFooInt = "Base.IMethod1<System.Int32>(7,8)";
+ TestWithClass(new Derived());
+ Console.WriteLine("====================");
+
+
+ s_GMethod1 = "Derived.GMethod1<System.Int32>(1,2)";
+ s_IFooString = "Derived.IFoo<string>.IMethod1<System.Int32>(3,4)";
+ s_IFooObject = "Derived.IFoo<string>.IMethod1<System.Int32>(5,6)";
+ s_IFooInt = "SuperDerived.IFoo<int>.IMethod1<System.Int32>(7,8)";
+ TestWithClass(new SuperDerived());
+ Console.WriteLine("====================");
+ }
+
+ {
+ s_GMethod1 = "GenBase<System.Byte>.GMethod1<System.Int32>(1,2)";
+ s_IFooString = "GenBase<System.Byte>.IMethod1<System.Int32>(3,4)";
+ s_IFooObject = "GenBase<System.Byte>.IMethod1<System.Int32>(5,6)";
+ s_IFooInt = "GenBase<System.Byte>.IMethod1<System.Int32>(7,8)";
+ TestWithGenClass<byte>(new GenBase<byte>());
+ Console.WriteLine("====================");
+
+
+ s_GMethod1 = "GenDerived<System.Byte>.GMethod1<System.Int32>(1,2)";
+ s_IFooString = "GenDerived<System.Byte>.IFoo<string>.IMethod1<System.Int32>(3,4)";
+ s_IFooObject = "GenDerived<System.Byte>.IFoo<string>.IMethod1<System.Int32>(5,6)";
+ s_IFooInt = "GenBase<System.Byte>.IMethod1<System.Int32>(7,8)";
+ TestWithGenClass<byte>(new GenDerived<byte>());
+ Console.WriteLine("====================");
+
+
+ s_GMethod1 = "GenDerived<System.String>.GMethod1<System.Int32>(1,2)";
+ s_IFooString = "GenDerived<System.String>.IFoo<string>.IMethod1<System.Int32>(3,4)";
+ s_IFooObject = "GenDerived<System.String>.IFoo<string>.IMethod1<System.Int32>(5,6)";
+ s_IFooInt = "GenBase<System.String>.IMethod1<System.Int32>(7,8)";
+ TestWithGenClass<String>(new GenDerived<String>());
+ Console.WriteLine("====================");
+
+
+ s_GMethod1 = "GenDerived<System.Byte>.GMethod1<System.Int32>(1,2)";
+ s_IFooString = "GenDerived<System.Byte>.IFoo<string>.IMethod1<System.Int32>(3,4)";
+ s_IFooObject = "GenDerived<System.Byte>.IFoo<string>.IMethod1<System.Int32>(5,6)";
+ s_IFooInt = "GenSuperDerived<System.Byte>.IFoo<int>.IMethod1<System.Int32>(7,8)";
+ TestWithGenClass<byte>(new GenSuperDerived<byte>());
+ Console.WriteLine("====================");
+ }
+
+ {
+ s_IFooString = "MyStruct1.IFoo<string>.IMethod1<System.Int32>(1,2)";
+ s_IFooObject = "MyStruct1.IFoo<string>.IMethod1<System.Int32>(3,4)";
+ s_IFooInt = "MyStruct1.IFoo<int>.IMethod1<System.Int32>(5,6)";
+ TestWithStruct(new MyStruct1(), new MyStruct1(), new MyStruct1());
+ Console.WriteLine("====================");
+
+
+ s_IFooString = "MyStruct2.IFoo<string>.IMethod1<System.Int32>(1,2)";
+ s_IFooObject = "MyStruct2.IFoo<string>.IMethod1<System.Int32>(3,4)";
+ s_IFooInt = "MyStruct2.IMethod1<System.Int32>(5,6)";
+ TestWithStruct(new MyStruct2(), new MyStruct2(), new MyStruct2());
+ Console.WriteLine("====================");
+
+
+ s_IFooString = "MyStruct3.IMethod1<System.Int32>(1,2)";
+ s_IFooObject = "MyStruct3.IMethod1<System.Int32>(3,4)";
+ s_IFooInt = "MyStruct3.IFoo<int>.IMethod1<System.Int32>(5,6)";
+ TestWithStruct(new MyStruct3(), new MyStruct3(), new MyStruct3());
+ Console.WriteLine("====================");
+ }
+
+ if (s_NumErrors != 0)
+ throw new Exception();
+ }
+ }
}