Skip to content
Merged
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
34 changes: 30 additions & 4 deletions tests/MSBuildDeviceIntegration/Tests/DebuggingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace Xamarin.Android.Build.Tests
[Category ("UsesDevice")]
public class DebuggingTest : DeviceTest
{
const int DEBUGGER_MAX_CONNECTIONS = 100;
const int DEBUGGER_CONNECTION_TIMEOUT = 3000;

[TearDown]
public void ClearDebugProperties ()
{
Expand Down Expand Up @@ -242,7 +245,8 @@ public override void OnCreate ()
int port = rnd.Next (10000, 20000);
TestContext.Out.WriteLine ($"{port}");
var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) {
MaxConnectionAttempts = 2000, // we need a long delay here to get a reliable connection
MaxConnectionAttempts = DEBUGGER_MAX_CONNECTIONS, // we need a long delay here to get a reliable connection
TimeBetweenConnectionAttempts = DEBUGGER_CONNECTION_TIMEOUT,
};
var startInfo = new SoftDebuggerStartInfo (args) {
WorkingDirectory = Path.Combine (b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets"),
Expand Down Expand Up @@ -299,70 +303,87 @@ public override void OnCreate ()
/* allowDeltaInstall */ false,
/* user */ null,
/* packageFormat */ "apk",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ true,
/* fastDevType */ "Assemblies",
/* allowDeltaInstall */ false,
/* user */ null,
/* packageFormat */ "apk",
/* useLatestSdk */ false,
},
new object[] {
/* embedAssemblies */ false,
/* fastDevType */ "Assemblies",
/* allowDeltaInstall */ false,
/* user */ null,
/* packageFormat */ "apk",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ false,
/* fastDevType */ "Assemblies",
/* allowDeltaInstall */ true,
/* user */ null,
/* packageFormat */ "apk",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ false,
/* fastDevType */ "Assemblies:Dexes",
/* allowDeltaInstall */ false,
/* user */ null,
/* packageFormat */ "apk",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ false,
/* fastDevType */ "Assemblies:Dexes",
/* allowDeltaInstall */ true,
/* user */ null,
/* packageFormat */ "apk",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ true,
/* fastDevType */ "Assemblies",
/* allowDeltaInstall */ false,
/* user */ DeviceTest.GuestUserName,
/* packageFormat */ "apk",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ false,
/* fastDevType */ "Assemblies",
/* allowDeltaInstall */ false,
/* user */ DeviceTest.GuestUserName,
/* packageFormat */ "apk",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ true,
/* fastDevType */ "Assemblies",
/* allowDeltaInstall */ false,
/* user */ null,
/* packageFormat */ "aab",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ true,
/* fastDevType */ "Assemblies",
/* allowDeltaInstall */ false,
/* user */ DeviceTest.GuestUserName,
/* packageFormat */ "aab",
/* useLatestSdk */ true,
},
};
#pragma warning restore 414

[Test, Category ("Debugger")]
[Test, Category ("Debugger"), Category ("WearOS")]
[TestCaseSource (nameof(DebuggerTestCases))]
[Retry (5)]
public void ApplicationRunsWithDebuggerAndBreaks (bool embedAssemblies, string fastDevType, bool allowDeltaInstall, string username, string packageFormat)
public void ApplicationRunsWithDebuggerAndBreaks (bool embedAssemblies, string fastDevType, bool allowDeltaInstall, string username, string packageFormat, bool useLatestSdk)
{
AssertCommercialBuild ();
SwitchUser ();
Expand Down Expand Up @@ -405,6 +426,10 @@ public Foo ()
EmbedAssembliesIntoApk = embedAssemblies,
AndroidFastDeploymentType = fastDevType
};
if (!useLatestSdk) {
lib.TargetFramework = "net7.0-android";
app.TargetFramework = "net7.0-android";
}
app.SetProperty ("AndroidPackageFormat", packageFormat);
app.MainPage = app.MainPage.Replace ("InitializeComponent ();", "InitializeComponent (); new Foo ();");
app.AddReference (lib);
Expand Down Expand Up @@ -465,7 +490,8 @@ public Foo ()
int port = rnd.Next (10000, 20000);
TestContext.Out.WriteLine ($"{port}");
var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) {
MaxConnectionAttempts = 2000,
MaxConnectionAttempts = DEBUGGER_MAX_CONNECTIONS,
TimeBetweenConnectionAttempts = DEBUGGER_CONNECTION_TIMEOUT,
};
var startInfo = new SoftDebuggerStartInfo (args) {
WorkingDirectory = Path.Combine (appBuilder.ProjectDirectory, app.IntermediateOutputPath, "android", "assets"),
Expand Down
102 changes: 102 additions & 0 deletions tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using System.Xml.XPath;
Expand Down Expand Up @@ -1137,5 +1138,106 @@ public void CheckResouceIsOverridden ([Values (true, false)] bool useAapt2)
}
}

