Add more test files
[mono.git] / mcs / tests / test-async-02.cs
1 // Compiler options: -langversion:future
2
3 using System;
4 using System.Threading.Tasks;
5 using System.Threading;
6
7 class C
8 {
9         ManualResetEvent mre = new ManualResetEvent (false);
10
11         public async Task TestTask ()
12         {
13                 await Call ();
14         }
15
16         Task Call ()
17         {
18                 return Task.Factory.StartNew (() => {
19                         mre.WaitOne ();
20                         Console.WriteLine ("a");
21                 });
22         }
23
24         public async Task<int> TestTaskGeneric ()
25         {
26                 return await CallGeneric ();
27         }
28
29         Task<int> CallGeneric ()
30         {
31                 return Task.Factory.StartNew (() => {
32                         mre.WaitOne ();
33                         return 5;
34                 });
35         }
36
37         public static int Main ()
38         {
39                 var c = new C ();
40                 var t = c.TestTask ();
41                 if (t.Status != TaskStatus.WaitingForActivation)
42                         return 1;
43
44                 c.mre.Set ();
45                 Task.WaitAll (t);
46
47                 if (t.Status != TaskStatus.RanToCompletion)
48                         return 2;
49
50                 c = new C ();
51                 var t2 = c.TestTaskGeneric ();
52                 if (t2.Status != TaskStatus.WaitingForActivation)
53                         return 3;
54
55                 c.mre.Set ();
56                 Task.WaitAll (t2);
57
58                 if (t2.Result != 5)
59                         return 4;
60
61                 if (t2.Status != TaskStatus.RanToCompletion)
62                         return 5;
63
64                 return 0;
65         }
66 }