PageRenderTime 35ms CodeModel.GetById 25ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 261 lines | 218 code | 33 blank | 10 comment | 42 complexity | 8f52872e28ced4060c63100abc5828fa 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 2177
 14			namespace Scenario2177{
 15				
 16				public class Test
 17				{
 18			    [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Equal__6", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
 19			    public static Expression Equal__6() {
 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_bool_Equal();
 33				        }
 34				        finally
 35				        {
 36				            Ext.StopCapture();
 37				        }
 38				        return success ? 0 : 1;
 39				    }
 40				
 41				    static bool check_bool_Equal() {
 42				        bool[] svals = new bool[] { true };
 43				        for (int i = 0; i < svals.Length; i++) {
 44				            for (int j = 0; j < svals.Length; j++) {
 45				                if (!check_bool_Equal(svals[i], svals[j])) {
 46				                    Console.WriteLine("bool_Equal failed");
 47				                    return false;
 48				                }
 49				            }
 50				        }
 51				        return true;
 52				    }
 53				
 54				    static bool check_bool_Equal(bool val0, bool val1) {
 55				        Expression<Func<bool>> e =
 56				            Expression.Lambda<Func<bool>>(
 57				                Expression.Equal(Expression.Constant(val0, typeof(bool)),
 58				                    Expression.Constant(val1, typeof(bool))),
 59				                new System.Collections.Generic.List<ParameterExpression>());
 60				        Func<bool> f = e.Compile();
 61				
 62				        bool fResult = default(bool);
 63				        Exception fEx = null;
 64				        try {
 65				            fResult = f();
 66				        }
 67				        catch (Exception ex) {
 68				            fEx = ex;
 69				        }
 70				
 71				        bool csResult = default(bool);
 72				        Exception csEx = null;
 73				        try {
 74				            csResult = (bool) (val0 == val1);
 75				        }
 76				        catch (Exception ex) {
 77				            csEx = ex;
 78				        }
 79				
 80				        if (fEx != null || csEx != null) {
 81				            return fEx != null && csEx != null && fEx.GetType() == csEx.GetType();
 82				        }
 83				        else {
 84				            return object.Equals(fResult, csResult);
 85				        }
 86				    }
 87				}
 88			
 89			
 90			public  static class Ext {
 91			    public static void StartCapture() {
 92			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
 93			//        m.Invoke(null, new object[] { "test.dll" });
 94			    }
 95			
 96			    public static void StopCapture() {
 97			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
 98			//        m.Invoke(null, new object[0]);
 99			    }
100			
101			    public static bool IsIntegralOrEnum(Type type) {
102			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
103			            case TypeCode.Byte:
104			            case TypeCode.SByte:
105			            case TypeCode.Int16:
106			            case TypeCode.Int32:
107			            case TypeCode.Int64:
108			            case TypeCode.UInt16:
109			            case TypeCode.UInt32:
110			            case TypeCode.UInt64:
111			                return true;
112			            default:
113			                return false;
114			        }
115			    }
116			
117			    public static bool IsFloating(Type type) {
118			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
119			            case TypeCode.Single:
120			            case TypeCode.Double:
121			                return true;
122			            default:
123			                return false;
124			        }
125			    }
126			
127			    public static Type GetNonNullableType(Type type) {
128			        return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
129			                type.GetGenericArguments()[0] :
130			                type;
131			    }
132			}
133			
134		
135	}
136			
137			//-------- Scenario 2178
138			namespace Scenario2178{
139				
140				public class Test
141				{
142			    [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "NotEqual__6", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
143			    public static Expression NotEqual__6() {
144			       if(Main() != 0 ) {
145			           throw new Exception();
146			       } else { 
147			           return Expression.Constant(0);
148			       }
149			    }
150				public     static int Main()
151				    {
152				        Ext.StartCapture();
153				        bool success = false;
154				        try
155				        {
156				            success = check_bool_NotEqual();
157				        }
158				        finally
159				        {
160				            Ext.StopCapture();
161				        }
162				        return success ? 0 : 1;
163				    }
164				
165				    static bool check_bool_NotEqual() {
166				        bool[] svals = new bool[] { true };
167				        for (int i = 0; i < svals.Length; i++) {
168				            for (int j = 0; j < svals.Length; j++) {
169				                if (!check_bool_NotEqual(svals[i], svals[j])) {
170				                    Console.WriteLine("bool_NotEqual failed");
171				                    return false;
172				                }
173				            }
174				        }
175				        return true;
176				    }
177				
178				    static bool check_bool_NotEqual(bool val0, bool val1) {
179				        Expression<Func<bool>> e =
180				            Expression.Lambda<Func<bool>>(
181				                Expression.NotEqual(Expression.Constant(val0, typeof(bool)),
182				                    Expression.Constant(val1, typeof(bool))),
183				                new System.Collections.Generic.List<ParameterExpression>());
184				        Func<bool> f = e.Compile();
185				
186				        bool fResult = default(bool);
187				        Exception fEx = null;
188				        try {
189				            fResult = f();
190				        }
191				        catch (Exception ex) {
192				            fEx = ex;
193				        }
194				
195				        bool csResult = default(bool);
196				        Exception csEx = null;
197				        try {
198				            csResult = (bool) (val0 != val1);
199				        }
200				        catch (Exception ex) {
201				            csEx = ex;
202				        }
203				
204				        if (fEx != null || csEx != null) {
205				            return fEx != null && csEx != null && fEx.GetType() == csEx.GetType();
206				        }
207				        else {
208				            return object.Equals(fResult, csResult);
209				        }
210				    }
211				}
212			
213			
214			public  static class Ext {
215			    public static void StartCapture() {
216			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
217			//        m.Invoke(null, new object[] { "test.dll" });
218			    }
219			
220			    public static void StopCapture() {
221			//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
222			//        m.Invoke(null, new object[0]);
223			    }
224			
225			    public static bool IsIntegralOrEnum(Type type) {
226			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
227			            case TypeCode.Byte:
228			            case TypeCode.SByte:
229			            case TypeCode.Int16:
230			            case TypeCode.Int32:
231			            case TypeCode.Int64:
232			            case TypeCode.UInt16:
233			            case TypeCode.UInt32:
234			            case TypeCode.UInt64:
235			                return true;
236			            default:
237			                return false;
238			        }
239			    }
240			
241			    public static bool IsFloating(Type type) {
242			        switch (Type.GetTypeCode(GetNonNullableType(type))) {
243			            case TypeCode.Single:
244			            case TypeCode.Double:
245			                return true;
246			            default:
247			                return false;
248			        }
249			    }
250			
251			    public static Type GetNonNullableType(Type type) {
252			        return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
253			                type.GetGenericArguments()[0] :
254			                type;
255			    }
256			}
257			
258		
259	}
260	
261}