[Test]
[Category ("WearOS")]
public void DotNetInstallAndRunPreviousSdk ([Values (false, true)] bool isRelease)
{
var proj = new XamarinFormsAndroidApplicationProject () {
TargetFramework = "net7.0-android",
IsRelease = isRelease,
EnableDefaultItems = true,
};

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

WaitForPermissionActivity (Path.Combine (Root, builder.ProjectDirectory, "permission-logcat.log"));
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity",
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30);
Assert.IsTrue(didLaunch, "Activity should have started.");
}

[Test]
public void TypeAndMemberRemapping ([Values (false, true)] bool isRelease)
{
var proj = new XamarinAndroidApplicationProject () {
IsRelease = isRelease,
EnableDefaultItems = true,
OtherBuildItems = {
new AndroidItem._AndroidRemapMembers ("RemapActivity.xml") {
Encoding = Encoding.UTF8,
TextContent = () => ResourceData.RemapActivityXml,
},
new AndroidItem.AndroidJavaSource ("RemapActivity.java") {
Encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false),
TextContent = () => ResourceData.RemapActivityJava,
Metadata = {
{ "Bind", "True" },
},
},
},
};
proj.MainActivity = proj.DefaultMainActivity.Replace (": Activity", ": global::Example.RemapActivity");
var builder = CreateApkBuilder ();
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed");
RunProjectAndAssert (proj, builder);
var appStartupLogcatFile = Path.Combine (Root, builder.ProjectDirectory, "logcat.log");
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity", appStartupLogcatFile);
Assert.IsTrue (didLaunch, "MainActivity should have launched!");
var logcatOutput = File.ReadAllText (appStartupLogcatFile);

StringAssert.Contains (
"RemapActivity.onMyCreate() invoked!",
logcatOutput,
"Activity.onCreate() wasn't remapped to RemapActivity.onMyCreate()!"
);
StringAssert.Contains (
"ViewHelper.mySetOnClickListener() invoked!",
logcatOutput,
"View.setOnClickListener() wasn't remapped to ViewHelper.mySetOnClickListener()!"
);
}

[Test]
public void SupportDesugaringStaticInterfaceMethods ()
{
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
EnableDefaultItems = true,
OtherBuildItems = {
new AndroidItem.AndroidJavaSource ("StaticMethodsInterface.java") {
Encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false),
TextContent = () => ResourceData.IdmStaticMethodsInterface,
Metadata = {
{ "Bind", "True" },
},
},
},
};

// Note: To properly test, Desugaring must be *enabled*, which requires that
// `$(SupportedOSPlatformVersion)` be *less than* 23. 21 is currently the default,
// but set this explicitly anyway just so that this implicit requirement is explicit.
proj.SupportedOSPlatformVersion = "21";

proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", @"
Console.WriteLine ($""# jonp static interface default method invocation; IStaticMethodsInterface.Value={Example.IStaticMethodsInterface.Value}"");
");
var builder = CreateApkBuilder ();
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed");
RunProjectAndAssert (proj, builder);
var appStartupLogcatFile = Path.Combine (Root, builder.ProjectDirectory, "logcat.log");
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity", appStartupLogcatFile);
Assert.IsTrue (didLaunch, "MainActivity should have launched!");
var logcatOutput = File.ReadAllText (appStartupLogcatFile);

StringAssert.Contains (
"IStaticMethodsInterface.Value=3",
logcatOutput,
"Was IStaticMethodsInterface.Value executed?"
);
}

}
}
Loading