Author: spouliot
Date: 2005-03-24 08:40:19 -0500 (Thu, 24 Mar 2005)
New Revision: 42208

Added:
   trunk/mcs/class/corlib/Test/System/ActivatorCas.cs
   trunk/mcs/class/corlib/Test/System/ConsoleCas.cs
   trunk/mcs/class/corlib/Test/System/MarshalByRefObjectCas.cs
   trunk/mcs/class/corlib/Test/System/RuntimeMethodHandleCas.cs
   trunk/mcs/class/corlib/Test/System/TypedReferenceCas.cs
Modified:
   trunk/mcs/class/corlib/Test/System/ChangeLog
   trunk/mcs/class/corlib/Test/System/EnvironmentCas.cs
   trunk/mcs/class/corlib/Test/System/ExceptionCas.cs
Log:
2005-03-24  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * ActivatorCas.cs: New. CAS unit tests for Activator.
        * ConsoleCas.cs: New. CAS unit tests for Console.
        * EnvironmentCas.cs: Added partial trust test cases.
        * ExceptionCas.cs: Added partial trust test cases.
        * MarshalByRefObjectCas.cs: New. CAS unit tests for MarshalByRefObject.
        * RuntimeMethodHandleCas.cs: New. CAS unit tests RuntimeMethodHandle.
        * TypedReferenceCas.cs: New. CAS unit tests for TypedReference.



