From fe920c511945f892c05d6120f1c25058ccb9aef5 Mon Sep 17 00:00:00 2001 From: camalot Date: Sat, 9 Apr 2016 23:47:00 -0500 Subject: [PATCH 01/24] redoing the tests --- .appveyor/DeployCodePlex.msbuild | 3 +- .appveyor/appveyor.after-build.ps1 | 23 +- .appveyor/appveyor.after-test.ps1 | 3 + .appveyor/appveyor.before-deployment.ps1 | 34 -- .appveyor/appveyor.install.ps1 | 4 +- .build/SharedProperties.msbuild | 4 +- .build/WebPublish.msbuild | 2 +- ...ish-changelog.txt => publishChangelog.txt} | 0 Madb.Site/Madb.Site.csproj | 4 +- Madb.Site/Web.config | 2 +- Madb.Site/packages.config | 4 +- Managed.Adb.Tests/AdbHelperTests.cs | 326 ---------------- Managed.Adb.Tests/AndroidDebugBridgeTests.cs | 34 -- Managed.Adb.Tests/BaseDeviceTests.cs | 16 - Managed.Adb.Tests/BatteryInfoTests.cs | 21 -- Managed.Adb.Tests/BusyBoxTests.cs | 69 ---- Managed.Adb.Tests/DeviceTests.cs | 22 -- Managed.Adb.Tests/FileEntryTests.cs | 39 -- Managed.Adb.Tests/FileSystemTests.cs | 62 ---- .../ForLinuxPath/ChangeExtensionTests.cs | 66 ++++ .../ForLinuxPath/CombineTests.cs | 347 ++++++++++++++++++ .../ForLinuxPath/GetDirectoryNameTests.cs | 109 ++++++ .../ForLinuxPath/GetPathWithoutFile.cs | 29 ++ .../ForLinuxPath/LinuxPathConsts.cs | 16 + Managed.Adb.Tests/LinuxPathTests.cs | 157 -------- Managed.Adb.Tests/Managed.Adb.Tests.csproj | 142 +++---- Managed.Adb.Tests/PackageManagerTests.cs | 40 -- Managed.Adb.Tests/Properties/AssemblyInfo.cs | 31 +- Managed.Adb.Tests/app.config | 6 +- Managed.Adb.Tests/madb.xunit | 6 - Managed.Adb.Tests/packages.config | 15 +- Managed.Adb.Tests/xunit.runner.json | 3 + Managed.AndroidDebugBridge.sln | 39 +- .../AndroidDebugBridge.cs | 17 - Managed.AndroidDebugBridge/IO/LinuxPath.cs | 46 +-- Managed.AndroidDebugBridge/Managed.Adb.csproj | 8 +- Managed.AndroidDebugBridge/packages.config | 2 +- 37 files changed, 765 insertions(+), 986 deletions(-) create mode 100644 .appveyor/appveyor.after-test.ps1 rename .build/{publish-changelog.txt => publishChangelog.txt} (100%) delete mode 100644 Managed.Adb.Tests/AdbHelperTests.cs delete mode 100644 Managed.Adb.Tests/AndroidDebugBridgeTests.cs delete mode 100644 Managed.Adb.Tests/BaseDeviceTests.cs delete mode 100644 Managed.Adb.Tests/BatteryInfoTests.cs delete mode 100644 Managed.Adb.Tests/BusyBoxTests.cs delete mode 100644 Managed.Adb.Tests/DeviceTests.cs delete mode 100644 Managed.Adb.Tests/FileEntryTests.cs delete mode 100644 Managed.Adb.Tests/FileSystemTests.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/CombineTests.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs delete mode 100644 Managed.Adb.Tests/LinuxPathTests.cs delete mode 100644 Managed.Adb.Tests/PackageManagerTests.cs delete mode 100644 Managed.Adb.Tests/madb.xunit create mode 100644 Managed.Adb.Tests/xunit.runner.json diff --git a/.appveyor/DeployCodePlex.msbuild b/.appveyor/DeployCodePlex.msbuild index 5cc5eee..ff162d2 100644 --- a/.appveyor/DeployCodePlex.msbuild +++ b/.appveyor/DeployCodePlex.msbuild @@ -23,7 +23,7 @@ 120 1200 - $(MSBuildProjectDirectory)\..\.build\publish-changelog.txt + $(MSBuildProjectDirectory)\..\.build\publishChangelog.txt $(MSBuildProjectDirectory)\codeplex-release.txt @@ -105,6 +105,7 @@ + diff --git a/.appveyor/appveyor.after-build.ps1 b/.appveyor/appveyor.after-build.ps1 index 76a883b..fc25e7b 100644 --- a/.appveyor/appveyor.after-build.ps1 +++ b/.appveyor/appveyor.after-build.ps1 @@ -1,10 +1,15 @@ -## THIS IS HERE BECAUSE THE 'BEFORE-DEPLOYMENT' DOESNT WANT TO RUN +## THIS IS HERE BECAUSE THE 'BEFORE-DEPLOYMENT' DOESNT WANT TO RUN UNLESS ONE OF THE DEPLOYMENTS EVALUATES TO TRUE ## AND IT IS PISSING ME OFF $commitMessageRegex = "^\[deploy\:(pre-release|draft|release)\]$"; +# read the publishChangelog file +if(-not $env:CI_RELEASE_DESCRIPTION) { + $env:CI_RELEASE_DESCRIPTION = (Get-Content -Path ".\.build\publishChangelog.txt" -Raw); +} + # Must come from master branch. # Must not have a PULL Request Number # Must match regex @@ -17,10 +22,9 @@ if ( $env:APPVEYOR_REPO_BRANCH -eq "master" ) { $env:CI_DEPLOY_WebDeploy = $true; $env:CI_DEPLOY_CodePlex = $false; $env:CI_DEPLOY_WEBAPI_RELEASE = $false; - $env:CI_DEPLOY_PUSHBULLET = $true; + $env:CI_DEPLOY_PUSHBULLET = $false; $env:CI_DEPLOY = $true; -} else { - # Do not assign a release number or deploy +} elseif ( $env:APPVEYOR_REPO_BRANCH -eq "develop" ) { $env:CI_DEPLOY_NUGET = $true; $env:CI_DEPLOY_GITHUB_PRE = $true; $env:CI_DEPLOY_GITHUB = $false; @@ -31,4 +35,15 @@ if ( $env:APPVEYOR_REPO_BRANCH -eq "master" ) { $env:CI_DEPLOY_WEBAPI_RELEASE = $false; $env:CI_DEPLOY_PUSHBULLET = $false; $env:CI_DEPLOY = $false; +} else { + $env:CI_DEPLOY_NUGET = $false; + $env:CI_DEPLOY_GITHUB_PRE = $false; + $env:CI_DEPLOY_GITHUB = $false; + $env:CI_DEPLOY_FTP = $false; + $env:CI_DEPLOY_WebHook = $false; + $env:CI_DEPLOY_WebDeploy = $false; + $env:CI_DEPLOY_CodePlex = $false; + $env:CI_DEPLOY_WEBAPI_RELEASE = $false; + $env:CI_DEPLOY_PUSHBULLET = $false; + $env:CI_DEPLOY = $false; } \ No newline at end of file diff --git a/.appveyor/appveyor.after-test.ps1 b/.appveyor/appveyor.after-test.ps1 new file mode 100644 index 0000000..30d17af --- /dev/null +++ b/.appveyor/appveyor.after-test.ps1 @@ -0,0 +1,3 @@ +.\packages\OpenCover.4.6.519\OpenCover.Console.exe -register:user -target:".\packages\xunit.runner.console.2.1.0\tools\xunit.console" -targetargs:".\Managed.Adb.Tests\bin\Debug\Managed.Adb.Tests.dll -nologo -noshadow -notrait ""category=IntegrationTest""" -filter:"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\managed.adb.coverage.xml +pip install codecov +codecov -f "managed.adb.coverage.xml" \ No newline at end of file diff --git a/.appveyor/appveyor.before-deployment.ps1 b/.appveyor/appveyor.before-deployment.ps1 index 6665df3..e69de29 100644 --- a/.appveyor/appveyor.before-deployment.ps1 +++ b/.appveyor/appveyor.before-deployment.ps1 @@ -1,34 +0,0 @@ -<# - # - # - #> - -#$commitMessageRegex = "^\[deploy\:(pre-release|draft|release)\]$"; - - -## Must come from master branch. -## Must not have a PULL Request Number -## Must match regex -#if ( ($env:APPVEYOR_REPO_BRANCH -eq "master") -and ($env:APPVEYOR_REPO_COMMIT_MESSAGE -match $commitMessageRegex) ) { -# $env:CI_DEPLOY_NUGET = $true; -# $env:CI_DEPLOY_GITHUB = $true; -# $env:CI_DEPLOY_FTP = $false; -# $env:CI_DEPLOY_WebHook = $true; -# $env:CI_DEPLOY_WebDeploy = $true; -# $env:CI_DEPLOY_CodePlex = $false; -# $env:CI_DEPLOY_WEBAPI_RELEASE = $false; -# $env:CI_DEPLOY_PUSHBULLET = $true; -# $env:CI_DEPLOY = $true; -#} else { -# # Do not assign a release number or deploy -# $env:CI_DEPLOY_NUGET = $true; -# $env:CI_DEPLOY_GITHUB_PRE = $true; -# $env:CI_DEPLOY_GITHUB = $false; -# $env:CI_DEPLOY_FTP = $false; -# $env:CI_DEPLOY_WebHook = $false; -# $env:CI_DEPLOY_WebDeploy = $false; -# $env:CI_DEPLOY_CodePlex = $false; -# $env:CI_DEPLOY_WEBAPI_RELEASE = $false; -# $env:CI_DEPLOY_PUSHBULLET = $false; -# $env:CI_DEPLOY = $false; -#} \ No newline at end of file diff --git a/.appveyor/appveyor.install.ps1 b/.appveyor/appveyor.install.ps1 index e6167f3..4dbf0eb 100644 --- a/.appveyor/appveyor.install.ps1 +++ b/.appveyor/appveyor.install.ps1 @@ -1,3 +1,3 @@ -choco install -y nuget.commandline --version 3.3.0; +choco install -y nuget.commandline -version 3.3.0; -$env:PATH = "C:\ProgramData\chocolatey\lib\NuGet.CommandLine\tools;$env:PATH"; \ No newline at end of file +$env:PATH = "C:\ProgramData\chocolatey\lib\NuGet.CommandLine\tools\;C:\Python34;C:\Python34\Scripts\;$env:PATH"; \ No newline at end of file diff --git a/.build/SharedProperties.msbuild b/.build/SharedProperties.msbuild index 035fb1d..5fdaac3 100644 --- a/.build/SharedProperties.msbuild +++ b/.build/SharedProperties.msbuild @@ -88,7 +88,7 @@ madbee $(CI_PROJECT_FRIENDLY_NAME).$(Platform) $(CI_PROJECT_FRIENDLY_NAME) - $(MSBuildProjectDirectory)\Build\publish-changelog.txt + $(MSBuildProjectDirectory)\Build\publishChangelog.txt $(CI_ARTIFACT_PATH)\$(Configuration)\nuget\ @@ -115,7 +115,7 @@ - + diff --git a/.build/WebPublish.msbuild b/.build/WebPublish.msbuild index 3476f98..9b25ac5 100644 --- a/.build/WebPublish.msbuild +++ b/.build/WebPublish.msbuild @@ -15,7 +15,7 @@ bin\ True - Configuration=$(Configuration);Platform=$(Platform);OutputPath=$(OutputPath);VisualStudioVersion=12.0;DefineConstants=MVC5 + Configuration=$(Configuration);Platform=$(Platform);OutputPath=$(OutputPath);VisualStudioVersion=14.0;DefineConstants=MVC5 diff --git a/.build/publish-changelog.txt b/.build/publishChangelog.txt similarity index 100% rename from .build/publish-changelog.txt rename to .build/publishChangelog.txt diff --git a/Madb.Site/Madb.Site.csproj b/Madb.Site/Madb.Site.csproj index a0e3727..3eac823 100644 --- a/Madb.Site/Madb.Site.csproj +++ b/Madb.Site/Madb.Site.csproj @@ -62,8 +62,8 @@ ..\packages\morelinq.1.1.0\lib\net35\MoreLinq.dll - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll True diff --git a/Madb.Site/Web.config b/Madb.Site/Web.config index da7437e..6f658cf 100644 --- a/Madb.Site/Web.config +++ b/Madb.Site/Web.config @@ -71,7 +71,7 @@ - + diff --git a/Madb.Site/packages.config b/Madb.Site/packages.config index 522e7c3..a8d80cb 100644 --- a/Madb.Site/packages.config +++ b/Madb.Site/packages.config @@ -3,7 +3,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/Managed.Adb.Tests/AdbHelperTests.cs b/Managed.Adb.Tests/AdbHelperTests.cs deleted file mode 100644 index 5d20336..0000000 --- a/Managed.Adb.Tests/AdbHelperTests.cs +++ /dev/null @@ -1,326 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; -using System.IO; -using Managed.Adb.IO; -using System.Drawing.Imaging; -using Managed.Adb.Exceptions; - -namespace Managed.Adb.Tests { - public class AdbHelperTests : BaseDeviceTests { - - - [Fact] - public void GetDevicesTest ( ) { - List devices = AdbHelper.Instance.GetDevices ( AndroidDebugBridge.SocketAddress ); - Assert.True ( devices.Count >= 1 ); - foreach ( var item in devices ) { - Console.WriteLine ( "{0}\t{1}{2}", item.SerialNumber, item.State, item.IsEmulator ? " - Emulator" : String.Empty ); - } - } - - [Fact] - public void KillAdbTest ( ) { - var device = GetFirstDevice ( ); - AdbHelper.Instance.KillAdb ( AndroidDebugBridge.SocketAddress ); - } - - [Fact] - public void DeviceGetMountPointsTest ( ) { - Device device = GetFirstDevice ( ); - foreach ( var item in device.MountPoints.Keys ) { - Console.WriteLine ( device.MountPoints[item] ); - } - - Assert.True ( device.MountPoints.ContainsKey ( "/system" ) ); - } - - [Fact] - public void DeviceRemountMountPointTest ( ) { - Device device = GetFirstDevice ( ); - - Assert.True ( device.MountPoints.ContainsKey ( "/system" ), "Device does not contain mount point /system" ); - bool isReadOnly = device.MountPoints["/system"].IsReadOnly; - - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - device.RemountMountPoint ( device.MountPoints["/system"], !isReadOnly ); - } ) ); - - Assert.Equal ( !isReadOnly, device.MountPoints["/system"].IsReadOnly ); - Console.WriteLine ( "Successfully mounted /system as {0}", !isReadOnly ? "ro" : "rw" ); - - // revert it back... - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - device.RemountMountPoint ( device.MountPoints["/system"], isReadOnly ); - } ) ); - Assert.Equal ( isReadOnly, device.MountPoints["/system"].IsReadOnly ); - Console.WriteLine ( "Successfully mounted /system as {0}", isReadOnly ? "ro" : "rw" ); - - } - - [Fact] - public void ExecuteRemoteCommandTest ( ) { - - Device device = GetFirstDevice ( ); - ConsoleOutputReceiver creciever = new ConsoleOutputReceiver ( ); - - - device.ExecuteShellCommand("pm list packages -f",creciever); - - Console.WriteLine ( "Executing 'ls':" ); - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - try { - device.ExecuteShellCommand ( "ls -lF --color=never", creciever ); - } catch ( UnknownOptionException ) { - device.ExecuteShellCommand ( "ls -l", creciever ); - } - } ) ); - - - Console.WriteLine ( "Executing 'busybox':" ); - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - bool hasBB = false; - try { - device.ExecuteShellCommand ( "busybox", creciever ); - hasBB = true; - } catch ( FileNotFoundException ) { - hasBB = false; - } finally { - Console.WriteLine ( "Busybox enabled: {0}", hasBB ); - } - } ) ); - - Console.WriteLine ( "Executing 'unknowncommand':" ); - Assert.Throws ( new Assert.ThrowsDelegate ( delegate ( ) { - device.ExecuteShellCommand ( "unknowncommand", creciever ); - } ) ); - - Console.WriteLine ( "Executing 'ls /system/foo'" ); - Assert.Throws ( new Assert.ThrowsDelegate ( delegate ( ) { - device.ExecuteShellCommand ("ls /system/foo", creciever ); - } ) ); - - } - - [Fact] - public void ExecuteRemoteRootCommandTest( ) { - Device device = GetFirstDevice ( ); - ConsoleOutputReceiver creciever = new ConsoleOutputReceiver ( ); - - Console.WriteLine ( "Executing 'ls':" ); - if ( device.CanSU ( ) ) { - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - try { - device.ExecuteRootShellCommand ( "busybox ls -lFa --color=never", creciever ); - } catch ( UnknownOptionException ) { - device.ExecuteRootShellCommand ( "ls -lF", creciever ); - } - } ) ); - } else { - // if the device doesn't have root, then we check that it is throwing the PermissionDeniedException - Assert.Throws ( new Assert.ThrowsDelegate(delegate ( ) { - try { - device.ExecuteRootShellCommand ( "busybox ls -lFa --color=never", creciever ); - } catch ( UnknownOptionException ) { - device.ExecuteRootShellCommand ( "ls -lF", creciever ); - } - } ) ); - } - } - - [Fact] - public void GetRawImageTest ( ) { - Device device = GetFirstDevice ( ); - - RawImage rawImage = device.Screenshot; - - Assert.NotNull ( rawImage ); - Assert.Equal ( 32, rawImage.Bpp ); - Assert.Equal ( 480, rawImage.Width ); - Assert.Equal ( 800, rawImage.Height ); - - rawImage.ToImage ( PixelFormat.Format32bppArgb ).Save ( @"c:\Users\Ryan\Desktop\file.png",ImageFormat.Png ); - - } - - [Fact] - public void FileListingServiceTest ( ) { - Device device = GetFirstDevice ( ); - device.FileListingService.ForceBusyBox = true; - FileEntry[] entries = device.FileListingService.GetChildren ( device.FileListingService.Root, false, null ); - foreach ( var item in entries ) { - Console.WriteLine ( item.FullPath ); - } - } - - [Fact] - public void SyncServicePullFileTest ( ) { - Device device = GetFirstDevice ( ); - using ( SyncService sync = device.SyncService ) { - String rfile = "/sdcard/bootanimations/bootanimation-cm.zip"; - FileEntry rentry = device.FileListingService.FindFileEntry ( rfile ); - - String lpath = Environment.GetFolderPath ( Environment.SpecialFolder.DesktopDirectory ); - String lfile = Path.Combine ( lpath, LinuxPath.GetFileName ( rfile ) ); - FileInfo lfi = new FileInfo ( lfile ); - SyncResult result = sync.PullFile ( rfile, lfile, new FileSyncProgressMonitor ( ) ); - - Assert.True ( lfi.Exists ); - Assert.True ( ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString ( result.Code ) ); - lfi.Delete ( ); - - result = sync.PullFile ( rentry, lfile, new FileSyncProgressMonitor ( ) ); - Assert.True ( lfi.Exists ); - Assert.True ( ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString ( result.Code ) ); - lfi.Delete ( ); - - } - } - - [Fact] - public void SyncServicePushFileTest ( ) { - String testFile = CreateTestFile ( ); - FileInfo localFile = new FileInfo ( testFile ); - String remoteFile = String.Format ( "/sdcard/{0}", Path.GetFileName ( testFile ) ); - Device device = GetFirstDevice ( ); - - - using ( SyncService sync = device.SyncService ) { - SyncResult result = sync.PushFile ( localFile.FullName, remoteFile, new FileSyncProgressMonitor ( ) ); - Assert.True ( ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString ( result.Code ) ); - FileEntry remoteEntry = null; - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - remoteEntry = device.FileListingService.FindFileEntry ( remoteFile ); - } ) ); - - // check the size - Assert.Equal ( localFile.Length, remoteEntry.Size ); - - // clean up temp file on sdcard - device.ExecuteShellCommand ( String.Format ( "rm {0}", remoteEntry.FullEscapedPath ), new ConsoleOutputReceiver ( ) ); - } - } - - [Fact] - public void SyncServicePullFilesTest ( ) { - Device device = GetFirstDevice ( ); - using ( SyncService sync = device.SyncService ) { - String lpath = Path.Combine ( Environment.GetFolderPath ( Environment.SpecialFolder.DesktopDirectory ), "apps" ); - String rpath = "/system/app/"; - DirectoryInfo ldir = new DirectoryInfo ( lpath ); - if ( !ldir.Exists ) { - ldir.Create ( ); - } - FileEntry fentry = device.FileListingService.FindFileEntry ( rpath ); - Assert.True ( fentry.IsDirectory ); - - FileEntry[] entries = device.FileListingService.GetChildren ( fentry, false, null ); - SyncResult result = sync.Pull ( entries, ldir.FullName, new FileSyncProgressMonitor ( ) ); - - Assert.True ( ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString ( result.Code ) ); - } - } - - [Fact] - public void DeviceInstallPackageTest ( ) { - Device device = GetFirstDevice ( ); - String package = Path.Combine ( Environment.GetFolderPath ( Environment.SpecialFolder.DesktopDirectory ), "com.camalotdesigns.httpdump.apk" ); - Assert.True ( File.Exists ( package ) ); - - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - device.InstallPackage ( package, false ); - } ) ); - } - - [Fact] - public void DeviceUninstallPackageTest ( ) { - Device device = GetFirstDevice ( ); - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - device.UninstallPackage ( "com.camalotdesigns.httpdump" ); - } ) ); - } - - [Fact] - public void DeviceEnvironmentVariablesTest ( ) { - Device device = GetFirstDevice ( ); - foreach ( var key in device.EnvironmentVariables.Keys ) { - Console.WriteLine ( "{0}={1}", key, device.EnvironmentVariables[key] ); - } - - Assert.True ( device.EnvironmentVariables.Count > 0 ); - Assert.True ( device.EnvironmentVariables.ContainsKey ( "ANDROID_ROOT" ) ); - } - - [Fact] - public void DevicePropertiesTest ( ) { - Device device = GetFirstDevice ( ); - foreach ( var key in device.Properties.Keys ) { - Console.WriteLine ( "[{0}]: {1}", key, device.Properties[key] ); - } - - Assert.True ( device.Properties.Count > 0 ); - Assert.True ( device.Properties.ContainsKey ( "ro.product.device" ) ); - } - - - - - private String CreateTestFile ( ) { - String tfile = Path.GetTempFileName ( ); - Random r = new Random ( (int)DateTime.Now.Ticks ); - - using ( var fs = new FileStream ( tfile, System.IO.FileMode.Create, FileAccess.Write ) ) { - for ( int i = 0; i < 1024; i++ ) { - byte[] buffer = new byte[1024]; - r.NextBytes ( buffer ); - fs.Write ( buffer, 0, buffer.Length ); - } - } - return tfile; - } - - - public class FileListingServiceReceiver : IListingReceiver { - - public void SetChildren ( FileEntry entry, FileEntry[] children ) { - entry.Children.Clear ( ); - entry.Children.AddRange ( children ); - } - - public void RefreshEntry ( FileEntry entry ) { - entry.FetchTime = 0; - } - } - - public class FileSyncProgressMonitor : ISyncProgressMonitor { - - public void Start ( long totalWork ) { - Console.WriteLine ( "Starting Transfer" ); - this.TotalWork = this.Remaining = totalWork; - Transfered = 0; - } - - public void Stop ( ) { - IsCanceled = true; - } - - public bool IsCanceled { get; private set; } - - public void StartSubTask ( String source, String destination ) { - Console.WriteLine ( "Syncing {0} -> {1}", source, destination ); - } - - public void Advance ( long work ) { - Transfered += work; - Remaining -= work; - Console.WriteLine ( "Transfered {0} of {1} - {2} remaining", Transfered, TotalWork, Remaining ); - } - - public long TotalWork { get; set; } - public long Remaining { get; set; } - public long Transfered { get; set; } - } - } -} diff --git a/Managed.Adb.Tests/AndroidDebugBridgeTests.cs b/Managed.Adb.Tests/AndroidDebugBridgeTests.cs deleted file mode 100644 index 72d6206..0000000 --- a/Managed.Adb.Tests/AndroidDebugBridgeTests.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; -using System.IO; -using MoreLinq; -namespace Managed.Adb.Tests { - public class AndroidDebugBridgeTests : BaseDeviceTests { - - [Fact] - public void CreateBridgeTest ( ) { - try { - AndroidDebugBridge adb = CreateBridge ( @"d:\android\android-sdk\platform-tools\adb.exe" ); - bool result = adb.Start ( ); - Assert.True ( result, "Failed to start ADB" ); - - adb.Devices.ForEach ( d => { - Console.WriteLine ( "{0}\t{1}", d.SerialNumber, d.State ); - } ); - - adb.Stop ( ); - } catch ( Exception ex ) { - Console.WriteLine ( ex.ToString ( ) ); - throw; - } - } - - private AndroidDebugBridge CreateBridge ( String location ) { - AndroidDebugBridge adb = AndroidDebugBridge.CreateBridge ( location, false ); - return adb; - } - } -} diff --git a/Managed.Adb.Tests/BaseDeviceTests.cs b/Managed.Adb.Tests/BaseDeviceTests.cs deleted file mode 100644 index 0138bf4..0000000 --- a/Managed.Adb.Tests/BaseDeviceTests.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; - -namespace Managed.Adb.Tests { - public class BaseDeviceTests { - protected Device GetFirstDevice( ) { - List devices = AdbHelper.Instance.GetDevices ( AndroidDebugBridge.SocketAddress ); - Assert.True ( devices.Count >= 1 ); - return devices[0]; - } - - } -} diff --git a/Managed.Adb.Tests/BatteryInfoTests.cs b/Managed.Adb.Tests/BatteryInfoTests.cs deleted file mode 100644 index 4d26bfc..0000000 --- a/Managed.Adb.Tests/BatteryInfoTests.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; - -namespace Managed.Adb.Tests { - public class BatteryInfoTests : BaseDeviceTests { - - [Fact] - public void GetBatteryInfoTest ( ) { - Device device = GetFirstDevice ( ); - Assert.NotNull ( device ); - - var batteryInfo = device.GetBatteryInfo ( ); - Assert.True ( batteryInfo.Present ); - Console.WriteLine ( batteryInfo.ToString ( ) ); - } - - } -} diff --git a/Managed.Adb.Tests/BusyBoxTests.cs b/Managed.Adb.Tests/BusyBoxTests.cs deleted file mode 100644 index 41d0135..0000000 --- a/Managed.Adb.Tests/BusyBoxTests.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.IO; -using Xunit; - -namespace Managed.Adb.Tests { - public class BusyBoxTests : BaseDeviceTests { - - [Fact] - public void GetCommandsTest( ) { - Device device = GetFirstDevice ( ); - bool avail = device.BusyBox.Available; - Assert.True ( avail, "BusyBox is not available" ); - - - foreach ( var item in device.BusyBox.Commands ) { - Console.Write ( "{0},", item ); - } - - Assert.True ( avail && device.BusyBox.Commands.Count > 0 ); - } - - [Fact] - public void InstallTest( ) { - Device device = GetFirstDevice ( ); - bool avail = device.BusyBox.Available; - if ( !avail ) { - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - bool result = device.BusyBox.Install ( "/sdcard/busybox" ); - Assert.True ( result, "BusyBox Install returned false" ); - } ) ); - } - - device.ExecuteShellCommand ( "printenv", new ConsoleOutputReceiver ( ) ); - - Assert.True ( device.BusyBox.Available, "BusyBox is not installed" ); - } - - [Fact] - public void ExecuteRemoteCommandTest( ) { - Device device = GetFirstDevice ( ); - ConsoleOutputReceiver creciever = new ConsoleOutputReceiver ( ); - - Console.WriteLine ( "Executing 'busybox':" ); - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - bool hasBB = false; - try { - device.ExecuteShellCommand ( "busybox", creciever ); - hasBB = true; - } catch ( FileNotFoundException ) { - hasBB = false; - } finally { - Console.WriteLine ( "Busybox enabled: {0}", hasBB ); - } - } ) ); - - - Console.WriteLine ( "Executing 'busybox ls': " ); - Assert.DoesNotThrow ( new Assert.ThrowsDelegate ( delegate ( ) { - try { - device.BusyBox.ExecuteShellCommand ( "ls", creciever ); - } catch ( Exception ex) { - Console.WriteLine ( ex.Message ); - throw; - } - } ) ); - } - - } -} diff --git a/Managed.Adb.Tests/DeviceTests.cs b/Managed.Adb.Tests/DeviceTests.cs deleted file mode 100644 index 936548d..0000000 --- a/Managed.Adb.Tests/DeviceTests.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; - -namespace Managed.Adb.Tests { - public class DeviceTests : BaseDeviceTests { - [Fact] - public void CanBackupTest ( ) { - var device = GetFirstDevice ( ); - - Assert.True ( device.CanBackup ( ) ); - } - - [Fact] - public void BackupTest ( ) { - var device = GetFirstDevice ( ); - device.Backup ( ); - } - } -} diff --git a/Managed.Adb.Tests/FileEntryTests.cs b/Managed.Adb.Tests/FileEntryTests.cs deleted file mode 100644 index 7319b22..0000000 --- a/Managed.Adb.Tests/FileEntryTests.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; - -namespace Managed.Adb.Tests { - public class FileEntryTests : BaseDeviceTests { - - [Fact] - public void FindEntryTest ( ) { - Device device = GetFirstDevice ( ); - - FileEntry fe = FileEntry.Find ( device, "/system/" ); - - fe = FileEntry.Find ( device, "/" ); - - - fe = FileEntry.Find ( device, "/system/bin/" ); - - fe = FileEntry.Find ( device, "/mnt/sdcard/Android/data/com.camalotdesigns.myandroider/Injector.jar" ); - // test links - fe = FileEntry.Find ( device, "/sdcard/Android/data/com.camalotdesigns.myandroider/Injector.jar" ); - - } - - - [Fact] - public void FindOrCreateTest( ) { - Device device = GetFirstDevice ( ); - var path ="/mnt/sdcard/test/delete/"; - FileEntry fe = FileEntry.FindOrCreate ( device, path ); - Assert.True ( fe.Exists ); - device.FileSystem.Delete ( fe.FullResolvedPath ); - } - - - } -} diff --git a/Managed.Adb.Tests/FileSystemTests.cs b/Managed.Adb.Tests/FileSystemTests.cs deleted file mode 100644 index 994f234..0000000 --- a/Managed.Adb.Tests/FileSystemTests.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; -using MoreLinq; -using Camalot.Common.Extensions; - -namespace Managed.Adb.Tests { - public class FileSystemTests : BaseDeviceTests { - [Fact] - public void GetDeviceBlocksTest( ) { - Device d = GetFirstDevice ( ); - IEnumerable blocks = d.FileSystem.DeviceBlocks; - blocks.ForEach ( b => { - Console.WriteLine ( b.ToString ( ) ); - } ); - Assert.True ( blocks.Count() > 0 ); - } - - [Fact] - public void MakeDirectory( ) { - Device d = GetFirstDevice ( ); - var testPath = "/mnt/sdcard/test/delete/"; - Console.WriteLine ( "Making directory: {0}", testPath ); - d.FileSystem.MakeDirectory ( testPath ); - Assert.True ( d.FileSystem.Exists ( testPath ) ); - Console.WriteLine ( "Deleting {0}", testPath ); - d.FileSystem.Delete(testPath); - Assert.True ( !d.FileSystem.Exists ( testPath ) ); - - Console.WriteLine ( "Making directory (forced): {0}", testPath ); - d.FileSystem.MakeDirectory ( testPath,true ); - Assert.True ( d.FileSystem.Exists ( testPath ) ); - Console.WriteLine ( "Deleting {0}", testPath ); - d.FileSystem.Delete ( testPath ); - Assert.True ( !d.FileSystem.Exists ( testPath ) ); - } - - [Fact] - public void ResolveLink ( ) { - Device d = GetFirstDevice ( ); - var vendor = d.FileSystem.ResolveLink ( "/vendor" ); - Assert.Equal ( vendor, "/system/vendor" ); - Console.WriteLine ( "/vendor -> {0}".With ( vendor ) ); - - var nonsymlink = d.FileSystem.ResolveLink ( "/system" ); - Assert.Equal ( nonsymlink, "/system" ); - Console.WriteLine ( "/system -> {0}".With ( nonsymlink ) ); - - - var legacy = "/storage/emulated/legacy"; - var sdcard0 = "/storage/sdcard0"; - - var sdcard = d.FileSystem.ResolveLink ( "/sdcard" ); - // depending on the version of android - Assert.True ( sdcard.Equals ( legacy ) || sdcard.Equals ( sdcard0 ) ); - Console.WriteLine ( "/sdcard -> {0}".With ( sdcard ) ); - - } - } -} diff --git a/Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs b/Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs new file mode 100644 index 0000000..7d3d09c --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Camalot.Common.Extensions; +using Managed.Adb.IO; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class ChangeExtensionTests { + + [Fact] + public void WhenPathIsNull_ShouldReturnNull () { + string result = LinuxPath.ChangeExtension ( null, "ext" ); + Assert.Null ( result ); + } + + /// + /// Whens the path contains invalid character_ should throw argument exception. + /// + [Fact] + public void WhenPathContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.ChangeExtension ("/my-invalid-path/f-{0}".With ( LinuxPathConsts.InvalidChars[x]), "ext" ); + } catch (ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + } + + [Fact] + public void WhenPathLengthIsZero_ShouldReturnEmpty () { + string result = LinuxPath.ChangeExtension ( string.Empty, "ext" ); + Assert.Equal ( string.Empty, result ); + } + + [Fact] + public void WhenExtensionIsEmpty_ShouldReturnPath ( ) { + string result = LinuxPath.ChangeExtension ( "/my-path/to/file.ext1", string.Empty ); + Assert.Equal ( "/my-path/to/file.ext1", result ); + } + + [Fact] + public void WhenExtensionDoesNotStartWithDot_ShouldReturnChangedExtensionWithDot () { + string result = LinuxPath.ChangeExtension ( "/my-path/to/file.ext1", "ext2" ); + Assert.Equal ( "/my-path/to/file.ext2", result ); + } + + [Fact] + public void WhenExtensionStartsWithDot_ShouldReturnChangedExtension ( ) { + string result = LinuxPath.ChangeExtension ( "/my-path/to/file.ext1", ".ext2" ); + Assert.Equal ( "/my-path/to/file.ext2", result ); + } + + [Fact] + public void WhenPathHasNoExtension_ShouldReturnPathWithExtension ( ) { + string result = LinuxPath.ChangeExtension ( "/my-path/to/file", ".ext2" ); + Assert.Equal ( "/my-path/to/file.ext2", result ); + } + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/CombineTests.cs b/Managed.Adb.Tests/ForLinuxPath/CombineTests.cs new file mode 100644 index 0000000..c2823ca --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/CombineTests.cs @@ -0,0 +1,347 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Camalot.Common.Extensions; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class CombineTests { + [Fact] + public void When2ArgsAndPath1IsNull_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + Assert.Throws ( ( ) => { + var result = LinuxPath.Combine ( null, fixture.Create ( "path2" ) ); + } ); + } + [Fact] + public void When2ArgsAndPath2IsNull_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + Assert.Throws ( ( ) => { + var result = LinuxPath.Combine ( fixture.Create ( "path1" ), null ); + } ); + } + + [Fact] + public void When2ArgsAndPath1IsEmpty_ShouldReturnRelativePath2 ( ) { + var fixture = new Fixture ( ); + var p2 = fixture.Create ( "path2-" ); + var result = LinuxPath.Combine ( string.Empty, p2 ); + Assert.Equal ( "./{0}/".With ( p2 ), result ); + } + + [Fact] + public void When2ArgsAndPath1IsEmptyAndPath2IsRooted_ShouldReturnRootedPath2 ( ) { + var fixture = new Fixture ( ); + var p2 = fixture.Create ( "/path2-" ); + var result = LinuxPath.Combine ( string.Empty, p2 ); + Assert.Equal ( "/{0}/".With ( p2 ).REReplace ( "//", "/" ), result ); + } + + [Fact] + public void When2ArgsAndPath2IsEmpty_ShouldReturnRelativePath1 ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "path1-" ); + var p2 = string.Empty; + var result = LinuxPath.Combine ( p1, p2 ); + Assert.Equal ( "./{0}/".With ( p1 ), result ); + } + + [Fact] + public void When2ArgsAndPath2IsEmptyAndPath2IsRooted_ShouldReturnRootedPath1 ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1-" ); + var p2 = string.Empty; + var result = LinuxPath.Combine ( p1, p2 ); + Assert.Equal ( "/{0}/".With ( p1 ).REReplace ( "//", "/" ), result ); + } + + [Fact] + public void When2ArgsAndPath1ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.Combine ( "/{0}-{1}".With ( LinuxPathConsts.InvalidChars[x], fixture.Create ( "path1" ) ), fixture.Create ( "path2" ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + + } + + [Fact] + public void When2ArgsAndPath2ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), "{0}-{1}".With ( fixture.Create ( "path2" ), LinuxPathConsts.InvalidChars[x] ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + + } + + [Fact] + public void When2Args_ShouldReturnCombined ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1" ); + var p2 = fixture.Create ( "path2" ); + var result = LinuxPath.Combine ( p1, p2 ); + Assert.Equal ( "{0}/{1}".With ( p1, p2 ), result ); + } + + [Fact] + public void When2ArgsAndPathsHaveSeparators_ShouldReturnCombined ( ) { + var fixture = new Fixture ( ); + var p1 = "{0}/".With ( fixture.Create ( "/path1" ) ); + var p2 = fixture.Create ( "path2" ); + var result = LinuxPath.Combine ( p1, p2 ); + Assert.Equal ( "{0}/{1}".With ( p1, p2 ).REReplace ( "//", "/" ), result ); + } + + [Fact] + public void When2ArgsAndPath2IsRooted_ShouldReturnPath2 ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1-" ); + var p2 = fixture.Create ( "/path2-" ); + var result = LinuxPath.Combine ( p1, p2 ); + Assert.Equal ( "{0}/".With ( p2 ), result ); + } + + [Fact] + public void When3ArgsAndPath1IsNull_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + Assert.Throws ( ( ) => { + var result = LinuxPath.Combine ( null, fixture.Create ( "path2" ), fixture.Create ( "path3" ) ); + } ); + } + + [Fact] + public void When3ArgsAndPath2IsNull_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + Assert.Throws ( ( ) => { + var result = LinuxPath.Combine ( fixture.Create ( "path1" ), null, fixture.Create ( "path3" ) ); + } ); + } + + [Fact] + public void When3ArgsAndPath3IsNull_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + Assert.Throws ( ( ) => { + var result = LinuxPath.Combine ( fixture.Create ( "path1" ), fixture.Create ( "path2" ), null ); + } ); + } + + [Fact] + public void When3ArgsAndPath1ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.Combine ( "/{0}-{1}".With ( LinuxPathConsts.InvalidChars[x], fixture.Create ( "path1" ) ), fixture.Create ( "path2" ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + + } + + [Fact] + public void When3ArgsAndPath2ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), "{0}-{1}".With ( fixture.Create ( "path2" ), LinuxPathConsts.InvalidChars[x] ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + + } + + [Fact] + public void When3ArgsAndPath3ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), fixture.Create ( "path2" ), "{0}-{1}".With ( fixture.Create ( "path3" ), LinuxPathConsts.InvalidChars[x] ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + + } + + [Fact] + public void When3Args_ShouldReturnCombined ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1" ); + var p2 = fixture.Create ( "path2" ); + var p3 = fixture.Create ( "path3" ); + var result = LinuxPath.Combine ( p1, p2, p3 ); + Assert.Equal ( "{0}/{1}/{2}".With ( p1, p2, p3 ), result ); + } + + [Fact] + public void When4ArgsAndPath1IsNull_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + Assert.Throws ( ( ) => { + var result = LinuxPath.Combine ( null, fixture.Create ( "path2" ), fixture.Create ( "path3" ), fixture.Create ( "path4" ) ); + } ); + } + + [Fact] + public void When4ArgsAndPath2IsNull_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + Assert.Throws ( ( ) => { + var result = LinuxPath.Combine ( fixture.Create ( "path1" ), null, fixture.Create ( "path3" ), fixture.Create ( "path4" ) ); + } ); + } + + [Fact] + public void When4ArgsAndPath3IsNull_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + Assert.Throws ( ( ) => { + var result = LinuxPath.Combine ( fixture.Create ( "path1" ), fixture.Create ( "path2" ), null, fixture.Create ( "path4" ) ); + } ); + } + [Fact] + public void When4ArgsAndPath4IsNull_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + Assert.Throws ( ( ) => { + var result = LinuxPath.Combine ( fixture.Create ( "path1" ), fixture.Create ( "path2" ), fixture.Create ( "path3" ), null ); + } ); + } + + [Fact] + public void When4ArgsAndPath1ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.Combine ( "/{0}-{1}".With ( LinuxPathConsts.InvalidChars[x], fixture.Create ( "path1" ) ), fixture.Create ( "path2" ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + + } + + [Fact] + public void When4ArgsAndPath2ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), "{0}-{1}".With ( fixture.Create ( "path2" ), LinuxPathConsts.InvalidChars[x] ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + + } + + [Fact] + public void When4ArgsAndPath3ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), fixture.Create ( "path2" ), "{0}-{1}".With ( fixture.Create ( "path3" ), LinuxPathConsts.InvalidChars[x] ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + + } + + [Fact] + public void When4ArgsAndPath4ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), fixture.Create ( "path2" ), fixture.Create ( "path3" ), "{0}-{1}".With ( fixture.Create ( "path4" ), LinuxPathConsts.InvalidChars[x] ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + + } + + [Fact] + public void When4Args_ShouldReturnCombined ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1" ); + var p2 = fixture.Create ( "path2/" ); + var p3 = fixture.Create ( "./path3" ); + var p4 = fixture.Create ( "path4/" ); + var result = LinuxPath.Combine ( p1, p2, p3, p4 ); + Assert.Equal ( "{0}/{1}/{2}/{3}".With ( p1, p2, p3, p4 ), result ); + } + + [Fact] + public void WhenArgsArray_ShouldReturnCombined ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1" ); + var p2 = fixture.Create ( "path2" ); + var p3 = fixture.Create ( "path3" ); + var p4 = fixture.Create ( "path4" ); + var p5 = fixture.Create ( "path5" ); + var result = LinuxPath.Combine ( p1, p2, p3, p4, p5 ); + var expected = "{0}/{1}/{2}/{3}/{4}".With ( p1, p2, p3, p4, p5 ); + Assert.Equal ( expected, result ); + } + + [Fact] + public void WhenArgsArrayIsNull_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + string[] args = null; + Assert.Throws ( ( ) => { + LinuxPath.Combine ( args ); + } ); + } + + [Fact] + public void WhenArgsArrayContainsNullItem_ShouldThrowArgumentNullException ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1" ); + string p2 = null; + var p3 = fixture.Create ( "path3" ); + var p4 = fixture.Create ( "path4" ); + var p5 = fixture.Create ( "path5" ); + Assert.Throws ( ( ) => { + LinuxPath.Combine ( p1, p2, p3, p4, p5 ); + } ); + + } + + + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs b/Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs new file mode 100644 index 0000000..ac51dcd --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Camalot.Common.Extensions; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class GetDirectoryNameTests { + [Fact] + public void WhenPathIsNull_ShouldReturnNull ( ) { + var result = LinuxPath.GetDirectoryName ( null ); + Assert.Null ( result ); + } + + + [Fact] + public void WhenPathContainsInvalidCharacters_ShouldThrowException ( ) { + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + try { + string result = LinuxPath.GetDirectoryName ( "/my-invalid-path/f-{0}".With ( LinuxPathConsts.InvalidChars[x] ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + } + + [Fact] + public void WhenPathLengthIs1_ShouldReturnRelativePath ( ) { + string result = LinuxPath.GetDirectoryName ( "a" ); + Assert.Equal ( "./a/", result ); + } + + [Fact] + public void WhenPathLengthIsRoot_ShouldReturnRootPath ( ) { + string result = LinuxPath.GetDirectoryName ( "/" ); + Assert.Equal ( "/", result ); + } + + [Fact] + public void WhenPathRelative_ShouldReturnRelativePath ( ) { + var fixture = new Fixture ( ); + var p = fixture.Create ( "path" ); + string result = LinuxPath.GetDirectoryName ( p ); + Assert.Equal ( "./{0}/".With ( p ), result ); + } + + [Fact] + public void WhenPathRelativeWithFileWithExtension_ShouldReturnDirectoryRelativePath ( ) { + var fixture = new Fixture ( ); + var p = fixture.Create ( "path" ); + var pf = "{0}/file.ext".With ( p ); + string result = LinuxPath.GetDirectoryName ( pf ); + Assert.Equal ( "./{0}/".With ( p ), result ); + } + + + [Fact] + public void WhenPathRelativeWithFileWithoutExtension_ShouldReturnDirectoryRelativePath ( ) { + var fixture = new Fixture ( ); + var p = fixture.Create ( "path" ); + var pf = "{0}/file".With ( p ); + string result = LinuxPath.GetDirectoryName ( pf ); + Assert.Equal ( "./{0}/".With ( p ), result ); + } + + [Fact] + public void WhenPathRootedWithFileWithExtension_ShouldReturnDirectoryRootedPath ( ) { + var fixture = new Fixture ( ); + var p = fixture.Create ( "path" ); + var pf = "/{0}/file.ext".With ( p ); + string result = LinuxPath.GetDirectoryName ( pf ); + Assert.Equal ( "/{0}/".With ( p ), result ); + } + + + [Fact] + public void WhenPathRootedWithFileWithoutExtension_ShouldReturnDirectoryRootedPath ( ) { + var fixture = new Fixture ( ); + var p = fixture.Create ( "path" ); + var pf = "/{0}/file".With ( p ); + string result = LinuxPath.GetDirectoryName ( pf ); + Assert.Equal ( "/{0}/".With ( p ), result ); + } + + [Fact] + public void WhenPathRooted_ShouldReturnRootPath ( ) { + var fixture = new Fixture ( ); + var p = "/{0}/".With ( fixture.Create ( "path" ) ); + string result = LinuxPath.GetDirectoryName ( p ); + Assert.Equal ( p, result ); + } + + [Fact] + public void WhenPathIsLevels_ShouldReturnRootPath ( ) { + var fixture = new Fixture ( ); + var pname = fixture.Create ( "path" ); + var p = "/some/path/deep/{0}/".With ( pname ); + string result = LinuxPath.GetDirectoryName ( p ); + Assert.Equal ( "{0}".With ( p ), result ); + } + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs b/Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs new file mode 100644 index 0000000..3ba68a1 --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Camalot.Common.Extensions; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class GetPathWithoutFile { + [Fact] + public void WhenPathIsNull_ShouldReturnNull() { + Assert.Null ( LinuxPath.GetPathWithoutFile ( null ) ); + } + + [Fact] + public void WhenPathContainsFile_ShouldReturnPath ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "path1-" ); + var p2 = fixture.Create ( "path2-" ); + var f1 = fixture.Create ( "file-" ); + var p = "/{0}/{1}/{2}".With ( p1, p2, f1 ); + var result = LinuxPath.GetPathWithoutFile ( p ); + Assert.Equal ( "/{0}/{1}/".With ( p1, p2 ), result ); + } + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs b/Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs new file mode 100644 index 0000000..f431b9c --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Managed.Adb.Tests.ForLinuxPath { + internal class LinuxPathConsts { + internal static readonly char[] InvalidChars = new char[] { + '"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v', + '\f', '\r', '\x000e', '\x000f', '\x0010', '\x0011', '\x0012', '\x0013', '\x0014', '\x0015', '\x0016', '\x0017', '\x0018', '\x0019', '\x001a', '\x001b', + '\x001c', '\x001d', '\x001e', '\x001f' + }; + + } +} diff --git a/Managed.Adb.Tests/LinuxPathTests.cs b/Managed.Adb.Tests/LinuxPathTests.cs deleted file mode 100644 index 55f7606..0000000 --- a/Managed.Adb.Tests/LinuxPathTests.cs +++ /dev/null @@ -1,157 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Managed.Adb.IO; -using Xunit; - -namespace Managed.Adb.Tests { - public class LinuxPathTests { - - [Fact] - public void CombineTest ( ) { - String result = LinuxPath.Combine ( "/system", "busybox" ); - Assert.Equal ( "/system/busybox", result ); - - result = LinuxPath.Combine ( "/system/", "busybox" ); - Assert.Equal ( "/system/busybox", result ); - - result = LinuxPath.Combine ( "/system/xbin", "busybox" ); - Assert.Equal ( "/system/xbin/busybox", result ); - - result = LinuxPath.Combine ( "/system/xbin/", "busybox" ); - Assert.Equal ( "/system/xbin/busybox", result ); - - result = LinuxPath.Combine ( "/system//xbin", "busybox" ); - Assert.Equal ( "/system/xbin/busybox", result ); - - result = LinuxPath.Combine ( "/system","xbin", "busybox" ); - Assert.Equal ( "/system/xbin/busybox", result ); - - result = LinuxPath.Combine ( "/system", "xbin", "really", "long", "path" ,"to", "nothing" ); - Assert.Equal ( "/system/xbin/really/long/path/to/nothing", result ); - } - - [Fact] - public void GetDirectoryNameTest ( ) { - String result = LinuxPath.GetDirectoryName ( "/system/busybox" ); - Assert.Equal ( "/system/", result ); - - result = LinuxPath.GetDirectoryName ( "/" ); - Assert.Equal ( "/", result ); - - result = LinuxPath.GetDirectoryName ( "/system/xbin/" ); - Assert.Equal ( "/system/xbin/", result ); - } - - [Fact] - public void GetFileNameTest ( ) { - String result = LinuxPath.GetFileName ( "/system/busybox" ); - Assert.Equal ( "busybox", result ); - - result = LinuxPath.GetFileName ( "/" ); - Assert.Equal ( "", result ); - - result = LinuxPath.GetFileName ( "/system/xbin/" ); - Assert.Equal ( "", result ); - - result = LinuxPath.GetFileName ( "/system/xbin/file.ext" ); - Assert.Equal ( "file.ext", result ); - } - - - [Fact] - public void GetFileNameExtensionTest ( ) { - String result = LinuxPath.GetExtension ( "/system/busybox" ); - Assert.Equal ( "", result ); - - result = LinuxPath.GetExtension ( "/" ); - Assert.Equal ( "", result ); - - result = LinuxPath.GetExtension ( "/system/xbin/" ); - Assert.Equal ( "", result ); - - result = LinuxPath.GetExtension ( "/system/xbin/file.ext" ); - Assert.Equal ( ".ext", result ); - } - - [Fact] - public void GetFileNameWithoutExtensionTest ( ) { - String result = LinuxPath.GetFileNameWithoutExtension ( "/system/busybox" ); - Assert.Equal ( "busybox", result ); - - result = LinuxPath.GetFileNameWithoutExtension ( "/" ); - Assert.Equal ( "", result ); - - result = LinuxPath.GetFileNameWithoutExtension ( "/system/xbin/" ); - Assert.Equal ( "", result ); - - result = LinuxPath.GetFileNameWithoutExtension ( "/system/xbin/file.ext" ); - Assert.Equal ( "file", result ); - } - - [Fact] - public void ChangeExtensionTest ( ) { - String result = LinuxPath.ChangeExtension ( "/system/busybox", "foo" ); - Assert.Equal ( "/system/busybox.foo", result ); - - result = LinuxPath.ChangeExtension ( "/system/xbin/file.ext", "myext" ); - Assert.Equal ( "/system/xbin/file.myext", result ); - - result = LinuxPath.ChangeExtension ( "/system/xbin/file.ext", "" ); - Assert.Equal ( "/system/xbin/file", result ); - - result = LinuxPath.ChangeExtension ( "/system/busybox.foo", "" ); - Assert.Equal ( "/system/busybox", result ); - } - - [Fact] - public void GetPathWithoutFileTest ( ) { - String result = LinuxPath.GetPathWithoutFile ( "/system/busybox" ); - Assert.Equal ( "/system/", result ); - - result = LinuxPath.GetPathWithoutFile ( "/system/xbin/" ); - Assert.Equal ( "/system/xbin/", result ); - - result = LinuxPath.GetPathWithoutFile ( "/system/xbin/file.ext"); - Assert.Equal ( "/system/xbin/", result ); - } - - [Fact] - public void GetPathRootTest ( ) { - String result = LinuxPath.GetPathRoot ( "/system/busybox" ); - Assert.Equal ( "/", result ); - - result = LinuxPath.GetPathRoot ( "/system/xbin/" ); - Assert.Equal ( "/", result ); - - result = LinuxPath.GetPathRoot ( "/system/xbin/file.ext" ); - Assert.Equal ( "/", result ); - } - - - [Fact] - public void IsPathRootedTest ( ) { - bool result = LinuxPath.IsPathRooted ( "/system/busybox" ); - Assert.Equal ( true, result ); - - result = LinuxPath.IsPathRooted ( "/system/xbin/" ); - Assert.Equal ( true, result ); - - result = LinuxPath.IsPathRooted ( "system/xbin/" ); - Assert.Equal ( false, result ); - } - - [Fact] - public void HasExtensionTest ( ) { - bool result = LinuxPath.HasExtension ( "/system/busybox" ); - Assert.Equal ( false, result ); - - result = LinuxPath.HasExtension ( "/system/xbin.foo/" ); - Assert.Equal ( false, result ); - - result = LinuxPath.HasExtension ( "system/xbin/file.ext" ); - Assert.Equal ( true, result ); - } - } -} diff --git a/Managed.Adb.Tests/Managed.Adb.Tests.csproj b/Managed.Adb.Tests/Managed.Adb.Tests.csproj index 6a75857..05eb658 100644 --- a/Managed.Adb.Tests/Managed.Adb.Tests.csproj +++ b/Managed.Adb.Tests/Managed.Adb.Tests.csproj @@ -1,24 +1,25 @@  + + Debug AnyCPU - 8.0.30703 - 2.0 - {2C43B828-BE5E-47B6-93BB-A624B6B36633} + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47} Library Properties Managed.Adb.Tests Managed.Adb.Tests v4.5.1 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + b0edf53b - %24/madb/trunk/Managed.AndroidDebugBridge/Managed.Adb.Tests - . - https://tfs.codeplex.com/tfs/tfs02 - {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} - ..\ - true true @@ -28,7 +29,6 @@ DEBUG;TRACE prompt 4 - false pdbonly @@ -37,97 +37,103 @@ TRACE prompt 4 - false - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - true - true - false - - - bin\x64\Release\ - TRACE - true - pdbonly - AnyCPU - prompt - true - true - false ..\packages\Camalot.Common.1.0.5937.17275\lib\net45\Camalot.Common.dll True - - ..\packages\morelinq.1.1.0\lib\net35\MoreLinq.dll + + ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll + True + + + ..\packages\morelinq.1.0\lib\net35\MoreLinq.dll + True + + + ..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll + True - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\AutoFixture.3.43.0\lib\net40\Ploeh.AutoFixture.dll + True + + + ..\packages\AutoFixture.Xunit2.3.43.0\lib\net45\Ploeh.AutoFixture.Xunit2.dll True - - - - - - - ..\3rdParty\xunit\xunit.dll + + ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll + True + + + ..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll + True + + + ..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll + True + + + + + + + + - - Properties\SharedAssemblyInfo.cs - - - Properties\AssemblyVersionInfo.cs - - - - - - - - - - - + + + + + - - {65473257-E70F-410B-9269-D0C0F771EA87} + {65473257-e70f-410b-9269-d0c0f771ea87} Managed.Adb - - - + + + + + False + + + False + + + False + + + False + + + + + - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + + - " + Client.ClientData/*.Pid*/ diff --git a/Managed.AndroidDebugBridge/Device.cs b/Managed.AndroidDebugBridge/Device.cs index 4c846fe..30fef13 100644 --- a/Managed.AndroidDebugBridge/Device.cs +++ b/Managed.AndroidDebugBridge/Device.cs @@ -47,8 +47,17 @@ public enum DeviceState { /// /// public sealed class Device : IDevice { + /// + /// The mnt external storage + /// public const String MNT_EXTERNAL_STORAGE = "EXTERNAL_STORAGE"; + /// + /// mnt data + /// public const String MNT_DATA = "ANDROID_DATA"; + /// + /// The mnt root + /// public const String MNT_ROOT = "ANDROID_ROOT"; /// @@ -95,7 +104,7 @@ public sealed class Device : IDevice { public const String FIRST_EMULATOR_SN = "emulator-5554"; /** @deprecated Use {@link #PROP_BUILD_API_LEVEL}. */ - [Obsolete("Use PROP_BUILD_API_LEVEL")] + [Obsolete ( "Use PROP_BUILD_API_LEVEL" )] public const String PROP_BUILD_VERSION_NUMBER = PROP_BUILD_API_LEVEL; /// @@ -116,11 +125,10 @@ public sealed class Device : IDevice { private const int BATTERY_TIMEOUT = 2 * 1000; //2 seconds private const int GETPROP_TIMEOUT = 2 * 1000; //2 seconds private const int INSTALL_TIMEOUT = 2 * 60 * 1000; // 2 minutes - /// - /// - /// + /// + /// + /// private string _avdName; - private IPEndPoint _endpoint; private bool _canSU = false; private BatteryInfo _lastBatteryInfo = null; private DateTime _lastBatteryCheckTime = DateTime.MinValue; @@ -133,30 +141,30 @@ public sealed class Device : IDevice { /// The model. /// The product. /// The device. - public Device(string serial, DeviceState state, string model, string product, string device) { + public Device ( string serial, DeviceState state, string model, string product, string device ) { this.SerialNumber = serial; this.State = state; - MountPoints = new Dictionary(); - Properties = new Dictionary(); - EnvironmentVariables = new Dictionary(); - Clients = new List(); - FileSystem = new FileSystem(this); - BusyBox = new BusyBox(this); + MountPoints = new Dictionary ( ); + Properties = new Dictionary ( ); + EnvironmentVariables = new Dictionary ( ); + Clients = new List ( ); + FileSystem = new FileSystem ( this ); + BusyBox = new BusyBox ( this ); Model = model; Product = product; DeviceProperty = device; - RetrieveDeviceInfo(); + RetrieveDeviceInfo ( ); } /// /// Retrieves the device info. /// - private void RetrieveDeviceInfo() { - RefreshMountPoints(); - RefreshEnvironmentVariables(); - RefreshProperties(); + private void RetrieveDeviceInfo ( ) { + RefreshMountPoints ( ); + RefreshEnvironmentVariables ( ); + RefreshProperties ( ); } /// @@ -164,19 +172,19 @@ private void RetrieveDeviceInfo() { /// /// The device state string /// - private static DeviceState GetStateFromString(String state) { + private static DeviceState GetStateFromString ( String state ) { String tstate = state; - if(String.Compare(state, "device", false) == 0) { + if ( String.Compare ( state, "device", false ) == 0 ) { tstate = "online"; } - if(Enum.IsDefined(typeof(DeviceState), tstate)) { - return (DeviceState)Enum.Parse(typeof(DeviceState), tstate, true); + if ( Enum.IsDefined ( typeof ( DeviceState ), tstate ) ) { + return (DeviceState)Enum.Parse ( typeof ( DeviceState ), tstate, true ); } else { - foreach(var fi in typeof(DeviceState).GetFields()) { - if(string.Compare(fi.Name, tstate, true) == 0) { - return (DeviceState)fi.GetValue(null); + foreach ( var fi in typeof ( DeviceState ).GetFields ( ) ) { + if ( string.Compare ( fi.Name, tstate, true ) == 0 ) { + return (DeviceState)fi.GetValue ( null ); } } } @@ -190,16 +198,16 @@ private static DeviceState GetStateFromString(String state) { /// /// the line data for the device /// - public static Device CreateFromAdbData(String data) { - Regex re = new Regex(RE_DEVICELIST_INFO, RegexOptions.Compiled | RegexOptions.IgnoreCase); - Match m = re.Match(data); - if(m.Success) { + public static Device CreateFromAdbData ( String data ) { + Regex re = new Regex ( RE_DEVICELIST_INFO, RegexOptions.Compiled | RegexOptions.IgnoreCase ); + Match m = re.Match ( data ); + if ( m.Success ) { if ( m.Groups[2].Value != "host" ) { return new Device ( m.Groups[1].Value, GetStateFromString ( m.Groups[2].Value ), m.Groups[4].Value, m.Groups[3].Value, m.Groups[5].Value ); } return null; } else { - throw new ArgumentException("Invalid device list data"); + throw new ArgumentException ( "Invalid device list data" ); } } @@ -209,25 +217,26 @@ public static Device CreateFromAdbData(String data) { /// /// true if this device can perform a backup; otherwise, false. /// - public bool CanBackup() { - return this.FileSystem.Exists("/system/bin/bu"); + public bool CanBackup ( ) { + return this.FileSystem.Exists ( "/system/bin/bu" ); } /// /// Backups this device. /// - public void Backup() { - AdbHelper.Instance.Backup(AndroidDebugBridge.SocketAddress); +#pragma warning disable 618 + public void Backup ( ) { + AdbHelper.Instance.Backup ( AndroidDebugBridge.SocketAddress ); } - +#pragma warning restore /// /// Determines whether this instance can use the SU shell. /// /// /// true if this instance can use the SU shell; otherwise, false. /// - public bool CanSU() { - if(_canSU) { + public bool CanSU ( ) { + if ( _canSU ) { return _canSU; } @@ -236,11 +245,11 @@ public bool CanSU() { // this now checks if permission was denied and accounts for that. // The nulloutput receiver is fine here because it doesn't need to send the output anywhere, // the execute command can still handle the output with the null output receiver. - this.ExecuteRootShellCommand("echo \\\"I can haz root\\\"", NullOutputReceiver.Instance); + this.ExecuteRootShellCommand ( "echo \\\"I can haz root\\\"", NullOutputReceiver.Instance ); _canSU = true; - } catch(PermissionDeniedException) { + } catch ( PermissionDeniedException ) { _canSU = false; - } catch(FileNotFoundException) { + } catch ( FileNotFoundException ) { _canSU = false; } @@ -268,6 +277,12 @@ public bool CanSU() { /// public IPEndPoint Endpoint { get; private set; } + /// + /// Gets the type of the transport used to connect to this device. + /// + /// + /// The type of the transport. + /// public TransportType TransportType { get; private set; } @@ -277,8 +292,8 @@ public bool CanSU() { public String AvdName { get { return _avdName; } set { - if(!IsEmulator) { - throw new ArgumentException("Cannot set the AVD name of the device is not an emulator"); + if ( !IsEmulator ) { + throw new ArgumentException ( "Cannot set the AVD name of the device is not an emulator" ); } _avdName = value; } @@ -337,8 +352,8 @@ public String AvdName { /// /// the value or null if the property does not exist. /// - public String GetProperty(String name) { - return GetProperty(new String[] { name }); + public String GetProperty ( String name ) { + return GetProperty ( new String[] { name } ); } /// @@ -346,9 +361,9 @@ public String GetProperty(String name) { /// /// The array of property names. /// - public String GetProperty(params String[] name) { - foreach(var item in name) { - if(Properties.ContainsKey(item)) { + public String GetProperty ( params String[] name ) { + foreach ( var item in name ) { + if ( Properties.ContainsKey ( item ) ) { return Properties[item]; } } @@ -382,7 +397,7 @@ public bool IsOnline { /// true if this device is emulator; otherwise, false. public bool IsEmulator { get { - return Regex.Match(SerialNumber, RE_EMULATOR_SN).Success; + return Regex.Match ( SerialNumber, RE_EMULATOR_SN ).Success; } } @@ -423,10 +438,10 @@ public bool IsRecovery { /// /// The mount point. /// if set to true the mount poine will be set to read-only. - public void RemountMountPoint(MountPoint mnt, bool readOnly) { - String command = String.Format("mount -o {0},remount -t {1} {2} {3}", readOnly ? "ro" : "rw", mnt.FileSystem, mnt.Block, mnt.Name); - this.ExecuteShellCommand(command, NullOutputReceiver.Instance); - RefreshMountPoints(); + public void RemountMountPoint ( MountPoint mnt, bool readOnly ) { + String command = String.Format ( "mount -o {0},remount -t {1} {2} {3}", readOnly ? "ro" : "rw", mnt.FileSystem, mnt.Block, mnt.Name ); + this.ExecuteShellCommand ( command, NullOutputReceiver.Instance ); + RefreshMountPoints ( ); } /// @@ -435,12 +450,12 @@ public void RemountMountPoint(MountPoint mnt, bool readOnly) { /// the mount point /// if set to true the mount poine will be set to read-only. /// Throws if the mount point does not exist. - public void RemountMountPoint(String mountPoint, bool readOnly) { - if(MountPoints.ContainsKey(mountPoint)) { + public void RemountMountPoint ( String mountPoint, bool readOnly ) { + if ( MountPoints.ContainsKey ( mountPoint ) ) { MountPoint mnt = MountPoints[mountPoint]; - RemountMountPoint(mnt, readOnly); + RemountMountPoint ( mnt, readOnly ); } else { - throw new IOException("Invalid mount point"); + throw new IOException ( "Invalid mount point" ); } } @@ -448,11 +463,11 @@ public void RemountMountPoint(String mountPoint, bool readOnly) { /// /// Refreshes the mount points. /// - public void RefreshMountPoints() { - if(!IsOffline) { + public void RefreshMountPoints ( ) { + if ( !IsOffline ) { try { - this.ExecuteShellCommand(MountPointReceiver.MOUNT_COMMAND, new MountPointReceiver(this)); - } catch(AdbException) { + this.ExecuteShellCommand ( MountPointReceiver.MOUNT_COMMAND, new MountPointReceiver ( this ) ); + } catch ( AdbException ) { } } @@ -461,11 +476,11 @@ public void RefreshMountPoints() { /// /// Refreshes the environment variables. /// - public void RefreshEnvironmentVariables() { - if(!IsOffline) { + public void RefreshEnvironmentVariables ( ) { + if ( !IsOffline ) { try { - this.ExecuteShellCommand(EnvironmentVariablesReceiver.ENV_COMMAND, new EnvironmentVariablesReceiver(this)); - } catch(AdbException) { + this.ExecuteShellCommand ( EnvironmentVariablesReceiver.ENV_COMMAND, new EnvironmentVariablesReceiver ( this ) ); + } catch ( AdbException ) { } } @@ -474,12 +489,12 @@ public void RefreshEnvironmentVariables() { /// /// Refreshes the properties. /// - public void RefreshProperties() { - if(!IsOffline) { + public void RefreshProperties ( ) { + if ( !IsOffline ) { try { - this.ExecuteShellCommand(GetPropReceiver.GETPROP_COMMAND, new GetPropReceiver(this)); - } catch(AdbException aex) { - Log.w(LOG_TAG, aex); + this.ExecuteShellCommand ( GetPropReceiver.GETPROP_COMMAND, new GetPropReceiver ( this ) ); + } catch ( AdbException aex ) { + Log.w ( LOG_TAG, aex ); } } } @@ -488,23 +503,23 @@ public void RefreshProperties() { /// Reboots the device in to the specified state /// /// The reboot state - public void Reboot(String into) { - AdbHelper.Instance.Reboot(into, AndroidDebugBridge.SocketAddress, this); + public void Reboot ( String into ) { + AdbHelper.Instance.Reboot ( into, AndroidDebugBridge.SocketAddress, this ); } /// /// Reboots the device in to the specified state /// - public void Reboot() { - Reboot(String.Empty); + public void Reboot ( ) { + Reboot ( String.Empty ); } /// /// Gets the battery level. /// /// - public BatteryInfo GetBatteryInfo() { - return GetBatteryInfo(5 * 60 * 1000); + public BatteryInfo GetBatteryInfo ( ) { + return GetBatteryInfo ( 5 * 60 * 1000 ); } /// @@ -512,13 +527,13 @@ public BatteryInfo GetBatteryInfo() { /// /// The freshness. /// - public BatteryInfo GetBatteryInfo(long freshness) { - if(_lastBatteryInfo != null - && this._lastBatteryCheckTime > (DateTime.Now.AddMilliseconds(-freshness))) { + public BatteryInfo GetBatteryInfo ( long freshness ) { + if ( _lastBatteryInfo != null + && this._lastBatteryCheckTime > ( DateTime.Now.AddMilliseconds ( -freshness ) ) ) { return _lastBatteryInfo; } - var receiver = new BatteryReceiver(); - ExecuteShellCommand("dumpsys battery", receiver, BATTERY_TIMEOUT); + var receiver = new BatteryReceiver ( ); + ExecuteShellCommand ( "dumpsys battery", receiver, BATTERY_TIMEOUT ); _lastBatteryInfo = receiver.BatteryInfo; _lastBatteryCheckTime = DateTime.Now; return _lastBatteryInfo; @@ -553,8 +568,8 @@ public bool HasClients { /// Throws IOException if the connection with adb failed. public SyncService SyncService { get { - SyncService syncService = new SyncService(AndroidDebugBridge.SocketAddress, this); - if(syncService.Open()) { + SyncService syncService = new SyncService ( AndroidDebugBridge.SocketAddress, this ); + if ( syncService.Open ( ) ) { return syncService; } @@ -567,7 +582,7 @@ public SyncService SyncService { /// public PackageManager PackageManager { get { - return new PackageManager(this); + return new PackageManager ( this ); } } @@ -577,7 +592,7 @@ public PackageManager PackageManager { /// public FileListingService FileListingService { get { - return new FileListingService(this); + return new FileListingService ( this ); } } @@ -587,7 +602,7 @@ public FileListingService FileListingService { /// The screenshot. public RawImage Screenshot { get { - return AdbHelper.Instance.GetFrameBuffer(AndroidDebugBridge.SocketAddress, this); + return AdbHelper.Instance.GetFrameBuffer ( AndroidDebugBridge.SocketAddress, this ); } } @@ -596,8 +611,8 @@ public RawImage Screenshot { /// /// The command to execute /// The receiver object getting the result from the command. - public void ExecuteShellCommand(String command, IShellOutputReceiver receiver) { - ExecuteShellCommand(command, receiver, new object[] { }); + public void ExecuteShellCommand ( String command, IShellOutputReceiver receiver ) { + ExecuteShellCommand ( command, receiver, new object[] { } ); } /// @@ -606,8 +621,8 @@ public void ExecuteShellCommand(String command, IShellOutputReceiver receiver) { /// The command. /// The receiver. /// The timeout. - public void ExecuteShellCommand(String command, IShellOutputReceiver receiver, int timeout) { - ExecuteShellCommand(command, receiver, new object[] { }); + public void ExecuteShellCommand ( String command, IShellOutputReceiver receiver, int timeout ) { + ExecuteShellCommand ( command, receiver, new object[] { } ); } @@ -617,8 +632,8 @@ public void ExecuteShellCommand(String command, IShellOutputReceiver receiver, i /// The command. /// The receiver. /// The command args. - public void ExecuteShellCommand(String command, IShellOutputReceiver receiver, params object[] commandArgs) { - AdbHelper.Instance.ExecuteRemoteCommand(AndroidDebugBridge.SocketAddress, string.Format(command, commandArgs), this, receiver); + public void ExecuteShellCommand ( String command, IShellOutputReceiver receiver, params object[] commandArgs ) { + AdbHelper.Instance.ExecuteRemoteCommand ( AndroidDebugBridge.SocketAddress, string.Format ( command, commandArgs ), this, receiver ); } /// @@ -628,8 +643,8 @@ public void ExecuteShellCommand(String command, IShellOutputReceiver receiver, p /// The receiver. /// The timeout. /// The command args. - public void ExecuteShellCommand(String command, IShellOutputReceiver receiver, int timeout, params object[] commandArgs) { - AdbHelper.Instance.ExecuteRemoteCommand(AndroidDebugBridge.SocketAddress, string.Format(command, commandArgs), this, receiver); + public void ExecuteShellCommand ( String command, IShellOutputReceiver receiver, int timeout, params object[] commandArgs ) { + AdbHelper.Instance.ExecuteRemoteCommand ( AndroidDebugBridge.SocketAddress, string.Format ( command, commandArgs ), this, receiver ); } @@ -638,8 +653,9 @@ public void ExecuteShellCommand(String command, IShellOutputReceiver receiver, i /// /// The command. /// The receiver. - public void ExecuteRootShellCommand(String command, IShellOutputReceiver receiver, int timeout) { - ExecuteRootShellCommand(command, receiver, timeout, new object[] { }); + /// The timeout. + public void ExecuteRootShellCommand ( String command, IShellOutputReceiver receiver, int timeout ) { + ExecuteRootShellCommand ( command, receiver, timeout, new object[] { } ); } /// @@ -647,8 +663,8 @@ public void ExecuteRootShellCommand(String command, IShellOutputReceiver receive /// /// The command to execute /// The receiver object getting the result from the command. - public void ExecuteRootShellCommand(String command, IShellOutputReceiver receiver) { - ExecuteRootShellCommand(command, receiver, int.MaxValue); + public void ExecuteRootShellCommand ( String command, IShellOutputReceiver receiver ) { + ExecuteRootShellCommand ( command, receiver, int.MaxValue ); } /// @@ -657,8 +673,8 @@ public void ExecuteRootShellCommand(String command, IShellOutputReceiver receive /// The command. /// The receiver. /// The command args. - public void ExecuteRootShellCommand(String command, IShellOutputReceiver receiver, params object[] commandArgs) { - ExecuteRootShellCommand(command, receiver, int.MaxValue, commandArgs); + public void ExecuteRootShellCommand ( String command, IShellOutputReceiver receiver, params object[] commandArgs ) { + ExecuteRootShellCommand ( command, receiver, int.MaxValue, commandArgs ); } /// @@ -668,8 +684,8 @@ public void ExecuteRootShellCommand(String command, IShellOutputReceiver receive /// The receiver. /// The timeout. /// The command args. - public void ExecuteRootShellCommand(String command, IShellOutputReceiver receiver, int timeout, params object[] commandArgs) { - AdbHelper.Instance.ExecuteRemoteRootCommand(AndroidDebugBridge.SocketAddress, string.Format(command, commandArgs), this, receiver, timeout); + public void ExecuteRootShellCommand ( String command, IShellOutputReceiver receiver, int timeout, params object[] commandArgs ) { + AdbHelper.Instance.ExecuteRemoteRootCommand ( AndroidDebugBridge.SocketAddress, string.Format ( command, commandArgs ), this, receiver, timeout ); } @@ -677,8 +693,8 @@ public void ExecuteRootShellCommand(String command, IShellOutputReceiver receive /// Runs the event log service. /// /// The receiver. - public void RunEventLogService(LogReceiver receiver) { - AdbHelper.Instance.RunEventLogService(AndroidDebugBridge.SocketAddress, this, receiver); + public void RunEventLogService ( LogReceiver receiver ) { + AdbHelper.Instance.RunEventLogService ( AndroidDebugBridge.SocketAddress, this, receiver ); } /// @@ -686,8 +702,8 @@ public void RunEventLogService(LogReceiver receiver) { /// /// The logname. /// The receiver. - public void RunLogService(String logname, LogReceiver receiver) { - AdbHelper.Instance.RunLogService(AndroidDebugBridge.SocketAddress, this, logname, receiver); + public void RunLogService ( String logname, LogReceiver receiver ) { + AdbHelper.Instance.RunLogService ( AndroidDebugBridge.SocketAddress, this, logname, receiver ); } /// @@ -696,11 +712,11 @@ public void RunLogService(String logname, LogReceiver receiver) { /// the local port to forward /// the remote port. /// true if success. - public bool CreateForward(int localPort, int remotePort) { + public bool CreateForward ( int localPort, int remotePort ) { try { - return AdbHelper.Instance.CreateForward(AndroidDebugBridge.SocketAddress, this, localPort, remotePort); - } catch(IOException e) { - Log.w("ddms", e); + return AdbHelper.Instance.CreateForward ( AndroidDebugBridge.SocketAddress, this, localPort, remotePort ); + } catch ( IOException e ) { + Log.w ( "ddms", e ); return false; } } @@ -709,13 +725,14 @@ public bool CreateForward(int localPort, int remotePort) { /// Removes a port forwarding between a local and a remote port. /// /// the local port to forward - /// the remote port. - /// true if success. - public bool RemoveForward(int localPort) { + /// + /// true if success. + /// + public bool RemoveForward ( int localPort ) { try { - return AdbHelper.Instance.RemoveForward(AndroidDebugBridge.SocketAddress, this, localPort); - } catch(IOException e) { - Log.w("ddms", e); + return AdbHelper.Instance.RemoveForward ( AndroidDebugBridge.SocketAddress, this, localPort ); + } catch ( IOException e ) { + Log.w ( "ddms", e ); return false; } } @@ -789,10 +806,10 @@ void Update ( Client client, int changeMask ) { /// /// the absolute file system path to file on local host to install /// set to trueif re-install of app should be performed - public void InstallPackage(String packageFilePath, bool reinstall) { - String remoteFilePath = SyncPackageToDevice(packageFilePath); - InstallRemotePackage(remoteFilePath, reinstall); - RemoveRemotePackage(remoteFilePath); + public void InstallPackage ( String packageFilePath, bool reinstall ) { + String remoteFilePath = SyncPackageToDevice ( packageFilePath ); + InstallRemotePackage ( remoteFilePath, reinstall ); + RemoveRemotePackage ( remoteFilePath ); } /// @@ -801,30 +818,30 @@ public void InstallPackage(String packageFilePath, bool reinstall) { /// the absolute path to file on local host /// destination path on device for file /// if fatal error occurred when pushing file - public String SyncPackageToDevice(String localFilePath) { + public String SyncPackageToDevice ( String localFilePath ) { try { - String packageFileName = Path.GetFileName(localFilePath); + String packageFileName = Path.GetFileName ( localFilePath ); // only root has access to /data/local/tmp/... not sure how adb does it then... // workitem: 16823 // workitem: 19711 - String remoteFilePath = LinuxPath.Combine(TEMP_DIRECTORY_FOR_INSTALL, packageFileName); - Log.d(packageFileName, String.Format("Uploading {0} onto device '{1}'", packageFileName, SerialNumber)); + String remoteFilePath = LinuxPath.Combine ( TEMP_DIRECTORY_FOR_INSTALL, packageFileName ); + Log.d ( packageFileName, String.Format ( "Uploading {0} onto device '{1}'", packageFileName, SerialNumber ) ); SyncService sync = SyncService; - if(sync != null) { - String message = String.Format("Uploading file onto device '{0}'", SerialNumber); - Log.d(LOG_TAG, message); - SyncResult result = sync.PushFile(localFilePath, remoteFilePath, SyncService.NullProgressMonitor); + if ( sync != null ) { + String message = String.Format ( "Uploading file onto device '{0}'", SerialNumber ); + Log.d ( LOG_TAG, message ); + SyncResult result = sync.PushFile ( localFilePath, remoteFilePath, SyncService.NullProgressMonitor ); - if(result.Code != ErrorCodeHelper.RESULT_OK) { - throw new IOException(String.Format("Unable to upload file: {0}", result.Message)); + if ( result.Code != ErrorCodeHelper.RESULT_OK ) { + throw new IOException ( String.Format ( "Unable to upload file: {0}", result.Message ) ); } } else { - throw new IOException("Unable to open sync connection!"); + throw new IOException ( "Unable to open sync connection!" ); } return remoteFilePath; - } catch(IOException e) { - Log.e(LOG_TAG, String.Format("Unable to open sync connection! reason: {0}", e.Message)); + } catch ( IOException e ) { + Log.e ( LOG_TAG, String.Format ( "Unable to open sync connection! reason: {0}", e.Message ) ); throw; } } @@ -834,14 +851,14 @@ public String SyncPackageToDevice(String localFilePath) { /// /// absolute file path to package file on device /// set to true if re-install of app should be performed - public void InstallRemotePackage(String remoteFilePath, bool reinstall) { - InstallReceiver receiver = new InstallReceiver(); - FileEntry entry = FileListingService.FindFileEntry(remoteFilePath); - String cmd = String.Format("pm install {1}{0}", entry.FullEscapedPath, reinstall ? "-r " : String.Empty); - ExecuteShellCommand(cmd, receiver); + public void InstallRemotePackage ( String remoteFilePath, bool reinstall ) { + InstallReceiver receiver = new InstallReceiver ( ); + FileEntry entry = FileListingService.FindFileEntry ( remoteFilePath ); + String cmd = String.Format ( "pm install {1}{0}", entry.FullEscapedPath, reinstall ? "-r " : String.Empty ); + ExecuteShellCommand ( cmd, receiver ); - if(!String.IsNullOrEmpty(receiver.ErrorMessage)) { - throw new PackageInstallationException(receiver.ErrorMessage); + if ( !String.IsNullOrEmpty ( receiver.ErrorMessage ) ) { + throw new PackageInstallationException ( receiver.ErrorMessage ); } } @@ -851,12 +868,12 @@ public void InstallRemotePackage(String remoteFilePath, bool reinstall) { /// /// path on device of file to remove /// if file removal failed - public void RemoveRemotePackage(String remoteFilePath) { + public void RemoveRemotePackage ( String remoteFilePath ) { // now we delete the app we sync'ed try { - ExecuteShellCommand("rm " + remoteFilePath, NullOutputReceiver.Instance); - } catch(IOException e) { - Log.e(LOG_TAG, String.Format("Failed to delete temporary package: {0}", e.Message)); + ExecuteShellCommand ( "rm " + remoteFilePath, NullOutputReceiver.Instance ); + } catch ( IOException e ) { + Log.e ( LOG_TAG, String.Format ( "Failed to delete temporary package: {0}", e.Message ) ); throw e; } } @@ -865,14 +882,13 @@ public void RemoveRemotePackage(String remoteFilePath) { /// Uninstall an package from the device. /// /// Name of the package. + /// /// - /// - /// - public void UninstallPackage(String packageName) { - InstallReceiver receiver = new InstallReceiver(); - ExecuteShellCommand(String.Format("pm uninstall {0}", packageName), receiver); - if(!String.IsNullOrEmpty(receiver.ErrorMessage)) { - throw new PackageInstallationException(receiver.ErrorMessage); + public void UninstallPackage ( String packageName ) { + InstallReceiver receiver = new InstallReceiver ( ); + ExecuteShellCommand ( String.Format ( "pm uninstall {0}", packageName ), receiver ); + if ( !String.IsNullOrEmpty ( receiver.ErrorMessage ) ) { + throw new PackageInstallationException ( receiver.ErrorMessage ); } } @@ -880,9 +896,9 @@ public void UninstallPackage(String packageName) { /// Raises the event. /// /// The instance containing the event data. - internal void OnStateChanged(EventArgs e) { - if(this.StateChanged != null) { - this.StateChanged(this, e); + internal void OnStateChanged ( EventArgs e ) { + if ( this.StateChanged != null ) { + this.StateChanged ( this, e ); } } @@ -890,9 +906,9 @@ internal void OnStateChanged(EventArgs e) { /// Raises the event. /// /// The instance containing the event data. - internal void OnBuildInfoChanged(EventArgs e) { - if(this.BuildInfoChanged != null) { - this.BuildInfoChanged(this, e); + internal void OnBuildInfoChanged ( EventArgs e ) { + if ( this.BuildInfoChanged != null ) { + this.BuildInfoChanged ( this, e ); } } @@ -900,9 +916,9 @@ internal void OnBuildInfoChanged(EventArgs e) { /// Raises the event. /// /// The instance containing the event data. - internal void OnClientListChanged(EventArgs e) { - if(this.ClientListChanged != null) { - this.ClientListChanged(this, e); + internal void OnClientListChanged ( EventArgs e ) { + if ( this.ClientListChanged != null ) { + this.ClientListChanged ( this, e ); } } } diff --git a/Managed.AndroidDebugBridge/DeviceEventArgs.cs b/Managed.AndroidDebugBridge/DeviceEventArgs.cs index dab43d4..848b873 100644 --- a/Managed.AndroidDebugBridge/DeviceEventArgs.cs +++ b/Managed.AndroidDebugBridge/DeviceEventArgs.cs @@ -4,7 +4,11 @@ using System.Text; namespace Managed.Adb { - public class DeviceEventArgs : EventArgs { + /// + /// + /// + /// + public class DeviceEventArgs : EventArgs { /// /// Initializes a new instance of the class. diff --git a/Managed.AndroidDebugBridge/DeviceMonitor.cs b/Managed.AndroidDebugBridge/DeviceMonitor.cs index a680cd6..d76a223 100644 --- a/Managed.AndroidDebugBridge/DeviceMonitor.cs +++ b/Managed.AndroidDebugBridge/DeviceMonitor.cs @@ -401,6 +401,10 @@ private void QueryNewDeviceForInfo( Device device ) { } } + /// + /// Queries the new device for environment variables. + /// + /// The device. private void QueryNewDeviceForEnvironmentVariables( Device device ) { try { if ( device.State != DeviceState.Offline && device.State != DeviceState.Unknown ) { @@ -411,6 +415,10 @@ private void QueryNewDeviceForEnvironmentVariables( Device device ) { } } + /// + /// Queries the new device for mounting point. + /// + /// The device. private void QueryNewDeviceForMountingPoint( Device device ) { try { if ( device.State != DeviceState.Offline && device.State != DeviceState.Unknown ) { @@ -421,6 +429,11 @@ private void QueryNewDeviceForMountingPoint( Device device ) { } } + /// + /// Starts the monitoring device. + /// + /// The device. + /// private bool StartMonitoringDevice( Device device ) { Socket socket = OpenAdbConnection ( ); @@ -451,7 +464,7 @@ private bool StartMonitoringDevice( Device device ) { try { // attempt to close the socket if needed. socket.Close ( ); - } catch ( IOException e1 ) { + } catch ( IOException ) { // we can ignore that one. It may already have been closed. } Log.d ( TAG, "Connection Failure when starting to monitor device '{0}' : {1}", device, e.Message ); @@ -461,6 +474,9 @@ private bool StartMonitoringDevice( Device device ) { return false; } + /// + /// Starts the device monitor thread. + /// private void StartDeviceMonitorThread( ) { //Selector = Selector.Open(); Thread t = new Thread ( new ThreadStart ( DeviceClientMonitorLoop ) ); @@ -468,6 +484,9 @@ private void StartDeviceMonitorThread( ) { t.Start ( ); } + /// + /// Devices the client monitor loop. + /// private void DeviceClientMonitorLoop( ) { do { try { @@ -555,7 +574,7 @@ private void DeviceClientMonitorLoop( ) { } } }*/ - } catch ( IOException e ) { + } catch ( IOException ) { if ( !IsRunning ) { } @@ -724,7 +743,7 @@ private int ReadLength( Socket socket, byte[] buffer ) { try { int len = int.Parse ( msg, System.Globalization.NumberStyles.HexNumber ); return len; - } catch ( FormatException nfe ) { + } catch ( FormatException ) { // we'll throw an exception below. } } @@ -739,7 +758,7 @@ private int ReadLength( Socket socket, byte[] buffer ) { /// The socket. /// The data. /// - private String Read( Socket socket, byte[] data ) { + private string Read( Socket socket, byte[] data ) { int count = -1; int totalRead = 0; diff --git a/Managed.AndroidDebugBridge/ErrorCodeHelper.cs b/Managed.AndroidDebugBridge/ErrorCodeHelper.cs index 55ef5d1..5d3d029 100644 --- a/Managed.AndroidDebugBridge/ErrorCodeHelper.cs +++ b/Managed.AndroidDebugBridge/ErrorCodeHelper.cs @@ -4,6 +4,10 @@ using System.Text; namespace Managed.Adb { + /// + /// + /// + /// true public static class ErrorCodeHelper { /** Result code for transfer success. */ public const int RESULT_OK = 0; @@ -37,6 +41,11 @@ public static class ErrorCodeHelper { public const int RESULT_BUFFER_OVERRUN = 14; + /// + /// Errors the code to string. + /// + /// The code. + /// public static String ErrorCodeToString ( int code ) { switch ( code ) { case RESULT_OK: diff --git a/Managed.AndroidDebugBridge/Exceptions/AdbCommandRejectedException.cs b/Managed.AndroidDebugBridge/Exceptions/AdbCommandRejectedException.cs index d74f8f9..01dc914 100644 --- a/Managed.AndroidDebugBridge/Exceptions/AdbCommandRejectedException.cs +++ b/Managed.AndroidDebugBridge/Exceptions/AdbCommandRejectedException.cs @@ -9,17 +9,38 @@ namespace Managed.Adb.Exceptions { /// Exception thrown when adb refuses a command. /// public class AdbCommandRejectedException : AdbException { + /// + /// Initializes a new instance of the class. + /// + /// The message. public AdbCommandRejectedException ( String message ) : base ( message ) { IsDeviceOffline = message.Equals ( "device offline" ); WasErrorDuringDeviceSelection = false; } + /// + /// Initializes a new instance of the class. + /// + /// The message. + /// if set to true [error during device selection]. public AdbCommandRejectedException ( String message, bool errorDuringDeviceSelection ) : base ( message ) { WasErrorDuringDeviceSelection = errorDuringDeviceSelection; IsDeviceOffline = message.Equals ( "device offline" ); } + /// + /// Gets a value indicating whether this instance is device offline. + /// + /// + /// true if this instance is device offline; otherwise, false. + /// public bool IsDeviceOffline { get; private set; } + /// + /// Gets a value indicating whether [was error during device selection]. + /// + /// + /// true if [was error during device selection]; otherwise, false. + /// public bool WasErrorDuringDeviceSelection { get; private set; } } } diff --git a/Managed.AndroidDebugBridge/Exceptions/PermissionDeniedException.cs b/Managed.AndroidDebugBridge/Exceptions/PermissionDeniedException.cs index 94b521f..ddcf7a7 100644 --- a/Managed.AndroidDebugBridge/Exceptions/PermissionDeniedException.cs +++ b/Managed.AndroidDebugBridge/Exceptions/PermissionDeniedException.cs @@ -5,6 +5,10 @@ using System.Runtime.Serialization; namespace Managed.Adb.Exceptions { + /// + /// + /// + /// public class PermissionDeniedException : Exception { /// diff --git a/Managed.AndroidDebugBridge/Exceptions/ShellCommandUnresponsiveException.cs b/Managed.AndroidDebugBridge/Exceptions/ShellCommandUnresponsiveException.cs index 51e86f5..cd52e27 100644 --- a/Managed.AndroidDebugBridge/Exceptions/ShellCommandUnresponsiveException.cs +++ b/Managed.AndroidDebugBridge/Exceptions/ShellCommandUnresponsiveException.cs @@ -4,7 +4,14 @@ using System.Text; namespace Managed.Adb.Exceptions { + /// + /// + /// + /// public class ShellCommandUnresponsiveException : AdbException { + /// + /// Initializes a new instance of the class. + /// public ShellCommandUnresponsiveException ( ) : base("The shell command has become unresponsive"){ } diff --git a/Managed.AndroidDebugBridge/Extensions/IntegerHelper.cs b/Managed.AndroidDebugBridge/Extensions/IntegerHelper.cs index 886b6d1..7b9183f 100644 --- a/Managed.AndroidDebugBridge/Extensions/IntegerHelper.cs +++ b/Managed.AndroidDebugBridge/Extensions/IntegerHelper.cs @@ -117,67 +117,6 @@ public static T ToEnum ( this sbyte value ){ return (T)Enum.ToObject ( typeof ( T ), value ); } - /*// reverse byte order (16-bit) - /// - /// reverse byte order (16-bit) - /// - /// The value. - /// - public static UInt16 ReverseBytes ( this UInt16 value ) { - return (UInt16)( ( value & 0xFFU ) << 8 | ( value & 0xFF00U ) >> 8 ); - } - - // reverse byte order (32-bit) - /// - /// reverse byte order (32-bit) - /// - /// The value. - /// - public static UInt32 ReverseBytes ( this UInt32 value ) { - return ( value & 0x000000FFU ) << 24 | ( value & 0x0000FF00U ) << 8 | - ( value & 0x00FF0000U ) >> 8 | ( value & 0xFF000000U ) >> 24; - } - - /// - /// reverse byte order (32-bit) - /// - /// The value. - /// - public static Int32 ReverseBytes ( this Int32 value ) { - return BitConverter.ToInt32 ( ReverseByteArray ( BitConverter.GetBytes ( value ) ), 0 ); - } - - /// - /// reverse byte order (16-bit) - /// - /// The value. - /// - public static Int16 ReverseBytes ( this Int16 value ) { - return BitConverter.ToInt16 ( ReverseByteArray ( BitConverter.GetBytes ( value ) ), 0 ); - } - - /// - /// reverse byte order (64-bit) - /// - /// The value. - /// - public static Int64 ReverseBytes ( this Int64 value ) { - return BitConverter.ToInt16 ( ReverseByteArray ( BitConverter.GetBytes ( value ) ), 0 ); - } - - // reverse byte order (64-bit) - /// - /// reverse byte order (64-bit) - /// - /// The value. - /// - public static UInt64 ReverseBytes ( this UInt64 value ) { - return ( value & 0x00000000000000FFUL ) << 56 | ( value & 0x000000000000FF00UL ) << 40 | - ( value & 0x0000000000FF0000UL ) << 24 | ( value & 0x00000000FF000000UL ) << 8 | - ( value & 0x000000FF00000000UL ) >> 8 | ( value & 0x0000FF0000000000UL ) >> 24 | - ( value & 0x00FF000000000000UL ) >> 40 | ( value & 0xFF00000000000000UL ) >> 56; - }*/ - /// /// Reverses the byte array. /// diff --git a/Managed.AndroidDebugBridge/Extensions/ThrowIf.cs b/Managed.AndroidDebugBridge/Extensions/ThrowIf.cs index a1a67c5..048443c 100644 --- a/Managed.AndroidDebugBridge/Extensions/ThrowIf.cs +++ b/Managed.AndroidDebugBridge/Extensions/ThrowIf.cs @@ -19,18 +19,34 @@ internal static void ThrowIfNonPositive ( this int argument, Expression + /// Throws if null. + /// + /// + /// The argument. + /// The function. public static void ThrowIfNull ( this T argument, Expression> func ) where T : class { if ( argument == null ) { ThrowException ( s => new ArgumentNullException ( s ), func ); } } + /// + /// Throws if null or empty. + /// + /// The argument. + /// The function. public static void ThrowIfNullOrEmpty ( this String argument, Expression> func ) { if ( String.IsNullOrEmpty(argument) ) { ThrowException ( s => new ArgumentNullException ( s ), func ); } } + /// + /// Throws if null or white space. + /// + /// The argument. + /// The function. public static void ThrowIfNullOrWhiteSpace ( this String argument, Expression> func ) { if ( String.IsNullOrEmpty ( argument ) || String.IsNullOrEmpty(argument.Trim()) ) { ThrowException ( s => new ArgumentNullException ( s ), func ); diff --git a/Managed.AndroidDebugBridge/FilePermission.cs b/Managed.AndroidDebugBridge/FilePermission.cs index ab1c993..544477a 100644 --- a/Managed.AndroidDebugBridge/FilePermission.cs +++ b/Managed.AndroidDebugBridge/FilePermission.cs @@ -4,12 +4,23 @@ using System.Text; namespace Managed.Adb { + /// + /// + /// public class FilePermissions { + /// + /// Initializes a new instance of the class. + /// public FilePermissions ( ) : this("---------") { } + /// + /// Initializes a new instance of the class. + /// + /// The permissions. + /// public FilePermissions ( String permissions ) { if ( permissions.Length > 9 ) { permissions = permissions.Substring ( 1,9 ); @@ -24,14 +35,38 @@ public FilePermissions ( String permissions ) { Other = new FilePermission ( permissions.Substring ( 6, 3 ) ); } + /// + /// Initializes a new instance of the class. + /// + /// The user. + /// The group. + /// The other. public FilePermissions ( FilePermission user, FilePermission group, FilePermission other ) { User = user; Group = group; Other = other; - } + } + /// + /// Gets or sets the user permission. + /// + /// + /// The user. + /// public FilePermission User { get; set; } + /// + /// Gets or sets the group permission. + /// + /// + /// The group. + /// public FilePermission Group { get; set; } + /// + /// Gets or sets the other permission. + /// + /// + /// The other. + /// public FilePermission Other { get; set; } @@ -129,7 +164,13 @@ public FilePermission ( string linuxPermissions ) { /// public bool CanDelete { get; private set; } - public String ToString ( ) { + /// + /// Returns a string that represents the current object. + /// + /// + /// A string that represents the current object. + /// + public override string ToString ( ) { StringBuilder perm = new StringBuilder ( ); return perm.AppendFormat ( "{0}", CanRead ? "r" : "-" ).AppendFormat ( "{0}", CanWrite ? "w" : "-" ).AppendFormat ( "{0}", CanExecute ? CanDelete ? "x" : "t" : "-" ).ToString ( ); } diff --git a/Managed.AndroidDebugBridge/FileSystem.cs b/Managed.AndroidDebugBridge/FileSystem.cs index fdb73cb..68c59d1 100644 --- a/Managed.AndroidDebugBridge/FileSystem.cs +++ b/Managed.AndroidDebugBridge/FileSystem.cs @@ -8,6 +8,9 @@ using System.Text.RegularExpressions; namespace Managed.Adb { + /// + /// + /// public class FileSystem { /// @@ -83,7 +86,7 @@ public bool Exists ( String path ) { try { FileEntry fe = Device.FileListingService.FindFileEntry ( path ); return fe != null; - } catch ( FileNotFoundException e ) { + } catch ( FileNotFoundException ) { return false; } } else { @@ -259,12 +262,9 @@ public void Delete(String path) { /// /// The file entry. /// If the command fails. + /// If device is null or if path is null or empty. + public void Delete ( FileEntry fileEntry ) { - /// - /// If device is null - /// or - /// If path is null or empty. - /// Device.ThrowIfNull("Device"); fileEntry.ThrowIfNull ( "fileEntry" ); if ( fileEntry.Exists ) { @@ -428,7 +428,7 @@ public String ResolveLink ( String path ) { return ( string.IsNullOrWhiteSpace ( cresult.Result ) ) ? path : cresult.Result; } return cresult.Result; - } catch ( Exception e ) { + } catch ( Exception ) { // if the command doesn't exist then we just return the path. } return path; diff --git a/Managed.AndroidDebugBridge/IClient.cs b/Managed.AndroidDebugBridge/IClient.cs index 17223c0..22ed9c4 100644 --- a/Managed.AndroidDebugBridge/IClient.cs +++ b/Managed.AndroidDebugBridge/IClient.cs @@ -5,76 +5,312 @@ using System.Net.Sockets; namespace Managed.Adb { - [Flags] + /// + /// + /// + [Flags] public enum ClientChangeState { - Name = 0x0001, - DebuggerStatus = 0x0002, - Port = 0x0004, - ThreadMode = 0x0008, - ThreadData = 0x0010, - HeapMode = 0x0020, - HeapData = 0x0040, - NativeHeapData = 0x0080, - ThreadStackTrace = 0x0100, - HeapAllocations = 0x0200, - HeapAllocationStatus = 0x0400, - MethodProfilingStatus = 0x0800, - Info = Name | DebuggerStatus | Port, + /// + /// The name + /// + Name = 0x0001, + /// + /// The debugger status + /// + DebuggerStatus = 0x0002, + /// + /// The port + /// + Port = 0x0004, + /// + /// The thread mode + /// + ThreadMode = 0x0008, + /// + /// The thread data + /// + ThreadData = 0x0010, + /// + /// The heap mode + /// + HeapMode = 0x0020, + /// + /// The heap data + /// + HeapData = 0x0040, + /// + /// The native heap data + /// + NativeHeapData = 0x0080, + /// + /// The thread stack trace + /// + ThreadStackTrace = 0x0100, + /// + /// The heap allocations + /// + HeapAllocations = 0x0200, + /// + /// The heap allocation status + /// + HeapAllocationStatus = 0x0400, + /// + /// The method profiling status + /// + MethodProfilingStatus = 0x0800, + /// + /// The information + /// + Info = Name | DebuggerStatus | Port, } - public enum ClientConnectionState { - Init = 1, - NotJDWP = 2, - AwaitShake = 10, - NeedDDMPacket = 11, - NotDDM = 12, - Ready = 13, - Error = 20, - Disconnected = 21, + /// + /// + /// + public enum ClientConnectionState { + /// + /// The initialize + /// + Init = 1, + /// + /// The not JDWP + /// + NotJDWP = 2, + /// + /// The await shake + /// + AwaitShake = 10, + /// + /// The need DDM packet + /// + NeedDDMPacket = 11, + /// + /// The not DDM + /// + NotDDM = 12, + /// + /// The ready + /// + Ready = 13, + /// + /// The error + /// + Error = 20, + /// + /// The disconnected + /// + Disconnected = 21, } + /// + /// + /// + /// public interface IClient : IPacketConsumer { + /// + /// Gets the state of the connection. + /// + /// + /// The state of the connection. + /// ClientConnectionState ConnectionState { get; } + /// + /// Gets the state of the change. + /// + /// + /// The state of the change. + /// ClientChangeState ChangeState { get; } + /// + /// Gets or sets the channel. + /// + /// + /// The channel. + /// Socket Channel { get; set; } + /// + /// Gets the device. + /// + /// + /// The device. + /// IDevice Device { get; } + /// + /// Gets the device implementation. + /// + /// + /// The device implementation. + /// Device DeviceImplementation { get; } + /// + /// Gets the debugger listen port. + /// + /// + /// The debugger listen port. + /// int DebuggerListenPort { get; } + /// + /// Gets a value indicating whether this instance is DDM aware. + /// + /// + /// true if this instance is DDM aware; otherwise, false. + /// bool IsDdmAware { get; } + /// + /// Gets a value indicating whether this instance is debugger attached. + /// + /// + /// true if this instance is debugger attached; otherwise, false. + /// bool IsDebuggerAttached { get; } + /// + /// Gets the debugger. + /// + /// + /// The debugger. + /// Debugger Debugger { get; } + /// + /// Gets the client data. + /// + /// + /// The client data. + /// ClientData ClientData { get; } + /// + /// Gets or sets a value indicating whether this instance is thread update enabled. + /// + /// + /// true if this instance is thread update enabled; otherwise, false. + /// bool IsThreadUpdateEnabled { get; set; } + /// + /// Gets or sets a value indicating whether this instance is heap update enabled. + /// + /// + /// true if this instance is heap update enabled; otherwise, false. + /// bool IsHeapUpdateEnabled { get; set; } + /// + /// Gets or sets a value indicating whether this instance is selected client. + /// + /// + /// true if this instance is selected client; otherwise, false. + /// bool IsSelectedClient { get; set; } + /// + /// Returns true if ... is valid. + /// + /// + /// true if this instance is valid; otherwise, false. + /// bool IsValid { get; } + /// + /// Executes the garbage collector. + /// void ExecuteGarbageCollector ( ); + /// + /// Dumps the hprof. + /// void DumpHprof ( ); + /// + /// Toggles the method profiling. + /// void ToggleMethodProfiling ( ); + /// + /// Requests the method profiling status. + /// void RequestMethodProfilingStatus ( ); + /// + /// Requests the thread update. + /// void RequestThreadUpdate ( ); + /// + /// Requests the thread stack trace. + /// + /// The thread identifier. void RequestThreadStackTrace ( int threadID ); + /// + /// Requests the native heap information. + /// + /// bool RequestNativeHeapInformation ( ); + /// + /// Enables the allocation tracker. + /// + /// if set to true [enable]. void EnableAllocationTracker ( bool enable ); + /// + /// Requests the allocation status. + /// void RequestAllocationStatus ( ); + /// + /// Requests the allocation details. + /// void RequestAllocationDetails ( ); + /// + /// Kills this instance. + /// void Kill ( ); // TODO: Define Selector + /// + /// Registers the specified selector. + /// + /// The selector. void Register ( /*Selector*/ Object selector ); + /// + /// Listens for debugger. + /// + /// The listen port. void ListenForDebugger ( int listenPort ); // TODO: JdwpPacket + /// + /// Sends the and consume. + /// + /// The packet. + /// The reply handler. void SendAndConsume ( /*JdwpPacket*/ Object packet, ChunkHandler replyHandler ); + /// + /// Adds the request identifier. + /// + /// The identifier. + /// The handler. void AddRequestId ( int id, ChunkHandler handler ); + /// + /// Removes the request identifier. + /// + /// The identifier. void RemoveRequestId ( int id ); + /// + /// Determines whether [is response to us] [the specified identifier]. + /// + /// The identifier. + /// ChunkHandler IsResponseToUs ( int id ); // TODO: JdwpPacket + /// + /// Packets the failed. + /// + /// The packet. void PacketFailed ( /*JdwpPacket*/ Object packet ); + /// + /// DDMs the seen. + /// + /// bool DdmSeen ( ); + /// + /// Closes the specified notify. + /// + /// if set to true [notify]. void Close ( bool notify ); + /// + /// Updates the specified change mask. + /// + /// The change mask. void Update ( ClientChangeMask changeMask ); } } diff --git a/Managed.AndroidDebugBridge/IDebugPortProvider.cs b/Managed.AndroidDebugBridge/IDebugPortProvider.cs index a6d78f2..6cc1746 100644 --- a/Managed.AndroidDebugBridge/IDebugPortProvider.cs +++ b/Managed.AndroidDebugBridge/IDebugPortProvider.cs @@ -4,6 +4,9 @@ using System.Text; namespace Managed.Adb { + /// + /// + /// public interface IDebugPortProvider { /// /// Returns a non-random debugger port for the specified application running on the specified Device. diff --git a/Managed.AndroidDebugBridge/IDevice.cs b/Managed.AndroidDebugBridge/IDevice.cs index eefb42f..f39dcb0 100644 --- a/Managed.AndroidDebugBridge/IDevice.cs +++ b/Managed.AndroidDebugBridge/IDevice.cs @@ -45,7 +45,7 @@ public interface IDevice { /// Gets the serial number of the device. /// /// The serial number. - String SerialNumber { get; } + string SerialNumber { get; } /// /// Gets the TCP endpoint defined when the transport is TCP. /// @@ -73,19 +73,19 @@ public interface IDevice { /// if there isn't any. /// /// The name of the avd. - String AvdName { get; set; } + string AvdName { get; set; } /// /// Gets the environment variables. /// /// The environment variables. - Dictionary EnvironmentVariables { get; } + Dictionary EnvironmentVariables { get; } /// /// Gets the mount points. /// /// The mount points. - Dictionary MountPoints { get; } + Dictionary MountPoints { get; } /// /// Gets the state. @@ -98,7 +98,7 @@ public interface IDevice { /// Returns the device properties. It contains the whole output of 'getprop' /// /// The properties. - Dictionary Properties { get; } + Dictionary Properties { get; } /// /// Gets the property value. @@ -107,7 +107,7 @@ public interface IDevice { /// /// the value or null if the property does not exist. /// - String GetProperty ( String name ); + string GetProperty ( string name ); /// /// Gets the first property that exists in the array of property names. /// @@ -115,7 +115,7 @@ public interface IDevice { /// /// the value or null if the property does not exist. /// - String GetProperty ( params String[] name ); + string GetProperty ( params string[] name ); /// /// Gets a value indicating whether the device is online. @@ -149,7 +149,7 @@ public interface IDevice { /// bool IsBootLoader { get; } - /** + /* * Returns whether the {@link Device} has {@link Client}s. */ //bool HasClients { get; } @@ -159,7 +159,7 @@ public interface IDevice { /// List Clients { get; } - /** + /* * Returns a {@link Client} by its application name. * @param applicationName the name of the application * @return the Client object or null if no match was found. @@ -167,18 +167,24 @@ public interface IDevice { //Client GetClient(String applicationName); /// - /// Returns a object to push / pull files to and from the device. + /// Returns a object to push / pull files to and from the device. /// + /// + /// The synchronize service. + /// + /// Throws IOException if the connection with adb failed. /// /// null if the SyncService couldn't be created. This can happen if adb /// refuse to open the connection because the {@link IDevice} is invalid (or got disconnected). /// - /// Throws IOException if the connection with adb failed. SyncService SyncService { get; } /// - /// Returns a for this device. + /// Returns a for this device. /// + /// + /// The file listing service. + /// FileListingService FileListingService { get; } @@ -193,15 +199,14 @@ public interface IDevice { /// /// The command to execute /// The receiver object getting the result from the command. - void ExecuteShellCommand ( String command, IShellOutputReceiver receiver ); + void ExecuteShellCommand ( string command, IShellOutputReceiver receiver ); /// /// Executes a shell command on the device, and sends the result to a receiver. /// - /// /// The command to execute /// The receiver object getting the result from the command. /// The max time to output response. - void ExecuteShellCommand ( String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse ); + void ExecuteShellCommand ( string command, IShellOutputReceiver receiver, int maxTimeToOutputResponse ); /// /// Executes a shell command on the device, and sends the result to a receiver. @@ -209,7 +214,7 @@ public interface IDevice { /// The command to execute /// The receiver object getting the result from the command. /// The command args. - void ExecuteShellCommand ( String command, IShellOutputReceiver receiver, params object[] commandArgs ); + void ExecuteShellCommand ( string command, IShellOutputReceiver receiver, params object[] commandArgs ); /// /// Executes a shell command on the device, and sends the result to a receiver. @@ -218,7 +223,7 @@ public interface IDevice { /// The receiver object getting the result from the command. /// The max time to output response. /// The command args. - void ExecuteShellCommand ( String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse, params object[] commandArgs ); + void ExecuteShellCommand ( string command, IShellOutputReceiver receiver, int maxTimeToOutputResponse, params object[] commandArgs ); /// @@ -227,7 +232,7 @@ public interface IDevice { /// The command to execute /// The receiver object getting the result from the command. /// The command args. - void ExecuteRootShellCommand ( String command, IShellOutputReceiver receiver, params object[] commandArgs ); + void ExecuteRootShellCommand ( string command, IShellOutputReceiver receiver, params object[] commandArgs ); /// /// Executes a shell command on the device as root, and sends the result to a receiver. @@ -236,14 +241,14 @@ public interface IDevice { /// The receiver object getting the result from the command. /// The max time to output response. /// The command args. - void ExecuteRootShellCommand ( String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse, params object[] commandArgs ); + void ExecuteRootShellCommand ( string command, IShellOutputReceiver receiver, int maxTimeToOutputResponse, params object[] commandArgs ); /// /// Executes a shell command on the device as root, and sends the result to a receiver. /// /// The command to execute /// The receiver object getting the result from the command. - void ExecuteRootShellCommand ( String command, IShellOutputReceiver receiver ); + void ExecuteRootShellCommand ( string command, IShellOutputReceiver receiver ); /// /// Executes a shell command on the device as root, and sends the result to a receiver. @@ -251,15 +256,15 @@ public interface IDevice { /// The command to execute /// The receiver object getting the result from the command. /// The max time to output response. - void ExecuteRootShellCommand ( String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse ); - /** + void ExecuteRootShellCommand ( string command, IShellOutputReceiver receiver, int maxTimeToOutputResponse ); + /* * Runs the event log service and outputs the event log to the {@link LogReceiver}. * @param receiver the receiver to receive the event log entries. * @throws IOException */ //void RunEventLogService(LogReceiver receiver); - /** + /* * Runs the log service for the given log and outputs the log to the {@link LogReceiver}. * @param logname the logname of the log to read from. * @param receiver the receiver to receive the event log entries. @@ -282,7 +287,7 @@ public interface IDevice { /// true if success. bool RemoveForward ( int localPort ); - /** + /* * Returns the name of the client by pid or null if pid is unknown * @param pid the pid of the client. */ @@ -295,38 +300,40 @@ public interface IDevice { /// /// the absolute file system path to file on local host to install /// set to trueif re-install of app should be performed - void InstallPackage ( String packageFilePath, bool reinstall ); + void InstallPackage ( string packageFilePath, bool reinstall ); /// /// Pushes a file to device /// /// the absolute path to file on local host - /// destination path on device for file - /// if fatal error occurred when pushing file - String SyncPackageToDevice ( String localFilePath ); + /// + /// destination path on device for file + /// + /// if fatal error occurred when pushing file + string SyncPackageToDevice ( string localFilePath ); /// /// Installs the application package that was pushed to a temporary location on the device. /// /// absolute file path to package file on device /// set to true if re-install of app should be performed - void InstallRemotePackage(String remoteFilePath, bool reinstall); + void InstallRemotePackage( string remoteFilePath, bool reinstall); /// /// Remove a file from device /// /// path on device of file to remove - /// if file removal failed - void RemoveRemotePackage(String remoteFilePath); + /// if file removal failed + void RemoveRemotePackage(string remoteFilePath); /// /// Uninstall an package from the device. /// /// Name of the package. - /// - /// - void UninstallPackage(String packageName) ; + /// + /// + void UninstallPackage (string packageName) ; /// /// Refreshes the environment variables. diff --git a/Managed.AndroidDebugBridge/IO/ByteOrder.cs b/Managed.AndroidDebugBridge/IO/ByteOrder.cs index 90cf075..347049f 100644 --- a/Managed.AndroidDebugBridge/IO/ByteOrder.cs +++ b/Managed.AndroidDebugBridge/IO/ByteOrder.cs @@ -10,6 +10,10 @@ namespace Managed.Adb.IO { /// true public class ByteOrder { + /// + /// Initializes a new instance of the class. + /// + /// The name. private ByteOrder ( String name ) { this.Name = name; } @@ -29,14 +33,14 @@ private ByteOrder ( String name ) { /// /// The name. /// - public String Name { get; private set; } + public string Name { get; private set; } /// /// Returns a that represents the current . /// /// /// A that represents the current . /// - public String ToString ( ) { + public override string ToString ( ) { return Name; } } diff --git a/Managed.AndroidDebugBridge/IO/ScreenResolution.cs b/Managed.AndroidDebugBridge/IO/ScreenResolution.cs index df2e4b4..d782f46 100644 --- a/Managed.AndroidDebugBridge/IO/ScreenResolution.cs +++ b/Managed.AndroidDebugBridge/IO/ScreenResolution.cs @@ -113,6 +113,12 @@ private ScreenResolution ( ) { } private static ScreenResolution _instance = null; + /// + /// Gets the instance. + /// + /// + /// The instance. + /// public static ScreenResolution Instance { get { if ( _instance == null ) { @@ -122,9 +128,21 @@ public static ScreenResolution Instance { } } + /// + /// Gets the sizes. + /// + /// + /// The sizes. + /// public Dictionary Sizes { get; private set; } + /// + /// Calculates the size. + /// + /// The pixels. + /// + /// public Size CalculateSize ( long pixels ) { // this doesnt work very well, unless the number of pixels is exact! List ordered = new List ( Sizes.Keys ); @@ -143,6 +161,12 @@ public Size CalculateSize ( long pixels ) { } + /// + /// Pixelses from size. + /// + /// The size. + /// + /// public int PixelsFromSize ( Size size ) { foreach ( var item in Sizes.Keys ) { diff --git a/Managed.AndroidDebugBridge/IPacketConsumer.cs b/Managed.AndroidDebugBridge/IPacketConsumer.cs index a9f7839..e2daa02 100644 --- a/Managed.AndroidDebugBridge/IPacketConsumer.cs +++ b/Managed.AndroidDebugBridge/IPacketConsumer.cs @@ -13,12 +13,17 @@ public interface IPacketConsumer { /// void Read ( ); // TODO: JdwpPacket - /*JdwpPacket*/ Object GetJdwpPacket ( ); + /// + /// Gets the JDWP packet. + /// + /// + /*JdwpPacket*/ + object GetJdwpPacket ( ); /// /// Forwards the packet to client. /// /// The packet. - void ForwardPacketToClient ( /*JdwpPacket*/ Object packet ); + void ForwardPacketToClient ( /*JdwpPacket*/ object packet ); /// /// Sends the handshake. /// @@ -27,6 +32,6 @@ public interface IPacketConsumer { /// Sends the and consume. /// /// The packet. - void SendAndConsume ( /*JdwpPacket*/ Object packet ); + void SendAndConsume ( /*JdwpPacket*/ object packet ); } } diff --git a/Managed.AndroidDebugBridge/ISyncProgressMonitor.cs b/Managed.AndroidDebugBridge/ISyncProgressMonitor.cs index 4292217..708e0ce 100644 --- a/Managed.AndroidDebugBridge/ISyncProgressMonitor.cs +++ b/Managed.AndroidDebugBridge/ISyncProgressMonitor.cs @@ -28,8 +28,9 @@ public interface ISyncProgressMonitor { /// /// Sent when a sub task is started. /// + /// The source. /// the destination. - void StartSubTask ( String source, String destination ); + void StartSubTask ( string source, string destination ); /// /// Sent when some progress have been made. diff --git a/Managed.AndroidDebugBridge/Log.cs b/Managed.AndroidDebugBridge/Log.cs index 8f008d5..0a2a2c5 100644 --- a/Managed.AndroidDebugBridge/Log.cs +++ b/Managed.AndroidDebugBridge/Log.cs @@ -105,7 +105,7 @@ public static void d ( String tag, String format, params object[] args ) { /// Outputs a Info level message. /// /// The tag associated with the message. - /// The message to output. + /// The message. public static void i ( String tag, String message ) { WriteLine ( LogLevel.Info, tag, message ); } diff --git a/Managed.AndroidDebugBridge/LogLevel.cs b/Managed.AndroidDebugBridge/LogLevel.cs index c627806..c3bac0f 100644 --- a/Managed.AndroidDebugBridge/LogLevel.cs +++ b/Managed.AndroidDebugBridge/LogLevel.cs @@ -67,6 +67,11 @@ static LogLevel ( ) { /// The levels. public static Dictionary Levels { get; private set; } + /// + /// Gets the by string. + /// + /// The value. + /// public static LogLevelInfo GetByString ( String value ) { foreach ( LogLevelInfo item in Values ) { diff --git a/Managed.AndroidDebugBridge/Logs/ILogListener.cs b/Managed.AndroidDebugBridge/Logs/ILogListener.cs index 0f57df4..3f36216 100644 --- a/Managed.AndroidDebugBridge/Logs/ILogListener.cs +++ b/Managed.AndroidDebugBridge/Logs/ILogListener.cs @@ -4,6 +4,9 @@ using System.Text; namespace Managed.Adb.Logs { + /// + /// + /// public interface ILogListener { /// /// Sent when a new LogEntry has been parsed by the LogReceiver. diff --git a/Managed.AndroidDebugBridge/Logs/LogEntry.cs b/Managed.AndroidDebugBridge/Logs/LogEntry.cs index 8112b44..e89a35f 100644 --- a/Managed.AndroidDebugBridge/Logs/LogEntry.cs +++ b/Managed.AndroidDebugBridge/Logs/LogEntry.cs @@ -4,12 +4,51 @@ using System.Text; namespace Managed.Adb.Logs { + /// + /// + /// public sealed class LogEntry { + /// + /// Gets or sets the length. + /// + /// + /// The length. + /// public int Length { get; set; } + /// + /// Gets or sets the process identifier. + /// + /// + /// The process identifier. + /// public int ProcessId { get; set; } + /// + /// Gets or sets the thread identifier. + /// + /// + /// The thread identifier. + /// public int ThreadId { get; set; } + /// + /// Gets or sets the time stamp. + /// + /// + /// The time stamp. + /// public DateTime TimeStamp { get; set; } + /// + /// Gets or sets the nano seconds. + /// + /// + /// The nano seconds. + /// public int NanoSeconds { get; set; } + /// + /// Gets or sets the data. + /// + /// + /// The data. + /// public byte[] Data { get; set; } } } diff --git a/Managed.AndroidDebugBridge/Logs/LogReceiver.cs b/Managed.AndroidDebugBridge/Logs/LogReceiver.cs index 26d87d8..5351a98 100644 --- a/Managed.AndroidDebugBridge/Logs/LogReceiver.cs +++ b/Managed.AndroidDebugBridge/Logs/LogReceiver.cs @@ -4,8 +4,18 @@ using System.Text; namespace Managed.Adb.Logs { + /// + /// + /// public class LogReceiver { + /// + /// The entr y_ heade r_ size + /// private const int ENTRY_HEADER_SIZE = 20; // 2*2 + 4*4; see LogEntry. + /// + /// Initializes a new instance of the class. + /// + /// The listener. public LogReceiver ( ILogListener listener ) { EntryDataOffset = 0; EntryHeaderBuffer = new byte[ENTRY_HEADER_SIZE]; @@ -13,18 +23,63 @@ public LogReceiver ( ILogListener listener ) { Listener = listener; } + /// + /// Gets or sets the entry data offset. + /// + /// + /// The entry data offset. + /// private int EntryDataOffset { get; set; } + /// + /// Gets or sets the entry header offset. + /// + /// + /// The entry header offset. + /// private int EntryHeaderOffset { get; set; } + /// + /// Gets or sets the entry header buffer. + /// + /// + /// The entry header buffer. + /// private byte[] EntryHeaderBuffer { get; set; } + /// + /// Gets or sets the current entry. + /// + /// + /// The current entry. + /// private LogEntry CurrentEntry { get; set; } + /// + /// Gets or sets the listener. + /// + /// + /// The listener. + /// private ILogListener Listener { get; set; } + /// + /// Gets a value indicating whether this instance is cancelled. + /// + /// + /// true if this instance is cancelled; otherwise, false. + /// public bool IsCancelled { get; private set; } + /// + /// Cancels this instance. + /// public void Cancel ( ) { this.IsCancelled = true; } + /// + /// Parses the new data. + /// + /// The data. + /// The offset. + /// The length. public void ParseNewData ( byte[] data, int offset, int length ) { // notify the listener of new raw data if ( Listener != null ) { @@ -108,6 +163,13 @@ public void ParseNewData ( byte[] data, int offset, int length ) { } + /// + /// Creates the entry. + /// + /// The data. + /// The offset. + /// + /// Buffer not big enough to hold full LoggerEntry header private LogEntry CreateEntry ( byte[] data, int offset ) { if ( data.Length < offset + ENTRY_HEADER_SIZE ) { throw new ArgumentException ( "Buffer not big enough to hold full LoggerEntry header" ); diff --git a/Managed.AndroidDebugBridge/MonitorThread.cs b/Managed.AndroidDebugBridge/MonitorThread.cs index 7070390..39ad200 100644 --- a/Managed.AndroidDebugBridge/MonitorThread.cs +++ b/Managed.AndroidDebugBridge/MonitorThread.cs @@ -71,6 +71,11 @@ internal void SetDebugSelectedPort ( int value ) { //throw new NotImplementedException ( ); } + /// + /// Drops the client. + /// + /// The client. + /// if set to true [notify]. public void DropClient ( IClient client, bool notify ) { } diff --git a/Managed.AndroidDebugBridge/RawImage.cs b/Managed.AndroidDebugBridge/RawImage.cs index 531c84c..89a016d 100644 --- a/Managed.AndroidDebugBridge/RawImage.cs +++ b/Managed.AndroidDebugBridge/RawImage.cs @@ -102,6 +102,12 @@ public RawImage ( ) { * @param buf the buffer to read from. * @return true if success */ + /// + /// Reads the header. + /// + /// The version. + /// The buf. + /// public bool ReadHeader ( int version, BinaryReader buf ) { this.Version = version; // https://github.com/android/platform_system_core/blob/master/adb/framebuffer_service.c @@ -146,11 +152,11 @@ public bool ReadHeader ( int version, BinaryReader buf ) { return true; } - /** - * Returns the size of the header for a specific version of the framebuffer adb protocol. - * @param version the version of the protocol - * @return the number of int that makes up the header. - */ + /// + /// Returns the size of the header for a specific version of the framebuffer adb protocol. + /// + /// the version of the protocol. + /// the number of int that makes up the header. public static int GetHeaderSize ( int version ) { switch ( version ) { case 16: // compatibility mode @@ -166,10 +172,11 @@ public static int GetHeaderSize ( int version ) { return 0; } - /** - * Returns a rotated version of the image - * The image is rotated counter-clockwise. - */ + /// + /// Returns a rotated version of the image + /// The image is rotated counter-clockwise. + /// + /// public RawImage GetRotated ( ) { RawImage rotated = new RawImage ( ); rotated.Version = this.Version; @@ -258,6 +265,11 @@ public Image ToImage ( ) { return ToImage ( this.Bpp == 32 ? PixelFormat.Format32bppArgb : PixelFormat.Format16bppRgb565 ); } + /// + /// Swaps the specified b. + /// + /// The b. + /// private byte[] Swap ( byte[] b ) { var clone = new List ( ); b.IntReverseForRawImage ( bitem => { diff --git a/Managed.AndroidDebugBridge/Receivers/CommandErrorReceiver.cs b/Managed.AndroidDebugBridge/Receivers/CommandErrorReceiver.cs index db60db0..c6c5526 100644 --- a/Managed.AndroidDebugBridge/Receivers/CommandErrorReceiver.cs +++ b/Managed.AndroidDebugBridge/Receivers/CommandErrorReceiver.cs @@ -4,6 +4,10 @@ using System.Text; namespace Managed.Adb { + /// + /// + /// + /// internal class CommandErrorReceiver : MultiLineReceiver { /// /// Initializes a new instance of the class. diff --git a/Managed.AndroidDebugBridge/Receivers/LinkResoverReceiver.cs b/Managed.AndroidDebugBridge/Receivers/LinkResoverReceiver.cs index b348305..4b74cba 100644 --- a/Managed.AndroidDebugBridge/Receivers/LinkResoverReceiver.cs +++ b/Managed.AndroidDebugBridge/Receivers/LinkResoverReceiver.cs @@ -6,13 +6,30 @@ using MoreLinq; namespace Managed.Adb { + /// + /// + /// + /// internal sealed class LinkResoverReceiver : MultiLineReceiver { + /// + /// Initializes a new instance of the class. + /// public LinkResoverReceiver ( ) { } - public String ResolvedPath { get; set; } + /// + /// Gets or sets the resolved path. + /// + /// + /// The resolved path. + /// + public string ResolvedPath { get; set; } + /// + /// Processes the new lines. + /// + /// The lines. protected override void ProcessNewLines ( string[] lines ) { // all we care about is a line with '->' var regex = @"->\s+([^$]+)"; diff --git a/Managed.AndroidDebugBridge/Receivers/MountPointReceiver.cs b/Managed.AndroidDebugBridge/Receivers/MountPointReceiver.cs index b5e0eef..3abe5ee 100644 --- a/Managed.AndroidDebugBridge/Receivers/MountPointReceiver.cs +++ b/Managed.AndroidDebugBridge/Receivers/MountPointReceiver.cs @@ -52,22 +52,6 @@ protected override void ProcessNewLines ( string[] lines ) { } } } ); - /* - foreach ( var line in lines ) { - Match m = Regex.Match ( line, RE_MOUNTPOINT_PATTERN, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace ); - if ( m.Success ) { - String block = m.Groups[1].Value.Trim ( ).Replace ( "//", "/" ); - String name = m.Groups[2].Value.Trim ( ); - String fs = m.Groups[3].Value.Trim ( ); - bool ro = String.Compare ( "ro", m.Groups[4].Value.Trim ( ), false ) == 0; - MountPoint mnt = new MountPoint ( block, name, fs, ro ); - String key = name.Substring ( 1 ); - // currently does not support multiple mounts to the same location... - if ( !Device.MountPoints.ContainsKey ( name ) ) { - Device.MountPoints.Add ( name, mnt ); - } - } - }*/ } /// diff --git a/Managed.AndroidDebugBridge/SyncService.cs b/Managed.AndroidDebugBridge/SyncService.cs index 0866675..79e6826 100644 --- a/Managed.AndroidDebugBridge/SyncService.cs +++ b/Managed.AndroidDebugBridge/SyncService.cs @@ -9,6 +9,10 @@ using Camalot.Common.Extensions; namespace Managed.Adb { + /// + /// + /// + /// public class SyncService : IDisposable { private const String OKAY = "OKAY"; private const String FAIL = "FAIL"; @@ -20,6 +24,9 @@ public class SyncService : IDisposable { private const String LIST = "LIST"; private const String DENT = "DENT"; private const string TAG = "sync"; + /// + /// + /// [Flags] public enum FileMode { /// @@ -83,7 +90,9 @@ public enum FileMode { private const int SYNC_DATA_MAX = 64 * 1024; private const int REMOTE_PATH_MAX_LENGTH = 1024; - #region static members + /// + /// Initializes the class. + /// static SyncService ( ) { NullProgressMonitor = new NullSyncProgressMonitor ( ); } @@ -95,6 +104,12 @@ static SyncService ( ) { /// The null progress monitor. /// public static NullSyncProgressMonitor NullProgressMonitor { get; private set; } + /// + /// Gets or sets the data buffer. + /// + /// + /// The data buffer. + /// private static byte[] DataBuffer { get; set; } /// @@ -206,10 +221,24 @@ private static byte[] CreateFileRequest ( byte[] command, byte[] path ) { return array; } + /// + /// Creates the send file request. + /// + /// The command. + /// The path. + /// The mode. + /// private static byte[] CreateSendFileRequest ( String command, String path, FileMode mode ) { return CreateSendFileRequest ( Encoding.Default.GetBytes ( command ), Encoding.Default.GetBytes ( path ), mode ); } + /// + /// Creates the send file request. + /// + /// The command. + /// The path. + /// The mode. + /// private static byte[] CreateSendFileRequest ( byte[] command, byte[] path, FileMode mode ) { String modeString = String.Format ( ",{0}", ( (int)mode & 0777 ) ); byte[] modeContent = null; @@ -227,7 +256,6 @@ private static byte[] CreateSendFileRequest ( byte[] command, byte[] path, FileM return array; } - #endregion /// /// Initializes a new instance of the class. @@ -263,6 +291,12 @@ public SyncService ( IPEndPoint address, Device device ) { /// The device. /// public Device Device { get; private set; } + /// + /// Gets or sets the channel. + /// + /// + /// The channel. + /// private Socket Channel { get; set; } /// /// Gets a value indicating whether this instance is open. @@ -644,6 +678,14 @@ private SyncResult DoPushFile ( string local, string remotePath, ISyncProgressMo return new SyncResult ( ErrorCodeHelper.RESULT_OK ); } + /// + /// Does the push. + /// + /// The files. + /// The remote path. + /// The monitor. + /// + /// monitor;Monitor cannot be null private SyncResult DoPush ( IEnumerable files, string remotePath, ISyncProgressMonitor monitor ) { if ( monitor == null ) { throw new ArgumentNullException ( "monitor", "Monitor cannot be null" ); @@ -802,15 +844,15 @@ private SyncResult DoPullFile ( string remotePath, string localPath, ISyncProgre } /// - /// + /// Does the pull. /// - /// - /// - /// - /// + /// The entries. + /// The local path. + /// The file listing service. + /// The monitor. /// - /// Throws if unable to create a file or folder /// Throws if the ISyncProgressMonitor is null + /// Throws if unable to create a file or folder private SyncResult DoPull ( IEnumerable entries, string localPath, FileListingService fileListingService, ISyncProgressMonitor monitor ) { if ( monitor == null ) { throw new ArgumentNullException ( "monitor", "Monitor cannot be null" ); @@ -896,9 +938,13 @@ private long GetTotalRemoteFileSize ( IEnumerable entries, FileListin /// /// compute the recursive file size of all the files in the list. Folders have a weight of 1. /// - /// The local files / folders - /// The total number of bytes - /// This does not check for circular links. + /// The fsis. + /// + /// The total number of bytes + /// + /// + /// This does not check for circular links. + /// private long GetTotalLocalFileSize ( IEnumerable fsis ) { long count = 0; From f41f03dd968de6e40fbf170293cfb8ee362553bb Mon Sep 17 00:00:00 2001 From: camalot Date: Sun, 10 Apr 2016 11:06:24 -0500 Subject: [PATCH 15/24] removed all switches from xunit console. --- .appveyor/appveyor.test.ps1 | 2 +- Managed.AndroidDebugBridge/IO/LinuxPath.cs | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/.appveyor/appveyor.test.ps1 b/.appveyor/appveyor.test.ps1 index 2d3977a..ca176c8 100644 --- a/.appveyor/appveyor.test.ps1 +++ b/.appveyor/appveyor.test.ps1 @@ -1,4 +1,4 @@ # /notrait category=IntegrationTest -& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe" -targetargs:"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\Debug\Managed.Adb.Tests.dll /nologo /noshadow" -filter:"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml" +& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe" -targetargs:"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\Debug\Managed.Adb.Tests.dll" -filter:"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml" pip install codecov codecov -f "${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml" -X gcov \ No newline at end of file diff --git a/Managed.AndroidDebugBridge/IO/LinuxPath.cs b/Managed.AndroidDebugBridge/IO/LinuxPath.cs index 1bb8757..e4b81a5 100644 --- a/Managed.AndroidDebugBridge/IO/LinuxPath.cs +++ b/Managed.AndroidDebugBridge/IO/LinuxPath.cs @@ -58,16 +58,6 @@ public static class LinuxPath { '\x001c', '\x001d', '\x001e', '\x001f' }; - /// - /// Determines whether this instance [can path circumvent security native] the specified part of path. - /// - /// The part of path. - /// - /// true if this instance [can path circumvent security native] the specified part of path; otherwise, false. - /// - [MethodImpl ( MethodImplOptions.InternalCall )] - private static extern bool CanPathCircumventSecurityNative ( string partOfPath ); - /// Changes the extension of a path string. /// A string containing the modified path information.On Windows-based desktop platforms, if path is null or an empty string (""), the path information is returned unmodified. If extension is null, the returned string contains the specified path with its extension removed. If path has no extension, and extension is not null, the returned path string contains extension appended to the end of path. /// The new extension (with a leading period). Specify null to remove an existing extension from path. From bdab596ec4d16450df7556c9ec92c2a3e42d2901 Mon Sep 17 00:00:00 2001 From: camalot Date: Sun, 10 Apr 2016 11:12:19 -0500 Subject: [PATCH 16/24] removed some unused/duplicated code. Changed the test runner script to try to get it to parse correctly in appveyor. --- .appveyor/appveyor.test.ps1 | 4 +- Managed.AndroidDebugBridge/IO/LinuxPath.cs | 128 --------------------- 2 files changed, 2 insertions(+), 130 deletions(-) diff --git a/.appveyor/appveyor.test.ps1 b/.appveyor/appveyor.test.ps1 index ca176c8..d08b03a 100644 --- a/.appveyor/appveyor.test.ps1 +++ b/.appveyor/appveyor.test.ps1 @@ -1,4 +1,4 @@ # /notrait category=IntegrationTest -& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe" -targetargs:"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\Debug\Managed.Adb.Tests.dll" -filter:"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml" +& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe -targetargs:${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\Debug\Managed.Adb.Tests.dll -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml pip install codecov -codecov -f "${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml" -X gcov \ No newline at end of file +codecov -f `"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml`" -X gcov \ No newline at end of file diff --git a/Managed.AndroidDebugBridge/IO/LinuxPath.cs b/Managed.AndroidDebugBridge/IO/LinuxPath.cs index e4b81a5..5f98020 100644 --- a/Managed.AndroidDebugBridge/IO/LinuxPath.cs +++ b/Managed.AndroidDebugBridge/IO/LinuxPath.cs @@ -91,54 +91,6 @@ public static string ChangeExtension ( string path, string extension ) { return ( str + extension ); } - /// - /// Checks if the char array starts with ordinal - /// - /// The array. - /// The num chars. - /// The compare to. - /// if set to true [ignore case]. - /// - private static unsafe bool CharArrayStartsWithOrdinal ( char* array, int numChars, string compareTo, bool ignoreCase ) { - if ( numChars < compareTo.Length ) { - return false; - } - if ( ignoreCase ) { - string str = new string ( array, 0, compareTo.Length ); - return compareTo.Equals ( str, StringComparison.OrdinalIgnoreCase ); - } - for ( int i = 0; i < compareTo.Length; i++ ) { - if ( array[i] != compareTo[i] ) { - return false; - } - } - return true; - } - - /// - /// Checks if the char array starts with ordinal - /// - /// The array. - /// The num chars. - /// The compare to. - /// if set to true [ignore case]. - /// - private static bool CharArrayStartsWithOrdinal ( char[] array, int numChars, string compareTo, bool ignoreCase ) { - if ( numChars < compareTo.Length ) { - return false; - } - if ( ignoreCase ) { - string str = new string ( array, 0, compareTo.Length ); - return compareTo.Equals ( str, StringComparison.OrdinalIgnoreCase ); - } - for ( int i = 0; i < compareTo.Length; i++ ) { - if ( array[i] != compareTo[i] ) { - return false; - } - } - return true; - } - /// /// Checks the invalid path chars. /// @@ -152,57 +104,6 @@ internal static void CheckInvalidPathChars( string path ) { } } - /// Combines two path strings. - /// A string containing the combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If path2 contains an absolute path, this method returns path2. - /// The second path. - /// The first path. - /// path1 or path2 is null. - /// path1 or path2 contain one or more of the invalid characters defined in , or contains a wildcard character. - public static string Combine ( string path1, string path2 ) { - if ( ( path1 == null ) || ( path2 == null ) ) { - throw new ArgumentNullException ( ( path1 == null ) ? "path1" : "path2" ); - } - CheckInvalidPathChars ( path1 ); - CheckInvalidPathChars ( path2 ); - return CombineNoChecks ( path1, path2 ); - } - - /// - /// Combine the specified paths to form one path - /// - /// The path1. - /// The path2. - /// The path3. - /// - public static string Combine ( string path1, string path2, string path3 ) { - if ( ( ( path1 == null ) || ( path2 == null ) ) || ( path3 == null ) ) { - throw new ArgumentNullException ( ( path1 == null ) ? "path1" : ( ( path2 == null ) ? "path2" : "path3" ) ); - } - CheckInvalidPathChars ( path1 ); - CheckInvalidPathChars ( path2 ); - CheckInvalidPathChars ( path3 ); - return CombineNoChecks ( CombineNoChecks ( path1, path2 ), path3 ); - } - - /// - /// Combine the specified paths to form one path - /// - /// The path1. - /// The path2. - /// The path3. - /// The path4. - /// - public static string Combine ( string path1, string path2, string path3, string path4 ) { - if ( ( ( path1 == null ) || ( path2 == null ) ) || ( ( path3 == null ) || ( path4 == null ) ) ) { - throw new ArgumentNullException ( ( path1 == null ) ? "path1" : ( ( path2 == null ) ? "path2" : ( ( path3 == null ) ? "path3" : "path4" ) ) ); - } - CheckInvalidPathChars ( path1 ); - CheckInvalidPathChars ( path2 ); - CheckInvalidPathChars ( path3 ); - CheckInvalidPathChars ( path4 ); - return CombineNoChecks ( CombineNoChecks ( CombineNoChecks ( path1, path2 ), path3 ), path4 ); - } - /// /// Combine the specified paths to form one path /// @@ -482,35 +383,6 @@ public static bool HasExtension ( string path ) { return false; } - /// - /// Combine the specified paths to form one path - /// - /// The path1. - /// The path2. - /// - internal static string InternalCombine ( string path1, string path2 ) { - if ( ( path1 == null ) || ( path2 == null ) ) { - throw new ArgumentNullException ( ( path1 == null ) ? "path1" : "path2" ); - } - CheckInvalidPathChars ( path1 ); - CheckInvalidPathChars ( path2 ); - if ( path2.Length == 0 ) { - throw new ArgumentException ( "Path can not empty", "path2" ); - } - if ( IsPathRooted ( path2 ) ) { - throw new ArgumentException ( "Path is already rooted", "path2" ); - } - int length = path1.Length; - if ( length == 0 ) { - return path2; - } - char ch = path1[length - 1]; - if ( ( ( ch != DirectorySeparatorChar ) && ( ch != AltDirectorySeparatorChar ) ) ) { - return ( path1 + DirectorySeparatorChar + path2 ); - } - return ( path1 + path2 ); - } - internal static bool IsDirectorySeparator ( char c ) { if ( c != DirectorySeparatorChar ) { return ( c == AltDirectorySeparatorChar ); From 6b6745b8ee7a9e37d0b41ba6f49b983899fbbfa6 Mon Sep 17 00:00:00 2001 From: camalot Date: Sun, 10 Apr 2016 11:44:26 -0500 Subject: [PATCH 17/24] added coverage artifact. updated args for xunit command --- .appveyor/appveyor.before-test.ps1 | 1 + .appveyor/appveyor.test.ps1 | 10 ++-- .build/BuildAll.msbuild | 2 +- Managed.Adb.Tests/Managed.Adb.Tests.csproj | 57 ++++++++++++++++------ Managed.AndroidDebugBridge.sln | 54 ++++++++++---------- appveyor.yml | 2 + 6 files changed, 79 insertions(+), 47 deletions(-) diff --git a/.appveyor/appveyor.before-test.ps1 b/.appveyor/appveyor.before-test.ps1 index e69de29..c0f4c98 100644 --- a/.appveyor/appveyor.before-test.ps1 +++ b/.appveyor/appveyor.before-test.ps1 @@ -0,0 +1 @@ +pip install codecov; diff --git a/.appveyor/appveyor.test.ps1 b/.appveyor/appveyor.test.ps1 index d08b03a..0987754 100644 --- a/.appveyor/appveyor.test.ps1 +++ b/.appveyor/appveyor.test.ps1 @@ -1,4 +1,6 @@ -# /notrait category=IntegrationTest -& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe -targetargs:${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\Debug\Managed.Adb.Tests.dll -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml -pip install codecov -codecov -f `"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml`" -X gcov \ No newline at end of file +. ./appveyor.before-tests.ps1; + +& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:`"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe`" -targetargs:`"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\Debug\Managed.Adb.Tests.dll /noshadow /nologo /notrait category=IntegrationTest`" -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml +codecov -f `"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml`" -X gcov; + +. ./appveyor.after-tests.ps1; diff --git a/.build/BuildAll.msbuild b/.build/BuildAll.msbuild index c2461c7..7327fc1 100644 --- a/.build/BuildAll.msbuild +++ b/.build/BuildAll.msbuild @@ -16,7 +16,7 @@ - + diff --git a/Managed.Adb.Tests/Managed.Adb.Tests.csproj b/Managed.Adb.Tests/Managed.Adb.Tests.csproj index a5d4452..8b5680f 100644 --- a/Managed.Adb.Tests/Managed.Adb.Tests.csproj +++ b/Managed.Adb.Tests/Managed.Adb.Tests.csproj @@ -3,9 +3,9 @@ - Debug - AnyCPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47} + Debug + x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47} Library Properties Managed.Adb.Tests @@ -20,23 +20,52 @@ UnitTest b0edf53b + true + TRACE;DEBUG;PLATFORMX86 + full + true + GlobalSuppressions.cs + prompt + true + AllRules.ruleset + x86 + true - + true + bin\x64\Debug\ + TRACE;DEBUG;PLATFORMX64 + full + x64 + prompt + MinimumRecommendedRules.ruleset + + + bin\x64\Release\ + TRACE;DEBUG;PLATFORMX64 + true full - false - bin\Debug\ - DEBUG;TRACE + x64 + prompt + MinimumRecommendedRules.ruleset + + + true + bin\x86\Debug\ + TRACE;DEBUG;PLATFORMX86 + full + x86 prompt - 4 + MinimumRecommendedRules.ruleset - - pdbonly - true - bin\Release\ - TRACE + + bin\x86\Release\ + TRACE;DEBUG;PLATFORMX86 + true + full + x86 prompt - 4 + MinimumRecommendedRules.ruleset diff --git a/Managed.AndroidDebugBridge.sln b/Managed.AndroidDebugBridge.sln index a32e521..b06b268 100644 --- a/Managed.AndroidDebugBridge.sln +++ b/Managed.AndroidDebugBridge.sln @@ -81,16 +81,16 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Any CPU.Build.0 = Debug|Any CPU - {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Mixed Platforms.ActiveCfg = Debug|ia64 - {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Mixed Platforms.Build.0 = Debug|ia64 + {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Any CPU.ActiveCfg = Debug|x86 + {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Any CPU.Build.0 = Debug|x86 + {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Mixed Platforms.Build.0 = Debug|x86 {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|x64.ActiveCfg = Debug|x64 {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|x64.Build.0 = Debug|x64 - {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|x86.ActiveCfg = Release|x86 - {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|x86.Build.0 = Release|x86 - {65473257-E70F-410B-9269-D0C0F771EA87}.Release|Any CPU.ActiveCfg = Release|Any CPU - {65473257-E70F-410B-9269-D0C0F771EA87}.Release|Any CPU.Build.0 = Release|Any CPU + {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|x86.ActiveCfg = Debug|x86 + {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|x86.Build.0 = Debug|x86 + {65473257-E70F-410B-9269-D0C0F771EA87}.Release|Any CPU.ActiveCfg = Release|x86 + {65473257-E70F-410B-9269-D0C0F771EA87}.Release|Any CPU.Build.0 = Release|x86 {65473257-E70F-410B-9269-D0C0F771EA87}.Release|Mixed Platforms.ActiveCfg = Release|x86 {65473257-E70F-410B-9269-D0C0F771EA87}.Release|Mixed Platforms.Build.0 = Release|x86 {65473257-E70F-410B-9269-D0C0F771EA87}.Release|x64.ActiveCfg = Release|x64 @@ -103,8 +103,8 @@ Global {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|Mixed Platforms.Build.0 = Debug|x86 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|x64.ActiveCfg = Debug|x64 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|x64.Build.0 = Debug|x64 - {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|x86.ActiveCfg = Release|x86 - {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|x86.Build.0 = Release|x86 + {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|x86.ActiveCfg = Debug|x86 + {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|x86.Build.0 = Debug|x86 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|Any CPU.ActiveCfg = Release|x86 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|Any CPU.Build.0 = Release|x86 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|Mixed Platforms.ActiveCfg = Release|x86 @@ -118,8 +118,8 @@ Global {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|x64.ActiveCfg = Debug|Any CPU - {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|x86.ActiveCfg = Release|Any CPU - {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|x86.Build.0 = Release|Any CPU + {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|x86.ActiveCfg = Debug|Any CPU + {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|x86.Build.0 = Debug|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|Any CPU.ActiveCfg = Release|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|Any CPU.Build.0 = Release|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -127,22 +127,20 @@ Global {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|x64.ActiveCfg = Release|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|x86.ActiveCfg = Release|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|x86.Build.0 = Release|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x64.ActiveCfg = Debug|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x64.Build.0 = Debug|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x86.ActiveCfg = Debug|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x86.Build.0 = Debug|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Any CPU.Build.0 = Release|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x64.ActiveCfg = Release|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x64.Build.0 = Release|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x86.ActiveCfg = Release|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x86.Build.0 = Release|Any CPU + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Any CPU.ActiveCfg = Debug|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x64.ActiveCfg = Debug|x64 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x64.Build.0 = Debug|x64 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x86.ActiveCfg = Debug|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x86.Build.0 = Debug|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Any CPU.ActiveCfg = Release|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Mixed Platforms.Build.0 = Release|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x64.ActiveCfg = Debug|x64 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x64.Build.0 = Debug|x64 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x86.ActiveCfg = Debug|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x86.Build.0 = Debug|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/appveyor.yml b/appveyor.yml index 76168e3..1b13f0f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,6 +27,8 @@ artifacts: name: Zips - path: '**\Managed.Adb.*.nupkg' name: Nupkg +- path: '*.coverage.xml' + name: Coverage before_deploy: - ps: .\.appveyor\appveyor.before-deployment.ps1 deploy: From bbd8cc9276b3d2173a870308bd3c0f03da3ce9cc Mon Sep 17 00:00:00 2001 From: camalot Date: Sun, 10 Apr 2016 11:53:52 -0500 Subject: [PATCH 18/24] fixed the run scripts during tests --- .appveyor/appveyor.before-test.ps1 | 1 - .appveyor/appveyor.install.ps1 | 4 +++- .appveyor/appveyor.test.ps1 | 6 +++--- Managed.Adb.Tests/Managed.Adb.Tests.csproj | 9 ++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.appveyor/appveyor.before-test.ps1 b/.appveyor/appveyor.before-test.ps1 index c0f4c98..e69de29 100644 --- a/.appveyor/appveyor.before-test.ps1 +++ b/.appveyor/appveyor.before-test.ps1 @@ -1 +0,0 @@ -pip install codecov; diff --git a/.appveyor/appveyor.install.ps1 b/.appveyor/appveyor.install.ps1 index 2d08731..b3bcfcd 100644 --- a/.appveyor/appveyor.install.ps1 +++ b/.appveyor/appveyor.install.ps1 @@ -2,4 +2,6 @@ $env:PATH = "C:\ProgramData\chocolatey\lib\NuGet.CommandLine\tools\;C:\Python34;C:\Python34\Scripts\;$env:PATH"; -& python -m pip install --upgrade pip; \ No newline at end of file +& python -m pip install --upgrade pip; + +pip install codecov; diff --git a/.appveyor/appveyor.test.ps1 b/.appveyor/appveyor.test.ps1 index 0987754..ef02fbf 100644 --- a/.appveyor/appveyor.test.ps1 +++ b/.appveyor/appveyor.test.ps1 @@ -1,6 +1,6 @@ -. ./appveyor.before-tests.ps1; +. .\.appveyor\appveyor.before-tests.ps1; -& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:`"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe`" -targetargs:`"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\Debug\Managed.Adb.Tests.dll /noshadow /nologo /notrait category=IntegrationTest`" -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml +& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:`"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe`" -targetargs:`"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\${ENV:PLATFORM}\${ENV:CONFIGURATION}\Managed.Adb.Tests.dll /noshadow /nologo /notrait category=IntegrationTest`" -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml codecov -f `"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml`" -X gcov; -. ./appveyor.after-tests.ps1; +. .\.appveyor\appveyor.after-tests.ps1; diff --git a/Managed.Adb.Tests/Managed.Adb.Tests.csproj b/Managed.Adb.Tests/Managed.Adb.Tests.csproj index 8b5680f..25febd5 100644 --- a/Managed.Adb.Tests/Managed.Adb.Tests.csproj +++ b/Managed.Adb.Tests/Managed.Adb.Tests.csproj @@ -30,10 +30,10 @@ AllRules.ruleset x86 true - + bin\$(Platform)\$(Configuration)\ + true - bin\x64\Debug\ TRACE;DEBUG;PLATFORMX64 full x64 @@ -41,7 +41,7 @@ MinimumRecommendedRules.ruleset - bin\x64\Release\ + true TRACE;DEBUG;PLATFORMX64 true full @@ -51,7 +51,6 @@ true - bin\x86\Debug\ TRACE;DEBUG;PLATFORMX86 full x86 @@ -59,7 +58,7 @@ MinimumRecommendedRules.ruleset - bin\x86\Release\ + true TRACE;DEBUG;PLATFORMX86 true full From fe5c4ced984644c8d9bc7f76eda148d4fa6c8406 Mon Sep 17 00:00:00 2001 From: camalot Date: Sun, 10 Apr 2016 12:09:41 -0500 Subject: [PATCH 19/24] updated the build configurations in the solution --- .appveyor/appveyor.test.ps1 | 6 ++-- .build/BuildAll.msbuild | 2 +- Managed.Adb.Tests/Managed.Adb.Tests.csproj | 25 ++-------------- Managed.AndroidDebugBridge.sln | 34 ---------------------- README.md | 1 + 5 files changed, 7 insertions(+), 61 deletions(-) diff --git a/.appveyor/appveyor.test.ps1 b/.appveyor/appveyor.test.ps1 index ef02fbf..86c7b31 100644 --- a/.appveyor/appveyor.test.ps1 +++ b/.appveyor/appveyor.test.ps1 @@ -1,6 +1,4 @@ -. .\.appveyor\appveyor.before-tests.ps1; -& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:`"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe`" -targetargs:`"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\${ENV:PLATFORM}\${ENV:CONFIGURATION}\Managed.Adb.Tests.dll /noshadow /nologo /notrait category=IntegrationTest`" -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml -codecov -f `"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml`" -X gcov; +& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:`"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe`" -targetargs:`"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\x86\Debug\Managed.Adb.Tests.dll /noshadow /nologo /notrait category=IntegrationTest`" -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml -. .\.appveyor\appveyor.after-tests.ps1; +codecov -f `"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml`" -X gcov; \ No newline at end of file diff --git a/.build/BuildAll.msbuild b/.build/BuildAll.msbuild index 7327fc1..b4adda9 100644 --- a/.build/BuildAll.msbuild +++ b/.build/BuildAll.msbuild @@ -16,7 +16,7 @@ - + diff --git a/Managed.Adb.Tests/Managed.Adb.Tests.csproj b/Managed.Adb.Tests/Managed.Adb.Tests.csproj index 25febd5..a0b18ab 100644 --- a/Managed.Adb.Tests/Managed.Adb.Tests.csproj +++ b/Managed.Adb.Tests/Managed.Adb.Tests.csproj @@ -26,45 +26,26 @@ true GlobalSuppressions.cs prompt - true + false AllRules.ruleset - x86 true bin\$(Platform)\$(Configuration)\ - true TRACE;DEBUG;PLATFORMX64 - full - x64 - prompt - MinimumRecommendedRules.ruleset + x64 - true TRACE;DEBUG;PLATFORMX64 - true - full - x64 - prompt - MinimumRecommendedRules.ruleset + x64 - true TRACE;DEBUG;PLATFORMX86 - full x86 - prompt - MinimumRecommendedRules.ruleset - true TRACE;DEBUG;PLATFORMX86 - true - full x86 - prompt - MinimumRecommendedRules.ruleset diff --git a/Managed.AndroidDebugBridge.sln b/Managed.AndroidDebugBridge.sln index b06b268..4b9c396 100644 --- a/Managed.AndroidDebugBridge.sln +++ b/Managed.AndroidDebugBridge.sln @@ -71,72 +71,38 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Managed.Adb.Tests", "Manage EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|Mixed Platforms = Debug|Mixed Platforms Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|Mixed Platforms = Release|Mixed Platforms Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Any CPU.ActiveCfg = Debug|x86 - {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Any CPU.Build.0 = Debug|x86 - {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|Mixed Platforms.Build.0 = Debug|x86 {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|x64.ActiveCfg = Debug|x64 {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|x64.Build.0 = Debug|x64 {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|x86.ActiveCfg = Debug|x86 {65473257-E70F-410B-9269-D0C0F771EA87}.Debug|x86.Build.0 = Debug|x86 - {65473257-E70F-410B-9269-D0C0F771EA87}.Release|Any CPU.ActiveCfg = Release|x86 - {65473257-E70F-410B-9269-D0C0F771EA87}.Release|Any CPU.Build.0 = Release|x86 - {65473257-E70F-410B-9269-D0C0F771EA87}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {65473257-E70F-410B-9269-D0C0F771EA87}.Release|Mixed Platforms.Build.0 = Release|x86 {65473257-E70F-410B-9269-D0C0F771EA87}.Release|x64.ActiveCfg = Release|x64 {65473257-E70F-410B-9269-D0C0F771EA87}.Release|x64.Build.0 = Release|x64 {65473257-E70F-410B-9269-D0C0F771EA87}.Release|x86.ActiveCfg = Release|x86 {65473257-E70F-410B-9269-D0C0F771EA87}.Release|x86.Build.0 = Release|x86 - {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|Any CPU.ActiveCfg = Debug|x86 - {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|Any CPU.Build.0 = Debug|x86 - {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|Mixed Platforms.Build.0 = Debug|x86 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|x64.ActiveCfg = Debug|x64 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|x64.Build.0 = Debug|x64 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|x86.ActiveCfg = Debug|x86 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Debug|x86.Build.0 = Debug|x86 - {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|Any CPU.ActiveCfg = Release|x86 - {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|Any CPU.Build.0 = Release|x86 - {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|Mixed Platforms.Build.0 = Release|x86 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|x64.ActiveCfg = Release|x64 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|x64.Build.0 = Release|x64 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|x86.ActiveCfg = Release|x86 {F9A436F4-0606-4326-8607-9EA4D9E6AF18}.Release|x86.Build.0 = Release|x86 - {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|x64.ActiveCfg = Debug|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|x86.ActiveCfg = Debug|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Debug|x86.Build.0 = Debug|Any CPU - {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|Any CPU.Build.0 = Release|Any CPU - {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|Mixed Platforms.Build.0 = Release|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|x64.ActiveCfg = Release|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|x86.ActiveCfg = Release|Any CPU {A3BA455F-4829-4412-9ACC-DEFBC1BC84FC}.Release|x86.Build.0 = Release|Any CPU - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Any CPU.ActiveCfg = Debug|x86 - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Mixed Platforms.Build.0 = Debug|x86 {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x64.ActiveCfg = Debug|x64 {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x64.Build.0 = Debug|x64 {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x86.ActiveCfg = Debug|x86 {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x86.Build.0 = Debug|x86 - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Any CPU.ActiveCfg = Release|x86 - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Mixed Platforms.Build.0 = Release|x86 {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x64.ActiveCfg = Debug|x64 {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x64.Build.0 = Debug|x64 {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x86.ActiveCfg = Debug|x86 diff --git a/README.md b/README.md index 5202894..4a2ea47 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![MadBee](http://i.imgur.com/UxO8Lrj.png)](http://madb.bit13.com/) [![Build status](https://ci.appveyor.com/api/projects/status/dn8mjauo4i5ghwlg?svg=true)](https://ci.appveyor.com/project/camalot/madb) +[![Code Coverage by CodeCov](https://codecov.io/github/camalot/madb/coverage.svg)](https://codecov.io/github/camalot/madb) This is a Managed port of the Android Debug Bridge to allow communication from .NET applications to Android devices. This wraps the same methods that the ddms uses to directly communicate with ADB. From a828538f3e0cf211b972300cf9c77dc20e218afe Mon Sep 17 00:00:00 2001 From: camalot Date: Sun, 10 Apr 2016 12:15:53 -0500 Subject: [PATCH 20/24] removed switches again, i thought i had it fixed. Hopefully the tests actually run now too. --- .appveyor/appveyor.test.ps1 | 4 +-- license.md | 50 +++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/.appveyor/appveyor.test.ps1 b/.appveyor/appveyor.test.ps1 index 86c7b31..c90ac2b 100644 --- a/.appveyor/appveyor.test.ps1 +++ b/.appveyor/appveyor.test.ps1 @@ -1,4 +1,4 @@ - -& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:`"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe`" -targetargs:`"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\x86\Debug\Managed.Adb.Tests.dll /noshadow /nologo /notrait category=IntegrationTest`" -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml +# /noshadow /nologo /notrait category=IntegrationTest +& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:`"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe`" -targetargs:`"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\x86\Debug\Managed.Adb.Tests.dll`" -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml codecov -f `"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml`" -X gcov; \ No newline at end of file diff --git a/license.md b/license.md index 9e49556..6989bd3 100644 --- a/license.md +++ b/license.md @@ -1,4 +1,5 @@ -Copyright 2015 Ryan Conrad +Copyright 2010-2015 Ryan Conrad +Copyright 2007 The Android Open Source Project (original Java project) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -10,4 +11,49 @@ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and -limitations under the License. \ No newline at end of file +limitations under the License. + +Portions are: +Copyright (c) 2004-2008 Jon Skeet and Marc Gravell +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +3. The end-user documentation included with the redistribution, if +any, must include the following acknowledgment: + +"This product includes software developed by Jon Skeet +and Marc Gravell. Contact skeet@pobox.com, or see +http://www.pobox.com/~skeet/)." + +Alternately, this acknowledgment may appear in the software itself, +if and wherever such third-party acknowledgments normally appear. + +4. The name "Miscellaneous Utility Library" must not be used to endorse +or promote products derived from this software without prior written +permission. For written permission, please contact skeet@pobox.com. + +5. Products derived from this software may not be called +"Miscellaneous Utility Library", nor may "Miscellaneous Utility Library" +appear in their name, without prior written permission of Jon Skeet. + +THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL JON SKEET BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file From 6ca669fc84b5195a9af7e13e7a1313457dc9096d Mon Sep 17 00:00:00 2001 From: camalot Date: Sun, 10 Apr 2016 14:10:04 -0500 Subject: [PATCH 21/24] Run tests locally with the BuildAll. updated the appveyor script to run correctly??? I hope. --- .appveyor/appveyor.test.ps1 | 3 ++- .build/BuildAll.msbuild | 6 +++++- Managed.Adb.Tests/Managed.Adb.Tests.csproj | 8 ++++++-- Managed.Adb.Tests/xunit.runner.json | 2 +- Managed.AndroidDebugBridge.sln | 8 ++++---- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.appveyor/appveyor.test.ps1 b/.appveyor/appveyor.test.ps1 index c90ac2b..4b8093e 100644 --- a/.appveyor/appveyor.test.ps1 +++ b/.appveyor/appveyor.test.ps1 @@ -1,4 +1,5 @@ # /noshadow /nologo /notrait category=IntegrationTest -& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:`"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe`" -targetargs:`"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\x86\Debug\Managed.Adb.Tests.dll`" -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml + +& "${ENV:APPVEYOR_BUILD_FOLDER}\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -log:All -register:user -target:`"${ENV:APPVEYOR_BUILD_FOLDER}\packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe`" -filter:`"+[Managed.Adb]* -[Managed.Adb]Managed.Adb.Properties.*`" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:`"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml`" -targetargs:`"`\`"${ENV:APPVEYOR_BUILD_FOLDER}\Managed.Adb.Tests\bin\x86\Debug\Managed.Adb.Tests.dll`\`" -verbose -noshadow `"; codecov -f `"${ENV:APPVEYOR_BUILD_FOLDER}\managed.adb.coverage.xml`" -X gcov; \ No newline at end of file diff --git a/.build/BuildAll.msbuild b/.build/BuildAll.msbuild index b4adda9..68a7acb 100644 --- a/.build/BuildAll.msbuild +++ b/.build/BuildAll.msbuild @@ -1,7 +1,6 @@ - @@ -19,6 +18,11 @@ + + + \ No newline at end of file diff --git a/Managed.Adb.Tests/Managed.Adb.Tests.csproj b/Managed.Adb.Tests/Managed.Adb.Tests.csproj index a0b18ab..1201f5c 100644 --- a/Managed.Adb.Tests/Managed.Adb.Tests.csproj +++ b/Managed.Adb.Tests/Managed.Adb.Tests.csproj @@ -32,19 +32,23 @@ bin\$(Platform)\$(Configuration)\ + bin\x64\Debug\ TRACE;DEBUG;PLATFORMX64 x64 - TRACE;DEBUG;PLATFORMX64 + bin\x64\Release\ + TRACE;PLATFORMX64 x64 + bin\x86\Debug\ TRACE;DEBUG;PLATFORMX86 x86 - TRACE;DEBUG;PLATFORMX86 + bin\x86\Release\ + TRACE;PLATFORMX86 x86 diff --git a/Managed.Adb.Tests/xunit.runner.json b/Managed.Adb.Tests/xunit.runner.json index d177980..67d7a69 100644 --- a/Managed.Adb.Tests/xunit.runner.json +++ b/Managed.Adb.Tests/xunit.runner.json @@ -1,3 +1,3 @@ { - + "shadowCopy": false } diff --git a/Managed.AndroidDebugBridge.sln b/Managed.AndroidDebugBridge.sln index 4b9c396..8e1d1b4 100644 --- a/Managed.AndroidDebugBridge.sln +++ b/Managed.AndroidDebugBridge.sln @@ -103,10 +103,10 @@ Global {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x64.Build.0 = Debug|x64 {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x86.ActiveCfg = Debug|x86 {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|x86.Build.0 = Debug|x86 - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x64.ActiveCfg = Debug|x64 - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x64.Build.0 = Debug|x64 - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x86.ActiveCfg = Debug|x86 - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x86.Build.0 = Debug|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x64.ActiveCfg = Release|x64 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x64.Build.0 = Release|x64 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x86.ActiveCfg = Release|x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 580e805d3a0a351023540bb8af363c96c081783a Mon Sep 17 00:00:00 2001 From: camalot Date: Sun, 10 Apr 2016 15:04:38 -0500 Subject: [PATCH 22/24] Added some tests. --- .../ForLinuxPath/ChangeExtensionTests.cs | 6 +- .../ForLinuxPath/CombineTests.cs | 54 ++++++------ .../ForLinuxPath/GetDirectoryNameTests.cs | 6 +- Managed.Adb.Tests/ForLinuxPath/GetFileName.cs | 54 ++++++++++++ .../ForLinuxPath/GetInvalidFileNameChars.cs | 17 ++++ .../ForLinuxPath/GetInvalidPathChars.cs | 20 +++++ Managed.Adb.Tests/ForLinuxPath/GetPathRoot.cs | 43 ++++++++++ .../ForLinuxPath/HasExtension.cs | 51 ++++++++++++ .../ForLinuxPath/LinuxPathConsts.cs | 8 +- Managed.Adb.Tests/Managed.Adb.Tests.csproj | 53 ++++++------ Managed.AndroidDebugBridge/IO/LinuxPath.cs | 82 ++++++++----------- 11 files changed, 286 insertions(+), 108 deletions(-) create mode 100644 Managed.Adb.Tests/ForLinuxPath/GetFileName.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/GetInvalidFileNameChars.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/GetInvalidPathChars.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/GetPathRoot.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/HasExtension.cs diff --git a/Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs b/Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs index 7d3d09c..8032f5a 100644 --- a/Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs +++ b/Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs @@ -22,15 +22,15 @@ public void WhenPathIsNull_ShouldReturnNull () { [Fact] public void WhenPathContainsInvalidCharacter_ShouldThrowArgumentException ( ) { int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.ChangeExtension ("/my-invalid-path/f-{0}".With ( LinuxPathConsts.InvalidChars[x]), "ext" ); + string result = LinuxPath.ChangeExtension ("/my-invalid-path/f-{0}".With ( LinuxPathConsts.InvalidPathChars[x]), "ext" ); } catch (ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } [Fact] diff --git a/Managed.Adb.Tests/ForLinuxPath/CombineTests.cs b/Managed.Adb.Tests/ForLinuxPath/CombineTests.cs index c2823ca..3f32ae5 100644 --- a/Managed.Adb.Tests/ForLinuxPath/CombineTests.cs +++ b/Managed.Adb.Tests/ForLinuxPath/CombineTests.cs @@ -63,15 +63,15 @@ public void When2ArgsAndPath2IsEmptyAndPath2IsRooted_ShouldReturnRootedPath1 ( ) public void When2ArgsAndPath1ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { var fixture = new Fixture ( ); int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.Combine ( "/{0}-{1}".With ( LinuxPathConsts.InvalidChars[x], fixture.Create ( "path1" ) ), fixture.Create ( "path2" ) ); + string result = LinuxPath.Combine ( "/{0}-{1}".With ( LinuxPathConsts.InvalidPathChars[x], fixture.Create ( "path1" ) ), fixture.Create ( "path2" ) ); } catch ( ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } @@ -79,15 +79,15 @@ public void When2ArgsAndPath1ContainsInvalidCharacter_ShouldThrowArgumentExcepti public void When2ArgsAndPath2ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { var fixture = new Fixture ( ); int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), "{0}-{1}".With ( fixture.Create ( "path2" ), LinuxPathConsts.InvalidChars[x] ) ); + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), "{0}-{1}".With ( fixture.Create ( "path2" ), LinuxPathConsts.InvalidPathChars[x] ) ); } catch ( ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } @@ -146,15 +146,15 @@ public void When3ArgsAndPath3IsNull_ShouldThrowArgumentNullException ( ) { public void When3ArgsAndPath1ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { var fixture = new Fixture ( ); int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.Combine ( "/{0}-{1}".With ( LinuxPathConsts.InvalidChars[x], fixture.Create ( "path1" ) ), fixture.Create ( "path2" ) ); + string result = LinuxPath.Combine ( "/{0}-{1}".With ( LinuxPathConsts.InvalidPathChars[x], fixture.Create ( "path1" ) ), fixture.Create ( "path2" ) ); } catch ( ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } @@ -162,15 +162,15 @@ public void When3ArgsAndPath1ContainsInvalidCharacter_ShouldThrowArgumentExcepti public void When3ArgsAndPath2ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { var fixture = new Fixture ( ); int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), "{0}-{1}".With ( fixture.Create ( "path2" ), LinuxPathConsts.InvalidChars[x] ) ); + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), "{0}-{1}".With ( fixture.Create ( "path2" ), LinuxPathConsts.InvalidPathChars[x] ) ); } catch ( ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } @@ -178,15 +178,15 @@ public void When3ArgsAndPath2ContainsInvalidCharacter_ShouldThrowArgumentExcepti public void When3ArgsAndPath3ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { var fixture = new Fixture ( ); int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), fixture.Create ( "path2" ), "{0}-{1}".With ( fixture.Create ( "path3" ), LinuxPathConsts.InvalidChars[x] ) ); + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), fixture.Create ( "path2" ), "{0}-{1}".With ( fixture.Create ( "path3" ), LinuxPathConsts.InvalidPathChars[x] ) ); } catch ( ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } @@ -235,15 +235,15 @@ public void When4ArgsAndPath4IsNull_ShouldThrowArgumentNullException ( ) { public void When4ArgsAndPath1ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { var fixture = new Fixture ( ); int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.Combine ( "/{0}-{1}".With ( LinuxPathConsts.InvalidChars[x], fixture.Create ( "path1" ) ), fixture.Create ( "path2" ) ); + string result = LinuxPath.Combine ( "/{0}-{1}".With ( LinuxPathConsts.InvalidPathChars[x], fixture.Create ( "path1" ) ), fixture.Create ( "path2" ) ); } catch ( ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } @@ -251,15 +251,15 @@ public void When4ArgsAndPath1ContainsInvalidCharacter_ShouldThrowArgumentExcepti public void When4ArgsAndPath2ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { var fixture = new Fixture ( ); int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), "{0}-{1}".With ( fixture.Create ( "path2" ), LinuxPathConsts.InvalidChars[x] ) ); + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), "{0}-{1}".With ( fixture.Create ( "path2" ), LinuxPathConsts.InvalidPathChars[x] ) ); } catch ( ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } @@ -267,15 +267,15 @@ public void When4ArgsAndPath2ContainsInvalidCharacter_ShouldThrowArgumentExcepti public void When4ArgsAndPath3ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { var fixture = new Fixture ( ); int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), fixture.Create ( "path2" ), "{0}-{1}".With ( fixture.Create ( "path3" ), LinuxPathConsts.InvalidChars[x] ) ); + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), fixture.Create ( "path2" ), "{0}-{1}".With ( fixture.Create ( "path3" ), LinuxPathConsts.InvalidPathChars[x] ) ); } catch ( ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } @@ -283,15 +283,15 @@ public void When4ArgsAndPath3ContainsInvalidCharacter_ShouldThrowArgumentExcepti public void When4ArgsAndPath4ContainsInvalidCharacter_ShouldThrowArgumentException ( ) { var fixture = new Fixture ( ); int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), fixture.Create ( "path2" ), fixture.Create ( "path3" ), "{0}-{1}".With ( fixture.Create ( "path4" ), LinuxPathConsts.InvalidChars[x] ) ); + string result = LinuxPath.Combine ( "/{0}".With ( fixture.Create ( "path1" ) ), fixture.Create ( "path2" ), fixture.Create ( "path3" ), "{0}-{1}".With ( fixture.Create ( "path4" ), LinuxPathConsts.InvalidPathChars[x] ) ); } catch ( ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } diff --git a/Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs b/Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs index ac51dcd..00060f7 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs +++ b/Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs @@ -20,15 +20,15 @@ public void WhenPathIsNull_ShouldReturnNull ( ) { [Fact] public void WhenPathContainsInvalidCharacters_ShouldThrowException ( ) { int errorCount = 0; - for ( var x = 0; x < LinuxPathConsts.InvalidChars.Length; ++x ) { + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { try { - string result = LinuxPath.GetDirectoryName ( "/my-invalid-path/f-{0}".With ( LinuxPathConsts.InvalidChars[x] ) ); + string result = LinuxPath.GetDirectoryName ( "/my-invalid-path/f-{0}".With ( LinuxPathConsts.InvalidPathChars[x] ) ); } catch ( ArgumentException ) { errorCount++; } } - Assert.Equal ( LinuxPathConsts.InvalidChars.Length, errorCount ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); } [Fact] diff --git a/Managed.Adb.Tests/ForLinuxPath/GetFileName.cs b/Managed.Adb.Tests/ForLinuxPath/GetFileName.cs new file mode 100644 index 0000000..fff9037 --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/GetFileName.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Camalot.Common.Extensions; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class GetFileName { + + [Fact] + public void WhenPathIsNull_ShouldReturnNull ( ) { + var fixture = new Fixture ( ); + var result = LinuxPath.GetFileName ( null ); + Assert.Null ( result ); + } + + [Fact] + public void WhenPathIsDirectory_ShouldReturnEmpty ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1-" ); + var p2 = "{0}/".With ( fixture.Create ( "path2-" ) ); + var p = LinuxPath.Combine ( p1, p2 ); + var result = LinuxPath.GetFileName ( p ); + Assert.Equal ( string.Empty, result ); + } + + [Fact] + public void WhenPathIsFileWithExtension_ShouldReturnFileWithExtension ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1-" ); + var p2 = "{0}/".With ( fixture.Create ( "path2-" ) ); + var f = "{0}{1}".With ( fixture.Create ( "file-" ), ".ext1" ); + var p = LinuxPath.Combine ( p1, p2, f ); + var result = LinuxPath.GetFileName ( p ); + Assert.Equal ( f, result ); + } + + [Fact] + public void WhenPathIsFileWithoutExtension_ShouldReturnFileWithoutExtension ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1-" ); + var p2 = "{0}/".With ( fixture.Create ( "path2-" ) ); + var f = "{0}".With ( fixture.Create ( "file-" ) ); + var p = LinuxPath.Combine ( p1, p2, f ); + var result = LinuxPath.GetFileName ( p ); + Assert.Equal ( f, result ); + } + } +} + diff --git a/Managed.Adb.Tests/ForLinuxPath/GetInvalidFileNameChars.cs b/Managed.Adb.Tests/ForLinuxPath/GetInvalidFileNameChars.cs new file mode 100644 index 0000000..a2b924b --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/GetInvalidFileNameChars.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Managed.Adb.IO; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class GetInvalidFileNameChars { + [Fact] + public void WhenGetttingInvalidFileNameChars_ShouldEqualExpected () { + var result = LinuxPath.GetInvalidFileNameChars ( ); + Assert.Equal ( LinuxPathConsts.InvalidFileNameChars, result ); + } + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/GetInvalidPathChars.cs b/Managed.Adb.Tests/ForLinuxPath/GetInvalidPathChars.cs new file mode 100644 index 0000000..b96e3e2 --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/GetInvalidPathChars.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Managed.Adb.IO; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class GetInvalidPathChars { + [Fact] + public void WhenGetttingInvalidPathChars_ShouldEqualExpected ( ) { + var result = LinuxPath.GetInvalidPathChars ( ); + Assert.Equal ( LinuxPathConsts.InvalidPathChars, result ); + } + + + + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/GetPathRoot.cs b/Managed.Adb.Tests/ForLinuxPath/GetPathRoot.cs new file mode 100644 index 0000000..b01d2b5 --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/GetPathRoot.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class GetPathRoot { + [Fact] + public void WhenPathIsNull_ShouldReturnNull () { + var result = LinuxPath.GetPathRoot ( null ); + Assert.Null ( result ); + } + + [Fact] + public void WhenPathEmpty_ShouldReturnRelativeCurrentPath ( ) { + var result = LinuxPath.GetPathRoot ( string.Empty ); + Assert.Equal ( "./", result ); + } + + [Fact] + public void WhenPathIsRooted_ShouldReturnRootPath () { + var fixture = new Fixture ( ); + var path = fixture.Create ( "/path-" ); + var result = LinuxPath.GetPathRoot ( path ); + Assert.Equal ( "/", result ); + } + + [Fact] + public void WhenPathIsRelative_ShouldReturnRelativeCurrentPath ( ) { + var fixture = new Fixture ( ); + var path = fixture.Create ( "path-" ); + var result = LinuxPath.GetPathRoot ( path ); + Assert.Equal ( "./", result ); + } + + } + + +} diff --git a/Managed.Adb.Tests/ForLinuxPath/HasExtension.cs b/Managed.Adb.Tests/ForLinuxPath/HasExtension.cs new file mode 100644 index 0000000..c60f6c5 --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/HasExtension.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Camalot.Common.Extensions; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class HasExtension { + [Fact] + public void WhenPathIsNull_ShouldReturnFalse () { + var result = LinuxPath.HasExtension ( null ); + Assert.False ( result ); + } + + [Fact] + public void WhenPathIsEmpty_ShouldReturnFalse ( ) { + var result = LinuxPath.HasExtension ( string.Empty ); + Assert.False ( result ); + } + + [Fact] + public void WhenPathDoesNotHaveFile_ShouldReturnFalse ( ) { + var fixture = new Fixture ( ); + var path = "/path/to/file/"; + var result = LinuxPath.HasExtension ( path ); + Assert.False ( result ); + } + + [Fact] + public void WhenPathHasExtension_ShouldReturnTrue ( ) { + var fixture = new Fixture ( ); + var file = fixture.Create ( "file-" ); + var path = "/path/to/file/{0}.ext".With ( file ); + var result = LinuxPath.HasExtension ( path ); + Assert.True ( result ); + } + + [Fact] + public void WhenPathDoesNotHaveExtension_ShouldReturnFalse ( ) { + var fixture = new Fixture ( ); + var file = fixture.Create ( "file-" ); + var path = "/path/to/file/{0}".With ( file ); + var result = LinuxPath.HasExtension ( path ); + Assert.False ( result ); + } + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs b/Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs index f431b9c..81b5ca1 100644 --- a/Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs +++ b/Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs @@ -6,11 +6,17 @@ namespace Managed.Adb.Tests.ForLinuxPath { internal class LinuxPathConsts { - internal static readonly char[] InvalidChars = new char[] { + internal static readonly char[] InvalidPathChars = new char[] { '"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v', '\f', '\r', '\x000e', '\x000f', '\x0010', '\x0011', '\x0012', '\x0013', '\x0014', '\x0015', '\x0016', '\x0017', '\x0018', '\x0019', '\x001a', '\x001b', '\x001c', '\x001d', '\x001e', '\x001f' }; + internal static readonly char[] InvalidFileNameChars = new char[] { + '"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v', + '\f', '\r', '\x000e', '\x000f', '\x0010', '\x0011', '\x0012', '\x0013', '\x0014', '\x0015', '\x0016', '\x0017', '\x0018', '\x0019', '\x001a', '\x001b', + '\x001c', '\x001d', '\x001e', '\x001f', '*', '?', '\\', '/' + }; + } } diff --git a/Managed.Adb.Tests/Managed.Adb.Tests.csproj b/Managed.Adb.Tests/Managed.Adb.Tests.csproj index 1201f5c..3df252a 100644 --- a/Managed.Adb.Tests/Managed.Adb.Tests.csproj +++ b/Managed.Adb.Tests/Managed.Adb.Tests.csproj @@ -3,9 +3,9 @@ - Debug - x86 - {2E3DF5C2-8A38-4A03-86D7-8D463C917E47} + Debug + x86 + {2E3DF5C2-8A38-4A03-86D7-8D463C917E47} Library Properties Managed.Adb.Tests @@ -20,35 +20,35 @@ UnitTest b0edf53b - true - TRACE;DEBUG;PLATFORMX86 - full - true - GlobalSuppressions.cs - prompt - false - AllRules.ruleset - true - bin\$(Platform)\$(Configuration)\ - + true + TRACE;DEBUG;PLATFORMX86 + full + true + GlobalSuppressions.cs + prompt + false + AllRules.ruleset + true + bin\$(Platform)\$(Configuration)\ + - bin\x64\Debug\ - TRACE;DEBUG;PLATFORMX64 - x64 + bin\x64\Debug\ + TRACE;DEBUG;PLATFORMX64 + x64 - bin\x64\Release\ - TRACE;PLATFORMX64 - x64 + bin\x64\Release\ + TRACE;PLATFORMX64 + x64 - bin\x86\Debug\ - TRACE;DEBUG;PLATFORMX86 + bin\x86\Debug\ + TRACE;DEBUG;PLATFORMX86 x86 - bin\x86\Release\ - TRACE;PLATFORMX86 + bin\x86\Release\ + TRACE;PLATFORMX86 x86 @@ -105,7 +105,12 @@ + + + + + diff --git a/Managed.AndroidDebugBridge/IO/LinuxPath.cs b/Managed.AndroidDebugBridge/IO/LinuxPath.cs index 5f98020..2dd14ae 100644 --- a/Managed.AndroidDebugBridge/IO/LinuxPath.cs +++ b/Managed.AndroidDebugBridge/IO/LinuxPath.cs @@ -28,9 +28,9 @@ public static class LinuxPath { /// /// Invalid characters for a file name /// - private static readonly char[] InvalidFileNameChars = new char[] { - '"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v', - '\f', '\r', '\x000e', '\x000f', '\x0010', '\x0011', '\x0012', '\x0013', '\x0014', '\x0015', '\x0016', '\x0017', '\x0018', '\x0019', '\x001a', '\x001b', + private static readonly char[] InvalidFileNameChars = new char[] { + '"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v', + '\f', '\r', '\x000e', '\x000f', '\x0010', '\x0011', '\x0012', '\x0013', '\x0014', '\x0015', '\x0016', '\x0017', '\x0018', '\x0019', '\x001a', '\x001b', '\x001c', '\x001d', '\x001e', '\x001f', '*', '?', '\\', '/' }; /// @@ -52,9 +52,9 @@ public static class LinuxPath { /// /// Invalid characters for a file/directory path /// - private static readonly char[] RealInvalidPathChars = new char[] { - '"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v', - '\f', '\r', '\x000e', '\x000f', '\x0010', '\x0011', '\x0012', '\x0013', '\x0014', '\x0015', '\x0016', '\x0017', '\x0018', '\x0019', '\x001a', '\x001b', + private static readonly char[] RealInvalidPathChars = new char[] { + '"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v', + '\f', '\r', '\x000e', '\x000f', '\x0010', '\x0011', '\x0012', '\x0013', '\x0014', '\x0015', '\x0016', '\x0017', '\x0018', '\x0019', '\x001a', '\x001b', '\x001c', '\x001d', '\x001e', '\x001f' }; @@ -77,7 +77,7 @@ public static string ChangeExtension ( string path, string extension ) { str = path.Substring ( 0, length ); break; } - if ( ( ( ch == DirectorySeparatorChar ) || ( ch == AltDirectorySeparatorChar ) ) ) { + if ( IsDirectorySeparator(ch) ) { break; } } @@ -95,7 +95,7 @@ public static string ChangeExtension ( string path, string extension ) { /// Checks the invalid path chars. /// /// The path. - internal static void CheckInvalidPathChars( string path ) { + internal static void CheckInvalidPathChars ( string path ) { for ( int i = 0; i < path.Length; i++ ) { int num2 = path[i]; if ( ( ( num2 == 0x22 ) || ( num2 == 60 ) ) || ( ( ( num2 == 0x3e ) || ( num2 == 0x7c ) ) || ( num2 < 0x20 ) ) ) { @@ -128,7 +128,7 @@ public static string Combine ( params string[] paths ) { capacity += paths[i].Length; } char ch = paths[i][paths[i].Length - 1]; - if ( ( ( ch != DirectorySeparatorChar ) && ( ch != AltDirectorySeparatorChar ) ) ) { + if ( !IsDirectorySeparator(ch) ) { capacity++; } } @@ -140,10 +140,10 @@ public static string Combine ( params string[] paths ) { builder.Append ( FixupPath ( paths[j] ) ); } else { char ch2 = builder[builder.Length - 1]; - if ( ( ( ch2 != DirectorySeparatorChar ) && ( ch2 != AltDirectorySeparatorChar ) ) ) { + if ( !IsDirectorySeparator(ch2) ) { builder.Append ( DirectorySeparatorChar ); } - builder.Append ( paths[j] ); + builder.Append ( paths[j] ); } } } @@ -151,32 +151,6 @@ public static string Combine ( params string[] paths ) { } - /// - /// Combines the path with no checks. - /// - /// The path1. - /// The path2. - /// - private static string CombineNoChecks ( string path1, string path2 ) { - if ( path2.Length == 0 ) { - return FixupPath ( path1 ); - } - if ( path1.Length == 0 ) { - return FixupPath ( path2 ); - } - if ( IsPathRooted ( path2 ) ) { - return FixupPath ( path2 ); - } - char ch = path1[path1.Length - 1]; - char ch2 = path2[0]; - if ( ch != DirectorySeparatorChar && ch != AltDirectorySeparatorChar && - ch2 != DirectorySeparatorChar && ch2 != AltDirectorySeparatorChar ) { - return ( FixupPath ( path1 ) + path2 ).REReplace ( "//", "/" ); - } - return ( FixupPath ( path1 ) + path2 ).REReplace ( "//", "/" ); - } - - /// Returns the directory information for the specified path string. /// A containing directory information for path, or null if path denotes a root directory, is the empty string (""), or is null. Returns if path does not contain directory information. @@ -188,10 +162,10 @@ public static string GetDirectoryName ( string path ) { if ( path != null ) { CheckInvalidPathChars ( path ); var tpath = path; - if ( tpath.EndsWith ( new string ( new char[] { DirectorySeparatorChar } ) ) ) { + if ( EndsWithDirectorySeparator(tpath) ) { return FixupPath ( tpath ); } else { - var end = tpath.LastIndexOf ( new string ( new char[] { DirectorySeparatorChar } ) ); + var end = tpath.LastIndexOfAny ( new char[] { DirectorySeparatorChar, AltDirectorySeparatorChar } ); end = end < 0 ? tpath.Length : end; return FixupPath ( tpath.Substring ( 0, end ) ); } @@ -210,7 +184,7 @@ public static string GetPathWithoutFile ( string path ) { string tfilename = GetFileName ( path ); string tpath = path.Substring ( 0, path.Length - tfilename.Length ); tpath = FixupPath ( tpath ); - return tpath.Substring ( 0, tpath.LastIndexOf ( DirectorySeparatorChar ) + 1 ); + return tpath.Substring ( 0, tpath.LastIndexOfAny ( new char[] { DirectorySeparatorChar, AltDirectorySeparatorChar } ) + 1 ); } return null; } @@ -225,11 +199,11 @@ private static string FixupPath ( string path ) { sb = sb.Replace ( System.IO.Path.DirectorySeparatorChar, DirectorySeparatorChar ); - if ( !sb.StartsWith ( new string ( new char[] { DirectorySeparatorChar } ) ) ) { + if ( !StartsWithDirectorySeparator(sb) ) { sb = string.Format ( ".{0}{1}", DirectorySeparatorChar, sb ); } - if ( !sb.EndsWith ( new string ( new char[] { DirectorySeparatorChar } ) ) ) { + if ( !EndsWithDirectorySeparator(sb) ) { sb = string.Format ( "{0}{1}", sb, DirectorySeparatorChar ); } @@ -258,7 +232,7 @@ public static string GetExtension ( string path ) { } return string.Empty; } - if ( ( ( ch == DirectorySeparatorChar ) || ( ch == AltDirectorySeparatorChar ) ) ) { + if ( IsDirectorySeparator ( ch ) ) { break; } } @@ -277,7 +251,7 @@ public static string GetFileName ( string path ) { int num2 = length; while ( --num2 >= 0 ) { char ch = path[num2]; - if ( ( ( ch == DirectorySeparatorChar ) || ( ch == AltDirectorySeparatorChar ) ) ) { + if ( IsDirectorySeparator ( ch ) ) { return path.Substring ( num2 + 1, ( length - num2 ) - 1 ); } } @@ -342,7 +316,7 @@ internal static int GetRootLength ( string path ) { if ( ( length >= 2 ) && IsDirectorySeparator ( path[1] ) ) { num = 2; int num3 = 2; - while ( ( num < length ) && ( ( ( path[num] != DirectorySeparatorChar ) && ( path[num] != AltDirectorySeparatorChar ) ) || ( --num3 > 0 ) ) ) { + while ( ( num < length ) && !IsDirectorySeparator(path[num] ) || ( --num3 > 0 ) ) { num++; } } @@ -365,7 +339,7 @@ internal static int GetRootLength ( string path ) { public static bool HasExtension ( string path ) { if ( path != null ) { CheckInvalidPathChars ( path ); - if ( path.EndsWith ( new string ( new char[] { DirectorySeparatorChar } ) ) || path.EndsWith ( new string ( new char[] { AltDirectorySeparatorChar } ) ) ) { + if ( EndsWithDirectorySeparator ( path ) ) { return false; } @@ -375,7 +349,7 @@ public static bool HasExtension ( string path ) { if ( ch == '.' ) { return ( length != ( path.Length - 1 ) ); } - if ( ( ( ch == DirectorySeparatorChar ) || ( ch == AltDirectorySeparatorChar ) ) ) { + if ( IsDirectorySeparator ( ch ) ) { break; } } @@ -390,6 +364,14 @@ internal static bool IsDirectorySeparator ( char c ) { return true; } + internal static bool EndsWithDirectorySeparator ( string path ) { + return path.EndsWith ( new string ( new char[] { DirectorySeparatorChar } ) ) || path.EndsWith ( new string ( new char[] { AltDirectorySeparatorChar } ) ); + } + + internal static bool StartsWithDirectorySeparator ( string path ) { + return path.StartsWith ( new string ( new char[] { DirectorySeparatorChar } ) ) || path.StartsWith ( new string ( new char[] { AltDirectorySeparatorChar } ) ); + } + /// Gets a value indicating whether the specified path string contains absolute or relative path information. /// true if path contains an absolute path; otherwise, false. /// The path to test. @@ -399,7 +381,7 @@ public static bool IsPathRooted ( string path ) { if ( path != null ) { CheckInvalidPathChars ( path ); int length = path.Length; - if ( ( length >= 1 && ( path[0] == DirectorySeparatorChar || path[0] == AltDirectorySeparatorChar ) ) || + if ( ( length >= 1 && IsDirectorySeparator ( path[0] ) ) || ( length == 1 ) ) { return true; } @@ -412,7 +394,7 @@ public static bool IsPathRooted ( string path ) { /// /// The path. /// - public static string Escape( string path ) { + public static string Escape ( string path ) { return new Regex ( ESCAPEPATTERN ).Replace ( path, new MatchEvaluator ( delegate ( Match m ) { return m.Result ( "\\\\$1" ); } ) ); @@ -423,7 +405,7 @@ public static string Escape( string path ) { /// /// The path. /// - public static string Quote( string path ) { + public static string Quote ( string path ) { if ( path.Contains ( " " ) ) { return string.Format ( "\"{0}\"", path ); } else { From 8e8a160a54a9ded4e811ecdb59e1ff4b7b0db8fa Mon Sep 17 00:00:00 2001 From: camalot Date: Sun, 10 Apr 2016 17:22:26 -0500 Subject: [PATCH 23/24] added tests --- Managed.Adb.Tests/ForLinuxPath/Escape.cs | 50 +++++++++++++ .../ForLinuxPath/GetExtension.cs | 61 ++++++++++++++++ Managed.Adb.Tests/ForLinuxPath/GetFileName.cs | 15 ++++ .../GetFileNameWithoutExtension.cs | 70 +++++++++++++++++++ .../ForLinuxPath/GetPathWithoutFile.cs | 16 +++++ Managed.Adb.Tests/ForLinuxPath/Quote.cs | 42 +++++++++++ Managed.Adb.Tests/Managed.Adb.Tests.csproj | 4 ++ Managed.AndroidDebugBridge/IO/LinuxPath.cs | 15 ++-- 8 files changed, 268 insertions(+), 5 deletions(-) create mode 100644 Managed.Adb.Tests/ForLinuxPath/Escape.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/GetExtension.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/GetFileNameWithoutExtension.cs create mode 100644 Managed.Adb.Tests/ForLinuxPath/Quote.cs diff --git a/Managed.Adb.Tests/ForLinuxPath/Escape.cs b/Managed.Adb.Tests/ForLinuxPath/Escape.cs new file mode 100644 index 0000000..fc71459 --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/Escape.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Camalot.Common.Extensions; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class Escape { + [Fact] + public void WhenPathIsNull_ShouldReturnThrowArgumentNullException () { + Assert.Throws(() => { + LinuxPath.Escape ( null ); + } ); + } + + [Fact] + public void WhenPathIsEmpty_ShouldReturnThrowArgumentNullException ( ) { + Assert.Throws ( ( ) => { + LinuxPath.Escape ( string.Empty ); + } ); + } + + + [Fact] + public void WhenPathDoesNotContainCharactersToEscape_ShouldReturnPathUnchanged ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "p1-" ); + var result = LinuxPath.Escape ( p1 ); + Assert.Equal ( p1, result ); + } + + [Fact] + public void WhenPathContiansCharacterToEscape_ShouldReturnEscapedString ( ) { + var chars = @"\()*+?""'#/".ToCharArray(); + var fixture = new Fixture ( ); + + foreach ( var c in chars ) { + var b = "before-"; + var a = "-after"; + var check = "{0}{1}{2}".With ( b, c, a); + var result = LinuxPath.Escape ( check ); + Assert.Equal ( "{0}\\{1}{2}".With ( b, c, a ), result ); + } + } + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/GetExtension.cs b/Managed.Adb.Tests/ForLinuxPath/GetExtension.cs new file mode 100644 index 0000000..4855fbc --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/GetExtension.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Camalot.Common.Extensions; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class GetExtension { + [Fact] + public void WhenPathIsNull_ShouldReturnNull () { + Assert.Null ( LinuxPath.GetExtension ( null ) ); + } + + [Fact] + public void WhenPathContainsInvalidCharacter_ShouldThrowArgumentException () { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { + try { + string result = LinuxPath.GetExtension ( "/some/path/{0}-{1}.ext".With ( LinuxPathConsts.InvalidPathChars[x], fixture.Create ( "file-" ) ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); + } + + [Fact] + public void WhenFilePathContainsExtension_ShouldReturnExtension () { + var fixture = new Fixture ( ); + string result = LinuxPath.GetExtension ( "/some/path/{0}.ext".With (fixture.Create ( "file-" ) ) ); + Assert.Equal ( ".ext", result ); + } + + [Fact] + public void WhenFilePathDoesNotContainsExtension_ShouldReturnEmpty ( ) { + var fixture = new Fixture ( ); + string result = LinuxPath.GetExtension ( "/some/path/{0}".With ( fixture.Create ( "file-" ) ) ); + Assert.Equal ( string.Empty, result ); + } + + [Fact] + public void WhenFilePathEndsWithDot_ShouldReturnEmpty ( ) { + var fixture = new Fixture ( ); + string result = LinuxPath.GetExtension ( "/some/path/{0}.".With ( fixture.Create ( "file-" ) ) ); + Assert.Equal ( string.Empty, result ); + } + + [Fact] + public void WhenPathDoesNotFile_ShouldReturnEmpty ( ) { + var fixture = new Fixture ( ); + string result = LinuxPath.GetExtension ( "/some/path/{0}/".With ( fixture.Create ( "path-" ) ) ); + Assert.Equal ( string.Empty, result ); + } + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/GetFileName.cs b/Managed.Adb.Tests/ForLinuxPath/GetFileName.cs index fff9037..41e7801 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetFileName.cs +++ b/Managed.Adb.Tests/ForLinuxPath/GetFileName.cs @@ -11,6 +11,21 @@ namespace Managed.Adb.Tests.ForLinuxPath { public class GetFileName { + [Fact] + public void WhenPathContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { + try { + string result = LinuxPath.GetFileName ( "/some/path/{0}-{1}.ext".With ( LinuxPathConsts.InvalidPathChars[x], fixture.Create ( "file-" ) ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); + } + [Fact] public void WhenPathIsNull_ShouldReturnNull ( ) { var fixture = new Fixture ( ); diff --git a/Managed.Adb.Tests/ForLinuxPath/GetFileNameWithoutExtension.cs b/Managed.Adb.Tests/ForLinuxPath/GetFileNameWithoutExtension.cs new file mode 100644 index 0000000..b3d330a --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/GetFileNameWithoutExtension.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Camalot.Common.Extensions; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class GetFileNameWithoutExtension { + [Fact] + public void WhenPathContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { + try { + string result = LinuxPath.GetFileNameWithoutExtension ( "/some/path/{0}-{1}.ext".With ( LinuxPathConsts.InvalidPathChars[x], fixture.Create ( "file-" ) ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); + } + + + + [Fact] + public void WhenPathIsNull_ShouldReturnNull ( ) { + var fixture = new Fixture ( ); + var result = LinuxPath.GetFileNameWithoutExtension ( null ); + Assert.Null ( result ); + } + + [Fact] + public void WhenPathIsDirectory_ShouldReturnEmpty ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1-" ); + var p2 = "{0}/".With ( fixture.Create ( "path2-" ) ); + var p = LinuxPath.Combine ( p1, p2 ); + var result = LinuxPath.GetFileNameWithoutExtension ( p ); + Assert.Equal ( string.Empty, result ); + } + + [Fact] + public void WhenPathHasFileWithExtension_ShouldReturnFileWithoutExtension ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1-" ); + var p2 = "{0}/".With ( fixture.Create ( "path2-" ) ); + var f = fixture.Create ( "file-" ); + var fext = "{0}{1}".With ( f, ".ext1" ); + var p = LinuxPath.Combine ( p1, p2, f ); + var result = LinuxPath.GetFileNameWithoutExtension ( p ); + Assert.Equal ( f, result ); + } + + [Fact] + public void WhenPathHasFileWithoutExtension_ShouldReturnFileWithoutExtension ( ) { + var fixture = new Fixture ( ); + var p1 = fixture.Create ( "/path1-" ); + var p2 = "{0}/".With ( fixture.Create ( "path2-" ) ); + var f = "{0}".With ( fixture.Create ( "file-" ) ); + var p = LinuxPath.Combine ( p1, p2, f ); + var result = LinuxPath.GetFileNameWithoutExtension ( p ); + Assert.Equal ( f, result ); + } + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs b/Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs index 3ba68a1..5d6595a 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs +++ b/Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs @@ -25,5 +25,21 @@ public void WhenPathContainsFile_ShouldReturnPath ( ) { var result = LinuxPath.GetPathWithoutFile ( p ); Assert.Equal ( "/{0}/{1}/".With ( p1, p2 ), result ); } + + [Fact] + public void WhenPathContainsInvalidCharacter_ShouldThrowArgumentException ( ) { + var fixture = new Fixture ( ); + int errorCount = 0; + for ( var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x ) { + try { + string result = LinuxPath.GetPathWithoutFile ( "/{0}-{1}/".With ( LinuxPathConsts.InvalidPathChars[x], fixture.Create ( "path1" ) ) ); + } catch ( ArgumentException ) { + errorCount++; + } + } + + Assert.Equal ( LinuxPathConsts.InvalidPathChars.Length, errorCount ); + + } } } diff --git a/Managed.Adb.Tests/ForLinuxPath/Quote.cs b/Managed.Adb.Tests/ForLinuxPath/Quote.cs new file mode 100644 index 0000000..3679ce1 --- /dev/null +++ b/Managed.Adb.Tests/ForLinuxPath/Quote.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Camalot.Common.Extensions; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForLinuxPath { + public class Quote { + [Fact] + public void WhenValueIsNull_ShouldReturnNull ( ) { + var result = LinuxPath.Quote ( null ); + Assert.Null ( result ); + } + + [Fact] + public void WhenValueIsEmpty_ShouldReturnEmpty () { + var result = LinuxPath.Quote ( string.Empty ); + Assert.Equal ( string.Empty, result ); + } + [Fact] + public void WhenValueHasSpace_ShouldReturnQuotedValue() { + var fixture = new Fixture ( ); + + var val = fixture.Create ( "value " ); + var result = LinuxPath.Quote ( val ); + Assert.Equal ( "\"{0}\"".With ( val ), result ); + } + + [Fact] + public void WhenValueDoesNotHaveSpace_ShouldReturnValue ( ) { + var fixture = new Fixture ( ); + + var val = fixture.Create ( "value-" ); + var result = LinuxPath.Quote ( val ); + Assert.Equal ( val , result ); + } + } +} diff --git a/Managed.Adb.Tests/Managed.Adb.Tests.csproj b/Managed.Adb.Tests/Managed.Adb.Tests.csproj index 3df252a..bb38129 100644 --- a/Managed.Adb.Tests/Managed.Adb.Tests.csproj +++ b/Managed.Adb.Tests/Managed.Adb.Tests.csproj @@ -104,14 +104,18 @@ + + + + diff --git a/Managed.AndroidDebugBridge/IO/LinuxPath.cs b/Managed.AndroidDebugBridge/IO/LinuxPath.cs index 2dd14ae..1b91299 100644 --- a/Managed.AndroidDebugBridge/IO/LinuxPath.cs +++ b/Managed.AndroidDebugBridge/IO/LinuxPath.cs @@ -15,7 +15,7 @@ public static class LinuxPath { /// /// Pattern to escape filenames for shell command consumption. /// - private const string ESCAPEPATTERN = "([\\\\()*+?\"'#/\\s])"; + private const string ESCAPEPATTERN = @"([\\\(\)*+?""'\#/])"; /// /// The directory separator character @@ -394,9 +394,10 @@ public static bool IsPathRooted ( string path ) { /// /// The path. /// + /// When path is null. public static string Escape ( string path ) { - return new Regex ( ESCAPEPATTERN ).Replace ( path, new MatchEvaluator ( delegate ( Match m ) { - return m.Result ( "\\\\$1" ); + return path.Require ( ).REReplace(ESCAPEPATTERN, new MatchEvaluator ( delegate ( Match m) { + return m.Result ( "\\$1" ); } ) ); } @@ -406,8 +407,12 @@ public static string Escape ( string path ) { /// The path. /// public static string Quote ( string path ) { - if ( path.Contains ( " " ) ) { - return string.Format ( "\"{0}\"", path ); + if ( string.IsNullOrEmpty(path) ) { + return path; + } + + if(path.IsMatch(@"\s")) { + return "\"{0}\"".With ( path ); } else { return path; } From a4950c279ba6eefc3f1f8500019789442578f12c Mon Sep 17 00:00:00 2001 From: camalot Date: Sun, 10 Apr 2016 22:07:26 -0500 Subject: [PATCH 24/24] added some tests. refactored the directory structor for tests a bit. Removed some unuses code. --- .../ForIO/ForByteOrder/ByteOrder.cs | 46 +++++++++++++++++++ .../ForLinuxPath/ChangeExtensionTests.cs | 2 +- .../{ => ForIO}/ForLinuxPath/CombineTests.cs | 2 +- .../{ => ForIO}/ForLinuxPath/Escape.cs | 2 +- .../ForLinuxPath/GetDirectoryNameTests.cs | 2 +- .../{ => ForIO}/ForLinuxPath/GetExtension.cs | 2 +- .../{ => ForIO}/ForLinuxPath/GetFileName.cs | 2 +- .../GetFileNameWithoutExtension.cs | 4 +- .../ForLinuxPath/GetInvalidFileNameChars.cs | 2 +- .../ForLinuxPath/GetInvalidPathChars.cs | 2 +- .../{ => ForIO}/ForLinuxPath/GetPathRoot.cs | 2 +- .../ForLinuxPath/GetPathWithoutFile.cs | 2 +- .../{ => ForIO}/ForLinuxPath/HasExtension.cs | 2 +- .../ForLinuxPath/LinuxPathConsts.cs | 2 +- .../{ => ForIO}/ForLinuxPath/Quote.cs | 2 +- .../Swap32bitFromArray.cs | 38 +++++++++++++++ .../Swap32bitsToArray.cs | 44 ++++++++++++++++++ .../SwapU16bitFromArray.cs | 38 +++++++++++++++ Managed.Adb.Tests/Managed.Adb.Tests.csproj | 35 ++++++++------ .../Extensions/PathHelper.cs | 28 ----------- .../Extensions/StringHelper.cs | 9 ---- Managed.AndroidDebugBridge/IO/ByteOrder.cs | 2 +- Managed.AndroidDebugBridge/IO/Rgb565.cs | 8 ++-- .../Logs/LogReceiver.cs | 8 ++-- Managed.AndroidDebugBridge/Managed.Adb.csproj | 1 - .../Receivers/BatteryReceiver.cs | 44 +++++++++--------- .../Receivers/CommandResultReceiver.cs | 6 +-- .../Receivers/ConsoleOutputReceiver.cs | 2 +- .../Receivers/EnvironmentVariablesReceiver.cs | 10 ++-- .../Receivers/GetPropReceiver.cs | 8 ++-- .../Receivers/InstallReceiver.cs | 10 ++-- 31 files changed, 251 insertions(+), 116 deletions(-) create mode 100644 Managed.Adb.Tests/ForIO/ForByteOrder/ByteOrder.cs rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/ChangeExtensionTests.cs (97%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/CombineTests.cs (99%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/Escape.cs (96%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/GetDirectoryNameTests.cs (98%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/GetExtension.cs (97%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/GetFileName.cs (97%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/GetFileNameWithoutExtension.cs (95%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/GetInvalidFileNameChars.cs (90%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/GetInvalidPathChars.cs (89%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/GetPathRoot.cs (95%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/GetPathWithoutFile.cs (96%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/HasExtension.cs (96%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/LinuxPathConsts.cs (95%) rename Managed.Adb.Tests/{ => ForIO}/ForLinuxPath/Quote.cs (95%) create mode 100644 Managed.Adb.Tests/ForManagedAdbExtenstions/Swap32bitFromArray.cs create mode 100644 Managed.Adb.Tests/ForManagedAdbExtenstions/Swap32bitsToArray.cs create mode 100644 Managed.Adb.Tests/ForManagedAdbExtenstions/SwapU16bitFromArray.cs delete mode 100644 Managed.AndroidDebugBridge/Extensions/PathHelper.cs diff --git a/Managed.Adb.Tests/ForIO/ForByteOrder/ByteOrder.cs b/Managed.Adb.Tests/ForIO/ForByteOrder/ByteOrder.cs new file mode 100644 index 0000000..ed700c7 --- /dev/null +++ b/Managed.Adb.Tests/ForIO/ForByteOrder/ByteOrder.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Managed.Adb.IO; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForIO.ForByteOrder { + public class ByteOrder { + [Fact] + public void WhenBigEdianName_ShouldReturnBigEdian ( ) { + var fixture = new Fixture ( ); + + var be = IO.ByteOrder.BIG_ENDIAN; + Assert.Equal ( be.Name, "BIG_ENDIAN" ); + } + + [Fact] + public void WhenBigEdianToString_ShouldReturnBigEdian ( ) { + var fixture = new Fixture ( ); + + var be = IO.ByteOrder.BIG_ENDIAN; + Assert.Equal ( be.ToString(), "BIG_ENDIAN" ); + } + + + [Fact] + public void WhenLittleEdianName_ShouldReturnBigEdian ( ) { + var fixture = new Fixture ( ); + + var be = IO.ByteOrder.LITTLE_ENDIAN; + Assert.Equal ( be.Name, "LITTLE_ENDIAN" ); + } + + [Fact] + public void WhenLittleEdianToString_ShouldReturnBigEdian ( ) { + var fixture = new Fixture ( ); + + var be = IO.ByteOrder.LITTLE_ENDIAN; + Assert.Equal ( be.ToString ( ), "LITTLE_ENDIAN" ); + } + + } +} diff --git a/Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/ChangeExtensionTests.cs similarity index 97% rename from Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/ChangeExtensionTests.cs index 8032f5a..b6b8d6f 100644 --- a/Managed.Adb.Tests/ForLinuxPath/ChangeExtensionTests.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/ChangeExtensionTests.cs @@ -7,7 +7,7 @@ using Managed.Adb.IO; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class ChangeExtensionTests { [Fact] diff --git a/Managed.Adb.Tests/ForLinuxPath/CombineTests.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/CombineTests.cs similarity index 99% rename from Managed.Adb.Tests/ForLinuxPath/CombineTests.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/CombineTests.cs index 3f32ae5..1bb0cb1 100644 --- a/Managed.Adb.Tests/ForLinuxPath/CombineTests.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/CombineTests.cs @@ -8,7 +8,7 @@ using Ploeh.AutoFixture; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class CombineTests { [Fact] public void When2ArgsAndPath1IsNull_ShouldThrowArgumentNullException ( ) { diff --git a/Managed.Adb.Tests/ForLinuxPath/Escape.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/Escape.cs similarity index 96% rename from Managed.Adb.Tests/ForLinuxPath/Escape.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/Escape.cs index fc71459..6865a0c 100644 --- a/Managed.Adb.Tests/ForLinuxPath/Escape.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/Escape.cs @@ -8,7 +8,7 @@ using Ploeh.AutoFixture; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class Escape { [Fact] public void WhenPathIsNull_ShouldReturnThrowArgumentNullException () { diff --git a/Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetDirectoryNameTests.cs similarity index 98% rename from Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/GetDirectoryNameTests.cs index 00060f7..deba284 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetDirectoryNameTests.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetDirectoryNameTests.cs @@ -8,7 +8,7 @@ using Ploeh.AutoFixture; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class GetDirectoryNameTests { [Fact] public void WhenPathIsNull_ShouldReturnNull ( ) { diff --git a/Managed.Adb.Tests/ForLinuxPath/GetExtension.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetExtension.cs similarity index 97% rename from Managed.Adb.Tests/ForLinuxPath/GetExtension.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/GetExtension.cs index 4855fbc..6326437 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetExtension.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetExtension.cs @@ -8,7 +8,7 @@ using Ploeh.AutoFixture; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class GetExtension { [Fact] public void WhenPathIsNull_ShouldReturnNull () { diff --git a/Managed.Adb.Tests/ForLinuxPath/GetFileName.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetFileName.cs similarity index 97% rename from Managed.Adb.Tests/ForLinuxPath/GetFileName.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/GetFileName.cs index 41e7801..f2824d1 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetFileName.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetFileName.cs @@ -8,7 +8,7 @@ using Ploeh.AutoFixture; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class GetFileName { [Fact] diff --git a/Managed.Adb.Tests/ForLinuxPath/GetFileNameWithoutExtension.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetFileNameWithoutExtension.cs similarity index 95% rename from Managed.Adb.Tests/ForLinuxPath/GetFileNameWithoutExtension.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/GetFileNameWithoutExtension.cs index b3d330a..285796b 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetFileNameWithoutExtension.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetFileNameWithoutExtension.cs @@ -8,7 +8,7 @@ using Ploeh.AutoFixture; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class GetFileNameWithoutExtension { [Fact] public void WhenPathContainsInvalidCharacter_ShouldThrowArgumentException ( ) { @@ -51,7 +51,7 @@ public void WhenPathHasFileWithExtension_ShouldReturnFileWithoutExtension ( ) { var p2 = "{0}/".With ( fixture.Create ( "path2-" ) ); var f = fixture.Create ( "file-" ); var fext = "{0}{1}".With ( f, ".ext1" ); - var p = LinuxPath.Combine ( p1, p2, f ); + var p = LinuxPath.Combine ( p1, p2, fext ); var result = LinuxPath.GetFileNameWithoutExtension ( p ); Assert.Equal ( f, result ); } diff --git a/Managed.Adb.Tests/ForLinuxPath/GetInvalidFileNameChars.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetInvalidFileNameChars.cs similarity index 90% rename from Managed.Adb.Tests/ForLinuxPath/GetInvalidFileNameChars.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/GetInvalidFileNameChars.cs index a2b924b..34b0d6e 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetInvalidFileNameChars.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetInvalidFileNameChars.cs @@ -6,7 +6,7 @@ using Managed.Adb.IO; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class GetInvalidFileNameChars { [Fact] public void WhenGetttingInvalidFileNameChars_ShouldEqualExpected () { diff --git a/Managed.Adb.Tests/ForLinuxPath/GetInvalidPathChars.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetInvalidPathChars.cs similarity index 89% rename from Managed.Adb.Tests/ForLinuxPath/GetInvalidPathChars.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/GetInvalidPathChars.cs index b96e3e2..3c16a24 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetInvalidPathChars.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetInvalidPathChars.cs @@ -6,7 +6,7 @@ using Managed.Adb.IO; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class GetInvalidPathChars { [Fact] public void WhenGetttingInvalidPathChars_ShouldEqualExpected ( ) { diff --git a/Managed.Adb.Tests/ForLinuxPath/GetPathRoot.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetPathRoot.cs similarity index 95% rename from Managed.Adb.Tests/ForLinuxPath/GetPathRoot.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/GetPathRoot.cs index b01d2b5..f342b6a 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetPathRoot.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetPathRoot.cs @@ -7,7 +7,7 @@ using Ploeh.AutoFixture; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class GetPathRoot { [Fact] public void WhenPathIsNull_ShouldReturnNull () { diff --git a/Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetPathWithoutFile.cs similarity index 96% rename from Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/GetPathWithoutFile.cs index 5d6595a..51aa265 100644 --- a/Managed.Adb.Tests/ForLinuxPath/GetPathWithoutFile.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/GetPathWithoutFile.cs @@ -8,7 +8,7 @@ using Ploeh.AutoFixture; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class GetPathWithoutFile { [Fact] public void WhenPathIsNull_ShouldReturnNull() { diff --git a/Managed.Adb.Tests/ForLinuxPath/HasExtension.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/HasExtension.cs similarity index 96% rename from Managed.Adb.Tests/ForLinuxPath/HasExtension.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/HasExtension.cs index c60f6c5..8bfd9c8 100644 --- a/Managed.Adb.Tests/ForLinuxPath/HasExtension.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/HasExtension.cs @@ -8,7 +8,7 @@ using Ploeh.AutoFixture; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class HasExtension { [Fact] public void WhenPathIsNull_ShouldReturnFalse () { diff --git a/Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/LinuxPathConsts.cs similarity index 95% rename from Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/LinuxPathConsts.cs index 81b5ca1..55a074d 100644 --- a/Managed.Adb.Tests/ForLinuxPath/LinuxPathConsts.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/LinuxPathConsts.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { internal class LinuxPathConsts { internal static readonly char[] InvalidPathChars = new char[] { '"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v', diff --git a/Managed.Adb.Tests/ForLinuxPath/Quote.cs b/Managed.Adb.Tests/ForIO/ForLinuxPath/Quote.cs similarity index 95% rename from Managed.Adb.Tests/ForLinuxPath/Quote.cs rename to Managed.Adb.Tests/ForIO/ForLinuxPath/Quote.cs index 3679ce1..f6263dd 100644 --- a/Managed.Adb.Tests/ForLinuxPath/Quote.cs +++ b/Managed.Adb.Tests/ForIO/ForLinuxPath/Quote.cs @@ -8,7 +8,7 @@ using Ploeh.AutoFixture; using Xunit; -namespace Managed.Adb.Tests.ForLinuxPath { +namespace Managed.Adb.Tests.ForIOLinuxPath { public class Quote { [Fact] public void WhenValueIsNull_ShouldReturnNull ( ) { diff --git a/Managed.Adb.Tests/ForManagedAdbExtenstions/Swap32bitFromArray.cs b/Managed.Adb.Tests/ForManagedAdbExtenstions/Swap32bitFromArray.cs new file mode 100644 index 0000000..e4f545a --- /dev/null +++ b/Managed.Adb.Tests/ForManagedAdbExtenstions/Swap32bitFromArray.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForManagedAdbExtenstions { + public class Swap32bitFromArray { + [Fact] + public void WhenValueIsPositive_ShouldReturnInteger ( ) { + var fixture = new Fixture ( ); + var value = fixture.Create ( ); + var offset = fixture.Create ( ); + var dest = new byte[offset + 4]; + Assert.True ( offset >= 0 ); + ManagedAdbExtenstions.Swap32bitsToArray ( value, dest, offset ); + + var result = ManagedAdbExtenstions.Swap32bitFromArray ( dest, offset ); + Assert.Equal ( value, result ); + } + + + [Fact] + public void WhenValueIsZero_ShouldReturnInteger ( ) { + var fixture = new Fixture ( ); + var value = 0; + var offset = fixture.Create ( ); + var dest = new byte[offset + 4]; + Assert.True ( offset >= 0 ); + ManagedAdbExtenstions.Swap32bitsToArray ( value, dest, offset ); + + var result = ManagedAdbExtenstions.Swap32bitFromArray ( dest, offset ); + Assert.Equal ( value, result ); + } + } +} diff --git a/Managed.Adb.Tests/ForManagedAdbExtenstions/Swap32bitsToArray.cs b/Managed.Adb.Tests/ForManagedAdbExtenstions/Swap32bitsToArray.cs new file mode 100644 index 0000000..daa0745 --- /dev/null +++ b/Managed.Adb.Tests/ForManagedAdbExtenstions/Swap32bitsToArray.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForManagedAdbExtenstions { + public class Swap32bitsToArray { + [Fact] + public void WhenValueIsPositive_ShouldReturnSwapped() { + var fixture = new Fixture ( ); + var value = fixture.Create ( ); + var offset = fixture.Create ( ); + var dest = new byte[offset + 4]; + Assert.True ( offset >= 0 ); + + ManagedAdbExtenstions.Swap32bitsToArray ( value, dest, offset ); + Assert.True ( dest.Length == offset + 4 ); + Assert.True ( dest[offset] == (byte)( value & 0x000000FF ) ); + Assert.True ( dest[offset + 1] == (byte)( value & 0x0000FF00 ) >> 8 ); + Assert.True ( dest[offset + 2] == (byte)( value & 0x00FF0000 ) >> 16 ); + Assert.True ( dest[offset + 3] == (byte)( value & 0xFF000000 ) >> 24 ); + } + + [Fact] + public void WhenValueIsZero_ShouldReturnSwapped ( ) { + var fixture = new Fixture ( ); + var value = 0; + var offset = fixture.Create ( ); + var dest = new byte[offset + 4]; + Assert.True ( offset >= 0 ); + + ManagedAdbExtenstions.Swap32bitsToArray ( value, dest, offset ); + Assert.True ( dest.Length == offset + 4 ); + Assert.True ( dest[offset] == (byte)( value & 0x000000FF ) ); + Assert.True ( dest[offset + 1] == (byte)( value & 0x0000FF00 ) >> 8 ); + Assert.True ( dest[offset + 2] == (byte)( value & 0x00FF0000 ) >> 16 ); + Assert.True ( dest[offset + 3] == (byte)( value & 0xFF000000 ) >> 24 ); + } + + } +} diff --git a/Managed.Adb.Tests/ForManagedAdbExtenstions/SwapU16bitFromArray.cs b/Managed.Adb.Tests/ForManagedAdbExtenstions/SwapU16bitFromArray.cs new file mode 100644 index 0000000..71e1c84 --- /dev/null +++ b/Managed.Adb.Tests/ForManagedAdbExtenstions/SwapU16bitFromArray.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Ploeh.AutoFixture; +using Xunit; + +namespace Managed.Adb.Tests.ForManagedAdbExtenstions { + public class SwapU16bitFromArray { + [Fact] + public void WhenValueIsPositive_ShouldReturnInteger ( ) { + var fixture = new Fixture ( ); + var value = fixture.Create ( ); + var offset = fixture.Create ( ); + var dest = new byte[offset + 4]; + Assert.True ( offset >= 0 ); + ManagedAdbExtenstions.Swap32bitsToArray ( value, dest, offset ); + + var result = ManagedAdbExtenstions.SwapU16bitFromArray ( dest, offset ); + Assert.Equal ( value, result ); + } + + + [Fact] + public void WhenValueIsZero_ShouldReturnInteger ( ) { + var fixture = new Fixture ( ); + var value = 0; + var offset = fixture.Create ( ); + var dest = new byte[offset + 4]; + Assert.True ( offset >= 0 ); + ManagedAdbExtenstions.Swap32bitsToArray ( value, dest, offset ); + + var result = ManagedAdbExtenstions.SwapU16bitFromArray ( dest, offset ); + Assert.Equal ( value, result ); + } + } +} diff --git a/Managed.Adb.Tests/Managed.Adb.Tests.csproj b/Managed.Adb.Tests/Managed.Adb.Tests.csproj index bb38129..7cbb2be 100644 --- a/Managed.Adb.Tests/Managed.Adb.Tests.csproj +++ b/Managed.Adb.Tests/Managed.Adb.Tests.csproj @@ -102,20 +102,24 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -129,6 +133,9 @@ Managed.Adb + + + diff --git a/Managed.AndroidDebugBridge/Extensions/PathHelper.cs b/Managed.AndroidDebugBridge/Extensions/PathHelper.cs deleted file mode 100644 index 04d1bad..0000000 --- a/Managed.AndroidDebugBridge/Extensions/PathHelper.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace Managed.Adb { - /// true - public static partial class ManagedAdbExtenstions { - - /// - /// Combines the specified paths. - /// - /// This wraps the normal System.IO.Path.Combine to allow for an unlimited list of paths to combine - /// The paths. - /// - public static String Combine ( params String[] paths ) { - String lastPath = String.Empty; - - foreach ( var item in paths ) { - lastPath = Path.Combine ( lastPath, item ); - } - - return lastPath; - } - - } -} diff --git a/Managed.AndroidDebugBridge/Extensions/StringHelper.cs b/Managed.AndroidDebugBridge/Extensions/StringHelper.cs index ad93dd8..770a000 100644 --- a/Managed.AndroidDebugBridge/Extensions/StringHelper.cs +++ b/Managed.AndroidDebugBridge/Extensions/StringHelper.cs @@ -8,15 +8,6 @@ namespace Managed.Adb { /// true public static partial class ManagedAdbExtenstions { - /// - /// To the argument safe quoted string. - /// - /// The s. - /// - public static string ToArgumentSafe ( this string s ) { - return "{0}{1}{0}".With ( s.Contains ( " " ) ? "\"" : string.Empty, s ); - } - /// /// Gets the bytes from a string. /// diff --git a/Managed.AndroidDebugBridge/IO/ByteOrder.cs b/Managed.AndroidDebugBridge/IO/ByteOrder.cs index 347049f..5623f1d 100644 --- a/Managed.AndroidDebugBridge/IO/ByteOrder.cs +++ b/Managed.AndroidDebugBridge/IO/ByteOrder.cs @@ -14,7 +14,7 @@ public class ByteOrder { /// Initializes a new instance of the class. /// /// The name. - private ByteOrder ( String name ) { + private ByteOrder ( string name ) { this.Name = name; } diff --git a/Managed.AndroidDebugBridge/IO/Rgb565.cs b/Managed.AndroidDebugBridge/IO/Rgb565.cs index 8c23447..692014f 100644 --- a/Managed.AndroidDebugBridge/IO/Rgb565.cs +++ b/Managed.AndroidDebugBridge/IO/Rgb565.cs @@ -14,7 +14,7 @@ namespace Managed.Adb.IO { public static class Rgb565 { /// - /// To the image. + /// Reads the file and returns the RGB565 Image /// /// The file. /// @@ -25,7 +25,7 @@ public static Image ToImage ( string file ) { } /// - /// To the image. + /// Reads the file and returns the RGB565 Image /// /// The stream. /// @@ -44,7 +44,7 @@ public static Image ToImage ( Stream stream ) { } /// - /// To the image. + /// Reads the file and returns the RGB565 Image /// /// The buffer. /// @@ -53,7 +53,7 @@ public static Image ToImage ( byte[] buffer ) { } /// - /// To the image. + /// Reads the file and returns the RGB565 Image /// /// The format. /// The buffer. diff --git a/Managed.AndroidDebugBridge/Logs/LogReceiver.cs b/Managed.AndroidDebugBridge/Logs/LogReceiver.cs index 5351a98..091185b 100644 --- a/Managed.AndroidDebugBridge/Logs/LogReceiver.cs +++ b/Managed.AndroidDebugBridge/Logs/LogReceiver.cs @@ -12,10 +12,10 @@ public class LogReceiver { /// The entr y_ heade r_ size /// private const int ENTRY_HEADER_SIZE = 20; // 2*2 + 4*4; see LogEntry. - /// - /// Initializes a new instance of the class. - /// - /// The listener. + /// + /// Initializes a new instance of the class. + /// + /// The listener. public LogReceiver ( ILogListener listener ) { EntryDataOffset = 0; EntryHeaderBuffer = new byte[ENTRY_HEADER_SIZE]; diff --git a/Managed.AndroidDebugBridge/Managed.Adb.csproj b/Managed.AndroidDebugBridge/Managed.Adb.csproj index 2b438e8..1b60198 100644 --- a/Managed.AndroidDebugBridge/Managed.Adb.csproj +++ b/Managed.AndroidDebugBridge/Managed.Adb.csproj @@ -205,7 +205,6 @@ - diff --git a/Managed.AndroidDebugBridge/Receivers/BatteryReceiver.cs b/Managed.AndroidDebugBridge/Receivers/BatteryReceiver.cs index 52ed48e..47c7372 100644 --- a/Managed.AndroidDebugBridge/Receivers/BatteryReceiver.cs +++ b/Managed.AndroidDebugBridge/Receivers/BatteryReceiver.cs @@ -11,17 +11,17 @@ namespace Managed.Adb { /// /// public class BatteryReceiver : MultiLineReceiver { - private const String TAG = "BatteryReceiver"; - private const String BATTERY_LEVEL = @"\s*level:\s?(\d+)"; - private const String AC_POWER = @"\s*AC\spowered:\s?(true|false)"; - private const String USB_POWER = @"\s*USB\spowered:\s?(true|false)"; - private const String PRESENT = @"\s*present:\s?(true|false)"; - private const String STATUS = @"\s*status:\s(\d+)"; - private const String HEALTH = @"\s*health:\s(\d+)"; - private const String SCALE = @"\s*scale:\s(\d+)"; - private const String VOLTAGE = @"\s*voltage:\s(\d+)"; - private const String TYPE = @"\s*technology:\s(.*?)$"; - private const String TEMP = @"\s*temperature:\s(\d+)"; + private const string TAG = nameof ( BatteryReceiver ); + private const string BATTERY_LEVEL = @"\s*level:\s?(\d+)"; + private const string AC_POWER = @"\s*AC\spowered:\s?(true|false)"; + private const string USB_POWER = @"\s*USB\spowered:\s?(true|false)"; + private const string PRESENT = @"\s*present:\s?(true|false)"; + private const string STATUS = @"\s*status:\s(\d+)"; + private const string HEALTH = @"\s*health:\s(\d+)"; + private const string SCALE = @"\s*scale:\s(\d+)"; + private const string VOLTAGE = @"\s*voltage:\s(\d+)"; + private const string TYPE = @"\s*technology:\s(.*?)$"; + private const string TEMP = @"\s*temperature:\s(\d+)"; private const RegexOptions REOPTIONS = RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace; @@ -33,7 +33,7 @@ public class BatteryReceiver : MultiLineReceiver { /// The battery info. /// public BatteryInfo BatteryInfo { get; private set; } - + /// /// Processes the new lines. /// @@ -41,12 +41,12 @@ public class BatteryReceiver : MultiLineReceiver { protected override void ProcessNewLines ( string[] lines ) { BatteryInfo = new BatteryInfo ( ); foreach ( var line in lines ) { - var match = line.Match( BATTERY_LEVEL, REOPTIONS ); + var match = line.Match ( BATTERY_LEVEL, REOPTIONS ); if ( match.Success ) { try { BatteryInfo.Level = Int32.Parse ( match.Groups[1].Value ); } catch ( FormatException ) { - Log.w ( TAG, String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); + Log.w ( TAG, string.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } @@ -55,23 +55,23 @@ protected override void ProcessNewLines ( string[] lines ) { try { BatteryInfo.Scale = Int32.Parse ( match.Groups[1].Value ); } catch ( FormatException ) { - Log.w ( TAG, String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); + Log.w ( TAG, string.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } match = line.Match ( AC_POWER, REOPTIONS ); if ( match.Success ) { - BatteryInfo.ACPowered = String.Compare ( match.Groups[1].Value, bool.TrueString, true ) == 0; + BatteryInfo.ACPowered = string.Compare ( match.Groups[1].Value, bool.TrueString, true ) == 0; } match = line.Match ( USB_POWER, REOPTIONS ); if ( match.Success ) { - BatteryInfo.UsbPowered = String.Compare ( match.Groups[1].Value, bool.TrueString, true ) == 0; + BatteryInfo.UsbPowered = string.Compare ( match.Groups[1].Value, bool.TrueString, true ) == 0; } match = line.Match ( PRESENT, REOPTIONS ); if ( match.Success ) { - BatteryInfo.Present = String.Compare ( match.Groups[1].Value, bool.TrueString, true ) == 0; + BatteryInfo.Present = string.Compare ( match.Groups[1].Value, bool.TrueString, true ) == 0; } match = line.Match ( STATUS, REOPTIONS ); @@ -80,7 +80,7 @@ protected override void ProcessNewLines ( string[] lines ) { var i = Int32.Parse ( match.Groups[1].Value ); BatteryInfo.Status = i.ToEnum ( ); } catch ( FormatException ) { - Log.w ( TAG, String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); + Log.w ( TAG, string.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } @@ -90,7 +90,7 @@ protected override void ProcessNewLines ( string[] lines ) { var i = Int32.Parse ( match.Groups[1].Value ); BatteryInfo.Health = i.ToEnum ( ); } catch ( FormatException ) { - Log.w ( TAG, String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); + Log.w ( TAG, string.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } @@ -99,7 +99,7 @@ protected override void ProcessNewLines ( string[] lines ) { try { BatteryInfo.Voltage = Int32.Parse ( match.Groups[1].Value ); } catch ( FormatException ) { - Log.w ( TAG, String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); + Log.w ( TAG, string.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } @@ -113,7 +113,7 @@ protected override void ProcessNewLines ( string[] lines ) { try { BatteryInfo.Temperature = Int32.Parse ( match.Groups[1].Value ); } catch ( FormatException ) { - Log.w ( TAG, String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); + Log.w ( TAG, string.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } } diff --git a/Managed.AndroidDebugBridge/Receivers/CommandResultReceiver.cs b/Managed.AndroidDebugBridge/Receivers/CommandResultReceiver.cs index ee3de35..12eb2e6 100644 --- a/Managed.AndroidDebugBridge/Receivers/CommandResultReceiver.cs +++ b/Managed.AndroidDebugBridge/Receivers/CommandResultReceiver.cs @@ -14,8 +14,8 @@ public class CommandResultReceiver : MultiLineReceiver{ /// The lines. protected override void ProcessNewLines ( string[] lines ) { var result = new StringBuilder ( ); - foreach ( String line in lines ) { - if ( String.IsNullOrEmpty ( line ) || line.StartsWith ( "#" ) || line.StartsWith ( "$" ) ) { + foreach ( string line in lines ) { + if ( string.IsNullOrWhiteSpace ( line ) || line.StartsWith ( "#" ) || line.StartsWith ( "$" ) ) { continue; } @@ -31,6 +31,6 @@ protected override void ProcessNewLines ( string[] lines ) { /// /// The result. /// - public String Result { get; private set; } + public string Result { get; private set; } } } diff --git a/Managed.AndroidDebugBridge/Receivers/ConsoleOutputReceiver.cs b/Managed.AndroidDebugBridge/Receivers/ConsoleOutputReceiver.cs index ac9ef9f..5828a3a 100644 --- a/Managed.AndroidDebugBridge/Receivers/ConsoleOutputReceiver.cs +++ b/Managed.AndroidDebugBridge/Receivers/ConsoleOutputReceiver.cs @@ -29,7 +29,7 @@ public static ConsoleOutputReceiver Instance { /// The lines. protected override void ProcessNewLines ( string[] lines ) { foreach ( var line in lines ) { - if (string.IsNullOrEmpty ( line ) || line.StartsWith ( "#" ) || line.StartsWith("$") ) { + if (string.IsNullOrWhiteSpace ( line ) || line.StartsWith ( "#" ) || line.StartsWith("$") ) { continue; } Console.WriteLine ( line ); diff --git a/Managed.AndroidDebugBridge/Receivers/EnvironmentVariablesReceiver.cs b/Managed.AndroidDebugBridge/Receivers/EnvironmentVariablesReceiver.cs index 02739a1..b9cd6fa 100644 --- a/Managed.AndroidDebugBridge/Receivers/EnvironmentVariablesReceiver.cs +++ b/Managed.AndroidDebugBridge/Receivers/EnvironmentVariablesReceiver.cs @@ -36,15 +36,15 @@ public EnvironmentVariablesReceiver ( Device device ) { /// /// The lines. protected override void ProcessNewLines ( string[] lines ) { - foreach ( String line in lines ) { - if ( String.IsNullOrEmpty ( line ) || line.StartsWith ( "#" ) ) { + foreach ( string line in lines ) { + if ( string.IsNullOrWhiteSpace ( line ) || line.StartsWith ( "#" ) || line.StartsWith ( "$" ) ) { continue; } - Match m = Regex.Match ( line, ENV_PATTERN ); + var m = Regex.Match ( line, ENV_PATTERN ); if ( m.Success ) { - String label = m.Groups[1].Value.Trim ( ); - String value = m.Groups[2].Value.Trim ( ); + var label = m.Groups[1].Value.Trim ( ); + var value = m.Groups[2].Value.Trim ( ); if ( label.Length > 0 ) { if ( Device.EnvironmentVariables.ContainsKey ( label ) ) { diff --git a/Managed.AndroidDebugBridge/Receivers/GetPropReceiver.cs b/Managed.AndroidDebugBridge/Receivers/GetPropReceiver.cs index b8be196..24ce720 100644 --- a/Managed.AndroidDebugBridge/Receivers/GetPropReceiver.cs +++ b/Managed.AndroidDebugBridge/Receivers/GetPropReceiver.cs @@ -41,14 +41,14 @@ protected override void ProcessNewLines ( string[] lines ) { // date in the 2nd line. There seems to be an empty line // after all that. - foreach ( String line in lines ) { - if ( String.IsNullOrEmpty ( line ) || line.StartsWith ( "#" ) || line.StartsWith("$") ) { + foreach ( string line in lines ) { + if ( string.IsNullOrEmpty ( line ) || line.StartsWith ( "#" ) || line.StartsWith("$") ) { continue; } var m = line.Match ( GETPROP_PATTERN, RegexOptions.Compiled ); if ( m.Success ) { - String label = m.Groups[1].Value.Trim ( ); - String value = m.Groups[2].Value.Trim ( ); + var label = m.Groups[1].Value.Trim ( ); + var value = m.Groups[2].Value.Trim ( ); if ( label.Length > 0 ) { Device.Properties.Add ( label, value ); diff --git a/Managed.AndroidDebugBridge/Receivers/InstallReceiver.cs b/Managed.AndroidDebugBridge/Receivers/InstallReceiver.cs index 2693685..a082919 100644 --- a/Managed.AndroidDebugBridge/Receivers/InstallReceiver.cs +++ b/Managed.AndroidDebugBridge/Receivers/InstallReceiver.cs @@ -13,20 +13,20 @@ public class InstallReceiver : MultiLineReceiver { /// /// /// - private const String SUCCESS_OUTPUT = "Success"; + private const string SUCCESS_OUTPUT = "Success"; /// /// /// - private const String FAILURE_PATTERN = @"Failure(?:\s+\[(.*)\])?"; + private const string FAILURE_PATTERN = @"Failure(?:\s+\[(.*)\])?"; - private const String UNKNOWN_ERROR = "An unknown error occurred."; + private const string UNKNOWN_ERROR = "An unknown error occurred."; /// /// Processes the new lines. /// /// The lines. protected override void ProcessNewLines ( string[] lines ) { - foreach ( String line in lines ) { + foreach ( string line in lines ) { if ( line.Length > 0 ) { if ( line.StartsWith ( SUCCESS_OUTPUT ) ) { ErrorMessage = null; @@ -48,7 +48,7 @@ protected override void ProcessNewLines ( string[] lines ) { /// Gets the error message if the install was unsuccessful. /// /// The error message. - public String ErrorMessage { get; private set; } + public string ErrorMessage { get; private set; } /// /// Gets a value indicating whether the install was a success.