2008-04-10 Mark Probst <mark.probst@gmail.com>
[mono.git] / mono / tests / generic-virtual.2.cs
1 using System;
2
3 public class ClassA {}
4 public class ClassB {}
5
6 public class Gen<T> {
7         static bool checkArr<S> (Array arr, int length) {
8                 if (arr.GetType () != typeof (S[]))
9                         return false;
10                 if (arr.Length != length)
11                         return false;
12                 return true;
13         }
14
15         public bool test () {
16                 return checkArr<ClassB> (newArr<ClassB> (), myLength ());
17         }
18
19         public virtual int myLength () {
20                 return 3;
21         }
22
23         public virtual S[] newArr<S> () {
24                 return new S[3];
25         }
26 }
27
28 public class GenSub<T> : Gen<T> {
29         public override int myLength () {
30                 return 4;
31         }
32
33         public override S[] newArr<S> () {
34                 return new S[4];
35         }
36 }
37
38 public class GenSubSub : GenSub<ClassA> {
39         public override int myLength () {
40                 return 5;
41         }
42
43         public override S[] newArr<S> () {
44                 return new S[5];
45         }
46 }
47
48 public class main {
49         public static int Main () {
50                 Gen<ClassA> ga = new Gen<ClassA> ();
51                 Gen<ClassA> gsa = new GenSub<ClassA> ();
52                 Gen<ClassA> gss = new GenSubSub ();
53
54                 if (!ga.test ())
55                         return 1;
56                 if (!gsa.test ())
57                         return 1;
58                 if (!gss.test ())
59                         return 1;
60                 return 0;
61         }
62 }