Add tests for LpStr and LpWStr marshalling.
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 19 Mar 2012 20:20:43 +0000 (17:20 -0300)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 19 Mar 2012 20:47:40 +0000 (17:47 -0300)
mono/tests/libtest.c
mono/tests/pinvoke2.cs

index 1a9ee4892056df19501dc5833932d5eb649047c3..d710537588dff8e1619671ee57757fddb6f03527 100644 (file)
@@ -5076,3 +5076,42 @@ mono_test_marshal_call_callback (void)
        return callback ();
 }
 
+LIBTEST_API int STDCALL
+mono_test_marshal_lpstr (char *str)
+{
+       return strcmp ("ABC", str);
+}
+
+LIBTEST_API int STDCALL
+mono_test_marshal_lpwstr (gunichar2 *str)
+{
+       char *s;
+       int res;
+
+       s = g_utf16_to_utf8 (str, -1, NULL, NULL, NULL);
+       res = strcmp ("ABC", s);
+       g_free (s);
+
+       return res;
+}
+
+LIBTEST_API char* STDCALL
+mono_test_marshal_return_lpstr (void)
+{
+       char *res = marshal_alloc (4);
+       strcpy (res, "XYZ");
+       return res;
+}
+
+
+LIBTEST_API gunichar2* STDCALL
+mono_test_marshal_return_lpwstr (void)
+{
+       gunichar2 *res = marshal_alloc (8);
+       gunichar2* tmp = g_utf8_to_utf16 ("XYZ", -1, NULL, NULL, NULL);
+
+       memcpy (res, tmp, 8);
+       g_free (tmp);
+
+       return res;
+}
index 08a34c0047ad84acb0d610d3dac98f4cbae70ebb..826b91e1f8f7d4b38f48a062cf624f18b42ed516 100644 (file)
@@ -1646,5 +1646,55 @@ public class Tests {
                else
                        return 2;
        }
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_lpstr")]
+       public static extern int mono_test_marshal_lpstr ([MarshalAs(UnmanagedType.LPStr)] string str);
+
+       public static int test_0_mono_test_marshal_lpstr () {
+               string str = "ABC";
+
+               if (mono_test_marshal_lpstr (str) != 0)
+                       return 1;
+
+               return 0;
+       }
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_lpwstr")]
+       public static extern int mono_test_marshal_lpwstr ([MarshalAs(UnmanagedType.LPWStr)] string str);
+
+       public static int test_0_mono_test_marshal_lpwstr () {
+               string str = "ABC";
+
+               if (mono_test_marshal_lpwstr (str) != 0)
+                       return 1;
+
+               return 0;
+       }
+
+
+       [method: DllImport ("libtest", EntryPoint="mono_test_marshal_return_lpstr")]
+       [return: MarshalAs(UnmanagedType.LPStr)]
+       public static extern string mono_test_marshal_return_lpstr ();
+
+       public static int test_0_mono_test_marshal_return_lpstr () {
+               string str = mono_test_marshal_return_lpstr ();
+               if ("XYZ" == str)
+                       return 0;
+
+               return 1;
+       }
+
+       [method: DllImport ("libtest", EntryPoint="mono_test_marshal_return_lpwstr")]
+       [return: MarshalAs(UnmanagedType.LPWStr)]
+       public static extern string mono_test_marshal_return_lpwstr ();
+
+       public static int test_0_mono_test_marshal_return_lpwstr () {
+               string str = mono_test_marshal_return_lpwstr ();
+               if ("XYZ" == str)
+                       return 0;
+
+               return 1;
+       }
+
 }