Skip to content

Commit

Permalink
.NET Core compatibility fixes, fixes related to outdated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qmfrederik committed Apr 18, 2017
1 parent 737d36f commit 6499995
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 42 deletions.
2 changes: 1 addition & 1 deletion SharpAdbClient.Tests/LoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task ReadLogTests()
Assert.AreEqual(new DateTime(2015, 11, 14, 23, 38, 20, 590, DateTimeKind.Utc), log.TimeStamp);

var androidLog = (AndroidLogEntry)log;
Assert.AreEqual(4, androidLog.Priority);
Assert.AreEqual(Priority.Info, androidLog.Priority);
Assert.AreEqual("ActivityManager", androidLog.Tag);
Assert.AreEqual("Start proc com.google.android.gm for broadcast com.google.android.gm/.widget.GmailWidgetProvider: pid=7026 uid=10066 gids={50066, 9997, 3003, 1028, 1015} abi=x86", androidLog.Message);

Expand Down
57 changes: 57 additions & 0 deletions SharpAdbClient.Tests/SharpAdbClient.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp1.1;net451</TargetFrameworks>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>SharpAdbClient.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Moq" Version="4.7.8" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.14" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.14" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SharpAdbClient\SharpAdbClient.csproj" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<ItemGroup>
<None Update="dumpsys_package.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="framebuffer.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="framebufferheader-empty.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="framebufferheader.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="fstab.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="logcat.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="logcatevents.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="test.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
<PackageReference Include="System.Diagnostics.StackTrace">
<Version>4.3.0</Version>
</PackageReference>
</ItemGroup>

</Project>
16 changes: 8 additions & 8 deletions SharpAdbClient.Tests/TracingAdbSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ public override void Dispose()

public override void Read(byte[] data)
{
StackTrace trace = new StackTrace(false);
StackTrace trace = new StackTrace((Exception)null, false);

base.Read(data);

if (trace.GetFrame(1).GetMethod().DeclaringType != typeof(AdbSocket))
if (trace.GetFrames()[0].GetMethod().DeclaringType != typeof(AdbSocket))
{
this.SyncDataReceived.Enqueue(data);
}
}

public override void Read(byte[] data, int length)
{
StackTrace trace = new StackTrace(false);
StackTrace trace = new StackTrace((Exception)null, false);

base.Read(data, length);

if (trace.GetFrame(1).GetMethod().DeclaringType != typeof(AdbSocket))
if (trace.GetFrames()[0].GetMethod().DeclaringType != typeof(AdbSocket))
{
this.SyncDataReceived.Enqueue(data.Take(length).ToArray());
}
Expand Down Expand Up @@ -158,9 +158,9 @@ public override void SendSyncRequest(SyncCommand command, string path)

public override void SendSyncRequest(SyncCommand command, int length)
{
StackTrace trace = new StackTrace(false);
var trace = new StackTrace((Exception)null, false);

if (trace.GetFrame(1).GetMethod().DeclaringType != typeof(AdbSocket))
if (trace.GetFrames()[0].GetMethod().DeclaringType != typeof(AdbSocket))
{
this.SyncRequests.Add(new Tuple<SyncCommand, string>(command, length.ToString()));
}
Expand All @@ -177,11 +177,11 @@ public override SyncCommand ReadSyncResponse()

public override void Send(byte[] data, int length)
{
StackTrace trace = new StackTrace(false);
StackTrace trace = new StackTrace((Exception)null, false);

base.Send(data, length);

if (trace.GetFrame(1).GetMethod().DeclaringType != typeof(AdbSocket))
if (trace.GetFrames()[0].GetMethod().DeclaringType != typeof(AdbSocket))
{
this.SyncDataSent.Enqueue(data.Take(length).ToArray());
}
Expand Down
31 changes: 7 additions & 24 deletions SharpAdbClient/TcpSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class TcpSocket : ITcpSocket
/// </summary>
public TcpSocket()
{
this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -53,7 +54,11 @@ public int ReceiveBufferSize
/// <inheritdoc/>
public void Connect(EndPoint endPoint)
{
this.socket = CreateSocket(endPoint);
if (!(endPoint is IPEndPoint || endPoint is DnsEndPoint))
{
throw new NotSupportedException();
}

this.socket.Connect(endPoint);
this.socket.Blocking = true;
this.endPoint = endPoint;
Expand All @@ -68,7 +73,7 @@ public void Reconnect()
return;
}

this.socket = CreateSocket(this.endPoint);
this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
this.Connect(this.endPoint);
}

Expand Down Expand Up @@ -101,27 +106,5 @@ public Task<int> ReceiveAsync(byte[] buffer, int offset, int size, SocketFlags s
{
return this.socket.ReceiveAsync(buffer, offset, size, socketFlags, cancellationToken);
}

/// <summary>
/// Creates a new, uninitialized socket which can connect to an ADB server.
/// </summary>
/// <param name="endPoint">
/// The <see cref="EndPoint"/> to which to connect. Currently <see cref="IPEndPoint"/> and <see cref="DnsEndPoint"/>
/// endpoint types are supported.
/// </param>
/// <returns>
/// A new <see cref="Socket"/> which can connect to an ADB server.
/// </returns>
internal static Socket CreateSocket(EndPoint endPoint)
{
if (endPoint is IPEndPoint || endPoint is DnsEndPoint)
{
return new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
else
{
throw new NotSupportedException("Only TCP sockets are supported");
}
}
}
}
13 changes: 4 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,17 @@ assembly_info:
assembly_informational_version: '{version}'

build_script:
- cmd: cd SharpAdbClient
- cmd: cd %APPVEYOR_BUILD_FOLDER%\SharpAdbClient
- cmd: dotnet restore
- cmd: dotnet build -c Release --version-suffix beta%APPVEYOR_BUILD_NUMBER%
- cmd: dotnet pack -c Release --version-suffix beta%APPVEYOR_BUILD_NUMBER%

test_script:
- cmd: cd ..\SharpAdbClient.Tests\
- cmd: cd %APPVEYOR_BUILD_FOLDER%\SharpAdbClient.Tests\
- cmd: dotnet restore
- cmd: dotnet build
- cmd: dotnet vstest bin\Debug\netcoreapp1.1\SharpAdbClient.Tests.dll /testcasefilter:TestCategory!=IntegrationTest /logger:Appveyor
- cmd: dotnet vstest bin\Debug\netcoreapp1.1\SharpAdbClient.Tests.dll /testcasefilter:"TestCategory!=IntegrationTest & TestCategory!=PerformanceTest"

on_success:
- ps: Push-AppveyorArtifact "bin\Release\SharpAdbClient.2.1.0-beta$($env:APPVEYOR_BUILD_NUMBER).nupkg"
- ps: Push-AppveyorArtifact "bin\Release\SharpAdbClient.2.1.0-beta$($env:APPVEYOR_BUILD_NUMBER).symbols.nupkg"

nuget:
project_feed: true
account_feed: true
- ps: Push-AppveyorArtifact "$env:APPVEYOR_BUILD_FOLDER\SharpAdbClient\bin\Release\SharpAdbClient.2.1.0-beta$($env:APPVEYOR_BUILD_NUMBER).nupkg"

0 comments on commit 6499995

Please sign in to comment.