Skip to content

Commit

Permalink
Change UnixFileType to UnixFileStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Mar 16, 2024
1 parent b607b97 commit b9b5260
Show file tree
Hide file tree
Showing 34 changed files with 813 additions and 181 deletions.
12 changes: 6 additions & 6 deletions AdvancedSharpAdbClient.Tests/AdbSocketTests.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ await RunTestAsync(
[(byte)'D', (byte)'A', (byte)'T', (byte)'A', 2, 0, 0, 0]);

/// <summary>
/// Tests the <see cref="AdbSocket.SendSyncRequestAsync(SyncCommand, string, CancellationToken)"/> method.
/// Tests the <see cref="AdbSocket.SendSyncRequestAsync(SyncCommand, string, UnixFileStatus, CancellationToken)"/> method.
/// </summary>
[Fact]
public async void SendSyncSENDRequestAsyncTest() =>
await RunTestAsync(
socket => socket.SendSyncRequestAsync(SyncCommand.SEND, "/test", default),
[(byte)'S', (byte)'E', (byte)'N', (byte)'D', 5, 0, 0, 0, (byte)'/', (byte)'t', (byte)'e', (byte)'s', (byte)'t']);
socket => socket.SendSyncRequestAsync(SyncCommand.SEND, "/test", UnixFileStatus.GroupMask | UnixFileStatus.StickyBit | UnixFileStatus.UserExecute | UnixFileStatus.OtherExecute, default),
[(byte)'S', (byte)'E', (byte)'N', (byte)'D', 9, 0, 0, 0, (byte)'/', (byte)'t', (byte)'e', (byte)'s', (byte)'t', (byte)',', (byte)'6', (byte)'3', (byte)'3']);

/// <summary>
/// Tests the <see cref="AdbSocket.SendSyncRequestAsync(SyncCommand, string, int, CancellationToken)"/> method.
/// Tests the <see cref="AdbSocket.SendSyncRequestAsync(SyncCommand, string, CancellationToken)"/> method.
/// </summary>
[Fact]
public async void SendSyncDENTRequestAsyncTest() =>
await RunTestAsync(
socket => socket.SendSyncRequestAsync(SyncCommand.DENT, "/data", 633, default),
[(byte)'D', (byte)'E', (byte)'N', (byte)'T', 9, 0, 0, 0, (byte)'/', (byte)'d', (byte)'a', (byte)'t', (byte)'a', (byte)',', (byte)'6', (byte)'3', (byte)'3']);
socket => socket.SendSyncRequestAsync(SyncCommand.DENT, "/data", default),
[(byte)'D', (byte)'E', (byte)'N', (byte)'T', 5, 0, 0, 0, (byte)'/', (byte)'d', (byte)'a', (byte)'t', (byte)'a']);

/// <summary>
/// Tests the <see cref="AdbSocket.SendSyncRequestAsync(SyncCommand, string, CancellationToken)"/> method.
Expand Down
12 changes: 6 additions & 6 deletions AdvancedSharpAdbClient.Tests/AdbSocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ public void SendSyncDATARequestTest() =>
[(byte)'D', (byte)'A', (byte)'T', (byte)'A', 2, 0, 0, 0]);

/// <summary>
/// Tests the <see cref="AdbSocket.SendSyncRequest(SyncCommand, string)"/> method.
/// Tests the <see cref="AdbSocket.SendSyncRequest(SyncCommand, string, UnixFileStatus)"/> method.
/// </summary>
[Fact]
public void SendSyncSENDRequestTest() =>
RunTest(
socket => socket.SendSyncRequest(SyncCommand.SEND, "/test"),
[(byte)'S', (byte)'E', (byte)'N', (byte)'D', 5, 0, 0, 0, (byte)'/', (byte)'t', (byte)'e', (byte)'s', (byte)'t']);
socket => socket.SendSyncRequest(SyncCommand.SEND, "/test", UnixFileStatus.GroupMask | UnixFileStatus.StickyBit | UnixFileStatus.UserExecute | UnixFileStatus.OtherExecute),
[(byte)'S', (byte)'E', (byte)'N', (byte)'D', 9, 0, 0, 0, (byte)'/', (byte)'t', (byte)'e', (byte)'s', (byte)'t', (byte)',', (byte)'6', (byte)'3', (byte)'3']);

