2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[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         class MyArray : ArrayList
126         {
127                 public override object this[int index]
128                 {
129                         get { return base[index]; }
130                         set { base[index] = value;}
131                 }
132         }
133
134         public static int Main ()
135         {
136                 int result = Test ();
137
138                 Console.WriteLine ("RESULT: " + result);
139
140                 E e = new E ();
141                 e.g = "monkey";
142
143                 //
144                 // Now test base [...]
145                 //
146                 MyArray arr = new MyArray ( );
147                 arr.Add ( "String value" );
148                 if (arr[0].ToString () != "String value")
149                         return 100;
150
151                 return result;
152         }
153
154 }
155
156 public class A
157 {
158         [IndexerName("Monkey")]
159         public int this [int value] {
160                 get {
161                         return value * 4;
162                 }
163         }
164 }
165
166 public class B : A
167 {
168         public long this [long a, int value] {
169                 get {
170                         return a * value;
171                 }
172         }
173 }
174
175 public class C
176 {
177         public int this [int value] {
178                 get {
179                         return value * 4;
180                 }
181         }
182 }
183
184 public class D : C
185 {
186         public long this [long a, int value] {
187                 get {
188                         return a * value;
189                 }
190         }
191 }
192
193 public class E {
194         public virtual string g {
195                 get { return "g"; }
196                 set { }
197         }
198 }
199
200 public class F : E {
201         public override string g {
202                 get { return "h"; }
203         }
204 }
205
206 public class DisposableNotifyList : ArrayList
207         {
208         }
209         
210 public class ChildList : DisposableNotifyList
211     {
212                 public void Test()
213                 {
214                         base[0] = 1;
215
216                 }
217     }