4e4d2c83b047cdad1ba3af541e4ee4e98f11305c
[mono.git] / mcs / tests / test-42.cs
1 //
2 // This test exercises the various ways in which mutator operators can be
3 // used in C# and the various different scenarios that the compiler would
4 // have to deal with
5 //
6 // variables, linear arrays, multi-dimensional arrays, jagged arrays,
7 // properties, indexers and overloaded ++ and --
8 //
9
10 class X {
11
12         public int v, p;
13         public int idx;
14         
15         public int this [int n] {
16                 get {
17                         idx = n;
18                         return v;
19                 }
20                 set {
21                         idx = n;
22                         v = value;
23                 }
24         }
25
26         public int P {
27                 get {
28                         return p;
29                 }
30
31                 set {
32                         p = value;
33                 }
34         }
35         
36 }
37
38 class Z {
39         int v;
40
41         public Z P {
42                 get {
43                         return null;
44                 }
45
46                 set {
47                 }
48         }
49         
50         static public Z operator ++ (Z v)
51         {
52                 v.v++;
53                 return v;
54         }
55 }
56
57 class Y {
58
59         static int p_pre_increment (X x)
60         {
61                 return ++x.P;
62         }
63
64         static int p_post_increment (X x)
65         {
66                 return x.P++;
67         }
68
69         static int i_pre_increment (X x)
70         {
71                 return ++x [100];
72         }
73
74         static int  i_post_increment (X x)
75         {
76                 return x [14]++;
77         }
78
79         static Z overload_increment (Z z)
80         {
81                   return z++;
82         }
83         
84         static Z overload_pre_increment (Z z)
85         {
86                   return ++z;
87         }
88         
89         static Z ugly (Z z)
90         {
91                   return z.P++;
92         }
93
94         //
95         // Tests the ++ and -- operators on integers
96         //
97         static int simple (int i)
98         {
99                 if (++i != 11)
100                         return 1;
101                 if (--i != 10)
102                         return 2;
103                 if (i++ != 10)
104                         return 3;
105                 if (i-- != 11)
106                         return 4;
107                 return 0;
108         }
109         static int Main ()
110         {
111                 X x = new X ();
112                 int c;
113                 
114                 if ((c = simple (10)) != 0)
115                         return c;
116                 
117                 if (i_pre_increment (x) != 1)
118                         return 5;
119                 
120                 if (x.idx != 100)
121                         return 6;
122                 
123                 if (i_post_increment (x) != 1)
124                         return 7;
125
126                 if (x.idx != 14)
127                         return 8;
128                 
129                 if (p_pre_increment (x) != 1)
130                         return 9;
131
132                 if (x.p != 1)
133                         return 10;
134                 
135                 if (p_post_increment (x) != 1)
136                         return 10;
137
138                 if (x.p != 2)
139                         return 11;
140
141                 Z z = new Z();
142
143                 overload_increment (z);
144
145                 return 0;
146         }
147         
148 }