2 // AssignCultureTest.cs
5 // Ankit Jain (jankit@novell.com)
7 // Copyright 2008 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections.Generic;
32 using NUnit.Framework;
33 using Microsoft.Build.BuildEngine;
35 namespace MonoTests.Microsoft.Build.Tasks
38 public class AssignCultureTest
41 static char DSC = Path.DirectorySeparatorChar;
51 } else if ('\\' == DSC) {
55 //FIXME: For Mac. figure this out when we need it
58 files = new string [] {
60 ".\\foo.resx", @"bar\foo.resx",
61 "foo.fr.resx", @"dir\abc.en.resx", "foo.bar.resx",
63 "sample.txt", @"bar\sample.txt",
64 "sample.it.png", @"dir\sample.en.png", "sample.inv.txt"};
66 Engine engine = new Engine (Consts.BinPath);
67 project = engine.CreateNewProject ();
71 public void TestAssignedFiles ()
73 LoadAndBuildProject (files);
76 if (OS == OsType.Unix) {
77 CheckItems (new string [] {"./foo.resx", "bar/foo.resx", "foo.fr.resx", "dir/abc.en.resx", "foo.bar.resx",
78 "sample.txt", "bar/sample.txt", "sample.it.png", "dir/sample.en.png", "sample.inv.txt"},
79 new string [] {null, null, "fr", "en", null, null, null, "it", "en", null},
80 "AssignedFiles", "A2");
81 } else if (OS == OsType.Windows) {
82 CheckItems (new string [] {".\\foo.resx", @"bar\foo.resx", "foo.fr.resx", @"dir\abc.en.resx", "foo.bar.resx",
83 "sample.txt", @"bar\sample.txt", "sample.it.png", @"dir\sample.en.png", "sample.inv.txt"},
84 new string [] { null, null, "fr", "en", null, null, null, "it", "en", null },
85 "AssignedFiles", "A2");
90 public void TestAssignedFilesWithCulture ()
92 LoadAndBuildProject (files);
94 //AssignedFilesWithCulture
95 if (OS == OsType.Unix) {
96 CheckItems (new string [] { "foo.fr.resx", "dir/abc.en.resx", "sample.it.png", "dir/sample.en.png" },
97 new string [] {"fr", "en", "it", "en"},
98 "AssignedFilesWithCulture", "A2");
99 } else if (OS == OsType.Windows) {
100 CheckItems (new string [] { "foo.fr.resx", @"dir\abc.en.resx", "sample.it.png", @"dir\sample.en.png" },
101 new string [] { "fr", "en", "it", "en" },
102 "AssignedFilesWithCulture", "A2");
107 public void TestAssignedFilesWithNoCulture ()
109 LoadAndBuildProject (files);
111 //AssignedFilesWithNoCulture
112 if (OS == OsType.Unix) {
113 CheckItems (new string [] { "./foo.resx", "bar/foo.resx", "foo.bar.resx", "sample.txt", "bar/sample.txt", "sample.inv.txt"},
114 null, "AssignedFilesWithNoCulture", "A2");
115 } else if (OS == OsType.Windows) {
116 CheckItems (new string [] { ".\\foo.resx", @"bar\foo.resx", "foo.bar.resx", "sample.txt", @"bar\sample.txt", "sample.inv.txt"},
117 null, "AssignedFilesWithNoCulture", "A2");
122 public void TestCultureNeutralAssignedFiles ()
124 LoadAndBuildProject (files);
126 //CultureNeutralAssignedFiles
127 if (OS == OsType.Unix) {
128 CheckItems (new string [] { "./foo.resx", "bar/foo.resx", "foo.resx", "dir/abc.resx", "foo.bar.resx",
129 "sample.txt", "bar/sample.txt", "sample.png", "dir/sample.png", "sample.inv.txt"},
130 new string [] { null, null, "fr", "en", null, null, null, "it", "en", null },
131 "CultureNeutralAssignedFiles", "A2");
132 } else if (OS == OsType.Windows) {
133 CheckItems (new string [] { ".\\foo.resx", @"bar\foo.resx", "foo.resx", @"dir\abc.resx", "foo.bar.resx",
134 "sample.txt", @"bar\sample.txt", "sample.png", @"dir\sample.png", "sample.inv.txt"},
135 new string [] { null, null, "fr", "en", null, null, null, "it", "en", null },
136 "CultureNeutralAssignedFiles", "A2");
140 void LoadAndBuildProject (string [] files_list)
142 string projectText = CreateProjectString (files_list);
143 project.LoadXml (projectText);
144 Assert.IsTrue (project.Build ("1"), "A1 : Error in building");
147 void CheckItems (string [] values, string [] cultures, string itemlist_name, string prefix)
149 BuildItemGroup group = project.GetEvaluatedItemsByName (itemlist_name);
150 Assert.AreEqual (values.Length, group.Count, prefix + "#1");
151 for (int i = 0; i < values.Length; i++) {
152 Assert.AreEqual (values [i], group [i].FinalItemSpec, prefix + "#2");
153 Assert.IsTrue (group [i].HasMetadata ("Child"), prefix + "#3");
154 Assert.AreEqual ("ChildValue", group [i].GetMetadata ("Child"), prefix + "#4");
155 Assert.AreEqual (cultures != null && cultures [i] != null, group [i].HasMetadata ("Culture"), prefix + "#5");
156 if (cultures != null && cultures [i] != null)
157 Assert.AreEqual (cultures [i], group [i].GetMetadata ("Culture"), prefix + "#6");
161 string CreateProjectString (string [] files)
163 StringBuilder sb = new StringBuilder ();
164 sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""><ItemGroup>");
165 foreach (string file in files)
166 sb.AppendFormat ("<Files Include=\"{0}\"><Child>ChildValue</Child></Files>\n", file);
168 sb.Append (@"</ItemGroup>
170 <AssignCulture Files=""@(Files)"" >
171 <Output TaskParameter=""AssignedFiles"" ItemName=""AssignedFiles"" />
172 <Output TaskParameter=""AssignedFilesWithCulture"" ItemName=""AssignedFilesWithCulture"" />
173 <Output TaskParameter=""AssignedFilesWithNoCulture"" ItemName=""AssignedFilesWithNoCulture"" />
174 <Output TaskParameter=""CultureNeutralAssignedFiles"" ItemName=""CultureNeutralAssignedFiles"" />
179 return sb.ToString ();