Skip to content

Commit 9b79c81

Browse files
committed
Add a couple of tests
1 parent ac64906 commit 9b79c81

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,5 +796,46 @@ void CreateEmptyFile (string path)
796796
}
797797
}
798798

799+
[Test]
800+
[TestCase (false)]
801+
[TestCase (true)]
802+
public void CheckEmbeddedAssemblyStorePackaging (bool useCLR)
803+
{
804+
var proj = new XamarinAndroidApplicationProject {
805+
IsRelease = true
806+
};
807+
808+
AndroidTargetArch[] supportedArches = new[] {
809+
AndroidTargetArch.Arm64,
810+
AndroidTargetArch.X86_64,
811+
};
812+
813+
proj.SetRuntimeIdentifiers (supportedArches);
814+
proj.SetProperty ("AndroidUseAssemblyStore", "true");
815+
proj.SetProperty ("_AndroidEmbedAssemblyStoreInRuntime", "true");
816+
proj.SetProperty ("UseMonoRuntime", useCLR ? "false" : "true");
817+
818+
using var b = CreateApkBuilder ();
819+
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
820+
string apk = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, $"{proj.PackageName}-Signed.apk");
821+
822+
var knownAssemblyStoreFiles = new HashSet<string> (StringComparer.Ordinal);
823+
foreach (AndroidTargetArch arch in supportedArches) {
824+
string archName = MonoAndroidHelper.ArchToAbi (arch);
825+
knownAssemblyStoreFiles.Add ($"lib/{archName}/libassemblies.{archName}.blob.so");
826+
}
827+
828+
var foundAssemblyStoreFiles = new HashSet<string> (StringComparer.Ordinal);
829+
using var zip = ZipHelper.OpenZip (apk);
830+
831+
foreach (var entry in zip) {
832+
if (knownAssemblyStoreFiles.Contains (entry.FullName)) {
833+
foundAssemblyStoreFiles.Add (entry.FullName);
834+
}
835+
}
836+
837+
Assert.IsFalse (foundAssemblyStoreFiles.Count != 0, $"APK should not contain any of the files: {FoundFiles ()}");
838+
string FoundFiles () => String.Join (", ", foundAssemblyStoreFiles);
839+
}
799840
}
800841
}

tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,5 +1380,26 @@ public void AppStartsWithManagedMarshalMethodsLookupEnabled ()
13801380
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30);
13811381
Assert.IsTrue (didLaunch, "Activity should have started.");
13821382
}
1383+
1384+
[Test]
1385+
[TestCase (false)]
1386+
[TestCase (true)]
1387+
public void AppStartsWithEmbeddedAssemblyStore (bool useCLR)
1388+
{
1389+
var proj = new XamarinAndroidApplicationProject { IsRelease = true };
1390+
proj.SetProperty ("_AndroidEmbedAssemblyStoreInRuntime", "true");
1391+
proj.SetProperty ("UseMonoRuntime", useCLR ? "false" : "true");
1392+
1393+
using var builder = CreateApkBuilder ();
1394+
builder.Save (proj);
1395+
1396+
var dotnet = new DotNetCLI (Path.Combine (Root, builder.ProjectDirectory, proj.ProjectFilePath));
1397+
Assert.IsTrue (dotnet.Build (), "`dotnet build` should succeed");
1398+
Assert.IsTrue (dotnet.Run (), "`dotnet run --no-build` should succeed");
1399+
1400+
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity",
1401+
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30);
1402+
Assert.IsTrue (didLaunch, "Activity should have started.");
1403+
}
13831404
}
13841405
}

0 commit comments

Comments
 (0)