-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
ThreadPoolBoundHandle_FreeNativeOverlappedTests.cs
52 lines (46 loc) · 1.97 KB
/
ThreadPoolBoundHandle_FreeNativeOverlappedTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Threading;
using Xunit;
public partial class ThreadPoolBoundHandleTests
{
[Fact]
[PlatformSpecific(TestPlatforms.Windows)] // ThreadPoolBoundHandle.BindHandle is not supported on Unix
public unsafe void FreeNativeOverlapped_NullAsNativeOverlapped_ThrowsArgumentNullException()
{
using(ThreadPoolBoundHandle handle = CreateThreadPoolBoundHandle())
{
AssertExtensions.Throws<ArgumentNullException>("overlapped", () =>
{
handle.FreeNativeOverlapped((NativeOverlapped*)null);
});
}
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)] // ThreadPoolBoundHandle.BindHandle is not supported on Unix
public unsafe void FreeNativeOverlapped_WhenDisposed_DoesNotThrow()
{
ThreadPoolBoundHandle boundHandle = CreateThreadPoolBoundHandle();
NativeOverlapped* overlapped = boundHandle.AllocateNativeOverlapped((_, __, ___) => { }, new object(), new byte[256]);
boundHandle.Dispose();
boundHandle.FreeNativeOverlapped(overlapped);
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)] // ThreadPoolBoundHandle.BindHandle is not supported on Unix
public unsafe void FreeNativeOverlapped_WithWrongHandle_ThrowsArgumentException()
{
using(ThreadPoolBoundHandle handle = CreateThreadPoolBoundHandle())
{
NativeOverlapped* overlapped = handle.AllocateNativeOverlapped((_, __, ___) => { }, (object)null, (byte[])null);
using (ThreadPoolBoundHandle handle2 = CreateThreadPoolBoundHandle())
{
AssertExtensions.Throws<ArgumentException>("overlapped", () =>
{
handle2.FreeNativeOverlapped(overlapped);
});
}
handle.FreeNativeOverlapped(overlapped);
}
}
}