2010-04-13 Sebastien Pouliot <sebastien@ximian.com>
[mono-project.git] / mcs / tests / test-172.cs
blob091b2d44cdcd8b42730cdafa71977b42d4ff50df
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;
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;
20 static int fcalls = 0;
21 static int tcalls = 0;
23 static bool ff ()
25 fcalls++;
26 return false;
29 static bool tt ()
31 tcalls++;
32 return true;
35 static int test_if ()
38 // Ands in the if context
40 if (f && f)
41 return 1;
42 if (t && f)
43 return 2;
44 if (f && t)
45 return 3;
47 if (one < two && f)
48 return 4;
49 if (one > two && t)
50 return 5;
51 if (one < two && t)
52 Console.WriteLine ("");
54 if (ff () && ff ())
55 return 6;
56 if (fcalls != 1)
57 return 10;
59 if (tt () && tt ()){
60 if (tcalls != 2)
61 return 11;
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;
78 if (one < two && four > three){
79 if (one == one && two != three){
81 } else
82 return 20;
83 } else
84 return 21;
86 if (one == two || two != two)
87 return 22;
89 object o = null;
91 if (o == null || false){
92 o = 1;
94 if (o != null || false)
95 o = null;
96 else
97 return 23;
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;
112 return 25;
114 return 26;
116 return 27;
120 // This tests emitbranchable with an `onTrue' set to tru
122 static int test_while ()
124 int count = 0;
126 while (t && t){
127 count++;
128 break;
131 if (count != 1)
132 return 1;
134 while (f || t){
135 count++; break;
137 if (count != 2)
138 return 2;
139 while (f || f){
140 count++; break;
142 if (count != 2)
143 return 3;
145 while (one < two && two > one){
146 count++;
147 break;
149 if (count != 3)
150 return 4;
152 while (one < one || two > one){
153 count++;
154 break;
156 if (count != 4)
157 return 5;
159 while (one < one || two > two){
160 count++;
161 break;
163 if (count != 4)
164 return 6;
166 while (one < two && t){
167 count++;
168 break;
170 if (count != 5)
171 return 7;
173 while (one < one || t){
174 count++;
175 break;
177 if (count != 6)
178 return 8;
180 while (one < one || f){
181 count++;
182 break;
185 if (count != 6)
186 return 9;
188 return 0;
191 static int test_inline ()
193 bool lt = t || f;
195 if (!lt)
196 return 1;
198 return 0;
201 static int Main ()
203 int v;
204 object o = null;
206 if (o == null || false)
207 o = 1;
208 else
209 o = 2;
211 Console.WriteLine ("V: "+ o);
213 v = test_if ();
214 if (v != 0)
215 return v;
216 v = test_inline ();
217 if (v != 0)
218 return 30 + v;
220 v = test_while ();
221 if (v != 0)
222 return 90 + v;
224 Console.WriteLine ("test ok");
225 return 0;