[System] Use GZipStream from corefx
[mono-project.git] / mono / tests / generic-stack-traces.2.cs
blob499cf9e8d0075fb7e82282a5fd2fa29de18eb3d3
1 using System;
2 using System.Diagnostics;
3 using System.Reflection;
5 public class Gen<T> {
6 public static void staticCrash () {
7 object o = null;
8 o.GetType ();
11 public void callStaticCrash () {
12 staticCrash ();
16 class Foo<T1, T2> {
18 public void Throw () {
19 throw new Exception ();
22 public void Throw<T3> () {
23 throw new Exception ();
27 class Bar<T> : Foo<object, T> {
30 public class main {
31 public static void callCallStaticCrash<T> () {
32 Gen<T> gt = new Gen<T> ();
33 gt.callStaticCrash ();
36 public static bool test (Exception exc, Type type) {
37 StackTrace st = new StackTrace (exc);
38 for (int i = 0; i < st.FrameCount; ++i) {
39 StackFrame sf = st.GetFrame (i);
40 MethodBase m = sf.GetMethod ();
41 if (m == null)
42 continue;
43 Type t = m.DeclaringType;
44 if (m.IsGenericMethod) {
45 Type[] margs = m.GetGenericArguments ();
46 //Console.WriteLine (m.Name);
47 if (margs.Length != 1)
48 return false;
49 if (margs [0] != type)
50 return false;
52 if (t.IsGenericType) {
53 Type[] targs = t.GetGenericArguments ();
54 //Console.WriteLine (t.FullName);
55 if (targs.Length != 1)
56 return false;
57 if (targs [0] != type)
58 return false;
61 return true;
64 public static int Main () {
65 try {
66 callCallStaticCrash <int> ();
67 } catch (Exception exc) {
68 if (!test (exc, typeof (int)))
69 return 1;
71 try {
72 callCallStaticCrash <object> ();
73 } catch (Exception exc) {
74 if (!test (exc, typeof (object)))
75 return 1;
77 try {
78 callCallStaticCrash <string> ();
79 } catch (Exception exc) {
80 if (!test (exc, typeof (string)))
81 return 1;
83 try {
84 callCallStaticCrash <Gen<string>> ();
85 } catch (Exception exc) {
86 if (!test (exc, typeof (Gen<string>)))
87 return 1;
90 // Exception thrown in inherited method with different generic context
91 // (#509406)
92 try {
93 new Bar <string> ().Throw ();
94 } catch (Exception ex) {
95 Console.WriteLine (new StackTrace (ex));
98 try {
99 new Bar <string> ().Throw<Bar<string>> ();
100 } catch (Exception ex) {
101 Console.WriteLine (new StackTrace (ex));
104 return 0;