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