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,111 @@
2009-10-15 Sebastien Pouliot <sebastien@ximian.com>
* GCHandleTest.cs: Add more test cases for validations
2009-08-13 Zoltan Varga <vargaz@gmail.com>
* GCHandleTest.cs: Add a test for null GC handles with type
WeakTrackResurrection.
2009-06-20 Zoltan Varga <vargaz@gmail.com>
* *.cs: Convert all tests to new-style nunit classes/methods.
2009-04-30 Sebastien Pouliot <sebastien@ximian.com>
* MarshalTest.cs: Fix building unit tests for NET_1_1
2009-04-29 Jonathan Chambers <joncham@gmail.com>
* MarshalTest.cs: Add test for GetExceptionForHR.
2008-06-21 Gert Driesen <drieseng@users.sourceforge.net>
* MarshalTest.cs: Added tests for GetHINSTANCE. Improved existing
tests, and removed use of ExpectedException. Use more meaningful names
for test methods. Minor code formatting.
2007-12-29 Gert Driesen <drieseng@users.sourceforge.net>
* ExternalExceptionTest.cs: Improved ctor test.
2007-12-04 Gert Driesen <drieseng@users.sourceforge.net>
* ExternalExceptionTest.cs: Added ctor tests.
2007-11-06 Sebastien Pouliot <sebastien@ximian.com>
* MarshalTest.cs: Add test for various StringTo... to check for
bug #335488.
2007-11-06 Sebastien Pouliot <sebastien@ximian.com>
* MarshalTest.cs: Add a rountrip test case for BSTR (bug #339530).
2007-09-14 Zoltan Varga <vargaz@gmail.com>
* GCHandleTest.cs: Add some tests.
2007-08-23 Robert Jordan <robertj@gmx.net>
* MarshalTest.cs: Added test for HGlobal allocations. See bug #82499.
2006-08-31 Robert Jordan <robertj@gmx.net>
* MarshalTest.cs: Added tests for PtrToStringAuto/StringToHGlobalAuto.
2005-08-28 Sebastien Pouliot <sebastien@ximian.com>
* MarshalTest.cs: Added test for ReadInt32 (versus arch endianess).
Added endian check as Marshal must use CPU endianess.
2006-6-8 Jonathan Chambers <jonathan.chambers@ansys.com>
* MarshalTest.cs: Added tests for GetComSlotForMethodInfo.
2005-10-28 Sebastien Pouliot <sebastien@ximian.com>
* MarshalTest.cs: Added tests for 2.0 SecureTo* and ZeroFree* methods.
2005-09-20 Gert Driesen <drieseng@users.sourceforge.net>
* MarshalTest.cs: Added test for bug #76123.
2005-06-13 Sebastien Pouliot <sebastien@ximian.com>
* RuntimeEnvironmentTest.cs: Commented an assert than wasn't true when
doing a "make distcheck".
2005-06-07 Sebastien Pouliot <sebastien@ximian.com>
* RuntimeEnvironmentTest.cs: New. Unit tests for RuntimeEnvironment.
* RuntimeEnvironmentCas.cs: New. CAS unit tests for RuntimeEnvironment
2005-04-23 Zoltan Varga <vargaz@freemail.hu>
* MarshalTest.cs: Add test for OffsetOf and static fields.
2005-04-04 Zoltan Varga <vargaz@freemail.hu>
* GCHandleTest.cs: Add test for calling Alloc with null.
2004-09-03 Zoltan Varga <vargaz@freemail.hu>
* MarshalTest.cs: Add test for AllocHGlobal and zero size.
2004-08-31 Nick Drochak <ndrochak@gol.com>
* MarshalTest.cs: Make tests pass on .NET 1.1.
2004-05-05 Zoltan Varga <vargaz@freemail.hu>
* MarshalTest.cs: Add test for UnsafeAddrOfPinnedArrayElement.
2004-04-27 Zoltan Varga <vargaz@freemail.hu>
* MarshalTest.cs: New tests for PtrTo* methods and null.
2004-03-15 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* MarshalTest.cs: added a few tests for Marshal.SizeOf.

View File

@@ -0,0 +1,132 @@
//
// ExternalExceptionTest.cs - NUnit tests for ExternalException
//
// Author:
// Gert Driesen <drieseng@users.sourceforge.net>
//
// Copyright (C) 2007 Gert Driesen
//
// 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 System;
using System.Runtime.InteropServices;
using NUnit.Framework;
namespace MonoTests.System.Runtime.InteropServices
{
[TestFixture]
public class ExternalExceptionTest
{
[Test] // ctor ()
public void Constructor0 ()
{
ExternalException ex = new ExternalException ();
Assert.AreEqual (-2147467259, ex.ErrorCode, "#1");
Assert.IsNull (ex.InnerException, "#2");
Assert.IsNotNull (ex.Message, "#3");
Assert.IsTrue (ex.Message.IndexOf (ex.GetType ().FullName) == -1, "#4");
}
[Test] // ctor (string)
public void Constructor1 ()
{
ExternalException ex;
string msg = "ERROR";
ex = new ExternalException (msg);
Assert.AreEqual (-2147467259, ex.ErrorCode, "#A1");
Assert.IsNull (ex.InnerException, "#A2");
Assert.AreSame (msg, ex.Message, "#A3");
ex = new ExternalException ((string) null);
Assert.AreEqual (-2147467259, ex.ErrorCode, "#B1");
Assert.IsNull (ex.InnerException, "#B2");
Assert.IsNotNull (msg, ex.Message, "#B3");
Assert.IsTrue (ex.Message.IndexOf (ex.GetType ().FullName) != -1, "#B4");
ex = new ExternalException (string.Empty);
Assert.AreEqual (-2147467259, ex.ErrorCode, "#C1");
Assert.IsNull (ex.InnerException, "#C2");
Assert.IsNotNull (msg, ex.Message, "#C3");
Assert.AreEqual (string.Empty, ex.Message, "#C4");
}
[Test] // ctor (string, Exception)
public void Constructor3 ()
{
ExternalException ex;
string msg = "ERROR";
Exception inner = new Exception ();
ex = new ExternalException (msg, inner);
Assert.AreEqual (-2147467259, ex.ErrorCode, "#A1");
Assert.AreSame (inner, ex.InnerException, "#A2");
Assert.AreSame (msg, ex.Message, "#A3");
ex = new ExternalException ((string) null, inner);
Assert.AreEqual (-2147467259, ex.ErrorCode, "#B1");
Assert.AreSame (inner, ex.InnerException, "#B2");
Assert.IsNotNull (msg, ex.Message, "#B3");
Assert.AreEqual (new ExternalException (null).Message, ex.Message, "#B4");
ex = new ExternalException (msg, (Exception) null);
Assert.AreEqual (-2147467259, ex.ErrorCode, "#C1");
Assert.IsNull (ex.InnerException, "#C2");
Assert.AreSame (msg, ex.Message, "#C3");
ex = new ExternalException (string.Empty, (Exception) null);
Assert.AreEqual (-2147467259, ex.ErrorCode, "#D1");
Assert.IsNull (ex.InnerException, "#D2");
Assert.IsNotNull (ex.Message, "#D3");
Assert.AreEqual (string.Empty, ex.Message, "#D4");
}
[Test] // ctor (string, int)
public void Constructor4 ()
{
ExternalException ex;
string msg = "ERROR";
ex = new ExternalException (msg, int.MinValue);
Assert.AreEqual (int.MinValue, ex.ErrorCode, "#A1");
Assert.IsNull (ex.InnerException, "#A2");
Assert.AreSame (msg, ex.Message, "#A3");
ex = new ExternalException ((string) null, int.MaxValue);
Assert.AreEqual (int.MaxValue, ex.ErrorCode, "#B1");
Assert.IsNull (ex.InnerException, "#B2");
Assert.IsNotNull (msg, ex.Message, "#B3");
Assert.AreEqual (new ExternalException (null).Message, ex.Message, "#B4");
ex = new ExternalException (msg, 0);
Assert.AreEqual (0, ex.ErrorCode, "#C1");
Assert.IsNull (ex.InnerException, "#C2");
Assert.AreSame (msg, ex.Message, "#C3");
ex = new ExternalException (string.Empty, 0);
Assert.AreEqual (0, ex.ErrorCode, "#D1");
Assert.IsNull (ex.InnerException, "#D2");
Assert.IsNotNull (ex.Message, "#D3");
Assert.AreEqual (string.Empty, ex.Message, "#D4");
}
}
}

View File

@@ -0,0 +1,199 @@
//
// System.Runtime.InteropServices.GCHandle Test Cases
//
// Authors:
// Paolo Molaro (lupus@ximian.com)
//
// Copyright (C) 2005, 2009 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Globalization;
namespace MonoTests.System.Runtime.InteropServices
{
[TestFixture]
public class GCHandleTest
{
static GCHandle handle;
[Test]
public void DefaultZeroValue_Allocated ()
{
Assert.IsFalse (handle.IsAllocated, "IsAllocated");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void DefaultZeroValue_Target ()
{
Assert.IsNull (handle.Target, "Target");
}
[Test]
public void AllocNull ()
{
IntPtr ptr = (IntPtr) GCHandle.Alloc (null);
Assert.IsFalse (ptr == IntPtr.Zero, "ptr");
GCHandle gch = (GCHandle) ptr;
Assert.IsTrue (gch.IsAllocated, "IsAllocated");
Assert.IsNull (gch.Target, "Target");
}
[Test]
public void AllocNullWeakTrack ()
{
GCHandle gch = GCHandle.Alloc (null, GCHandleType.WeakTrackResurrection);
Assert.IsTrue (gch.IsAllocated, "IsAllocated");
Assert.IsNull (gch.Target, "Target");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void AddrOfPinnedObjectNormal ()
{
GCHandle handle = GCHandle.Alloc (new Object (), GCHandleType.Normal);
try {
IntPtr ptr = handle.AddrOfPinnedObject();
}
finally {
handle.Free();
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void AddrOfPinnedObjectWeak ()
{
GCHandle handle = GCHandle.Alloc (new Object (), GCHandleType.Weak);
try {
IntPtr ptr = handle.AddrOfPinnedObject();
}
finally {
handle.Free();
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void AddrOfPinnedObjectWeakTrackResurrection ()
{
GCHandle handle = GCHandle.Alloc (new Object (), GCHandleType.WeakTrackResurrection);
try {
IntPtr ptr = handle.AddrOfPinnedObject();
}
finally {
handle.Free();
}
}
[Test]
public void AddrOfPinnedObjectNull ()
{
GCHandle handle = GCHandle.Alloc (null, GCHandleType.Pinned);
try {
IntPtr ptr = handle.AddrOfPinnedObject();
Assert.AreEqual (new IntPtr (0), ptr);
}
finally {
handle.Free();
}
}
[Test]
[Ignore ("throw non-catchable ExecutionEngineException")]
[ExpectedException (typeof (ExecutionEngineException))]
public void AllocMinusOne ()
{
// -1 is a special value used by the mono runtime
// looks like it's special too in MS CLR (since it will crash)
GCHandle.Alloc (null, (GCHandleType) (-1));
}
[Test]
public void AllocInvalidType ()
{
GCHandle gch = GCHandle.Alloc (null, (GCHandleType) Int32.MinValue);
try {
Assert.IsTrue (gch.IsAllocated, "IsAllocated");
Assert.IsNull (gch.Target, "Target");
}
finally {
gch.Free ();
}
}
#if !MONOTOUCH
[Test]
public void WeakHandleWorksOnNonRootDomain ()
{
//Console.WriteLine("current app domain: " + AppDomain.CurrentDomain.Id);
AppDomain domain = AppDomain.CreateDomain("testdomain");
Assembly ea = Assembly.GetExecutingAssembly ();
domain.CreateInstanceFrom (ea.CodeBase,
typeof (AssemblyResolveHandler).FullName,
false,
BindingFlags.Public | BindingFlags.Instance,
null,
new object [] { ea.Location, ea.FullName },
CultureInfo.InvariantCulture,
null,
null);
var testerType = typeof (CrossDomainGCHandleRunner);
var r = (CrossDomainGCHandleRunner)domain.CreateInstanceAndUnwrap (
testerType.Assembly.FullName, testerType.FullName, false,
BindingFlags.Public | BindingFlags.Instance, null, new object [0],
CultureInfo.InvariantCulture, new object [0], null);
Assert.IsTrue (r.RunTest (), "#1");
AppDomain.Unload (domain);
}
public class CrossDomainGCHandleRunner : MarshalByRefObject {
public bool RunTest () {
object o = new object();
GCHandle gcHandle = GCHandle.Alloc (o, GCHandleType.Weak);
IntPtr intPtr = (IntPtr)gcHandle;
try {
object target = GCHandle.FromIntPtr(intPtr).Target;
return true;
} catch (Exception) {}
return false;
}
}
[Serializable ()]
class AssemblyResolveHandler
{
public AssemblyResolveHandler (string assemblyFile, string assemblyName)
{
_assemblyFile = assemblyFile;
_assemblyName = assemblyName;
AppDomain.CurrentDomain.AssemblyResolve +=
new ResolveEventHandler (ResolveAssembly);
}
private Assembly ResolveAssembly (object sender, ResolveEventArgs args)
{
if (args.Name == _assemblyName)
return Assembly.LoadFrom (_assemblyFile);
return null;
}
private readonly string _assemblyFile;
private readonly string _assemblyName;
}
#endif
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,118 @@
//
// RuntimeEnvironmentCas.cs - CAS Unit Tests for RuntimeEnvironment
//
// 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 System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using NUnit.Framework;
namespace MonoCasTests.System.Runtime.InteropServices {
[TestFixture]
[Category ("CAS")]
public class RuntimeEnvironmentCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager isn't enabled");
}
// Partial Trust Tests - i.e. call "normal" unit with reduced privileges
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void PartialTrust_DenyUnrestricted_Success ()
{
Assembly corlib = typeof (int).Assembly;
#if NET_2_0
Assert.IsTrue (RuntimeEnvironment.FromGlobalAccessCache (corlib), "corlib");
#else
// note: mscorlib.dll wasn't in the GAC for 1.x
Assert.IsFalse (RuntimeEnvironment.FromGlobalAccessCache (corlib), "corlib");
#endif
Assembly corlib_test = Assembly.GetExecutingAssembly ();
Assert.IsFalse (RuntimeEnvironment.FromGlobalAccessCache (corlib_test), "corlib_test");
}
// test Demand by denying the caller of the required privileges
// (note: is should only be PathDiscovery but that's not easy to test)
[Test]
[FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Deny_GetRuntimeDirectory ()
{
Assert.IsNotNull (RuntimeEnvironment.GetRuntimeDirectory ());
}
[Test]
[FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Deny_SystemConfigurationFile ()
{
Assert.IsNotNull (RuntimeEnvironment.SystemConfigurationFile);
}
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void Deny_GetSystemVersion ()
{
Assert.IsNotNull (RuntimeEnvironment.GetSystemVersion ());
}
// test Demand by permiting only the required privileges
// (note: is should only be PathDiscovery but that's not easy to test)
[Test]
[FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
public void PermitOnly_GetRuntimeDirectory ()
{
RuntimeEnvironment.GetRuntimeDirectory ();
}
[Test]
[FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
public void PermitOnly_SystemConfigurationFile ()
{
Assert.IsNotNull (RuntimeEnvironment.SystemConfigurationFile);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
public void PermitOnly_GetSystemVersion ()
{
Assert.IsNotNull (RuntimeEnvironment.GetSystemVersion ());
}
}
}

View File

@@ -0,0 +1,86 @@
//
// RuntimeEnvironmentTest.cs - NUnit tests for RuntimeEnvironment
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
// Copyright 2011 Xamarin Inc (http://www.xamarin.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 System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using NUnit.Framework;
namespace MonoTests.System.Runtime.InteropServices {
[TestFixture]
public class RuntimeEnvironmentTest {
[Test]
[Category ("MobileNotWorking")]
public void SystemConfigurationFile ()
{
string fname = RuntimeEnvironment.SystemConfigurationFile;
Assert.IsNotNull (fname, "SystemConfigurationFile");
Assert.IsTrue (File.Exists (fname), "Exists");
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void FromGlobalAccessCache_Null ()
{
RuntimeEnvironment.FromGlobalAccessCache (null);
}
[Test]
#if MOBILE
[Ignore ("There's no GAC for the NET_2_1 based profiles (Moonlight, MonoTouch and Mono for Android")]
#endif
public void FromGlobalAccessCache ()
{
Assembly corlib = typeof (int).Assembly;
// FIXME: This doesn't work when doing make distcheck (probably because the corlib used isn't the GAC)
// Assert.IsTrue (RuntimeEnvironment.FromGlobalAccessCache (corlib), "corlib");
Assembly corlib_test = Assembly.GetExecutingAssembly ();
Assert.IsFalse (RuntimeEnvironment.FromGlobalAccessCache (corlib_test), "corlib_test");
}
[Test]
public void GetRuntimeDirectory ()
{
string dirname = RuntimeEnvironment.GetRuntimeDirectory ();
Assert.IsNotNull (dirname, "GetRuntimeDirectory");
Assert.IsTrue (Directory.Exists (dirname), "Exists");
}
[Test]
public void GetSystemVersion ()
{
Assert.IsNotNull (RuntimeEnvironment.GetSystemVersion (), "GetSystemVersion");
}
}
}

View File

@@ -0,0 +1,129 @@
//
// System.Runtime.InteropServices.SafeHandle Test Cases
//
// Authors:
// Miguel de Icaza (miguel@novell.com)
//
// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Runtime.InteropServices;
using System.Security;
using Microsoft.Win32.SafeHandles;
namespace MonoTests.System.Runtime.InteropServices
{
[TestFixture]
public class SafeHandleTest
{
//
// This mimics SafeFileHandle, but does not actually own a handle
// We use this to test ownership and dispose exceptions.
//
public class FakeSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public bool released = false;
public FakeSafeHandle (): base (true)
{
}
public FakeSafeHandle (bool ownership) : base (ownership)
{
}
protected override bool ReleaseHandle ()
{
released = true;
return true;
}
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void Dispose1 ()
{
FakeSafeHandle sf = new FakeSafeHandle ();
sf.DangerousRelease ();
sf.DangerousRelease ();
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void Dispose2 ()
{
FakeSafeHandle sf = new FakeSafeHandle ();
sf.DangerousRelease ();
sf.Close ();
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void Dispose3 ()
{
FakeSafeHandle sf = new FakeSafeHandle ();
sf.Close ();
sf.DangerousRelease ();
}
[Test]
public void NoReleaseUnowned ()
{
FakeSafeHandle sf = new FakeSafeHandle (false);
sf.Close ();
Assert.AreEqual (sf.released, false, "r1");
sf = new FakeSafeHandle (false);
sf.DangerousRelease ();
Assert.AreEqual (sf.released, false, "r2");
sf = new FakeSafeHandle (false);
((IDisposable) sf).Dispose ();
Assert.AreEqual (sf.released, false, "r3");
}
//
// This test does a DangerousAddRef on a new instance
// of a custom user Safe Handle, and it just happens
// that the default value for the handle is an invalid
// handle.
//
// .NET does not throw an exception in this case, so
// we should not either
//
[Test]
public void DangerousAddRefOnNewInstance ()
{
var h = new IntPtrSafe ();
var success = false;
h.DangerousAddRef (ref success);
Assert.AreEqual (success, true, "daroni");
}
public class IntPtrSafe : SafeHandle {
public IntPtrSafe() : base(IntPtr.Zero, true)
{
}
protected override bool ReleaseHandle()
{
return true;
}
public IntPtr Handle { get; set; }
public override bool IsInvalid
{
get { return Handle == IntPtr.Zero; }
}
}
}
}
#endif