Merge pull request #2819 from BrzVlad/fix-major-log
[mono.git] / mcs / tests / test-async-85.cs
1 using System;
2 using System.Threading.Tasks;
3
4 class Program
5 {
6         static int count;
7
8         static int Main ()
9         {
10                 Test (false).Wait ();
11                 Console.WriteLine (count);
12                 if (count != 110011)
13                         return 1;
14
15                 count = 0;
16                 Test (true).Wait ();
17                 Console.WriteLine (count);
18                 if (count != 111101)
19                         return 2;
20
21                 count = 0;
22                 Test2 (false).Wait ();
23                 Console.WriteLine (count);
24                 if (count != 11)
25                         return 3;
26
27                 count = 0;
28                 Test2 (true).Wait ();
29                 Console.WriteLine (count);
30                 if (count != 1101)
31                         return 4;
32
33                 return 0;
34         }
35
36         static async Task Test (bool throwTest)
37         {
38                 try {
39                         count += 1;
40                         await Task.Delay (10);
41
42                         if (throwTest)
43                                 throw new ApplicationException ();
44
45                         count += 10;
46                 } catch (ApplicationException) {
47                         count += 100;
48                         await Task.Delay (10);
49                         count += 1000;
50                 } finally {
51                         count += 10000;
52                         await Task.Delay (10);
53                         count += 100000;
54                 }
55         }
56
57         static async Task Test2 (bool throwTest)
58         {
59                 try {
60                         count += 1;
61                         await Task.Delay (10);
62
63                         if (throwTest)
64                                 throw new ApplicationException ();
65
66                         count += 10;
67                 } catch (ApplicationException) {
68                         count += 100;
69                         await Task.Delay (10);
70                         count += 1000;
71                 } finally {
72                 }
73         }       
74 }