PageRenderTime 38ms CodeModel.GetById 2ms app.highlight 31ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 760 lines | 616 code | 129 blank | 15 comment | 84 complexity | fb79c283ae2934e4a80e62d7da6b11eb 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 256
 14				namespace Scenario256{
 15					
 16					public class Test
 17					{
 18				    [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "int_double_Sp_New__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
 19				    public static Expression int_double_Sp_New__() {
 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_int_double_Sp_New();
 33					        }
 34					        finally
 35					        {
 36					            Ext.StopCapture();
 37					        }
 38					        return success ? 0 : 1;
 39					    }
 40					
 41					    static bool check_int_double_Sp_New() {
 42					        int[] svals0 = new int[] { 0, 1, -1, int.MinValue, int.MaxValue };
 43					        double[] svals1 = new double[] { 0, 1, -1, double.MinValue, double.MaxValue, double.Epsilon, double.NegativeInfinity, double.PositiveInfinity, double.NaN };
 44					        for (int i = 0; i < svals0.Length; i++) {
 45					            for (int j = 0; j < svals1.Length; j++) {
 46					                if (!check_int_double_Sp_New(svals0[i], svals1[j])) {
 47					                    Console.WriteLine("int_double_Sp_New failed");
 48					                    return false;
 49					                }
 50					            }
 51					        }
 52					        return true;
 53					    }
 54					
 55					    static bool check_int_double_Sp_New(int val0, double val1) {
 56					        ConstructorInfo constructor = typeof(Sp).GetConstructor(new Type[] { typeof(int), typeof(double) });
 57					        Expression[] exprArgs = new Expression[] { Expression.Constant(val0, typeof(int)), Expression.Constant(val1, typeof(double)) };
 58					        Expression<Func<Sp>> e = Expression.Lambda<Func<Sp>>(
 59					            Expression.New(constructor, exprArgs),
 60					            new System.Collections.Generic.List<ParameterExpression>());
 61					        Func<Sp> f = e.Compile();
 62					
 63					        return object.Equals(f(), new Sp(val0, val1));
 64					    }
 65					}
 66				
 67				
 68				public  static class Ext {
 69				    public static void StartCapture() {
 70				//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
 71				//        m.Invoke(null, new object[] { "test.dll" });
 72				    }
 73				
 74				    public static void StopCapture() {
 75				//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
 76				//        m.Invoke(null, new object[0]);
 77				    }
 78				
 79				    public static bool IsIntegralOrEnum(Type type) {
 80				        switch (Type.GetTypeCode(GetNonNullableType(type))) {
 81				            case TypeCode.Byte:
 82				            case TypeCode.SByte:
 83				            case TypeCode.Int16:
 84				            case TypeCode.Int32:
 85				            case TypeCode.Int64:
 86				            case TypeCode.UInt16:
 87				            case TypeCode.UInt32:
 88				            case TypeCode.UInt64:
 89				                return true;
 90				            default:
 91				                return false;
 92				        }
 93				    }
 94				
 95				    public static bool IsFloating(Type type) {
 96				        switch (Type.GetTypeCode(GetNonNullableType(type))) {
 97				            case TypeCode.Single:
 98				            case TypeCode.Double:
 99				                return true;
100				            default:
101				                return false;
102				        }
103				    }
104				
105				    public static Type GetNonNullableType(Type type) {
106				        return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
107				                type.GetGenericArguments()[0] :
108				                type;
109				    }
110				}
111				
112			
113			
114			
115			public interface I {
116			  void M();
117			}
118			
119			public  class C : IEquatable<C>, I {
120			    void I.M() {
121			    }
122			
123			    public override bool Equals(object o) {
124			        return o is C && Equals((C) o);
125			    }
126			
127			    public bool Equals(C c) {
128			        return c != null;
129			    }
130			
131			    public override int GetHashCode() {
132			        return 0;
133			    }
134			}
135			
136			public  class D : C, IEquatable<D> {
137			    public int Val;
138			    public string S;
139			
140			    public D() {
141			    }
142			    public D(int val) : this(val, "") {
143			    }
144			
145			    public D(int val, string s) {
146			        Val = val;
147			        S = s;
148			    }
149			
150			    public override bool Equals(object o) {
151			        return o is D && Equals((D) o);
152			    }
153			
154			    public bool Equals(D d) {
155			        return d != null && d.Val == Val && d.S == S;
156			    }
157			
158			    public override int GetHashCode() {
159			        return Val ^ (S == null ? 0 : S.GetHashCode());
160			    }
161			}
162			
163			public enum E {
164			  A=1, B=2
165			}
166			
167			public enum El : long {
168			  A, B, C
169			}
170			
171			public struct S : IEquatable<S> {
172			    public override bool Equals(object o) {
173			        return (o is S) && Equals((S) o);
174			    }
175			    public bool Equals(S other) {
176			        return true;
177			    }
178			    public override int GetHashCode() {
179			        return 0;
180			    }
181			}
182			
183			public struct Sp : IEquatable<Sp> {
184			    public Sp(int i, double d) {
185			        I = i;
186			        D = d;
187			    }
188			
189			    public int I;
190			    public double D;
191			
192			    public override bool Equals(object o) {
193			        return (o is Sp) && Equals((Sp) o);
194			    }
195			    public bool Equals(Sp other) {
196			        return other.I.Equals(I) && other.D.Equals(D);
197			    }
198			    public override int GetHashCode() {
199			        return I.GetHashCode() ^ D.GetHashCode();
200			    }
201			}
202			
203			public struct Ss : IEquatable<Ss> {
204			    public Ss(S s) {
205			        Val = s;
206			    }
207			
208			    public S Val;
209			
210			    public override bool Equals(object o) {
211			        return (o is Ss) && Equals((Ss) o);
212			    }
213			    public bool Equals(Ss other) {
214			        return other.Val.Equals(Val);
215			    }
216			    public override int GetHashCode() {
217			        return Val.GetHashCode();
218			    }
219			}
220			
221			public struct Sc : IEquatable<Sc> {
222			    public Sc(string s) {
223			        S = s;
224			    }
225			
226			    public string S;
227			
228			    public override bool Equals(object o) {
229			        return (o is Sc) && Equals((Sc) o);
230			    }
231			    public bool Equals(Sc other) {
232			        return other.S == S;
233			    }
234			    public override int GetHashCode() {
235			        return S.GetHashCode();
236			    }
237			}
238			
239			public struct Scs : IEquatable<Scs> {
240			    public Scs(string s, S val) {
241			        S = s;
242			        Val = val;
243			    }
244			
245			    public string S;
246			    public S Val;
247			
248			    public override bool Equals(object o) {
249			        return (o is Scs) && Equals((Scs) o);
250			    }
251			    public bool Equals(Scs other) {
252			        return other.S == S && other.Val.Equals(Val);
253			    }
254			    public override int GetHashCode() {
255			        return S.GetHashCode() ^ Val.GetHashCode();
256			    }
257			}
258			
259		
260	}
261				
262				//-------- Scenario 257
263				namespace Scenario257{
264					
265					public class Test
266					{
267				    [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "string_S_Scs_New__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
268				    public static Expression string_S_Scs_New__() {
269				       if(Main() != 0 ) {
270				           throw new Exception();
271				       } else { 
272				           return Expression.Constant(0);
273				       }
274				    }
275					public     static int Main()
276					    {
277					        Ext.StartCapture();
278					        bool success = false;
279					        try
280					        {
281					            success = check_string_S_Scs_New();
282					        }
283					        finally
284					        {
285					            Ext.StopCapture();
286					        }
287					        return success ? 0 : 1;
288					    }
289					
290					    static bool check_string_S_Scs_New() {
291					        string[] svals0 = new string[] { null, "", "a", "foo" };
292					        S[] svals1 = new S[] { default(S), new S() };
293					        for (int i = 0; i < svals0.Length; i++) {
294					            for (int j = 0; j < svals1.Length; j++) {
295					                if (!check_string_S_Scs_New(svals0[i], svals1[j])) {
296					                    Console.WriteLine("string_S_Scs_New failed");
297					                    return false;
298					                }
299					            }
300					        }
301					        return true;
302					    }
303					
304					    static bool check_string_S_Scs_New(string val0, S val1) {
305					        ConstructorInfo constructor = typeof(Scs).GetConstructor(new Type[] { typeof(string), typeof(S) });
306					        Expression[] exprArgs = new Expression[] { Expression.Constant(val0, typeof(string)), Expression.Constant(val1, typeof(S)) };
307					        Expression<Func<Scs>> e = Expression.Lambda<Func<Scs>>(
308					            Expression.New(constructor, exprArgs),
309					            new System.Collections.Generic.List<ParameterExpression>());
310					        Func<Scs> f = e.Compile();
311					
312					        return object.Equals(f(), new Scs(val0, val1));
313					    }
314					}
315				
316				
317				public  static class Ext {
318				    public static void StartCapture() {
319				//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
320				//        m.Invoke(null, new object[] { "test.dll" });
321				    }
322				
323				    public static void StopCapture() {
324				//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
325				//        m.Invoke(null, new object[0]);
326				    }
327				
328				    public static bool IsIntegralOrEnum(Type type) {
329				        switch (Type.GetTypeCode(GetNonNullableType(type))) {
330				            case TypeCode.Byte:
331				            case TypeCode.SByte:
332				            case TypeCode.Int16:
333				            case TypeCode.Int32:
334				            case TypeCode.Int64:
335				            case TypeCode.UInt16:
336				            case TypeCode.UInt32:
337				            case TypeCode.UInt64:
338				                return true;
339				            default:
340				                return false;
341				        }
342				    }
343				
344				    public static bool IsFloating(Type type) {
345				        switch (Type.GetTypeCode(GetNonNullableType(type))) {
346				            case TypeCode.Single:
347				            case TypeCode.Double:
348				                return true;
349				            default:
350				                return false;
351				        }
352				    }
353				
354				    public static Type GetNonNullableType(Type type) {
355				        return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
356				                type.GetGenericArguments()[0] :
357				                type;
358				    }
359				}
360				
361			
362			
363			
364			public interface I {
365			  void M();
366			}
367			
368			public  class C : IEquatable<C>, I {
369			    void I.M() {
370			    }
371			
372			    public override bool Equals(object o) {
373			        return o is C && Equals((C) o);
374			    }
375			
376			    public bool Equals(C c) {
377			        return c != null;
378			    }
379			
380			    public override int GetHashCode() {
381			        return 0;
382			    }
383			}
384			
385			public  class D : C, IEquatable<D> {
386			    public int Val;
387			    public string S;
388			
389			    public D() {
390			    }
391			    public D(int val) : this(val, "") {
392			    }
393			
394			    public D(int val, string s) {
395			        Val = val;
396			        S = s;
397			    }
398			
399			    public override bool Equals(object o) {
400			        return o is D && Equals((D) o);
401			    }
402			
403			    public bool Equals(D d) {
404			        return d != null && d.Val == Val && d.S == S;
405			    }
406			
407			    public override int GetHashCode() {
408			        return Val ^ (S == null ? 0 : S.GetHashCode());
409			    }
410			}
411			
412			public enum E {
413			  A=1, B=2
414			}
415			
416			public enum El : long {
417			  A, B, C
418			}
419			
420			public struct S : IEquatable<S> {
421			    public override bool Equals(object o) {
422			        return (o is S) && Equals((S) o);
423			    }
424			    public bool Equals(S other) {
425			        return true;
426			    }
427			    public override int GetHashCode() {
428			        return 0;
429			    }
430			}
431			
432			public struct Sp : IEquatable<Sp> {
433			    public Sp(int i, double d) {
434			        I = i;
435			        D = d;
436			    }
437			
438			    public int I;
439			    public double D;
440			
441			    public override bool Equals(object o) {
442			        return (o is Sp) && Equals((Sp) o);
443			    }
444			    public bool Equals(Sp other) {
445			        return other.I.Equals(I) && other.D.Equals(D);
446			    }
447			    public override int GetHashCode() {
448			        return I.GetHashCode() ^ D.GetHashCode();
449			    }
450			}
451			
452			public struct Ss : IEquatable<Ss> {
453			    public Ss(S s) {
454			        Val = s;
455			    }
456			
457			    public S Val;
458			
459			    public override bool Equals(object o) {
460			        return (o is Ss) && Equals((Ss) o);
461			    }
462			    public bool Equals(Ss other) {
463			        return other.Val.Equals(Val);
464			    }
465			    public override int GetHashCode() {
466			        return Val.GetHashCode();
467			    }
468			}
469			
470			public struct Sc : IEquatable<Sc> {
471			    public Sc(string s) {
472			        S = s;
473			    }
474			
475			    public string S;
476			
477			    public override bool Equals(object o) {
478			        return (o is Sc) && Equals((Sc) o);
479			    }
480			    public bool Equals(Sc other) {
481			        return other.S == S;
482			    }
483			    public override int GetHashCode() {
484			        return S.GetHashCode();
485			    }
486			}
487			
488			public struct Scs : IEquatable<Scs> {
489			    public Scs(string s, S val) {
490			        S = s;
491			        Val = val;
492			    }
493			
494			    public string S;
495			    public S Val;
496			
497			    public override bool Equals(object o) {
498			        return (o is Scs) && Equals((Scs) o);
499			    }
500			    public bool Equals(Scs other) {
501			        return other.S == S && other.Val.Equals(Val);
502			    }
503			    public override int GetHashCode() {
504			        return S.GetHashCode() ^ Val.GetHashCode();
505			    }
506			}
507			
508		
509	}
510				
511				//-------- Scenario 258
512				namespace Scenario258{
513					
514					public class Test
515					{
516				    [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "int_string_D_New__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
517				    public static Expression int_string_D_New__() {
518				       if(Main() != 0 ) {
519				           throw new Exception();
520				       } else { 
521				           return Expression.Constant(0);
522				       }
523				    }
524					public     static int Main()
525					    {
526					        Ext.StartCapture();
527					        bool success = false;
528					        try
529					        {
530					            success = check_int_string_D_New();
531					        }
532					        finally
533					        {
534					            Ext.StopCapture();
535					        }
536					        return success ? 0 : 1;
537					    }
538					
539					    static bool check_int_string_D_New() {
540					        int[] svals0 = new int[] { 0, 1, -1, int.MinValue, int.MaxValue };
541					        string[] svals1 = new string[] { null, "", "a", "foo" };
542					        for (int i = 0; i < svals0.Length; i++) {
543					            for (int j = 0; j < svals1.Length; j++) {
544					                if (!check_int_string_D_New(svals0[i], svals1[j])) {
545					                    Console.WriteLine("int_string_D_New failed");
546					                    return false;
547					                }
548					            }
549					        }
550					        return true;
551					    }
552					
553					    static bool check_int_string_D_New(int val0, string val1) {
554					        ConstructorInfo constructor = typeof(D).GetConstructor(new Type[] { typeof(int), typeof(string) });
555					        Expression[] exprArgs = new Expression[] { Expression.Constant(val0, typeof(int)), Expression.Constant(val1, typeof(string)) };
556					        Expression<Func<D>> e = Expression.Lambda<Func<D>>(
557					            Expression.New(constructor, exprArgs),
558					            new System.Collections.Generic.List<ParameterExpression>());
559					        Func<D> f = e.Compile();
560					
561					        return object.Equals(f(), new D(val0, val1));
562					    }
563					}
564				
565				
566				public  static class Ext {
567				    public static void StartCapture() {
568				//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
569				//        m.Invoke(null, new object[] { "test.dll" });
570				    }
571				
572				    public static void StopCapture() {
573				//        MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
574				//        m.Invoke(null, new object[0]);
575				    }
576				
577				    public static bool IsIntegralOrEnum(Type type) {
578				        switch (Type.GetTypeCode(GetNonNullableType(type))) {
579				            case TypeCode.Byte:
580				            case TypeCode.SByte:
581				            case TypeCode.Int16:
582				            case TypeCode.Int32:
583				            case TypeCode.Int64:
584				            case TypeCode.UInt16:
585				            case TypeCode.UInt32:
586				            case TypeCode.UInt64:
587				                return true;
588				            default:
589				                return false;
590				        }
591				    }
592				
593				    public static bool IsFloating(Type type) {
594				        switch (Type.GetTypeCode(GetNonNullableType(type))) {
595				            case TypeCode.Single:
596				            case TypeCode.Double:
597				                return true;
598				            default:
599				                return false;
600				        }
601				    }
602				
603				    public static Type GetNonNullableType(Type type) {
604				        return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
605				                type.GetGenericArguments()[0] :
606				                type;
607				    }
608				}
609				
610			
611			
612			
613			public interface I {
614			  void M();
615			}
616			
617			public  class C : IEquatable<C>, I {
618			    void I.M() {
619			    }
620			
621			    public override bool Equals(object o) {
622			        return o is C && Equals((C) o);
623			    }
624			
625			    public bool Equals(C c) {
626			        return c != null;
627			    }
628			
629			    public override int GetHashCode() {
630			        return 0;
631			    }
632			}
633			
634			public  class D : C, IEquatable<D> {
635			    public int Val;
636			    public string S;
637			
638			    public D() {
639			    }
640			    public D(int val) : this(val, "") {
641			    }
642			
643			    public D(int val, string s) {
644			        Val = val;
645			        S = s;
646			    }
647			
648			    public override bool Equals(object o) {
649			        return o is D && Equals((D) o);
650			    }
651			
652			    public bool Equals(D d) {
653			        return d != null && d.Val == Val && d.S == S;
654			    }
655			
656			    public override int GetHashCode() {
657			        return Val ^ (S == null ? 0 : S.GetHashCode());
658			    }
659			}
660			
661			public enum E {
662			  A=1, B=2
663			}
664			
665			public enum El : long {
666			  A, B, C
667			}
668			
669			public struct S : IEquatable<S> {
670			    public override bool Equals(object o) {
671			        return (o is S) && Equals((S) o);
672			    }
673			    public bool Equals(S other) {
674			        return true;
675			    }
676			    public override int GetHashCode() {
677			        return 0;
678			    }
679			}
680			
681			public struct Sp : IEquatable<Sp> {
682			    public Sp(int i, double d) {
683			        I = i;
684			        D = d;
685			    }
686			
687			    public int I;
688			    public double D;
689			
690			    public override bool Equals(object o) {
691			        return (o is Sp) && Equals((Sp) o);
692			    }
693			    public bool Equals(Sp other) {
694			        return other.I.Equals(I) && other.D.Equals(D);
695			    }
696			    public override int GetHashCode() {
697			        return I.GetHashCode() ^ D.GetHashCode();
698			    }
699			}
700			
701			public struct Ss : IEquatable<Ss> {
702			    public Ss(S s) {
703			        Val = s;
704			    }
705			
706			    public S Val;
707			
708			    public override bool Equals(object o) {
709			        return (o is Ss) && Equals((Ss) o);
710			    }
711			    public bool Equals(Ss other) {
712			        return other.Val.Equals(Val);
713			    }
714			    public override int GetHashCode() {
715			        return Val.GetHashCode();
716			    }
717			}
718			
719			public struct Sc : IEquatable<Sc> {
720			    public Sc(string s) {
721			        S = s;
722			    }
723			
724			    public string S;
725			
726			    public override bool Equals(object o) {
727			        return (o is Sc) && Equals((Sc) o);
728			    }
729			    public bool Equals(Sc other) {
730			        return other.S == S;
731			    }
732			    public override int GetHashCode() {
733			        return S.GetHashCode();
734			    }
735			}
736			
737			public struct Scs : IEquatable<Scs> {
738			    public Scs(string s, S val) {
739			        S = s;
740			        Val = val;
741			    }
742			
743			    public string S;
744			    public S Val;
745			
746			    public override bool Equals(object o) {
747			        return (o is Scs) && Equals((Scs) o);
748			    }
749			    public bool Equals(Scs other) {
750			        return other.S == S && other.Val.Equals(Val);
751			    }
752			    public override int GetHashCode() {
753			        return S.GetHashCode() ^ Val.GetHashCode();
754			    }
755			}
756			
757		
758	}
759	
760}