Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-149.cs
1 using System;
2
3 public delegate long MyDelegate (int a);
4
5 public interface X
6 {
7         event EventHandler Foo;
8
9         event MyDelegate TestEvent;
10 }
11
12 public class Y : X
13 {
14         static int a = 0;
15
16         event EventHandler X.Foo {
17                 add {
18                 }
19
20                 remove {
21                 }
22         }
23
24         public event EventHandler Foo;
25
26         public event MyDelegate TestEvent;
27
28         public int Test ()
29         {
30                 X x = this;
31
32                 Foo += new EventHandler (callback1);
33                 TestEvent += new MyDelegate (callback2);
34
35                 x.Foo += new EventHandler (callback3);
36
37                 if (a != 0)
38                         return 1;
39
40                 Foo (this, new EventArgs ());
41                 if (a != 1)
42                         return 2;
43
44                 if (TestEvent (2) != 4)
45                         return 3;
46
47                 if (a != 2)
48                         return 4;
49
50                 return 0;
51         }
52
53
54         private static void callback1 (object sender, EventArgs e)
55         {
56                 a = 1;
57         }
58
59         private static long callback2 (int b)
60         {
61                 a = b;
62                 return a * a;
63         }
64
65         private static void callback3 (object sender, EventArgs e)
66         {
67                 a = 3;
68         }
69 }
70
71 public class Z : Y
72 {
73         public delegate int SomeEventHandler();
74         public static event SomeEventHandler BuildStarted;
75
76         static int a ()
77         {
78                 return 1;
79         }
80         public static int Main ()
81         {
82                 Z z = new Z ();
83
84                 int result = z.Test ();
85
86                 if (result != 0)
87                         return result;
88
89                 if (BuildStarted != null) {
90                         BuildStarted();
91                 }
92                 BuildStarted = new SomeEventHandler (a);
93                 if (BuildStarted () != 1)
94                         return 50; 
95
96                 return 0;
97         }
98 }
99
100 //
101 // This class is just to test a bug in mcs; where we used to fail
102 // when accessing a static event, from an instance method.
103 //
104 public class Static {
105         public static event EventHandler Test;
106                         
107         public void Fire()
108         {
109                 if ( Test != null )
110                         Test (null, null);
111         }
112 }