Skip to content

Commit 18fd0b8

Browse files
committed
Inital Commit
1 parent 18cf836 commit 18fd0b8

File tree

10 files changed

+71
-9
lines changed

10 files changed

+71
-9
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<SystemCollectionsImmutableVersion>6.0.0</SystemCollectionsImmutableVersion>
5151
<SystemRuntimeCompilerServicesUnsafeVersion>6.0.0</SystemRuntimeCompilerServicesUnsafeVersion>
5252
<ELFSharpVersion>2.13.1</ELFSharpVersion>
53+
<HumanizerVersion>2.14.1</HumanizerVersion>
5354
<MdocPackageVersion Condition=" '$(MdocPackageVersion)' == '' ">5.8.9.2</MdocPackageVersion>
5455
</PropertyGroup>
5556

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,33 @@ public void CheckIncludedAssemblies ([Values (false, true)] bool usesAssemblySto
7373
};
7474
proj.SetProperty ("AndroidUseAssemblyStore", usesAssemblyStores.ToString ());
7575
proj.SetAndroidSupportedAbis ("armeabi-v7a");
76+
proj.PackageReferences.Add (new Package {
77+
Id = "Humanizer.Core",
78+
Version = "2.14.1",
79+
});
80+
proj.PackageReferences.Add (new Package {
81+
Id = "Humanizer.Core.es",
82+
Version = "2.14.1",
83+
});
84+
proj.MainActivity = proj.DefaultMainActivity
85+
.Replace ("//${USINGS}", @"using System;
86+
using Humanizer;
87+
using System.Globalization;")
88+
.Replace ("//${AFTER_ONCREATE}", @"var c = new CultureInfo (""es-ES"");
89+
Console.WriteLine ($""{DateTime.UtcNow.AddHours(-30).Humanize(culture:c)}"");
90+
//${AFTER_ONCREATE}");
91+
if (Builder.UseDotNet) {
92+
proj.OtherBuildItems.Add (new BuildItem ("Using", "System.Globalization"));
93+
proj.OtherBuildItems.Add (new BuildItem ("Using", "Humanizer"));
94+
}
7695
if (!Builder.UseDotNet) {
7796
proj.PackageReferences.Add (new Package {
7897
Id = "System.Runtime.InteropServices.WindowsRuntime",
7998
Version = "4.0.1",
8099
TargetFramework = "monoandroid71",
81100
});
82101
proj.References.Add (new BuildItem.Reference ("Mono.Data.Sqlite.dll"));
83-
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", "var command = new Mono.Data.Sqlite.SqliteCommand ();");
102+
proj.MainActivity = proj.MainActivity.Replace ("//${AFTER_ONCREATE}", "var command = new Mono.Data.Sqlite.SqliteCommand ();");
84103
}
85104
var expectedFiles = Builder.UseDotNet ?
86105
new [] {
@@ -95,6 +114,11 @@ public void CheckIncludedAssemblies ([Values (false, true)] bool usesAssemblySto
95114
"System.Linq.dll",
96115
"UnnamedProject.dll",
97116
"_Microsoft.Android.Resource.Designer.dll",
117+
"Humanizer.dll",
118+
"es/Humanizer.resources.dll",
119+
"System.Collections.dll",
120+
"System.Collections.Concurrent.dll",
121+
"System.Text.RegularExpressions.dll",
98122
} :
99123
new [] {
100124
"Java.Interop.dll",
@@ -106,6 +130,8 @@ public void CheckIncludedAssemblies ([Values (false, true)] bool usesAssemblySto
106130
"UnnamedProject.dll",
107131
"Mono.Data.Sqlite.dll",
108132
"Mono.Data.Sqlite.dll.config",
133+
"Humanizer.dll",
134+
//"es/Humanizer.resources.dll", <- Bug in classic.
109135
};
110136
using (var b = CreateApkBuilder ()) {
111137
Assert.IsTrue (b.Build (proj), "build should have succeeded.");

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ArchiveAssemblyHelper.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ void ArchiveContains (string[] fileNames, out List<string> existingFiles, out Li
239239
{
240240
using (var zip = ZipHelper.OpenZip (archivePath)) {
241241
existingFiles = zip.Where (a => a.FullName.StartsWith (assembliesRootDir, StringComparison.InvariantCultureIgnoreCase)).Select (a => a.FullName).ToList ();
242-
missingFiles = fileNames.Where (x => !zip.ContainsEntry (assembliesRootDir + Path.GetFileName (x))).ToList ();
243-
additionalFiles = existingFiles.Where (x => !fileNames.Contains (Path.GetFileName (x))).ToList ();
242+
missingFiles = fileNames.Where (x => !zip.ContainsEntry (assembliesRootDir + x)).ToList ();
243+
additionalFiles = existingFiles.Where (x => !fileNames.Contains (x.Replace (assembliesRootDir, string.Empty))).ToList ();
244244
}
245245
}
246246

@@ -258,15 +258,21 @@ void StoreContains (string[] fileNames, out List<string> existingFiles, out List
258258
if (otherFiles.Count > 0) {
259259
using (var zip = ZipHelper.OpenZip (archivePath)) {
260260
foreach (string file in otherFiles) {
261-
string fullPath = assembliesRootDir + Path.GetFileName (file);
261+
string fullPath = assembliesRootDir + file;
262262
if (zip.ContainsEntry (fullPath)) {
263263
existingFiles.Add (file);
264264
}
265265
}
266266
}
267267
}
268268

269-
var explorer = new AssemblyStoreExplorer (archivePath);
269+
var explorer = new AssemblyStoreExplorer (archivePath, customLogger: (a, s) => {
270+
Console.WriteLine ($"DEBUG! {s}");
271+
});
272+
273+
foreach (var f in explorer.AssembliesByName) {
274+
Console.WriteLine ($"DEBUG!\tKey:{f.Key}");
275+
}
270276

271277
// Assembly stores don't store the assembly extension
272278
var storeAssemblies = explorer.AssembliesByName.Keys.Select (x => $"{x}.dll");
@@ -298,7 +304,7 @@ void StoreContains (string[] fileNames, out List<string> existingFiles, out List
298304
}
299305

300306
foreach (string file in fileNames) {
301-
if (existingFiles.Contains (Path.GetFileName (file))) {
307+
if (existingFiles.Contains (file)) {
302308
continue;
303309
}
304310
missingFiles.Add (file);

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<ItemGroup>
5757
<PackageReference Include="ELFSharp" Version="$(ELFSharpVersion)" />
5858
<PackageReference Include="ICSharpCode.Decompiler" Version="7.2.1.6856" />
59+
<PackageReference Include="Humanizer" Version="$(HumanizerVersion)" />
5960
</ItemGroup>
6061

6162
<ItemGroup>

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/MainActivity.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Android.Views;
77
using Android.Widget;
88
using Android.OS;
9+
//${USINGS}
910

1011
namespace ${ROOT_NAMESPACE}
1112
{

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/DotNet/MainActivity.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//${USINGS}
12
namespace ${ROOT_NAMESPACE}
23
{
34
[Android.Runtime.Register ("${JAVA_PACKAGENAME}.MainActivity"), Activity (Label = "${PROJECT_NAME}", MainLauncher = true, Icon = "@drawable/icon")]

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Forms/MainActivity.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Android.Views;
77
using Android.Widget;
88
using Android.OS;
9+
//${USINGS}
910

1011
namespace ${ROOT_NAMESPACE}
1112
{
@@ -23,4 +24,4 @@ protected override void OnCreate (Bundle savedInstanceState)
2324
LoadApplication (new App ());
2425
}
2526
}
26-
}
27+
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Wear/MainActivity.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Android.Support.Wearable.Views;
99
using Android.Views;
1010
using Android.Widget;
11+
//${USINGS}
1112

1213
namespace ${ROOT_NAMESPACE}
1314
{

tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<PackageReference Include="NodaTime" Version="2.4.5" />
4141
<PackageReference Include="MSBuild.StructuredLogger" Version="2.1.787" />
4242
<PackageReference Include="ICSharpCode.Decompiler" Version="7.2.1.6856" />
43+
<PackageReference Include="Humanizer" Version="$(HumanizerVersion)" />
4344
</ItemGroup>
4445

4546
<ItemGroup>

tests/MSBuildDeviceIntegration/Tests/LocalizationTests.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NUnit.Framework;
88
using NUnit.Framework.Interfaces;
99
using Xamarin.ProjectTools;
10+
using Humanizer;
1011

1112
namespace Xamarin.Android.Build.Tests
1213
{
@@ -30,14 +31,23 @@ public void BeforeAllTests ()
3031
}
3132

3233
proj = new XamarinAndroidApplicationProject (packageName: "LocalizationTests");
33-
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", @"button.Text = $""Strings.SomeString={Strings.SomeString}"";
34+
proj.PackageReferences.Add (new Package {
35+
Id = "Humanizer",
36+
Version = "2.14.1",
37+
});
38+
var source = proj.DefaultMainActivity
39+
.Replace ("//${USINGS}", @"using Humanizer;
40+
using System.Globalization;");
41+
source = source.Replace ("//${AFTER_ONCREATE}", @"button.Text = $""Strings.SomeString={Strings.SomeString}"";
3442
Console.WriteLine ($""LocaleNative={Java.Util.Locale.Default.Language}-{Java.Util.Locale.Default.Country}"");
3543
Console.WriteLine ($""CurrentCulture={System.Globalization.CultureInfo.CurrentCulture.Name}"");
3644
Console.WriteLine ($""Strings.SomeString={Strings.SomeString}"");
45+
Console.WriteLine ($""Humanizer={DateTime.UtcNow.AddHours(-30).Humanize()}"");
3746
");
47+
proj.MainActivity = source;
3848
InlineData.AddCultureResourcesToProject (proj, "Strings", "SomeString");
3949
InlineData.AddCultureResourceDesignerToProject (proj, proj.RootNamespace ?? proj.ProjectName, "Strings", "SomeString");
40-
50+
4151
builder = CreateApkBuilder (Path.Combine ("temp", "LocalizationTests"));
4252
builder.BuildLogFile = "onetimesetup-install.log";
4353
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");
@@ -247,8 +257,21 @@ public void CheckLocalizationIsCorrect (string locale)
247257
}
248258
return false;
249259
}, appStartupLogcatFile, 45), $"App output did not contain '{logcatSearchString}'");
260+
Assert.IsTrue (logLine.Contains (expectedLogcatOutput), $"Line '{logLine}' did not contain '{expectedLogcatOutput}'");
250261

262+
string humanizerLogCatFile = Path.Combine (Root, builder.ProjectDirectory, $"humanizer-logcat-{locale.Replace ("/", "-")}.log");
263+
var culture = new CultureInfo (locale);
264+
expectedLogcatOutput = DateTime.UtcNow.AddHours(-30).Humanize(culture: culture);
265+
logcatSearchString = "Humanizer=";
266+
Assert.IsTrue (MonitorAdbLogcat ((line) => {
267+
if (line.Contains (logcatSearchString)) {
268+
logLine = line;
269+
return true;
270+
}
271+
return false;
272+
}, humanizerLogCatFile, timeout:45), $"App output did not contain '{logcatSearchString}'");
251273
Assert.IsTrue (logLine.Contains (expectedLogcatOutput), $"Line '{logLine}' did not contain '{expectedLogcatOutput}'");
274+
252275
}
253276
}
254277
}

0 commit comments

Comments
 (0)