Skip to content

Commit

Permalink
Let getter gets directly
Browse files Browse the repository at this point in the history
Add CombineDotDirTest
  • Loading branch information
wherewhere committed Mar 28, 2024
1 parent dba6608 commit 4714c48
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 20 deletions.
1 change: 0 additions & 1 deletion AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion AdvancedSharpAdbClient.Tests/AdbClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Versioning;
using System.Text;
using Xunit;

Expand Down
16 changes: 16 additions & 0 deletions AdvancedSharpAdbClient.Tests/DeviceCommands/LinuxPathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ public void CombineCurrentDirTest()
Assert.Equal("./Test.txt", result);
}

[Fact]
public void CombineDotDirTest()
{
string result = LinuxPath.Combine("Test.Test", "Test.txt");
Assert.Equal("./Test.Test/Test.txt", result);

result = LinuxPath.Combine("Test/Test.Test", "Test.txt");
Assert.Equal("./Test/Test.Test/Test.txt", result);

result = LinuxPath.Combine("/Test/Test.Test", "Test.txt");
Assert.Equal("/Test/Test.Test/Test.txt", result);

result = LinuxPath.Combine("/Test Test/Test.Test", "Test.txt");
Assert.Equal("/Test Test/Test.Test/Test.txt", result);
}

[Fact]
public void GetDirectoryNameTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.Versioning;
using Xunit;

namespace AdvancedSharpAdbClient.Models.Tests
Expand Down
1 change: 0 additions & 1 deletion AdvancedSharpAdbClient.Tests/Models/FramebufferTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Runtime.Versioning;
using Xunit;

namespace AdvancedSharpAdbClient.Models.Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PackageManagerReceiver(PackageManager packageManager) : MultiLineRe
/// <summary>
/// Gets the package manager.
/// </summary>
public PackageManager PackageManager { get; } = packageManager;
public PackageManager PackageManager => packageManager;

/// <inheritdoc/>
protected override void ProcessNewLines(IEnumerable<string> lines)
Expand Down
2 changes: 1 addition & 1 deletion AdvancedSharpAdbClient/DeviceMonitor.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private async Task InitializeSocketAsync(CancellationToken cancellationToken)
/// <summary>
/// Gets a value that indicates whether the asynchronous operation has completed.
/// </summary>
public bool IsCompleted { get; } = false;
public bool IsCompleted => false;

/// <summary>
/// Ends the await on the completed task.
Expand Down
26 changes: 23 additions & 3 deletions AdvancedSharpAdbClient/Models/ColorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;

