Skip to content

Commit f7b24f7

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tests] Add tests for <ResolveSdks/> (#1321)
This commit adds a basic unit test for the `<ResolveSdks/>` task.
1 parent d207275 commit f7b24f7

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using NUnit.Framework;
3+
using Xamarin.ProjectTools;
4+
using System.IO;
5+
using System.Linq;
6+
using Microsoft.Build.Framework;
7+
using System.Text;
8+
using Xamarin.Android.Tasks;
9+
using Microsoft.Build.Utilities;
10+
11+
namespace Xamarin.Android.Build.Tests {
12+
13+
[TestFixture]
14+
[Parallelizable (ParallelScope.Children)]
15+
public class ResolveSdksTaskTests : BaseTest {
16+
[Test]
17+
public void ResolveSdkTiming ()
18+
{
19+
var path = Path.Combine ("temp", TestName);
20+
var androidSdkPath = CreateFauxAndroidSdkDirectory (Path.Combine (path, "android-sdk"), "26.0.3");
21+
string javaExe = string.Empty;
22+
var javaPath = CreateFauxJavaSdkDirectory (Path.Combine (path, "jdk"), "1.8.0", out javaExe);
23+
var referencePath = CreateFauxReferencesDirectory (Path.Combine (path, "references"), new ApiInfo [] {
24+
new ApiInfo () { Id = 26, Level = 26, Name = "Oreo", FrameworkVersion = "v8.0", Stable = true },
25+
new ApiInfo () { Id = 27, Level = 27, Name = "Oreo", FrameworkVersion = "v8.1", Stable = true },
26+
});
27+
IBuildEngine engine = new MockBuildEngine (TestContext.Out);
28+
var task = new ResolveSdks {
29+
BuildEngine = engine
30+
};
31+
task.AndroidSdkPath = androidSdkPath;
32+
task.AndroidNdkPath = androidSdkPath;
33+
task.JavaSdkPath = javaPath;
34+
task.TargetFrameworkVersion = "v8.0";
35+
task.AndroidSdkBuildToolsVersion = "26.0.3";
36+
task.BuildingInsideVisualStudio = "true";
37+
task.UseLatestAndroidPlatformSdk = false;
38+
task.AotAssemblies = false;
39+
task.LatestSupportedJavaVersion = "1.8.0";
40+
task.MinimumSupportedJavaVersion = "1.7.0";
41+
task.ReferenceAssemblyPaths = new string [] {
42+
Path.Combine (referencePath, "MonoAndroid"),
43+
};
44+
task.CacheFile = Path.Combine (Root, path, "sdk.xml");
45+
task.SequencePointsMode = "None";
46+
task.JavaToolExe = javaExe;
47+
var start = DateTime.UtcNow;
48+
Assert.IsTrue (task.Execute ());
49+
var executionTime = DateTime.UtcNow - start;
50+
Assert.LessOrEqual (executionTime, TimeSpan.FromSeconds(1), "Task should not take more than 1 second to run.");
51+
Assert.AreEqual (task.AndroidApiLevel, "26", "AndroidApiLevel should be 26");
52+
Assert.AreEqual (task.TargetFrameworkVersion, "v8.0", "TargetFrameworkVersion should be v8.0");
53+
Assert.AreEqual (task.AndroidApiLevelName, "26", "AndroidApiLevelName should be 26");
54+
Assert.AreEqual (task.SupportedApiLevel, "26", "SupportedApiLevel should be 26");
55+
Assert.NotNull (task.ReferenceAssemblyPaths, "ReferenceAssemblyPaths should not be null.");
56+
Assert.AreEqual (task.ReferenceAssemblyPaths.Length, 1, "ReferenceAssemblyPaths should have 1 entry.");
57+
Assert.AreEqual (task.ReferenceAssemblyPaths[0], Path.Combine (referencePath, "MonoAndroid"), $"ReferenceAssemblyPaths should be {Path.Combine (referencePath, "MonoAndroid")}.");
58+
var expected = Path.Combine (Root);
59+
Assert.AreEqual (task.MonoAndroidToolsPath, expected, $"MonoAndroidToolsPath should be {expected}");
60+
expected = Path.Combine (Root, "Darwin" + Path.DirectorySeparatorChar);
61+
Assert.AreEqual (task.MonoAndroidBinPath, expected, $"MonoAndroidBinPath should be {expected}");
62+
Assert.AreEqual (task.MonoAndroidIncludePath, null, "MonoAndroidIncludePath should be null");
63+
//Assert.AreEqual (task.AndroidNdkPath, "26", "AndroidNdkPath should be 26");
64+
Assert.AreEqual (task.AndroidSdkPath, androidSdkPath, $"AndroidSdkPath should be {androidSdkPath}");
65+
Assert.AreEqual (task.JavaSdkPath, javaPath, $"JavaSdkPath should be {javaPath}");
66+
expected = Path.Combine (androidSdkPath, "build-tools", "26.0.3");
67+
Assert.AreEqual (task.AndroidSdkBuildToolsPath, expected, $"AndroidSdkBuildToolsPath should be {expected}");
68+
Assert.AreEqual (task.AndroidSdkBuildToolsBinPath, expected, "AndroidSdkBuildToolsBinPath should be {expected}");
69+
Assert.AreEqual (task.ZipAlignPath, expected, "ZipAlignPath should be {expected}");
70+
Assert.AreEqual (task.AndroidSequencePointsMode, "None", "AndroidSequencePointsMode should be None");
71+
expected = Path.Combine (androidSdkPath, "tools");
72+
Assert.AreEqual (task.LintToolPath, expected, $"LintToolPath should be {expected}");
73+
expected = Path.Combine (androidSdkPath, "build-tools", "26.0.3", "lib", "apksigner.jar");
74+
Assert.AreEqual (task.ApkSignerJar, expected, $"ApkSignerJar should be {expected}");
75+
Assert.AreEqual (task.AndroidUseApkSigner, false, "AndroidUseApkSigner should be false");
76+
Assert.AreEqual (task.JdkVersion, "1.8.0", "JdkVersion should be 1.8.0");
77+
Assert.AreEqual (task.MinimumRequiredJdkVersion, "1.8", "MinimumRequiredJdkVersion should be 1.8");
78+
}
79+
}
80+
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ protected string CreateFauxAndroidSdkDirectory (string path, string buildToolsVe
122122
File.WriteAllText (Path.Combine (androidSdkPlatformToolsPath, IsWindows ? "adb.exe" : "adb"), "");
123123
File.WriteAllText (Path.Combine (androidSdkBuildToolsPath, IsWindows ? "zipalign.exe" : "zipalign"), "");
124124
File.WriteAllText (Path.Combine (androidSdkBuildToolsPath, IsWindows ? "aapt.exe" : "aapt"), "");
125+
File.WriteAllText (Path.Combine (androidSdkToolsPath, IsWindows ? "lint.exe" : "lint"), "");
125126

126127
for (int i=minApiLevel; i < maxApiLevel; i++) {
127128
var dir = Path.Combine (androidSdkPlatformsPath, $"android-{i}");

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,6 @@
7373
<Compile Include="ManifestTest.OSS.cs" />
7474
<Compile Include="AndroidRegExTests.cs" />
7575
<Compile Include="GetDependenciesTests.cs" />
76+
<Compile Include="ResolveSdksTaskTests.cs" />
7677
</ItemGroup>
7778
</Project>

0 commit comments

Comments
 (0)