/// <summary>
/// Tests the <see cref="AdbSocket.SendSyncRequest(SyncCommand, string, int)"/> method.
/// Tests the <see cref="AdbSocket.SendSyncRequest(SyncCommand, string)"/> method.
/// </summary>
[Fact]
public void SendSyncDENTRequestTest() =>
RunTest(
socket => socket.SendSyncRequest(SyncCommand.DENT, "/data", 633),
[(byte)'D', (byte)'E', (byte)'N', (byte)'T', 9, 0, 0, 0, (byte)'/', (byte)'d', (byte)'a', (byte)'t', (byte)'a', (byte)',', (byte)'6', (byte)'3', (byte)'3']);
socket => socket.SendSyncRequest(SyncCommand.DENT, "/data"),
[(byte)'D', (byte)'E', (byte)'N', (byte)'T', 5, 0, 0, 0, (byte)'/', (byte)'d', (byte)'a', (byte)'t', (byte)'a']);

/// <summary>
/// Tests the <see cref="AdbSocket.SendSyncRequest(SyncCommand, string)"/> method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Choose>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.1" PrivateAssets="all">
<PackageReference Include="coverlet.msbuild" Version="6.0.2" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
Expand Down
6 changes: 3 additions & 3 deletions AdvancedSharpAdbClient.Tests/Dummys/DummyAdbSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal class DummyAdbSocket : IDummyAdbSocket

public void SendSyncRequest(SyncCommand command, int length) => SyncRequests.Add((command, length.ToString()));

public void SendSyncRequest(SyncCommand command, string path, int permissions) => SyncRequests.Add((command, $"{path},{permissions}"));
public void SendSyncRequest(SyncCommand command, string path, UnixFileStatus permission) => SyncRequests.Add((command, $"{path},{(int)permission}"));

public void SendAdbRequest(string request) => Requests.Add(request);

Expand Down Expand Up @@ -192,10 +192,10 @@ public async ValueTask SendAsync(ReadOnlyMemory<byte> data, CancellationToken ca
Send(data.Span);
}

public async Task SendSyncRequestAsync(SyncCommand command, string path, int permissions, CancellationToken cancellationToken = default)
public async Task SendSyncRequestAsync(SyncCommand command, string path, UnixFileStatus permission, CancellationToken cancellationToken = default)
{
await Task.Yield();
SendSyncRequest(command, path, permissions);
SendSyncRequest(command, path, permission);
}

public async Task SendSyncRequestAsync(SyncCommand command, string path, CancellationToken cancellationToken = default)
Expand Down
4 changes: 2 additions & 2 deletions AdvancedSharpAdbClient.Tests/Dummys/DummySyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task PullAsync(string remotePath, Stream stream, Action<SyncProgres
}
}

