Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
2005-10-17 Sebastien Pouliot <sebastien@ximian.com>
* IntranetZoneCredentialPolicyCas.cs: New. CAS unit tests.
* IntranetZoneCredentialPolicyTest.cs: New. Unit tests.
2005-10-17 Sebastien Pouliot <sebastien@ximian.com>
* PowerModeChangedEventArgsCas.cs: New. CAS unit tests.
* SessionEndedEventArgsCas.cs: New. CAS unit tests.
* SessionEndingEventArgsCas.cs: New. CAS unit tests.
* SessionSwitchEventArgsCas.cs: New. CAS unit tests.
* SystemEventsCas.cs: New. CAS unit tests.
* TimerElapsedEventArgsCas.cs: New. CAS unit tests.
* UserPreferenceChangedEventArgsCas.cs: New. CAS unit tests.
* UserPreferenceChangingEventArgsCas.cs: New. CAS unit tests.

View File

@@ -0,0 +1,117 @@
//
// IntranetZoneCredentialPolicyCas.cs
// - CAS unit tests for Microsoft.Win32.IntranetZoneCredentialPolicy
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using Microsoft.Win32;
using MonoTests.Microsoft.Win32;
namespace MonoCasTests.Microsoft.Win32 {
[TestFixture]
[Category ("CAS")]
public class IntranetZoneCredentialPolicyCas {
private IntranetZoneCredentialPolicyTest unit;
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
// execute IntranetZoneCredentialPolicy ctor at fulltrust
unit = new IntranetZoneCredentialPolicyTest ();
unit.FixtureSetUp ();
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void Constructor_Deny_ControlPolicy ()
{
new IntranetZoneCredentialPolicy ();
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlPolicy = true)]
public void Constructor_PermitOnly_ControlPolicy ()
{
new IntranetZoneCredentialPolicy ();
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
public void UnitTestReuse ()
{
unit.NullRequest ();
unit.NullCredential ();
unit.NullModule ();
unit.Localhost ();
unit.LocalhostWithoutWebRequest ();
unit.LocalhostWithoutCredentials ();
unit.LocalhostWithoutModule ();
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_ControlPolicy ()
{
ConstructorInfo ci = typeof (IntranetZoneCredentialPolicy).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor");
try {
ci.Invoke (null);
}
catch (TargetInvocationException tie) {
// same as directly calling the ctor
throw tie.InnerException;
}
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlPolicy = true)]
public void LinkDemand_PermitOnly_ControlPolicy ()
{
ConstructorInfo ci = typeof (IntranetZoneCredentialPolicy).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,164 @@
//
// IntranetZoneCredentialPolicyTest.cs
// - Unit tests for Microsoft.Win32.IntranetZoneCredentialPolicy
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Net;
using Microsoft.Win32;
namespace MonoTests.Microsoft.Win32 {
public class Module: IAuthenticationModule {
private string type;
private bool pre_auth;
private string token;
public Module (string type, bool preAuth, string token)
{
this.type = type;
pre_auth = preAuth;
this.token = token;
}
public Authorization Authenticate (string challenge, WebRequest request, ICredentials credentials)
{
return new Authorization (token);
}
public string AuthenticationType {
get { return type; }
}
public bool CanPreAuthenticate {
get { return pre_auth; }
}
public Authorization PreAuthenticate (WebRequest request, ICredentials credentials)
{
return new Authorization (token);
}
}
[TestFixture]
public class IntranetZoneCredentialPolicyTest {
private IntranetZoneCredentialPolicy policy;
private Uri uri;
private WebRequest request;
private NetworkCredential credential;
private IAuthenticationModule module;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
policy = new IntranetZoneCredentialPolicy ();
uri = new Uri ("http://www.mono-project.com");
request = WebRequest.Create (uri);
credential = new NetworkCredential ("me", "mine");
module = new Module ("type", true, "token");
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void NullUri ()
{
policy.ShouldSendCredential (null, request, credential, module);
}
[Test]
public void NullRequest ()
{
Assert.IsFalse (policy.ShouldSendCredential (uri, null, credential, module));
}
[Test]
public void NullCredential ()
{
Assert.IsFalse (policy.ShouldSendCredential (uri, request, null, module));
}
[Test]
public void NullModule ()
{
Assert.IsFalse (policy.ShouldSendCredential (uri, request, credential, null));
}
[Test]
public void Localhost ()
{
Uri localhost = new Uri ("http://localhost/");
WebRequest wr = WebRequest.Create (uri);
Assert.IsTrue (policy.ShouldSendCredential (localhost, wr, credential, module), "localhost");
localhost = new Uri ("http://127.0.0.1");
wr = WebRequest.Create (uri);
Assert.IsFalse (policy.ShouldSendCredential (localhost, wr, credential, module), "127.0.0.1");
}
[Test]
public void LocalhostWithoutWebRequest ()
{
Uri localhost = new Uri ("http://localhost/");
Assert.IsTrue (policy.ShouldSendCredential (localhost, null, credential, module), "localhost");
localhost = new Uri ("http://127.0.0.1");
Assert.IsFalse (policy.ShouldSendCredential (localhost, null, credential, module), "127.0.0.1");
}
[Test]
public void LocalhostWithoutCredentials ()
{
Uri localhost = new Uri ("http://localhost/");
WebRequest wr = WebRequest.Create (uri);
Assert.IsTrue (policy.ShouldSendCredential (localhost, wr, null, module), "localhost");
localhost = new Uri ("http://127.0.0.1");
wr = WebRequest.Create (uri);
Assert.IsFalse (policy.ShouldSendCredential (localhost, wr, null, module), "127.0.0.1");
}
[Test]
public void LocalhostWithoutModule ()
{
Uri localhost = new Uri ("http://localhost/");
WebRequest wr = WebRequest.Create (uri);
Assert.IsTrue (policy.ShouldSendCredential (localhost, wr, credential, null), "localhost");
localhost = new Uri ("http://127.0.0.1");
wr = WebRequest.Create (uri);
Assert.IsFalse (policy.ShouldSendCredential (localhost, wr, credential, null), "127.0.0.1");
}
}
}
#endif

View File

@@ -0,0 +1,97 @@
//
// PowerModeChangedEventArgsCas.cs
// - CAS unit tests for Microsoft.Win32.PowerModeChangedEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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;
using Microsoft.Win32;
namespace MonoCasTests.Microsoft.Win32 {
[TestFixture]
[Category ("CAS")]
public class PowerModeChangedEventArgsCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
PowerModeChangedEventArgs pmcea = new PowerModeChangedEventArgs (PowerModes.StatusChange);
Assert.AreEqual (PowerModes.StatusChange, pmcea.Mode, "Mode");
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
Type[] t = new Type[1] { typeof (PowerModes) };
ConstructorInfo ci = typeof (PowerModeChangedEventArgs).GetConstructor (t);
Assert.IsNotNull (ci, ".ctor(PowerModes)");
return ci.Invoke (new object[1] { PowerModes.StatusChange });
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}

View File

@@ -0,0 +1,97 @@
//
// SessionEndedEventArgsCas.cs
// - CAS unit tests for Microsoft.Win32.SessionEndedEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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;
using Microsoft.Win32;
namespace MonoCasTests.Microsoft.Win32 {
[TestFixture]
[Category ("CAS")]
public class SessionEndedEventArgsCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
SessionEndedEventArgs seea = new SessionEndedEventArgs (SessionEndReasons.SystemShutdown);
Assert.AreEqual (SessionEndReasons.SystemShutdown, seea.Reason, "Reason");
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
Type[] t = new Type[1] { typeof (SessionEndReasons) };
ConstructorInfo ci = typeof (SessionEndedEventArgs).GetConstructor (t);
Assert.IsNotNull (ci, ".ctor(SessionEndReasons)");
return ci.Invoke (new object[1] { SessionEndReasons.SystemShutdown });
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}

View File

@@ -0,0 +1,100 @@
//
// SessionEndingEventArgsCas.cs
// - CAS unit tests for Microsoft.Win32.SessionEndingEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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;
using Microsoft.Win32;
namespace MonoCasTests.Microsoft.Win32 {
[TestFixture]
[Category ("CAS")]
public class SessionEndingEventArgsCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
SessionEndingEventArgs seea = new SessionEndingEventArgs (SessionEndReasons.SystemShutdown);
Assert.AreEqual (SessionEndReasons.SystemShutdown, seea.Reason, "Reason");
Assert.IsFalse (seea.Cancel, "Cancel-false");
seea.Cancel = true;
Assert.IsTrue (seea.Cancel, "Cancel-true");
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
Type[] t = new Type[1] { typeof (SessionEndReasons) };
ConstructorInfo ci = typeof (SessionEndingEventArgs).GetConstructor (t);
Assert.IsNotNull (ci, ".ctor(SessionEndReasons)");
return ci.Invoke (new object[1] { SessionEndReasons.SystemShutdown });
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}

View File

@@ -0,0 +1,101 @@
//
// SessionSwitchEventArgsCas.cs
// - CAS unit tests for Microsoft.Win32.SessionSwitchEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using Microsoft.Win32;
namespace MonoCasTests.Microsoft.Win32 {
[TestFixture]
[Category ("CAS")]
public class SessionSwitchEventArgsCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
SessionSwitchEventArgs swea = new SessionSwitchEventArgs (SessionSwitchReason.SessionLock);
Assert.AreEqual (SessionSwitchReason.SessionLock, swea.Reason, "Reason");
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
Type[] t = new Type[1] { typeof (SessionSwitchReason) };
ConstructorInfo ci = typeof (SessionSwitchEventArgs).GetConstructor (t);
Assert.IsNotNull (ci, ".ctor(SessionSwitchReason)");
return ci.Invoke (new object[1] { SessionSwitchReason.SessionLock });
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}
#endif

View File

@@ -0,0 +1,63 @@
//
// SessionSwitchEventArgsTest.cs
// - Unit tests for Microsoft.Win32.SessionSwitchEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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.
//
#if NET_2_0
using NUnit.Framework;
using System;
using Microsoft.Win32;
namespace MonoTests.Microsoft.Win32 {
[TestFixture]
[Category ("CAS")]
public class SessionSwitchEventArgsTest {
[Test]
public void Constructor ()
{
foreach (SessionSwitchReason ssr in Enum.GetValues (typeof (SessionSwitchReason))) {
SessionSwitchEventArgs ssea = new SessionSwitchEventArgs (ssr);
Assert.AreEqual (ssr, ssea.Reason, ssr.ToString ());
}
}
[Test]
public void OutOfRange ()
{
SessionSwitchReason ssr = (SessionSwitchReason) Int32.MinValue;
SessionSwitchEventArgs ssea = new SessionSwitchEventArgs (ssr);
Assert.AreEqual (ssr, ssea.Reason, "Int32.MinValue");
// no validation is done on the enum value used
}
}
}
#endif

View File

@@ -0,0 +1,310 @@
//
// SystemEventsCas.cs - CAS unit tests for Microsoft.Win32.SystemEvents
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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;
using Microsoft.Win32;
namespace MonoCasTests.Microsoft.Win32 {
[TestFixture]
[Category ("CAS")]
public class SystemEventsCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
private void TimerCallback (object o, TimerElapsedEventArgs args)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Methods_Deny_Unrestricted ()
{
IntPtr timer = SystemEvents.CreateTimer (5000);
SystemEvents.KillTimer (timer);
try {
SystemEvents.InvokeOnEventsThread (new TimerElapsedEventHandler (TimerCallback));
}
catch (NotImplementedException) {
// mono
}
}
private void EventCallback (object o, EventArgs args)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void DisplaySettingsChanged_Deny_Unrestricted ()
{
try {
SystemEvents.DisplaySettingsChanged += new EventHandler (EventCallback);
SystemEvents.DisplaySettingsChanged -= new EventHandler (EventCallback);
}
catch (NotImplementedException) {
// mono
}
}
#if NET_2_0
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void DisplaySettingsChanging_Deny_Unrestricted ()
{
try {
SystemEvents.DisplaySettingsChanging += new EventHandler (EventCallback);
SystemEvents.DisplaySettingsChanging -= new EventHandler (EventCallback);
}
catch (NotImplementedException) {
// mono
}
}
#endif
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void EventsThreadShutdown_Deny_Unrestricted ()
{
try {
SystemEvents.EventsThreadShutdown += new EventHandler (EventCallback);
SystemEvents.EventsThreadShutdown -= new EventHandler (EventCallback);
}
catch (NotImplementedException) {
// mono
}
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void InstalledFontsChanged_Deny_Unrestricted ()
{
try {
SystemEvents.InstalledFontsChanged += new EventHandler (EventCallback);
SystemEvents.InstalledFontsChanged -= new EventHandler (EventCallback);
}
catch (NotImplementedException) {
// mono
}
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LowMemory_Deny_Unrestricted ()
{
try {
SystemEvents.LowMemory += new EventHandler (EventCallback);
SystemEvents.LowMemory -= new EventHandler (EventCallback);
}
catch (NotImplementedException) {
// mono
}
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void PaletteChanged_Deny_Unrestricted ()
{
try {
SystemEvents.PaletteChanged += new EventHandler (EventCallback);
SystemEvents.PaletteChanged -= new EventHandler (EventCallback);
}
catch (NotImplementedException) {
// mono
}
}
private void PowerModeChangedCallback (object o, PowerModeChangedEventArgs args)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void PowerModeChanged_Deny_Unrestricted ()
{
try {
SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler (PowerModeChangedCallback);
SystemEvents.PowerModeChanged -= new PowerModeChangedEventHandler (PowerModeChangedCallback);
}
catch (NotImplementedException) {
// mono
}
}
private void SessionEndedCallback (object o, SessionEndedEventArgs args)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SessionEnded_Deny_Unrestricted ()
{
try {
SystemEvents.SessionEnded += new SessionEndedEventHandler (SessionEndedCallback);
SystemEvents.SessionEnded -= new SessionEndedEventHandler (SessionEndedCallback);
}
catch (NotImplementedException) {
// mono
}
}
private void SessionEndingCallback (object o, SessionEndingEventArgs args)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SessionEnding_Deny_Unrestricted ()
{
try {
SystemEvents.SessionEnding += new SessionEndingEventHandler (SessionEndingCallback);
SystemEvents.SessionEnding -= new SessionEndingEventHandler (SessionEndingCallback);
}
catch (NotImplementedException) {
// mono
}
}
#if NET_2_0
private void SessionSwitchCallback (object o, SessionSwitchEventArgs args)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SessionSwitch_Deny_Unrestricted ()
{
try {
SystemEvents.SessionSwitch += new SessionSwitchEventHandler (SessionSwitchCallback);
SystemEvents.SessionSwitch -= new SessionSwitchEventHandler (SessionSwitchCallback);
}
catch (NotImplementedException) {
// mono
}
}
#endif
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void TimeChanged_Deny_Unrestricted ()
{
try {
SystemEvents.TimeChanged += new EventHandler (EventCallback);
SystemEvents.TimeChanged -= new EventHandler (EventCallback);
}
catch (NotImplementedException) {
// mono
}
}
private void TimerElapsedCallback (object o, TimerElapsedEventArgs args)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void TimerElapsed_Deny_Unrestricted ()
{
SystemEvents.TimerElapsed += new TimerElapsedEventHandler (TimerElapsedCallback);
SystemEvents.TimerElapsed -= new TimerElapsedEventHandler (TimerElapsedCallback);
}
private void UserPreferenceChangedCallback (object o, UserPreferenceChangedEventArgs args)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void UserPreferenceChanged_Deny_Unrestricted ()
{
SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler (UserPreferenceChangedCallback);
SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler (UserPreferenceChangedCallback);
}
private void UserPreferenceChangingCallback (object o, UserPreferenceChangingEventArgs args)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void UserPreferenceChanging_Deny_Unrestricted ()
{
try {
SystemEvents.UserPreferenceChanging += new UserPreferenceChangingEventHandler (UserPreferenceChangingCallback);
SystemEvents.UserPreferenceChanging -= new UserPreferenceChangingEventHandler (UserPreferenceChangingCallback);
}
catch (NotImplementedException) {
// mono
}
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
MethodInfo mi = typeof (SystemEvents).GetMethod ("CreateTimer");
Assert.IsNotNull (mi, "CreateTimer");
return mi.Invoke (null, new object[1] { 5000 });
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}

View File

@@ -0,0 +1,97 @@
//
// TimerElapsedEventArgsCas.cs
// - CAS unit tests for Microsoft.Win32.TimerElapsedEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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;
using Microsoft.Win32;
namespace MonoCasTests.Microsoft.Win32 {
[TestFixture]
[Category ("CAS")]
public class TimerElapsedEventArgsCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
TimerElapsedEventArgs teea = new TimerElapsedEventArgs (IntPtr.Zero);
Assert.AreEqual (IntPtr.Zero, teea.TimerId, "TimerId");
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
Type[] t = new Type[1] { typeof (IntPtr) };
ConstructorInfo ci = typeof (TimerElapsedEventArgs).GetConstructor (t);
Assert.IsNotNull (ci, ".ctor(IntPtr)");
return ci.Invoke (new object[1] { IntPtr.Zero });
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}

View File

@@ -0,0 +1,97 @@
//
// UserPreferenceChangedEventArgsCas.cs
// - CAS unit tests for Microsoft.Win32.UserPreferenceChangedEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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;
using Microsoft.Win32;
namespace MonoCasTests.Microsoft.Win32 {
[TestFixture]
[Category ("CAS")]
public class UserPreferenceChangedEventArgsCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
UserPreferenceChangedEventArgs upcea = new UserPreferenceChangedEventArgs (UserPreferenceCategory.Color);
Assert.AreEqual (UserPreferenceCategory.Color, upcea.Category, "Category");
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
Type[] t = new Type[1] { typeof (UserPreferenceCategory) };
ConstructorInfo ci = typeof (UserPreferenceChangedEventArgs).GetConstructor (t);
Assert.IsNotNull (ci, ".ctor(UserPreferenceCategory)");
return ci.Invoke (new object[1] { UserPreferenceCategory.Color });
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}

View File

@@ -0,0 +1,97 @@
//
// UserPreferenceChangingEventArgsCas.cs
// - CAS unit tests for Microsoft.Win32.UserPreferenceChangingEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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;
using Microsoft.Win32;
namespace MonoCasTests.Microsoft.Win32 {
[TestFixture]
[Category ("CAS")]
public class UserPreferenceChangingEventArgsCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
UserPreferenceChangingEventArgs upcea = new UserPreferenceChangingEventArgs (UserPreferenceCategory.Color);
Assert.AreEqual (UserPreferenceCategory.Color, upcea.Category, "Category");
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
Type[] t = new Type[1] { typeof (UserPreferenceCategory) };
ConstructorInfo ci = typeof (UserPreferenceChangingEventArgs).GetConstructor (t);
Assert.IsNotNull (ci, ".ctor(UserPreferenceCategory)");
return ci.Invoke (new object[1] { UserPreferenceCategory.Color });
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}