[tuner] handle the case with multiple "preserve" attributes
[mono-project.git] / mcs / tests / test-async-15.cs
bloba3ae814086e2e10e58f9060f496815d011fce6b0
1 using System;
2 using System.Threading.Tasks;
3 using System.Threading;
4 using System.Collections;
5 using System.Collections.Generic;
7 interface IFoo
9 int Value { get; set; }
12 struct S : IFoo
14 public S (int a1, string a2)
15 : this ()
17 Value = a1;
20 public int Value { get; set; }
22 public void SetValue (int value)
24 Value = value;
28 struct S2 : IEnumerable
30 public List<int> Values;
32 public void Add (int x)
34 if (Values == null)
35 Values = new List<int> ();
37 Values.Add(x);
40 public IEnumerator GetEnumerator()
42 return Values as IEnumerator;
46 class Tester
48 async Task<T> NewInitTestGen<T> () where T : struct, IFoo
50 var s = new T () {
51 Value = await Task.Factory.StartNew (() => 13).ConfigureAwait (false)
54 if (s.Value != 13)
55 return new T ();
57 return s;
60 static async Task<int> NewInitCol ()
62 var s = new S2 {
63 await Task.FromResult (1),
64 await Task.Factory.StartNew (() => 2)
67 return s.Values [0] + s.Values [1];
70 public static int Main ()
72 var t = new Tester().NewInitTestGen<S> ();
74 if (!Task.WaitAll (new[] { t }, 1000)) {
75 return 1;
78 if (t.Result.Value != 13)
79 return 2;
81 var v = NewInitCol ().Result;
82 if (v != 3)
83 return 3;
85 return 0;