Skip to content

Commit

Permalink
Clean up tests under CoreMangLib/system/runtime/interopservices/safeh…
Browse files Browse the repository at this point in the history
…andle (dotnet#58528)

* Delete redundant SafeHandle tests

* Move DangerousGetHandle and SetHandleAsInvalid tests to libraries

Remove IsClosed and SetHandle tests - covered by existing/new checks in
libraries tests.
  • Loading branch information
elinor-fung authored Sep 2, 2021
1 parent 9a5baa9 commit 6714f81
Show file tree
Hide file tree
Showing 19 changed files with 28 additions and 1,875 deletions.
29 changes: 28 additions & 1 deletion src/libraries/System.Runtime.Handles/tests/SafeHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,40 @@ public static void SafeHandle_invalid()
Assert.False(mch.IsClosed);
Assert.True(mch.IsInvalid);
Assert.False(mch.IsReleased);
Assert.Equal(IntPtr.Zero, mch.DangerousGetHandle());

mch.Dispose();
Assert.True(mch.IsClosed);
Assert.True(mch.IsInvalid);
Assert.False(mch.IsReleased);

// Make sure we can dispose multiple times
mch.Dispose();
Assert.True(mch.IsClosed);
Assert.True(mch.IsInvalid);
Assert.False(mch.IsReleased);
}

[Fact]
public static void SafeHandle_valid()
{
MySafeHandle mch = new MySafeHandle(new IntPtr(1));
IntPtr ptr = new IntPtr(1);
MySafeHandle mch = new MySafeHandle(ptr);
Assert.False(mch.IsClosed);
Assert.False(mch.IsInvalid);
Assert.False(mch.IsReleased);
Assert.Equal(ptr, mch.DangerousGetHandle());

mch.Dispose();
Assert.True(mch.IsClosed);
Assert.False(mch.IsInvalid);
Assert.True(mch.IsReleased);

// Make sure we can dispose multiple times
mch.Dispose();
Assert.True(mch.IsClosed);
Assert.False(mch.IsInvalid);
Assert.True(mch.IsReleased);
}

[Fact]
Expand All @@ -81,6 +96,18 @@ public static void SafeHandle_valid_close()
Assert.True(mch.IsReleased);
}

[Fact]
public static void SafeHandle_SetHandleAsInvalid()
{
IntPtr ptr = new IntPtr(1);
MySafeHandle handle = new MySafeHandle(ptr);
handle.SetHandleAsInvalid();
Assert.True(handle.IsClosed);
Assert.False(handle.IsInvalid);
Assert.False(handle.IsReleased);
Assert.Equal(ptr, handle.DangerousGetHandle());
}

[DllImport("Kernel32", SetLastError = true)]
private static extern void SetLastError(int error);

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6714f81

Please sign in to comment.