PageRenderTime 64ms CodeModel.GetById 14ms app.highlight 44ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Runtime/Tests/ETScenariosCSLinq/CSLinq/ExpressionCompiler/lift_BackSl_lift_BackSl_test2.cs

#
C# | 529 lines | 442 code | 67 blank | 20 comment | 44 complexity | fee6f2edaf42344a4835daad0f99abc7 MD5 | raw file
  1#if !CLR2
  2using System.Linq.Expressions;
  3#else
  4using Microsoft.Scripting.Ast;
  5using Microsoft.Scripting.Utils;
  6#endif
  7
  8using System.Reflection;
  9using System;
 10namespace ExpressionCompiler { 
 11	
 12			
 13			//-------- Scenario 267
 14			namespace Scenario267{
 15				
 16				public class Test
 17				{
 18			    [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "And__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
 19			    public static Expression And__() {
 20			       if(Main() != 0 ) {
 21			           throw new Exception();
 22			       } else { 
 23			           return Expression.Constant(0);
 24			       }
 25			    }
 26				public     static int Main()
 27				    {
 28				        Ext.StartCapture();
 29				        bool success = false;
 30				        try
 31				        {
 32				            success = check_boolq_And();
 33				        }
 34				        finally
 35				        {
 36				            Ext.StopCapture();
 37				        }
 38				        return success ? 0 : 1;
 39				    }
 40				
 41				    static bool check_boolq_And()
 42				    {
 43				        bool?[] svals = new bool?[] { null, true, false };
 44				        for (int i = 0; i < svals.Length; i++)
 45				        {
 46				            for (int j = 0; j < svals.Length; j++)
 47				            {
 48				                if (!check_boolq_And(svals[i], svals[j]))
 49				                {
 50				                    Console.WriteLine("boolq_And failed");
 51				                    return false;
 52				                }
 53				            }
 54				        }
 55				        return true;
 56				    }
 57				
 58				    static bool And(bool val0, bool val1)
 59				    {
 60				        return val0 & val1;
 61				    }
 62				
 63				    static bool check_boolq_And(bool? val0, bool? val1)
 64				    {
 65				        ParameterExpression p0 = Expression.Parameter(typeof(bool), "p0");
 66				        ParameterExpression p1 = Expression.Parameter(typeof(bool), "p1");
 67				        Expression<Func<bool?>> e = Expression.Lambda<Func<bool?>>(
 68				                            Expression.And(
 69				                                Expression.Constant(val0, typeof(bool?)),
 70				                                Expression.Constant(val1, typeof(bool?)),
 71				                                typeof(Test).GetMethod("And")
 72				                                ),
 73				                        new ParameterExpression[] { });
 74				
 75				        Func<bool?> f = e.Compile();
 76				
 77				        bool? fResult = default(bool);
 78				        Exception fEx = null;
 79				        try
 80				        {
 81				            fResult = f();
 82				        }
 83				        catch (Exception ex)
 84				        {
 85				            fEx = ex;
 86				        }
 87				
 88				        bool? csResult = (val0) & (val1);
 89				        bool result = object.Equals(fResult, csResult);
 90				        return result;
 91				    }
 92				}
 93			
 94			
 95			public  static class Ext {
 96			    public static void StartCapture() {
 97			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
 98			//        m.Invoke(null, new object[] { "test.dll" });
 99			    }
100			
101			    public static void StopCapture() {
102			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
103			//        m.Invoke(null, new object[0]);
104			    }
105			
106			    public static bool IsIntegralOrEnum(Type type) {
107			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
108			            case TypeCode.Byte:
109			            case TypeCode.SByte:
110			            case TypeCode.Int16:
111			            case TypeCode.Int32:
112			            case TypeCode.Int64:
113			            case TypeCode.UInt16:
114			            case TypeCode.UInt32:
115			            case TypeCode.UInt64:
116			                return true;
117			            default:
118			                return false;
119			        }
120			    }
121			
122			    public static bool IsFloating(Type type) {
123			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
124			            case TypeCode.Single:
125			            case TypeCode.Double:
126			                return true;
127			            default:
128			                return false;
129			        }
130			    }
131			
132			    public static Type GetNonNullableType(Type type) {
133			        return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
134			                type.GetGenericArguments()[0] :
135			                type;
136			    }
137			}
138			
139		
140	}
141			
142			//-------- Scenario 268
143			namespace Scenario268{
144				
145				public class Test
146				{
147			    [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Or__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
148			    public static Expression Or__() {
149			       if(Main() != 0 ) {
150			           throw new Exception();
151			       } else { 
152			           return Expression.Constant(0);
153			       }
154			    }
155				public     static int Main()
156				    {
157				        Ext.StartCapture();
158				        bool success = false;
159				        try
160				        {
161				            success = check_boolq_Or();
162				        }
163				        finally
164				        {
165				            Ext.StopCapture();
166				        }
167				        return success ? 0 : 1;
168				    }
169				
170				    static bool check_boolq_Or()
171				    {
172				        bool?[] svals = new bool?[] { null, true, false };
173				        for (int i = 0; i < svals.Length; i++)
174				        {
175				            for (int j = 0; j < svals.Length; j++)
176				            {
177				                if (!check_boolq_Or(svals[i], svals[j]))
178				                {
179				                    Console.WriteLine("boolq_Or failed");
180				                    return false;
181				                }
182				            }
183				        }
184				        return true;
185				    }
186				
187				    static bool Or(bool val0, bool val1)
188				    {
189				        return val0 | val1;
190				    }
191				
192				    static bool check_boolq_Or(bool? val0, bool? val1)
193				    {
194				        ParameterExpression p0 = Expression.Parameter(typeof(bool), "p0");
195				        ParameterExpression p1 = Expression.Parameter(typeof(bool), "p1");
196				        Expression<Func<bool?>> e = Expression.Lambda<Func<bool?>>(
197				                            Expression.Or(
198				                                Expression.Constant(val0, typeof(bool?)),
199				                                Expression.Constant(val1, typeof(bool?)),
200				                                typeof(Test).GetMethod("Or")
201				                                ),
202				                        new ParameterExpression[] { });
203				
204				        Func<bool?> f = e.Compile();
205				
206				        bool? fResult = default(bool);
207				        Exception fEx = null;
208				        try
209				        {
210				            fResult = f();
211				        }
212				        catch (Exception ex)
213				        {
214				            fEx = ex;
215				        }
216				
217				        bool? csResult = (val0) | (val1);
218				        bool result = object.Equals(fResult, csResult);
219				        return result;
220				    }
221				}
222			
223			
224			public  static class Ext {
225			    public static void StartCapture() {
226			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
227			//        m.Invoke(null, new object[] { "test.dll" });
228			    }
229			
230			    public static void StopCapture() {
231			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
232			//        m.Invoke(null, new object[0]);
233			    }
234			
235			    public static bool IsIntegralOrEnum(Type type) {
236			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
237			            case TypeCode.Byte:
238			            case TypeCode.SByte:
239			            case TypeCode.Int16:
240			            case TypeCode.Int32:
241			            case TypeCode.Int64:
242			            case TypeCode.UInt16:
243			            case TypeCode.UInt32:
244			            case TypeCode.UInt64:
245			                return true;
246			            default:
247			                return false;
248			        }
249			    }
250			
251			    public static bool IsFloating(Type type) {
252			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
253			            case TypeCode.Single:
254			            case TypeCode.Double:
255			                return true;
256			            default:
257			                return false;
258			        }
259			    }
260			
261			    public static Type GetNonNullableType(Type type) {
262			        return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
263			                type.GetGenericArguments()[0] :
264			                type;
265			    }
266			}
267			
268		
269	}
270			
271			//-------- Scenario 269
272			namespace Scenario269{
273				
274				public class Test
275				{
276			    [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "AndAlso__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
277			    public static Expression AndAlso__() {
278			       if(Main() != 0 ) {
279			           throw new Exception();
280			       } else { 
281			           return Expression.Constant(0);
282			       }
283			    }
284				public     static int Main()
285				    {
286				        Ext.StartCapture();
287				        bool success = false;
288				        try
289				        {
290				            success = check_boolq_AndAlso();
291				        }
292				        finally
293				        {
294				            Ext.StopCapture();
295				        }
296				        return success ? 0 : 1;
297				    }
298				
299				    static bool check_boolq_AndAlso()
300				    {
301				        bool?[] svals = new bool?[] { null, true, false };
302				        for (int i = 0; i < svals.Length; i++)
303				        {
304				            for (int j = 0; j < svals.Length; j++)
305				            {
306				                if (!check_boolq_AndAlso(svals[i], svals[j]))
307				                {
308				                    Console.WriteLine("boolq_AndAlso failed");
309				                    return false;
310				                }
311				            }
312				        }
313				        return true;
314				    }
315				
316				    static bool AndAlso(bool val0, bool val1)
317				    {
318				        return val0 && val1;
319				    }
320				
321				    static bool check_boolq_AndAlso(bool? val0, bool? val1)
322				    {
323				        ParameterExpression p0 = Expression.Parameter(typeof(bool), "p0");
324				        ParameterExpression p1 = Expression.Parameter(typeof(bool), "p1");
325				        Expression<Func<bool?>> e = Expression.Lambda<Func<bool?>>(
326				                            Expression.AndAlso(
327				                                Expression.Constant(val0, typeof(bool?)),
328				                                Expression.Constant(val1, typeof(bool?)),
329				                                typeof(Test).GetMethod("AndAlso")
330				                                ),
331				                        new ParameterExpression[] { });
332				
333				        Func<bool?> f = e.Compile();
334				
335				        bool? fResult = default(bool);
336				        Exception fEx = null;
337				        try
338				        {
339				            fResult = f();
340				        }
341				        catch (Exception ex)
342				        {
343				            fEx = ex;
344				        }
345				
346				        bool? csResult = (val0) == false ? false : (val0) & (val1);
347				        bool result = object.Equals(fResult, csResult);
348				        return result;
349				    }
350				}
351			
352			
353			public  static class Ext {
354			    public static void StartCapture() {
355			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
356			//        m.Invoke(null, new object[] { "test.dll" });
357			    }
358			
359			    public static void StopCapture() {
360			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
361			//        m.Invoke(null, new object[0]);
362			    }
363			
364			    public static bool IsIntegralOrEnum(Type type) {
365			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
366			            case TypeCode.Byte:
367			            case TypeCode.SByte:
368			            case TypeCode.Int16:
369			            case TypeCode.Int32:
370			            case TypeCode.Int64:
371			            case TypeCode.UInt16:
372			            case TypeCode.UInt32:
373			            case TypeCode.UInt64:
374			                return true;
375			            default:
376			                return false;
377			        }
378			    }
379			
380			    public static bool IsFloating(Type type) {
381			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
382			            case TypeCode.Single:
383			            case TypeCode.Double:
384			                return true;
385			            default:
386			                return false;
387			        }
388			    }
389			
390			    public static Type GetNonNullableType(Type type) {
391			        return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
392			                type.GetGenericArguments()[0] :
393			                type;
394			    }
395			}
396			
397		
398	}
399			
400			//-------- Scenario 270
401			namespace Scenario270{
402				
403				public class Test
404				{
405			    [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "OrElse__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
406			    public static Expression OrElse__() {
407			       if(Main() != 0 ) {
408			           throw new Exception();
409			       } else { 
410			           return Expression.Constant(0);
411			       }
412			    }
413				public     static int Main()
414				    {
415				        Ext.StartCapture();
416				        bool success = false;
417				        try
418				        {
419				            success = check_boolq_OrElse();
420				        }
421				        finally
422				        {
423				            Ext.StopCapture();
424				        }
425				        return success ? 0 : 1;
426				    }
427				
428				    static bool check_boolq_OrElse()
429				    {
430				        bool?[] svals = new bool?[] { null, true, false };
431				        for (int i = 0; i < svals.Length; i++)
432				        {
433				            for (int j = 0; j < svals.Length; j++)
434				            {
435				                if (!check_boolq_OrElse(svals[i], svals[j]))
436				                {
437				                    Console.WriteLine("boolq_OrElse failed");
438				                    return false;
439				                }
440				            }
441				        }
442				        return true;
443				    }
444				
445				    static bool OrElse(bool val0, bool val1)
446				    {
447				        return val0 || val1;
448				    }
449				
450				    static bool check_boolq_OrElse(bool? val0, bool? val1)
451				    {
452				        ParameterExpression p0 = Expression.Parameter(typeof(bool), "p0");
453				        ParameterExpression p1 = Expression.Parameter(typeof(bool), "p1");
454				        Expression<Func<bool?>> e = Expression.Lambda<Func<bool?>>(
455				                            Expression.OrElse(
456				                                Expression.Constant(val0, typeof(bool?)),
457				                                Expression.Constant(val1, typeof(bool?)),
458				                                typeof(Test).GetMethod("OrElse")
459				                                ),
460				                        new ParameterExpression[] { });
461				
462				        Func<bool?> f = e.Compile();
463				
464				        bool? fResult = default(bool);
465				        Exception fEx = null;
466				        try
467				        {
468				            fResult = f();
469				        }
470				        catch (Exception ex)
471				        {
472				            fEx = ex;
473				        }
474				
475				        bool? csResult = (val0) == true ? true : (val0) | (val1);
476				        bool result = object.Equals(fResult, csResult);
477				        return result;
478				    }
479				}
480			
481			
482			public  static class Ext {
483			    public static void StartCapture() {
484			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
485			//        m.Invoke(null, new object[] { "test.dll" });
486			    }
487			
488			    public static void StopCapture() {
489			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
490			//        m.Invoke(null, new object[0]);
491			    }
492			
493			    public static bool IsIntegralOrEnum(Type type) {
494			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
495			            case TypeCode.Byte:
496			            case TypeCode.SByte:
497			            case TypeCode.Int16:
498			            case TypeCode.Int32:
499			            case TypeCode.Int64:
500			            case TypeCode.UInt16:
501			            case TypeCode.UInt32:
502			            case TypeCode.UInt64:
503			                return true;
504			            default:
505			                return false;
506			        }
507			    }
508			
509			    public static bool IsFloating(Type type) {
510			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
511			            case TypeCode.Single:
512			            case TypeCode.Double:
513			                return true;
514			            default:
515			                return false;
516			        }
517			    }
518			
519			    public static Type GetNonNullableType(Type type) {
520			        return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
521			                type.GetGenericArguments()[0] :
522			                type;
523			    }
524			}
525			
526		
527	}
528	
529}