/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
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
- #if !CLR2
- using System.Linq.Expressions;
- #else
- using Microsoft.Scripting.Ast;
- using Microsoft.Scripting.Utils;
- #endif
-
- using System.Reflection;
- using System;
- namespace ExpressionCompiler {
-
-
- //-------- Scenario 2177
- namespace Scenario2177{
-
- public class Test
- {
- [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Equal__6", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
- public static Expression Equal__6() {
- if(Main() != 0 ) {
- throw new Exception();
- } else {
- return Expression.Constant(0);
- }
- }
- public static int Main()
- {
- Ext.StartCapture();
- bool success = false;
- try
- {
- success = check_bool_Equal();
- }
- finally
- {
- Ext.StopCapture();
- }
- return success ? 0 : 1;
- }
-
- static bool check_bool_Equal() {
- bool[] svals = new bool[] { true };
- for (int i = 0; i < svals.Length; i++) {
- for (int j = 0; j < svals.Length; j++) {
- if (!check_bool_Equal(svals[i], svals[j])) {
- Console.WriteLine("bool_Equal failed");
- return false;
- }
- }
- }
- return true;
- }
-
- static bool check_bool_Equal(bool val0, bool val1) {
- Expression<Func<bool>> e =
- Expression.Lambda<Func<bool>>(
- Expression.Equal(Expression.Constant(val0, typeof(bool)),
- Expression.Constant(val1, typeof(bool))),
- new System.Collections.Generic.List<ParameterExpression>());
- Func<bool> f = e.Compile();
-
- bool fResult = default(bool);
- Exception fEx = null;
- try {
- fResult = f();
- }
- catch (Exception ex) {
- fEx = ex;
- }
-
- bool csResult = default(bool);
- Exception csEx = null;
- try {
- csResult = (bool) (val0 == val1);
- }
- catch (Exception ex) {
- csEx = ex;
- }
-
- if (fEx != null || csEx != null) {
- return fEx != null && csEx != null && fEx.GetType() == csEx.GetType();
- }
- else {
- return object.Equals(fResult, csResult);
- }
- }
- }
-
-
- public static class Ext {
- public static void StartCapture() {
- // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
- // m.Invoke(null, new object[] { "test.dll" });
- }
-
- public static void StopCapture() {
- // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
- // m.Invoke(null, new object[0]);
- }
-
- public static bool IsIntegralOrEnum(Type type) {
- switch (Type.GetTypeCode(GetNonNullableType(type))) {
- case TypeCode.Byte:
- case TypeCode.SByte:
- case TypeCode.Int16:
- case TypeCode.Int32:
- case TypeCode.Int64:
- case TypeCode.UInt16:
- case TypeCode.UInt32:
- case TypeCode.UInt64:
- return true;
- default:
- return false;
- }
- }
-
- public static bool IsFloating(Type type) {
- switch (Type.GetTypeCode(GetNonNullableType(type))) {
- case TypeCode.Single:
- case TypeCode.Double:
- return true;
- default:
- return false;
- }
- }
-
- public static Type GetNonNullableType(Type type) {
- return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
- type.GetGenericArguments()[0] :
- type;
- }
- }
-
-
- }
-
- //-------- Scenario 2178
- namespace Scenario2178{
-
- public class Test
- {
- [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "NotEqual__6", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
- public static Expression NotEqual__6() {
- if(Main() != 0 ) {
- throw new Exception();
- } else {
- return Expression.Constant(0);
- }
- }
- public static int Main()
- {
- Ext.StartCapture();
- bool success = false;
- try
- {
- success = check_bool_NotEqual();
- }
- finally
- {
- Ext.StopCapture();
- }
- return success ? 0 : 1;
- }
-
- static bool check_bool_NotEqual() {
- bool[] svals = new bool[] { true };
- for (int i = 0; i < svals.Length; i++) {
- for (int j = 0; j < svals.Length; j++) {
- if (!check_bool_NotEqual(svals[i], svals[j])) {
- Console.WriteLine("bool_NotEqual failed");
- return false;
- }
- }
- }
- return true;
- }
-
- static bool check_bool_NotEqual(bool val0, bool val1) {
- Expression<Func<bool>> e =
- Expression.Lambda<Func<bool>>(
- Expression.NotEqual(Expression.Constant(val0, typeof(bool)),
- Expression.Constant(val1, typeof(bool))),
- new System.Collections.Generic.List<ParameterExpression>());
- Func<bool> f = e.Compile();
-
- bool fResult = default(bool);
- Exception fEx = null;
- try {
- fResult = f();
- }
- catch (Exception ex) {
- fEx = ex;
- }
-
- bool csResult = default(bool);
- Exception csEx = null;
- try {
- csResult = (bool) (val0 != val1);
- }
- catch (Exception ex) {
- csEx = ex;
- }
-
- if (fEx != null || csEx != null) {
- return fEx != null && csEx != null && fEx.GetType() == csEx.GetType();
- }
- else {
- return object.Equals(fResult, csResult);
- }
- }
- }
-
-
- public static class Ext {
- public static void StartCapture() {
- // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
- // m.Invoke(null, new object[] { "test.dll" });
- }
-
- public static void StopCapture() {
- // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
- // m.Invoke(null, new object[0]);
- }
-
- public static bool IsIntegralOrEnum(Type type) {
- switch (Type.GetTypeCode(GetNonNullableType(type))) {
- case TypeCode.Byte:
- case TypeCode.SByte:
- case TypeCode.Int16:
- case TypeCode.Int32:
- case TypeCode.Int64:
- case TypeCode.UInt16:
- case TypeCode.UInt32:
- case TypeCode.UInt64:
- return true;
- default:
- return false;
- }
- }
-
- public static bool IsFloating(Type type) {
- switch (Type.GetTypeCode(GetNonNullableType(type))) {
- case TypeCode.Single:
- case TypeCode.Double:
- return true;
- default:
- return false;
- }
- }
-
- public static Type GetNonNullableType(Type type) {
- return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
- type.GetGenericArguments()[0] :
- type;
- }
- }
-
-
- }
-
- }