Merge pull request #5675 from mono/glib-debug-symbols
[mono.git] / mcs / tests / test-async-14.cs
1 using System;
2 using System.Threading.Tasks;
3 using System.Threading;
4
5 class C
6 {
7         public async Task<int> TestResult ()
8         {
9                 if (await Task.Factory.StartNew (() => 8).ConfigureAwait (false) != 9) {
10                         return 2;
11                 }
12                 
13                 return 0;
14         }
15
16         public static int Main ()
17         {
18                 var c = new C ();
19                 var t = c.TestResult ();
20
21                 if (!Task.WaitAll (new[] { t }, 3000))
22                         return 1;
23
24                 if (t.Status != TaskStatus.RanToCompletion)
25                         return 2;
26                 
27                 if (t.Result != 2)
28                         return 3;
29                 
30                 Func<Task<int>> f = async () => {
31                         var tr = await Task.Factory.StartNew (() => 1).ConfigureAwait (false);
32                         if (tr == 1)
33                                 return 3;
34
35                         return 1;
36                 };
37                 
38                 var t2 = f ();
39
40                 if (!Task.WaitAll (new[] { t2 }, 3000))
41                         return 4;
42
43                 if (t2.Status != TaskStatus.RanToCompletion)
44                         return 5;
45                 
46                 if (t2.Result != 3)
47                         return 6;
48
49                 Console.WriteLine ("ok");
50                 return 0;
51         }
52 }