[runtime] Remove all NACL support. It was unmaintained for a long time. (#4955)
[mono.git] / mono / tests / generic-virtual.2.cs
1 using System;
2
3 public class ClassA {}
4 public class ClassB {}
5
6 public delegate string[] StringArrayDelegate ();
7
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;
15         }
16
17         public bool test () {
18                 return checkArr<ClassB> (newArr<ClassB> (), myLength ());
19         }
20
21         public virtual int myLength () {
22                 return 3;
23         }
24
25         public virtual S[] newArr<S> () {
26                 return new S[3];
27         }
28 }
29
30 public class GenSub<T> : Gen<T> {
31         public override int myLength () {
32                 return 4;
33         }
34
35         public override S[] newArr<S> () {
36                 return new S[4];
37         }
38 }
39
40 public class GenSubSub : GenSub<ClassA> {
41         public override int myLength () {
42                 return 5;
43         }
44
45         public override S[] newArr<S> () {
46                 return new S[5];
47         }
48
49         public static S[] staticNewArr<S> () {
50                 return new S[5];
51         }
52 }
53
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;
60
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;
68
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;
75
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;
82                 }
83
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;
89                 }
90                 for (i = 0; i < 1000; ++i) {
91                         object o = ga.newArr<object> ();
92                         if (!(o is object[]))
93                                 return 2;
94                 }
95
96                 return 0;
97         }
98 }