Browse files

2006-05-17 Zoltan Varga <vargaz@gmail.com>

	* marshal8.cs: Applied a patch from Jonathan Chambers to add a test case to
	#77523.

svn path=/trunk/mono/; revision=60790
  • Loading branch information...
1 parent 1f91adb commit f7f517e7003d6e8c127907c3bd9288d164fcfe08 @vargaz vargaz committed May 17, 2006
Showing with 55 additions and 0 deletions.
  1. +5 −0 mono/tests/ChangeLog
  2. +50 −0 mono/tests/marshal8.cs
View
5 mono/tests/ChangeLog
@@ -1,3 +1,8 @@
+2006-05-17 Zoltan Varga <vargaz@gmail.com>
+
+ * marshal8.cs: Applied a patch from Jonathan Chambers to add a test case to
+ #77523.
+
2006-05-10 Atsushi Enomoto <atsushi@ximian.com>
* test-enum-indstoreil.il : removed duplicate label.
View
50 mono/tests/marshal8.cs
@@ -14,6 +14,28 @@ public class Dummy {
public long[] c;
}
+[StructLayout(LayoutKind.Sequential)]
+class FormattedClass
+{
+ public int i;
+
+ public FormattedClass(int i)
+ {
+ this.i = i;
+ }
+}
+
+[StructLayout(LayoutKind.Sequential)]
+struct Struct
+{
+ public int i;
+
+ public Struct(int i)
+ {
+ this.i = i;
+ }
+}
+
public class X {
public static unsafe int Main () {
@@ -70,6 +92,34 @@ public class X {
Marshal.FreeHGlobal(p);
+
+ ///
+ /// Only allow
+ ///
+ FormattedClass fc = new FormattedClass(20);
+ IntPtr fc_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FormattedClass)));
+ Marshal.StructureToPtr(fc, fc_ptr, false);
+ Marshal.PtrToStructure(fc_ptr, fc);
+ if (fc.i != 20)
+ return 10;
+ Marshal.FreeHGlobal(fc_ptr);
+
+ bool exception = false;
+ try
+ {
+ object str = new Struct(20);
+ IntPtr str_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Struct)));
+ Marshal.StructureToPtr(str, str_ptr, false);
+ Marshal.PtrToStructure(str_ptr, str);
+ Marshal.FreeHGlobal(str_ptr);
+ }
+ catch (Exception ex)
+ {
+ exception = true;
+ }
+ if (!exception)
+ return 11;
+
return 0;
}
}

0 comments on commit f7f517e

Please sign in to comment.