linux-packaging-mono/mcs/tests/test-async-18.cs
Jo Shields 8b9b85e7f5 Imported Upstream version 3.10.0
Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
2014-10-04 11:27:48 +01:00

73 lines
1.1 KiB
C#

using System;
using System.Threading.Tasks;
using System.Threading;
class Tester
{
async Task<int> Lambda_1 ()
{
int res = 1;
{
int a = 8;
Func<int> f = () => a;
res = await Task.Factory.StartNew (f).ConfigureAwait (false);
res += f ();
}
return res - 16;
}
async Task<int> Lambda_2 ()
{
int res = 1;
{
int a = 8;
Func<int> f = () => a + res;
res = await Task.Factory.StartNew (f).ConfigureAwait (false);
res += f ();
}
return res - 26;
}
async Task<int> Lambda_3<T> ()
{
int res = 1;
{
int a = 8;
Func<int> f = () => a;
res = await Task.Factory.StartNew (f).ConfigureAwait (false);
res += f ();
}
return res - 16;
}
public static int Main ()
{
var t = new Tester ().Lambda_1 ();
if (!Task.WaitAll (new [] { t }, 1000))
return 1;
if (t.Result != 0)
return 2;
t = new Tester ().Lambda_2 ();
if (!Task.WaitAll (new [] { t }, 1000))
return 3;
if (t.Result != 0)
return 4;
t = new Tester ().Lambda_3<ulong>();
if (!Task.WaitAll (new [] { t }, 1000))
return 5;
if (t.Result != 0)
return 6;
Console.WriteLine ("ok");
return 0;
}
}