summaryrefslogtreecommitdiff
path: root/mcs/tests/test-async-63.cs
blob: 4572d7e2eda3e3cc4acf76583643d0e333f3422f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Threading.Tasks;

class C
{
	static int counter;
	public static async Task TestSingleAwait (bool throwException)
	{
		try {
			if (throwException)
				throw new ApplicationException ();
		} catch (ApplicationException ex) {
			Console.WriteLine ("x1a");
			++counter;
			await Call ();
			Console.WriteLine ("x2a");
			++counter;
		} catch {
			throw;
		}

		Console.WriteLine ("end");
	}
	
	public static async Task TestDoubleAwait (bool throwException)
	{
		try {
			if (throwException)
				throw new ApplicationException ();
		} catch (ApplicationException ex) {
			Console.WriteLine ("x1a");
			++counter;
			await Call ();
			Console.WriteLine ("x2a");
			++counter;
		} catch {
			Console.WriteLine ("x1b");
			counter += 4;
			await Call ();
			Console.WriteLine ("x2b");
			counter += 7;
		}

		Console.WriteLine ("end");
	}

	static Task Call ()
	{
		return Task.Factory.StartNew (() => false);
	}

	void HH ()
	{
		try {
				throw new ApplicationException ();
		} catch {
			throw;
		}
	}

	public static int Main ()
	{
		TestSingleAwait (true).Wait ();
		Console.WriteLine (counter);
		if (counter != 2)
			return 1;

		TestSingleAwait (false).Wait ();
		if (counter != 2)
			return 2;

		counter = 0;

		TestDoubleAwait (true).Wait ();
		Console.WriteLine (counter);
		if (counter != 2)
			return 3;

		TestDoubleAwait (false).Wait ();
		if (counter != 2)
			return 4;		

		return 0;
	}
}