Skip to content

Commit ae4f229

Browse files
authored
[tests] Remove duplicates from XASdkTests (#8214)
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.
1 parent 80a4716 commit ae4f229

12 files changed

+1537
-1808
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text.RegularExpressions;
77
using System.Xml.Linq;
88
using Microsoft.Build.Framework;
9+
using Mono.Cecil;
910
using NUnit.Framework;
1011
using Xamarin.Android.Tools;
1112
using Xamarin.ProjectTools;
@@ -648,6 +649,50 @@ public void CheckOldResourceDesignerWithWrongCasingIsRemoved ([Values (true, fal
648649
}
649650
}
650651

652+
[Test]
653+
public void GenerateResourceDesigner_false([Values (false, true)] bool useDesignerAssembly)
654+
{
655+
var proj = new XamarinAndroidApplicationProject {
656+
EnableDefaultItems = true,
657+
Sources = {
658+
new AndroidItem.AndroidResource (() => "Resources\\drawable\\foo.png") {
659+
BinaryContent = () => XamarinAndroidCommonProject.icon_binary_mdpi,
660+
},
661+
}
662+
};
663+
proj.SetProperty (KnownProperties.OutputType, "Library");
664+
665+
// Turn off Resource.designer.cs and remove usage of it
666+
proj.SetProperty ("AndroidGenerateResourceDesigner", "false");
667+
if (!useDesignerAssembly)
668+
proj.SetProperty ("AndroidUseDesignerAssembly", "false");
669+
proj.MainActivity = proj.DefaultMainActivity
670+
.Replace ("Resource.Layout.Main", "0")
671+
.Replace ("Resource.Id.myButton", "0");
672+
673+
var builder = CreateDllBuilder ();
674+
Assert.IsTrue (builder.RunTarget(proj, "CoreCompile", parameters: new string[] { "BuildingInsideVisualStudio=true" }), "Designtime build should succeed.");
675+
var intermediate = Path.Combine (Root, builder.ProjectDirectory, proj.IntermediateOutputPath);
676+
var resource_designer_cs = Path.Combine (intermediate, "designtime", "Resource.designer.cs");
677+
if (useDesignerAssembly)
678+
resource_designer_cs = Path.Combine (intermediate, "__Microsoft.Android.Resource.Designer.cs");
679+
FileAssert.DoesNotExist (resource_designer_cs);
680+
681+
Assert.IsTrue (builder.Build (proj), "build should succeed");
682+
683+
resource_designer_cs = Path.Combine (intermediate, "Resource.designer.cs");
684+
if (useDesignerAssembly)
685+
resource_designer_cs = Path.Combine (intermediate, "__Microsoft.Android.Resource.Designer.cs");
686+
FileAssert.DoesNotExist (resource_designer_cs);
687+
688+
var assemblyPath = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll");
689+
FileAssert.Exists (assemblyPath);
690+
using var assembly = AssemblyDefinition.ReadAssembly (assemblyPath);
691+
var typeName = $"{proj.ProjectName}.Resource";
692+
var type = assembly.MainModule.GetType (typeName);
693+
Assert.IsNull (type, $"{assemblyPath} should *not* contain {typeName}");
694+
}
695+
651696
[Test]
652697
public void CheckThatXA1034IsRaisedForInvalidConfiguration ([Values (true, false)] bool isRelease)
653698
{

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
45
using System.Text;
@@ -8,6 +9,7 @@
89
using NUnit.Framework;
910
using Xamarin.ProjectTools;
1011
using Xamarin.Android.Build;
12+
using Xamarin.Android.Tasks;
1113

1214
namespace Xamarin.Android.Build.Tests
1315
{
@@ -486,5 +488,45 @@ public void AotAssembliesInIDE ()
486488
Assert.IsNotNull (entry, $"{path} should be in {apk}", abi);
487489
}
488490
}
491+
492+
[Test]
493+
public void CheckWhetherLibcAndLibmAreReferencedInAOTLibraries ()
494+
{
495+
if (IsWindows)
496+
Assert.Ignore ("https://github.com/dotnet/runtime/issues/88625");
497+
498+
var proj = new XamarinAndroidApplicationProject {
499+
IsRelease = true,
500+
EmbedAssembliesIntoApk = true,
501+
AotAssemblies = true,
502+
};
503+
proj.SetProperty ("EnableLLVM", "True");
504+
505+
var abis = new [] { "arm64-v8a", "x86_64" };
506+
proj.SetAndroidSupportedAbis (abis);
507+
508+
var libPaths = new List<string> ();
509+
if (Builder.UseDotNet) {
510+
libPaths.Add (Path.Combine ("android-arm64", "aot", "Mono.Android.dll.so"));
511+
libPaths.Add (Path.Combine ("android-x64", "aot", "Mono.Android.dll.so"));
512+
} else {
513+
libPaths.Add (Path.Combine ("aot", "arm64-v8a", "libaot-Mono.Android.dll.so"));
514+
libPaths.Add (Path.Combine ("aot", "x86_64", "libaot-Mono.Android.dll.so"));
515+
}
516+
517+
using (var b = CreateApkBuilder ()) {
518+
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
519+
string objPath = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
520+
521+
foreach (string libPath in libPaths) {
522+
string lib = Path.Combine (objPath, libPath);
523+
524+
Assert.IsTrue (File.Exists (lib), $"Library {lib} should exist on disk");
525+
Assert.IsTrue (ELFHelper.ReferencesLibrary (lib, "libc.so"), $"Library {lib} should reference libc.so");
526+
Assert.IsTrue (ELFHelper.ReferencesLibrary (lib, "libm.so"), $"Library {lib} should reference libm.so");
527+
}
528+
}
529+
}
530+
489531
}
490532
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,53 @@
1212
namespace Xamarin.Android.Build.Tests
1313
{
1414
[Parallelizable (ParallelScope.Children)]
15-
public class BindingBuildTest : BaseTest {
16-
#pragma warning disable 414
15+
public class BindingBuildTest : BaseTest
16+
{
17+
[Test]
18+
public void DotNetBuildBinding ()
19+
{
20+
var proj = new XamarinAndroidLibraryProject () {
21+
EnableDefaultItems = true,
22+
};
23+
// Both transform files should be applied
24+
proj.Sources.Add (new AndroidItem.TransformFile ("Transforms.xml") {
25+
TextContent = () =>
26+
@"<metadata>
27+
<attr path=""/api/package[@name='com.xamarin.android.test.msbuildtest']"" name=""managedName"">FooBar</attr>
28+
</metadata>",
29+
});
30+
proj.Sources.Add (new AndroidItem.TransformFile ("Transforms\\Metadata.xml") {
31+
TextContent = () =>
32+
@"<metadata>
33+
<attr path=""/api/package[@managedName='FooBar']"" name=""managedName"">MSBuildTest</attr>
34+
</metadata>",
35+
});
36+
proj.Sources.Add (new AndroidItem.AndroidLibrary ("javaclasses.jar") {
37+
BinaryContent = () => ResourceData.JavaSourceJarTestJar,
38+
});
39+
proj.OtherBuildItems.Add (new BuildItem ("JavaSourceJar", "javaclasses-sources.jar") {
40+
BinaryContent = () => ResourceData.JavaSourceJarTestSourcesJar,
41+
});
42+
proj.OtherBuildItems.Add (new AndroidItem.AndroidJavaSource ("JavaSourceTestExtension.java") {
43+
Encoding = Encoding.ASCII,
44+
TextContent = () => ResourceData.JavaSourceTestExtension,
45+
Metadata = { { "Bind", "True"} },
46+
});
47+
var builder = CreateDllBuilder ();
48+
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed");
49+
50+
var assemblyPath = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, "UnnamedProject.dll");
51+
FileAssert.Exists (assemblyPath);
52+
using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) {
53+
var typeName = "MSBuildTest.JavaSourceJarTest";
54+
var type = assembly.MainModule.GetType (typeName);
55+
Assert.IsNotNull (type, $"{assemblyPath} should contain {typeName}");
56+
typeName = "MSBuildTest.JavaSourceTestExtension";
57+
type = assembly.MainModule.GetType (typeName);
58+
Assert.IsNotNull (type, $"{assemblyPath} should contain {typeName}");
59+
}
60+
}
61+
1762
static object [] ClassParseOptions = new object [] {
1863
new object[] {
1964
/* classParser */ "class-parse",
@@ -22,7 +67,7 @@ public class BindingBuildTest : BaseTest {
2267

2368
[Test]
2469
[TestCaseSource (nameof (ClassParseOptions))]
25-
public void BuildBasicBindingLibrary (string classParser)
70+
public void BindingLibraryIncremental (string classParser)
2671
{
2772
var targets = new List<string> {
2873
"_ExportJarToXml",
@@ -475,6 +520,39 @@ public void JavaSourceJar ()
475520
}
476521
}
477522

523+
[Test]
524+
public void AppWithSingleJar ()
525+
{
526+
var proj = new XamarinAndroidApplicationProject {
527+
EnableDefaultItems = true,
528+
Sources = {
529+
new AndroidItem.AndroidLibrary ("Jars\\javaclasses.jar") {
530+
BinaryContent = () => ResourceData.JavaSourceJarTestJar,
531+
}
532+
}
533+
};
534+
535+
var builder = CreateApkBuilder ();
536+
Assert.IsTrue (builder.Build (proj), "first build should succeed");
537+
538+
var assemblyPath = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll");
539+
var typeName = "Com.Xamarin.Android.Test.Msbuildtest.JavaSourceJarTest";
540+
FileAssert.Exists (assemblyPath);
541+
using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) {
542+
Assert.IsNotNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should contain {typeName}");
543+
}
544+
545+
// Remove the @(AndroidLibrary) & build again
546+
proj.Sources.RemoveAt (proj.Sources.Count - 1);
547+
Directory.Delete (Path.Combine (Root, builder.ProjectDirectory, "Jars"), recursive: true);
548+
Assert.IsTrue (builder.Build (proj), "second build should succeed");
549+
550+
FileAssert.Exists (assemblyPath);
551+
using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) {
552+
Assert.IsNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should *not* contain {typeName}");
553+
}
554+
}
555+
478556
[Test]
479557
[TestCaseSource (nameof (ClassParseOptions))]
480558
public void DesignTimeBuild (string classParser)

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.TestCaseSource.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,105 @@ namespace Xamarin.Android.Build.Tests
1111
{
1212
public partial class BuildTest : BaseTest
1313
{
14+
static readonly object [] DotNetBuildSource = new object [] {
15+
new object [] {
16+
/* runtimeIdentifiers */ "android-arm",
17+
/* isRelease */ false,
18+
/* aot */ false,
19+
/* usesAssemblyStore */ false,
20+
},
21+
new object [] {
22+
/* runtimeIdentifiers */ "android-arm",
23+
/* isRelease */ false,
24+
/* aot */ false,
25+
/* usesAssemblyStore */ true,
26+
},
27+
new object [] {
28+
/* runtimeIdentifiers */ "android-arm64",
29+
/* isRelease */ false,
30+
/* aot */ false,
31+
/* usesAssemblyStore */ false,
32+
},
33+
new object [] {
34+
/* runtimeIdentifiers */ "android-x86",
35+
/* isRelease */ false,
36+
/* aot */ false,
37+
/* usesAssemblyStore */ false,
38+
},
39+
new object [] {
40+
/* runtimeIdentifiers */ "android-x64",
41+
/* isRelease */ false,
42+
/* aot */ false,
43+
/* usesAssemblyStore */ false,
44+
},
45+
new object [] {
46+
/* runtimeIdentifiers */ "android-arm",
47+
/* isRelease */ true,
48+
/* aot */ false,
49+
/* usesAssemblyStore */ false,
50+
},
51+
new object [] {
52+
/* runtimeIdentifiers */ "android-arm",
53+
/* isRelease */ true,
54+
/* aot */ false,
55+
/* usesAssemblyStore */ true,
56+
},
57+
new object [] {
58+
/* runtimeIdentifiers */ "android-arm",
59+
/* isRelease */ true,
60+
/* aot */ true,
61+
/* usesAssemblyStore */ false,
62+
},
63+
new object [] {
64+
/* runtimeIdentifiers */ "android-arm",
65+
/* isRelease */ true,
66+
/* aot */ true,
67+
/* usesAssemblyStore */ true,
68+
},
69+
new object [] {
70+
/* runtimeIdentifiers */ "android-arm64",
71+
/* isRelease */ true,
72+
/* aot */ false,
73+
/* usesAssemblyStore */ false,
74+
},
75+
new object [] {
76+
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
77+
/* isRelease */ false,
78+
/* aot */ false,
79+
/* usesAssemblyStore */ false,
80+
},
81+
new object [] {
82+
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
83+
/* isRelease */ false,
84+
/* aot */ false,
85+
/* usesAssemblyStore */ true,
86+
},
87+
new object [] {
88+
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86",
89+
/* isRelease */ true,
90+
/* aot */ false,
91+
/* usesAssemblyStore */ false,
92+
},
93+
new object [] {
94+
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
95+
/* isRelease */ true,
96+
/* aot */ false,
97+
/* usesAssemblyStore */ false,
98+
},
99+
new object [] {
100+
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
101+
/* isRelease */ true,
102+
/* aot */ false,
103+
/* usesAssemblyStore */ true,
104+
},
105+
new object [] {
106+
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
107+
/* isRelease */ true,
108+
/* aot */ true,
109+
/* usesAssemblyStore */ false,
110+
},
111+
};
112+
14113
#pragma warning disable 414
15114
static object [] RuntimeChecks () => new object [] {
16115
new object[] {

0 commit comments

Comments
 (0)