Repository navigation
Expand file tree
/
Copy pathDebuggingTest.cs
More file actions
executable file
·159 lines (143 loc) · 6.08 KB
/
Copy pathDebuggingTest.cs
File metadata and controls
executable file
·159 lines (143 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Net;
using NUnit.Framework;
using Xamarin.ProjectTools;
using System.Collections.Generic;
using Microsoft.Build.Framework;
using Xamarin.Android.Tasks;
using Xamarin.Android.Tools;
namespace Xamarin.Android.Build.Tests
{
[TestFixture]
[Category ("UsesDevice")]
public class DebuggingTest : DeviceTest
{
const int DEBUGGER_MAX_CONNECTIONS = 100;
const int DEBUGGER_CONNECTION_TIMEOUT = 3000;
void SetTargetFrameworkAndManifest(XamarinAndroidApplicationProject proj, Builder builder, int? apiLevelOverride)
{
builder.LatestTargetFrameworkVersion (out string apiLevel);
proj.SupportedOSPlatformVersion = "24";
proj.AndroidManifest = $@"<?xml version=""1.0"" encoding=""utf-8""?>
<manifest xmlns:android=""http://schemas.android.com/apk/res/android"" android:versionCode=""1"" android:versionName=""1.0"" package=""{proj.PackageName}"">
<uses-sdk android:targetSdkVersion=""{apiLevelOverride?.ToString () ?? apiLevel}"" />
<application android:label=""${{PROJECT_NAME}}"">
</application >
</manifest>";
}
int FindTextInFile (string file, string text)
{
int lineNumber = 1;
foreach (var line in File.ReadAllLines (file)) {
if (line.Contains (text)) {
return lineNumber;
}
lineNumber++;
}
Console.WriteLine ($"Could not find '{text}' in '{file}'");
return -1;
}
static IEnumerable<TestCaseData> ApplicationRunsWithoutDebuggerCases ()
{
foreach (var configuration in BaseTest.ValidRuntimeConfigurations) {
foreach (var extractNativeLibs in new [] { false, true }) {
foreach (var useEmbeddedDex in new [] { false, true }) {
// Release normalizes embedded DEX to false; retain the existing NativeAOT skip cases.
if (configuration.isRelease && configuration.runtime == AndroidRuntime.CoreCLR && useEmbeddedDex) {
continue;
}
yield return new TestCaseData (configuration, extractNativeLibs, useEmbeddedDex);
}
}
}
}
[TestCaseSource (nameof (ApplicationRunsWithoutDebuggerCases))]
public void ApplicationRunsWithoutDebugger ((bool isRelease, AndroidRuntime runtime) configuration, bool extractNativeLibs, bool useEmbeddedDex)
{
var (isRelease, runtime) = configuration;
if (runtime == AndroidRuntime.NativeAOT) {
// TODO: Xamarin.Forms startup cannot find the ResourcesProvider constructor under NativeAOT.
Assert.Ignore ("NativeAOT Xamarin.Forms startup throws MissingMethodException.");
}
SwitchUser ();
var proj = new XamarinFormsAndroidApplicationProject () {
IsRelease = isRelease,
};
proj.SetRuntime (runtime);
proj.SetProperty ("AndroidEnableLegacyCompatibilityAssemblyFixups", "true");
if (isRelease) {
proj.SetRuntimeIdentifiers (new[] { DeviceAbi });
}
proj.SetDefaultTargetDevice ();
if (isRelease) {
// bundle tool does NOT support embeddedDex files it seems.
useEmbeddedDex = false;
}
using (var b = CreateApkBuilder ()) {
SetTargetFrameworkAndManifest (proj, b, null);
proj.AndroidManifest = proj.AndroidManifest.Replace ("<application ", $"<application android:extractNativeLibs=\"{extractNativeLibs.ToString ().ToLowerInvariant ()}\" android:useEmbeddedDex=\"{useEmbeddedDex.ToString ().ToLowerInvariant ()}\" ");
Assert.True (b.Install (proj), "Project should have installed.");
var manifest = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "AndroidManifest.xml");
AssertExtractNativeLibs (manifest, extractNativeLibs);
RunProjectAndAssert (proj, b);
Assert.True (WaitForActivityToStart (proj.PackageName, "MainActivity",
Path.Combine (Root, b.ProjectDirectory, "logcat.log"), ActivityStartTimeoutInSeconds), "Activity should have started.");
b.BuildLogFile = "uninstall.log";
Assert.True (b.Uninstall (proj), "Project should have uninstalled.");
}
}
[Test]
public void ClassLibraryMainLauncherRuns ([Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime)
{
bool isRelease = runtime == AndroidRuntime.NativeAOT;
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
return;
}
SwitchUser ();
var path = Path.Combine ("temp", TestName);
var app = new XamarinAndroidApplicationProject {
IsRelease = isRelease,
ProjectName = "MyApp",
};
app.SetRuntime (runtime);
app.SetDefaultTargetDevice ();
var lib = new XamarinAndroidLibraryProject {
ProjectName = "MyLibrary"
};
lib.Sources.Add (new BuildItem.Source ("MainActivity.cs") {
TextContent = () => lib.ProcessSourceTemplate (app.DefaultMainActivity).Replace ("${JAVA_PACKAGENAME}", app.JavaPackageName),
});
lib.AndroidResources.Clear ();
foreach (var resource in app.AndroidResources) {
lib.AndroidResources.Add (resource);
}
var reference = $"..\\{lib.ProjectName}\\{lib.ProjectName}.csproj";
app.References.Add (new BuildItem.ProjectReference (reference, lib.ProjectName, lib.ProjectGuid));
// Remove the default MainActivity.cs & AndroidResources
app.AndroidResources.Clear ();
app.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\layout\\foo.xml") {
TextContent = () =>
@"<?xml version=""1.0"" encoding=""utf-8""?>
<LinearLayout
xmlns:android=""http://schemas.android.com/apk/res/android""
android:layout_width=""fill_parent""
android:layout_height=""wrap_content""
/>"
});
app.Sources.Remove (app.GetItem ("MainActivity.cs"));
using (var libBuilder = CreateDllBuilder (Path.Combine (path, lib.ProjectName)))
using (var appBuilder = CreateApkBuilder (Path.Combine (path, app.ProjectName))) {
SetTargetFrameworkAndManifest (app, appBuilder, null);
Assert.IsTrue (libBuilder.Build (lib), "library build should have succeeded.");
Assert.True (appBuilder.Install (app), "app should have installed.");
RunProjectAndAssert (app, appBuilder);
Assert.True (WaitForActivityToStart (app.PackageName, "MainActivity",
Path.Combine (Root, appBuilder.ProjectDirectory, "logcat.log"), ActivityStartTimeoutInSeconds), "Activity should have started.");
}
}
}
}