Author: spouliot
Date: 2005-10-28 10:56:47 -0400 (Fri, 28 Oct 2005)
New Revision: 52327
Modified:
trunk/mcs/class/corlib/Test/System.Runtime.InteropServices/ChangeLog
trunk/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs
Log:
2005-10-28 Sebastien Pouliot <[EMAIL PROTECTED]>
* MarshalTest.cs: Added tests for 2.0 SecureTo* and ZeroFree* methods.
Modified: trunk/mcs/class/corlib/Test/System.Runtime.InteropServices/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Runtime.InteropServices/ChangeLog
2005-10-28 14:55:30 UTC (rev 52326)
+++ trunk/mcs/class/corlib/Test/System.Runtime.InteropServices/ChangeLog
2005-10-28 14:56:47 UTC (rev 52327)
@@ -1,3 +1,7 @@
+2005-10-28 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * MarshalTest.cs: Added tests for 2.0 SecureTo* and ZeroFree* methods.
+
2005-09-20 Gert Driesen <[EMAIL PROTECTED]>
* MarshalTest.cs: Added test for bug #76123.
Modified:
trunk/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs
2005-10-28 14:55:30 UTC (rev 52326)
+++ trunk/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs
2005-10-28 14:56:47 UTC (rev 52327)
@@ -3,13 +3,15 @@
//
// Authors:
// Gonzalo Paniagua Javier ([EMAIL PROTECTED])
+// Sebastien Pouliot <[EMAIL PROTECTED]>
//
-// (c) 2004 Novell, Inc. (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.Runtime.InteropServices;
+using System.Security;
namespace MonoTests.System.Runtime.InteropServices
{
@@ -150,6 +152,143 @@
s = Marshal.PtrToStringUni (handle);
Assert.AreEqual (19, s.Length, "#2");
}
+#if NET_2_0
+ private const string NotSupported = "Not supported before
Windows 2000 Service Pack 3";
+ private static char[] PlainText = new char[] { 'a', 'b', 'c' };
+ private static byte[] AsciiPlainText = new byte[] { (byte) 'a',
(byte) 'b', (byte) 'c' };
+
+ private unsafe SecureString GetSecureString ()
+ {
+ fixed (char* p = &PlainText[0]) {
+ return new SecureString (p, PlainText.Length);
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void SecureStringToBSTR_Null ()
+ {
+ Marshal.SecureStringToBSTR (null);
+ }
+
+ [Test]
+ public void SecureStringToBSTR ()
+ {
+ try {
+ SecureString ss = GetSecureString ();
+ IntPtr p = Marshal.SecureStringToBSTR (ss);
+
+ char[] decrypted = new char[ss.Length];
+ Marshal.Copy (p, decrypted, 0,
decrypted.Length);
+ Assert.AreEqual (PlainText, decrypted,
"Decrypted");
+
+ Marshal.ZeroFreeBSTR (p);
+ }
+ catch (NotSupportedException) {
+ Assert.Ignore (NotSupported);
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void SecureStringToCoTaskMemAnsi_Null ()
+ {
+ Marshal.SecureStringToCoTaskMemAnsi (null);
+ }
+
+ [Test]
+ public void SecureStringToCoTaskMemAnsi ()
+ {
+ try {
+ SecureString ss = GetSecureString ();
+ IntPtr p = Marshal.SecureStringToCoTaskMemAnsi
(ss);
+
+ byte[] decrypted = new byte[ss.Length];
+ Marshal.Copy (p, decrypted, 0,
decrypted.Length);
+ Assert.AreEqual (AsciiPlainText, decrypted,
"Decrypted");
+
+ Marshal.ZeroFreeCoTaskMemAnsi (p);
+ }
+ catch (NotSupportedException) {
+ Assert.Ignore (NotSupported);
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void SecureStringToCoTaskMemUnicode_Null ()
+ {
+ Marshal.SecureStringToCoTaskMemUnicode (null);
+ }
+
+ [Test]
+ public void SecureStringToCoTaskMemUnicode ()
+ {
+ try {
+ SecureString ss = GetSecureString ();
+ IntPtr p =
Marshal.SecureStringToCoTaskMemUnicode (ss);
+
+ char[] decrypted = new char[ss.Length];
+ Marshal.Copy (p, decrypted, 0,
decrypted.Length);
+ Assert.AreEqual (PlainText, decrypted,
"Decrypted");
+
+ Marshal.ZeroFreeCoTaskMemUnicode (p);
+ }
+ catch (NotSupportedException) {
+ Assert.Ignore (NotSupported);
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void SecureStringToGlobalAllocAnsi_Null ()
+ {
+ Marshal.SecureStringToGlobalAllocAnsi (null);
+ }
+
+ [Test]
+ public void SecureStringToGlobalAllocAnsi ()
+ {
+ try {
+ SecureString ss = GetSecureString ();
+ IntPtr p =
Marshal.SecureStringToGlobalAllocAnsi (ss);
+
+ byte[] decrypted = new byte[ss.Length];
+ Marshal.Copy (p, decrypted, 0,
decrypted.Length);
+ Assert.AreEqual (AsciiPlainText, decrypted,
"Decrypted");
+
+ Marshal.ZeroFreeGlobalAllocAnsi (p);
+ }
+ catch (NotSupportedException) {
+ Assert.Ignore (NotSupported);
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void SecureStringToGlobalAllocUnicode_Null ()
+ {
+ Marshal.SecureStringToGlobalAllocUnicode (null);
+ }
+
+ [Test]
+ public void SecureStringToGlobalAllocUnicode ()
+ {
+ try {
+ SecureString ss = GetSecureString ();
+ IntPtr p =
Marshal.SecureStringToGlobalAllocUnicode (ss);
+
+ char[] decrypted = new char[ss.Length];
+ Marshal.Copy (p, decrypted, 0,
decrypted.Length);
+ Assert.AreEqual (PlainText, decrypted,
"Decrypted");
+
+ Marshal.ZeroFreeGlobalAllocUnicode (p);
+ }
+ catch (NotSupportedException) {
+ Assert.Ignore (NotSupported);
+ }
+ }
+#endif
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches