Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SafeWaitHandleExtensions.cs « tests « System.Runtime.Handles « src - github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad6fda6cc547c2a3cb242eea91f0d33ff2b88429 (plain)
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
53
54
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Threading;
using Xunit;

public partial class SafeWaitHandleExtensions_4000_Tests
{
    public class MyWaitHandle : WaitHandle
    {
        public MyWaitHandle()
        { }
    }

    [Fact]
    public static void SafeWaitHandleExtensions_get()
    {
        var wh = new MyWaitHandle();

        var swh = wh.GetSafeWaitHandle();

        Assert.Equal(new IntPtr(-1), swh.DangerousGetHandle());
    }

    [Fact]
    public static void SafeWaitHandleExtensions_set()
    {
        var wh = new MyWaitHandle();

        var swhExpected = new SafeWaitHandle(new IntPtr(5), true);
        wh.SetSafeWaitHandle(swhExpected);

        var swh = wh.GetSafeWaitHandle();

        Assert.Equal(swhExpected, swh);

        wh.SetSafeWaitHandle(null);
        swh = wh.GetSafeWaitHandle();
        Assert.NotNull(swh);
        Assert.Equal(new IntPtr(-1), swh.DangerousGetHandle());
    }

    [Fact]
    public static void SafeWaitHandleExtensions_nullWaitHandle()
    {
        WaitHandle wh = null;

        Assert.Throws<ArgumentNullException>(() => wh.GetSafeWaitHandle());
        Assert.Throws<ArgumentNullException>(() => wh.SetSafeWaitHandle(new SafeWaitHandle(IntPtr.Zero, false)));
    }
}