Skip to content

Commit

Permalink
Add tests for LpStr and LpWStr marshalling.
Browse files Browse the repository at this point in the history
  • Loading branch information
kumpera committed Mar 19, 2012
1 parent 43fac74 commit c51f3e2
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
39 changes: 39 additions & 0 deletions mono/tests/libtest.c
Expand Up @@ -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;
}
50 changes: 50 additions & 0 deletions mono/tests/pinvoke2.cs
Expand Up @@ -1646,5 +1646,55 @@ public class T2 : T {
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;
}

}

0 comments on commit c51f3e2

Please sign in to comment.