Skip to content

Commit

Permalink
[tests] Remove duplicates from XASdkTests (#8214)
Browse files Browse the repository at this point in the history
I've spent some time reviewing tests in `XASdkTests`, `BuildTest`, and
`BuildTest2`.  Tests from `XASdkTests` have been migrated to other
fixtures or removed where applicable.

 * DotNetBuildXamarinForms has been removed and merged into CheckMonoComponentsMask.

 * DotNetIncremental has been removed and merged into BuildIncrementalAot.

 * DotNetDesignTimeBuild has been renamed to DesignTimeBuildSignAndroidPackage.

 * BenchmarkDotNet has been removed and merged into BuildHasNoWarnings.

 * BuildApplicationWithJavaSource has been removed due to existing coverage of .java file inclusion elsewhere.

 * BuildReleaseApplicationWithNugetPackages has been removed due to existing coverage in GenerateLibraryResourcesTests.

 * BuildAfterAddingNuget has been removed as the same scenario is covered in BuildAfterUpgradingNuget.

 * ValidateJavaVersion has been removed as .NET Android requires JDK 11+, which is not covered by any of the legacy parameters.
  • Loading branch information
pjcollins authored Aug 2, 2023
1 parent 80a4716 commit ae4f229
Show file tree
Hide file tree
Showing 12 changed files with 1,537 additions and 1,808 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Microsoft.Build.Framework;
using Mono.Cecil;
using NUnit.Framework;
using Xamarin.Android.Tools;
using Xamarin.ProjectTools;
Expand Down Expand Up @@ -648,6 +649,50 @@ public void CheckOldResourceDesignerWithWrongCasingIsRemoved ([Values (true, fal
}
}

[Test]
public void GenerateResourceDesigner_false([Values (false, true)] bool useDesignerAssembly)
{
var proj = new XamarinAndroidApplicationProject {
EnableDefaultItems = true,
Sources = {
new AndroidItem.AndroidResource (() => "Resources\\drawable\\foo.png") {
BinaryContent = () => XamarinAndroidCommonProject.icon_binary_mdpi,
},
}
};
proj.SetProperty (KnownProperties.OutputType, "Library");

// Turn off Resource.designer.cs and remove usage of it
proj.SetProperty ("AndroidGenerateResourceDesigner", "false");
if (!useDesignerAssembly)
proj.SetProperty ("AndroidUseDesignerAssembly", "false");
proj.MainActivity = proj.DefaultMainActivity
.Replace ("Resource.Layout.Main", "0")
.Replace ("Resource.Id.myButton", "0");

var builder = CreateDllBuilder ();
Assert.IsTrue (builder.RunTarget(proj, "CoreCompile", parameters: new string[] { "BuildingInsideVisualStudio=true" }), "Designtime build should succeed.");
var intermediate = Path.Combine (Root, builder.ProjectDirectory, proj.IntermediateOutputPath);
var resource_designer_cs = Path.Combine (intermediate, "designtime", "Resource.designer.cs");
if (useDesignerAssembly)
resource_designer_cs = Path.Combine (intermediate, "__Microsoft.Android.Resource.Designer.cs");
FileAssert.DoesNotExist (resource_designer_cs);

Assert.IsTrue (builder.Build (proj), "build should succeed");

resource_designer_cs = Path.Combine (intermediate, "Resource.designer.cs");
if (useDesignerAssembly)
resource_designer_cs = Path.Combine (intermediate, "__Microsoft.Android.Resource.Designer.cs");
FileAssert.DoesNotExist (resource_designer_cs);

var assemblyPath = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll");
FileAssert.Exists (assemblyPath);
using var assembly = AssemblyDefinition.ReadAssembly (assemblyPath);
var typeName = $"{proj.ProjectName}.Resource";
var type = assembly.MainModule.GetType (typeName);
Assert.IsNull (type, $"{assemblyPath} should *not* contain {typeName}");
}

[Test]
public void CheckThatXA1034IsRaisedForInvalidConfiguration ([Values (true, false)] bool isRelease)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -8,6 +9,7 @@
using NUnit.Framework;
using Xamarin.ProjectTools;
using Xamarin.Android.Build;
using Xamarin.Android.Tasks;

namespace Xamarin.Android.Build.Tests
{
Expand Down Expand Up @@ -486,5 +488,45 @@ public void AotAssembliesInIDE ()
Assert.IsNotNull (entry, $"{path} should be in {apk}", abi);
}
}

[Test]
public void CheckWhetherLibcAndLibmAreReferencedInAOTLibraries ()
{
if (IsWindows)
Assert.Ignore ("https://github.com/dotnet/runtime/issues/88625");

var proj = new XamarinAndroidApplicationProject {
IsRelease = true,
EmbedAssembliesIntoApk = true,
AotAssemblies = true,
};
proj.SetProperty ("EnableLLVM", "True");

var abis = new [] { "arm64-v8a", "x86_64" };
proj.SetAndroidSupportedAbis (abis);

var libPaths = new List<string> ();
if (Builder.UseDotNet) {
libPaths.Add (Path.Combine ("android-arm64", "aot", "Mono.Android.dll.so"));
libPaths.Add (Path.Combine ("android-x64", "aot", "Mono.Android.dll.so"));
} else {
libPaths.Add (Path.Combine ("aot", "arm64-v8a", "libaot-Mono.Android.dll.so"));
libPaths.Add (Path.Combine ("aot", "x86_64", "libaot-Mono.Android.dll.so"));
}

using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
string objPath = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);

foreach (string libPath in libPaths) {
string lib = Path.Combine (objPath, libPath);

Assert.IsTrue (File.Exists (lib), $"Library {lib} should exist on disk");
Assert.IsTrue (ELFHelper.ReferencesLibrary (lib, "libc.so"), $"Library {lib} should reference libc.so");
Assert.IsTrue (ELFHelper.ReferencesLibrary (lib, "libm.so"), $"Library {lib} should reference libm.so");
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,53 @@
namespace Xamarin.Android.Build.Tests
{
[Parallelizable (ParallelScope.Children)]
public class BindingBuildTest : BaseTest {
#pragma warning disable 414
public class BindingBuildTest : BaseTest
{
[Test]
public void DotNetBuildBinding ()
{
var proj = new XamarinAndroidLibraryProject () {
EnableDefaultItems = true,
};
// Both transform files should be applied
proj.Sources.Add (new AndroidItem.TransformFile ("Transforms.xml") {
TextContent = () =>
@"<metadata>
<attr path=""/api/package[@name='com.xamarin.android.test.msbuildtest']"" name=""managedName"">FooBar</attr>
</metadata>",
});
proj.Sources.Add (new AndroidItem.TransformFile ("Transforms\\Metadata.xml") {
TextContent = () =>
@"<metadata>
<attr path=""/api/package[@managedName='FooBar']"" name=""managedName"">MSBuildTest</attr>
</metadata>",
});
proj.Sources.Add (new AndroidItem.AndroidLibrary ("javaclasses.jar") {
BinaryContent = () => ResourceData.JavaSourceJarTestJar,
});
proj.OtherBuildItems.Add (new BuildItem ("JavaSourceJar", "javaclasses-sources.jar") {
BinaryContent = () => ResourceData.JavaSourceJarTestSourcesJar,
});
proj.OtherBuildItems.Add (new AndroidItem.AndroidJavaSource ("JavaSourceTestExtension.java") {
Encoding = Encoding.ASCII,
TextContent = () => ResourceData.JavaSourceTestExtension,
Metadata = { { "Bind", "True"} },
});
var builder = CreateDllBuilder ();
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed");

var assemblyPath = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, "UnnamedProject.dll");
FileAssert.Exists (assemblyPath);
using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) {
var typeName = "MSBuildTest.JavaSourceJarTest";
var type = assembly.MainModule.GetType (typeName);
Assert.IsNotNull (type, $"{assemblyPath} should contain {typeName}");
typeName = "MSBuildTest.JavaSourceTestExtension";
type = assembly.MainModule.GetType (typeName);
Assert.IsNotNull (type, $"{assemblyPath} should contain {typeName}");
}
}

static object [] ClassParseOptions = new object [] {
new object[] {
/* classParser */ "class-parse",
Expand All @@ -22,7 +67,7 @@ public class BindingBuildTest : BaseTest {

[Test]
[TestCaseSource (nameof (ClassParseOptions))]
public void BuildBasicBindingLibrary (string classParser)
public void BindingLibraryIncremental (string classParser)
{
var targets = new List<string> {
"_ExportJarToXml",
Expand Down Expand Up @@ -475,6 +520,39 @@ public void JavaSourceJar ()
}
}

[Test]
public void AppWithSingleJar ()
{
var proj = new XamarinAndroidApplicationProject {
EnableDefaultItems = true,
Sources = {
new AndroidItem.AndroidLibrary ("Jars\\javaclasses.jar") {
BinaryContent = () => ResourceData.JavaSourceJarTestJar,
}
}
};

var builder = CreateApkBuilder ();
Assert.IsTrue (builder.Build (proj), "first build should succeed");

var assemblyPath = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll");
var typeName = "Com.Xamarin.Android.Test.Msbuildtest.JavaSourceJarTest";
FileAssert.Exists (assemblyPath);
using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) {
Assert.IsNotNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should contain {typeName}");
}

// Remove the @(AndroidLibrary) & build again
proj.Sources.RemoveAt (proj.Sources.Count - 1);
Directory.Delete (Path.Combine (Root, builder.ProjectDirectory, "Jars"), recursive: true);
Assert.IsTrue (builder.Build (proj), "second build should succeed");

FileAssert.Exists (assemblyPath);
using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) {
Assert.IsNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should *not* contain {typeName}");
}
}

[Test]
[TestCaseSource (nameof (ClassParseOptions))]
public void DesignTimeBuild (string classParser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,105 @@ namespace Xamarin.Android.Build.Tests
{
public partial class BuildTest : BaseTest
{
static readonly object [] DotNetBuildSource = new object [] {
new object [] {
/* runtimeIdentifiers */ "android-arm",
/* isRelease */ false,
/* aot */ false,
/* usesAssemblyStore */ false,
},
new object [] {
/* runtimeIdentifiers */ "android-arm",
/* isRelease */ false,
/* aot */ false,
/* usesAssemblyStore */ true,
},
new object [] {
/* runtimeIdentifiers */ "android-arm64",
/* isRelease */ false,
/* aot */ false,
/* usesAssemblyStore */ false,
},
new object [] {
/* runtimeIdentifiers */ "android-x86",
/* isRelease */ false,
/* aot */ false,
/* usesAssemblyStore */ false,
},
new object [] {
/* runtimeIdentifiers */ "android-x64",
/* isRelease */ false,
/* aot */ false,
/* usesAssemblyStore */ false,
},
new object [] {
/* runtimeIdentifiers */ "android-arm",
/* isRelease */ true,
/* aot */ false,
/* usesAssemblyStore */ false,
},
new object [] {
/* runtimeIdentifiers */ "android-arm",
/* isRelease */ true,
/* aot */ false,
/* usesAssemblyStore */ true,
},
new object [] {
/* runtimeIdentifiers */ "android-arm",
/* isRelease */ true,
/* aot */ true,
/* usesAssemblyStore */ false,
},
new object [] {
/* runtimeIdentifiers */ "android-arm",
/* isRelease */ true,
/* aot */ true,
/* usesAssemblyStore */ true,
},
new object [] {
/* runtimeIdentifiers */ "android-arm64",
/* isRelease */ true,
/* aot */ false,
/* usesAssemblyStore */ false,
},
new object [] {
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
/* isRelease */ false,
/* aot */ false,
/* usesAssemblyStore */ false,
},
new object [] {
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
/* isRelease */ false,
/* aot */ false,
/* usesAssemblyStore */ true,
},
new object [] {
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86",
/* isRelease */ true,
/* aot */ false,
/* usesAssemblyStore */ false,
},
new object [] {
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
/* isRelease */ true,
/* aot */ false,
/* usesAssemblyStore */ false,
},
new object [] {
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
/* isRelease */ true,
/* aot */ false,
/* usesAssemblyStore */ true,
},
new object [] {
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
/* isRelease */ true,
/* aot */ true,
/* usesAssemblyStore */ false,
},
};

#pragma warning disable 414
static object [] RuntimeChecks () => new object [] {
new object[] {
Expand Down
Loading

0 comments on commit ae4f229

Please sign in to comment.