Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-async-72.cs
1 using System;
2 using System.Threading.Tasks;
3
4 class Test
5 {
6         static async Task<int> YieldValue (int a)
7         {
8                 await Task.Yield ();
9                 return a;
10         }
11
12         public static async Task<int> BreakTest ()
13         {
14                 int value = 0;
15                 try {
16                         for (int i = 0; i < 8; ++i) {
17                                 try {
18                                         try {
19                                                 value += await YieldValue (1);
20
21                                                 Console.WriteLine ("i = " + i);
22
23                                                 if (i > 2)
24                                                         break;
25
26                                                 if (i > 1)
27                                                         throw new ApplicationException ();
28                                         } catch (ApplicationException) {
29                                                 Console.WriteLine ("catch");
30                                                 value += await YieldValue (100);
31                                         }
32                                 } finally {
33                                         Console.WriteLine ("F1");
34                                         value += await YieldValue (10);
35                                 }
36                         }
37                 } finally {
38                         Console.WriteLine ("F2");
39                         value += await YieldValue (1000);
40                 }
41
42                 return value;
43         }
44
45         public static async Task<int> ContinueTest ()
46         {
47                 int value = 0;
48                 try {
49                         for (int i = 0; i < 8; ++i) {
50                                 try {
51                                         try {
52                                                 value += await YieldValue (1);
53
54                                                 Console.WriteLine ("i = " + i);
55
56                                                 if (i < 2)
57                                                         continue;
58
59                                                 if (i > 1)
60                                                         throw new ApplicationException ();
61                                         } catch (ApplicationException) {
62                                                 Console.WriteLine ("catch");
63                                                 value += await YieldValue (100);
64                                         }
65                                 } finally {
66                                         Console.WriteLine ("F1");
67                                         value += await YieldValue (10);
68                                 }
69                         }
70                 } finally {
71                         Console.WriteLine ("F2");
72                         value += await YieldValue (1000);
73                 }
74
75                 return value;
76         }
77
78         public static int Main ()
79         {
80                 if (BreakTest ().Result != 1144)
81                         return 1;
82
83                 if (ContinueTest ().Result != 1688)
84                         return 1;
85
86                 return 0;
87         }
88 }