namespace AdvancedSharpAdbClient.Models
{
Expand All @@ -26,6 +27,11 @@ namespace AdvancedSharpAdbClient.Models
[DebuggerDisplay($"{{{nameof(ToString)}(),nq}}")]
public readonly record struct ColorData(uint Offset, uint Length) : IReadOnlyList<byte>
{
/// <summary>
/// The length of <see cref="ColorData"/> in bytes.
/// </summary>
private const int count = 8;

/// <summary>
/// Initializes a new instance of the <see cref="ColorData"/> struct.
/// </summary>
Expand All @@ -43,13 +49,13 @@ namespace AdvancedSharpAdbClient.Models
public uint Length { get; init; } = Length;

/// <summary>
/// The length of <see cref="ColorData"/> in bytes.
/// Gets the length of <see cref="ColorData"/> in bytes.
/// </summary>
public readonly int Count => 8;
public readonly int Count => count;

/// <inheritdoc/>
public readonly byte this[int index] =>
index < 0 || index >= Count
index is < 0 or >= count
? throw new IndexOutOfRangeException("Index was out of range. Must be non-negative and less than the size of the collection.")
: index switch
{
Expand All @@ -66,6 +72,20 @@ namespace AdvancedSharpAdbClient.Models
_ => throw new IndexOutOfRangeException("Index was out of range. Must be non-negative and less than the size of the collection.")
};

/// <summary>
/// Provides a string representation of the <see cref="ColorData"/> struct.
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to append the string representation to.</param>
/// <returns><see langword="true"/> if the members were appended to the <paramref name="builder"/>; otherwise, <see langword="false"/>.</returns>
private bool PrintMembers(StringBuilder builder)
{
_ = builder.Append("Offset = ")
.Append(Offset)
.Append(", Length = ")
.Append(Length);
return true;
}

/// <summary>
/// Deconstruct the <see cref="ColorData"/> struct.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions AdvancedSharpAdbClient/Models/DeviceData.EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class DeviceDataEventArgs(DeviceData device) : EventArgs
/// Gets the device where the change occurred.
/// </summary>
/// <value>The device where the change occurred.</value>
public DeviceData Device { get; } = device;
public DeviceData Device => device;

/// <inheritdoc/>
public override string ToString()
Expand Down Expand Up @@ -50,7 +50,7 @@ public sealed class DeviceDataNotifyEventArgs(IEnumerable<DeviceData> devices) :
/// Gets the list of device where the change occurred.
/// </summary>
/// <value>The list of device where the change occurred.</value>
public IEnumerable<DeviceData> Devices { get; } = devices;
public IEnumerable<DeviceData> Devices => devices;

/// <inheritdoc/>
public override string ToString() => $"Got {Devices.Count()} devices";
Expand All @@ -67,7 +67,7 @@ public sealed class DeviceDataConnectEventArgs(DeviceData device, bool isConnect
/// <summary>
/// Gets the connect state of the device after the reported change.
/// </summary>
public bool IsConnect { get; } = isConnect;
public bool IsConnect => isConnect;

/// <inheritdoc/>
public override string ToString()
Expand Down Expand Up @@ -102,12 +102,12 @@ public sealed class DeviceDataChangeEventArgs(DeviceData device, DeviceState new
/// <summary>
/// Gets the state of the device after the reported change.
/// </summary>
public DeviceState NewState { get; } = newState;
public DeviceState NewState => newState;

/// <summary>
/// Gets the state of the device before the reported change.
/// </summary>
public DeviceState OldState { get; } = oldState;
public DeviceState OldState => oldState;

/// <inheritdoc/>
public override string ToString()
Expand Down
6 changes: 3 additions & 3 deletions AdvancedSharpAdbClient/Models/FramebufferHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public FramebufferHeader(ReadOnlySpan<byte> data) : this()
public ColorData Alpha { get; init; }

/// <summary>
/// The length of the head in bytes.
/// Gets the length of the head in bytes.
/// </summary>
public int Count => Version < 2 ? MiniLength : MaxLength;

Expand Down Expand Up @@ -347,8 +347,8 @@ private PixelFormat StandardizePixelFormat(ref byte[] buffer)
int blueIndex = (int)Blue.Offset / 8;
int greenIndex = (int)Green.Offset / 8;
int alphaIndex = (int)Alpha.Offset / 8;

byte[] array = new byte[buffer.Length];
byte[] array = new byte[(int)Size * 4];
// Loop over the array and re-order as required
for (int i = 0; i < (int)Size; i += 4)
{
Expand Down
2 changes: 1 addition & 1 deletion AdvancedSharpAdbClient/Models/InstallProgress.EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public InstallProgressEventArgs(int packageFinished, int packageRequired, Packag
/// <summary>
/// Gets the state of the installation.
/// </summary>
public PackageInstallProgressState State { get; } = state;
public PackageInstallProgressState State => state;

/// <summary>
/// Gets the number of packages which is finished operation.
Expand Down
4 changes: 2 additions & 2 deletions AdvancedSharpAdbClient/Models/SyncService.EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public sealed class SyncProgressChangedEventArgs(long current, long total) : Eve
/// Gets the number of bytes sync to the local computer.
/// </summary>
/// <value>An <see cref="long"/> representing the number of sync bytes.</value>
public long ReceivedBytesSize { get; } = current;
public long ReceivedBytesSize => current;

/// <summary>
/// Gets the total number of bytes for the sync operation.
/// </summary>
/// <value>An <see cref="long"/> representing the total size of the download, in bytes.</value>
public long TotalBytesToReceive { get; } = total;
public long TotalBytesToReceive => total;

/// <summary>
/// Gets the number of progress percentage (from <see langword="0"/> to <see langword="100"/>) for the sync operation.
Expand Down

0 comments on commit 4714c48

Please sign in to comment.