2008-10-24 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mcs / tests / gtest-etree-07.cs
1 // Compiler options: -unsafe
2
3 using System;
4 using System.Linq.Expressions;
5
6 delegate void EmptyDelegate ();
7 unsafe delegate int* UnsafeDelegate ();
8
9 class C
10 {
11         static int i;
12         
13         static void Test ()
14         {
15                 i += 9;
16         }
17         
18         static unsafe int* Foo ()
19         {
20                 return (int*)1;
21         }
22         
23         public static int Main ()
24         {
25                 Expression<Func<EmptyDelegate>> e = () => new EmptyDelegate (Test);
26                 
27                 if (e.Body.ToString () != "Convert(CreateDelegate(EmptyDelegate, null, Void Test()))")
28                         return 1;
29
30                 var v = e.Compile ();
31                 v.Invoke ()();
32                 
33                 if (i != 9)
34                         return 2;
35                 
36                 Expression<Func<EmptyDelegate>> e2 = () => Test;
37                 if (e2.Body.ToString () != "Convert(CreateDelegate(EmptyDelegate, null, Void Test()))")
38                         return 3;
39
40                 var v2 = e2.Compile ();
41                 v2.Invoke ()();
42                 
43                 if (i != 18)
44                         return 4;
45                         
46                 unsafe {
47                         Expression<Func<UnsafeDelegate>> e3 = () => new UnsafeDelegate (Foo);
48                         if (e3.Body.ToString () != "Convert(CreateDelegate(UnsafeDelegate, null, Int32* Foo()))")
49                                 return 5;
50                         
51                         var v3 = e3.Compile ();
52                         if (v3.Invoke ()() != (int*)1)
53                                 return 6;
54                 }
55
56                 Console.WriteLine ("OK");
57                 return 0;
58         }
59 }
60