2 using System
.Runtime
.InteropServices
;
7 // This is not permitted, should throw an exception
9 [DllImport ("libtest")]
10 public static extern void mono_safe_handle_ref (ref HandleRef handle
);
12 [DllImport ("libtest", EntryPoint
="mono_xr_as_handle")]
13 public static extern HandleRef
mono_xr_as_handle (HandleRef r
);
15 [DllImport ("libtest")]
16 public static extern int mono_xr (HandleRef sh
);
19 // Mono should throw exceptions on ref HandleRefs
21 public static int test_0_ref_handleref ()
23 object o
= new object ();
24 HandleRef s
= new HandleRef (o
, (IntPtr
) 0xeadcafe);
26 mono_safe_handle_ref (ref s
);
27 } catch (MarshalDirectiveException
){
35 // Mono should throw excentions on return HandleRefs
37 public static int test_0_handleref_return ()
39 object o
= new object ();
40 HandleRef s
= new HandleRef (o
, (IntPtr
) 0xeadcafe);
42 HandleRef ret
= mono_xr_as_handle (s
);
43 } catch (MarshalDirectiveException
){
50 public static int test_0_marshal_handleref_argument ()
52 object o
= new object ();
53 Console
.WriteLine ("BEFORE");
54 HandleRef s
= new HandleRef (o
, (IntPtr
) 0xeadcafe);
55 if (mono_xr (s
) != (0xeadcafe + 1234))
57 Console
.WriteLine ("AFTER");
61 [StructLayout (LayoutKind
.Sequential
)]
62 public struct StructTest
{
64 public HandleRef handle1
;
65 public HandleRef handle2
;
69 [DllImport ("libtest")]
70 public static extern int mono_safe_handle_struct_ref (ref StructTest test
);
72 [DllImport ("libtest")]
73 public static extern int mono_safe_handle_struct (StructTest test
);
75 static StructTest x
= new StructTest ();
77 public static int test_0_marshal_safehandle_field ()
81 object o
= new object ();
82 x
.handle1
= new HandleRef (o
, (IntPtr
) 0x7080feed);
83 x
.handle2
= new HandleRef (o
, (IntPtr
) 0x1234abcd);
85 if (mono_safe_handle_struct (x
) != 0xf00f)
91 public static int test_0_marshal_safehandle_field_ref ()
95 object o
= new object ();
96 x
.handle1
= new HandleRef (o
, (IntPtr
) 0x7080feed);
97 x
.handle2
= new HandleRef (o
, (IntPtr
) 0x1234abcd);
99 if (mono_safe_handle_struct_ref (ref x
) != 0xf00d)
107 return TestDriver
.RunTests (typeof (Tests
));