2004-09-15 Martin Baulig <martin@ximian.com>
[mono.git] / mono / tests / pinvoke18.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 class Test
5 {
6         [DllImport("libtest")]
7         extern static int marshal_test_ref_bool
8         (
9                 int i, 
10                 [MarshalAs(UnmanagedType.I1)] ref bool b1, 
11                 [MarshalAs(UnmanagedType.VariantBool)] ref bool b2, 
12                 ref bool b3
13         );
14
15         struct BoolStruct
16         {
17                 public int i;
18                 [MarshalAs(UnmanagedType.I1)] public bool b1;
19                 [MarshalAs(UnmanagedType.VariantBool)] public bool b2;
20                 public bool b3;
21         }
22
23         [DllImport("libtest")]
24         extern static int marshal_test_bool_struct(ref BoolStruct s);
25
26         public static int Main()
27         {
28                 for (int i = 0; i < 8; i++)
29                 {
30                         bool b1 = (i & 4) != 0;
31                         bool b2 = (i & 2) != 0;
32                         bool b3 = (i & 1) != 0;
33                         bool orig_b1 = b1, orig_b2 = b2, orig_b3 = b3;
34                         if (marshal_test_ref_bool(i, ref b1, ref b2, ref b3) != 0)
35                                 return 4 * i + 1;
36                         if (b1 != !orig_b1)
37                                 return 4 * i + 2;
38                         if (b2 != !orig_b2)
39                                 return 4 * i + 3;
40                         if (b3 != !orig_b3)
41                                 return 4 * i + 4;
42                 }
43
44                 for (int i = 0; i < 8; i++)
45                 {
46                         BoolStruct s = new BoolStruct();
47                         s.i = i;
48                         s.b1 = (i & 4) != 0;
49                         s.b2 = (i & 2) != 0;
50                         s.b3 = (i & 1) != 0;
51                         BoolStruct orig = s;
52                         if (marshal_test_bool_struct(ref s) != 0)
53                                 return 4 * i + 33;
54                         if (s.b1 != !orig.b1)
55                                 return 4 * i + 34;
56                         if (s.b2 != !orig.b2)
57                                 return 4 * i + 35;
58                         if (s.b3 != !orig.b3)
59                                 return 4 * i + 36;
60                 }
61
62                 Console.WriteLine("Success");
63                 return 0;
64         }
65 }