[System.Net] Add support for .pac proxy config scripts on mac
[mono.git] / mcs / tests / test-async-10.cs
1 // Compiler options: -langversion:future
2
3 using System;
4 using System.Threading.Tasks;
5 using System.Threading;
6 using System.Collections.Generic;
7
8
9 class C
10 {
11         static async Task<string> TestCompositionCall_1 ()
12         {
13                 return await Task.Factory.StartNew (() => { Thread.Sleep (10); return "a"; }).ConfigureAwait (false) +
14                         await Task.Factory.StartNew (() => "b").ConfigureAwait (false) + "c";
15         }
16
17         static async Task<string> TestCompositionCall_2 ()
18         {
19                 return "a" + 1.ToString () +
20                         await Task.Factory.StartNew (() => "b").ConfigureAwait (false) + "c";
21         }
22
23         static async Task<int> TestCompositionCall_3 ()
24         {
25                 return await M (await Task.Factory.StartNew (() => (byte) 4).ConfigureAwait (false)).ConfigureAwait (false);
26         }
27
28         static async Task<int> TestCompositionPair_1 ()
29         {
30                 return await Task.Factory.StartNew (() => 3).ConfigureAwait (false) + 6;
31         }
32
33         static async Task<int> TestCompositionPair_2 ()
34         {
35                 return await Task.Factory.StartNew (() => { Thread.Sleep (10); return 3; }).ConfigureAwait (false) - 
36                         await Task.Factory.StartNew (() => 4).ConfigureAwait (false);
37         }
38
39         static async Task<int> TestCompositionPair_3 ()
40         {
41                 return -8 * 
42                         await Task.Factory.StartNew (() => 4).ConfigureAwait (false);
43         }
44
45         static async Task<int> TestCompositionPair_4 ()
46         {
47                 return await Task.Factory.StartNew (() => 3).ConfigureAwait (false) + 
48                         await Task.Factory.StartNew (() => 4).ConfigureAwait (false) +
49                         await Task.Factory.StartNew (() => 7).ConfigureAwait (false);
50         }
51         
52         static Task<byte> M (byte value)
53         {
54                 return Task.Factory.StartNew (() => value);
55         }
56         
57         public static int Main ()
58         {
59                 var t1 = TestCompositionCall_1 ();
60                 if (!Task.WaitAll (new[] { t1 }, 1000))
61                         return 1;
62                 
63                 if (t1.Result != "abc")
64                         return 2;
65                 
66                 var t2 = TestCompositionCall_2 ();
67                 if (!Task.WaitAll (new[] { t2 }, 1000))
68                         return 3;
69                 
70                 if (t2.Result != "a1bc")
71                         return 4;
72                 
73                 var t3 = TestCompositionCall_3 ();
74                 if (!Task.WaitAll (new[] { t3 }, 1000))
75                         return 5;
76                 
77                 if (t3.Result != 4)
78                         return 6;
79
80                 var t5 = TestCompositionPair_1 ();
81                 if (!Task.WaitAll (new[] { t5 }, 1000))
82                         return 7;
83                 
84                 if (t5.Result != 9)
85                         return 8;
86                 
87                 var t6 = TestCompositionPair_2 ();
88                 if (!Task.WaitAll (new[] { t6 }, 1000))
89                         return 9;
90                 
91                 if (t6.Result != -1)
92                         return 10;
93
94                 var t7 = TestCompositionPair_3 ();
95                 if (!Task.WaitAll (new[] { t7 }, 1000))
96                         return 11;
97                 
98                 if (t7.Result != -32)
99                         return 12;
100
101                 var t8 = TestCompositionPair_4 ();
102                 if (!Task.WaitAll (new[] { t8 }, 1000))
103                         return 13;
104                 
105                 if (t8.Result != 14)
106                         return 14;
107                 
108                 Console.WriteLine ("ok");
109                 return 0;
110         }
111 }