2002-11-14 Martin Baulig <martin@gnome.org>
[mono.git] / mcs / tests / test-148.cs
1 using System;
2 using System.Runtime.CompilerServices;
3
4 public interface X
5 {
6         [IndexerName ("Foo")]
7         int this [int a] {
8                 get;
9         }
10 }
11
12 public class Y : X
13 {
14         int X.this [int a] {
15                 get {
16                         return 1;
17                 }
18         }
19
20         [IndexerName ("Bar")]
21         public int this [int a] {
22                 get {
23                         return 2;
24                 }
25         }
26
27         [IndexerName ("Bar")]
28         public long this [double a] {
29                 get {
30                         return 3;
31                 }
32         }
33 }
34
35 public class Z : Y
36 {
37         [IndexerName ("Whatever")]
38         new public long this [double a] {
39                 get {
40                         return 4;
41                 }
42         }
43
44         [IndexerName ("Whatever")]
45         public float this [long a, int b] {
46                 get {
47                         return a / b;
48                 }
49         }
50
51         public int InstanceTest ()
52         {
53                 double index = 5;
54
55                 Console.WriteLine ("INSTANCE TEST");
56
57                 if (this [index] != 4)
58                         return 6;
59                 if (base [index] != 3)
60                         return 7;
61
62                 return 0;
63         }
64
65         public static int Test ()
66         {
67                 Z z = new Z ();
68                 X x = (X) z;
69                 Y y = (Y) z;
70
71                 Console.WriteLine (z [1]);
72                 Console.WriteLine (y [2]);
73                 Console.WriteLine (x [3]);
74
75                 if (z [1] != 4)
76                         return 1;
77                 if (y [1] != 2)
78                         return 2;
79                 if (x [1] != 1)
80                         return 3;
81
82                 double index = 5;
83
84                 Console.WriteLine (z [index]);
85                 Console.WriteLine (y [index]);
86
87                 if (z [index] != 4)
88                         return 4;
89                 if (y [index] != 3)
90                         return 5;
91
92                 int retval = z.InstanceTest ();
93                 if (retval != 0)
94                         return retval;
95
96                 B b = new B ();
97                 if (b [4] != 16)
98                         return 8;
99                 if (b [3,5] != 15)
100                         return 9;
101
102                 D d = new D ();
103                 if (d [4] != 16)
104                         return 10;
105                 if (d [3,5] != 15)
106                         return 11;
107
108                 return 0;
109         }
110
111         public static int Main ()
112         {
113                 int result = Test ();
114
115                 Console.WriteLine ("RESULT: " + result);
116
117                 return result;
118         }
119 }
120
121 public class A
122 {
123         [IndexerName("Monkey")]
124         public int this [int value] {
125                 get {
126                         return value * 4;
127                 }
128         }
129 }
130
131 public class B : A
132 {
133         public long this [long a, int value] {
134                 get {
135                         return a * value;
136                 }
137         }
138 }
139
140 public class C
141 {
142         public int this [int value] {
143                 get {
144                         return value * 4;
145                 }
146         }
147 }
148
149 public class D : C
150 {
151         public long this [long a, int value] {
152                 get {
153                         return a * value;
154                 }
155         }
156 }