Merge pull request #5675 from mono/glib-debug-symbols
[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
110         static int arrays ()
111         {
112                 int [] a = new int [10];
113                 int i, j;
114                 
115                 for (i = 0; i < 10; i++)
116                         a [i]++;
117
118                 for (i = 0; i < 10; i++)
119                         if (a [i] != 1)
120                                 return 100;
121
122                 int [,] b = new int [10,10];
123                 for (i = 0; i < 10; i++){
124                         for (j = 0; j < 10; j++){
125                                 b [i,j] = i * 10 + j;
126                                 if (i < 5)
127                                         b [i,j]++;
128                                 else
129                                         ++b [i,j];
130                         }
131                 }
132
133                 for (i = 0; i < 10; i++){
134                         for (j = 0; j < 10; j++){
135                                 if (b [i,j] != i * 10 + (j + 1))
136                                         return 101;
137                         }
138                 }
139                 
140                 return 0;
141         }
142         
143         public static int Main ()
144         {
145                 X x = new X ();
146                 int c;
147                 
148                 if ((c = simple (10)) != 0)
149                         return c;
150                 
151                 if (i_pre_increment (x) != 1)
152                         return 5;
153                 
154                 if (x.idx != 100)
155                         return 6;
156                 
157                 if (i_post_increment (x) != 1)
158                         return 7;
159
160                 if (x.idx != 14)
161                         return 8;
162                 
163                 if (p_pre_increment (x) != 1)
164                         return 9;
165
166                 if (x.p != 1)
167                         return 10;
168                 
169                 if (p_post_increment (x) != 1)
170                         return 10;
171
172                 if (x.p != 2)
173                         return 11;
174
175                 Z z = new Z();
176
177                 overload_increment (z);
178
179                 arrays ();
180                 
181                 return 0;
182         }
183         
184 }