2010-01-04 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / tests / generic-virtual.2.cs
blob3cf9ce579d13a72854597f270148bb0625e89940
1 using System;
3 public class ClassA {}
4 public class ClassB {}
6 public delegate string[] StringArrayDelegate ();
8 public class Gen<T> {
9 static bool checkArr<S> (Array arr, int length) {
10 if (arr.GetType () != typeof (S[]))
11 return false;
12 if (arr.Length != length)
13 return false;
14 return true;
17 public bool test () {
18 return checkArr<ClassB> (newArr<ClassB> (), myLength ());
21 public virtual int myLength () {
22 return 3;
25 public virtual S[] newArr<S> () {
26 return new S[3];
30 public class GenSub<T> : Gen<T> {
31 public override int myLength () {
32 return 4;
35 public override S[] newArr<S> () {
36 return new S[4];
40 public class GenSubSub : GenSub<ClassA> {
41 public override int myLength () {
42 return 5;
45 public override S[] newArr<S> () {
46 return new S[5];
49 public static S[] staticNewArr<S> () {
50 return new S[5];
54 public class main {
55 public static int Main () {
56 Gen<ClassA> ga = new Gen<ClassA> ();
57 Gen<ClassA> gsa = new GenSub<ClassA> ();
58 Gen<ClassA> gss = new GenSubSub ();
59 int i;
61 for (i = 0; i < 100; ++i) {
62 if (!ga.test ())
63 return 1;
64 if (!gsa.test ())
65 return 1;
66 if (!gss.test ())
67 return 1;
69 StringArrayDelegate sad = new StringArrayDelegate (GenSubSub.staticNewArr<string>);
70 string[] arr = sad ();
71 if (arr.GetType () != typeof (string[]))
72 return 1;
73 if (arr.Length != 5)
74 return 1;
76 sad = new StringArrayDelegate (gss.newArr<string>);
77 arr = sad ();
78 if (arr.GetType () != typeof (string[]))
79 return 1;
80 if (arr.Length != 5)
81 return 1;
84 /* A test for rebuilding generic virtual thunks */
85 for (i = 0; i < 1000; ++i) {
86 object o = ga.newArr<string> ();
87 if (!(o is string[]))
88 return 2;
90 for (i = 0; i < 1000; ++i) {
91 object o = ga.newArr<object> ();
92 if (!(o is object[]))
93 return 2;
96 return 0;