Merge pull request #472 from MelanieT/spmanager_fix
[mono.git] / mcs / tests / test-async-18.cs
1 // Compiler options: -langversion:future
2 using System;
3 using System.Threading.Tasks;
4 using System.Threading;
5
6 class Tester
7 {
8         async Task<int> Lambda_1 ()
9         {
10                 int res = 1;
11                 {
12                         int a = 8;
13                         Func<int> f = () => a;
14                         res = await Task.Factory.StartNew (f).ConfigureAwait (false);
15                         res += f ();
16                 }
17                 
18                 return res - 16;
19         }
20         
21         async Task<int> Lambda_2 ()
22         {
23                 int res = 1;
24                 {
25                         int a = 8;
26                         Func<int> f = () => a + res;
27                         res = await Task.Factory.StartNew (f).ConfigureAwait (false);
28                         res += f ();
29                 }
30                 
31                 return res - 26;
32         }
33         
34         async Task<int> Lambda_3<T> ()
35         {
36                 int res = 1;
37                 {
38                         int a = 8;
39                         Func<int> f = () => a;
40                         res = await Task.Factory.StartNew (f).ConfigureAwait (false);
41                         res += f ();
42                 }
43                 
44                 return res - 16;
45         }       
46
47         public static int Main ()
48         {
49                 var t = new Tester ().Lambda_1 ();
50                 if (!Task.WaitAll (new [] { t }, 1000))
51                         return 1;
52                 
53                 if (t.Result != 0)
54                         return 2;
55                 
56                 t = new Tester ().Lambda_2 ();
57                 if (!Task.WaitAll (new [] { t }, 1000))
58                         return 3;
59                 
60                 if (t.Result != 0)
61                         return 4;
62
63                 t = new Tester ().Lambda_3<ulong>();
64                 if (!Task.WaitAll (new [] { t }, 1000))
65                         return 5;
66                 
67                 if (t.Result != 0)
68                         return 6;
69                 
70                 Console.WriteLine ("ok");
71                 return 0;
72         }
73 }