[corlib] Make Marshal.BufferToBSTR(Array, int) non-public again (#5670)
[mono.git] / mcs / tests / test-async-69.cs
1 using System;
2 using System.Threading.Tasks;
3
4 class Test
5 {
6         static bool fin;
7
8         static async Task<int> YieldValue (int a)
9         {
10                 await Task.Yield ();
11                 return a;
12         }
13
14         static async Task<int> TestFinallyWithReturn (int value)
15         {
16                 fin = false;
17                 try {
18                         if (value > 4)
19                                 return 5;
20
21                         value += 10;
22                         Console.WriteLine ("try");
23                 } finally {
24                         fin = true;
25                         Console.WriteLine ("finally");
26                         value += await YieldValue (100);
27                 }
28
29                 value += 1000;
30                 Console.WriteLine ("over");
31
32                 return value;
33         }
34
35         static async Task TestFinallyWithReturnNoValue (int value)
36         {
37                 fin = false;
38                 try {
39                         if (value > 4)
40                                 return;
41
42                         value += 10;
43                         Console.WriteLine ("try");
44                 } finally {
45                         fin = true;
46                         Console.WriteLine ("finally");
47                         value += await YieldValue (100);
48                 }
49
50                 value += 1000;
51                 Console.WriteLine ("over");
52         }
53
54         static async Task<int> TestFinallyWithGoto (int value)
55         {
56                 fin = false;
57                 try {
58                         if (value > 4)
59                                 goto L;
60
61                         value += 10;
62                         Console.WriteLine ("try");
63                 } finally {
64                         fin = true;
65                         Console.WriteLine ("finally");
66                         value += await YieldValue (100);
67                 }
68                 value += 1000;
69 L:
70                 Console.WriteLine ("over");
71                 return value;
72         }
73
74          static async Task<int> TestFinallyWithGotoAndReturn (int value)
75         {
76                 fin = false;
77                 try {
78                         if (value > 4)
79                                 goto L;
80
81                         value += 10;
82                         Console.WriteLine ("try");
83                         if (value > 12)
84                                 return 9;
85                 } finally {
86                         fin = true;
87                         Console.WriteLine ("finally");
88                         value += await YieldValue (100);
89                 }
90                 value += 1000;
91 L:
92                 Console.WriteLine ("over");
93                 return value;
94         }
95
96         public static int Main ()
97         {
98                 if (TestFinallyWithReturn (9).Result != 5)
99                         return 1;
100
101                 if (!fin)
102                         return 2;
103
104                 if (TestFinallyWithReturn (1).Result != 1111)
105                         return 3;
106
107                 if (!fin)
108                         return 4;
109
110                 TestFinallyWithReturnNoValue (9).Wait ();
111                 if (!fin)
112                         return 5;
113
114                 TestFinallyWithReturnNoValue (1).Wait ();
115                 if (!fin)
116                         return 6;
117
118                 if (TestFinallyWithGoto (9).Result != 109)
119                         return 7;
120
121                 if (!fin)
122                         return 8;
123
124                 if (TestFinallyWithGoto (1).Result != 1111)
125                         return 9;
126
127                 if (!fin)
128                         return 10;
129
130                 if (TestFinallyWithGotoAndReturn (9).Result != 109)
131                         return 11;
132
133                 if (!fin)
134                         return 12;
135
136                 if (TestFinallyWithGotoAndReturn (1).Result != 1111)
137                         return 13;
138
139                 if (!fin)
140                         return 14;
141
142                 if (TestFinallyWithGotoAndReturn (3).Result != 9)
143                         return 15;
144
145                 if (!fin)
146                         return 16;
147
148                 Console.WriteLine ("ok");
149                 return 0;
150         }
151 }