public void Push(Stream stream, string remotePath, int permissions, DateTimeOffset timestamp, Action<SyncProgressChangedEventArgs> callback = null, in bool isCancelled = false)
public void Push(Stream stream, string remotePath, UnixFileStatus permission, DateTimeOffset timestamp, Action<SyncProgressChangedEventArgs> callback = null, in bool isCancelled = false)
{
for (int i = 0; i <= 100; i++)
{
Expand All @@ -54,7 +54,7 @@ public void Push(Stream stream, string remotePath, int permissions, DateTimeOffs
}
}

public async Task PushAsync(Stream stream, string remotePath, int permissions, DateTimeOffset timestamp, Action<SyncProgressChangedEventArgs> callback = null, CancellationToken cancellationToken = default)
public async Task PushAsync(Stream stream, string remotePath, UnixFileStatus permission, DateTimeOffset timestamp, Action<SyncProgressChangedEventArgs> callback = null, CancellationToken cancellationToken = default)
{
for (int i = 0; i <= 100; i++)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Xunit;

namespace AdvancedSharpAdbClient.Tests
namespace AdvancedSharpAdbClient.Models.Tests
{
/// <summary>
/// Tests the <see cref="SyncCommandConverter"/> class.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
using Xunit;

namespace AdvancedSharpAdbClient.Models.Tests
{
/// <summary>
/// Tests the <see cref="UnixFileStatusExtensions"/> class.
/// </summary>
public class UnixFileStatusExtensionsTests
{
[Theory]
[InlineData((UnixFileStatus)0x7DAB, (UnixFileStatus)0x7000)]
[InlineData((UnixFileStatus)0x3D94, (UnixFileStatus)0x3000)]
[InlineData((UnixFileStatus)0x3052, (UnixFileStatus)0x3000)]
[InlineData((UnixFileStatus)0x8724, (UnixFileStatus)0x8000)]
[InlineData((UnixFileStatus)0xEBC3, (UnixFileStatus)0xE000)]
[InlineData((UnixFileStatus)0xBFBA, (UnixFileStatus)0xB000)]
[InlineData((UnixFileStatus)0x2059, (UnixFileStatus)0x2000)]
[InlineData((UnixFileStatus)0xAFDC, (UnixFileStatus)0xA000)]
[InlineData((UnixFileStatus)0x2D2F, (UnixFileStatus)0x2000)]
[InlineData((UnixFileStatus)0xC10F, (UnixFileStatus)0xC000)]
public void GetFileTypeTest(UnixFileStatus source, UnixFileStatus type) => Assert.Equal(type, source.GetFileType());

[Theory]
[InlineData((UnixFileStatus)0xF118, (UnixFileStatus)0x0118)]
[InlineData((UnixFileStatus)0x638A, (UnixFileStatus)0x038A)]
[InlineData((UnixFileStatus)0xB72D, (UnixFileStatus)0x072D)]
[InlineData((UnixFileStatus)0x5AF9, (UnixFileStatus)0x0AF9)]
[InlineData((UnixFileStatus)0xA3F5, (UnixFileStatus)0x03F5)]
[InlineData((UnixFileStatus)0x7ACD, (UnixFileStatus)0x0ACD)]
[InlineData((UnixFileStatus)0x4751, (UnixFileStatus)0x0751)]
[InlineData((UnixFileStatus)0xDA30, (UnixFileStatus)0x0A30)]
[InlineData((UnixFileStatus)0xB829, (UnixFileStatus)0x0829)]
[InlineData((UnixFileStatus)0xFE1A, (UnixFileStatus)0x0E1A)]
public void GetPermissionsTest(UnixFileStatus source, UnixFileStatus type) => Assert.Equal(type, source.GetPermissions());

[Theory]
[InlineData((UnixFileStatus)0x28DA, (UnixFileStatus)0x00DA)]
[InlineData((UnixFileStatus)0x69EE, (UnixFileStatus)0x01EE)]
[InlineData((UnixFileStatus)0x2507, (UnixFileStatus)0x0107)]
[InlineData((UnixFileStatus)0x763F, (UnixFileStatus)0x003F)]
[InlineData((UnixFileStatus)0x8ECC, (UnixFileStatus)0x00CC)]
[InlineData((UnixFileStatus)0xBFB8, (UnixFileStatus)0x01B8)]
[InlineData((UnixFileStatus)0xF893, (UnixFileStatus)0x0093)]
[InlineData((UnixFileStatus)0x8E54, (UnixFileStatus)0x0054)]
[InlineData((UnixFileStatus)0x6270, (UnixFileStatus)0x0070)]
[InlineData((UnixFileStatus)0x21AB, (UnixFileStatus)0x01AB)]
public void GetAccessPermissionsTest(UnixFileStatus source, UnixFileStatus type) => Assert.Equal(type, source.GetAccessPermissions());

[Theory]
[InlineData((UnixFileStatus)0x0FFF, false)]
[InlineData((UnixFileStatus)0x1FB6, false)]
[InlineData((UnixFileStatus)0x21FF, false)]
[InlineData((UnixFileStatus)0x41B6, true)]
[InlineData((UnixFileStatus)0x616D, false)]
[InlineData((UnixFileStatus)0x80DB, false)]
[InlineData((UnixFileStatus)0xA124, false)]
[InlineData((UnixFileStatus)0xC092, false)]
[InlineData((UnixFileStatus)0xF049, false)]
public void IsDirectoryTest(UnixFileStatus mode, bool result) => Assert.Equal(result, mode.IsDirectory());

[Theory]
[InlineData((UnixFileStatus)0x0FFF, false)]
[InlineData((UnixFileStatus)0x1FB6, false)]
[InlineData((UnixFileStatus)0x21FF, true)]
[InlineData((UnixFileStatus)0x41B6, false)]
[InlineData((UnixFileStatus)0x616D, false)]
[InlineData((UnixFileStatus)0x80DB, false)]
[InlineData((UnixFileStatus)0xA124, false)]
[InlineData((UnixFileStatus)0xC092, false)]
[InlineData((UnixFileStatus)0xF049, false)]
public void IsCharacterFileTest(UnixFileStatus mode, bool result) => Assert.Equal(result, mode.IsCharacterFile());

[Theory]
[InlineData((UnixFileStatus)0x0FFF, false)]
[InlineData((UnixFileStatus)0x1FB6, false)]
[InlineData((UnixFileStatus)0x21FF, false)]
[InlineData((UnixFileStatus)0x41B6, false)]
[InlineData((UnixFileStatus)0x616D, true)]
[InlineData((UnixFileStatus)0x80DB, false)]
[InlineData((UnixFileStatus)0xA124, false)]
[InlineData((UnixFileStatus)0xC092, false)]
[InlineData((UnixFileStatus)0xF049, false)]
public void IsBlockFileTest(UnixFileStatus mode, bool result) => Assert.Equal(result, mode.IsBlockFile());

[Theory]
[InlineData((UnixFileStatus)0x0FFF, false)]
[InlineData((UnixFileStatus)0x1FB6, false)]
[InlineData((UnixFileStatus)0x21FF, false)]
[InlineData((UnixFileStatus)0x41B6, false)]
[InlineData((UnixFileStatus)0x616D, false)]
[InlineData((UnixFileStatus)0x80DB, true)]
[InlineData((UnixFileStatus)0xA124, false)]
[InlineData((UnixFileStatus)0xC092, false)]
[InlineData((UnixFileStatus)0xF049, false)]
public void IsRegularFileTest(UnixFileStatus mode, bool result) => Assert.Equal(result, mode.IsRegularFile());

[Theory]
[InlineData((UnixFileStatus)0x0FFF, false)]
[InlineData((UnixFileStatus)0x1FB6, true)]
[InlineData((UnixFileStatus)0x21FF, false)]
[InlineData((UnixFileStatus)0x41B6, false)]
[InlineData((UnixFileStatus)0x616D, false)]
[InlineData((UnixFileStatus)0x80DB, false)]
[InlineData((UnixFileStatus)0xA124, false)]
[InlineData((UnixFileStatus)0xC092, false)]
[InlineData((UnixFileStatus)0xF049, false)]
public void IsFIFOTest(UnixFileStatus mode, bool result) => Assert.Equal(result, mode.IsFIFO());

[Theory]
[InlineData((UnixFileStatus)0x0FFF, false)]
[InlineData((UnixFileStatus)0x1FB6, false)]
[InlineData((UnixFileStatus)0x21FF, false)]
[InlineData((UnixFileStatus)0x41B6, false)]
[InlineData((UnixFileStatus)0x616D, false)]
[InlineData((UnixFileStatus)0x80DB, false)]
[InlineData((UnixFileStatus)0xA124, true)]
[InlineData((UnixFileStatus)0xC092, false)]
[InlineData((UnixFileStatus)0xF049, false)]
public void IsSymbolicLinkTest(UnixFileStatus mode, bool result) => Assert.Equal(result, mode.IsSymbolicLink());

[Theory]
[InlineData((UnixFileStatus)0x0FFF, false)]
[InlineData((UnixFileStatus)0x1FB6, false)]
[InlineData((UnixFileStatus)0x21FF, false)]
[InlineData((UnixFileStatus)0x41B6, false)]
[InlineData((UnixFileStatus)0x616D, false)]
[InlineData((UnixFileStatus)0x80DB, false)]
[InlineData((UnixFileStatus)0xA124, false)]
[InlineData((UnixFileStatus)0xC092, true)]
[InlineData((UnixFileStatus)0xF049, false)]
public void IsSocketTest(UnixFileStatus mode, bool result) => Assert.Equal(result, mode.IsSocket());

[Theory]
[InlineData((UnixFileStatus)0x0FFF, true)]
[InlineData((UnixFileStatus)0x1FB6, true)]
[InlineData((UnixFileStatus)0x21FF, true)]
[InlineData((UnixFileStatus)0x41B6, false)]
[InlineData((UnixFileStatus)0x616D, true)]
[InlineData((UnixFileStatus)0x80DB, false)]
[InlineData((UnixFileStatus)0xA124, false)]
[InlineData((UnixFileStatus)0xC092, true)]
[InlineData((UnixFileStatus)0xF049, true)]
public void IsOtherTest(UnixFileStatus mode, bool result) => Assert.Equal(result, mode.IsOther());

[Theory]
[InlineData((UnixFileStatus)0x0FFF, false)]
[InlineData((UnixFileStatus)0x1FB6, true)]
[InlineData((UnixFileStatus)0x21FF, true)]
[InlineData((UnixFileStatus)0x41B6, true)]
[InlineData((UnixFileStatus)0x616D, true)]
[InlineData((UnixFileStatus)0x80DB, true)]
[InlineData((UnixFileStatus)0xA124, true)]
[InlineData((UnixFileStatus)0xC092, true)]
[InlineData((UnixFileStatus)0xF049, true)]
public void IsTypeKnownTest(UnixFileStatus mode, bool result) => Assert.Equal(result, mode.IsTypeKnown());

[Theory]
[InlineData("\0rwsrwsrwt", (UnixFileStatus)0x0FFF)]
[InlineData("prwSrwSrwT", (UnixFileStatus)0x1FB6)]
[InlineData("crwxrwxrwx", (UnixFileStatus)0x21FF)]
[InlineData("drw-rw-rw-", (UnixFileStatus)0x41B6)]
[InlineData("br-xr-xr-x", (UnixFileStatus)0x616D)]
[InlineData("--wx-wx-wx", (UnixFileStatus)0x80DB)]
[InlineData("lr--r--r--", (UnixFileStatus)0xA124)]
[InlineData("s-w--w--w-", (UnixFileStatus)0xC092)]
[InlineData("?--x--x--x", (UnixFileStatus)0x0049)]
[InlineData("7777", (UnixFileStatus)0x0FFF)]
public void FromPermissionCodeTest(string code, UnixFileStatus mode) => Assert.Equal(mode, UnixFileStatusExtensions.FromPermissionCode(code));

[Theory]
[InlineData((UnixFileStatus)0x0FFF, "\0rwsrwsrwt")]
[InlineData((UnixFileStatus)0x1FB6, "prwSrwSrwT")]
[InlineData((UnixFileStatus)0x21FF, "crwxrwxrwx")]
[InlineData((UnixFileStatus)0x41B6, "drw-rw-rw-")]
[InlineData((UnixFileStatus)0x616D, "br-xr-xr-x")]
[InlineData((UnixFileStatus)0x80DB, "--wx-wx-wx")]
[InlineData((UnixFileStatus)0xA124, "lr--r--r--")]
[InlineData((UnixFileStatus)0xC092, "s-w--w--w-")]
[InlineData((UnixFileStatus)0xF049, "?--x--x--x")]
public void ToPermissionCodeTest(UnixFileStatus mode, string code) => Assert.Equal(code, mode.ToPermissionCode());
}
}
31 changes: 31 additions & 0 deletions AdvancedSharpAdbClient.Tests/Models/UnixFileStatusTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.IO;
using Xunit;

namespace AdvancedSharpAdbClient.Models.Tests
{
/// <summary>
/// Tests the <see cref="UnixFileStatus"/> class.
/// </summary>
public class UnixFileStatusTests
{
[Theory]
[InlineData(UnixFileMode.SetUser, UnixFileStatus.SetUser)]
[InlineData(UnixFileMode.SetGroup, UnixFileStatus.SetGroup)]
[InlineData(UnixFileMode.StickyBit, UnixFileStatus.StickyBit)]
[InlineData(UnixFileMode.UserRead, UnixFileStatus.UserRead)]
[InlineData(UnixFileMode.UserWrite, UnixFileStatus.UserWrite)]
[InlineData(UnixFileMode.UserExecute, UnixFileStatus.UserExecute)]
[InlineData(UnixFileMode.GroupRead, UnixFileStatus.GroupRead)]
[InlineData(UnixFileMode.GroupWrite, UnixFileStatus.GroupWrite)]
[InlineData(UnixFileMode.GroupExecute, UnixFileStatus.GroupExecute)]
[InlineData(UnixFileMode.OtherRead, UnixFileStatus.OtherRead)]
[InlineData(UnixFileMode.OtherWrite, UnixFileStatus.OtherWrite)]
[InlineData(UnixFileMode.OtherExecute, UnixFileStatus.OtherExecute)]
public void UnixFileModeTest(UnixFileMode mode, UnixFileStatus status)
{
Assert.Equal((int)mode, (int)status);
Assert.Equal(mode, (UnixFileMode)status);
Assert.Equal((UnixFileStatus)mode, status);
}
}
}
Loading

0 comments on commit b9b5260

Please sign in to comment.