Mark tests as not working under TARGET_JVM
[mono.git] / mono / mini / generics.2.cs
1 using System;
2
3 class Tests {
4
5         struct TestStruct {
6                 public int i;
7
8                 public TestStruct (int i) {
9                         this.i = i;
10                 }
11         }
12
13         static int Main ()
14         {
15                 return TestDriver.RunTests (typeof (Tests));
16         }
17
18         public static int test_1_nullable_unbox ()
19         {
20                 return Unbox<int?> (1).Value;
21         }
22
23         public static int test_1_nullable_unbox_null ()
24         {
25                 return Unbox<int?> (null).HasValue ? 0 : 1;
26         }
27
28         public static int test_1_nullable_box ()
29         {
30                 return (int) Box<int?> (1);
31         }
32
33         public static int test_1_nullable_box_null ()
34         {
35                 return Box<int?> (null) == null ? 1 : 0;
36         }
37
38         public static int test_1_isinst_nullable ()
39         {
40                 object o = 1;
41                 return (o is int?) ? 1 : 0;
42         }
43
44         public static int test_1_nullable_unbox_vtype ()
45         {
46                 return Unbox<TestStruct?> (new TestStruct (1)).Value.i;
47         }
48
49         public static int test_1_nullable_unbox_null_vtype ()
50         {
51                 return Unbox<TestStruct?> (null).HasValue ? 0 : 1;
52         }
53
54         public static int test_1_nullable_box_vtype ()
55         {
56                 return ((TestStruct)(Box<TestStruct?> (new TestStruct (1)))).i;
57         }
58
59         public static int test_1_nullable_box_null_vtype ()
60         {
61                 return Box<TestStruct?> (null) == null ? 1 : 0;
62         }
63
64         public static int test_1_isinst_nullable_vtype ()
65         {
66                 object o = new TestStruct (1);
67                 return (o is TestStruct?) ? 1 : 0;
68         }
69
70         public static void stelem_any<T> (T[] arr, T elem) {
71                 arr [0] = elem;
72         }
73
74         public static T ldelem_any<T> (T[] arr) {
75                 return arr [0];
76         }
77
78         public static int test_1_ldelem_stelem_any_int () {
79                 int[] arr = new int [3];
80                 stelem_any (arr, 1);
81
82                 return ldelem_any (arr);
83         }
84
85         interface ITest
86         {
87                 void Foo<T> ();
88         }
89
90         public static int test_0_iface_call_null_bug_77442 () {
91                 ITest test = null;
92
93                 try {
94                         test.Foo<int> ();
95                 }
96                 catch (NullReferenceException) {
97                         return 0;
98                 }
99                 
100                 return 1;
101         }
102
103         public struct GenericStruct<T> {
104                 public T t;
105
106                 public GenericStruct (T t) {
107                         this.t = t;
108                 }
109         }
110
111         public class GenericClass<T> {
112                 public T t;
113
114                 public GenericClass (T t) {
115                         this.t = t;
116                 }
117         }
118
119         public class MRO : MarshalByRefObject {
120                 public GenericStruct<int> struct_field;
121                 public GenericClass<int> class_field;
122         }
123
124         public static int test_0_ldfld_stfld_mro () {
125                 MRO m = new MRO ();
126                 GenericStruct<int> s = new GenericStruct<int> (5);
127                 // This generates stfld
128                 m.struct_field = s;
129
130                 // This generates ldflda
131                 if (m.struct_field.t != 5)
132                         return 1;
133
134                 // This generates ldfld
135                 GenericStruct<int> s2 = m.struct_field;
136                 if (s2.t != 5)
137                         return 2;
138
139                 if (m.struct_field.t != 5)
140                         return 3;
141
142                 m.class_field = new GenericClass<int> (5);
143                 if (m.class_field.t != 5)
144                         return 4;
145
146                 return 0;
147         }
148
149     public static int test_0_generic_virtual_call_on_vtype_unbox () {
150                 object o = new Object ();
151         IMyHandler h = new Handler(o);
152
153         if (h.Bar<object> () != o)
154                         return 1;
155                 else
156                         return 0;
157     }
158
159         public static int test_0_box_brtrue_opt_regress_81102 () {
160                 if (new Foo<int>(5).ToString () == "null")
161                         return 0;
162                 else
163                         return 1;
164         }
165
166         public class Foo<T1>
167         {
168                 public Foo(T1 t1)
169                 {
170                         m_t1 = t1;
171                 }
172                 
173                 public override string ToString()
174                 {
175                         return Bar(m_t1 == null ? "null" : "null");
176                 }
177
178                 public String Bar (String s) {
179                         return s;
180                 }
181                 
182                 readonly T1 m_t1;
183         }
184
185         public interface IMyHandler {
186                 object Bar<T>();
187         }
188
189         struct Handler : IMyHandler {
190                 object o;
191
192                 public Handler(object o) {
193                         this.o = o;
194                 }
195
196                 public object Bar<T>() {
197                         return o;
198                 }
199         }
200
201         static object Box<T> (T t)
202         {
203                 return t;
204         }
205         
206         static T Unbox <T> (object o) {
207                 return (T) o;
208         }
209 }