2010-04-07 Jb Evain <jbevain@novell.com>
[mcs.git] / tests / test-148.cs
blob61aa394433ca6f3f52cb63a1e66a57ad91456ae0
1 using System;
2 using System.Collections;
3 using System.Runtime.CompilerServices;
5 public interface X
7 [IndexerName ("Foo")]
8 int this [int a] {
9 get;
13 public class Y : X
15 int X.this [int a] {
16 get {
17 return 1;
21 [IndexerName ("Bar")]
22 public int this [int a] {
23 get {
24 return 2;
28 [IndexerName ("Bar")]
29 public long this [double a] {
30 get {
31 return 3;
36 public class Z : Y
38 [IndexerName ("Whatever")]
39 new public long this [double a] {
40 get {
41 return 4;
45 [IndexerName ("Whatever")]
46 public float this [long a, int b] {
47 get {
48 return a / b;
52 public int InstanceTest ()
54 double index = 5;
56 Console.WriteLine ("INSTANCE TEST");
58 if (this [index] != 4)
59 return 6;
60 if (base [index] != 3)
61 return 7;
63 return 0;
66 public static int Test ()
68 Z z = new Z ();
69 X x = (X) z;
70 Y y = (Y) z;
72 Console.WriteLine (z [1]);
73 Console.WriteLine (y [2]);
74 Console.WriteLine (x [3]);
76 if (z [1] != 4)
77 return 1;
78 if (y [1] != 2)
79 return 2;
80 if (x [1] != 1)
81 return 3;
83 double index = 5;
85 Console.WriteLine (z [index]);
86 Console.WriteLine (y [index]);
88 if (z [index] != 4)
89 return 4;
90 if (y [index] != 3)
91 return 5;
93 int retval = z.InstanceTest ();
94 if (retval != 0)
95 return retval;
97 B b = new B ();
98 if (b [4] != 16)
99 return 8;
100 if (b [3,5] != 15)
101 return 9;
103 D d = new D ();
104 if (d [4] != 16)
105 return 10;
106 if (d [3,5] != 15)
107 return 11;
110 // Now test for bug 35492
112 ChildList xd = new ChildList ();
114 xd.Add (0);
115 if (0 != (int)xd [0])
116 return 12;
118 xd.Test ();
119 if (1 != (int) xd [0])
120 return 13;
122 return 0;
125 class MyArray : ArrayList
127 public override object this[int index]
129 get { return base[index]; }
130 set { base[index] = value;}
134 public static int Main ()
136 int result = Test ();
138 Console.WriteLine ("RESULT: " + result);
140 E e = new E ();
141 e.g = "monkey";
144 // Now test base [...]
146 MyArray arr = new MyArray ( );
147 arr.Add ( "String value" );
148 if (arr[0].ToString () != "String value")
149 return 100;
151 return result;
156 public class A
158 [IndexerName("Monkey")]
159 public int this [int value] {
160 get {
161 return value * 4;
166 public class B : A
168 public long this [long a, int value] {
169 get {
170 return a * value;
175 public class C
177 public int this [int value] {
178 get {
179 return value * 4;
184 public class D : C
186 public long this [long a, int value] {
187 get {
188 return a * value;
193 public class E {
194 public virtual string g {
195 get { return "g"; }
196 set { }
200 public class F : E {
201 public override string g {
202 get { return "h"; }
206 public class DisposableNotifyList : ArrayList
210 public class ChildList : DisposableNotifyList
212 public void Test()
214 base[0] = 1;