2009-03-05 Zoltan Varga <vargaz@gmail.com>
[mono-debugger.git] / mono / tests / generic-stack-traces.2.cs
blobc8ae9bf8bf40eb6315b10b0029b78ec9beb1cb8d
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 public class main {
17 public static void callCallStaticCrash<T> () {
18 Gen<T> gt = new Gen<T> ();
19 gt.callStaticCrash ();
22 public static bool test (Exception exc, Type type) {
23 StackTrace st = new StackTrace (exc);
24 for (int i = 0; i < st.FrameCount; ++i) {
25 StackFrame sf = st.GetFrame (i);
26 MethodBase m = sf.GetMethod ();
27 Type t = m.DeclaringType;
28 if (m.IsGenericMethod) {
29 Type[] margs = m.GetGenericArguments ();
30 //Console.WriteLine (m.Name);
31 if (margs.Length != 1)
32 return false;
33 if (margs [0] != type)
34 return false;
36 if (t.IsGenericType) {
37 Type[] targs = t.GetGenericArguments ();
38 //Console.WriteLine (t.FullName);
39 if (targs.Length != 1)
40 return false;
41 if (targs [0] != type)
42 return false;
45 return true;
48 public static int Main () {
49 try {
50 callCallStaticCrash <int> ();
51 } catch (Exception exc) {
52 if (!test (exc, typeof (int)))
53 return 1;
55 try {
56 callCallStaticCrash <object> ();
57 } catch (Exception exc) {
58 if (!test (exc, typeof (object)))
59 return 1;
61 try {
62 callCallStaticCrash <string> ();
63 } catch (Exception exc) {
64 if (!test (exc, typeof (string)))
65 return 1;
67 try {
68 callCallStaticCrash <Gen<string>> ();
69 } catch (Exception exc) {
70 if (!test (exc, typeof (Gen<string>)))
71 return 1;
73 return 0;