2005-03-24 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 24 Mar 2005 20:53:40 +0000 (20:53 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 24 Mar 2005 20:53:40 +0000 (20:53 -0000)
* IsolatedStorageFileStreamCas.cs: Added reflection-based unit tests
to test LinkDemand on Handle and SafeFileHandle (2.0) properties.

svn path=/trunk/mcs/; revision=42239

mcs/class/corlib/Test/System.IO.IsolatedStorage/ChangeLog
mcs/class/corlib/Test/System.IO.IsolatedStorage/IsolatedStorageFileStreamCas.cs

index 2da145c10ead7b6c30380c9ab4abb18e3af0c15b..01da3a00b48ae214a0abcc841a340ff590bd7558 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-24  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * IsolatedStorageFileStreamCas.cs: Added reflection-based unit tests 
+       to test LinkDemand on Handle and SafeFileHandle (2.0) properties.
+
 2005-03-15  Sebastien Pouliot  <sebastien@ximian.com>
 
        * IsolatedStorageFileStreamCas.cs: New. CAS unit tests for 
index d782ef713e9a146015a0b8d606cfa3a349dc3236..8be0d41a601acb6dd59624412ea0062be971c81b 100644 (file)
@@ -32,6 +32,7 @@ using NUnit.Framework;
 using System;
 using System.IO;
 using System.IO.IsolatedStorage;
+using System.Reflection;
 using System.Security;
 using System.Security.Permissions;
 
@@ -208,7 +209,7 @@ namespace MonoCasTests.System.IO.IsolatedStorage {
                {
                        IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-Handle", FileMode.Create);
                        IntPtr p = isfs.Handle;
-                       // LAMSPEC: SecurityException with UnmanagedCode
+                       // Note: The SecurityException for UnmanagedCode cannot be tested here because it's a LinkDemand
                }
 #if NET_2_0
                [Test]
@@ -218,6 +219,42 @@ namespace MonoCasTests.System.IO.IsolatedStorage {
                {
                        IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-SafeFileHandle", FileMode.Create);
                        SafeFileHandle sfh = isfs.SafeFileHandle;
+                       // Note: The SecurityException for UnmanagedCode cannot be tested here because it's a LinkDemand
+               }
+#endif
+
+               // we use reflection to call IsolatedStorageFileStream as the Handle and SafeFileHandle
+               // properties are protected by LinkDemand (which will be converted into full demand, 
+               // i.e. a stack walk) when reflection is used (i.e. it gets testable).
+
+               [Test]
+               [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void Handle_UnmanagedCode ()
+               {
+                       IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-Handle-Unmanaged", FileMode.Create);
+                       try {
+                               MethodInfo mi = typeof (IsolatedStorageFileStream).GetProperty ("Handle").GetGetMethod ();
+                               mi.Invoke (isfs, null);
+                       }
+                       finally {
+                               isfs.Close ();
+                       }
+               }
+#if NET_2_0
+               [Test]
+               [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void SafeFileHandle_UnmanagedCode ()
+               {
+                       IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-SafeFileHandle-Unmanaged", FileMode.Create);
+                       try {
+                               MethodInfo mi = typeof (IsolatedStorageFileStream).GetProperty ("SafeFileHandle").GetGetMethod ();
+                               mi.Invoke (isfs, null);
+                       }
+                       finally {
+                               isfs.Close ();
+                       }
                }
 #endif
        }