summaryrefslogtreecommitdiff
path: root/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid4.cs
blob: ebfde369f5f73000c75d0604efd047d65be04017 (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
55
56
57
// 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 System;
using System.Threading;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

/// <summary>
/// Verifies passing an invalid handle (not overlapped) to BindHandle works as expected
/// </summary>
class BindHandleInvalid3
{
    public static int Main(string[] args)
    {
        return (new BindHandleInvalid3().RunTest());
    }

    int RunTest()
    {
        try
        {
            try
            {
                using (FileStream fs1 = new FileStream("test.txt", FileMode.Create))
                {
                    ThreadPool.BindHandle(fs1.SafeFileHandle);
                }
            }
            catch (Exception ex)
            {
                if (ex.ToString().IndexOf("0x80070057") != -1) // E_INVALIDARG, the handle isn't overlapped
                {
                    Console.WriteLine("Test passed");
                    return (100);
                }
                else
                {
                    Console.WriteLine("Got wrong error: {0}", ex);
                }
            }
        }
        finally
        {
            if (File.Exists("test.txt"))
            {
                File.Delete("test.txt");
            }
        }
        Console.WriteLine("Didn't get argument null exception");
        return (99);
    }


}