|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.IO; |
4 | 4 | using System.Linq; |
| 5 | +using System.Text; |
5 | 6 | using System.Text.RegularExpressions; |
6 | 7 | using System.Xml.Linq; |
7 | 8 | using System.Xml.XPath; |
|
11 | 12 | namespace Xamarin.Android.Build.Tests |
12 | 13 | { |
13 | 14 | [TestFixture] |
14 | | - [Category ("UsesDevice")] |
| 15 | + [Category ("UsesDevice"), Category ("WearOS")] |
15 | 16 | public class InstallAndRunTests : DeviceTest |
16 | 17 | { |
17 | 18 | static ProjectBuilder builder; |
@@ -1137,5 +1138,105 @@ public void CheckResouceIsOverridden ([Values (true, false)] bool useAapt2) |
1137 | 1138 | } |
1138 | 1139 | } |
1139 | 1140 |
|
| 1141 | + public void DotNetInstallAndRunPreviousSdk ([Values (false, true)] bool isRelease) |
| 1142 | + { |
| 1143 | + XamarinAndroidApplicationProject proj; |
| 1144 | + proj = new XamarinFormsAndroidApplicationProject { |
| 1145 | + TargetFramework = "net7.0-android", |
| 1146 | + IsRelease = isRelease, |
| 1147 | + EnableDefaultItems = true, |
| 1148 | + }; |
| 1149 | + |
| 1150 | + var builder = CreateApkBuilder (); |
| 1151 | + Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed"); |
| 1152 | + RunProjectAndAssert (proj, builder); |
| 1153 | + |
| 1154 | + WaitForPermissionActivity (Path.Combine (Root, builder.ProjectDirectory, "permission-logcat.log")); |
| 1155 | + bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity", |
| 1156 | + Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30); |
| 1157 | + Assert.IsTrue(didLaunch, "Activity should have started."); |
| 1158 | + } |
| 1159 | + |
| 1160 | + [Test] |
| 1161 | + public void TypeAndMemberRemapping ([Values (false, true)] bool isRelease) |
| 1162 | + { |
| 1163 | + var proj = new XamarinAndroidApplicationProject () { |
| 1164 | + IsRelease = isRelease, |
| 1165 | + EnableDefaultItems = true, |
| 1166 | + OtherBuildItems = { |
| 1167 | + new AndroidItem._AndroidRemapMembers ("RemapActivity.xml") { |
| 1168 | + Encoding = Encoding.UTF8, |
| 1169 | + TextContent = () => ResourceData.RemapActivityXml, |
| 1170 | + }, |
| 1171 | + new AndroidItem.AndroidJavaSource ("RemapActivity.java") { |
| 1172 | + Encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false), |
| 1173 | + TextContent = () => ResourceData.RemapActivityJava, |
| 1174 | + Metadata = { |
| 1175 | + { "Bind", "True" }, |
| 1176 | + }, |
| 1177 | + }, |
| 1178 | + }, |
| 1179 | + }; |
| 1180 | + proj.MainActivity = proj.DefaultMainActivity.Replace (": Activity", ": global::Example.RemapActivity"); |
| 1181 | + var builder = CreateApkBuilder (); |
| 1182 | + Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed"); |
| 1183 | + RunProjectAndAssert (proj, builder); |
| 1184 | + var appStartupLogcatFile = Path.Combine (Root, builder.ProjectDirectory, "logcat.log"); |
| 1185 | + bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity", appStartupLogcatFile); |
| 1186 | + Assert.IsTrue (didLaunch, "MainActivity should have launched!"); |
| 1187 | + var logcatOutput = File.ReadAllText (appStartupLogcatFile); |
| 1188 | + |
| 1189 | + StringAssert.Contains ( |
| 1190 | + "RemapActivity.onMyCreate() invoked!", |
| 1191 | + logcatOutput, |
| 1192 | + "Activity.onCreate() wasn't remapped to RemapActivity.onMyCreate()!" |
| 1193 | + ); |
| 1194 | + StringAssert.Contains ( |
| 1195 | + "ViewHelper.mySetOnClickListener() invoked!", |
| 1196 | + logcatOutput, |
| 1197 | + "View.setOnClickListener() wasn't remapped to ViewHelper.mySetOnClickListener()!" |
| 1198 | + ); |
| 1199 | + } |
| 1200 | + |
| 1201 | + [Test] |
| 1202 | + public void SupportDesugaringStaticInterfaceMethods () |
| 1203 | + { |
| 1204 | + var proj = new XamarinAndroidApplicationProject () { |
| 1205 | + IsRelease = true, |
| 1206 | + EnableDefaultItems = true, |
| 1207 | + OtherBuildItems = { |
| 1208 | + new AndroidItem.AndroidJavaSource ("StaticMethodsInterface.java") { |
| 1209 | + Encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false), |
| 1210 | + TextContent = () => ResourceData.IdmStaticMethodsInterface, |
| 1211 | + Metadata = { |
| 1212 | + { "Bind", "True" }, |
| 1213 | + }, |
| 1214 | + }, |
| 1215 | + }, |
| 1216 | + }; |
| 1217 | + |
| 1218 | + // Note: To properly test, Desugaring must be *enabled*, which requires that |
| 1219 | + // `$(SupportedOSPlatformVersion)` be *less than* 23. 21 is currently the default, |
| 1220 | + // but set this explicitly anyway just so that this implicit requirement is explicit. |
| 1221 | + proj.SupportedOSPlatformVersion = "21"; |
| 1222 | + |
| 1223 | + proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", @" |
| 1224 | + Console.WriteLine ($""# jonp static interface default method invocation; IStaticMethodsInterface.Value={Example.IStaticMethodsInterface.Value}""); |
| 1225 | +"); |
| 1226 | + var builder = CreateApkBuilder (); |
| 1227 | + Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed"); |
| 1228 | + RunProjectAndAssert (proj, builder); |
| 1229 | + var appStartupLogcatFile = Path.Combine (Root, builder.ProjectDirectory, "logcat.log"); |
| 1230 | + bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity", appStartupLogcatFile); |
| 1231 | + Assert.IsTrue (didLaunch, "MainActivity should have launched!"); |
| 1232 | + var logcatOutput = File.ReadAllText (appStartupLogcatFile); |
| 1233 | + |
| 1234 | + StringAssert.Contains ( |
| 1235 | + "IStaticMethodsInterface.Value=3", |
| 1236 | + logcatOutput, |
| 1237 | + "Was IStaticMethodsInterface.Value executed?" |
| 1238 | + ); |
| 1239 | + } |
| 1240 | + |
1140 | 1241 | } |
1141 | 1242 | } |
0 commit comments