forked from xamarin/xamarin-android
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] Added support for missing resource types
Fixes xamarin#1262 The initial version of the ManagedResourceParser was missing some types. Specifically `Menu`, `Animator`, `Plurals`, `Mipmap` and `Font`. This commit adds support for those missing types. It also adds a Task unit test for the Parser so ensure that the types are added.
- Loading branch information
1 parent
36993b3
commit c81515a
Showing
2 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...marin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManagedResourceParserTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using Xamarin.ProjectTools; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.Build.Framework; | ||
using System.Text; | ||
using Xamarin.Android.Tasks; | ||
using Microsoft.Build.Utilities; | ||
using Xamarin.ProjectTools; | ||
|
||
namespace Xamarin.Android.Build.Tests { | ||
[TestFixture] | ||
[Parallelizable (ParallelScope.Children)] | ||
public class ManagedResourceParserTests : BaseTest { | ||
|
||
const string StringsXml = @"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<resources> | ||
<string name = ""hello"" > Hello World, Click Me!</string> | ||
<string name = ""app_name"" > App1 </string > | ||
<plurals name=""num_locations_reported""> | ||
<item quantity=""zero"">No location reported</item> | ||
<item quantity=""one""> One location reported</item> | ||
<item quantity=""other"">%d locations reported</item> | ||
</plurals> | ||
<string name=""menu_settings"">Android Beam settings</string> | ||
</resources> | ||
"; | ||
|
||
const string StringsXml2 = @"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<resources> | ||
<string name = ""foo"" > Hello World, Click Me!</string> | ||
</resources> | ||
"; | ||
const string Menu = @"<menu xmlns:android=""http://schemas.android.com/apk/res/android""> | ||
<item android:id=""@+id/menu_settings"" | ||
android:icon=""@drawable/ic_menu_preferences"" | ||
android:showAsAction=""ifRoom"" | ||
android:title=""@string/menu_settings"" /> | ||
</menu>"; | ||
|
||
const string Animator = @"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<objectAnimator xmlns:android=""http://schemas.android.com/apk/res/android"" | ||
android:duration=""600"" | ||
android:interpolator=""@android:interpolator/fast_out_linear_in"" | ||
android:propertyName=""y"" | ||
android:valueFrom=""5000"" | ||
android:valueTo=""0"" | ||
android:valueType=""floatType"" />"; | ||
|
||
[Test] | ||
public void GenerateDesignerFile () | ||
{ | ||
var path = Path.Combine ("temp", TestName); | ||
Directory.CreateDirectory (Path.Combine (Root, path, "res", "values")); | ||
|
||
File.WriteAllText (Path.Combine (Root, path, "res", "values", "strings.xml"), StringsXml); | ||
|
||
Directory.CreateDirectory (Path.Combine (Root, path, "lp", "res", "animator")); | ||
Directory.CreateDirectory (Path.Combine (Root, path, "lp", "res", "font")); | ||
Directory.CreateDirectory (Path.Combine (Root, path, "lp", "res", "values")); | ||
Directory.CreateDirectory (Path.Combine (Root, path, "lp", "res", "drawable")); | ||
Directory.CreateDirectory (Path.Combine (Root, path, "lp", "res", "menu")); | ||
Directory.CreateDirectory (Path.Combine (Root, path, "lp", "res", "mipmap-hdpi")); | ||
File.WriteAllText (Path.Combine (Root, path, "lp", "res", "animator", "slide_in_bottom.xml"), Animator); | ||
File.WriteAllText (Path.Combine (Root, path, "lp", "res", "font", "arial.ttf"), ""); | ||
File.WriteAllText (Path.Combine (Root, path, "lp", "res", "values", "strings.xml"), StringsXml2); | ||
using (var stream = typeof (XamarinAndroidCommonProject).Assembly.GetManifestResourceStream ("Xamarin.ProjectTools.Resources.Base.Icon.png")) { | ||
var icon_binary_mdpi = new byte [stream.Length]; | ||
stream.Read (icon_binary_mdpi, 0, (int)stream.Length); | ||
File.WriteAllBytes (Path.Combine (Root, path, "lp", "res", "drawable", "ic_menu_preferences.png"), icon_binary_mdpi); | ||
File.WriteAllBytes (Path.Combine (Root, path, "lp", "res", "mipmap-hdpi", "icon.png"), icon_binary_mdpi); | ||
} | ||
File.WriteAllText (Path.Combine (Root, path, "lp", "res", "menu", "Options.xml"), Menu); | ||
IBuildEngine engine = new MockBuildEngine (TestContext.Out); | ||
var task = new GenerateResourceDesigner { | ||
BuildEngine = engine | ||
}; | ||
task.UseManagedResourceGenerator = true; | ||
task.DesignTimeBuild = true; | ||
task.Namespace = "Foo.Foo"; | ||
task.NetResgenOutputFile = Path.Combine (Root, path, "Resource.designer.cs"); | ||
task.ProjectDir = Path.Combine (Root, path); | ||
task.ResourceDirectory = Path.Combine (Root, path, "res") + Path.DirectorySeparatorChar; | ||
task.Resources = new TaskItem [] { | ||
new TaskItem (Path.Combine (Root, path, "res", "values", "strings.xml"), new Dictionary<string, string> () { | ||
{ "LogicalName", "values\\strings.xml" }, | ||
}), | ||
}; | ||
task.AdditionalResourceDirectories = new TaskItem [] { | ||
new TaskItem (Path.Combine (Root, path, "lp", "res")), | ||
}; | ||
task.IsApplication = true; | ||
Assert.IsTrue (task.Execute (), "Task should have executed successfully."); | ||
var data = File.ReadAllText (task.NetResgenOutputFile); | ||
Assert.IsTrue (data.Contains ("hello = 0;")); | ||
Assert.IsTrue (data.Contains ("app_name = 0;")); | ||
Assert.IsTrue (data.Contains ("foo = 0;")); | ||
Assert.IsTrue (data.Contains ("num_locations_reported = 0;")); | ||
Assert.IsTrue (data.Contains ("menu_settings = 0;")); | ||
Assert.IsTrue (data.Contains ("ic_menu_preferences = 0;")); | ||
Assert.IsTrue (data.Contains ("Options = 0;")); | ||
Assert.IsTrue (data.Contains ("icon = 0;")); | ||
Assert.IsTrue (data.Contains ("slide_in_bottom = 0;")); | ||
Assert.IsTrue (data.Contains ("arial = 0;")); | ||
Directory.Delete (Path.Combine (Root, path), recursive: true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters