Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-172.cs
1 //
2 // This test excercises a few new optimizations that were entered in the context
3 // of Binary operators and EmitBranchable.
4 //
5 // There are a number of cases:
6 //
7 //   EmitBranchable can be called with an `onTrue' (false for if, true for loops).
8 //
9 //   The == and != operators handle the Null compares specially
10 using System;
11
12 class X {
13         static int one = 1;
14         static int two = 2;
15         static int three = 3;
16         static int four = 4;
17         static bool t = true;
18         static bool f = false;
19
20         static int fcalls = 0;
21         static int tcalls = 0;
22         
23         static bool ff ()
24         {
25                 fcalls++;
26                 return false;
27         }
28
29         static bool tt ()
30         {
31                 tcalls++;
32                 return true;
33         }
34         
35         static int test_if ()
36         {
37                 //
38                 // Ands in the if context
39                 //
40                 if (f && f)
41                         return 1;
42                 if (t && f)
43                         return 2;
44                 if (f && t)
45                         return 3;
46                 
47                 if (one < two && f)
48                         return 4;
49                 if (one > two && t)
50                         return 5;
51                 if (one < two && t)
52                         Console.WriteLine ("");
53
54                 if (ff () && ff ())
55                         return 6;
56                 if (fcalls != 1)
57                         return 10;
58                 
59                 if (tt () && tt ()){
60                         if (tcalls != 2)
61                                 return 11;
62                         
63                         if (tt () && ff ())
64                                 return 8;
65                         if (tcalls != 3)
66                                 return 12;
67                         if (fcalls != 2)
68                                 return 13;
69                         if (ff () && tt ())
70                                 return 9;
71                         if (fcalls != 3)
72                                 return 14;
73                         if (tcalls != 3)
74                                 return 15;
75                 } else
76                         return 7;
77
78                 if (one < two && four > three){
79                         if (one == one && two != three){
80                                 
81                         } else 
82                                 return 20;
83                 } else
84                         return 21;
85
86                 if (one == two || two != two)
87                         return 22;
88
89                 object o = null;
90
91                 if (o == null || false){
92                         o = 1;
93
94                         if (o != null || false)
95                                 o = null;
96                         else
97                                 return 23;
98
99                         if (true || o == null){
100                                 if (o != null || o == null){
101                                         if (o == null && o != null)
102                                                 return 25;
103                                         if (o == null && one == two)
104                                                 return 26;
105                                         if (one == one && o != null)
106                                                 return 27;
107                                         o = 1;
108                                         if (two == two && o == null)
109                                                 return 28;
110                                         return 0;
111                                 }
112                                 return 25;
113                         }
114                         return 26;
115                 }
116                 return 27;
117         }
118
119         //
120         // This tests emitbranchable with an `onTrue' set to tru
121         //
122         static int test_while ()
123         {
124                 int count = 0;
125                 
126                 while (t && t){
127                         count++;
128                         break;
129                 }
130
131                 if (count != 1)
132                         return 1;
133
134                 while (f || t){
135                         count++; break;
136                 }
137                 if (count != 2)
138                         return 2;
139                 while (f || f){
140                         count++; break;
141                 }
142                 if (count != 2)
143                         return 3;
144
145                 while (one < two && two > one){
146                         count++;
147                         break;
148                 }
149                 if (count != 3)
150                         return 4;
151
152                 while (one < one || two > one){
153                         count++;
154                         break;
155                 }
156                 if (count != 4)
157                         return 5;
158
159                 while (one < one || two > two){
160                         count++;
161                         break;
162                 }
163                 if (count != 4)
164                         return 6;
165                 
166                 while (one < two && t){
167                         count++;
168                         break;
169                 }
170                 if (count != 5)
171                         return 7;
172
173                 while (one < one || t){
174                         count++;
175                         break;
176                 }
177                 if (count != 6)
178                         return 8;
179
180                 while (one < one || f){
181                         count++;
182                         break;
183                 }
184
185                 if (count != 6)
186                         return 9;
187                 
188                 return 0;
189         }
190         
191         static int test_inline ()
192         {
193                 bool lt = t || f;
194
195                 if (!lt)
196                         return 1;
197
198                 return 0;
199         }
200         
201         public static int Main ()
202         {
203                 int v;
204                 object o = null;
205
206                 if (o == null || false)
207                         o = 1;
208                 else
209                         o = 2;
210
211                 Console.WriteLine ("V: "+ o);
212                 
213                 v = test_if ();
214                 if (v != 0)
215                         return v;
216                 v = test_inline ();
217                 if (v != 0)
218                         return 30 + v;
219                 
220                 v = test_while ();
221                 if (v != 0)
222                         return 90 + v;
223                 
224                 Console.WriteLine ("test ok");
225                 return 0;
226         }
227 }
228