2 using System.Runtime.InteropServices;
5 public static bool b_cctor_run = false;
12 public static void method () {
16 delegate void DoIt ();
20 [DllImport("cygwin1.dll", EntryPoint="puts", CharSet=CharSet.Ansi)]
21 public static extern int puts (string name);
23 delegate void SimpleDelegate ();
24 delegate string NotSimpleDelegate (int a);
25 delegate int AnotherDelegate (string s);
27 delegate string StringDelegate ();
32 Console.WriteLine ("Test.F from delegate");
34 public static string G (int a) {
36 throw new Exception ("Something went wrong in G");
37 return "G got: " + a.ToString ();
39 public string H (int a) {
41 throw new Exception ("Something went wrong in H");
42 return "H got: " + a.ToString () + " and " + data.ToString ();
45 public virtual void VF () {
46 Console.WriteLine ("Test.VF from delegate");
53 static int Main (String[] args) {
54 return TestDriver.RunTests (typeof (Tests), args);
57 public static int test_0_tests () {
58 // Check that creation of delegates do not runs the class cctor
59 DoIt doit = new DoIt (B.method);
63 Tests test = new Tests ();
64 SimpleDelegate d = new SimpleDelegate (F);
65 SimpleDelegate d1 = new SimpleDelegate (test.VF);
66 NotSimpleDelegate d2 = new NotSimpleDelegate (G);
67 NotSimpleDelegate d3 = new NotSimpleDelegate (test.H);
70 // we run G() and H() before and after using them as delegates
71 // to be sure we don't corrupt them.
74 Console.WriteLine (d2 (2));
75 Console.WriteLine (d3 (3));
79 if (d.Method.Name != "F")
82 if (d3.Method == null)
86 Console.WriteLine (d3.DynamicInvoke (args));
88 AnotherDelegate d4 = new AnotherDelegate (puts);
89 if (d4.Method == null)
92 Console.WriteLine (d4.Method);
93 Console.WriteLine (d4.Method.Name);
94 Console.WriteLine (d4.Method.DeclaringType);
99 public static int test_0_unbox_this () {
101 StringDelegate d5 = new StringDelegate (x.ToString);
102 return d5 () == "10" ? 0 : 1;
105 delegate long LongDelegate (long l);
107 static long long_delegate (long l) {
111 public static int test_56_long () {
112 LongDelegate l = new LongDelegate (long_delegate);
117 delegate float FloatDelegate (float l);
119 static float float_delegate (float l) {
123 public static int test_56_float () {
124 FloatDelegate l = new FloatDelegate (float_delegate);
129 delegate double DoubleDelegate (double l);
131 static double double_delegate (double l) {
135 public static int test_56_double () {
136 DoubleDelegate l = new DoubleDelegate (double_delegate);
141 static int count = 0;
143 public static void inc_count () {
147 public static int test_0_multicast () {
148 SimpleDelegate d = new SimpleDelegate (inc_count);
153 return count == 2 ? 0 : 1;
156 public delegate int Delegate0 ();
158 public delegate int Delegate1 (int i);
160 public delegate int Delegate2 (int i, int j);
162 public int int_field;
164 public int adder0 () {
168 public static int adder0_static () {
172 public int adder1 (int i) {
173 return int_field + i;
176 public static int adder1_static (int i) {
180 public int adder2 (int i, int j) {
181 return int_field + i + j;
184 public static int adder2_static (int i, int j) {
188 public static int test_0_delegate_opt () {
189 Tests d = new Tests ();
192 if (new Delegate0 (d.adder0) () != 1)
195 if (new Delegate1 (d.adder1) (2) != 3)
198 if (new Delegate2 (d.adder2) (2, 3) != 6)
201 if (new Delegate0 (adder0_static) () != 1)
204 if (new Delegate1 (adder1_static) (2) != 2)
207 if (new Delegate2 (adder2_static) (2, 3) != 5)