Author: zoltan
Date: 2006-06-28 13:09:54 -0400 (Wed, 28 Jun 2006)
New Revision: 62120

Modified:
   trunk/mono/mono/tests/ChangeLog
   trunk/mono/mono/tests/marshal2.cs
Log:
2006-06-28  Zoltan Varga  <[EMAIL PROTECTED]>

        * marshal2.cs: Add tests for ByValTStr + Unicode encoding.


Modified: trunk/mono/mono/tests/ChangeLog
===================================================================
--- trunk/mono/mono/tests/ChangeLog     2006-06-28 17:00:43 UTC (rev 62119)
+++ trunk/mono/mono/tests/ChangeLog     2006-06-28 17:09:54 UTC (rev 62120)
@@ -1,3 +1,15 @@
+2006-06-28  Zoltan Varga  <[EMAIL PROTECTED]>
+
+       * marshal2.cs: Add tests for ByValTStr + Unicode encoding.
+
+2006-06-15  Zoltan Varga  <[EMAIL PROTECTED]>
+
+       * pinvoke-2.cs: Rename to pinvoke-2.2.cs.
+       
+       * Makefile.am (TEST_CS2_SRC): Add pinvoke-2.2.cs
+
+       * pinvoke-2.2.cs libtest.c: Add Marshal.GetDelegateForFunctionPointer 
() tests.
+       
 2006-06-22  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * Makefile.am: Add 'cas' to SUBDIRS

Modified: trunk/mono/mono/tests/marshal2.cs
===================================================================
--- trunk/mono/mono/tests/marshal2.cs   2006-06-28 17:00:43 UTC (rev 62119)
+++ trunk/mono/mono/tests/marshal2.cs   2006-06-28 17:09:54 UTC (rev 62120)
@@ -36,12 +36,17 @@
                public double x;
                [MarshalAs (UnmanagedType.ByValArray, SizeConst=2)] public 
char[] a2;
        }
+
+       [StructLayout (LayoutKind.Sequential, CharSet=CharSet.Unicode)]
+       public struct ByValWStrStruct {
+               [MarshalAs (UnmanagedType.ByValTStr, SizeConst=4)] public 
string s1;
+               public int i;
+       }
        
        public unsafe static int Main () {
                SimpleStruct ss = new SimpleStruct ();
                int size = Marshal.SizeOf (typeof (SimpleStruct));
                
-               Console.WriteLine ("SimpleStruct:" + size);
                //if (size != 52)
                //return 1;
                
@@ -148,7 +153,32 @@
 
                if (cp.a2 [1] != 'b')
                        return 30;
-               
+
+               /* ByValTStr with Unicode */
+               ByValWStrStruct s = new ByValWStrStruct ();
+
+               IntPtr p2 = Marshal.AllocHGlobal (Marshal.SizeOf (typeof 
(ByValWStrStruct)));
+               Marshal.StructureToPtr(s, p2, false);
+
+               /* Check that the ByValWStr is initialized correctly */
+               for (int i = 0; i < 8; ++i)
+                       if (Marshal.ReadByte (p2, i) != 0)
+                               return 31;
+
+               s.s1 = "ABCD";
+               s.i = 55;
+
+               Marshal.StructureToPtr(s, p2, false);
+
+               ByValWStrStruct s2 = (ByValWStrStruct)Marshal.PtrToStructure 
(p2, typeof (ByValWStrStruct));
+
+               /* The fourth char is lost because of null-termination */
+               if (s2.s1 != "ABC")
+                       return 32;
+
+               if (s2.i != 55)
+                       return 33;
+
                return 0;
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to