//
// Copyright 2011 Xamarin Inc (http://www.xamarin.com).
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
public struct EmptyStruct {
}
+ [StructLayout (LayoutKind.Sequential, Size=1)]
+ public struct EmptyStructCpp {
+ }
+
[StructLayout (LayoutKind.Sequential)]
public struct DelegateStruct {
public int a;
[DllImport ("libtest", EntryPoint="mono_test_marshal_out_array")]
public static extern int mono_test_marshal_out_array ([Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int [] a1, int n);
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_out_byref_array_out_size_param")]
+ public static extern int mono_test_marshal_out_byref_array_out_size_param ([Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] out int [] a1, out int n);
+
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_out_lparray_out_size_param")]
+ public static extern int mono_test_marshal_out_lparray_out_size_param ([Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int [] a1, out int n);
+
[DllImport ("libtest", EntryPoint="mono_test_marshal_inout_nonblittable_array", CharSet = CharSet.Unicode)]
public static extern int mono_test_marshal_inout_nonblittable_array ([In, Out] char [] a1);
[DllImport ("libtest", EntryPoint="mono_test_empty_struct")]
public static extern int mono_test_empty_struct (int a, EmptyStruct es, int b);
+ [DllImport ("libtest", EntryPoint="mono_test_return_empty_struct")]
+ public static extern EmptyStruct mono_test_return_empty_struct (int a);
+
+ [DllImport ("libtest", EntryPoint="mono_test_return_empty_struct")]
+ public static extern EmptyStructCpp mono_test_return_empty_struct_cpp (int a);
+
[DllImport ("libtest", EntryPoint="mono_test_marshal_lpstruct")]
public static extern int mono_test_marshal_lpstruct ([In, MarshalAs(UnmanagedType.LPStruct)] SimpleStruct ss);
[DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder")]
public static extern void mono_test_marshal_stringbuilder (StringBuilder sb, int len);
- [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder2")]
- public static extern void mono_test_marshal_stringbuilder2 (StringBuilder sb, int len);
-
[DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_default")]
public static extern void mono_test_marshal_stringbuilder_default (StringBuilder sb, int len);
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_append")]
+ public static extern void mono_test_marshal_stringbuilder_append (StringBuilder sb, int len);
+
[DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_unicode", CharSet=CharSet.Unicode)]
public static extern void mono_test_marshal_stringbuilder_unicode (StringBuilder sb, int len);
return 0;
}
+ public static int test_0_marshal_out_byref_array_out_size_param () {
+ int [] a1 = null;
+ int len;
+
+ int res = mono_test_marshal_out_byref_array_out_size_param (out a1, out len);
+ if (len != 4)
+ return 1;
+ for (int i = 0; i < len; i++)
+ if (a1 [i] != i)
+ return 2;
+ return 0;
+ }
+
+ public static int test_0_marshal_out_lparray_out_size_param () {
+ int [] a1 = null;
+ int len;
+
+ a1 = new int [10];
+ int res = mono_test_marshal_out_lparray_out_size_param (a1, out len);
+ // Check that a1 was not overwritten
+ a1.GetHashCode ();
+ if (len != 4)
+ return 1;
+ for (int i = 0; i < len; i++)
+ if (a1 [i] != i)
+ return 2;
+ return 0;
+ }
+
public static int test_0_marshal_inout_nonblittable_array () {
char [] a1 = new char [10];
for (int i = 0; i < 10; i++)
if (mono_test_empty_struct (1, es, 2) != 0)
return 1;
+
+ mono_test_return_empty_struct (42);
+
+ return 0;
+ }
+
+ /* FIXME: This doesn't work on all platforms */
+ /*
+ public static int test_0_marshal_empty_struct_cpp () {
+ EmptyStructCpp es = new EmptyStructCpp ();
+
+ mono_test_return_empty_struct_cpp (42);
return 0;
}
+ */
public static int test_0_marshal_lpstruct () {
SimpleStruct ss = new SimpleStruct ();
if (res != "This is my message. Isn't it nice?")
return 1;
- // Test that cached_str is cleared
- mono_test_marshal_stringbuilder2 (sb, sb.Capacity);
- res = sb.ToString();
- if (res != "EFGH")
- return 2;
+ // Test StringBuilder with default capacity (16)
+ StringBuilder sb2 = new StringBuilder();
+ mono_test_marshal_stringbuilder_default (sb2, sb2.Capacity);
+ if (sb2.ToString () != "This is my messa")
+ return 3;
+
+ return 0;
+ }
+
+ public static int test_0_marshal_stringbuilder_append () {
+ const String in_sentinel = "MONO_";
+ const String out_sentinel = "CSHARP_";
+ const int iterations = 100;
+ StringBuilder sb = new StringBuilder(255);
+ StringBuilder check = new StringBuilder(255);
+
+ for (int i = 0; i < iterations; i++) {
+ sb.Append (in_sentinel[i % in_sentinel.Length]);
+ check.Append (out_sentinel[i % out_sentinel.Length]);
+
+ mono_test_marshal_stringbuilder_append (sb, sb.Length);
+
+ String res = sb.ToString();
+ String checkRev = check.ToString();
+ if (res != checkRev)
+ return 1;
+ }
// Test StringBuilder with default capacity (16)
StringBuilder sb2 = new StringBuilder();