Skip to content

Commit

Permalink
Merge pull request #5 from StormHub/Poll
Browse files Browse the repository at this point in the history
Migrate Poll tests. #4
  • Loading branch information
StormHub committed Feb 26, 2017
2 parents 2876b77 + 257eb56 commit c36f705
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/NetUV.Core/Native/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum uv_err_code
UV_ENOTCONN = -4053,
UV_ENOTDIR,
UV_ENOTEMPTY,
UV_ENOTSOCK,
UV_ENOTSOCK = -4050,
UV_ENOTSUP,
UV_EPERM,
UV_EPIPE = -4047,
Expand Down
5 changes: 4 additions & 1 deletion test/NetUV.Tests/FSPollTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace NetUV.Core.Tests
// Copyright (c) Johnny Z. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace NetUV.Core.Tests
{
using System;
using NetUV.Core.Handles;
Expand Down
44 changes: 44 additions & 0 deletions test/NetUV.Tests/PollTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Johnny Z. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace NetUV.Core.Tests
{
using System;
using System.IO;
using NetUV.Core.Handles;
using NetUV.Core.Native;
using Xunit;

public sealed class PollTests : IDisposable
{
Loop loop;
IDisposable fdHandle;

public PollTests()
{
this.loop = new Loop();
}

[Fact]
public void BadFileDescriptorType()
{
FileStream file = TestHelper.OpenTempFile();
this.fdHandle = file;

IntPtr handle = file.SafeFileHandle.DangerousGetHandle();
var error = Assert.Throws<OperationException>(() => this.loop.CreatePoll(handle.ToInt32()));
file.Dispose();

Assert.Equal((int)uv_err_code.UV_ENOTSOCK, error.ErrorCode);
}

public void Dispose()
{
this.fdHandle?.Dispose();
this.fdHandle = null;

this.loop?.Dispose();
this.loop = null;
}
}
}
9 changes: 9 additions & 0 deletions test/NetUV.Tests/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public static string CreateTempFile(string directory)

return fileName;
}

public static FileStream OpenTempFile()
{
string directory = CreateTempDirectory();
string fileName = Path.Combine(directory, Path.GetRandomFileName());
FileStream file = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
return file;
}

public static void CreateFile(string fullName)
{
if (File.Exists(fullName))
Expand Down

0 comments on commit c36f705

Please sign in to comment.