[threads] Don't ignore abort requests in abort protected blocks
[mono.git] / mono / mini / generics-interp.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Runtime.CompilerServices;
5 using System.Threading;
6 using System.Threading.Tasks;
7
8 #if __MOBILE__
9 class GenericsTests
10 #else
11 class Tests
12 #endif
13 {
14         struct TestStruct {
15                 public int i;
16                 public int j;
17
18                 public TestStruct (int i, int j) {
19                         this.i = i;
20                         this.j = j;
21                 }
22         }
23
24 #if !__MOBILE__
25         public static int Main (string[] args) {
26                 return TestDriver.RunTests (typeof (Tests), args);
27         }
28 #endif
29
30         public static int test_1_no_nullable_unbox ()
31         {
32                 return Unbox<int> (1);
33         }
34
35         public static int test_1_nullable_unbox_null ()
36         {
37                 return Unbox<int?> (null).HasValue ? 0 : 1;
38         }
39
40         public static int test_1_nullable_box ()
41         {
42                 return (int) Box<int?> (1);
43         }
44
45         public static int test_1_nullable_box_null ()
46         {
47                 return Box<int?> (null) == null ? 1 : 0;
48         }
49
50         public static int test_1_isinst_nullable ()
51         {
52                 object o = 1;
53                 return (o is int?) ? 1 : 0;
54         }
55
56         public static int test_1_nullable_unbox_vtype ()
57         {
58                 return Unbox<TestStruct?> (new TestStruct (1, 2)).Value.i;
59         }
60
61
62         public static int test_1_nullable_unbox_null_vtype ()
63         {
64                 return Unbox<TestStruct?> (null).HasValue ? 0 : 1;
65         }
66
67         public static int test_1_nullable_box_vtype ()
68         {
69                 return ((TestStruct)(Box<TestStruct?> (new TestStruct (1, 2)))).i;
70         }
71
72         public static int test_1_nullable_box_null_vtype ()
73         {
74                 return Box<TestStruct?> (null) == null ? 1 : 0;
75         }
76
77         public static int test_1_isinst_nullable_vtype ()
78         {
79                 object o = new TestStruct (1, 2);
80                 return (o is TestStruct?) ? 1 : 0;
81         }
82
83         public static int test_0_nullable_normal_unbox ()
84         {
85                 int? i = 5;
86
87                 object o = i;
88                 // This uses unbox instead of unbox_any
89                 int? j = (int?)o;
90
91                 if (j != 5)
92                         return 1;
93
94                 return 0;
95         }
96
97         public static void stelem_any<T> (T[] arr, T elem) {
98                 arr [0] = elem;
99         }
100
101         public static T ldelem_any<T> (T[] arr) {
102                 return arr [0];
103         }
104
105         public static int test_1_ldelem_stelem_any_int () {
106                 int[] arr = new int [3];
107                 stelem_any (arr, 1);
108
109                 return ldelem_any (arr);
110         }
111
112         public static T return_ref<T> (ref T t) {
113                 return t;
114         }
115
116         public static T ldelema_any<T> (T[] arr) {
117                 return return_ref<T> (ref arr [0]);
118         }
119
120         public static int test_0_ldelema () {
121                 string[] arr = new string [1];
122
123                 arr [0] = "Hello";
124
125                 if (ldelema_any <string> (arr) == "Hello")
126                         return 0;
127                 else
128                         return 1;
129         }
130
131         public static T[,] newarr_multi<T> () {
132                 return new T [1, 1];
133         }
134
135         public static int test_0_newarr_multi_dim () {
136                 return newarr_multi<string> ().GetType () == typeof (string[,]) ? 0 : 1;
137         }
138
139         static object Box<T> (T t)
140         {
141                 return t;
142         }
143
144         static T Unbox <T> (object o) {
145                 return (T) o;
146         }
147 }