From f7b24f7cc39cff6b1086049b3aade1a73a87a0b5 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 20 Feb 2018 16:25:23 +0000 Subject: [PATCH] [Xamarin.Android.Build.Tests] Add tests for (#1321) This commit adds a basic unit test for the `` task. --- .../ResolveSdksTaskTests.cs | 80 +++++++++++++++++++ .../Utilities/BaseTest.cs | 1 + .../Xamarin.Android.Build.Tests.csproj | 1 + 3 files changed, 82 insertions(+) create mode 100644 src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ResolveSdksTaskTests.cs diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ResolveSdksTaskTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ResolveSdksTaskTests.cs new file mode 100644 index 00000000000..e642d56ec4e --- /dev/null +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ResolveSdksTaskTests.cs @@ -0,0 +1,80 @@ +using System; +using NUnit.Framework; +using Xamarin.ProjectTools; +using System.IO; +using System.Linq; +using Microsoft.Build.Framework; +using System.Text; +using Xamarin.Android.Tasks; +using Microsoft.Build.Utilities; + +namespace Xamarin.Android.Build.Tests { + + [TestFixture] + [Parallelizable (ParallelScope.Children)] + public class ResolveSdksTaskTests : BaseTest { + [Test] + public void ResolveSdkTiming () + { + var path = Path.Combine ("temp", TestName); + var androidSdkPath = CreateFauxAndroidSdkDirectory (Path.Combine (path, "android-sdk"), "26.0.3"); + string javaExe = string.Empty; + var javaPath = CreateFauxJavaSdkDirectory (Path.Combine (path, "jdk"), "1.8.0", out javaExe); + var referencePath = CreateFauxReferencesDirectory (Path.Combine (path, "references"), new ApiInfo [] { + new ApiInfo () { Id = 26, Level = 26, Name = "Oreo", FrameworkVersion = "v8.0", Stable = true }, + new ApiInfo () { Id = 27, Level = 27, Name = "Oreo", FrameworkVersion = "v8.1", Stable = true }, + }); + IBuildEngine engine = new MockBuildEngine (TestContext.Out); + var task = new ResolveSdks { + BuildEngine = engine + }; + task.AndroidSdkPath = androidSdkPath; + task.AndroidNdkPath = androidSdkPath; + task.JavaSdkPath = javaPath; + task.TargetFrameworkVersion = "v8.0"; + task.AndroidSdkBuildToolsVersion = "26.0.3"; + task.BuildingInsideVisualStudio = "true"; + task.UseLatestAndroidPlatformSdk = false; + task.AotAssemblies = false; + task.LatestSupportedJavaVersion = "1.8.0"; + task.MinimumSupportedJavaVersion = "1.7.0"; + task.ReferenceAssemblyPaths = new string [] { + Path.Combine (referencePath, "MonoAndroid"), + }; + task.CacheFile = Path.Combine (Root, path, "sdk.xml"); + task.SequencePointsMode = "None"; + task.JavaToolExe = javaExe; + var start = DateTime.UtcNow; + Assert.IsTrue (task.Execute ()); + var executionTime = DateTime.UtcNow - start; + Assert.LessOrEqual (executionTime, TimeSpan.FromSeconds(1), "Task should not take more than 1 second to run."); + Assert.AreEqual (task.AndroidApiLevel, "26", "AndroidApiLevel should be 26"); + Assert.AreEqual (task.TargetFrameworkVersion, "v8.0", "TargetFrameworkVersion should be v8.0"); + Assert.AreEqual (task.AndroidApiLevelName, "26", "AndroidApiLevelName should be 26"); + Assert.AreEqual (task.SupportedApiLevel, "26", "SupportedApiLevel should be 26"); + Assert.NotNull (task.ReferenceAssemblyPaths, "ReferenceAssemblyPaths should not be null."); + Assert.AreEqual (task.ReferenceAssemblyPaths.Length, 1, "ReferenceAssemblyPaths should have 1 entry."); + Assert.AreEqual (task.ReferenceAssemblyPaths[0], Path.Combine (referencePath, "MonoAndroid"), $"ReferenceAssemblyPaths should be {Path.Combine (referencePath, "MonoAndroid")}."); + var expected = Path.Combine (Root); + Assert.AreEqual (task.MonoAndroidToolsPath, expected, $"MonoAndroidToolsPath should be {expected}"); + expected = Path.Combine (Root, "Darwin" + Path.DirectorySeparatorChar); + Assert.AreEqual (task.MonoAndroidBinPath, expected, $"MonoAndroidBinPath should be {expected}"); + Assert.AreEqual (task.MonoAndroidIncludePath, null, "MonoAndroidIncludePath should be null"); + //Assert.AreEqual (task.AndroidNdkPath, "26", "AndroidNdkPath should be 26"); + Assert.AreEqual (task.AndroidSdkPath, androidSdkPath, $"AndroidSdkPath should be {androidSdkPath}"); + Assert.AreEqual (task.JavaSdkPath, javaPath, $"JavaSdkPath should be {javaPath}"); + expected = Path.Combine (androidSdkPath, "build-tools", "26.0.3"); + Assert.AreEqual (task.AndroidSdkBuildToolsPath, expected, $"AndroidSdkBuildToolsPath should be {expected}"); + Assert.AreEqual (task.AndroidSdkBuildToolsBinPath, expected, "AndroidSdkBuildToolsBinPath should be {expected}"); + Assert.AreEqual (task.ZipAlignPath, expected, "ZipAlignPath should be {expected}"); + Assert.AreEqual (task.AndroidSequencePointsMode, "None", "AndroidSequencePointsMode should be None"); + expected = Path.Combine (androidSdkPath, "tools"); + Assert.AreEqual (task.LintToolPath, expected, $"LintToolPath should be {expected}"); + expected = Path.Combine (androidSdkPath, "build-tools", "26.0.3", "lib", "apksigner.jar"); + Assert.AreEqual (task.ApkSignerJar, expected, $"ApkSignerJar should be {expected}"); + Assert.AreEqual (task.AndroidUseApkSigner, false, "AndroidUseApkSigner should be false"); + Assert.AreEqual (task.JdkVersion, "1.8.0", "JdkVersion should be 1.8.0"); + Assert.AreEqual (task.MinimumRequiredJdkVersion, "1.8", "MinimumRequiredJdkVersion should be 1.8"); + } + } +} diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs index b951d241601..41858b33412 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs @@ -122,6 +122,7 @@ protected string CreateFauxAndroidSdkDirectory (string path, string buildToolsVe File.WriteAllText (Path.Combine (androidSdkPlatformToolsPath, IsWindows ? "adb.exe" : "adb"), ""); File.WriteAllText (Path.Combine (androidSdkBuildToolsPath, IsWindows ? "zipalign.exe" : "zipalign"), ""); File.WriteAllText (Path.Combine (androidSdkBuildToolsPath, IsWindows ? "aapt.exe" : "aapt"), ""); + File.WriteAllText (Path.Combine (androidSdkToolsPath, IsWindows ? "lint.exe" : "lint"), ""); for (int i=minApiLevel; i < maxApiLevel; i++) { var dir = Path.Combine (androidSdkPlatformsPath, $"android-{i}"); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj index 45222dd1511..c46e853f7be 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj @@ -73,5 +73,6 @@ +