Merge pull request #129 from grumpydev/CryptoFixo
[mono.git] / mcs / tests / test-async-15.cs
1 // Compiler options: -langversion:future
2
3 using System;
4 using System.Threading.Tasks;
5 using System.Threading;
6
7 interface IFoo
8 {
9         int Value { get; set; }
10 }
11
12 struct S : IFoo
13 {
14         public S (int a1, string a2)
15                 : this ()
16         {
17                 Value = a1;
18         }
19         
20         public int Value { get; set; }
21         
22         public void SetValue (int value)
23         {
24                 Value = value;
25         }
26 }
27
28 class Tester
29 {
30         async Task<T> NewInitTestGen<T> () where T : struct, IFoo
31         {
32                 int value = 9;
33                 
34                 var s = new T () {
35                         Value = await Task.Factory.StartNew (() => 13)
36                 };
37                 
38                 if (s.Value != 13)
39                         return new T ();
40                 
41                 return s;
42         }
43         
44         public static int Main ()
45         {
46                 var t = new Tester().NewInitTestGen<S> ();
47                 
48                 if (!Task.WaitAll (new[] { t }, 1000)) {
49                         return 1;
50                 }
51                 
52                 if (t.Result.Value != 13)
53                         return 2;
54                 
55                 return 0;
56         }
57 }