Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Runtime.CompilerServices;
using System.Text;
using Xamarin.Android.Tasks;
using Xamarin.ProjectTools;

namespace Xamarin.Android.Build.Tests;

class PackageUtils
{
/// <summary>
/// Constructs Android package name parameter for the <see cref="XamarinAndroidApplicationProject" /> which includes
/// the runtime used to build and run the application. A unique per-runtime package name is necessary so that elements
/// of different runtimes don't mix when running the same test for several of them.
/// </summary>
public static string MakePackageName (AndroidRuntime runtime, [CallerMemberName] string packageName = "")
{
if (String.IsNullOrEmpty (packageName)) {
throw new ArgumentException ("Must not be null or empty", nameof (packageName));
}

var sb = new StringBuilder (packageName);
sb.Append ('_');
sb.Append (runtime.ToString ().ToLowerInvariant ());

return sb.ToString ();
}
}
29 changes: 27 additions & 2 deletions tests/MSBuildDeviceIntegration/Tests/LocalizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,38 @@
using NUnit.Framework.Interfaces;
using Xamarin.ProjectTools;
using Humanizer;
using Xamarin.Android.Tasks;

namespace Xamarin.Android.Build.Tests
{
[TestFixture]
[TestFixtureSource (nameof (Get_Fixture_Args))]
[Category ("Localization")]
[NonParallelizable]
public class LocalizationTests : DeviceTest
{
ProjectBuilder builder;
XamarinAndroidApplicationProject proj;
string localeFileSuffix;
readonly AndroidRuntime runtime;
readonly bool isRelease;

static IEnumerable<object[]> Get_Fixture_Args ()
{
var ret = new List<object[]> ();

foreach (AndroidRuntime runtime in Enum.GetValues (typeof (AndroidRuntime))) {
ret.Add (new object[] { runtime });
}

return ret;
}

public LocalizationTests (AndroidRuntime runtime)
{
this.runtime = runtime;
isRelease = runtime == AndroidRuntime.NativeAOT;
}

[OneTimeSetUp]
public void BeforeAllTests ()
Expand All @@ -31,7 +52,11 @@ public void BeforeAllTests ()
Assert.Fail ("LocalizationTests need to use `su root` and this device does not support that feature. Try using an emulator.");
}

proj = new XamarinAndroidApplicationProject (packageName: "LocalizationTests");
proj = new XamarinAndroidApplicationProject (packageName: PackageUtils.MakePackageName (runtime, "LocalizationTests")) {
IsRelease = isRelease,
};
proj.SetRuntime (runtime);

proj.PackageReferences.Add (new Package {
Id = "Humanizer",
Version = "2.14.1",
Expand All @@ -49,7 +74,7 @@ public void BeforeAllTests ()
InlineData.AddCultureResourcesToProject (proj, "Strings", "SomeString");
InlineData.AddCultureResourceDesignerToProject (proj, proj.RootNamespace ?? proj.ProjectName, "Strings", "SomeString");

builder = CreateApkBuilder (Path.Combine ("temp", "LocalizationTests"));
builder = CreateApkBuilder (Path.Combine ("temp", TestName));
builder.BuildLogFile = "onetimesetup-install.log";
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,21 @@ public override void Close ()
";

[Test]
public void MarshalMethodsAppRuns ([Values (AndroidRuntime.CoreCLR, AndroidRuntime.MonoVM)] AndroidRuntime runtime)
public void MarshalMethodsAppRuns ([Values] AndroidRuntime runtime)
{
var proj = new XamarinAndroidApplicationProject (packageName: "marshal2") {
IsRelease = true,
const bool isRelease = true;
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
return;
}

if (runtime == AndroidRuntime.NativeAOT) {
Assert.Ignore ("Not supported with NativeAOT");
}

var proj = new XamarinAndroidApplicationProject (packageName: PackageUtils.MakePackageName (runtime, "marshal2")) {
IsRelease = isRelease,
EnableMarshalMethods = true,
SupportedOSPlatformVersion = "23",
SupportedOSPlatformVersion = "24", // Minimum 24 to be able to test on Android 16
TrimModeRelease = TrimMode.Full,
ProjectName = "marshal2",
};
Expand Down
12 changes: 8 additions & 4 deletions tests/MSBuildDeviceIntegration/Tests/MonoAndroidExportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ public class MonoAndroidExportTest : DeviceTest
{
[Test]
public void MonoAndroidExportReferencedAppStarts (
[Values (true, false)] bool embedAssemblies,
[Values (true, false)] bool isRelease,
[Values (AndroidRuntime.CoreCLR, AndroidRuntime.MonoVM)] AndroidRuntime runtime)
[Values] bool embedAssemblies,
[Values] bool isRelease,
[Values] AndroidRuntime runtime)
{
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
return;
}

AssertCommercialBuild ();
var proj = new XamarinAndroidApplicationProject () {
var proj = new XamarinAndroidApplicationProject (packageName: PackageUtils.MakePackageName (runtime)) {
IsRelease = isRelease,
References = {
new BuildItem.Reference ("Mono.Android.Export"),
Expand Down
4 changes: 3 additions & 1 deletion tests/MSBuildDeviceIntegration/Tests/PerformanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Logging.StructuredLogger;
using NUnit.Framework;
using Xamarin.Android.Tasks;
using Xamarin.ProjectTools;

namespace Xamarin.Android.Build.Tests
{
// TODO: update for NativeAOT and CoreCLR
[TestFixture]
[Category ("Performance")]
public class PerformanceTest : DeviceTest
Expand Down Expand Up @@ -61,7 +63,7 @@ void Profile (ProjectBuilder builder, int iterations, Action<ProjectBuilder> act
action (builder);
var actual = GetDurationFromBinLog (builder);
TestContext.Out.WriteLine ($"run {i} took: {actual}ms");
total += actual;
total += actual;
if (afterRun is not null)
afterRun (builder);
}
Expand Down
10 changes: 8 additions & 2 deletions tests/MSBuildDeviceIntegration/Tests/SystemApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Xml.Linq;
using System.Collections.Generic;
using Xamarin.Android.Tasks;

namespace Xamarin.Android.Build.Tests
{
Expand All @@ -16,14 +17,19 @@ public class SystemApplicationTests : DeviceTest
{
// All Tests here require the emulator to be started with -writable-system
[Test, Category ("SystemApplication")]
public void SystemApplicationCanInstall ()
public void SystemApplicationCanInstall ([Values] AndroidRuntime runtime)
{
const bool isRelease = false;
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
return;
}
AssertCommercialBuild ();

var proj = new XamarinAndroidApplicationProject () {
var proj = new XamarinAndroidApplicationProject (packageName: PackageUtils.MakePackageName (runtime)) {
IsRelease = false,
EmbedAssembliesIntoApk = false,
};
proj.SetRuntime (runtime);
proj.OtherBuildItems.Add (new BuildItem ("None", "platform.pk8") {
WebContent = "https://github.com/aosp-mirror/platform_build/raw/master/target/product/security/platform.pk8"
});
Expand Down
27 changes: 25 additions & 2 deletions tests/MSBuildDeviceIntegration/Tests/TimeZoneInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using Xamarin.Android.Tasks;
using Xamarin.ProjectTools;

namespace Xamarin.Android.Build.Tests
Expand All @@ -17,6 +18,25 @@ public class TimeZoneInfoTests : DeviceTest
ProjectBuilder builder;
XamarinAndroidApplicationProject proj;
string tzFileSuffix;
readonly AndroidRuntime runtime;
readonly bool isRelease;

static IEnumerable<object[]> Get_Fixture_Args ()
{
var ret = new List<object[]> ();

foreach (AndroidRuntime runtime in Enum.GetValues (typeof (AndroidRuntime))) {
ret.Add (new object[] { runtime });
}

return ret;
}

public TimeZoneInfoTests (AndroidRuntime runtime)
{
this.runtime = runtime;
isRelease = runtime == AndroidRuntime.NativeAOT;
}

[OneTimeSetUp]
public void BeforeAllTests ()
Expand All @@ -30,13 +50,16 @@ public void BeforeAllTests ()
// Disable auto timezone
RunAdbCommand ("shell settings put global auto_time_zone 0");

proj = new XamarinAndroidApplicationProject (packageName: "TimeZoneInfoTests");
proj = new XamarinAndroidApplicationProject (packageName: PackageUtils.MakePackageName (runtime, "TimeZoneInfoTests")) {
IsRelease = isRelease,
};
proj.SetRuntime (runtime);
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", @"button.Text = $""TimeZoneInfo={TimeZoneInfo.Local.Id}"";
Console.WriteLine ($""TimeZoneInfoNative={Java.Util.TimeZone.Default.ID}"");
Console.WriteLine ($""TimeZoneInfoTests.TimeZoneInfo={TimeZoneInfo.Local.Id}"");
");

builder = CreateApkBuilder (Path.Combine ("temp", "TimeZoneInfoTests"));
builder = CreateApkBuilder (Path.Combine ("temp", TestName));
builder.BuildLogFile = "onetimesetup-install.log";
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");
}
Expand Down
13 changes: 11 additions & 2 deletions tests/MSBuildDeviceIntegration/Tests/UncaughtExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Text.RegularExpressions;
using NUnit.Framework;
using Xamarin.Android.Tasks;
using Xamarin.ProjectTools;

namespace Xamarin.Android.Build.Tests
Expand All @@ -20,12 +21,18 @@ class LogcatLine
};

[Test]
public void EnsureUncaughtExceptionWorks ()
public void EnsureUncaughtExceptionWorks ([Values] AndroidRuntime runtime)
{
bool isRelease = runtime == AndroidRuntime.NativeAOT;
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
return;
}

var lib = new XamarinAndroidBindingProject {
ProjectName = "Scratch.Try",
AndroidClassParser = "class-parse",
};
lib.SetRuntime (runtime);

lib.Imports.Add (
new Import (() => "Directory.Build.targets") {
Expand Down Expand Up @@ -89,9 +96,11 @@ public static final void tryCatchFinally (Runnable r, CatchThrowableHandler c, R
"
});

var app = new XamarinAndroidApplicationProject {
var app = new XamarinAndroidApplicationProject (packageName: PackageUtils.MakePackageName (runtime)) {
IsRelease = isRelease,
ProjectName = "Scratch.JMJMException",
};
app.SetRuntime (runtime);

app.SetDefaultTargetDevice ();
app.AddReference (lib);
Expand Down
Loading