Skip to content

Commit c4df398

Browse files
committed
Add a test
1 parent 728a814 commit c4df398

File tree

1 file changed

+63
-0
lines changed
  • src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests

1 file changed

+63
-0
lines changed

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,5 +2153,68 @@ public void Plugin_Maui_Audio ([Values] AndroidRuntime runtime)
21532153
const string className = "Lcrc64467b05f37239e7a6/StreamMediaDataSource;";
21542154
Assert.IsTrue (DexUtils.ContainsClass (className, dexFile, AndroidSdkPath), $"`{dexFile}` should include `{className}`!");
21552155
}
2156+
2157+
[Test]
2158+
public void MarshalMethodsUnhandledExceptionRuntimeFixUpWorks ([Values] AndroidRuntime runtime)
2159+
{
2160+
const bool isRelease = true;
2161+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
2162+
return;
2163+
}
2164+
2165+
switch (runtime) {
2166+
case AndroidRuntime.NativeAOT:
2167+
Assert.Ignore ("NativeAOT does not support marshal methods");
2168+
break;
2169+
2170+
// TODO: CoreCLR currently breaks with
2171+
// System.NotSupportedException: Writing mixed-mode assemblies is not supported
2172+
// at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
2173+
// at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
2174+
// at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
2175+
// at Mono.Cecil.AssemblyDefinition.Write(String fileName, WriterParameters parameters)
2176+
// at Xamarin.Android.Tasks.MonoAndroidRuntimeMarshalMethodsFixUp.ApplyFixUp(TaskLoggingHelper log, ITaskItem monoAndroidRuntime) in src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidRuntimeMarshalMethodsFixUp.cs:line 59
2177+
// at Xamarin.Android.Tasks.MonoAndroidRuntimeMarshalMethodsFixUp.Run(TaskLoggingHelper log, List`1 items) in src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidRuntimeMarshalMethodsFixUp.cs:line 18
2178+
// at Xamarin.Android.Tasks.FixUpMonoAndroidRuntime.RunTask() in src/Xamarin.Android.Build.Tasks/Tasks/FixUpMonoAndroidRuntime.cs:line 35
2179+
// at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs
2180+
case AndroidRuntime.CoreCLR:
2181+
Assert.Ignore ("CoreCLR currently doesn't work due to a bug in Mono.Cecil");
2182+
break;
2183+
}
2184+
2185+
var proj = new XamarinAndroidApplicationProject {
2186+
IsRelease = isRelease,
2187+
EnableMarshalMethods = true,
2188+
};
2189+
proj.SetRuntime (runtime);
2190+
using var builder = CreateApkBuilder ();
2191+
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
2192+
2193+
string monoAndroidRuntimePath = Path.Combine (
2194+
Root,
2195+
builder.ProjectDirectory,
2196+
proj.IntermediateOutputPath,
2197+
"android-arm64",
2198+
"linked",
2199+
"Mono.Android.Runtime.dll"
2200+
);
2201+
FileAssert.Exists (monoAndroidRuntimePath);
2202+
2203+
using var asm = AssemblyDefinition.ReadAssembly (monoAndroidRuntimePath);
2204+
const string TypeName = "Android.Runtime.AndroidEnvironmentInternal";
2205+
TypeDefinition? type = null;
2206+
2207+
foreach (ModuleDefinition module in asm.Modules) {
2208+
foreach (TypeDefinition t in module.Types) {
2209+
if (t.FullName.Equals (TypeName, StringComparison.Ordinal)) {
2210+
type = t;
2211+
break;
2212+
}
2213+
}
2214+
}
2215+
2216+
Assert.NotNull (type, $"Failed to find the '{TypeName}' type in '{monoAndroidRuntimePath}'");
2217+
Assert.IsTrue (type.IsPublic, "Type '{typeName}' should be public");
2218+
}
21562219
}
21572220
}

0 commit comments

Comments
 (0)