Fix makefile
[mono.git] / mcs / tests / test-148.cs
1 using System;
2 using System.Collections;
3 using System.Runtime.CompilerServices;
4
5 public interface X
6 {
7         [IndexerName ("Foo")]
8         int this [int a] {
9                 get;
10         }
11 }
12
13 public class Y : X
14 {
15         int X.this [int a] {
16                 get {
17                         return 1;
18                 }
19         }
20
21         [IndexerName ("Bar")]
22         public int this [int a] {
23                 get {
24                         return 2;
25                 }
26         }
27
28         [IndexerName ("Bar")]
29         public long this [double a] {
30                 get {
31                         return 3;
32                 }
33         }
34 }
35
36 public class Z : Y
37 {
38         [IndexerName ("Whatever")]
39         new public long this [double a] {
40                 get {
41                         return 4;
42                 }
43         }
44
45         [IndexerName ("Whatever")]
46         public float this [long a, int b] {
47                 get {
48                         return a / b;
49                 }
50         }
51
52         public int InstanceTest ()
53         {
54                 double index = 5;
55
56                 Console.WriteLine ("INSTANCE TEST");
57
58                 if (this [index] != 4)
59                         return 6;
60                 if (base [index] != 3)
61                         return 7;
62
63                 return 0;
64         }
65
66         public static int Test ()
67         {
68                 Z z = new Z ();
69                 X x = (X) z;
70                 Y y = (Y) z;
71
72                 Console.WriteLine (z [1]);
73                 Console.WriteLine (y [2]);
74                 Console.WriteLine (x [3]);
75
76                 if (z [1] != 4)
77                         return 1;
78                 if (y [1] != 2)
79                         return 2;
80                 if (x [1] != 1)
81                         return 3;
82
83                 double index = 5;
84
85                 Console.WriteLine (z [index]);
86                 Console.WriteLine (y [index]);
87
88                 if (z [index] != 4)
89                         return 4;
90                 if (y [index] != 3)
91                         return 5;
92
93                 int retval = z.InstanceTest ();
94                 if (retval != 0)
95                         return retval;
96
97                 B b = new B ();
98                 if (b [4] != 16)
99                         return 8;
100                 if (b [3,5] != 15)
101                         return 9;
102
103                 D d = new D ();
104                 if (d [4] != 16)
105                         return 10;
106                 if (d [3,5] != 15)
107                         return 11;
108
109                 //
110                 // Now test for bug 35492
111                 //
112                 ChildList xd = new ChildList ();
113
114                 xd.Add (0);
115                 if (0 != (int)xd [0])
116                         return 12;
117                 
118                 xd.Test ();
119                 if (1 != (int) xd [0])
120                         return 13;
121                 
122                 return 0;
123         }
124
125         public static int Main ()
126         {
127                 int result = Test ();
128
129                 Console.WriteLine ("RESULT: " + result);
130
131                 E e = new E ();
132                 e.g = "monkey";
133
134                 return result;
135         }
136
137 }
138
139 public class A
140 {
141         [IndexerName("Monkey")]
142         public int this [int value] {
143                 get {
144                         return value * 4;
145                 }
146         }
147 }
148
149 public class B : A
150 {
151         public long this [long a, int value] {
152                 get {
153                         return a * value;
154                 }
155         }
156 }
157
158 public class C
159 {
160         public int this [int value] {
161                 get {
162                         return value * 4;
163                 }
164         }
165 }
166
167 public class D : C
168 {
169         public long this [long a, int value] {
170                 get {
171                         return a * value;
172                 }
173         }
174 }
175
176 public class E {
177         public virtual string g {
178                 get { return "g"; }
179                 set { }
180         }
181 }
182
183 public class F : E {
184         public override string g {
185                 get { return "h"; }
186         }
187 }
188
189 public class DisposableNotifyList : ArrayList
190         {
191         }
192         
193 public class ChildList : DisposableNotifyList
194     {
195                 public void Test()
196                 {
197                         base[0] = 1;
198
199                 }
200     }