codeowners update
[mono.git] / mcs / tests / test-async-63.cs
1 using System;
2 using System.Threading.Tasks;
3
4 class C
5 {
6         static int counter;
7         public static async Task TestSingleAwait (bool throwException)
8         {
9                 try {
10                         if (throwException)
11                                 throw new ApplicationException ();
12                 } catch (ApplicationException ex) {
13                         Console.WriteLine ("x1a");
14                         ++counter;
15                         await Call ();
16                         Console.WriteLine ("x2a");
17                         ++counter;
18                 } catch {
19                         throw;
20                 }
21
22                 Console.WriteLine ("end");
23         }
24         
25         public static async Task TestDoubleAwait (bool throwException)
26         {
27                 try {
28                         if (throwException)
29                                 throw new ApplicationException ();
30                 } catch (ApplicationException ex) {
31                         Console.WriteLine ("x1a");
32                         ++counter;
33                         await Call ();
34                         Console.WriteLine ("x2a");
35                         ++counter;
36                 } catch {
37                         Console.WriteLine ("x1b");
38                         counter += 4;
39                         await Call ();
40                         Console.WriteLine ("x2b");
41                         counter += 7;
42                 }
43
44                 Console.WriteLine ("end");
45         }
46
47         static Task Call ()
48         {
49                 return Task.Factory.StartNew (() => false);
50         }
51
52         void HH ()
53         {
54                 try {
55                                 throw new ApplicationException ();
56                 } catch {
57                         throw;
58                 }
59         }
60
61         public static int Main ()
62         {
63                 TestSingleAwait (true).Wait ();
64                 Console.WriteLine (counter);
65                 if (counter != 2)
66                         return 1;
67
68                 TestSingleAwait (false).Wait ();
69                 if (counter != 2)
70                         return 2;
71
72                 counter = 0;
73
74                 TestDoubleAwait (true).Wait ();
75                 Console.WriteLine (counter);
76                 if (counter != 2)
77                         return 3;
78
79                 TestDoubleAwait (false).Wait ();
80                 if (counter != 2)
81                         return 4;               
82
83                 return 0;
84         }
85 }