New tests, updates
[mono.git] / mcs / tests / test-anon-82.cs
1 //\r
2 // Tests different anonymous method caching scenarios\r
3 //\r
4 \r
5 public delegate void StringSender (string str);\r
6 public delegate void VoidDelegate ();\r
7 \r
8 public class MainClass\r
9 {\r
10         public static void Main()\r
11         {\r
12                 MainClass mc = new MainClass ();\r
13                 VoidDelegate del = new VoidDelegate (\r
14                         delegate {\r
15                                 StringSender ss = delegate (string s) {\r
16                                         SimpleCallback(mc, s);\r
17                                 };\r
18                                 ss("Yo!");\r
19                         }\r
20                 );\r
21                 del();\r
22                 \r
23                 mc.Test2 (10);\r
24                 mc.Test3 (20);\r
25                 mc.Test4 ();\r
26                 mc.Test5 (50);\r
27         }\r
28         \r
29         void Test2 (int a)\r
30         {\r
31                 StringSender d = delegate (string s) {\r
32                         VoidDelegate d2 = delegate {\r
33                                 s = "10";\r
34                         };\r
35                 };\r
36         }\r
37         \r
38         void Test3 (int a)\r
39         {\r
40                 int u = 8;\r
41                 VoidDelegate d = delegate () { u = 9; };\r
42                 VoidDelegate d2 = delegate () { };\r
43         }\r
44 \r
45         void Test4 ()\r
46         {\r
47                 VoidDelegate d = delegate () {\r
48                         VoidDelegate d2 = delegate () {\r
49                                 int a = 9;\r
50                                 VoidDelegate d3 = delegate () {\r
51                                         VoidDelegate d4 = delegate () {\r
52                                                 a = 3;\r
53                                         };\r
54                                 };\r
55                         };\r
56                 };\r
57         }\r
58         \r
59         int a;\r
60         int b;\r
61         \r
62         delegate int D (int a);\r
63         \r
64         void Test5 (int arg)\r
65         {\r
66                 D d2 = delegate (int i) {\r
67                         D d1 = delegate (int a) {\r
68                                 return a;\r
69                         };\r
70 \r
71                         return d1 (9) + arg;\r
72                 };\r
73         }\r
74         \r
75         static void SimpleCallback (MainClass mc, string str)\r
76         {\r
77                 System.Console.WriteLine(str);\r
78         }\r
79 }\r