[System.Net] Add support for .pac proxy config scripts on mac
[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 ().ConfigureAwait (false);
14         }
15
16         public async Task TestTask2 ()
17         {
18                 await Call ().ConfigureAwait (false);
19                 return;
20         }
21
22         Task Call ()
23         {
24                 return Task.Factory.StartNew (() => {
25                         mre.WaitOne (3000);
26                         Console.WriteLine ("a");
27                 });
28         }
29
30         public async Task<int> TestTaskGeneric ()
31         {
32                 return await CallGeneric ().ConfigureAwait (false);
33         }
34
35         Task<int> CallGeneric ()
36         {
37                 return Task.Factory.StartNew (() => {
38                         mre.WaitOne (3000);
39                         return 5;
40                 });
41         }
42
43         public static int Main ()
44         {
45                 var c = new C ();
46                 var t = c.TestTask ();
47                 if (t.Status != TaskStatus.WaitingForActivation)
48                         return 1;
49
50                 c.mre.Set ();
51                 if (!Task.WaitAll (new[] { t }, 3000))
52                         return 2;
53
54                 if (t.Status != TaskStatus.RanToCompletion)
55                         return 3;
56
57                 c = new C ();
58                 t = c.TestTask2 ();
59                 if (t.Status != TaskStatus.WaitingForActivation)
60                         return 4;
61
62                 c.mre.Set ();
63                 if (!Task.WaitAll (new[] { t }, 3000))
64                         return 5;
65
66                 if (t.Status != TaskStatus.RanToCompletion)
67                         return 6;
68
69                 c = new C ();
70                 var t2 = c.TestTaskGeneric ();
71                 if (t2.Status != TaskStatus.WaitingForActivation)
72                         return 7;
73
74                 c.mre.Set ();
75                 if (!Task.WaitAll (new[] { t2 }, 3000))
76                         return 8;
77
78                 if (t2.Result != 5)
79                         return 9;
80
81                 if (t2.Status != TaskStatus.RanToCompletion)
82                         return 10;
83
84                 return 0;
85         }
86 }