5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2006 Marek Sieradzki
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.
30 using Microsoft.Build.BuildEngine;
31 using NUnit.Framework;
33 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
36 private string GetItems (Project proj, string name)
38 BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
39 string str = String.Empty;
43 foreach (BuildItem bi in big) {
44 if (str == String.Empty)
45 str = bi.FinalItemSpec;
47 str += ";" + bi.FinalItemSpec;
54 // FIXME: split it to several tests and add more tests
55 public void TestItems1 ()
57 Engine engine = new Engine (Consts.BinPath);
58 Project proj = engine.CreateNewProject ();
60 string documentString = @"
61 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
63 <Item0 Include=""A"" />
64 <Item1 Include=""A;B;C"" />
65 <Item2 Include=""@(Item1);A;D"" />
66 <Item3 Include=""@(Item2)"" Exclude=""A"" />
67 <Item4 Include=""@(Item1);Q"" Exclude=""@(Item2)"" />
68 <Item5 Include=""@(Item1)"" Exclude=""@(Item2)"" />
69 <Item6 Include=""@(Item2)"" Exclude=""@(Item1)"" />
71 <ItemOrig Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
72 <ItemT1 Include=""@(Item1->'%(Identity)')"" />
73 <ItemT2 Include=""@(Item1->'%(Identity)%(Identity)')"" />
74 <ItemT3 Include=""@(Item1->'(-%(Identity)-)')"" />
75 <ItemT4 Include=""@(ItemOrig->'%(Extension)')"" />
76 <ItemT5 Include=""@(ItemOrig->'%(Filename)/%(Extension)')"" />
77 <ItemT6 Include=""@(ItemOrig->'%(RelativeDir)X/%(Filename)')"" />
79 <ItemS1 Include=""@(Item1,'-')"" />
80 <ItemS2 Include=""@(Item1,'xx')"" />
81 <ItemS3 Include=""@(Item1, '-')"" />
86 proj.LoadXml (documentString);
87 Assert.AreEqual ("A", GetItems (proj, "Item0"), "A1");
88 Assert.AreEqual ("A;B;C", GetItems (proj, "Item1"), "A2");
89 Assert.AreEqual ("A;B;C;A;D", GetItems (proj, "Item2"), "A3");
90 Assert.AreEqual ("B;C;D", GetItems (proj, "Item3"), "A4");
91 Assert.AreEqual ("Q", GetItems (proj, "Item4"), "A5");
92 Assert.AreEqual ("", GetItems (proj, "Item5"), "A6");
93 Assert.AreEqual ("D", GetItems (proj, "Item6"), "A7");
95 Assert.AreEqual ("A;B;C", GetItems (proj, "ItemT1"), "A8");
96 Assert.AreEqual ("AA;BB;CC", GetItems (proj, "ItemT2"), "A9");
97 Assert.AreEqual ("(-A-);(-B-);(-C-)", GetItems (proj, "ItemT3"), "A10");
98 Assert.AreEqual (".txt;.txt;.zip;.zip", GetItems (proj, "ItemT4"), "A11");
99 Assert.AreEqual ("B/.txt;C/.txt;B/.zip;C/.zip", GetItems (proj, "ItemT5"), "A12");
100 Assert.AreEqual (@"A\X/B;A\X/C;B\X/B;B\X/C", GetItems (proj, "ItemT6"), "A13");
102 Assert.AreEqual ("A-B-C", GetItems (proj, "ItemS1"), "A14");
103 Assert.AreEqual ("AxxBxxC", GetItems (proj, "ItemS2"), "A15");
105 Assert.AreEqual ("A-B-C", GetItems (proj, "ItemS3"), "A16");