// 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. /* Test the following matrix for structs with virtual newslot final methods (implicit override): Non-Generic virtual methods: Non-generic Interface Generic Interface Non-generic type N/A Test4 Generic type Test2 Test6 Generic virtual methods: Non-generic Interface Generic Interface Non-generic type Test1 Test5 Generic type Test3 Test7 */ using System; public class A {} public struct S {} public interface I { int method1(); int method2(); } public interface IGen { int method1(); int method2(); } public struct C1 : I { public int method1() { return 1; } public int method2() { return 2; } } public struct C2 : I { public int method1() { return 3; } public int method2() { return 4; } } public struct C3Int : IGen { public int method1() { return 5; } public int method2() { return 6; } } public struct C3String : IGen { public int method1() { return 5; } public int method2() { return 6; } } public struct C3Object: IGen { public int method1() { return 5; } public int method2() { return 6; } } public struct C4 : IGen { public int method1() { return 7; } public int method2() { return 8; } } public class Test { public static bool pass = true; public static void TestNonGenInterface_NonGenType() { I ic1 = new C1(); // TEST1: test generic virtual method if (ic1.method2() != 2 || ic1.method2() != 2 || ic1.method2() != 2 || ic1.method2>() != 2 || ic1.method2>() != 2 ) { Console.WriteLine("Failed at TestNonGenInterface_NonGenType: generic method"); pass = false; } } public static void TestNonGenInterface_GenType() { I ic2Int = new C2(); I ic2Object = new C2(); I ic2String = new C2(); // TEST2: test non generic virtual method if ( ic2Int.method1() != 3 || ic2String.method1() != 3 || ic2Object.method1() != 3 ) { Console.WriteLine("Failed at TestNonGenInterface_GenType: non generic method"); pass = false; } // TEST3: test generic virtual method if (ic2Int.method2() != 4 || ic2Int.method2() != 4|| ic2Int.method2() != 4 || ic2Int.method2>() != 4 || ic2Int.method2>() != 4 || ic2String.method2() != 4 || ic2String.method2() != 4|| ic2String.method2() != 4 || ic2String.method2>() != 4 || ic2String.method2>() != 4 || ic2Object.method2() != 4 || ic2Object.method2() != 4|| ic2Object.method2() != 4 || ic2Object.method2>() != 4 || ic2Object.method2>() != 4 ) { Console.WriteLine("Failed at TestNonGenInterface_GenType: generic method"); pass = false; } } public static void TestGenInterface_NonGenType() { IGen iIntc3 = new C3Int(); IGen iObjectc3 = new C3Object(); IGen iStringc3 = new C3String(); // TEST4: test non generic virtual method if ( iIntc3.method1() != 5 || iObjectc3.method1() != 5 || iStringc3.method1() != 5 ) { Console.WriteLine("Failed at TestGenInterface_NonGenType: non generic method"); pass = false; } // TEST5: test generic virtual method if (iIntc3.method2() != 6 || iIntc3.method2() != 6|| iIntc3.method2() != 6 || iIntc3.method2>() != 6 || iIntc3.method2>() != 6 || iObjectc3.method2() != 6 || iObjectc3.method2() != 6|| iObjectc3.method2() != 6 || iObjectc3.method2>() != 6 || iObjectc3.method2>() != 6 || iStringc3.method2() != 6 || iStringc3.method2() != 6|| iStringc3.method2() != 6 || iStringc3.method2>() != 6 || iStringc3.method2>() != 6 ) { Console.WriteLine("Failed at TestGenInterface_NonGenType: generic method"); pass = false; } } public static void TestGenInterface_GenType() { IGen iGenC4Int = new C4(); IGen iGenC4Object = new C4(); IGen iGenC4String = new C4(); // TEST6: test non generic virtual method if ( iGenC4Int.method1() != 7 || iGenC4Object.method1() != 7 || iGenC4String.method1() != 7 ) { Console.WriteLine("Failed at TestGenInterface_GenType: non generic method"); pass = false; } // TEST7: test generic virtual method if (iGenC4Int.method2() != 8 || iGenC4Int.method2() != 8 || iGenC4Int.method2() != 8 || iGenC4Int.method2>() != 8 || iGenC4Int.method2>() != 8 || iGenC4Object.method2() != 8 || iGenC4Object.method2() != 8 || iGenC4Object.method2() != 8 || iGenC4Object.method2>() != 8 || iGenC4Object.method2>() != 8 || iGenC4String.method2() != 8 || iGenC4String.method2() != 8 || iGenC4String.method2() != 8 || iGenC4String.method2>() != 8 || iGenC4String.method2>() != 8 ) { Console.WriteLine("Failed at TestGenInterface_GenType: generic method"); pass = false; } } public static int Main() { TestNonGenInterface_NonGenType(); TestNonGenInterface_GenType(); TestGenInterface_NonGenType(); TestGenInterface_GenType(); if (pass) { Console.WriteLine("PASS"); return 100; } else { Console.WriteLine("FAIL"); return 101; } } }