[System.Net] Add support for .pac proxy config scripts on mac
[mono.git] / mcs / tests / test-async-11.cs
1 // Compiler options: -langversion:future
2
3 using System;
4 using System.Threading;
5 using System.Threading.Tasks;
6 using System.Collections.Generic;
7
8 // Async stack spilling tests
9
10 struct S
11 {
12         public int value;
13 }
14
15 enum E : byte
16 {
17         E_1,
18         E_2
19 }
20
21 class G<T>
22 {
23         public async Task<int> TestStack_1 (T t)
24         {
25                 T[] a = new T[] { t };
26                 return Call (t, a[0], out t,
27                         await Task.Factory.StartNew (() => 3).ConfigureAwait (false));
28         }
29         
30         int Call (T t1, T t2, out T t3, int i)
31         {
32                 t3 = t2;
33                 return 0;
34         }
35 }
36
37 class C
38 {
39         int field;
40         
41         int prop_value;
42         int get_called;
43         
44         int Prop {
45                 get {
46                         ++get_called;
47                         return prop_value;
48                 }
49                 set {
50                         prop_value += value;
51                 }
52         }
53
54         int TestCall (ref int a, Type type, object o, ulong ul, int b)
55         {
56                 field = a;
57                 
58                 if (type != typeof (string)) {
59                         return 1;
60                 }
61                 
62                 S s = (S) o;
63                 if (s.value != 4)
64                         return 2;
65                 
66                 if (ul != ulong.MaxValue)
67                         return 3;
68                 
69                 return 0;
70         }
71         
72         static async Task<int> TestStack_1 ()
73         {
74                 int v = 9;
75                 var array = new ulong[] { ulong.MaxValue };
76                 return new C ().TestCall (ref v, typeof (string), new S () { value = 4 }, array [0],
77                         await Task.Factory.StartNew (() => 3).ConfigureAwait (false));
78         }
79
80         int TestCall2<T1, T2, T3, T4, T5, T6, T7> (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
81         {
82                 return 0;
83         }
84         
85         static async Task<int> TestStack_2 (ulong value)
86         {
87                 short v = 2;
88                 return new C ().TestCall2 ((byte) 1, v, value = 9999, float.MaxValue, double.MaxValue, decimal.MaxValue,
89                         await Task.Factory.StartNew (() => 3).ConfigureAwait (false));
90         }
91
92         static async Task<int> TestStack_3 ()
93         {
94                 var s = new S [] { new S () };
95                 s[0].value = 6;
96                 
97                 var s2 = new S [,] { { new S () }, { new S () } };
98                 s2[0, 0].value = 3;
99                 
100                 TestCall3 (ref s [0], ref s2 [0, 0], s [0].value++,
101                         await Task.Factory.StartNew (() => 3).ConfigureAwait (false));
102                 
103                 if (s [0].value != 10)
104                         return 1;
105                 
106                 if (s2 [0, 0].value != 20)
107                         return 2;
108
109                 return 0;
110         }
111         
112         static int TestCall3 (ref S value, ref S value2, int value3, int i)
113         {
114                 value.value = 10;
115                 value2.value = 20;
116                 return 0;
117         }
118
119         static async Task<int> TestStack_4 ()
120         {
121                 var a1 = new [] { E.E_2 };
122                 var a2 = new [] { new S () { value = 5 } };
123                 var a3 = new [] { new C () };
124                 
125                 return TestCall4 (a1[0], a2[0], a3[0],
126                         await Task.Factory.StartNew (() => 3).ConfigureAwait (false));
127         }
128         
129         static int TestCall4 (E e, S s, C c, int i)
130         {
131                 if (e != E.E_2)
132                         return 100;
133                 
134                 if (s.value != 5)
135                         return 101;
136                 
137                 if (i != 3)
138                         return 102;
139                 
140                 return 0;
141         }
142         
143         static async Task<int> TestStack_5 ()
144         {
145                 var c = new C ();
146                 c.prop_value = 7;
147                 c.Prop += await Task.Factory.StartNew (() => {
148                         if (c.get_called != 1) 
149                                 return -44;
150                         
151                         c.prop_value = 99;
152                         return 3;
153                 }).ConfigureAwait (false);
154                 
155                 if (c.get_called != 1)
156                         return 1;
157                 
158                 if (c.prop_value != 109)
159                         return 2;
160
161                 return 0;
162         }
163
164         public static int Main ()
165         {
166                 Task<int> t;
167
168                 t = TestStack_1 ();
169                 if (!Task.WaitAll (new[] { t }, 1000))
170                         return 1;
171                 
172                 if (t.Result != 0)
173                         return 2;
174                 
175                 t = TestStack_2 (ulong.MaxValue);
176                 if (!Task.WaitAll (new[] { t }, 1000))
177                         return 3;
178                 
179                 if (t.Result != 0)
180                         return 4;
181                 
182                 t = TestStack_3 ();
183                 if (!Task.WaitAll (new[] { t }, 1000))
184                         return 4;
185                 
186                 if (t.Result != 0)
187                         return 5;
188                 
189                 t = TestStack_4 ();
190                 if (!Task.WaitAll (new[] { t }, 1000))
191                         return 6;
192                 
193                 if (t.Result != 0)
194                         return 7;
195                 
196                 var g = new G<sbyte> ();
197                 t = g.TestStack_1 (9);
198                 if (!Task.WaitAll (new[] { t }, 1000))
199                         return 8;
200                 
201                 if (t.Result != 0)
202                         return 9;
203                 
204                 t = TestStack_5 ();
205                 if (!Task.WaitAll (new[] { t }, 1000))
206                         return 10;
207                 
208                 if (t.Result != 0)
209                         return 11;
210                 
211                 Console.WriteLine ("ok");
212                 return 0;
213         }
214 }