Skip to content

Commit cf89575

Browse files
committed
Fix remaining unit tests?
Move `TypeAndMemberRemapping()` *earlier* in the file. `DotNetInstallAndRun()` appears in the **Tests** tab, but `TypeAndMemberRemapping()` was not, which was very confusing. On a lark, suspect that `TypeAndMemberRemapping()` isn't run because it's after `DotNetDebug()`, which is `[Category("Debugger")]`. Will moving the test fix things? Fix Mono.Android.NET-Tests, via removing a debug message from AndroidRuntime, and test fixes within external/Java.Interop.
1 parent 23f570b commit cf89575

File tree

4 files changed

+61
-55
lines changed

4 files changed

+61
-55
lines changed

src/Mono.Android/Android.Runtime/AndroidRuntime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ protected override IEnumerable<string> GetSimpleReferences (Type type)
310310
if (JNIEnv.ReplacementTypes == null) {
311311
return null;
312312
}
313-
Logger.Log (LogLevel.Warn, "*jonp*", $"# jonp: looking for replacement type for `{jniSimpleReference}`");
314-
Logger.Log (LogLevel.Warn, "*jonp*", new System.Diagnostics.StackTrace (true).ToString ());
313+
Logger.Log (LogLevel.Warn, "*jonp*", $"# jonp: looking for replacement type for `{jniSimpleReference}`; ReplacementTypes? {JNIEnv.ReplacementTypes != null}");
314+
// Logger.Log (LogLevel.Warn, "*jonp*", new System.Diagnostics.StackTrace (true).ToString ());
315315
if (JNIEnv.ReplacementTypes.TryGetValue (jniSimpleReference, out var v)) {
316316
Logger.Log (LogLevel.Warn, "*jonp*", $"# jonp: found replacement type: `{jniSimpleReference}` => `{v}`");
317317
return v;

tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,57 @@ public void DotNetInstallAndRun (bool isRelease, bool xamarinForms, bool? publis
8484
Assert.IsTrue(didLaunch, "Activity should have started.");
8585
}
8686

87+
[Test]
88+
public void TypeAndMemberRemapping ([Values (false, true)] bool isRelease)
89+
{
90+
AssertHasDevices ();
91+
92+
var proj = new XASdkProject () {
93+
IsRelease = isRelease,
94+
OtherBuildItems = {
95+
new AndroidItem._AndroidRemapMembers ("RemapActivity.xml") {
96+
Encoding = Encoding.UTF8,
97+
TextContent = () => ResourceData.RemapActivityXml,
98+
},
99+
new AndroidItem.AndroidJavaSource ("RemapActivity.java") {
100+
Encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false),
101+
TextContent = () => ResourceData.RemapActivityJava,
102+
Metadata = {
103+
{ "Bind", "True" },
104+
},
105+
},
106+
},
107+
};
108+
proj.MainActivity = proj.DefaultMainActivity.Replace (": Activity", ": global::Example.RemapActivity");
109+
proj.SetRuntimeIdentifier (DeviceAbi);
110+
var relativeProjDir = Path.Combine ("temp", TestName);
111+
var fullProjDir = Path.Combine (Root, relativeProjDir);
112+
TestOutputDirectories [TestContext.CurrentContext.Test.ID] = fullProjDir;
113+
var files = proj.Save ();
114+
proj.Populate (relativeProjDir, files);
115+
proj.CopyNuGetConfig (relativeProjDir);
116+
var dotnet = new DotNetCLI (proj, Path.Combine (fullProjDir, proj.ProjectFilePath));
117+
118+
Assert.IsTrue (dotnet.Build (), "`dotnet build` should succeed");
119+
Assert.IsTrue (dotnet.Run (), "`dotnet run` should succeed");
120+
121+
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity",
122+
Path.Combine (fullProjDir, "logcat.log"));
123+
Assert.IsTrue (didLaunch, "MainActivity should have launched!");
124+
var logcatOutput = File.ReadAllText (Path.Combine (fullProjDir, "logcat.log"));
125+
126+
StringAssert.Contains (
127+
"RemapActivity.onMyCreate() invoked!",
128+
logcatOutput,
129+
"Activity.onCreate() wasn't remapped to RemapActivity.onMyCreate()!"
130+
);
131+
StringAssert.Contains (
132+
"ViewHelper.mySetOnClickListener() invoked!",
133+
logcatOutput,
134+
"View.setOnClickListener() wasn't remapped to ViewHelper.mySetOnClickListener()!"
135+
);
136+
}
137+
87138
[Test]
88139
[Category ("Debugger"), Category ("Node-4")]
89140
public void DotNetDebug ()
@@ -157,57 +208,6 @@ public void DotNetDebug ()
157208
WaitFor (2000);
158209
Assert.IsTrue (breakpointHit, "Should have a breakpoint");
159210
}
160-
161-
[Test]
162-
public void TypeAndMemberRemapping ([Values (false, true)] bool isRelease)
163-
{
164-
AssertHasDevices ();
165-
166-
var proj = new XASdkProject () {
167-
IsRelease = isRelease,
168-
OtherBuildItems = {
169-
new AndroidItem._AndroidRemapMembers ("RemapActivity.xml") {
170-
Encoding = Encoding.UTF8,
171-
TextContent = () => ResourceData.RemapActivityXml,
172-
},
173-
new AndroidItem.AndroidJavaSource ("RemapActivity.java") {
174-
Encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false),
175-
TextContent = () => ResourceData.RemapActivityJava,
176-
Metadata = {
177-
{ "Bind", "True" },
178-
},
179-
},
180-
},
181-
};
182-
proj.MainActivity = proj.DefaultMainActivity.Replace (": Activity", ": global::Example.RemapActivity");
183-
proj.SetRuntimeIdentifier (DeviceAbi);
184-
var relativeProjDir = Path.Combine ("temp", TestName);
185-
var fullProjDir = Path.Combine (Root, relativeProjDir);
186-
TestOutputDirectories [TestContext.CurrentContext.Test.ID] = fullProjDir;
187-
var files = proj.Save ();
188-
proj.Populate (relativeProjDir, files);
189-
proj.CopyNuGetConfig (relativeProjDir);
190-
var dotnet = new DotNetCLI (proj, Path.Combine (fullProjDir, proj.ProjectFilePath));
191-
192-
Assert.IsTrue (dotnet.Build (), "`dotnet build` should succeed");
193-
Assert.IsTrue (dotnet.Run (), "`dotnet run` should succeed");
194-
195-
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity",
196-
Path.Combine (fullProjDir, "logcat.log"));
197-
Assert.IsTrue (didLaunch, "MainActivity should have launched!");
198-
var logcatOutput = File.ReadAllText (Path.Combine (fullProjDir, "logcat.log"));
199-
200-
StringAssert.Contains (
201-
"RemapActivity.onMyCreate() invoked!",
202-
logcatOutput,
203-
"Activity.onCreate() wasn't remapped to RemapActivity.onMyCreate()!"
204-
);
205-
StringAssert.Contains (
206-
"ViewHelper.mySetOnClickListener() invoked!",
207-
logcatOutput,
208-
"View.setOnClickListener() wasn't remapped to ViewHelper.mySetOnClickListener()!"
209-
);
210-
}
211211
}
212212
}
213213
#endif

tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Remaps.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@
1717
source-type="java/lang/Runtime"
1818
source-method-name="remappedToGetRuntime"
1919
target-type="java/lang/Runtime"
20-
target-method-name="getRuntime" target-method-instance-to-static="true" />
20+
target-method-name="getRuntime" target-method-instance-to-static="false" />
21+
<replace-method
22+
source-type="com/xamarin/interop/RenameClassBase2"
23+
source-method-name="hashCode"
24+
source-method-signature="()"
25+
target-type="com/xamarin/interop/RenameClassBase2"
26+
target-method-name="myNewHashCode" target-method-instance-to-static="false" />
2127
</replacements>

0 commit comments

Comments
 (0)