-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
SafeHandleLifetimeTests.cs
46 lines (37 loc) · 1.62 KB
/
SafeHandleLifetimeTests.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
// 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.IO;
using System.Runtime.InteropServices;
using Xunit;
namespace SafeHandleTests
{
public class SafeHandleLifetimeTests
{
private static readonly IntPtr initialValue = new IntPtr(458613);
private static readonly IntPtr newValue = new IntPtr(987185);
public static void RunTest()
{
var testHandle = new TestSafeHandle(initialValue);
Assert.True(SafeHandleNative.SafeHandleByValue(testHandle, initialValue));
Assert.False(testHandle.IsClosed);
Assert.True(SafeHandleNative.SafeHandleByRef(ref testHandle, initialValue, newValue));
Assert.False(testHandle.IsClosed);
testHandle = null;
SafeHandleNative.SafeHandleOut(out testHandle, initialValue);
Assert.False(testHandle.IsClosed);
testHandle = SafeHandleNative.SafeHandleReturn(newValue);
Assert.False(testHandle.IsClosed);
testHandle = SafeHandleNative.SafeHandleReturn_Swapped(newValue);
Assert.False(testHandle.IsClosed);
var str = new SafeHandleNative.StructWithHandle
{
handle = new TestSafeHandle(initialValue)
};
SafeHandleNative.StructWithSafeHandleByValue(str, initialValue);
Assert.False(str.handle.IsClosed);
SafeHandleNative.StructWithSafeHandleByRef(ref str, initialValue, initialValue);
Assert.False(str.handle.IsClosed);
}
}
}