Added: trunk/mcs/class/corlib/Test/System/ActivatorCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/ActivatorCas.cs  2005-03-24 13:33:17 UTC 
(rev 42207)
+++ trunk/mcs/class/corlib/Test/System/ActivatorCas.cs  2005-03-24 13:40:19 UTC 
(rev 42208)
@@ -0,0 +1,73 @@
+//
+// ActivatorCas.cs - CAS unit tests for System.Activator
+//
+// Author:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+
+using System;
+using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
+
+namespace MonoCasTests.System {
+
+       [TestFixture]
+       [Category ("CAS")]
+       public class ActivatorCas {
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       if (!SecurityManager.SecurityEnabled)
+                               Assert.Ignore ("SecurityManager.SecurityEnabled 
is OFF");
+               }
+
+               // we use reflection to call Activator as the GetObject methods 
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, RemotingConfiguration 
= true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void GetObject2 ()
+               {
+                       Type[] parameters = new Type [2] { typeof (Type), 
typeof (string) };
+                       MethodInfo mi = typeof (Activator).GetMethod 
("GetObject", parameters);
+                       Assert.IsNotNull (mi.Invoke (null, new object [2] { 
typeof (object), String.Empty }), "GetObject");
+               }
+
+               [Test]
+               [SecurityPermission (SecurityAction.Deny, RemotingConfiguration 
= true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void GetObject3 ()
+               {
+                       Type[] parameters = new Type [3] { typeof (Type), 
typeof (string), typeof (object) };
+                       MethodInfo mi = typeof (Activator).GetMethod 
("GetObject", parameters);
+                       Assert.IsNotNull (mi.Invoke (null, new object [3] { 
typeof (object), String.Empty, null }), "GetObject");
+               }
+       }
+}

Modified: trunk/mcs/class/corlib/Test/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System/ChangeLog        2005-03-24 13:33:17 UTC 
(rev 42207)
+++ trunk/mcs/class/corlib/Test/System/ChangeLog        2005-03-24 13:40:19 UTC 
(rev 42208)
@@ -1,3 +1,13 @@
+2005-03-24  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * ActivatorCas.cs: New. CAS unit tests for Activator.
+       * ConsoleCas.cs: New. CAS unit tests for Console.
+       * EnvironmentCas.cs: Added partial trust test cases.
+       * ExceptionCas.cs: Added partial trust test cases.
+       * MarshalByRefObjectCas.cs: New. CAS unit tests for MarshalByRefObject.
+       * RuntimeMethodHandleCas.cs: New. CAS unit tests RuntimeMethodHandle.
+       * TypedReferenceCas.cs: New. CAS unit tests for TypedReference.
+
 2005-03-15  Sebastien Pouliot  <[EMAIL PROTECTED]> 
 
        * BadImageFormatExceptionCas.cs: New. Permission tests for 

Added: trunk/mcs/class/corlib/Test/System/ConsoleCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/ConsoleCas.cs    2005-03-24 13:33:17 UTC 
(rev 42207)
+++ trunk/mcs/class/corlib/Test/System/ConsoleCas.cs    2005-03-24 13:40:19 UTC 
(rev 42208)
@@ -0,0 +1,140 @@
+//
+// ConsoleCas.cs - CAS unit tests for System.Console
+//
+// Author:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+
+using System;
+using System.IO;
+using System.Security;
+using System.Security.Permissions;
+
+namespace MonoCasTests.System {
+
+       [TestFixture]
+       [Category ("CAS")]
+       public class ConsoleCas {
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       if (!SecurityManager.SecurityEnabled)
+                               Assert.Ignore ("SecurityManager.SecurityEnabled 
is OFF");
+               }
+
+               // Partial Trust Tests - i.e. call "normal" unit with reduced 
privileges
+
+               [Test]
+               [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+               public void PartialTrust_DenyUnrestricted_Success ()
+               {
+                       MonoTests.System.ConsoleTest ct = new 
MonoTests.System.ConsoleTest ();
+                       // call most unit tests from ConsoleTest
+                       ct.TestError ();
+                       ct.TestIn ();
+                       ct.TestOut ();
+                       ct.TestOpenStandardError ();
+                       ct.TestOpenStandardInput ();
+                       ct.TestOpenStandardOutput ();
+               }
+
+               [Test]
+               [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = 
true)]
+               public void PartialTrust_PermitOnly_UnmanagedCode ()
+               {
+                       MonoTests.System.ConsoleTest ct = new 
MonoTests.System.ConsoleTest ();
+                       // call unit tests from ConsoleTest that requires 
UnmanagedCode to work
+                       ct.TestSetError ();
+                       ct.TestSetIn ();
+                       ct.TestSetOut ();
+                       ct.TestRead ();
+                       ct.TestReadLine ();
+                       ct.TestWrite ();
+                       ct.TestWriteLine ();
+               }
+
+               // Console is using restricted stuff (like opening FileStream 
+               // with handles) but isn't restricted itself - so we must 
+               // assert the required permission in Console
+
+               [Test]
+               [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+               public void OpenStandardError ()
+               {
+                       Stream s = Console.OpenStandardError ();
+                       Assert.IsNotNull (s, "1");
+                       s = Console.OpenStandardError (1024);
+                       Assert.IsNotNull (s, "2");
+               }
+
+               [Test]
+               [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+               public void OpenStandardInput ()
+               {
+                       Stream s = Console.OpenStandardInput ();
+                       Assert.IsNotNull (s, "1");
+                       s = Console.OpenStandardInput (1024);
+                       Assert.IsNotNull (s, "2");
+               }
+
+               [Test]
+               [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+               public void OpenStandardOutput ()
+               {
+                       Stream s = Console.OpenStandardOutput ();
+                       Assert.IsNotNull (s, "1");
+                       s = Console.OpenStandardOutput (1024);
+                       Assert.IsNotNull (s, "2");
+               }
+
+               // Unmanaged code is required to call Console.Set* methods
+
+               [Test]
+               [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void SetError ()
+               {
+                       Console.SetError (new StreamWriter 
(Console.OpenStandardError ()));
+               }
+
+               [Test]
+               [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void SetIn ()
+               {
+                       Console.SetIn (new StreamReader 
(Console.OpenStandardInput ()));
+               }
+
+               [Test]
+               [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void SetOut ()
+               {
+                       Console.SetOut (new StreamWriter 
(Console.OpenStandardOutput ()));
+               }
+       }
+}

Modified: trunk/mcs/class/corlib/Test/System/EnvironmentCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/EnvironmentCas.cs        2005-03-24 
13:33:17 UTC (rev 42207)
+++ trunk/mcs/class/corlib/Test/System/EnvironmentCas.cs        2005-03-24 
13:40:19 UTC (rev 42208)
@@ -47,8 +47,33 @@
                                Assert.Ignore ("SecurityManager.SecurityEnabled 
is OFF");
                }
 
+               // Partial Trust Tests - i.e. call "normal" unit with reduced 
privileges
 
                [Test]
+               [EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted 
= true)]
+               public void PartialTrust_PermitOnly_Environment ()
+               {
+                       MonoTests.System.EnvironmentTest et = new 
MonoTests.System.EnvironmentTest ();
+                       // call most (all but arguments checking) unit tests 
from EnvironmentTest
+                       et.ExpandEnvironmentVariables_UnknownVariable ();
+                       et.ExpandEnvironmentVariables_KnownVariable ();
+                       et.ExpandEnvironmentVariables_NotVariable ();
+                       et.ExpandEnvironmentVariables_Alone ();
+                       et.ExpandEnvironmentVariables_End ();
+                       et.ExpandEnvironmentVariables_None ();
+                       et.ExpandEnvironmentVariables_EmptyVariable ();
+                       et.ExpandEnvironmentVariables_Double ();
+                       et.ExpandEnvironmentVariables_ComplexExpandable ();
+                       
et.ExpandEnvironmentVariables_ExpandableAndNonExpandable ();
+                       
et.ExpandEnvironmentVariables_ExpandableWithTrailingPercent ();
+                       et.ExpandEnvironmentVariables_ComplexExpandable2 ();
+                       et.GetEnvironmentVariables ();
+                       et.GetCommandLineArgs ();
+               }               
+
+               // test Demand by denying it's caller from the required 
privileges
+
+               [Test]
                [EnvironmentPermission (SecurityAction.Deny, Read = "PATH")]
                [ExpectedException (typeof (SecurityException))]
                public void CommandLine ()
@@ -98,9 +123,23 @@
                }
 
                [Test]
-               [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
                public void CurrentDirectory_Set_FileIOPermission ()
                {
+                       // this test will change the current directory
+                       // and cause tests failures elsewhere...
+                       string cd = Environment.CurrentDirectory;
+                       try {
+                               
CurrentDirectory_Set_FileIOPermission_Restricted ();
+                       }
+                       finally {
+                               // ... unless we return to the original 
directory
+                               Environment.CurrentDirectory = cd;
+                       }
+               }
+
+               [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
+               private void CurrentDirectory_Set_FileIOPermission_Restricted ()
+               {
                        // now that the stack is set, call the method
 #if WINDOWS
                        Environment.CurrentDirectory = "C:\\";

Modified: trunk/mcs/class/corlib/Test/System/ExceptionCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/ExceptionCas.cs  2005-03-24 13:33:17 UTC 
(rev 42207)
+++ trunk/mcs/class/corlib/Test/System/ExceptionCas.cs  2005-03-24 13:40:19 UTC 
(rev 42208)
@@ -45,8 +45,21 @@
                                Assert.Ignore ("SecurityManager.SecurityEnabled 
is OFF");
                }
 
+               // Partial Trust Tests - i.e. call "normal" unit with reduced 
privileges
 
                [Test]
+               [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+               public void PartialTrust_DenyUnrestricted_Success ()
+               {
+                       MonoTests.System.ExceptionTest et = new 
MonoTests.System.ExceptionTest ();
+                       // call most (all but arguments checking) unit tests 
from ExceptionTest
+                       et.TestThrowOnBlockBoundaries ();
+                       et.InnerExceptionSource ();
+               }
+
+               // CAS tests
+
+               [Test]
                public void NoRestriction ()
                {
                        Exception e = new Exception ("message", new Exception 
("inner message"));

Added: trunk/mcs/class/corlib/Test/System/MarshalByRefObjectCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/MarshalByRefObjectCas.cs 2005-03-24 
13:33:17 UTC (rev 42207)
+++ trunk/mcs/class/corlib/Test/System/MarshalByRefObjectCas.cs 2005-03-24 
13:40:19 UTC (rev 42208)
@@ -0,0 +1,99 @@
+//
+// MarshalByRefObjectCas.cs - CAS unit tests for System.MarshalByRefObject
+//
+// Author:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+
+using System;
+using System.IO;
+using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
+
+namespace MonoCasTests.System {
+
+       [TestFixture]
+       [Category ("CAS")]
+       public class MarshalByRefObjectCas {
+
+               private MarshalByRefObject mbro;
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       if (!SecurityManager.SecurityEnabled)
+                               Assert.Ignore ("SecurityManager.SecurityEnabled 
is OFF");
+
+                       // we do this in SetUp because we want the security 
+                       // stack to be "normal/empty" so each unit test can 
+                       // mess with it as it wishes
+                       mbro = (MarshalByRefObject) AppDomain.CurrentDomain;
+               }
+
+               // we use reflection to call the AppDomain (who inherits from 
MarshalByRefObject)
+               // as it's methods 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, Infrastructure = 
true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void CreateObjRef ()
+               {
+                       MethodInfo mi = typeof (AppDomain).GetMethod 
("CreateObjRef");
+                       Assert.IsNotNull (mi.Invoke (mbro, new object [1] { 
typeof (int) }), "CreateObjRef");
+               }
+
+               [Test]
+               [SecurityPermission (SecurityAction.Deny, Infrastructure = 
true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void GetLifetimeService ()
+               {
+
+                       MethodInfo mi = typeof (AppDomain).GetMethod 
("GetLifetimeService");
+                       Assert.IsNotNull (mi.Invoke (mbro, null), 
"GetLifetimeService");
+               }
+
+               [Test]
+               [SecurityPermission (SecurityAction.Deny, Infrastructure = 
true)]
+               public void AppDomain_InitializeLifetimeService ()
+               {
+                       // special case - AppDomain doesn't call 
base.InitializeLifetimeService
+                       // so there is no link, nor the stack required, to 
initiate the Demand
+                       MethodInfo mi = typeof (AppDomain).GetMethod 
("InitializeLifetimeService");
+                       Assert.IsNull (mi.Invoke (mbro, null), 
"InitializeLifetimeService");
+               }
+
+               [Test]
+               [SecurityPermission (SecurityAction.Deny, Infrastructure = 
true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void Stream_InitializeLifetimeService ()
+               {
+                       MethodInfo mi = typeof (Stream).GetMethod 
("InitializeLifetimeService");
+                       Assert.IsNull (mi.Invoke (Stream.Null, null), 
"InitializeLifetimeService");
+               }
+       }
+}

Added: trunk/mcs/class/corlib/Test/System/RuntimeMethodHandleCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/RuntimeMethodHandleCas.cs        
2005-03-24 13:33:17 UTC (rev 42207)
+++ trunk/mcs/class/corlib/Test/System/RuntimeMethodHandleCas.cs        
2005-03-24 13:40:19 UTC (rev 42208)
@@ -0,0 +1,63 @@
+//
+// RuntimeMethodHandleCas.cs - CAS unit tests for System.RuntimeMethodHandle
+//
+// Author:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+
+using System;
+using System.Security;
+using System.Security.Permissions;
+
+namespace MonoCasTests.System {
+
+       [TestFixture]
+       [Category ("CAS")]
+       public class RuntimeMethodHandleCas {
+
+               private RuntimeMethodHandle handle;
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       if (!SecurityManager.SecurityEnabled)
+                               Assert.Ignore ("SecurityManager.SecurityEnabled 
is OFF");
+
+                       // we do this in SetUp because we want the security 
+                       // stack to be "normal/empty" so each unit test can 
+                       // mess with it as it wishes
+                       handle = typeof (RuntimeMethodHandleCas).GetMethod 
("SetUp").MethodHandle;
+               }
+
+               [Test]
+               [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void GetFunctionPointer ()
+               {
+                       Assert.AreEqual (IntPtr.Zero, handle.GetFunctionPointer 
(), "GetFunctionPointer");
+               }
+       }
+}

Added: trunk/mcs/class/corlib/Test/System/TypedReferenceCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/TypedReferenceCas.cs     2005-03-24 
13:33:17 UTC (rev 42207)
+++ trunk/mcs/class/corlib/Test/System/TypedReferenceCas.cs     2005-03-24 
13:40:19 UTC (rev 42208)
@@ -0,0 +1,62 @@
+//
+// TypedReferenceCas.cs - CAS unit tests for System.TypedReference
+//
+// Author:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+
+using System;
+using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
+
+namespace MonoCasTests.System {
+
+       [TestFixture]
+       [Category ("CAS")]
+       public class TypedReferenceCas {
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       if (!SecurityManager.SecurityEnabled)
+                               Assert.Ignore ("SecurityManager.SecurityEnabled 
is OFF");
+               }
+
+               // we use reflection to call TypeReference as the method is 
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]
+               [ReflectionPermission (SecurityAction.Deny, MemberAccess = 
true)]
+               [ExpectedException (typeof (SecurityException))]
+               public void MakeTypedReference ()
+               {
+                       MethodInfo mi = typeof (TypedReference).GetMethod 
("MakeTypedReference", BindingFlags.Static | BindingFlags.Public);
+                       Assert.IsNotNull (mi.Invoke (null, new object [2] { 
null, new FieldInfo [0] }), "MakeTypedReference");
+               }
+       }
+}

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

Reply via email to