2008-02-23 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / tests / pinvoke3.cs
index a55e9a571583731bf0cf1676378cc526e691c688..ccdaa38fedde6a18bb593ff893e27261ff61f9e9 100644 (file)
@@ -710,6 +710,49 @@ public class Tests {
                }
        }
 
+       public delegate int ArrayDelegate4_2 (int i, 
+                                                                               string j, 
+                                                                                 string[] arr);
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
+       public static extern int mono_test_marshal_array_delegate4_2 (string[] arr, int len, ArrayDelegate4_2 d);
+
+       public static int array_delegate4_2 (int i, string j, string[] arr) {
+               return (arr == null) ? 0 : 1;
+       }
+
+       public static int test_0_marshal_array_delegate_no_marshal_directive () {
+               try {
+                       mono_test_marshal_array_delegate4_2 (null, 0, new ArrayDelegate4_2 (array_delegate4_2));
+                       return 1;
+               }
+               catch (MarshalDirectiveException) {
+                       return 0;
+               }
+       }
+
+       public delegate int ArrayDelegate4_3 (int i, 
+                                                                               string j, 
+                                                                                 string[] arr);
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
+       public static extern int mono_test_marshal_array_delegate4_3 (string[] arr, int len, ArrayDelegate4_3 d);
+
+       public int array_delegate4_3 (int i, string j, string[] arr) {
+               return (arr == null) ? 0 : 1;
+       }
+
+       public static int test_0_marshal_array_delegate_no_marshal_directive_instance () {
+               try {
+                       Tests t = new Tests ();
+                       mono_test_marshal_array_delegate4_3 (null, 0, new ArrayDelegate4_3 (t.array_delegate4_3));
+                       return 1;
+               }
+               catch (MarshalDirectiveException) {
+                       return 0;
+               }
+       }
+
        public delegate int ArrayDelegate5 (int i, 
                                                                                string j, 
                                                                                [In, MarshalAs(UnmanagedType.LPArray, 
@@ -848,4 +891,75 @@ public class Tests {
                return mono_test_marshal_out_string_array_delegate (arr, 2, new ArrayDelegate10 (array_delegate10));
        }
 
+       /*
+        * [In, Out] classes
+        */
+
+       public delegate int InOutByvalClassDelegate ([In, Out] SimpleClass ss);
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_byval_class_delegate")]
+       public static extern int mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate d);
+
+       public static int delegate_test_byval_class_inout (SimpleClass ss) {
+               if ((ss.a != false) || (ss.b != true) || (ss.c != false) || (ss.d != "FOO"))
+                       return 1;
+
+               ss.a = true;
+               ss.b = false;
+               ss.c = true;
+               ss.d = "RES";
+
+               return 0;
+       }
+
+       public static int test_0_marshal_inout_byval_class_delegate () {
+               return mono_test_marshal_inout_byval_class_delegate (new InOutByvalClassDelegate (delegate_test_byval_class_inout));
+       }
+
+       /*
+        * Returning unicode strings
+        */
+       [return: MarshalAs(UnmanagedType.LPWStr)]
+       public delegate string ReturnUnicodeStringDelegate([MarshalAs(UnmanagedType.LPWStr)] string message);
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_return_unicode_string_delegate")]
+       public static extern int mono_test_marshal_return_unicode_string_delegate (ReturnUnicodeStringDelegate d);
+
+       public static String return_unicode_string_delegate (string message) {
+               return message;
+       }
+
+       public static int test_0_marshal_return_unicode_string_delegate () {    
+               return mono_test_marshal_return_unicode_string_delegate (new ReturnUnicodeStringDelegate (return_unicode_string_delegate));
+       }
+
+       /*
+        * Returning string arrays
+        */
+       public delegate string[] ReturnArrayDelegate (int i);
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_return_string_array_delegate")]
+       public static extern int mono_test_marshal_return_string_array_delegate (ReturnArrayDelegate d);
+
+       public static String[] return_array_delegate (int i) {
+               String[] arr = new String [2];
+
+               arr [0] = "ABC";
+               arr [1] = "DEF";
+
+               return arr;
+       }
+
+       public static String[] return_array_delegate_null (int i) {
+               return null;
+       }
+
+       public static int test_0_marshal_return_string_array_delegate () {      
+               return mono_test_marshal_return_string_array_delegate (new ReturnArrayDelegate (return_array_delegate));
+       }
+
+       public static int test_3_marshal_return_string_array_delegate_null () { 
+               return mono_test_marshal_return_string_array_delegate (new ReturnArrayDelegate (return_array_delegate_null));
+       }
+
 }