2002-12-31 Martin Baulig <martin@ximian.com>
[mono.git] / mono / tests / pinvoke2.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 public class Test {
5
6         public static int delegate_test (int a)
7         {
8                 Console.WriteLine ("Delegate: " + a);
9                 
10                 if (a == 2)
11                         return 0;
12
13                 return 1;
14         }
15         
16         [StructLayout (LayoutKind.Sequential)]
17         public struct SimpleStruct {
18                 public bool a;
19                 public bool b;
20                 public bool c;
21                 public string d;
22         }
23
24         [DllImport ("libtest.so", EntryPoint="mono_test_marshal_char")]
25         public static extern int mono_test_marshal_char (char a1);
26
27         [DllImport ("libtest.so", EntryPoint="mono_test_marshal_array")]
28         public static extern int mono_test_marshal_array (int [] a1);
29         
30         [DllImport ("libtest.so", EntryPoint="mono_test_marshal_struct")]
31         public static extern int mono_test_marshal_struct (SimpleStruct ss);
32
33         [DllImport ("libtest.so", EntryPoint="mono_test_marshal_delegate")]
34         public static extern int mono_test_marshal_delegate (SimpleDelegate d);
35
36         public delegate int SimpleDelegate (int a);
37
38         public static int Main () {
39                 if (mono_test_marshal_char ('a') != 0)
40                         return 1;
41
42                 int [] a1 = new int [50];
43                 for (int i = 0; i < 50; i++)
44                         a1 [i] = i;
45
46                 if (mono_test_marshal_array (a1) != 1225)
47                         return 2;
48
49                 SimpleStruct ss = new  SimpleStruct ();
50                 ss.b = true;
51                 ss.d = "TEST";
52                 mono_test_marshal_struct (ss);
53                 
54                 SimpleDelegate d = new SimpleDelegate (delegate_test);
55
56                 if (mono_test_marshal_delegate (d) != 0)
57                         return 1;
58                 
59                 return 0;
60         }
61 }